### 2021-08-03更新
------ #### MyDbV4 V3.0.2108.0301 - *.[新增]新增内置HtmlAgilityPack组件。
This commit is contained in:
parent
c3d4ddf574
commit
a1d6dce946
Binary file not shown.
BIN
Bin/Debug/CommonControls/.NET4 示例/Itrycn_Project2.exe
Normal file
BIN
Bin/Debug/CommonControls/.NET4 示例/Itrycn_Project2.exe
Normal file
Binary file not shown.
Binary file not shown.
File diff suppressed because it is too large
Load Diff
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
File diff suppressed because it is too large
Load Diff
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
File diff suppressed because it is too large
Load Diff
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
File diff suppressed because it is too large
Load Diff
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
11
CHANGELOG.md
11
CHANGELOG.md
|
|
@ -1,13 +1,16 @@
|
|||
### 2021-07-29更新
|
||||
### 2021-08-03更新
|
||||
------
|
||||
#### MyDbV4 V3.0.2108.0301
|
||||
- *.[新增]新增内置HtmlAgilityPack组件。
|
||||
|
||||
### 2021-07-29更新
|
||||
------
|
||||
#### MyDbV4 V3.0.2107.2901
|
||||
- *.[新增]新增支持计算文件MD5。
|
||||
|
||||
- *.[新增]部分DataProvider功能移植到DbExtension里,增加扩展性。
|
||||
|
||||
- *.[新增]UnixTimeToDateTime和JSTimeToDateTime新增支持long参数。
|
||||
|
||||
- *.[合并]合并RyWeb项目到MyDb里。
|
||||
- *.[改进]改进ModalResult类的窗体居中算法。
|
||||
|
||||
#### ryControlsV4 V3.0.2107.2901
|
||||
|
||||
|
|
|
|||
Binary file not shown.
BIN
Source/.vs/公用控件组V4/v17/.suo
Normal file
BIN
Source/.vs/公用控件组V4/v17/.suo
Normal file
Binary file not shown.
BIN
Source/.vs/公用控件组V4/v17/fileList.bin
Normal file
BIN
Source/.vs/公用控件组V4/v17/fileList.bin
Normal file
Binary file not shown.
File diff suppressed because it is too large
Load Diff
|
|
@ -4,6 +4,7 @@ using System.Collections.Generic;
|
|||
using System.Drawing;
|
||||
using System.Drawing.Imaging;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
using System.Windows.Forms;
|
||||
|
|
@ -344,6 +345,75 @@ namespace ryCommon
|
|||
return -200;
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// 大文件多次复制文件 true:复制成功 false:复制失败
|
||||
/// </summary>
|
||||
/// <param name="soucrePath">原始文件路径</param>
|
||||
/// <param name="targetPath">复制目标文件路径</param>
|
||||
/// <returns></returns>
|
||||
public static bool CopyBigFile(string soucrePath, string targetPath)
|
||||
{
|
||||
try
|
||||
{
|
||||
//读取复制文件流
|
||||
using (FileStream fsRead = new FileStream(soucrePath, FileMode.Open, FileAccess.Read))
|
||||
{
|
||||
//写入文件复制流
|
||||
using (FileStream fsWrite = new FileStream(targetPath, FileMode.OpenOrCreate, FileAccess.Write))
|
||||
{
|
||||
byte[] buffer = new byte[1024 * 1024 * 2]; //每次读取2M
|
||||
//可能文件比较大,要循环读取,每次读取2M
|
||||
while (true)
|
||||
{
|
||||
//每次读取的数据 n:是每次读取到的实际数据大小
|
||||
int n = fsRead.Read(buffer, 0, buffer.Count());
|
||||
//如果n=0说明读取的数据为空,已经读取到最后了,跳出循环
|
||||
if (n == 0)
|
||||
{
|
||||
break;
|
||||
}
|
||||
//写入每次读取的实际数据大小
|
||||
fsWrite.Write(buffer, 0, n);
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
catch
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// 复制文件夹到目标文件夹
|
||||
/// </summary>
|
||||
/// <param name="fromDir">源文件夹</param>
|
||||
/// <param name="ToDir">目标文件夹</param>
|
||||
/// <returns>返回移动操作是否成功的标识,成功返回0,负数表示复制失败的文件数量。1表示源文件夹不存在</returns>
|
||||
public static int CopyFolder(string fromDir, string ToDir)
|
||||
{
|
||||
var _fromDir = fromDir.TrimEnd('\\');
|
||||
var _ToDir=ToDir.TrimEnd('\\');
|
||||
if (!Directory.Exists(_fromDir)) { return 1; }
|
||||
var files = Directory.GetFiles(fromDir);
|
||||
var error = 0;
|
||||
foreach (var file in files)
|
||||
{
|
||||
if (CopyFile(file, _ToDir + "\\" + Path.GetFileName(file)) != 0)
|
||||
{
|
||||
error++;
|
||||
}
|
||||
}
|
||||
var dirs = Directory.GetDirectories(_fromDir);
|
||||
foreach (var dir in dirs)
|
||||
{
|
||||
if (CopyFolder(dir, _ToDir + "\\" + Path.GetFileName(dir)) > 0)
|
||||
{
|
||||
error++;
|
||||
}
|
||||
}
|
||||
return -error;
|
||||
}
|
||||
#endregion 【复制文件操作】
|
||||
|
||||
#region 【重命名文件】
|
||||
|
|
|
|||
39
Source/MyDb/HtmlAgilityPack.Shared/EncodingFoundException.cs
Normal file
39
Source/MyDb/HtmlAgilityPack.Shared/EncodingFoundException.cs
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
// Description: Html Agility Pack - HTML Parsers, selectors, traversors, manupulators.
|
||||
// Website & Documentation: http://html-agility-pack.net
|
||||
// Forum & Issues: https://github.com/zzzprojects/html-agility-pack
|
||||
// License: https://github.com/zzzprojects/html-agility-pack/blob/master/LICENSE
|
||||
// More projects: http://www.zzzprojects.com/
|
||||
// Copyright © ZZZ Projects Inc. 2014 - 2017. All rights reserved.
|
||||
|
||||
using System;
|
||||
using System.Text;
|
||||
|
||||
namespace HtmlAgilityPack
|
||||
{
|
||||
internal class EncodingFoundException : Exception
|
||||
{
|
||||
#region Fields
|
||||
|
||||
private Encoding _encoding;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constructors
|
||||
|
||||
internal EncodingFoundException(Encoding encoding)
|
||||
{
|
||||
_encoding = encoding;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Properties
|
||||
|
||||
internal Encoding Encoding
|
||||
{
|
||||
get { return _encoding; }
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,61 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup Label="SharedProjectFile_SccProperties">
|
||||
<SharedProjectFile_ProjectGuid>{766aa8be-d147-4e89-a3de-51c383456f20}</SharedProjectFile_ProjectGuid>
|
||||
<SharedProjectFile_SccProjectName>SAK</SharedProjectFile_SccProjectName>
|
||||
<SharedProjectFile_SccAuxPath>SAK</SharedProjectFile_SccAuxPath>
|
||||
<SharedProjectFile_SccLocalPath>SAK</SharedProjectFile_SccLocalPath>
|
||||
<SharedProjectFile_SccProvider>SAK</SharedProjectFile_SccProvider>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup>
|
||||
<MSBuildAllProjects>$(MSBuildAllProjects);$(MSBuildThisFileFullPath)</MSBuildAllProjects>
|
||||
<HasSharedItems>true</HasSharedItems>
|
||||
<SharedGUID>f1d90ca4-d7c4-43ea-852f-fb4ab5f3a600</SharedGUID>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Label="Configuration">
|
||||
<Import_RootNamespace>HtmlAgilityPack.Shared</Import_RootNamespace>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="$(MSBuildThisFileDirectory)crc32.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)EncodingFoundException.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)HtmlAttribute.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)HtmlAttributeCollection.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)HtmlCmdLine.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)HtmlCommentNode.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)HtmlConsoleListener.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)HtmlDocument.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)HtmlDocument.PathMethods.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)HtmlDocument.Xpath.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)HtmlElementFlag.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)HtmlEntity.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)HtmlNameTable.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)HtmlNode.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)HtmlNode.Encapsulator.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)HtmlNode.Xpath.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)HtmlNodeCollection.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)HtmlNodeNavigator.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)HtmlNodeType.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)HtmlParseError.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)HtmlParseErrorCode.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)HtmlTextNode.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)HtmlWeb.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)HtmlWeb.Xpath.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)HtmlWebException.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)InvalidProgramException.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)IOLibrary.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Metro\HtmlWeb.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Metro\InvalidProgramException.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)MimeTypeMap.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)MixedCodeDocument.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)MixedCodeDocumentCodeFragment.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)MixedCodeDocumentFragment.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)MixedCodeDocumentFragmentList.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)MixedCodeDocumentFragmentType.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)MixedCodeDocumentTextFragment.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)NameValuePair.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)NameValuePairList.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Trace.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Trace.FullFramework.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Utilities.cs" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
|
|
@ -0,0 +1,10 @@
|
|||
""
|
||||
{
|
||||
"FILE_VERSION" = "9237"
|
||||
"ENLISTMENT_CHOICE" = "NEVER"
|
||||
"PROJECT_FILE_RELATIVE_PATH" = ""
|
||||
"NUMBER_OF_EXCLUDED_FILES" = "0"
|
||||
"ORIGINAL_PROJECT_FILE_PATH" = ""
|
||||
"NUMBER_OF_NESTED_PROJECTS" = "0"
|
||||
"SOURCE_CONTROL_SETTINGS_PROVIDER" = "PROVIDER"
|
||||
}
|
||||
|
|
@ -0,0 +1,17 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup Label="Globals">
|
||||
<ProjectGuid>{5BA9A0D7-173F-4C4F-AFFA-3DD6DC2F9A79}</ProjectGuid>
|
||||
<MinimumVisualStudioVersion>14.0</MinimumVisualStudioVersion>
|
||||
<SccProjectName>SAK</SccProjectName>
|
||||
<SccProvider>SAK</SccProvider>
|
||||
<SccAuxPath>SAK</SccAuxPath>
|
||||
<SccLocalPath>SAK</SccLocalPath>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
|
||||
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\CodeSharing\Microsoft.CodeSharing.Common.Default.props" />
|
||||
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\CodeSharing\Microsoft.CodeSharing.Common.props" />
|
||||
<PropertyGroup />
|
||||
<Import Project="HtmlAgilityPack.Shared.projitems" Label="Shared" />
|
||||
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\CodeSharing\Microsoft.CodeSharing.CSharp.targets" />
|
||||
</Project>
|
||||
|
|
@ -0,0 +1,10 @@
|
|||
""
|
||||
{
|
||||
"FILE_VERSION" = "9237"
|
||||
"ENLISTMENT_CHOICE" = "NEVER"
|
||||
"PROJECT_FILE_RELATIVE_PATH" = ""
|
||||
"NUMBER_OF_EXCLUDED_FILES" = "0"
|
||||
"ORIGINAL_PROJECT_FILE_PATH" = ""
|
||||
"NUMBER_OF_NESTED_PROJECTS" = "0"
|
||||
"SOURCE_CONTROL_SETTINGS_PROVIDER" = "PROVIDER"
|
||||
}
|
||||
327
Source/MyDb/HtmlAgilityPack.Shared/HtmlAttribute.cs
Normal file
327
Source/MyDb/HtmlAgilityPack.Shared/HtmlAttribute.cs
Normal file
|
|
@ -0,0 +1,327 @@
|
|||
// Description: Html Agility Pack - HTML Parsers, selectors, traversors, manupulators.
|
||||
// Website & Documentation: http://html-agility-pack.net
|
||||
// Forum & Issues: https://github.com/zzzprojects/html-agility-pack
|
||||
// License: https://github.com/zzzprojects/html-agility-pack/blob/master/LICENSE
|
||||
// More projects: http://www.zzzprojects.com/
|
||||
// Copyright ?ZZZ Projects Inc. 2014 - 2017. All rights reserved.
|
||||
|
||||
#region
|
||||
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
|
||||
#endregion
|
||||
|
||||
// ReSharper disable InconsistentNaming
|
||||
|
||||
namespace HtmlAgilityPack
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents an HTML attribute.
|
||||
/// </summary>
|
||||
[DebuggerDisplay("Name: {OriginalName}, Value: {Value}")]
|
||||
public class HtmlAttribute : IComparable
|
||||
{
|
||||
#region Fields
|
||||
|
||||
private int _line;
|
||||
internal int _lineposition;
|
||||
internal string _name;
|
||||
internal int _namelength;
|
||||
internal int _namestartindex;
|
||||
internal HtmlDocument _ownerdocument; // attribute can exists without a node
|
||||
internal HtmlNode _ownernode;
|
||||
private AttributeValueQuote _quoteType = AttributeValueQuote.DoubleQuote;
|
||||
internal int _streamposition;
|
||||
internal string _value;
|
||||
internal int _valuelength;
|
||||
internal int _valuestartindex;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constructors
|
||||
|
||||
internal HtmlAttribute(HtmlDocument ownerdocument)
|
||||
{
|
||||
_ownerdocument = ownerdocument;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Properties
|
||||
|
||||
/// <summary>
|
||||
/// Gets the line number of this attribute in the document.
|
||||
/// </summary>
|
||||
public int Line
|
||||
{
|
||||
get { return _line; }
|
||||
internal set { _line = value; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the column number of this attribute in the document.
|
||||
/// </summary>
|
||||
public int LinePosition
|
||||
{
|
||||
get { return _lineposition; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the stream position of the value of this attribute in the document, relative to the start of the document.
|
||||
/// </summary>
|
||||
public int ValueStartIndex
|
||||
{
|
||||
get { return _valuestartindex; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the length of the value.
|
||||
/// </summary>
|
||||
public int ValueLength
|
||||
{
|
||||
get { return _valuelength; }
|
||||
}
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public bool UseOriginalName { get; set; } = false;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the qualified name of the attribute.
|
||||
/// </summary>
|
||||
public string Name
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_name == null)
|
||||
{
|
||||
_name = _ownerdocument.Text.Substring(_namestartindex, _namelength);
|
||||
}
|
||||
|
||||
return UseOriginalName ? _name : _name.ToLowerInvariant();
|
||||
}
|
||||
set
|
||||
{
|
||||
if (value == null)
|
||||
{
|
||||
throw new ArgumentNullException("value");
|
||||
}
|
||||
|
||||
_name = value;
|
||||
if (_ownernode != null)
|
||||
{
|
||||
_ownernode.SetChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Name of attribute with original case
|
||||
/// </summary>
|
||||
public string OriginalName
|
||||
{
|
||||
get { return _name; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the HTML document to which this attribute belongs.
|
||||
/// </summary>
|
||||
public HtmlDocument OwnerDocument
|
||||
{
|
||||
get { return _ownerdocument; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the HTML node to which this attribute belongs.
|
||||
/// </summary>
|
||||
public HtmlNode OwnerNode
|
||||
{
|
||||
get { return _ownernode; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Specifies what type of quote the data should be wrapped in
|
||||
/// </summary>
|
||||
public AttributeValueQuote QuoteType
|
||||
{
|
||||
get { return _quoteType; }
|
||||
set { _quoteType = value; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Specifies what type of quote the data should be wrapped in (internal to keep backward compatibility)
|
||||
/// </summary>
|
||||
internal AttributeValueQuote InternalQuoteType { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the stream position of this attribute in the document, relative to the start of the document.
|
||||
/// </summary>
|
||||
public int StreamPosition
|
||||
{
|
||||
get { return _streamposition; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the value of the attribute.
|
||||
/// </summary>
|
||||
public string Value
|
||||
{
|
||||
get
|
||||
{
|
||||
// A null value has been provided, the attribute should be considered as "hidden"
|
||||
if (_value == null && _ownerdocument.Text == null && _valuestartindex == 0 && _valuelength == 0)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
if (_value == null)
|
||||
{
|
||||
_value = _ownerdocument.Text.Substring(_valuestartindex, _valuelength);
|
||||
|
||||
if (!_ownerdocument.BackwardCompatibility)
|
||||
{
|
||||
_value = HtmlEntity.DeEntitize(_value);
|
||||
}
|
||||
}
|
||||
|
||||
return _value;
|
||||
}
|
||||
set
|
||||
{
|
||||
_value = value;
|
||||
|
||||
if (_ownernode != null)
|
||||
{
|
||||
_ownernode.SetChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the DeEntitized value of the attribute.
|
||||
/// </summary>
|
||||
public string DeEntitizeValue
|
||||
{
|
||||
get { return HtmlEntity.DeEntitize(Value); }
|
||||
}
|
||||
|
||||
internal string XmlName
|
||||
{
|
||||
get { return HtmlDocument.GetXmlName(Name, true, OwnerDocument.OptionPreserveXmlNamespaces); }
|
||||
}
|
||||
|
||||
internal string XmlValue
|
||||
{
|
||||
get { return Value; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a valid XPath string that points to this Attribute
|
||||
/// </summary>
|
||||
public string XPath
|
||||
{
|
||||
get
|
||||
{
|
||||
string basePath = (OwnerNode == null) ? "/" : OwnerNode.XPath + "/";
|
||||
return basePath + GetRelativeXpath();
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region IComparable Members
|
||||
|
||||
/// <summary>
|
||||
/// Compares the current instance with another attribute. Comparison is based on attributes' name.
|
||||
/// </summary>
|
||||
/// <param name="obj">An attribute to compare with this instance.</param>
|
||||
/// <returns>A 32-bit signed integer that indicates the relative order of the names comparison.</returns>
|
||||
public int CompareTo(object obj)
|
||||
{
|
||||
HtmlAttribute att = obj as HtmlAttribute;
|
||||
if (att == null)
|
||||
{
|
||||
throw new ArgumentException("obj");
|
||||
}
|
||||
|
||||
return Name.CompareTo(att.Name);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Public Methods
|
||||
|
||||
/// <summary>
|
||||
/// Creates a duplicate of this attribute.
|
||||
/// </summary>
|
||||
/// <returns>The cloned attribute.</returns>
|
||||
public HtmlAttribute Clone()
|
||||
{
|
||||
HtmlAttribute att = new HtmlAttribute(_ownerdocument);
|
||||
att.Name = Name;
|
||||
att.Value = Value;
|
||||
att.QuoteType = QuoteType;
|
||||
return att;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Removes this attribute from it's parents collection
|
||||
/// </summary>
|
||||
public void Remove()
|
||||
{
|
||||
_ownernode.Attributes.Remove(this);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Private Methods
|
||||
|
||||
private string GetRelativeXpath()
|
||||
{
|
||||
if (OwnerNode == null)
|
||||
return Name;
|
||||
|
||||
int i = 1;
|
||||
foreach (HtmlAttribute node in OwnerNode.Attributes)
|
||||
{
|
||||
if (node.Name != Name) continue;
|
||||
|
||||
if (node == this)
|
||||
break;
|
||||
|
||||
i++;
|
||||
}
|
||||
|
||||
return "@" + Name + "[" + i + "]";
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// An Enum representing different types of Quotes used for surrounding attribute values
|
||||
/// </summary>
|
||||
public enum AttributeValueQuote
|
||||
{
|
||||
/// <summary>
|
||||
/// A single quote mark '
|
||||
/// </summary>
|
||||
SingleQuote,
|
||||
|
||||
/// <summary>
|
||||
/// A double quote mark "
|
||||
/// </summary>
|
||||
DoubleQuote,
|
||||
|
||||
/// <summary>
|
||||
/// No quote mark
|
||||
/// </summary>
|
||||
None,
|
||||
|
||||
/// <summary>
|
||||
/// The initial value (current value)
|
||||
/// </summary>
|
||||
Initial
|
||||
}
|
||||
}
|
||||
452
Source/MyDb/HtmlAgilityPack.Shared/HtmlAttributeCollection.cs
Normal file
452
Source/MyDb/HtmlAgilityPack.Shared/HtmlAttributeCollection.cs
Normal file
|
|
@ -0,0 +1,452 @@
|
|||
// Description: Html Agility Pack - HTML Parsers, selectors, traversors, manupulators.
|
||||
// Website & Documentation: http://html-agility-pack.net
|
||||
// Forum & Issues: https://github.com/zzzprojects/html-agility-pack
|
||||
// License: https://github.com/zzzprojects/html-agility-pack/blob/master/LICENSE
|
||||
// More projects: http://www.zzzprojects.com/
|
||||
// Copyright © ZZZ Projects Inc. 2014 - 2017. All rights reserved.
|
||||
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace HtmlAgilityPack
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents a combined list and collection of HTML nodes.
|
||||
/// </summary>
|
||||
public class HtmlAttributeCollection : IList<HtmlAttribute>
|
||||
{
|
||||
#region Fields
|
||||
|
||||
internal Dictionary<string, HtmlAttribute> Hashitems = new Dictionary<string, HtmlAttribute>(StringComparer.OrdinalIgnoreCase);
|
||||
private HtmlNode _ownernode;
|
||||
internal List<HtmlAttribute> items = new List<HtmlAttribute>();
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constructors
|
||||
|
||||
internal HtmlAttributeCollection(HtmlNode ownernode)
|
||||
{
|
||||
_ownernode = ownernode;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
#region IList<HtmlAttribute> Members
|
||||
|
||||
/// <summary>
|
||||
/// Gets the number of elements actually contained in the list.
|
||||
/// </summary>
|
||||
public int Count
|
||||
{
|
||||
get { return items.Count; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets readonly status of colelction
|
||||
/// </summary>
|
||||
public bool IsReadOnly
|
||||
{
|
||||
get { return false; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the attribute at the specified index.
|
||||
/// </summary>
|
||||
public HtmlAttribute this[int index]
|
||||
{
|
||||
get { return items[index]; }
|
||||
set
|
||||
{
|
||||
var oldValue = items[index];
|
||||
|
||||
items[index] = value;
|
||||
|
||||
if (oldValue.Name != value.Name)
|
||||
{
|
||||
Hashitems.Remove(oldValue.Name);
|
||||
}
|
||||
Hashitems[value.Name] = value;
|
||||
|
||||
value._ownernode = _ownernode;
|
||||
_ownernode.SetChanged();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Gets a given attribute from the list using its name.
|
||||
/// </summary>
|
||||
public HtmlAttribute this[string name]
|
||||
{
|
||||
get
|
||||
{
|
||||
if (name == null)
|
||||
{
|
||||
throw new ArgumentNullException("name");
|
||||
}
|
||||
|
||||
HtmlAttribute value;
|
||||
return Hashitems.TryGetValue(name, out value) ? value : null;
|
||||
}
|
||||
set
|
||||
{
|
||||
HtmlAttribute currentValue;
|
||||
|
||||
if (!Hashitems.TryGetValue(name, out currentValue))
|
||||
{
|
||||
Append(value);
|
||||
}
|
||||
else
|
||||
{
|
||||
this[items.IndexOf(currentValue)] = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Adds a new attribute to the collection with the given values
|
||||
/// </summary>
|
||||
/// <param name="name"></param>
|
||||
/// <param name="value"></param>
|
||||
public void Add(string name, string value)
|
||||
{
|
||||
Append(name, value);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Adds supplied item to collection
|
||||
/// </summary>
|
||||
/// <param name="item"></param>
|
||||
public void Add(HtmlAttribute item)
|
||||
{
|
||||
Append(item);
|
||||
}
|
||||
|
||||
/// <summary>Adds a range supplied items to collection.</summary>
|
||||
/// <param name="items">An IEnumerable<HtmlAttribute> of items to append to this.</param>
|
||||
public void AddRange(IEnumerable<HtmlAttribute> items)
|
||||
{
|
||||
foreach (var item in items)
|
||||
{
|
||||
Append(item);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>Adds a range supplied items to collection using a dictionary.</summary>
|
||||
/// <param name="items">A Dictionary<string,string> of items to append to this.</param>
|
||||
public void AddRange(Dictionary<string, string> items)
|
||||
{
|
||||
foreach (var item in items)
|
||||
{
|
||||
Add(item.Key, item.Value);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Explicit clear
|
||||
/// </summary>
|
||||
void ICollection<HtmlAttribute>.Clear()
|
||||
{
|
||||
items.Clear();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Retreives existence of supplied item
|
||||
/// </summary>
|
||||
/// <param name="item"></param>
|
||||
/// <returns></returns>
|
||||
public bool Contains(HtmlAttribute item)
|
||||
{
|
||||
return items.Contains(item);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Copies collection to array
|
||||
/// </summary>
|
||||
/// <param name="array"></param>
|
||||
/// <param name="arrayIndex"></param>
|
||||
public void CopyTo(HtmlAttribute[] array, int arrayIndex)
|
||||
{
|
||||
items.CopyTo(array, arrayIndex);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get Explicit enumerator
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
IEnumerator<HtmlAttribute> IEnumerable<HtmlAttribute>.GetEnumerator()
|
||||
{
|
||||
return items.GetEnumerator();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Explicit non-generic enumerator
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
IEnumerator IEnumerable.GetEnumerator()
|
||||
{
|
||||
return items.GetEnumerator();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Retrieves the index for the supplied item, -1 if not found
|
||||
/// </summary>
|
||||
/// <param name="item"></param>
|
||||
/// <returns></returns>
|
||||
public int IndexOf(HtmlAttribute item)
|
||||
{
|
||||
return items.IndexOf(item);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Inserts given item into collection at supplied index
|
||||
/// </summary>
|
||||
/// <param name="index"></param>
|
||||
/// <param name="item"></param>
|
||||
public void Insert(int index, HtmlAttribute item)
|
||||
{
|
||||
if (item == null)
|
||||
{
|
||||
throw new ArgumentNullException("item");
|
||||
}
|
||||
|
||||
Hashitems[item.Name] = item;
|
||||
item._ownernode = _ownernode;
|
||||
items.Insert(index, item);
|
||||
|
||||
_ownernode.SetChanged();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Explicit collection remove
|
||||
/// </summary>
|
||||
/// <param name="item"></param>
|
||||
/// <returns></returns>
|
||||
bool ICollection<HtmlAttribute>.Remove(HtmlAttribute item)
|
||||
{
|
||||
return items.Remove(item);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Removes the attribute at the specified index.
|
||||
/// </summary>
|
||||
/// <param name="index">The index of the attribute to remove.</param>
|
||||
public void RemoveAt(int index)
|
||||
{
|
||||
HtmlAttribute att = items[index];
|
||||
Hashitems.Remove(att.Name);
|
||||
items.RemoveAt(index);
|
||||
|
||||
_ownernode.SetChanged();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Public Methods
|
||||
|
||||
/// <summary>
|
||||
/// Inserts the specified attribute as the last attribute in the collection.
|
||||
/// </summary>
|
||||
/// <param name="newAttribute">The attribute to insert. May not be null.</param>
|
||||
/// <returns>The appended attribute.</returns>
|
||||
public HtmlAttribute Append(HtmlAttribute newAttribute)
|
||||
{
|
||||
if (_ownernode.NodeType == HtmlNodeType.Text || _ownernode.NodeType == HtmlNodeType.Comment)
|
||||
{
|
||||
throw new Exception("A Text or Comment node cannot have attributes.");
|
||||
}
|
||||
|
||||
if (newAttribute == null)
|
||||
{
|
||||
throw new ArgumentNullException("newAttribute");
|
||||
}
|
||||
|
||||
Hashitems[newAttribute.Name] = newAttribute;
|
||||
newAttribute._ownernode = _ownernode;
|
||||
items.Add(newAttribute);
|
||||
|
||||
_ownernode.SetChanged();
|
||||
return newAttribute;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates and inserts a new attribute as the last attribute in the collection.
|
||||
/// </summary>
|
||||
/// <param name="name">The name of the attribute to insert.</param>
|
||||
/// <returns>The appended attribute.</returns>
|
||||
public HtmlAttribute Append(string name)
|
||||
{
|
||||
HtmlAttribute att = _ownernode._ownerdocument.CreateAttribute(name);
|
||||
return Append(att);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates and inserts a new attribute as the last attribute in the collection.
|
||||
/// </summary>
|
||||
/// <param name="name">The name of the attribute to insert.</param>
|
||||
/// <param name="value">The value of the attribute to insert.</param>
|
||||
/// <returns>The appended attribute.</returns>
|
||||
public HtmlAttribute Append(string name, string value)
|
||||
{
|
||||
HtmlAttribute att = _ownernode._ownerdocument.CreateAttribute(name, value);
|
||||
return Append(att);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Checks for existance of attribute with given name
|
||||
/// </summary>
|
||||
/// <param name="name"></param>
|
||||
/// <returns></returns>
|
||||
public bool Contains(string name)
|
||||
{
|
||||
for (int i = 0; i < items.Count; i++)
|
||||
{
|
||||
if (String.Equals(items[i].Name, name, StringComparison.OrdinalIgnoreCase))
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Inserts the specified attribute as the first node in the collection.
|
||||
/// </summary>
|
||||
/// <param name="newAttribute">The attribute to insert. May not be null.</param>
|
||||
/// <returns>The prepended attribute.</returns>
|
||||
public HtmlAttribute Prepend(HtmlAttribute newAttribute)
|
||||
{
|
||||
Insert(0, newAttribute);
|
||||
return newAttribute;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Removes a given attribute from the list.
|
||||
/// </summary>
|
||||
/// <param name="attribute">The attribute to remove. May not be null.</param>
|
||||
public void Remove(HtmlAttribute attribute)
|
||||
{
|
||||
if (attribute == null)
|
||||
{
|
||||
throw new ArgumentNullException("attribute");
|
||||
}
|
||||
|
||||
int index = GetAttributeIndex(attribute);
|
||||
if (index == -1)
|
||||
{
|
||||
throw new IndexOutOfRangeException();
|
||||
}
|
||||
|
||||
RemoveAt(index);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Removes an attribute from the list, using its name. If there are more than one attributes with this name, they will all be removed.
|
||||
/// </summary>
|
||||
/// <param name="name">The attribute's name. May not be null.</param>
|
||||
public void Remove(string name)
|
||||
{
|
||||
if (name == null)
|
||||
{
|
||||
throw new ArgumentNullException("name");
|
||||
}
|
||||
|
||||
for (int i = 0; i < items.Count; i++)
|
||||
{
|
||||
HtmlAttribute att = items[i];
|
||||
if (String.Equals(att.Name, name, StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
RemoveAt(i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Remove all attributes in the list.
|
||||
/// </summary>
|
||||
public void RemoveAll()
|
||||
{
|
||||
Hashitems.Clear();
|
||||
items.Clear();
|
||||
|
||||
_ownernode.SetChanged();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region LINQ Methods
|
||||
|
||||
/// <summary>
|
||||
/// Returns all attributes with specified name. Handles case insentivity
|
||||
/// </summary>
|
||||
/// <param name="attributeName">Name of the attribute</param>
|
||||
/// <returns></returns>
|
||||
public IEnumerable<HtmlAttribute> AttributesWithName(string attributeName)
|
||||
{
|
||||
for (int i = 0; i < items.Count; i++)
|
||||
{
|
||||
if (String.Equals(items[i].Name, attributeName, StringComparison.OrdinalIgnoreCase))
|
||||
yield return items[i];
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Removes all attributes from the collection
|
||||
/// </summary>
|
||||
public void Remove()
|
||||
{
|
||||
items.Clear();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Internal Methods
|
||||
|
||||
/// <summary>
|
||||
/// Clears the attribute collection
|
||||
/// </summary>
|
||||
internal void Clear()
|
||||
{
|
||||
Hashitems.Clear();
|
||||
items.Clear();
|
||||
}
|
||||
|
||||
internal int GetAttributeIndex(HtmlAttribute attribute)
|
||||
{
|
||||
if (attribute == null)
|
||||
{
|
||||
throw new ArgumentNullException("attribute");
|
||||
}
|
||||
|
||||
for (int i = 0; i < items.Count; i++)
|
||||
{
|
||||
if ((items[i]) == attribute)
|
||||
return i;
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
internal int GetAttributeIndex(string name)
|
||||
{
|
||||
if (name == null)
|
||||
{
|
||||
throw new ArgumentNullException("name");
|
||||
}
|
||||
|
||||
for (int i = 0; i < items.Count; i++)
|
||||
{
|
||||
if (String.Equals((items[i]).Name, name, StringComparison.OrdinalIgnoreCase))
|
||||
return i;
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
154
Source/MyDb/HtmlAgilityPack.Shared/HtmlCmdLine.cs
Normal file
154
Source/MyDb/HtmlAgilityPack.Shared/HtmlCmdLine.cs
Normal file
|
|
@ -0,0 +1,154 @@
|
|||
// Description: Html Agility Pack - HTML Parsers, selectors, traversors, manupulators.
|
||||
// Website & Documentation: http://html-agility-pack.net
|
||||
// Forum & Issues: https://github.com/zzzprojects/html-agility-pack
|
||||
// License: https://github.com/zzzprojects/html-agility-pack/blob/master/LICENSE
|
||||
// More projects: http://www.zzzprojects.com/
|
||||
// Copyright © ZZZ Projects Inc. 2014 - 2017. All rights reserved.
|
||||
|
||||
using System;
|
||||
|
||||
#if !NETSTANDARD1_3 && !METRO
|
||||
namespace HtmlAgilityPack
|
||||
{
|
||||
internal class HtmlCmdLine
|
||||
{
|
||||
#region Static Members
|
||||
|
||||
internal static bool Help;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constructors
|
||||
|
||||
static HtmlCmdLine()
|
||||
{
|
||||
Help = false;
|
||||
ParseArgs();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Internal Methods
|
||||
|
||||
internal static string GetOption(string name, string def)
|
||||
{
|
||||
string p = def;
|
||||
string[] args = Environment.GetCommandLineArgs();
|
||||
for (int i = 1; i < args.Length; i++)
|
||||
{
|
||||
GetStringArg(args[i], name, ref p);
|
||||
}
|
||||
|
||||
return p;
|
||||
}
|
||||
|
||||
internal static string GetOption(int index, string def)
|
||||
{
|
||||
string p = def;
|
||||
string[] args = Environment.GetCommandLineArgs();
|
||||
int j = 0;
|
||||
for (int i = 1; i < args.Length; i++)
|
||||
{
|
||||
if (GetStringArg(args[i], ref p))
|
||||
{
|
||||
if (index == j)
|
||||
return p;
|
||||
else
|
||||
p = def;
|
||||
j++;
|
||||
}
|
||||
}
|
||||
|
||||
return p;
|
||||
}
|
||||
|
||||
internal static bool GetOption(string name, bool def)
|
||||
{
|
||||
bool p = def;
|
||||
string[] args = Environment.GetCommandLineArgs();
|
||||
for (int i = 1; i < args.Length; i++)
|
||||
{
|
||||
GetBoolArg(args[i], name, ref p);
|
||||
}
|
||||
|
||||
return p;
|
||||
}
|
||||
|
||||
internal static int GetOption(string name, int def)
|
||||
{
|
||||
int p = def;
|
||||
string[] args = Environment.GetCommandLineArgs();
|
||||
for (int i = 1; i < args.Length; i++)
|
||||
{
|
||||
GetIntArg(args[i], name, ref p);
|
||||
}
|
||||
|
||||
return p;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Private Methods
|
||||
|
||||
private static void GetBoolArg(string Arg, string Name, ref bool ArgValue)
|
||||
{
|
||||
if (Arg.Length < (Name.Length + 1)) // -name is 1 more than name
|
||||
return;
|
||||
if (('/' != Arg[0]) && ('-' != Arg[0])) // not a param
|
||||
return;
|
||||
if (Arg.Substring(1, Name.Length).ToLowerInvariant() == Name.ToLowerInvariant())
|
||||
ArgValue = true;
|
||||
}
|
||||
|
||||
private static void GetIntArg(string Arg, string Name, ref int ArgValue)
|
||||
{
|
||||
if (Arg.Length < (Name.Length + 3)) // -name:12 is 3 more than name
|
||||
return;
|
||||
if (('/' != Arg[0]) && ('-' != Arg[0])) // not a param
|
||||
return;
|
||||
if (Arg.Substring(1, Name.Length).ToLowerInvariant() == Name.ToLowerInvariant())
|
||||
{
|
||||
try
|
||||
{
|
||||
ArgValue = Convert.ToInt32(Arg.Substring(Name.Length + 2, Arg.Length - Name.Length - 2));
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static bool GetStringArg(string Arg, ref string ArgValue)
|
||||
{
|
||||
if (('/' == Arg[0]) || ('-' == Arg[0]))
|
||||
return false;
|
||||
ArgValue = Arg;
|
||||
return true;
|
||||
}
|
||||
|
||||
private static void GetStringArg(string Arg, string Name, ref string ArgValue)
|
||||
{
|
||||
if (Arg.Length < (Name.Length + 3)) // -name:x is 3 more than name
|
||||
return;
|
||||
if (('/' != Arg[0]) && ('-' != Arg[0])) // not a param
|
||||
return;
|
||||
if (Arg.Substring(1, Name.Length).ToLowerInvariant() == Name.ToLowerInvariant())
|
||||
ArgValue = Arg.Substring(Name.Length + 2, Arg.Length - Name.Length - 2);
|
||||
}
|
||||
|
||||
private static void ParseArgs()
|
||||
{
|
||||
string[] args = Environment.GetCommandLineArgs();
|
||||
for (int i = 1; i < args.Length; i++)
|
||||
{
|
||||
// help
|
||||
GetBoolArg(args[i], "?", ref Help);
|
||||
GetBoolArg(args[i], "h", ref Help);
|
||||
GetBoolArg(args[i], "help", ref Help);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
#endif
|
||||
85
Source/MyDb/HtmlAgilityPack.Shared/HtmlCommentNode.cs
Normal file
85
Source/MyDb/HtmlAgilityPack.Shared/HtmlCommentNode.cs
Normal file
|
|
@ -0,0 +1,85 @@
|
|||
// Description: Html Agility Pack - HTML Parsers, selectors, traversors, manupulators.
|
||||
// Website & Documentation: http://html-agility-pack.net
|
||||
// Forum & Issues: https://github.com/zzzprojects/html-agility-pack
|
||||
// License: https://github.com/zzzprojects/html-agility-pack/blob/master/LICENSE
|
||||
// More projects: http://www.zzzprojects.com/
|
||||
// Copyright © ZZZ Projects Inc. 2014 - 2017. All rights reserved.
|
||||
|
||||
namespace HtmlAgilityPack
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents an HTML comment.
|
||||
/// </summary>
|
||||
public class HtmlCommentNode : HtmlNode
|
||||
{
|
||||
#region Fields
|
||||
|
||||
private string _comment;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constructors
|
||||
|
||||
internal HtmlCommentNode(HtmlDocument ownerdocument, int index)
|
||||
:
|
||||
base(HtmlNodeType.Comment, ownerdocument, index)
|
||||
{
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Properties
|
||||
|
||||
/// <summary>
|
||||
/// Gets or Sets the comment text of the node.
|
||||
/// </summary>
|
||||
public string Comment
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_comment == null)
|
||||
{
|
||||
return base.InnerHtml;
|
||||
}
|
||||
|
||||
return _comment;
|
||||
}
|
||||
set { _comment = value; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or Sets the HTML between the start and end tags of the object. In the case of a text node, it is equals to OuterHtml.
|
||||
/// </summary>
|
||||
public override string InnerHtml
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_comment == null)
|
||||
{
|
||||
return base.InnerHtml;
|
||||
}
|
||||
|
||||
return _comment;
|
||||
}
|
||||
set { _comment = value; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or Sets the object and its content in HTML.
|
||||
/// </summary>
|
||||
public override string OuterHtml
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_comment == null)
|
||||
{
|
||||
return base.OuterHtml;
|
||||
}
|
||||
|
||||
return "<!--" + _comment + "-->";
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
41
Source/MyDb/HtmlAgilityPack.Shared/HtmlConsoleListener.cs
Normal file
41
Source/MyDb/HtmlAgilityPack.Shared/HtmlConsoleListener.cs
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
// Description: Html Agility Pack - HTML Parsers, selectors, traversors, manupulators.
|
||||
// Website & Documentation: http://html-agility-pack.net
|
||||
// Forum & Issues: https://github.com/zzzprojects/html-agility-pack
|
||||
// License: https://github.com/zzzprojects/html-agility-pack/blob/master/LICENSE
|
||||
// More projects: http://www.zzzprojects.com/
|
||||
// Copyright © ZZZ Projects Inc. 2014 - 2017. All rights reserved.
|
||||
|
||||
#if !NETSTANDARD1_3 && !NETSTANDARD1_6 && !METRO
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
|
||||
namespace HtmlAgilityPack
|
||||
{
|
||||
internal class HtmlConsoleListener : TraceListener
|
||||
{
|
||||
#region Public Methods
|
||||
|
||||
public override void Write(string Message)
|
||||
{
|
||||
Write(Message, "");
|
||||
}
|
||||
|
||||
public override void Write(string Message, string Category)
|
||||
{
|
||||
Console.Write("T:" + Category + ": " + Message);
|
||||
}
|
||||
|
||||
public override void WriteLine(string Message)
|
||||
{
|
||||
Write(Message + "\n");
|
||||
}
|
||||
|
||||
public override void WriteLine(string Message, string Category)
|
||||
{
|
||||
Write(Message + "\n", Category);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
#endif
|
||||
237
Source/MyDb/HtmlAgilityPack.Shared/HtmlDocument.PathMethods.cs
Normal file
237
Source/MyDb/HtmlAgilityPack.Shared/HtmlDocument.PathMethods.cs
Normal file
|
|
@ -0,0 +1,237 @@
|
|||
// Description: Html Agility Pack - HTML Parsers, selectors, traversors, manupulators.
|
||||
// Website & Documentation: http://html-agility-pack.net
|
||||
// Forum & Issues: https://github.com/zzzprojects/html-agility-pack
|
||||
// License: https://github.com/zzzprojects/html-agility-pack/blob/master/LICENSE
|
||||
// More projects: http://www.zzzprojects.com/
|
||||
// Copyright © ZZZ Projects Inc. 2014 - 2017. All rights reserved.
|
||||
|
||||
#if !METRO
|
||||
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
|
||||
namespace HtmlAgilityPack
|
||||
{
|
||||
public partial class HtmlDocument
|
||||
{
|
||||
/// <summary>
|
||||
/// Detects the encoding of an HTML document from a file first, and then loads the file.
|
||||
/// </summary>
|
||||
/// <param name="path">The complete file path to be read.</param>
|
||||
public void DetectEncodingAndLoad(string path)
|
||||
{
|
||||
DetectEncodingAndLoad(path, true);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Detects the encoding of an HTML document from a file first, and then loads the file.
|
||||
/// </summary>
|
||||
/// <param name="path">The complete file path to be read. May not be null.</param>
|
||||
/// <param name="detectEncoding">true to detect encoding, false otherwise.</param>
|
||||
public void DetectEncodingAndLoad(string path, bool detectEncoding)
|
||||
{
|
||||
if (path == null)
|
||||
{
|
||||
throw new ArgumentNullException("path");
|
||||
}
|
||||
|
||||
Encoding enc;
|
||||
if (detectEncoding)
|
||||
{
|
||||
enc = DetectEncoding(path);
|
||||
}
|
||||
else
|
||||
{
|
||||
enc = null;
|
||||
}
|
||||
|
||||
if (enc == null)
|
||||
{
|
||||
Load(path);
|
||||
}
|
||||
else
|
||||
{
|
||||
Load(path, enc);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Detects the encoding of an HTML file.
|
||||
/// </summary>
|
||||
/// <param name="path">Path for the file containing the HTML document to detect. May not be null.</param>
|
||||
/// <returns>The detected encoding.</returns>
|
||||
public Encoding DetectEncoding(string path)
|
||||
{
|
||||
if (path == null)
|
||||
{
|
||||
throw new ArgumentNullException("path");
|
||||
}
|
||||
|
||||
#if NETSTANDARD1_3 || NETSTANDARD1_6
|
||||
using (StreamReader sr = new StreamReader(File.OpenRead(path), OptionDefaultStreamEncoding))
|
||||
#else
|
||||
using (StreamReader sr = new StreamReader(path, OptionDefaultStreamEncoding))
|
||||
#endif
|
||||
{
|
||||
Encoding encoding = DetectEncoding(sr);
|
||||
return encoding;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Loads an HTML document from a file.
|
||||
/// </summary>
|
||||
/// <param name="path">The complete file path to be read. May not be null.</param>
|
||||
public void Load(string path)
|
||||
{
|
||||
if (path == null)
|
||||
throw new ArgumentNullException("path");
|
||||
|
||||
#if NETSTANDARD1_3 || NETSTANDARD1_6
|
||||
using (StreamReader sr = new StreamReader(File.OpenRead(path), OptionDefaultStreamEncoding))
|
||||
#else
|
||||
using (StreamReader sr = new StreamReader(path, OptionDefaultStreamEncoding))
|
||||
#endif
|
||||
{
|
||||
Load(sr);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Loads an HTML document from a file.
|
||||
/// </summary>
|
||||
/// <param name="path">The complete file path to be read. May not be null.</param>
|
||||
/// <param name="detectEncodingFromByteOrderMarks">Indicates whether to look for byte order marks at the beginning of the file.</param>
|
||||
public void Load(string path, bool detectEncodingFromByteOrderMarks)
|
||||
{
|
||||
if (path == null)
|
||||
throw new ArgumentNullException("path");
|
||||
|
||||
#if NETSTANDARD1_3 || NETSTANDARD1_6
|
||||
using (StreamReader sr = new StreamReader(File.OpenRead(path), detectEncodingFromByteOrderMarks))
|
||||
#else
|
||||
using (StreamReader sr = new StreamReader(path, detectEncodingFromByteOrderMarks))
|
||||
#endif
|
||||
{
|
||||
Load(sr);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Loads an HTML document from a file.
|
||||
/// </summary>
|
||||
/// <param name="path">The complete file path to be read. May not be null.</param>
|
||||
/// <param name="encoding">The character encoding to use. May not be null.</param>
|
||||
public void Load(string path, Encoding encoding)
|
||||
{
|
||||
if (path == null)
|
||||
throw new ArgumentNullException("path");
|
||||
|
||||
if (encoding == null)
|
||||
throw new ArgumentNullException("encoding");
|
||||
|
||||
#if NETSTANDARD1_3 || NETSTANDARD1_6
|
||||
using (StreamReader sr = new StreamReader(File.OpenRead(path), encoding))
|
||||
#else
|
||||
using (StreamReader sr = new StreamReader(path, encoding))
|
||||
#endif
|
||||
{
|
||||
Load(sr);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Loads an HTML document from a file.
|
||||
/// </summary>
|
||||
/// <param name="path">The complete file path to be read. May not be null.</param>
|
||||
/// <param name="encoding">The character encoding to use. May not be null.</param>
|
||||
/// <param name="detectEncodingFromByteOrderMarks">Indicates whether to look for byte order marks at the beginning of the file.</param>
|
||||
public void Load(string path, Encoding encoding, bool detectEncodingFromByteOrderMarks)
|
||||
{
|
||||
if (path == null)
|
||||
throw new ArgumentNullException("path");
|
||||
|
||||
if (encoding == null)
|
||||
throw new ArgumentNullException("encoding");
|
||||
|
||||
#if NETSTANDARD1_3 || NETSTANDARD1_6
|
||||
using (StreamReader sr = new StreamReader(File.OpenRead(path), encoding, detectEncodingFromByteOrderMarks))
|
||||
#else
|
||||
using (StreamReader sr = new StreamReader(path, encoding, detectEncodingFromByteOrderMarks))
|
||||
#endif
|
||||
{
|
||||
Load(sr);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Loads an HTML document from a file.
|
||||
/// </summary>
|
||||
/// <param name="path">The complete file path to be read. May not be null.</param>
|
||||
/// <param name="encoding">The character encoding to use. May not be null.</param>
|
||||
/// <param name="detectEncodingFromByteOrderMarks">Indicates whether to look for byte order marks at the beginning of the file.</param>
|
||||
/// <param name="buffersize">The minimum buffer size.</param>
|
||||
public void Load(string path, Encoding encoding, bool detectEncodingFromByteOrderMarks, int buffersize)
|
||||
{
|
||||
if (path == null)
|
||||
throw new ArgumentNullException("path");
|
||||
|
||||
if (encoding == null)
|
||||
throw new ArgumentNullException("encoding");
|
||||
|
||||
#if NETSTANDARD1_3 || NETSTANDARD1_6
|
||||
using (StreamReader sr = new StreamReader(File.OpenRead(path), encoding, detectEncodingFromByteOrderMarks, buffersize))
|
||||
|
||||
#else
|
||||
using (StreamReader sr = new StreamReader(path, encoding, detectEncodingFromByteOrderMarks, buffersize))
|
||||
#endif
|
||||
{
|
||||
Load(sr);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Saves the mixed document to the specified file.
|
||||
/// </summary>
|
||||
/// <param name="filename">The location of the file where you want to save the document.</param>
|
||||
public void Save(string filename)
|
||||
{
|
||||
#if NETSTANDARD1_3 || NETSTANDARD1_6
|
||||
using (StreamWriter sw = new StreamWriter(File.OpenWrite(filename), GetOutEncoding()))
|
||||
#else
|
||||
using (StreamWriter sw = new StreamWriter(filename, false, GetOutEncoding()))
|
||||
#endif
|
||||
{
|
||||
Save(sw);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Saves the mixed document to the specified file.
|
||||
/// </summary>
|
||||
/// <param name="filename">The location of the file where you want to save the document. May not be null.</param>
|
||||
/// <param name="encoding">The character encoding to use. May not be null.</param>
|
||||
public void Save(string filename, Encoding encoding)
|
||||
{
|
||||
if (filename == null)
|
||||
{
|
||||
throw new ArgumentNullException("filename");
|
||||
}
|
||||
|
||||
if (encoding == null)
|
||||
{
|
||||
throw new ArgumentNullException("encoding");
|
||||
}
|
||||
#if NETSTANDARD1_3 || NETSTANDARD1_6
|
||||
using (StreamWriter sw = new StreamWriter(File.OpenWrite(filename), encoding))
|
||||
#else
|
||||
using (StreamWriter sw = new StreamWriter(filename, false, encoding))
|
||||
#endif
|
||||
{
|
||||
Save(sw);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
27
Source/MyDb/HtmlAgilityPack.Shared/HtmlDocument.Xpath.cs
Normal file
27
Source/MyDb/HtmlAgilityPack.Shared/HtmlDocument.Xpath.cs
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
// Description: Html Agility Pack - HTML Parsers, selectors, traversors, manupulators.
|
||||
// Website & Documentation: http://html-agility-pack.net
|
||||
// Forum & Issues: https://github.com/zzzprojects/html-agility-pack
|
||||
// License: https://github.com/zzzprojects/html-agility-pack/blob/master/LICENSE
|
||||
// More projects: http://www.zzzprojects.com/
|
||||
// Copyright © ZZZ Projects Inc. 2014 - 2017. All rights reserved.
|
||||
|
||||
#if !METRO
|
||||
|
||||
using System.Xml.XPath;
|
||||
|
||||
namespace HtmlAgilityPack
|
||||
{
|
||||
public partial class HtmlDocument : IXPathNavigable
|
||||
{
|
||||
/// <summary>
|
||||
/// Creates a new XPathNavigator object for navigating this HTML document.
|
||||
/// </summary>
|
||||
/// <returns>An XPathNavigator object. The XPathNavigator is positioned on the root of the document.</returns>
|
||||
public XPathNavigator CreateNavigator()
|
||||
{
|
||||
return new HtmlNodeNavigator(this, _documentnode);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
2220
Source/MyDb/HtmlAgilityPack.Shared/HtmlDocument.cs
Normal file
2220
Source/MyDb/HtmlAgilityPack.Shared/HtmlDocument.cs
Normal file
File diff suppressed because it is too large
Load Diff
38
Source/MyDb/HtmlAgilityPack.Shared/HtmlElementFlag.cs
Normal file
38
Source/MyDb/HtmlAgilityPack.Shared/HtmlElementFlag.cs
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
// Description: Html Agility Pack - HTML Parsers, selectors, traversors, manupulators.
|
||||
// Website & Documentation: http://html-agility-pack.net
|
||||
// Forum & Issues: https://github.com/zzzprojects/html-agility-pack
|
||||
// License: https://github.com/zzzprojects/html-agility-pack/blob/master/LICENSE
|
||||
// More projects: http://www.zzzprojects.com/
|
||||
// Copyright © ZZZ Projects Inc. 2014 - 2017. All rights reserved.
|
||||
|
||||
using System;
|
||||
|
||||
namespace HtmlAgilityPack
|
||||
{
|
||||
/// <summary>
|
||||
/// Flags that describe the behavior of an Element node.
|
||||
/// </summary>
|
||||
[Flags]
|
||||
public enum HtmlElementFlag
|
||||
{
|
||||
/// <summary>
|
||||
/// The node is a CDATA node.
|
||||
/// </summary>
|
||||
CData = 1,
|
||||
|
||||
/// <summary>
|
||||
/// The node is empty. META or IMG are example of such nodes.
|
||||
/// </summary>
|
||||
Empty = 2,
|
||||
|
||||
/// <summary>
|
||||
/// The node will automatically be closed during parsing.
|
||||
/// </summary>
|
||||
Closed = 4,
|
||||
|
||||
/// <summary>
|
||||
/// The node can overlap.
|
||||
/// </summary>
|
||||
CanOverlap = 8
|
||||
}
|
||||
}
|
||||
890
Source/MyDb/HtmlAgilityPack.Shared/HtmlEntity.cs
Normal file
890
Source/MyDb/HtmlAgilityPack.Shared/HtmlEntity.cs
Normal file
|
|
@ -0,0 +1,890 @@
|
|||
// Description: Html Agility Pack - HTML Parsers, selectors, traversors, manupulators.
|
||||
// Website & Documentation: http://html-agility-pack.net
|
||||
// Forum & Issues: https://github.com/zzzprojects/html-agility-pack
|
||||
// License: https://github.com/zzzprojects/html-agility-pack/blob/master/LICENSE
|
||||
// More projects: http://www.zzzprojects.com/
|
||||
// Copyright ?ZZZ Projects Inc. 2014 - 2017. All rights reserved.
|
||||
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.Text;
|
||||
|
||||
namespace HtmlAgilityPack
|
||||
{
|
||||
/// <summary>
|
||||
/// A utility class to replace special characters by entities and vice-versa.
|
||||
/// Follows HTML 4.0 specification found at http://www.w3.org/TR/html4/sgml/entities.html
|
||||
/// Follows Additional specification found at https://en.wikipedia.org/wiki/List_of_XML_and_HTML_character_entity_references
|
||||
/// See also: https://html.spec.whatwg.org/multipage/named-characters.html#named-character-references
|
||||
/// </summary>
|
||||
public class HtmlEntity
|
||||
{
|
||||
#region Static Members
|
||||
|
||||
#if !FX20 && !FX35
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public static bool UseWebUtility { get; set; }
|
||||
#endif
|
||||
|
||||
private static readonly int _maxEntitySize;
|
||||
private static Dictionary<int, string> _entityName;
|
||||
private static Dictionary<string, int> _entityValue;
|
||||
|
||||
/// <summary>
|
||||
/// A collection of entities indexed by name.
|
||||
/// </summary>
|
||||
public static Dictionary<int, string> EntityName
|
||||
{
|
||||
get { return _entityName; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A collection of entities indexed by value.
|
||||
/// </summary>
|
||||
public static Dictionary<string, int> EntityValue
|
||||
{
|
||||
get { return _entityValue; }
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constructors
|
||||
|
||||
static HtmlEntity()
|
||||
{
|
||||
_entityName = new Dictionary<int, string>();
|
||||
_entityValue = new Dictionary<string, int>();
|
||||
|
||||
#region Entities Definition
|
||||
|
||||
_entityValue.Add("quot", 34); // quotation mark = APL quote, U+0022 ISOnum
|
||||
_entityName.Add(34, "quot");
|
||||
_entityValue.Add("amp", 38); // ampersand, U+0026 ISOnum
|
||||
_entityName.Add(38, "amp");
|
||||
_entityValue.Add("apos", 39); // apostrophe-quote U+0027 (39)
|
||||
_entityName.Add(39, "apos");
|
||||
_entityValue.Add("lt", 60); // less-than sign, U+003C ISOnum
|
||||
_entityName.Add(60, "lt");
|
||||
_entityValue.Add("gt", 62); // greater-than sign, U+003E ISOnum
|
||||
_entityName.Add(62, "gt");
|
||||
_entityValue.Add("nbsp", 160); // no-break space = non-breaking space, U+00A0 ISOnum
|
||||
_entityName.Add(160, "nbsp");
|
||||
_entityValue.Add("iexcl", 161); // inverted exclamation mark, U+00A1 ISOnum
|
||||
_entityName.Add(161, "iexcl");
|
||||
_entityValue.Add("cent", 162); // cent sign, U+00A2 ISOnum
|
||||
_entityName.Add(162, "cent");
|
||||
_entityValue.Add("pound", 163); // pound sign, U+00A3 ISOnum
|
||||
_entityName.Add(163, "pound");
|
||||
_entityValue.Add("curren", 164); // currency sign, U+00A4 ISOnum
|
||||
_entityName.Add(164, "curren");
|
||||
_entityValue.Add("yen", 165); // yen sign = yuan sign, U+00A5 ISOnum
|
||||
_entityName.Add(165, "yen");
|
||||
_entityValue.Add("brvbar", 166); // broken bar = broken vertical bar, U+00A6 ISOnum
|
||||
_entityName.Add(166, "brvbar");
|
||||
_entityValue.Add("sect", 167); // section sign, U+00A7 ISOnum
|
||||
_entityName.Add(167, "sect");
|
||||
_entityValue.Add("uml", 168); // diaeresis = spacing diaeresis, U+00A8 ISOdia
|
||||
_entityName.Add(168, "uml");
|
||||
_entityValue.Add("copy", 169); // copyright sign, U+00A9 ISOnum
|
||||
_entityName.Add(169, "copy");
|
||||
_entityValue.Add("ordf", 170); // feminine ordinal indicator, U+00AA ISOnum
|
||||
_entityName.Add(170, "ordf");
|
||||
_entityValue.Add("laquo", 171);
|
||||
// left-pointing double angle quotation mark = left pointing guillemet, U+00AB ISOnum
|
||||
_entityName.Add(171, "laquo");
|
||||
_entityValue.Add("not", 172); // not sign, U+00AC ISOnum
|
||||
_entityName.Add(172, "not");
|
||||
_entityValue.Add("shy", 173); // soft hyphen = discretionary hyphen, U+00AD ISOnum
|
||||
_entityName.Add(173, "shy");
|
||||
_entityValue.Add("reg", 174); // registered sign = registered trade mark sign, U+00AE ISOnum
|
||||
_entityName.Add(174, "reg");
|
||||
_entityValue.Add("macr", 175); // macron = spacing macron = overline = APL overbar, U+00AF ISOdia
|
||||
_entityName.Add(175, "macr");
|
||||
_entityValue.Add("deg", 176); // degree sign, U+00B0 ISOnum
|
||||
_entityName.Add(176, "deg");
|
||||
_entityValue.Add("plusmn", 177); // plus-minus sign = plus-or-minus sign, U+00B1 ISOnum
|
||||
_entityName.Add(177, "plusmn");
|
||||
_entityValue.Add("sup2", 178); // superscript two = superscript digit two = squared, U+00B2 ISOnum
|
||||
_entityName.Add(178, "sup2");
|
||||
_entityValue.Add("sup3", 179); // superscript three = superscript digit three = cubed, U+00B3 ISOnum
|
||||
_entityName.Add(179, "sup3");
|
||||
_entityValue.Add("acute", 180); // acute accent = spacing acute, U+00B4 ISOdia
|
||||
_entityName.Add(180, "acute");
|
||||
_entityValue.Add("micro", 181); // micro sign, U+00B5 ISOnum
|
||||
_entityName.Add(181, "micro");
|
||||
_entityValue.Add("para", 182); // pilcrow sign = paragraph sign, U+00B6 ISOnum
|
||||
_entityName.Add(182, "para");
|
||||
_entityValue.Add("middot", 183); // middle dot = Georgian comma = Greek middle dot, U+00B7 ISOnum
|
||||
_entityName.Add(183, "middot");
|
||||
_entityValue.Add("cedil", 184); // cedilla = spacing cedilla, U+00B8 ISOdia
|
||||
_entityName.Add(184, "cedil");
|
||||
_entityValue.Add("sup1", 185); // superscript one = superscript digit one, U+00B9 ISOnum
|
||||
_entityName.Add(185, "sup1");
|
||||
_entityValue.Add("ordm", 186); // masculine ordinal indicator, U+00BA ISOnum
|
||||
_entityName.Add(186, "ordm");
|
||||
_entityValue.Add("raquo", 187);
|
||||
// right-pointing double angle quotation mark = right pointing guillemet, U+00BB ISOnum
|
||||
_entityName.Add(187, "raquo");
|
||||
_entityValue.Add("frac14", 188); // vulgar fraction one quarter = fraction one quarter, U+00BC ISOnum
|
||||
_entityName.Add(188, "frac14");
|
||||
_entityValue.Add("frac12", 189); // vulgar fraction one half = fraction one half, U+00BD ISOnum
|
||||
_entityName.Add(189, "frac12");
|
||||
_entityValue.Add("frac34", 190); // vulgar fraction three quarters = fraction three quarters, U+00BE ISOnum
|
||||
_entityName.Add(190, "frac34");
|
||||
_entityValue.Add("iquest", 191); // inverted question mark = turned question mark, U+00BF ISOnum
|
||||
_entityName.Add(191, "iquest");
|
||||
_entityValue.Add("Agrave", 192);
|
||||
// latin capital letter A with grave = latin capital letter A grave, U+00C0 ISOlat1
|
||||
_entityName.Add(192, "Agrave");
|
||||
_entityValue.Add("Aacute", 193); // latin capital letter A with acute, U+00C1 ISOlat1
|
||||
_entityName.Add(193, "Aacute");
|
||||
_entityValue.Add("Acirc", 194); // latin capital letter A with circumflex, U+00C2 ISOlat1
|
||||
_entityName.Add(194, "Acirc");
|
||||
_entityValue.Add("Atilde", 195); // latin capital letter A with tilde, U+00C3 ISOlat1
|
||||
_entityName.Add(195, "Atilde");
|
||||
_entityValue.Add("Auml", 196); // latin capital letter A with diaeresis, U+00C4 ISOlat1
|
||||
_entityName.Add(196, "Auml");
|
||||
_entityValue.Add("Aring", 197);
|
||||
// latin capital letter A with ring above = latin capital letter A ring, U+00C5 ISOlat1
|
||||
_entityName.Add(197, "Aring");
|
||||
_entityValue.Add("AElig", 198); // latin capital letter AE = latin capital ligature AE, U+00C6 ISOlat1
|
||||
_entityName.Add(198, "AElig");
|
||||
_entityValue.Add("Ccedil", 199); // latin capital letter C with cedilla, U+00C7 ISOlat1
|
||||
_entityName.Add(199, "Ccedil");
|
||||
_entityValue.Add("Egrave", 200); // latin capital letter E with grave, U+00C8 ISOlat1
|
||||
_entityName.Add(200, "Egrave");
|
||||
_entityValue.Add("Eacute", 201); // latin capital letter E with acute, U+00C9 ISOlat1
|
||||
_entityName.Add(201, "Eacute");
|
||||
_entityValue.Add("Ecirc", 202); // latin capital letter E with circumflex, U+00CA ISOlat1
|
||||
_entityName.Add(202, "Ecirc");
|
||||
_entityValue.Add("Euml", 203); // latin capital letter E with diaeresis, U+00CB ISOlat1
|
||||
_entityName.Add(203, "Euml");
|
||||
_entityValue.Add("Igrave", 204); // latin capital letter I with grave, U+00CC ISOlat1
|
||||
_entityName.Add(204, "Igrave");
|
||||
_entityValue.Add("Iacute", 205); // latin capital letter I with acute, U+00CD ISOlat1
|
||||
_entityName.Add(205, "Iacute");
|
||||
_entityValue.Add("Icirc", 206); // latin capital letter I with circumflex, U+00CE ISOlat1
|
||||
_entityName.Add(206, "Icirc");
|
||||
_entityValue.Add("Iuml", 207); // latin capital letter I with diaeresis, U+00CF ISOlat1
|
||||
_entityName.Add(207, "Iuml");
|
||||
_entityValue.Add("ETH", 208); // latin capital letter ETH, U+00D0 ISOlat1
|
||||
_entityName.Add(208, "ETH");
|
||||
_entityValue.Add("Ntilde", 209); // latin capital letter N with tilde, U+00D1 ISOlat1
|
||||
_entityName.Add(209, "Ntilde");
|
||||
_entityValue.Add("Ograve", 210); // latin capital letter O with grave, U+00D2 ISOlat1
|
||||
_entityName.Add(210, "Ograve");
|
||||
_entityValue.Add("Oacute", 211); // latin capital letter O with acute, U+00D3 ISOlat1
|
||||
_entityName.Add(211, "Oacute");
|
||||
_entityValue.Add("Ocirc", 212); // latin capital letter O with circumflex, U+00D4 ISOlat1
|
||||
_entityName.Add(212, "Ocirc");
|
||||
_entityValue.Add("Otilde", 213); // latin capital letter O with tilde, U+00D5 ISOlat1
|
||||
_entityName.Add(213, "Otilde");
|
||||
_entityValue.Add("Ouml", 214); // latin capital letter O with diaeresis, U+00D6 ISOlat1
|
||||
_entityName.Add(214, "Ouml");
|
||||
_entityValue.Add("times", 215); // multiplication sign, U+00D7 ISOnum
|
||||
_entityName.Add(215, "times");
|
||||
_entityValue.Add("Oslash", 216);
|
||||
// latin capital letter O with stroke = latin capital letter O slash, U+00D8 ISOlat1
|
||||
_entityName.Add(216, "Oslash");
|
||||
_entityValue.Add("Ugrave", 217); // latin capital letter U with grave, U+00D9 ISOlat1
|
||||
_entityName.Add(217, "Ugrave");
|
||||
_entityValue.Add("Uacute", 218); // latin capital letter U with acute, U+00DA ISOlat1
|
||||
_entityName.Add(218, "Uacute");
|
||||
_entityValue.Add("Ucirc", 219); // latin capital letter U with circumflex, U+00DB ISOlat1
|
||||
_entityName.Add(219, "Ucirc");
|
||||
_entityValue.Add("Uuml", 220); // latin capital letter U with diaeresis, U+00DC ISOlat1
|
||||
_entityName.Add(220, "Uuml");
|
||||
_entityValue.Add("Yacute", 221); // latin capital letter Y with acute, U+00DD ISOlat1
|
||||
_entityName.Add(221, "Yacute");
|
||||
_entityValue.Add("THORN", 222); // latin capital letter THORN, U+00DE ISOlat1
|
||||
_entityName.Add(222, "THORN");
|
||||
_entityValue.Add("szlig", 223); // latin small letter sharp s = ess-zed, U+00DF ISOlat1
|
||||
_entityName.Add(223, "szlig");
|
||||
_entityValue.Add("agrave", 224);
|
||||
// latin small letter a with grave = latin small letter a grave, U+00E0 ISOlat1
|
||||
_entityName.Add(224, "agrave");
|
||||
_entityValue.Add("aacute", 225); // latin small letter a with acute, U+00E1 ISOlat1
|
||||
_entityName.Add(225, "aacute");
|
||||
_entityValue.Add("acirc", 226); // latin small letter a with circumflex, U+00E2 ISOlat1
|
||||
_entityName.Add(226, "acirc");
|
||||
_entityValue.Add("atilde", 227); // latin small letter a with tilde, U+00E3 ISOlat1
|
||||
_entityName.Add(227, "atilde");
|
||||
_entityValue.Add("auml", 228); // latin small letter a with diaeresis, U+00E4 ISOlat1
|
||||
_entityName.Add(228, "auml");
|
||||
_entityValue.Add("aring", 229);
|
||||
// latin small letter a with ring above = latin small letter a ring, U+00E5 ISOlat1
|
||||
_entityName.Add(229, "aring");
|
||||
_entityValue.Add("aelig", 230); // latin small letter ae = latin small ligature ae, U+00E6 ISOlat1
|
||||
_entityName.Add(230, "aelig");
|
||||
_entityValue.Add("ccedil", 231); // latin small letter c with cedilla, U+00E7 ISOlat1
|
||||
_entityName.Add(231, "ccedil");
|
||||
_entityValue.Add("egrave", 232); // latin small letter e with grave, U+00E8 ISOlat1
|
||||
_entityName.Add(232, "egrave");
|
||||
_entityValue.Add("eacute", 233); // latin small letter e with acute, U+00E9 ISOlat1
|
||||
_entityName.Add(233, "eacute");
|
||||
_entityValue.Add("ecirc", 234); // latin small letter e with circumflex, U+00EA ISOlat1
|
||||
_entityName.Add(234, "ecirc");
|
||||
_entityValue.Add("euml", 235); // latin small letter e with diaeresis, U+00EB ISOlat1
|
||||
_entityName.Add(235, "euml");
|
||||
_entityValue.Add("igrave", 236); // latin small letter i with grave, U+00EC ISOlat1
|
||||
_entityName.Add(236, "igrave");
|
||||
_entityValue.Add("iacute", 237); // latin small letter i with acute, U+00ED ISOlat1
|
||||
_entityName.Add(237, "iacute");
|
||||
_entityValue.Add("icirc", 238); // latin small letter i with circumflex, U+00EE ISOlat1
|
||||
_entityName.Add(238, "icirc");
|
||||
_entityValue.Add("iuml", 239); // latin small letter i with diaeresis, U+00EF ISOlat1
|
||||
_entityName.Add(239, "iuml");
|
||||
_entityValue.Add("eth", 240); // latin small letter eth, U+00F0 ISOlat1
|
||||
_entityName.Add(240, "eth");
|
||||
_entityValue.Add("ntilde", 241); // latin small letter n with tilde, U+00F1 ISOlat1
|
||||
_entityName.Add(241, "ntilde");
|
||||
_entityValue.Add("ograve", 242); // latin small letter o with grave, U+00F2 ISOlat1
|
||||
_entityName.Add(242, "ograve");
|
||||
_entityValue.Add("oacute", 243); // latin small letter o with acute, U+00F3 ISOlat1
|
||||
_entityName.Add(243, "oacute");
|
||||
_entityValue.Add("ocirc", 244); // latin small letter o with circumflex, U+00F4 ISOlat1
|
||||
_entityName.Add(244, "ocirc");
|
||||
_entityValue.Add("otilde", 245); // latin small letter o with tilde, U+00F5 ISOlat1
|
||||
_entityName.Add(245, "otilde");
|
||||
_entityValue.Add("ouml", 246); // latin small letter o with diaeresis, U+00F6 ISOlat1
|
||||
_entityName.Add(246, "ouml");
|
||||
_entityValue.Add("divide", 247); // division sign, U+00F7 ISOnum
|
||||
_entityName.Add(247, "divide");
|
||||
_entityValue.Add("oslash", 248);
|
||||
// latin small letter o with stroke, = latin small letter o slash, U+00F8 ISOlat1
|
||||
_entityName.Add(248, "oslash");
|
||||
_entityValue.Add("ugrave", 249); // latin small letter u with grave, U+00F9 ISOlat1
|
||||
_entityName.Add(249, "ugrave");
|
||||
_entityValue.Add("uacute", 250); // latin small letter u with acute, U+00FA ISOlat1
|
||||
_entityName.Add(250, "uacute");
|
||||
_entityValue.Add("ucirc", 251); // latin small letter u with circumflex, U+00FB ISOlat1
|
||||
_entityName.Add(251, "ucirc");
|
||||
_entityValue.Add("uuml", 252); // latin small letter u with diaeresis, U+00FC ISOlat1
|
||||
_entityName.Add(252, "uuml");
|
||||
_entityValue.Add("yacute", 253); // latin small letter y with acute, U+00FD ISOlat1
|
||||
_entityName.Add(253, "yacute");
|
||||
_entityValue.Add("thorn", 254); // latin small letter thorn, U+00FE ISOlat1
|
||||
_entityName.Add(254, "thorn");
|
||||
_entityValue.Add("yuml", 255); // latin small letter y with diaeresis, U+00FF ISOlat1
|
||||
_entityName.Add(255, "yuml");
|
||||
_entityValue.Add("fnof", 402); // latin small f with hook = function = florin, U+0192 ISOtech
|
||||
_entityName.Add(402, "fnof");
|
||||
_entityValue.Add("Alpha", 913); // greek capital letter alpha, U+0391
|
||||
_entityName.Add(913, "Alpha");
|
||||
_entityValue.Add("Beta", 914); // greek capital letter beta, U+0392
|
||||
_entityName.Add(914, "Beta");
|
||||
_entityValue.Add("Gamma", 915); // greek capital letter gamma, U+0393 ISOgrk3
|
||||
_entityName.Add(915, "Gamma");
|
||||
_entityValue.Add("Delta", 916); // greek capital letter delta, U+0394 ISOgrk3
|
||||
_entityName.Add(916, "Delta");
|
||||
_entityValue.Add("Epsilon", 917); // greek capital letter epsilon, U+0395
|
||||
_entityName.Add(917, "Epsilon");
|
||||
_entityValue.Add("Zeta", 918); // greek capital letter zeta, U+0396
|
||||
_entityName.Add(918, "Zeta");
|
||||
_entityValue.Add("Eta", 919); // greek capital letter eta, U+0397
|
||||
_entityName.Add(919, "Eta");
|
||||
_entityValue.Add("Theta", 920); // greek capital letter theta, U+0398 ISOgrk3
|
||||
_entityName.Add(920, "Theta");
|
||||
_entityValue.Add("Iota", 921); // greek capital letter iota, U+0399
|
||||
_entityName.Add(921, "Iota");
|
||||
_entityValue.Add("Kappa", 922); // greek capital letter kappa, U+039A
|
||||
_entityName.Add(922, "Kappa");
|
||||
_entityValue.Add("Lambda", 923); // greek capital letter lambda, U+039B ISOgrk3
|
||||
_entityName.Add(923, "Lambda");
|
||||
_entityValue.Add("Mu", 924); // greek capital letter mu, U+039C
|
||||
_entityName.Add(924, "Mu");
|
||||
_entityValue.Add("Nu", 925); // greek capital letter nu, U+039D
|
||||
_entityName.Add(925, "Nu");
|
||||
_entityValue.Add("Xi", 926); // greek capital letter xi, U+039E ISOgrk3
|
||||
_entityName.Add(926, "Xi");
|
||||
_entityValue.Add("Omicron", 927); // greek capital letter omicron, U+039F
|
||||
_entityName.Add(927, "Omicron");
|
||||
_entityValue.Add("Pi", 928); // greek capital letter pi, U+03A0 ISOgrk3
|
||||
_entityName.Add(928, "Pi");
|
||||
_entityValue.Add("Rho", 929); // greek capital letter rho, U+03A1
|
||||
_entityName.Add(929, "Rho");
|
||||
_entityValue.Add("Sigma", 931); // greek capital letter sigma, U+03A3 ISOgrk3
|
||||
_entityName.Add(931, "Sigma");
|
||||
_entityValue.Add("Tau", 932); // greek capital letter tau, U+03A4
|
||||
_entityName.Add(932, "Tau");
|
||||
_entityValue.Add("Upsilon", 933); // greek capital letter upsilon, U+03A5 ISOgrk3
|
||||
_entityName.Add(933, "Upsilon");
|
||||
_entityValue.Add("Phi", 934); // greek capital letter phi, U+03A6 ISOgrk3
|
||||
_entityName.Add(934, "Phi");
|
||||
_entityValue.Add("Chi", 935); // greek capital letter chi, U+03A7
|
||||
_entityName.Add(935, "Chi");
|
||||
_entityValue.Add("Psi", 936); // greek capital letter psi, U+03A8 ISOgrk3
|
||||
_entityName.Add(936, "Psi");
|
||||
_entityValue.Add("Omega", 937); // greek capital letter omega, U+03A9 ISOgrk3
|
||||
_entityName.Add(937, "Omega");
|
||||
_entityValue.Add("alpha", 945); // greek small letter alpha, U+03B1 ISOgrk3
|
||||
_entityName.Add(945, "alpha");
|
||||
_entityValue.Add("beta", 946); // greek small letter beta, U+03B2 ISOgrk3
|
||||
_entityName.Add(946, "beta");
|
||||
_entityValue.Add("gamma", 947); // greek small letter gamma, U+03B3 ISOgrk3
|
||||
_entityName.Add(947, "gamma");
|
||||
_entityValue.Add("delta", 948); // greek small letter delta, U+03B4 ISOgrk3
|
||||
_entityName.Add(948, "delta");
|
||||
_entityValue.Add("epsilon", 949); // greek small letter epsilon, U+03B5 ISOgrk3
|
||||
_entityName.Add(949, "epsilon");
|
||||
_entityValue.Add("zeta", 950); // greek small letter zeta, U+03B6 ISOgrk3
|
||||
_entityName.Add(950, "zeta");
|
||||
_entityValue.Add("eta", 951); // greek small letter eta, U+03B7 ISOgrk3
|
||||
_entityName.Add(951, "eta");
|
||||
_entityValue.Add("theta", 952); // greek small letter theta, U+03B8 ISOgrk3
|
||||
_entityName.Add(952, "theta");
|
||||
_entityValue.Add("iota", 953); // greek small letter iota, U+03B9 ISOgrk3
|
||||
_entityName.Add(953, "iota");
|
||||
_entityValue.Add("kappa", 954); // greek small letter kappa, U+03BA ISOgrk3
|
||||
_entityName.Add(954, "kappa");
|
||||
_entityValue.Add("lambda", 955); // greek small letter lambda, U+03BB ISOgrk3
|
||||
_entityName.Add(955, "lambda");
|
||||
_entityValue.Add("mu", 956); // greek small letter mu, U+03BC ISOgrk3
|
||||
_entityName.Add(956, "mu");
|
||||
_entityValue.Add("nu", 957); // greek small letter nu, U+03BD ISOgrk3
|
||||
_entityName.Add(957, "nu");
|
||||
_entityValue.Add("xi", 958); // greek small letter xi, U+03BE ISOgrk3
|
||||
_entityName.Add(958, "xi");
|
||||
_entityValue.Add("omicron", 959); // greek small letter omicron, U+03BF NEW
|
||||
_entityName.Add(959, "omicron");
|
||||
_entityValue.Add("pi", 960); // greek small letter pi, U+03C0 ISOgrk3
|
||||
_entityName.Add(960, "pi");
|
||||
_entityValue.Add("rho", 961); // greek small letter rho, U+03C1 ISOgrk3
|
||||
_entityName.Add(961, "rho");
|
||||
_entityValue.Add("sigmaf", 962); // greek small letter final sigma, U+03C2 ISOgrk3
|
||||
_entityName.Add(962, "sigmaf");
|
||||
_entityValue.Add("sigma", 963); // greek small letter sigma, U+03C3 ISOgrk3
|
||||
_entityName.Add(963, "sigma");
|
||||
_entityValue.Add("tau", 964); // greek small letter tau, U+03C4 ISOgrk3
|
||||
_entityName.Add(964, "tau");
|
||||
_entityValue.Add("upsilon", 965); // greek small letter upsilon, U+03C5 ISOgrk3
|
||||
_entityName.Add(965, "upsilon");
|
||||
_entityValue.Add("phi", 966); // greek small letter phi, U+03C6 ISOgrk3
|
||||
_entityName.Add(966, "phi");
|
||||
_entityValue.Add("chi", 967); // greek small letter chi, U+03C7 ISOgrk3
|
||||
_entityName.Add(967, "chi");
|
||||
_entityValue.Add("psi", 968); // greek small letter psi, U+03C8 ISOgrk3
|
||||
_entityName.Add(968, "psi");
|
||||
_entityValue.Add("omega", 969); // greek small letter omega, U+03C9 ISOgrk3
|
||||
_entityName.Add(969, "omega");
|
||||
_entityValue.Add("thetasym", 977); // greek small letter theta symbol, U+03D1 NEW
|
||||
_entityName.Add(977, "thetasym");
|
||||
_entityValue.Add("upsih", 978); // greek upsilon with hook symbol, U+03D2 NEW
|
||||
_entityName.Add(978, "upsih");
|
||||
_entityValue.Add("piv", 982); // greek pi symbol, U+03D6 ISOgrk3
|
||||
_entityName.Add(982, "piv");
|
||||
_entityValue.Add("bull", 8226); // bullet = black small circle, U+2022 ISOpub
|
||||
_entityName.Add(8226, "bull");
|
||||
_entityValue.Add("hellip", 8230); // horizontal ellipsis = three dot leader, U+2026 ISOpub
|
||||
_entityName.Add(8230, "hellip");
|
||||
_entityValue.Add("prime", 8242); // prime = minutes = feet, U+2032 ISOtech
|
||||
_entityName.Add(8242, "prime");
|
||||
_entityValue.Add("Prime", 8243); // double prime = seconds = inches, U+2033 ISOtech
|
||||
_entityName.Add(8243, "Prime");
|
||||
_entityValue.Add("oline", 8254); // overline = spacing overscore, U+203E NEW
|
||||
_entityName.Add(8254, "oline");
|
||||
_entityValue.Add("frasl", 8260); // fraction slash, U+2044 NEW
|
||||
_entityName.Add(8260, "frasl");
|
||||
_entityValue.Add("weierp", 8472); // script capital P = power set = Weierstrass p, U+2118 ISOamso
|
||||
_entityName.Add(8472, "weierp");
|
||||
_entityValue.Add("image", 8465); // blackletter capital I = imaginary part, U+2111 ISOamso
|
||||
_entityName.Add(8465, "image");
|
||||
_entityValue.Add("real", 8476); // blackletter capital R = real part symbol, U+211C ISOamso
|
||||
_entityName.Add(8476, "real");
|
||||
_entityValue.Add("trade", 8482); // trade mark sign, U+2122 ISOnum
|
||||
_entityName.Add(8482, "trade");
|
||||
_entityValue.Add("alefsym", 8501); // alef symbol = first transfinite cardinal, U+2135 NEW
|
||||
_entityName.Add(8501, "alefsym");
|
||||
_entityValue.Add("larr", 8592); // leftwards arrow, U+2190 ISOnum
|
||||
_entityName.Add(8592, "larr");
|
||||
_entityValue.Add("uarr", 8593); // upwards arrow, U+2191 ISOnum
|
||||
_entityName.Add(8593, "uarr");
|
||||
_entityValue.Add("rarr", 8594); // rightwards arrow, U+2192 ISOnum
|
||||
_entityName.Add(8594, "rarr");
|
||||
_entityValue.Add("darr", 8595); // downwards arrow, U+2193 ISOnum
|
||||
_entityName.Add(8595, "darr");
|
||||
_entityValue.Add("harr", 8596); // left right arrow, U+2194 ISOamsa
|
||||
_entityName.Add(8596, "harr");
|
||||
_entityValue.Add("crarr", 8629); // downwards arrow with corner leftwards = carriage return, U+21B5 NEW
|
||||
_entityName.Add(8629, "crarr");
|
||||
_entityValue.Add("lArr", 8656); // leftwards double arrow, U+21D0 ISOtech
|
||||
_entityName.Add(8656, "lArr");
|
||||
_entityValue.Add("uArr", 8657); // upwards double arrow, U+21D1 ISOamsa
|
||||
_entityName.Add(8657, "uArr");
|
||||
_entityValue.Add("rArr", 8658); // rightwards double arrow, U+21D2 ISOtech
|
||||
_entityName.Add(8658, "rArr");
|
||||
_entityValue.Add("dArr", 8659); // downwards double arrow, U+21D3 ISOamsa
|
||||
_entityName.Add(8659, "dArr");
|
||||
_entityValue.Add("hArr", 8660); // left right double arrow, U+21D4 ISOamsa
|
||||
_entityName.Add(8660, "hArr");
|
||||
_entityValue.Add("forall", 8704); // for all, U+2200 ISOtech
|
||||
_entityName.Add(8704, "forall");
|
||||
_entityValue.Add("part", 8706); // partial differential, U+2202 ISOtech
|
||||
_entityName.Add(8706, "part");
|
||||
_entityValue.Add("exist", 8707); // there exists, U+2203 ISOtech
|
||||
_entityName.Add(8707, "exist");
|
||||
_entityValue.Add("empty", 8709); // empty set = null set = diameter, U+2205 ISOamso
|
||||
_entityName.Add(8709, "empty");
|
||||
_entityValue.Add("nabla", 8711); // nabla = backward difference, U+2207 ISOtech
|
||||
_entityName.Add(8711, "nabla");
|
||||
_entityValue.Add("isin", 8712); // element of, U+2208 ISOtech
|
||||
_entityName.Add(8712, "isin");
|
||||
_entityValue.Add("notin", 8713); // not an element of, U+2209 ISOtech
|
||||
_entityName.Add(8713, "notin");
|
||||
_entityValue.Add("ni", 8715); // contains as member, U+220B ISOtech
|
||||
_entityName.Add(8715, "ni");
|
||||
_entityValue.Add("prod", 8719); // n-ary product = product sign, U+220F ISOamsb
|
||||
_entityName.Add(8719, "prod");
|
||||
_entityValue.Add("sum", 8721); // n-ary sumation, U+2211 ISOamsb
|
||||
_entityName.Add(8721, "sum");
|
||||
_entityValue.Add("minus", 8722); // minus sign, U+2212 ISOtech
|
||||
_entityName.Add(8722, "minus");
|
||||
_entityValue.Add("lowast", 8727); // asterisk operator, U+2217 ISOtech
|
||||
_entityName.Add(8727, "lowast");
|
||||
_entityValue.Add("radic", 8730); // square root = radical sign, U+221A ISOtech
|
||||
_entityName.Add(8730, "radic");
|
||||
_entityValue.Add("prop", 8733); // proportional to, U+221D ISOtech
|
||||
_entityName.Add(8733, "prop");
|
||||
_entityValue.Add("infin", 8734); // infinity, U+221E ISOtech
|
||||
_entityName.Add(8734, "infin");
|
||||
_entityValue.Add("ang", 8736); // angle, U+2220 ISOamso
|
||||
_entityName.Add(8736, "ang");
|
||||
_entityValue.Add("and", 8743); // logical and = wedge, U+2227 ISOtech
|
||||
_entityName.Add(8743, "and");
|
||||
_entityValue.Add("or", 8744); // logical or = vee, U+2228 ISOtech
|
||||
_entityName.Add(8744, "or");
|
||||
_entityValue.Add("cap", 8745); // intersection = cap, U+2229 ISOtech
|
||||
_entityName.Add(8745, "cap");
|
||||
_entityValue.Add("cup", 8746); // union = cup, U+222A ISOtech
|
||||
_entityName.Add(8746, "cup");
|
||||
_entityValue.Add("int", 8747); // integral, U+222B ISOtech
|
||||
_entityName.Add(8747, "int");
|
||||
_entityValue.Add("there4", 8756); // therefore, U+2234 ISOtech
|
||||
_entityName.Add(8756, "there4");
|
||||
_entityValue.Add("sim", 8764); // tilde operator = varies with = similar to, U+223C ISOtech
|
||||
_entityName.Add(8764, "sim");
|
||||
_entityValue.Add("cong", 8773); // approximately equal to, U+2245 ISOtech
|
||||
_entityName.Add(8773, "cong");
|
||||
_entityValue.Add("asymp", 8776); // almost equal to = asymptotic to, U+2248 ISOamsr
|
||||
_entityName.Add(8776, "asymp");
|
||||
_entityValue.Add("ne", 8800); // not equal to, U+2260 ISOtech
|
||||
_entityName.Add(8800, "ne");
|
||||
_entityValue.Add("equiv", 8801); // identical to, U+2261 ISOtech
|
||||
_entityName.Add(8801, "equiv");
|
||||
_entityValue.Add("le", 8804); // less-than or equal to, U+2264 ISOtech
|
||||
_entityName.Add(8804, "le");
|
||||
_entityValue.Add("ge", 8805); // greater-than or equal to, U+2265 ISOtech
|
||||
_entityName.Add(8805, "ge");
|
||||
_entityValue.Add("sub", 8834); // subset of, U+2282 ISOtech
|
||||
_entityName.Add(8834, "sub");
|
||||
_entityValue.Add("sup", 8835); // superset of, U+2283 ISOtech
|
||||
_entityName.Add(8835, "sup");
|
||||
_entityValue.Add("nsub", 8836); // not a subset of, U+2284 ISOamsn
|
||||
_entityName.Add(8836, "nsub");
|
||||
_entityValue.Add("sube", 8838); // subset of or equal to, U+2286 ISOtech
|
||||
_entityName.Add(8838, "sube");
|
||||
_entityValue.Add("supe", 8839); // superset of or equal to, U+2287 ISOtech
|
||||
_entityName.Add(8839, "supe");
|
||||
_entityValue.Add("oplus", 8853); // circled plus = direct sum, U+2295 ISOamsb
|
||||
_entityName.Add(8853, "oplus");
|
||||
_entityValue.Add("otimes", 8855); // circled times = vector product, U+2297 ISOamsb
|
||||
_entityName.Add(8855, "otimes");
|
||||
_entityValue.Add("perp", 8869); // up tack = orthogonal to = perpendicular, U+22A5 ISOtech
|
||||
_entityName.Add(8869, "perp");
|
||||
_entityValue.Add("sdot", 8901); // dot operator, U+22C5 ISOamsb
|
||||
_entityName.Add(8901, "sdot");
|
||||
_entityValue.Add("lceil", 8968); // left ceiling = apl upstile, U+2308 ISOamsc
|
||||
_entityName.Add(8968, "lceil");
|
||||
_entityValue.Add("rceil", 8969); // right ceiling, U+2309 ISOamsc
|
||||
_entityName.Add(8969, "rceil");
|
||||
_entityValue.Add("lfloor", 8970); // left floor = apl downstile, U+230A ISOamsc
|
||||
_entityName.Add(8970, "lfloor");
|
||||
_entityValue.Add("rfloor", 8971); // right floor, U+230B ISOamsc
|
||||
_entityName.Add(8971, "rfloor");
|
||||
_entityValue.Add("lang", 9001); // left-pointing angle bracket = bra, U+2329 ISOtech
|
||||
_entityName.Add(9001, "lang");
|
||||
_entityValue.Add("rang", 9002); // right-pointing angle bracket = ket, U+232A ISOtech
|
||||
_entityName.Add(9002, "rang");
|
||||
_entityValue.Add("loz", 9674); // lozenge, U+25CA ISOpub
|
||||
_entityName.Add(9674, "loz");
|
||||
_entityValue.Add("spades", 9824); // black spade suit, U+2660 ISOpub
|
||||
_entityName.Add(9824, "spades");
|
||||
_entityValue.Add("clubs", 9827); // black club suit = shamrock, U+2663 ISOpub
|
||||
_entityName.Add(9827, "clubs");
|
||||
_entityValue.Add("hearts", 9829); // black heart suit = valentine, U+2665 ISOpub
|
||||
_entityName.Add(9829, "hearts");
|
||||
_entityValue.Add("diams", 9830); // black diamond suit, U+2666 ISOpub
|
||||
_entityName.Add(9830, "diams");
|
||||
_entityValue.Add("OElig", 338); // latin capital ligature OE, U+0152 ISOlat2
|
||||
_entityName.Add(338, "OElig");
|
||||
_entityValue.Add("oelig", 339); // latin small ligature oe, U+0153 ISOlat2
|
||||
_entityName.Add(339, "oelig");
|
||||
_entityValue.Add("Scaron", 352); // latin capital letter S with caron, U+0160 ISOlat2
|
||||
_entityName.Add(352, "Scaron");
|
||||
_entityValue.Add("scaron", 353); // latin small letter s with caron, U+0161 ISOlat2
|
||||
_entityName.Add(353, "scaron");
|
||||
_entityValue.Add("Yuml", 376); // latin capital letter Y with diaeresis, U+0178 ISOlat2
|
||||
_entityName.Add(376, "Yuml");
|
||||
_entityValue.Add("circ", 710); // modifier letter circumflex accent, U+02C6 ISOpub
|
||||
_entityName.Add(710, "circ");
|
||||
_entityValue.Add("tilde", 732); // small tilde, U+02DC ISOdia
|
||||
_entityName.Add(732, "tilde");
|
||||
_entityValue.Add("ensp", 8194); // en space, U+2002 ISOpub
|
||||
_entityName.Add(8194, "ensp");
|
||||
_entityValue.Add("emsp", 8195); // em space, U+2003 ISOpub
|
||||
_entityName.Add(8195, "emsp");
|
||||
_entityValue.Add("thinsp", 8201); // thin space, U+2009 ISOpub
|
||||
_entityName.Add(8201, "thinsp");
|
||||
_entityValue.Add("zwnj", 8204); // zero width non-joiner, U+200C NEW RFC 2070
|
||||
_entityName.Add(8204, "zwnj");
|
||||
_entityValue.Add("zwj", 8205); // zero width joiner, U+200D NEW RFC 2070
|
||||
_entityName.Add(8205, "zwj");
|
||||
_entityValue.Add("lrm", 8206); // left-to-right mark, U+200E NEW RFC 2070
|
||||
_entityName.Add(8206, "lrm");
|
||||
_entityValue.Add("rlm", 8207); // right-to-left mark, U+200F NEW RFC 2070
|
||||
_entityName.Add(8207, "rlm");
|
||||
_entityValue.Add("ndash", 8211); // en dash, U+2013 ISOpub
|
||||
_entityName.Add(8211, "ndash");
|
||||
_entityValue.Add("mdash", 8212); // em dash, U+2014 ISOpub
|
||||
_entityName.Add(8212, "mdash");
|
||||
_entityValue.Add("lsquo", 8216); // left single quotation mark, U+2018 ISOnum
|
||||
_entityName.Add(8216, "lsquo");
|
||||
_entityValue.Add("rsquo", 8217); // right single quotation mark, U+2019 ISOnum
|
||||
_entityName.Add(8217, "rsquo");
|
||||
_entityValue.Add("sbquo", 8218); // single low-9 quotation mark, U+201A NEW
|
||||
_entityName.Add(8218, "sbquo");
|
||||
_entityValue.Add("ldquo", 8220); // left double quotation mark, U+201C ISOnum
|
||||
_entityName.Add(8220, "ldquo");
|
||||
_entityValue.Add("rdquo", 8221); // right double quotation mark, U+201D ISOnum
|
||||
_entityName.Add(8221, "rdquo");
|
||||
_entityValue.Add("bdquo", 8222); // double low-9 quotation mark, U+201E NEW
|
||||
_entityName.Add(8222, "bdquo");
|
||||
_entityValue.Add("dagger", 8224); // dagger, U+2020 ISOpub
|
||||
_entityName.Add(8224, "dagger");
|
||||
_entityValue.Add("Dagger", 8225); // double dagger, U+2021 ISOpub
|
||||
_entityName.Add(8225, "Dagger");
|
||||
_entityValue.Add("permil", 8240); // per mille sign, U+2030 ISOtech
|
||||
_entityName.Add(8240, "permil");
|
||||
_entityValue.Add("lsaquo", 8249); // single left-pointing angle quotation mark, U+2039 ISO proposed
|
||||
_entityName.Add(8249, "lsaquo");
|
||||
_entityValue.Add("rsaquo", 8250); // single right-pointing angle quotation mark, U+203A ISO proposed
|
||||
_entityName.Add(8250, "rsaquo");
|
||||
_entityValue.Add("euro", 8364); // euro sign, U+20AC NEW
|
||||
_entityName.Add(8364, "euro");
|
||||
|
||||
_maxEntitySize = 8 + 1; // we add the # char
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
private HtmlEntity()
|
||||
{
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Public Methods
|
||||
|
||||
/// <summary>
|
||||
/// Replace known entities by characters.
|
||||
/// </summary>
|
||||
/// <param name="text">The source text.</param>
|
||||
/// <returns>The result text.</returns>
|
||||
public static string DeEntitize(string text)
|
||||
{
|
||||
if (text == null)
|
||||
return null;
|
||||
|
||||
if (text.Length == 0)
|
||||
return text;
|
||||
|
||||
StringBuilder sb = new StringBuilder(text.Length);
|
||||
ParseState state = ParseState.Text;
|
||||
StringBuilder entity = new StringBuilder(10);
|
||||
|
||||
for (int i = 0; i < text.Length; i++)
|
||||
{
|
||||
switch (state)
|
||||
{
|
||||
case ParseState.Text:
|
||||
switch (text[i])
|
||||
{
|
||||
case '&':
|
||||
state = ParseState.EntityStart;
|
||||
break;
|
||||
|
||||
default:
|
||||
sb.Append(text[i]);
|
||||
break;
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case ParseState.EntityStart:
|
||||
switch (text[i])
|
||||
{
|
||||
case ';':
|
||||
if (entity.Length == 0)
|
||||
{
|
||||
sb.Append("&;");
|
||||
}
|
||||
else
|
||||
{
|
||||
if (entity[0] == '#')
|
||||
{
|
||||
string e = entity.ToString();
|
||||
try
|
||||
{
|
||||
string codeStr = e.Substring(1).Trim();
|
||||
int fromBase;
|
||||
if (codeStr.StartsWith("x", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
fromBase = 16;
|
||||
codeStr = codeStr.Substring(1);
|
||||
}
|
||||
else
|
||||
{
|
||||
fromBase = 10;
|
||||
}
|
||||
|
||||
int code = Convert.ToInt32(codeStr, fromBase);
|
||||
sb.Append(Convert.ToChar(code));
|
||||
}
|
||||
catch
|
||||
{
|
||||
sb.Append("&#" + e + ";");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// named entity?
|
||||
int code;
|
||||
if (!_entityValue.TryGetValue(entity.ToString(), out code))
|
||||
{
|
||||
// nope
|
||||
sb.Append("&" + entity + ";");
|
||||
}
|
||||
else
|
||||
{
|
||||
// we found one
|
||||
sb.Append(Convert.ToChar(code));
|
||||
}
|
||||
}
|
||||
|
||||
entity.Remove(0, entity.Length);
|
||||
}
|
||||
|
||||
state = ParseState.Text;
|
||||
break;
|
||||
|
||||
case '&':
|
||||
// new entity start without end, it was not an entity...
|
||||
sb.Append("&" + entity);
|
||||
entity.Remove(0, entity.Length);
|
||||
break;
|
||||
|
||||
default:
|
||||
entity.Append(text[i]);
|
||||
if (entity.Length > _maxEntitySize)
|
||||
{
|
||||
// unknown stuff, just don't touch it
|
||||
state = ParseState.Text;
|
||||
sb.Append("&" + entity);
|
||||
entity.Remove(0, entity.Length);
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// finish the work
|
||||
if (state == ParseState.EntityStart)
|
||||
{
|
||||
sb.Append("&" + entity);
|
||||
}
|
||||
|
||||
return sb.ToString();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Clone and entitize an HtmlNode. This will affect attribute values and nodes' text. It will also entitize all child nodes.
|
||||
/// </summary>
|
||||
/// <param name="node">The node to entitize.</param>
|
||||
/// <returns>An entitized cloned node.</returns>
|
||||
public static HtmlNode Entitize(HtmlNode node)
|
||||
{
|
||||
if (node == null)
|
||||
{
|
||||
throw new ArgumentNullException("node");
|
||||
}
|
||||
|
||||
HtmlNode result = node.CloneNode(true);
|
||||
if (result.HasAttributes)
|
||||
Entitize(result.Attributes);
|
||||
|
||||
if (result.HasChildNodes)
|
||||
{
|
||||
Entitize(result.ChildNodes);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (result.NodeType == HtmlNodeType.Text)
|
||||
{
|
||||
((HtmlTextNode) result).Text = Entitize(((HtmlTextNode) result).Text, true, true);
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Replace characters above 127 by entities.
|
||||
/// </summary>
|
||||
/// <param name="text">The source text.</param>
|
||||
/// <returns>The result text.</returns>
|
||||
public static string Entitize(string text)
|
||||
{
|
||||
return Entitize(text, true);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Replace characters above 127 by entities.
|
||||
/// </summary>
|
||||
/// <param name="text">The source text.</param>
|
||||
/// <param name="useNames">If set to false, the function will not use known entities name. Default is true.</param>
|
||||
/// <returns>The result text.</returns>
|
||||
public static string Entitize(string text, bool useNames)
|
||||
{
|
||||
return Entitize(text, useNames, false);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Replace characters above 127 by entities.
|
||||
/// </summary>
|
||||
/// <param name="text">The source text.</param>
|
||||
/// <param name="useNames">If set to false, the function will not use known entities name. Default is true.</param>
|
||||
/// <param name="entitizeQuotAmpAndLtGt">If set to true, the [quote], [ampersand], [lower than] and [greather than] characters will be entitized.</param>
|
||||
/// <returns>The result text</returns>
|
||||
public static string Entitize(string text, bool useNames, bool entitizeQuotAmpAndLtGt)
|
||||
// _entityValue.Add("quot", 34); // quotation mark = APL quote, U+0022 ISOnum
|
||||
// _entityName.Add(34, "quot");
|
||||
// _entityValue.Add("amp", 38); // ampersand, U+0026 ISOnum
|
||||
// _entityName.Add(38, "amp");
|
||||
// _entityValue.Add("lt", 60); // less-than sign, U+003C ISOnum
|
||||
// _entityName.Add(60, "lt");
|
||||
// _entityValue.Add("gt", 62); // greater-than sign, U+003E ISOnum
|
||||
// _entityName.Add(62, "gt");
|
||||
{
|
||||
if (text == null)
|
||||
return null;
|
||||
|
||||
if (text.Length == 0)
|
||||
return text;
|
||||
|
||||
StringBuilder sb = new StringBuilder(text.Length);
|
||||
|
||||
#if !FX20 && !FX35
|
||||
if (UseWebUtility)
|
||||
{
|
||||
TextElementEnumerator enumerator = StringInfo.GetTextElementEnumerator(text);
|
||||
while (enumerator.MoveNext())
|
||||
{
|
||||
sb.Append(System.Net.WebUtility.HtmlEncode(enumerator.GetTextElement()));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
#endif
|
||||
for (int i = 0; i < text.Length; i++)
|
||||
{
|
||||
int code = text[i];
|
||||
if ((code > 127) ||
|
||||
(entitizeQuotAmpAndLtGt && ((code == 34) || (code == 38) || (code == 60) || (code == 62))))
|
||||
{
|
||||
string entity = null;
|
||||
|
||||
if (useNames)
|
||||
{
|
||||
EntityName.TryGetValue(code, out entity);
|
||||
}
|
||||
|
||||
if (entity == null)
|
||||
{
|
||||
sb.Append("&#" + code + ";");
|
||||
}
|
||||
else
|
||||
{
|
||||
sb.Append("&" + entity + ";");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
sb.Append(text[i]);
|
||||
}
|
||||
}
|
||||
#if !FX20 && !FX35
|
||||
}
|
||||
#endif
|
||||
|
||||
return sb.ToString();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Private Methods
|
||||
|
||||
private static void Entitize(HtmlAttributeCollection collection)
|
||||
{
|
||||
foreach (HtmlAttribute at in collection)
|
||||
{
|
||||
if (at.Value == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
at.Value = Entitize(at.Value);
|
||||
}
|
||||
}
|
||||
|
||||
private static void Entitize(HtmlNodeCollection collection)
|
||||
{
|
||||
foreach (HtmlNode node in collection)
|
||||
{
|
||||
if (node.HasAttributes)
|
||||
Entitize(node.Attributes);
|
||||
|
||||
if (node.HasChildNodes)
|
||||
{
|
||||
Entitize(node.ChildNodes);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (node.NodeType == HtmlNodeType.Text)
|
||||
{
|
||||
((HtmlTextNode) node).Text = Entitize(((HtmlTextNode) node).Text, true, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Nested type: ParseState
|
||||
|
||||
private enum ParseState
|
||||
{
|
||||
Text,
|
||||
EntityStart
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
59
Source/MyDb/HtmlAgilityPack.Shared/HtmlNameTable.cs
Normal file
59
Source/MyDb/HtmlAgilityPack.Shared/HtmlNameTable.cs
Normal file
|
|
@ -0,0 +1,59 @@
|
|||
// Description: Html Agility Pack - HTML Parsers, selectors, traversors, manupulators.
|
||||
// Website & Documentation: http://html-agility-pack.net
|
||||
// Forum & Issues: https://github.com/zzzprojects/html-agility-pack
|
||||
// License: https://github.com/zzzprojects/html-agility-pack/blob/master/LICENSE
|
||||
// More projects: http://www.zzzprojects.com/
|
||||
// Copyright © ZZZ Projects Inc. 2014 - 2017. All rights reserved.
|
||||
|
||||
using System.Xml;
|
||||
|
||||
namespace HtmlAgilityPack
|
||||
{
|
||||
internal class HtmlNameTable : XmlNameTable
|
||||
{
|
||||
#region Fields
|
||||
|
||||
private NameTable _nametable = new NameTable();
|
||||
|
||||
#endregion
|
||||
|
||||
#region Public Methods
|
||||
|
||||
public override string Add(string array)
|
||||
{
|
||||
return _nametable.Add(array);
|
||||
}
|
||||
|
||||
public override string Add(char[] array, int offset, int length)
|
||||
{
|
||||
return _nametable.Add(array, offset, length);
|
||||
}
|
||||
|
||||
public override string Get(string array)
|
||||
{
|
||||
return _nametable.Get(array);
|
||||
}
|
||||
|
||||
public override string Get(char[] array, int offset, int length)
|
||||
{
|
||||
return _nametable.Get(array, offset, length);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Internal Methods
|
||||
|
||||
internal string GetOrAdd(string array)
|
||||
{
|
||||
string s = Get(array);
|
||||
if (s == null)
|
||||
{
|
||||
return Add(array);
|
||||
}
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
980
Source/MyDb/HtmlAgilityPack.Shared/HtmlNode.Encapsulator.cs
Normal file
980
Source/MyDb/HtmlAgilityPack.Shared/HtmlNode.Encapsulator.cs
Normal file
|
|
@ -0,0 +1,980 @@
|
|||
// Description: Html Agility Pack - HTML Parsers, selectors, traversors, manupulators.
|
||||
// Website & Documentation: http://html-agility-pack.net
|
||||
// Forum & Issues: https://github.com/zzzprojects/html-agility-pack
|
||||
// License: https://github.com/zzzprojects/html-agility-pack/blob/master/LICENSE
|
||||
// More projects: http://www.zzzprojects.com/
|
||||
// Copyright © ZZZ Projects Inc. 2014 - 2017. All rights reserved.
|
||||
|
||||
#if !METRO && !NETSTANDARD1_3
|
||||
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Reflection;
|
||||
using System.Xml.XPath;
|
||||
|
||||
namespace HtmlAgilityPack
|
||||
{
|
||||
public partial class HtmlNode
|
||||
{
|
||||
/// <summary>
|
||||
/// Fill an object and go through it's properties and fill them too.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">Type of object to want to fill. It should have atleast one property that defined XPath.</typeparam>
|
||||
/// <returns>Returns an object of type T including Encapsulated data.</returns>
|
||||
/// <exception cref="ArgumentException">Why it's thrown.</exception>
|
||||
/// <exception cref="ArgumentNullException">Why it's thrown.</exception>
|
||||
/// <exception cref="MissingMethodException">Why it's thrown.</exception>
|
||||
/// <exception cref="MissingXPathException">Why it's thrown.</exception>
|
||||
/// <exception cref="XPathException">Why it's thrown.</exception>
|
||||
/// <exception cref="NodeNotFoundException">Why it's thrown.</exception>
|
||||
/// <exception cref="NodeAttributeNotFoundException">Why it's thrown.</exception>
|
||||
/// <exception cref="FormatException">Why it's thrown.</exception>
|
||||
/// <exception cref="Exception">Why it's thrown.</exception>
|
||||
public T GetEncapsulatedData<T>()
|
||||
{
|
||||
return (T)GetEncapsulatedData(typeof(T), null);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Fill an object and go through it's properties and fill them too.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">Type of object to want to fill. It should have atleast one property that defined XPath.</typeparam>
|
||||
/// <param name="htmlDocument">If htmlDocument includes data , leave this parameter null. Else pass your specific htmldocument.</param>
|
||||
/// <returns>Returns an object of type T including Encapsulated data.</returns>
|
||||
/// <exception cref="ArgumentException">Why it's thrown.</exception>
|
||||
/// <exception cref="ArgumentNullException">Why it's thrown.</exception>
|
||||
/// <exception cref="MissingMethodException">Why it's thrown.</exception>
|
||||
/// <exception cref="MissingXPathException">Why it's thrown.</exception>
|
||||
/// <exception cref="XPathException">Why it's thrown.</exception>
|
||||
/// <exception cref="NodeNotFoundException">Why it's thrown.</exception>
|
||||
/// <exception cref="NodeAttributeNotFoundException">Why it's thrown.</exception>
|
||||
/// <exception cref="FormatException">Why it's thrown.</exception>
|
||||
/// <exception cref="Exception">Why it's thrown.</exception>
|
||||
public T GetEncapsulatedData<T>(HtmlDocument htmlDocument)
|
||||
{
|
||||
return (T)GetEncapsulatedData(typeof(T), htmlDocument);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Fill an object and go through it's properties and fill them too.
|
||||
/// </summary>
|
||||
/// <param name="targetType">Type of object to want to fill. It should have atleast one property that defined XPath.</param>
|
||||
/// <param name="htmlDocument">If htmlDocument includes data , leave this parameter null. Else pass your specific htmldocument.</param>
|
||||
/// <returns>Returns an object of type targetType including Encapsulated data.</returns>
|
||||
/// <exception cref="ArgumentException">Why it's thrown.</exception>
|
||||
/// <exception cref="ArgumentNullException">Why it's thrown.</exception>
|
||||
/// <exception cref="MissingMethodException">Why it's thrown.</exception>
|
||||
/// <exception cref="MissingXPathException">Why it's thrown.</exception>
|
||||
/// <exception cref="XPathException">Why it's thrown.</exception>
|
||||
/// <exception cref="NodeNotFoundException">Why it's thrown.</exception>
|
||||
/// <exception cref="NodeAttributeNotFoundException">Why it's thrown.</exception>
|
||||
/// <exception cref="FormatException">Why it's thrown.</exception>
|
||||
/// <exception cref="Exception">Why it's thrown.</exception>
|
||||
public object GetEncapsulatedData(Type targetType, HtmlDocument htmlDocument = null)
|
||||
{
|
||||
|
||||
#region SettingPrerequisite
|
||||
|
||||
if (targetType == null)
|
||||
{
|
||||
throw new ArgumentNullException("Parameter targetType is null");
|
||||
}
|
||||
|
||||
HtmlDocument source;
|
||||
|
||||
if (htmlDocument == null)
|
||||
{
|
||||
source = OwnerDocument;
|
||||
}
|
||||
else
|
||||
{
|
||||
source = htmlDocument;
|
||||
}
|
||||
|
||||
|
||||
|
||||
object targetObject;
|
||||
|
||||
if (targetType.IsInstantiable() == false) // if it can not create instanse of T because of lack of constructor in type T.
|
||||
{
|
||||
throw new MissingMethodException("Parameterless Constructor excpected for " + targetType.FullName);
|
||||
}
|
||||
else
|
||||
{
|
||||
targetObject = Activator.CreateInstance(targetType);
|
||||
}
|
||||
|
||||
#endregion SettingPrerequisite
|
||||
|
||||
#region targetObject_Defined_XPath
|
||||
if (targetType.IsDefinedAttribute(typeof(HasXPathAttribute)) == true) // Object has xpath attribute (Defined HasXPath)
|
||||
{
|
||||
|
||||
// Store list of properties that defined xpath attribute
|
||||
IEnumerable<PropertyInfo> validProperties = targetType.GetPropertiesDefinedXPath();
|
||||
if (validProperties.CountOfIEnumerable() == 0) // if no XPath property exist in type T while T defined HasXpath attribute.
|
||||
{
|
||||
throw new MissingXPathException("Type " + targetType.FullName +
|
||||
" defined HasXPath Attribute but it does not have any property with XPath Attribte.");
|
||||
}
|
||||
else
|
||||
{
|
||||
// Fill targetObject variable Properties ( T targetObject )
|
||||
foreach (PropertyInfo propertyInfo in validProperties)
|
||||
{
|
||||
// Get xpath attribute from valid properties
|
||||
// for .Net old versions:
|
||||
XPathAttribute xPathAttribute = (propertyInfo.GetCustomAttributes(typeof(XPathAttribute), false) as IList)[0] as XPathAttribute;
|
||||
|
||||
|
||||
#region Property_IsNOT_IEnumerable
|
||||
if (propertyInfo.IsIEnumerable() == false) // Property is None-IEnumerable
|
||||
{
|
||||
|
||||
HtmlNode htmlNode = null;
|
||||
|
||||
// try to fill htmlNode based on XPath given
|
||||
try
|
||||
{
|
||||
htmlNode = source.DocumentNode.SelectSingleNode(xPathAttribute.XPath);
|
||||
}
|
||||
catch (XPathException ex) // if it can not select node based on given xpath
|
||||
{
|
||||
throw new XPathException(ex.Message + " That means you have a syntax error in XPath property of this Property : " +
|
||||
propertyInfo.PropertyType.FullName + " " + propertyInfo.Name);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
throw new NodeNotFoundException("Cannot find node with giving XPath to bind to " +
|
||||
propertyInfo.PropertyType.FullName + " " + propertyInfo.Name, ex);
|
||||
}
|
||||
|
||||
|
||||
if (htmlNode == null) // If Encapsulator could not find Node.
|
||||
{
|
||||
if (propertyInfo.IsDefined(typeof(SkipNodeNotFoundAttribute), false) == true)
|
||||
{
|
||||
// set default value.
|
||||
//throw new Exception("Okey !");
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new NodeNotFoundException("Cannot find node with giving XPath to bind to " +
|
||||
propertyInfo.PropertyType.FullName + " " + propertyInfo.Name);
|
||||
}
|
||||
|
||||
}
|
||||
else // if htmlNode is not null (Encapsulator find the Node)
|
||||
{
|
||||
|
||||
#region Property_Is_HasXPath_UserDefinedClass
|
||||
// Property is None-IEnumerable HasXPath-user-defined class
|
||||
if (propertyInfo.PropertyType.IsDefinedAttribute(typeof(HasXPathAttribute)) == true)
|
||||
{
|
||||
HtmlDocument innerHtmlDocument = new HtmlDocument();
|
||||
|
||||
innerHtmlDocument.LoadHtml(htmlNode.InnerHtml);
|
||||
|
||||
object o = GetEncapsulatedData(propertyInfo.PropertyType, innerHtmlDocument);
|
||||
|
||||
propertyInfo.SetValue(targetObject, o, null);
|
||||
}
|
||||
#endregion Property_Is_HasXPath_UserDefinedClass
|
||||
|
||||
#region Property_Is_SimpleType
|
||||
// Property is None-IEnumerable value-type or .Net class or user-defined class.
|
||||
// AND does not deifned xpath and shouldn't have property that defined xpath.
|
||||
else
|
||||
{
|
||||
string result = string.Empty;
|
||||
|
||||
if (xPathAttribute.AttributeName == null) // It target value of HTMLTag
|
||||
{
|
||||
result = Tools.GetNodeValueBasedOnXPathReturnType<string>(htmlNode, xPathAttribute);
|
||||
}
|
||||
else // It target attribute of HTMLTag
|
||||
{
|
||||
result = htmlNode.GetAttributeValue(xPathAttribute.AttributeName, null);
|
||||
}
|
||||
|
||||
if (result == null)
|
||||
{
|
||||
throw new NodeAttributeNotFoundException("Can not find " +
|
||||
xPathAttribute.AttributeName + " Attribute in " + htmlNode.Name +
|
||||
" related to " + propertyInfo.PropertyType.FullName + " " + propertyInfo.Name);
|
||||
}
|
||||
|
||||
|
||||
object resultCastedToTargetPropertyType;
|
||||
|
||||
try
|
||||
{
|
||||
resultCastedToTargetPropertyType = Convert.ChangeType(result, propertyInfo.PropertyType);
|
||||
}
|
||||
catch (FormatException)
|
||||
{
|
||||
throw new FormatException("Can not convert Invalid string to " + propertyInfo.PropertyType.FullName + " " + propertyInfo.Name);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
throw new Exception("Unhandled Exception : " + ex.Message);
|
||||
}
|
||||
|
||||
|
||||
|
||||
propertyInfo.SetValue(targetObject, resultCastedToTargetPropertyType, null);
|
||||
}
|
||||
#endregion Property_Is_SimpleType
|
||||
}
|
||||
|
||||
}
|
||||
#endregion Property_IsNOT_IEnumerable
|
||||
|
||||
|
||||
#region Property_Is_IEnumerable
|
||||
else // Property is IEnumerable<T>
|
||||
{
|
||||
IList<Type> T_Types = propertyInfo.GetGenericTypes() as IList<Type>; // Get T type
|
||||
|
||||
if (T_Types == null || T_Types.Count == 0)
|
||||
{
|
||||
throw new ArgumentException(propertyInfo.Name + " should have one generic argument.");
|
||||
}
|
||||
|
||||
else if (T_Types.Count > 1)
|
||||
{
|
||||
throw new ArgumentException(propertyInfo.Name + " should have one generic argument.");
|
||||
}
|
||||
|
||||
else if (T_Types.Count == 1) // It is NOT something like Dictionary<Tkey , Tvalue>
|
||||
{
|
||||
|
||||
HtmlNodeCollection nodeCollection;
|
||||
|
||||
// try to fill nodeCollection based on given xpath.
|
||||
try
|
||||
{
|
||||
nodeCollection = source.DocumentNode.SelectNodes(xPathAttribute.XPath);
|
||||
}
|
||||
catch (XPathException ex)
|
||||
{
|
||||
throw new XPathException(ex.Message + " That means you have a syntax error in XPath property of this Property : " +
|
||||
propertyInfo.PropertyType.FullName + " " + propertyInfo.Name);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
throw new NodeNotFoundException("Cannot find node with giving XPath to bind to " +
|
||||
propertyInfo.PropertyType.FullName + " " + propertyInfo.Name, ex);
|
||||
}
|
||||
|
||||
|
||||
if (nodeCollection == null || nodeCollection.Count == 0)
|
||||
{
|
||||
if (propertyInfo.IsDefined(typeof(SkipNodeNotFoundAttribute), false) == true)
|
||||
{
|
||||
// set default value.
|
||||
//throw new Exception("Okey !");
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new NodeNotFoundException("Cannot find node with giving XPath to bind to " +
|
||||
propertyInfo.PropertyType.FullName + " " + propertyInfo.Name);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
IList result = T_Types[0].CreateIListOfType();
|
||||
|
||||
#region Property_Is_IEnumerable<HasXPath-UserDefinedClass>
|
||||
if (T_Types[0].IsDefinedAttribute(typeof(HasXPathAttribute)) == true) // T is IEnumerable HasXPath-user-defined class (T type Defined XPath properties)
|
||||
{
|
||||
foreach (HtmlNode node in nodeCollection)
|
||||
{
|
||||
HtmlDocument innerHtmlDocument = new HtmlDocument();
|
||||
innerHtmlDocument.LoadHtml(node.InnerHtml);
|
||||
|
||||
object o = GetEncapsulatedData(T_Types[0], innerHtmlDocument);
|
||||
|
||||
result.Add(o);
|
||||
}
|
||||
}
|
||||
#endregion Property_Is_IEnumerable<HasXPath-UserDefinedClass>
|
||||
|
||||
#region Property_Is_IEnumerable<SimpleClass>
|
||||
else // T is value-type or .Net class or user-defined class ( without xpath )
|
||||
{
|
||||
if (xPathAttribute.AttributeName == null) // It target value
|
||||
{
|
||||
try
|
||||
{
|
||||
result = Tools.GetNodesValuesBasedOnXPathReturnType(nodeCollection, xPathAttribute, T_Types[0]);
|
||||
}
|
||||
catch (FormatException)
|
||||
{
|
||||
throw new FormatException("Can not convert Invalid string in node collection to " + T_Types[0].FullName + " " + propertyInfo.Name);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
throw new Exception("Unhandled Exception : " + ex.Message);
|
||||
}
|
||||
}
|
||||
else // It target attribute
|
||||
{
|
||||
foreach (HtmlNode node in nodeCollection)
|
||||
{
|
||||
string nodeAttributeValue = node.GetAttributeValue(xPathAttribute.AttributeName, null);
|
||||
if (nodeAttributeValue == null)
|
||||
{
|
||||
throw new NodeAttributeNotFoundException("Can not find " + xPathAttribute.AttributeName + " Attribute in " + node.Name + " related to " +
|
||||
propertyInfo.PropertyType.FullName + " " + propertyInfo.Name);
|
||||
}
|
||||
|
||||
object resultCastedToTargetPropertyType;
|
||||
|
||||
|
||||
try
|
||||
{
|
||||
resultCastedToTargetPropertyType = Convert.ChangeType(nodeAttributeValue, T_Types[0]);
|
||||
}
|
||||
catch (FormatException) // if it can not cast result(string) to type of property.
|
||||
{
|
||||
throw new FormatException("Can not convert Invalid string to " + T_Types[0].FullName + " " + propertyInfo.Name);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
throw new Exception("Unhandled Exception : " + ex.Message);
|
||||
}
|
||||
|
||||
|
||||
result.Add(resultCastedToTargetPropertyType);
|
||||
}
|
||||
}
|
||||
}
|
||||
#endregion Property_Is_IEnumerable<SimpleClass>
|
||||
|
||||
if (result == null || result.Count == 0)
|
||||
{
|
||||
throw new Exception("Cannot fill " + propertyInfo.PropertyType.FullName + " " + propertyInfo.Name + " because it is null.");
|
||||
}
|
||||
|
||||
propertyInfo.SetValue(targetObject, result, null);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
#endregion Property_Is_IEnumerable
|
||||
}
|
||||
|
||||
return targetObject;
|
||||
}
|
||||
}
|
||||
#endregion targetObject_Defined_XPath
|
||||
|
||||
#region targetObject_NOTDefined_XPath
|
||||
else // Object doesen't have xpath attribute
|
||||
{
|
||||
throw new MissingXPathException("Type T must define HasXPath attribute and include properties with XPath attribute.");
|
||||
}
|
||||
#endregion targetObject_NOTDefined_XPath
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Includes tools that GetEncapsulatedData method uses them.
|
||||
/// </summary>
|
||||
internal static class Tools
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// Determine if a type define an attribute or not , supporting both .NetStandard and .NetFramework2.0
|
||||
/// </summary>
|
||||
/// <param name="type">Type you want to test it.</param>
|
||||
/// <param name="attributeType">Attribute that type must have or not.</param>
|
||||
/// <returns>If true , The type parameter define attributeType parameter.</returns>
|
||||
internal static bool IsDefinedAttribute(this Type type, Type attributeType)
|
||||
{
|
||||
|
||||
if (type == null)
|
||||
{
|
||||
throw new ArgumentNullException("Parameter type is null when checking type defined attributeType or not.");
|
||||
}
|
||||
|
||||
if (attributeType == null)
|
||||
{
|
||||
throw new ArgumentNullException("Parameter attributeType is null when checking type defined attributeType or not.");
|
||||
}
|
||||
|
||||
#if !(NETSTANDARD1_3 || NETSTANDARD1_6)
|
||||
if (type.IsDefined(attributeType, false) == true)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
#if NETSTANDARD1_3 || NETSTANDARD1_6
|
||||
if (type.GetTypeInfo().IsDefined(attributeType) == true)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
|
||||
throw new Exception("Can't Target any platform when checking " + type.FullName + " is a " + attributeType.FullName + " or not.");
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Retrive properties of type that defined <see cref="XPathAttribute"/>.
|
||||
/// </summary>
|
||||
/// <param name="type">Type that you want to find it's XPath-Defined properties.</param>
|
||||
/// <returns>IEnumerable of property infos of a type , that defined specific attribute.</returns>
|
||||
internal static IEnumerable<PropertyInfo> GetPropertiesDefinedXPath(this Type type)
|
||||
{
|
||||
if (type == null)
|
||||
{
|
||||
throw new ArgumentNullException("Parameter type is null while retrieving properties defined XPathAttribute of Type type.");
|
||||
}
|
||||
|
||||
PropertyInfo[] properties = null;
|
||||
|
||||
|
||||
#if !(NETSTANDARD1_3 || NETSTANDARD1_6)
|
||||
properties = type.GetProperties();
|
||||
#endif
|
||||
|
||||
|
||||
#if NETSTANDARD1_3 || NETSTANDARD1_6
|
||||
properties = type.GetTypeInfo().GetProperties();
|
||||
#endif
|
||||
|
||||
|
||||
return properties.HAPWhere(x => x.IsDefined(typeof(XPathAttribute), false) == true);
|
||||
|
||||
throw new Exception("Can't Target any platform while retrieving properties defined XPathAttribute of Type type.");
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Determine if a <see cref="PropertyInfo"/> has implemented <see cref="IEnumerable"/> BUT <see cref="string"/> is considered as NONE-IEnumerable !
|
||||
/// </summary>
|
||||
/// <param name="propertyInfo">The property info you want to test.</param>
|
||||
/// <returns>True if property info is IEnumerable.</returns>
|
||||
internal static bool IsIEnumerable(this PropertyInfo propertyInfo)
|
||||
{
|
||||
//return propertyInfo.PropertyType.GetInterface(typeof(IEnumerable<>).FullName) != null;
|
||||
|
||||
if (propertyInfo == null)
|
||||
{
|
||||
throw new ArgumentNullException("Parameter propertyInfo is null while checking propertyInfo for being IEnumerable or not.");
|
||||
}
|
||||
|
||||
|
||||
if (propertyInfo.PropertyType == typeof(string))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
#if !(NETSTANDARD1_3 || NETSTANDARD1_6)
|
||||
return typeof(IEnumerable).IsAssignableFrom(propertyInfo.PropertyType);
|
||||
#endif
|
||||
|
||||
|
||||
#if NETSTANDARD1_3 || NETSTANDARD1_6
|
||||
return typeof(IEnumerable).GetTypeInfo().IsAssignableFrom(propertyInfo.PropertyType);
|
||||
#endif
|
||||
|
||||
throw new Exception("Can't Target any platform while checking propertyInfo for being IEnumerable or not.");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Returns T type(first generic type) of <see cref="IEnumerable{T}"/> or <see cref="List{T}"/>.
|
||||
/// </summary>
|
||||
/// <param name="propertyInfo">IEnumerable-Implemented property</param>
|
||||
/// <returns>List of generic types.</returns>
|
||||
internal static IEnumerable<Type> GetGenericTypes(this PropertyInfo propertyInfo)
|
||||
{
|
||||
|
||||
if (propertyInfo == null)
|
||||
{
|
||||
throw new ArgumentNullException("Parameter propertyInfo is null while Getting generic types of Property.");
|
||||
}
|
||||
|
||||
#if !(NETSTANDARD1_3 || NETSTANDARD1_6)
|
||||
return propertyInfo.PropertyType.GetGenericArguments();
|
||||
#endif
|
||||
|
||||
|
||||
#if NETSTANDARD1_3 || NETSTANDARD1_6
|
||||
return propertyInfo.PropertyType.GetTypeInfo().GetGenericArguments();
|
||||
#endif
|
||||
|
||||
throw new Exception("Can't Target any platform while Getting generic types of Property.");
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Find and Return a mehtod that defined in a class by it's name.
|
||||
/// </summary>
|
||||
/// <param name="type">Type of class include requested method.</param>
|
||||
/// <param name="methodName">Name of requested method as string.</param>
|
||||
/// <returns>Method info of requested method.</returns>
|
||||
internal static MethodInfo GetMethodByItsName(this Type type, string methodName)
|
||||
{
|
||||
if (type == null)
|
||||
{
|
||||
throw new ArgumentNullException("Parameter type is null while Getting method from it.");
|
||||
}
|
||||
|
||||
if (methodName == null || methodName == "")
|
||||
{
|
||||
throw new ArgumentNullException("Parameter methodName is null while Getting method from Type type.");
|
||||
}
|
||||
|
||||
#if !(NETSTANDARD1_3 || NETSTANDARD1_6)
|
||||
return type.GetMethod(methodName);
|
||||
#endif
|
||||
|
||||
|
||||
#if NETSTANDARD1_3 || NETSTANDARD1_6
|
||||
return type.GetTypeInfo().GetMethod(methodName);
|
||||
#endif
|
||||
|
||||
throw new Exception("Can't Target any platform while getting Method methodName from Type type.");
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Create <see cref="IList"/> of given type.
|
||||
/// </summary>
|
||||
/// <param name="type">Type that you want to make a List of it.</param>
|
||||
/// <returns>Returns IList of given type.</returns>
|
||||
internal static IList CreateIListOfType(this Type type)
|
||||
{
|
||||
if (type == null)
|
||||
{
|
||||
throw new ArgumentNullException("Parameter type is null while creating List<type>.");
|
||||
}
|
||||
|
||||
Type listType = typeof(List<>);
|
||||
Type constructedListType = listType.MakeGenericType(type);
|
||||
return Activator.CreateInstance(constructedListType) as IList;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Returns the part of value of <see cref="HtmlNode"/> you want as .
|
||||
/// </summary>
|
||||
/// <param name="htmlNode">A htmlNode instance.</param>
|
||||
/// <param name="xPathAttribute">Attribute that includes ReturnType</param>
|
||||
/// <returns>String that choosen from HtmlNode as result.</returns>
|
||||
internal static T GetNodeValueBasedOnXPathReturnType<T>(HtmlNode htmlNode, XPathAttribute xPathAttribute)
|
||||
{
|
||||
if (htmlNode == null)
|
||||
{
|
||||
throw new ArgumentNullException("parameter html node is null");
|
||||
}
|
||||
|
||||
if (xPathAttribute == null)
|
||||
{
|
||||
throw new ArgumentNullException("parameter xpathAttribute is null");
|
||||
}
|
||||
|
||||
object result;
|
||||
Type TType = typeof(T);
|
||||
|
||||
switch (xPathAttribute.NodeReturnType)
|
||||
{
|
||||
case ReturnType.InnerHtml:
|
||||
{
|
||||
result = Convert.ChangeType(htmlNode.InnerHtml, TType);
|
||||
}
|
||||
break;
|
||||
|
||||
|
||||
case ReturnType.InnerText:
|
||||
{
|
||||
result = Convert.ChangeType(htmlNode.InnerText, TType);
|
||||
}
|
||||
break;
|
||||
|
||||
case ReturnType.OuterHtml:
|
||||
{
|
||||
result = Convert.ChangeType(htmlNode.OuterHtml, TType);
|
||||
}
|
||||
break;
|
||||
|
||||
default: throw new Exception();
|
||||
}
|
||||
|
||||
return (T)result;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Returns parts of values of <see cref="HtmlNode"/> you want as <see cref="IList{T}"/>.
|
||||
/// </summary>
|
||||
/// <param name="htmlNodeCollection"><see cref="HtmlNodeCollection"/> that you want to retrive each <see cref="HtmlNode"/> value.</param>
|
||||
/// <param name="xPathAttribute">A <see cref="XPathAttribute"/> instnce incules <see cref="ReturnType"/>.</param>
|
||||
/// <param name="listGenericType">Type of IList generic you want.</param>
|
||||
/// <returns></returns>
|
||||
internal static IList GetNodesValuesBasedOnXPathReturnType(HtmlNodeCollection htmlNodeCollection, XPathAttribute xPathAttribute, Type listGenericType)
|
||||
{
|
||||
if (htmlNodeCollection == null || htmlNodeCollection.Count == 0)
|
||||
{
|
||||
throw new ArgumentNullException("parameter htmlNodeCollection is null or empty.");
|
||||
}
|
||||
|
||||
if (xPathAttribute == null)
|
||||
{
|
||||
throw new ArgumentNullException("parameter xpathAttribute is null");
|
||||
}
|
||||
|
||||
|
||||
IList result = listGenericType.CreateIListOfType();
|
||||
|
||||
switch (xPathAttribute.NodeReturnType)
|
||||
{
|
||||
|
||||
case ReturnType.InnerHtml:
|
||||
{
|
||||
foreach (HtmlNode node in htmlNodeCollection)
|
||||
{
|
||||
result.Add(Convert.ChangeType(node.InnerHtml, listGenericType));
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
|
||||
case ReturnType.InnerText:
|
||||
{
|
||||
foreach (HtmlNode node in htmlNodeCollection)
|
||||
{
|
||||
result.Add(Convert.ChangeType(node.InnerText, listGenericType));
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
|
||||
case ReturnType.OuterHtml:
|
||||
{
|
||||
foreach (HtmlNode node in htmlNodeCollection)
|
||||
{
|
||||
result.Add(Convert.ChangeType(node.OuterHtml, listGenericType));
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Simulate Func method to use in Lambada Expression.
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
/// <typeparam name="TResult"></typeparam>
|
||||
/// <param name="arg"></param>
|
||||
/// <returns></returns>
|
||||
internal delegate TResult HAPFunc<T, TResult>(T arg);
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// This method works like Where method in LINQ.
|
||||
/// </summary>
|
||||
/// <typeparam name="TSource"></typeparam>
|
||||
/// <param name="source"></param>
|
||||
/// <param name="predicate"></param>
|
||||
/// <returns></returns>
|
||||
internal static IEnumerable<TSource> HAPWhere<TSource>(this IEnumerable<TSource> source, HAPFunc<TSource, bool> predicate)
|
||||
{
|
||||
foreach (TSource item in source)
|
||||
{
|
||||
if (predicate(item))
|
||||
{
|
||||
yield return item;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Check if the type can instantiated.
|
||||
/// </summary>
|
||||
/// <param name="type"></param>
|
||||
/// <returns></returns>
|
||||
internal static bool IsInstantiable(this Type type)
|
||||
{
|
||||
if (type == null)
|
||||
{
|
||||
throw new ArgumentNullException("type is null");
|
||||
}
|
||||
|
||||
|
||||
#if !(NETSTANDARD1_3 || NETSTANDARD1_6)
|
||||
// checking for having parameterless constructor.
|
||||
if (type.GetConstructor(Type.EmptyTypes) == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
return true;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
#if NETSTANDARD1_3 || NETSTANDARD1_6
|
||||
// checking for having parameterless constructor.
|
||||
if (type.GetTypeInfo().DeclaredConstructors.HAPWhere(x => x.GetParameters().Length == 0).CountOfIEnumerable() == 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
return true;
|
||||
}
|
||||
#endif
|
||||
|
||||
throw new Exception("Can't Target any platform while getting Method methodName from Type type.");
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Returns count of elements stored in IEnumerable of T
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
/// <param name="source"></param>
|
||||
/// <returns></returns>
|
||||
internal static int CountOfIEnumerable<T>(this IEnumerable<T> source)
|
||||
{
|
||||
if (source == null)
|
||||
{
|
||||
throw new ArgumentNullException("Parameter source is null while counting the IEnumerable");
|
||||
}
|
||||
|
||||
int counter = 0;
|
||||
foreach (T item in source)
|
||||
{
|
||||
counter++;
|
||||
}
|
||||
return counter;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Specify which part of <see cref="HtmlNode"/> is requested.
|
||||
/// </summary>
|
||||
public enum ReturnType
|
||||
{
|
||||
/// <summary>
|
||||
/// The text between the start and end tags of the object.
|
||||
/// </summary>
|
||||
InnerText,
|
||||
|
||||
/// <summary>
|
||||
/// The HTML between the start and end tags of the object
|
||||
/// </summary>
|
||||
InnerHtml,
|
||||
|
||||
/// <summary>
|
||||
/// The object and its content in HTML
|
||||
/// </summary>
|
||||
OuterHtml
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Just mark and flag classes to show they have properties that defined <see cref="XPathAttribute"/>.
|
||||
/// </summary>
|
||||
[AttributeUsage(AttributeTargets.Class, Inherited = false, AllowMultiple = false)]
|
||||
public sealed class HasXPathAttribute : Attribute
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Includes XPath and <see cref="NodeReturnType"/>. XPath for finding html tags and <see cref="NodeReturnType"/> for specify which part of <see cref="HtmlNode"/> you want to return.
|
||||
/// </summary>
|
||||
[AttributeUsage(AttributeTargets.Property, Inherited = false, AllowMultiple = false)]
|
||||
public sealed class XPathAttribute : Attribute
|
||||
{
|
||||
/// <summary>
|
||||
/// XPath Expression that is used to find related html node.
|
||||
/// </summary>
|
||||
public string XPath { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Html Attribute name
|
||||
/// </summary>
|
||||
public string AttributeName { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The methode of output
|
||||
/// </summary>
|
||||
public ReturnType NodeReturnType { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Specify Xpath to find related Html Node.
|
||||
/// </summary>
|
||||
/// <param name="xpathString"></param>
|
||||
public XPathAttribute(string xpathString)
|
||||
{
|
||||
XPath = xpathString;
|
||||
NodeReturnType = ReturnType.InnerText;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Specify Xpath to find related Html Node.
|
||||
/// </summary>
|
||||
/// <param name="xpathString"></param>
|
||||
/// <param name="nodeReturnType">Specify you want the output include html text too.</param>
|
||||
public XPathAttribute(string xpathString, ReturnType nodeReturnType)
|
||||
{
|
||||
XPath = xpathString;
|
||||
NodeReturnType = nodeReturnType;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Specify Xpath and Attribute to find related Html Node and its attribute value.
|
||||
/// </summary>
|
||||
/// <param name="xpathString"></param>
|
||||
/// <param name="attributeName"></param>
|
||||
public XPathAttribute(string xpathString, string attributeName)
|
||||
{
|
||||
XPath = xpathString;
|
||||
AttributeName = attributeName;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Tagging a property with this Attribute make Encapsulator to ignore that property if it causes an error.
|
||||
/// </summary>
|
||||
[AttributeUsage(AttributeTargets.Property, Inherited = false, AllowMultiple = false)]
|
||||
public sealed class SkipNodeNotFoundAttribute : Attribute
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Exception that often occures when there is no way to bind a XPath to a Html Tag.
|
||||
/// </summary>
|
||||
public class NodeNotFoundException : Exception
|
||||
{
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public NodeNotFoundException() { }
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="message"></param>
|
||||
public NodeNotFoundException(string message) : base(message) { }
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="message"></param>
|
||||
/// <param name="inner"></param>
|
||||
public NodeNotFoundException(string message, Exception inner) : base(message, inner) { }
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Exception that often occures when there is no way to bind a XPath to a HtmlTag Attribute.
|
||||
/// </summary>
|
||||
public class NodeAttributeNotFoundException : Exception
|
||||
{
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public NodeAttributeNotFoundException() { }
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="message"></param>
|
||||
public NodeAttributeNotFoundException(string message) : base(message) { }
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="message"></param>
|
||||
/// <param name="inner"></param>
|
||||
public NodeAttributeNotFoundException(string message, Exception inner) : base(message, inner) { }
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Exception that often occures when there is no property that assigned with XPath Property in Class.
|
||||
/// </summary>
|
||||
public class MissingXPathException : Exception
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public MissingXPathException() { }
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="message"></param>
|
||||
public MissingXPathException(string message) : base(message) { }
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="message"></param>
|
||||
/// <param name="inner"></param>
|
||||
public MissingXPathException(string message, Exception inner) : base(message, inner) { }
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#if FX20
|
||||
namespace System.Runtime.CompilerServices
|
||||
{
|
||||
[AttributeUsage(AttributeTargets.Method |
|
||||
AttributeTargets.Class | AttributeTargets.Assembly)]
|
||||
public sealed class ExtensionAttribute : Attribute
|
||||
{
|
||||
}
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
132
Source/MyDb/HtmlAgilityPack.Shared/HtmlNode.Xpath.cs
Normal file
132
Source/MyDb/HtmlAgilityPack.Shared/HtmlNode.Xpath.cs
Normal file
|
|
@ -0,0 +1,132 @@
|
|||
// Description: Html Agility Pack - HTML Parsers, selectors, traversors, manupulators.
|
||||
// Website & Documentation: http://html-agility-pack.net
|
||||
// Forum & Issues: https://github.com/zzzprojects/html-agility-pack
|
||||
// License: https://github.com/zzzprojects/html-agility-pack/blob/master/LICENSE
|
||||
// More projects: http://www.zzzprojects.com/
|
||||
// Copyright © ZZZ Projects Inc. 2014 - 2017. All rights reserved.
|
||||
|
||||
#if !METRO
|
||||
|
||||
using System;
|
||||
using System.Xml.XPath;
|
||||
|
||||
namespace HtmlAgilityPack
|
||||
{
|
||||
public partial class HtmlNode : IXPathNavigable
|
||||
{
|
||||
/// <summary>
|
||||
/// Creates a new XPathNavigator object for navigating this HTML node.
|
||||
/// </summary>
|
||||
/// <returns>An XPathNavigator object. The XPathNavigator is positioned on the node from which the method was called. It is not positioned on the root of the document.</returns>
|
||||
public XPathNavigator CreateNavigator()
|
||||
{
|
||||
return new HtmlNodeNavigator(OwnerDocument, this);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates an XPathNavigator using the root of this document.
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public XPathNavigator CreateRootNavigator()
|
||||
{
|
||||
return new HtmlNodeNavigator(OwnerDocument, OwnerDocument.DocumentNode);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Selects a list of nodes matching the <see cref="XPath"/> expression.
|
||||
/// </summary>
|
||||
/// <param name="xpath">The XPath expression.</param>
|
||||
/// <returns>An <see cref="HtmlNodeCollection"/> containing a collection of nodes matching the <see cref="XPath"/> query, or <c>null</c> if no node matched the XPath expression.</returns>
|
||||
public HtmlNodeCollection SelectNodes(string xpath)
|
||||
{
|
||||
HtmlNodeCollection list = new HtmlNodeCollection(null);
|
||||
|
||||
HtmlNodeNavigator nav = new HtmlNodeNavigator(OwnerDocument, this);
|
||||
XPathNodeIterator it = nav.Select(xpath);
|
||||
while (it.MoveNext())
|
||||
{
|
||||
HtmlNodeNavigator n = (HtmlNodeNavigator) it.Current;
|
||||
list.Add(n.CurrentNode, false);
|
||||
}
|
||||
|
||||
if (list.Count == 0 && !OwnerDocument.OptionEmptyCollection)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Selects a list of nodes matching the <see cref="XPath"/> expression.
|
||||
/// </summary>
|
||||
/// <param name="xpath">The XPath expression.</param>
|
||||
/// <returns>An <see cref="HtmlNodeCollection"/> containing a collection of nodes matching the <see cref="XPath"/> query, or <c>null</c> if no node matched the XPath expression.</returns>
|
||||
public HtmlNodeCollection SelectNodes(XPathExpression xpath)
|
||||
{
|
||||
HtmlNodeCollection list = new HtmlNodeCollection(null);
|
||||
|
||||
HtmlNodeNavigator nav = new HtmlNodeNavigator(OwnerDocument, this);
|
||||
XPathNodeIterator it = nav.Select(xpath);
|
||||
while (it.MoveNext())
|
||||
{
|
||||
HtmlNodeNavigator n = (HtmlNodeNavigator) it.Current;
|
||||
list.Add(n.CurrentNode, false);
|
||||
}
|
||||
|
||||
if (list.Count == 0 && !OwnerDocument.OptionEmptyCollection)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Selects the first XmlNode that matches the XPath expression.
|
||||
/// </summary>
|
||||
/// <param name="xpath">The XPath expression. May not be null.</param>
|
||||
/// <returns>The first <see cref="HtmlNode"/> that matches the XPath query or a null reference if no matching node was found.</returns>
|
||||
public HtmlNode SelectSingleNode(string xpath)
|
||||
{
|
||||
if (xpath == null)
|
||||
{
|
||||
throw new ArgumentNullException("xpath");
|
||||
}
|
||||
|
||||
HtmlNodeNavigator nav = new HtmlNodeNavigator(OwnerDocument, this);
|
||||
XPathNodeIterator it = nav.Select(xpath);
|
||||
if (!it.MoveNext())
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
HtmlNodeNavigator node = (HtmlNodeNavigator) it.Current;
|
||||
return node.CurrentNode;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Selects a list of nodes matching the <see cref="XPath"/> expression.
|
||||
/// </summary>
|
||||
/// <param name="xpath">The XPath expression.</param>
|
||||
/// <returns>An <see cref="HtmlNodeCollection"/> containing a collection of nodes matching the <see cref="XPath"/> query, or <c>null</c> if no node matched the XPath expression.</returns>
|
||||
public HtmlNode SelectSingleNode(XPathExpression xpath)
|
||||
{
|
||||
if (xpath == null)
|
||||
{
|
||||
throw new ArgumentNullException("xpath");
|
||||
}
|
||||
|
||||
HtmlNodeNavigator nav = new HtmlNodeNavigator(OwnerDocument, this);
|
||||
XPathNodeIterator it = nav.Select(xpath);
|
||||
if (!it.MoveNext())
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
HtmlNodeNavigator node = (HtmlNodeNavigator)it.Current;
|
||||
return node.CurrentNode;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
2700
Source/MyDb/HtmlAgilityPack.Shared/HtmlNode.cs
Normal file
2700
Source/MyDb/HtmlAgilityPack.Shared/HtmlNode.cs
Normal file
File diff suppressed because it is too large
Load Diff
496
Source/MyDb/HtmlAgilityPack.Shared/HtmlNodeCollection.cs
Normal file
496
Source/MyDb/HtmlAgilityPack.Shared/HtmlNodeCollection.cs
Normal file
|
|
@ -0,0 +1,496 @@
|
|||
// Description: Html Agility Pack - HTML Parsers, selectors, traversors, manupulators.
|
||||
// Website & Documentation: http://html-agility-pack.net
|
||||
// Forum & Issues: https://github.com/zzzprojects/html-agility-pack
|
||||
// License: https://github.com/zzzprojects/html-agility-pack/blob/master/LICENSE
|
||||
// More projects: http://www.zzzprojects.com/
|
||||
// Copyright © ZZZ Projects Inc. 2014 - 2017. All rights reserved.
|
||||
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace HtmlAgilityPack
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents a combined list and collection of HTML nodes.
|
||||
/// </summary>
|
||||
public class HtmlNodeCollection : IList<HtmlNode>
|
||||
{
|
||||
#region Fields
|
||||
|
||||
private readonly HtmlNode _parentnode;
|
||||
private readonly List<HtmlNode> _items = new List<HtmlNode>();
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constructors
|
||||
|
||||
/// <summary>
|
||||
/// Initialize the HtmlNodeCollection with the base parent node
|
||||
/// </summary>
|
||||
/// <param name="parentnode">The base node of the collection</param>
|
||||
public HtmlNodeCollection(HtmlNode parentnode)
|
||||
{
|
||||
_parentnode = parentnode; // may be null
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Properties
|
||||
|
||||
/// <summary>Gets the parent node associated to the collection.</summary>
|
||||
internal HtmlNode ParentNode
|
||||
{
|
||||
get
|
||||
{
|
||||
return _parentnode;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a given node from the list.
|
||||
/// </summary>
|
||||
public int this[HtmlNode node]
|
||||
{
|
||||
get
|
||||
{
|
||||
int index = GetNodeIndex(node);
|
||||
if (index == -1)
|
||||
throw new ArgumentOutOfRangeException("node",
|
||||
"Node \"" + node.CloneNode(false).OuterHtml +
|
||||
"\" was not found in the collection");
|
||||
return index;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get node with tag name
|
||||
/// </summary>
|
||||
/// <param name="nodeName"></param>
|
||||
/// <returns></returns>
|
||||
public HtmlNode this[string nodeName]
|
||||
{
|
||||
get
|
||||
{
|
||||
for (int i = 0; i < _items.Count; i++)
|
||||
if (string.Equals(_items[i].Name, nodeName, StringComparison.OrdinalIgnoreCase))
|
||||
return _items[i];
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region IList<HtmlNode> Members
|
||||
|
||||
/// <summary>
|
||||
/// Gets the number of elements actually contained in the list.
|
||||
/// </summary>
|
||||
public int Count
|
||||
{
|
||||
get { return _items.Count; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Is collection read only
|
||||
/// </summary>
|
||||
public bool IsReadOnly
|
||||
{
|
||||
get { return false; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the node at the specified index.
|
||||
/// </summary>
|
||||
public HtmlNode this[int index]
|
||||
{
|
||||
get { return _items[index]; }
|
||||
set { _items[index] = value; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Add node to the collection
|
||||
/// </summary>
|
||||
/// <param name="node"></param>
|
||||
public void Add(HtmlNode node)
|
||||
{
|
||||
Add(node, true);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Add node to the collection
|
||||
/// </summary>
|
||||
/// <param name="node"></param>
|
||||
/// <param name="setParent"></param>
|
||||
public void Add(HtmlNode node, bool setParent)
|
||||
{
|
||||
_items.Add(node);
|
||||
|
||||
if (setParent)
|
||||
{
|
||||
node.ParentNode = _parentnode;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Clears out the collection of HtmlNodes. Removes each nodes reference to parentnode, nextnode and prevnode
|
||||
/// </summary>
|
||||
public void Clear()
|
||||
{
|
||||
foreach (HtmlNode node in _items)
|
||||
{
|
||||
node.ParentNode = null;
|
||||
node.NextSibling = null;
|
||||
node.PreviousSibling = null;
|
||||
}
|
||||
|
||||
_items.Clear();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets existence of node in collection
|
||||
/// </summary>
|
||||
/// <param name="item"></param>
|
||||
/// <returns></returns>
|
||||
public bool Contains(HtmlNode item)
|
||||
{
|
||||
return _items.Contains(item);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Copy collection to array
|
||||
/// </summary>
|
||||
/// <param name="array"></param>
|
||||
/// <param name="arrayIndex"></param>
|
||||
public void CopyTo(HtmlNode[] array, int arrayIndex)
|
||||
{
|
||||
_items.CopyTo(array, arrayIndex);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get Enumerator
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
IEnumerator<HtmlNode> IEnumerable<HtmlNode>.GetEnumerator()
|
||||
{
|
||||
return _items.GetEnumerator();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get Explicit Enumerator
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
IEnumerator IEnumerable.GetEnumerator()
|
||||
{
|
||||
return _items.GetEnumerator();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get index of node
|
||||
/// </summary>
|
||||
/// <param name="item"></param>
|
||||
/// <returns></returns>
|
||||
public int IndexOf(HtmlNode item)
|
||||
{
|
||||
return _items.IndexOf(item);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Insert node at index
|
||||
/// </summary>
|
||||
/// <param name="index"></param>
|
||||
/// <param name="node"></param>
|
||||
public void Insert(int index, HtmlNode node)
|
||||
{
|
||||
HtmlNode next = null;
|
||||
HtmlNode prev = null;
|
||||
|
||||
if (index > 0)
|
||||
prev = _items[index - 1];
|
||||
|
||||
if (index < _items.Count)
|
||||
next = _items[index];
|
||||
|
||||
_items.Insert(index, node);
|
||||
|
||||
if (prev != null)
|
||||
{
|
||||
if (node == prev)
|
||||
throw new InvalidProgramException("Unexpected error.");
|
||||
|
||||
prev._nextnode = node;
|
||||
}
|
||||
|
||||
if (next != null)
|
||||
next._prevnode = node;
|
||||
|
||||
node._prevnode = prev;
|
||||
if (next == node)
|
||||
throw new InvalidProgramException("Unexpected error.");
|
||||
|
||||
node._nextnode = next;
|
||||
node.SetParent(_parentnode);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Remove node
|
||||
/// </summary>
|
||||
/// <param name="item"></param>
|
||||
/// <returns></returns>
|
||||
public bool Remove(HtmlNode item)
|
||||
{
|
||||
int i = _items.IndexOf(item);
|
||||
RemoveAt(i);
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Remove <see cref="HtmlNode"/> at index
|
||||
/// </summary>
|
||||
/// <param name="index"></param>
|
||||
public void RemoveAt(int index)
|
||||
{
|
||||
HtmlNode next = null;
|
||||
HtmlNode prev = null;
|
||||
HtmlNode oldnode = _items[index];
|
||||
|
||||
// KEEP a reference since it will be set to null
|
||||
var parentNode = _parentnode ?? oldnode._parentnode;
|
||||
|
||||
if (index > 0)
|
||||
prev = _items[index - 1];
|
||||
|
||||
if (index < (_items.Count - 1))
|
||||
next = _items[index + 1];
|
||||
|
||||
_items.RemoveAt(index);
|
||||
|
||||
if (prev != null)
|
||||
{
|
||||
if (next == prev)
|
||||
throw new InvalidProgramException("Unexpected error.");
|
||||
prev._nextnode = next;
|
||||
}
|
||||
|
||||
if (next != null)
|
||||
next._prevnode = prev;
|
||||
|
||||
oldnode._prevnode = null;
|
||||
oldnode._nextnode = null;
|
||||
oldnode._parentnode = null;
|
||||
|
||||
if (parentNode != null)
|
||||
{
|
||||
parentNode.SetChanged();
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Public Methods
|
||||
|
||||
/// <summary>
|
||||
/// Get first instance of node in supplied collection
|
||||
/// </summary>
|
||||
/// <param name="items"></param>
|
||||
/// <param name="name"></param>
|
||||
/// <returns></returns>
|
||||
public static HtmlNode FindFirst(HtmlNodeCollection items, string name)
|
||||
{
|
||||
foreach (HtmlNode node in items)
|
||||
{
|
||||
if (node.Name.Equals(name, StringComparison.OrdinalIgnoreCase))
|
||||
return node;
|
||||
if (!node.HasChildNodes) continue;
|
||||
HtmlNode returnNode = FindFirst(node.ChildNodes, name);
|
||||
if (returnNode != null)
|
||||
return returnNode;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Add node to the end of the collection
|
||||
/// </summary>
|
||||
/// <param name="node"></param>
|
||||
public void Append(HtmlNode node)
|
||||
{
|
||||
HtmlNode last = null;
|
||||
if (_items.Count > 0)
|
||||
last = _items[_items.Count - 1];
|
||||
|
||||
_items.Add(node);
|
||||
node._prevnode = last;
|
||||
node._nextnode = null;
|
||||
node.SetParent(_parentnode);
|
||||
if (last == null) return;
|
||||
if (last == node)
|
||||
throw new InvalidProgramException("Unexpected error.");
|
||||
|
||||
last._nextnode = node;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get first instance of node with name
|
||||
/// </summary>
|
||||
/// <param name="name"></param>
|
||||
/// <returns></returns>
|
||||
public HtmlNode FindFirst(string name)
|
||||
{
|
||||
return FindFirst(this, name);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get index of node
|
||||
/// </summary>
|
||||
/// <param name="node"></param>
|
||||
/// <returns></returns>
|
||||
public int GetNodeIndex(HtmlNode node)
|
||||
{
|
||||
// TODO: should we rewrite this? what would be the key of a node?
|
||||
for (int i = 0; i < _items.Count; i++)
|
||||
if (node == _items[i])
|
||||
return i;
|
||||
return -1;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Add node to the beginning of the collection
|
||||
/// </summary>
|
||||
/// <param name="node"></param>
|
||||
public void Prepend(HtmlNode node)
|
||||
{
|
||||
HtmlNode first = null;
|
||||
if (_items.Count > 0)
|
||||
first = _items[0];
|
||||
|
||||
_items.Insert(0, node);
|
||||
|
||||
if (node == first)
|
||||
throw new InvalidProgramException("Unexpected error.");
|
||||
node._nextnode = first;
|
||||
node._prevnode = null;
|
||||
node.SetParent(_parentnode);
|
||||
|
||||
if (first != null)
|
||||
first._prevnode = node;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Remove node at index
|
||||
/// </summary>
|
||||
/// <param name="index"></param>
|
||||
/// <returns></returns>
|
||||
public bool Remove(int index)
|
||||
{
|
||||
RemoveAt(index);
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Replace node at index
|
||||
/// </summary>
|
||||
/// <param name="index"></param>
|
||||
/// <param name="node"></param>
|
||||
public void Replace(int index, HtmlNode node)
|
||||
{
|
||||
HtmlNode next = null;
|
||||
HtmlNode prev = null;
|
||||
HtmlNode oldnode = _items[index];
|
||||
|
||||
if (index > 0)
|
||||
prev = _items[index - 1];
|
||||
|
||||
if (index < (_items.Count - 1))
|
||||
next = _items[index + 1];
|
||||
|
||||
_items[index] = node;
|
||||
|
||||
if (prev != null)
|
||||
{
|
||||
if (node == prev)
|
||||
throw new InvalidProgramException("Unexpected error.");
|
||||
prev._nextnode = node;
|
||||
}
|
||||
|
||||
if (next != null)
|
||||
next._prevnode = node;
|
||||
|
||||
node._prevnode = prev;
|
||||
|
||||
if (next == node)
|
||||
throw new InvalidProgramException("Unexpected error.");
|
||||
|
||||
node._nextnode = next;
|
||||
node.SetParent(_parentnode);
|
||||
|
||||
oldnode._prevnode = null;
|
||||
oldnode._nextnode = null;
|
||||
oldnode._parentnode = null;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region LINQ Methods
|
||||
|
||||
/// <summary>
|
||||
/// Get all node descended from this collection
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public IEnumerable<HtmlNode> Descendants()
|
||||
{
|
||||
foreach (HtmlNode item in _items)
|
||||
foreach (HtmlNode n in item.Descendants())
|
||||
yield return n;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get all node descended from this collection with matching name
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public IEnumerable<HtmlNode> Descendants(string name)
|
||||
{
|
||||
foreach (HtmlNode item in _items)
|
||||
foreach (HtmlNode n in item.Descendants(name))
|
||||
yield return n;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets all first generation elements in collection
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public IEnumerable<HtmlNode> Elements()
|
||||
{
|
||||
foreach (HtmlNode item in _items)
|
||||
foreach (HtmlNode n in item.ChildNodes)
|
||||
yield return n;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets all first generation elements matching name
|
||||
/// </summary>
|
||||
/// <param name="name"></param>
|
||||
/// <returns></returns>
|
||||
public IEnumerable<HtmlNode> Elements(string name)
|
||||
{
|
||||
foreach (HtmlNode item in _items)
|
||||
foreach (HtmlNode n in item.Elements(name))
|
||||
yield return n;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// All first generation nodes in collection
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public IEnumerable<HtmlNode> Nodes()
|
||||
{
|
||||
foreach (HtmlNode item in _items)
|
||||
foreach (HtmlNode n in item.ChildNodes)
|
||||
yield return n;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
959
Source/MyDb/HtmlAgilityPack.Shared/HtmlNodeNavigator.cs
Normal file
959
Source/MyDb/HtmlAgilityPack.Shared/HtmlNodeNavigator.cs
Normal file
|
|
@ -0,0 +1,959 @@
|
|||
// Description: Html Agility Pack - HTML Parsers, selectors, traversors, manupulators.
|
||||
// Website & Documentation: http://html-agility-pack.net
|
||||
// Forum & Issues: https://github.com/zzzprojects/html-agility-pack
|
||||
// License: https://github.com/zzzprojects/html-agility-pack/blob/master/LICENSE
|
||||
// More projects: http://www.zzzprojects.com/
|
||||
// Copyright © ZZZ Projects Inc. 2014 - 2017. All rights reserved.
|
||||
|
||||
#if !METRO
|
||||
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using System.Xml;
|
||||
using System.Xml.XPath;
|
||||
|
||||
#pragma warning disable 0649
|
||||
namespace HtmlAgilityPack
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents an HTML navigator on an HTML document seen as a data store.
|
||||
/// </summary>
|
||||
public class HtmlNodeNavigator : XPathNavigator
|
||||
{
|
||||
#region Fields
|
||||
|
||||
private int _attindex;
|
||||
private HtmlNode _currentnode;
|
||||
private readonly HtmlDocument _doc;
|
||||
private readonly HtmlNameTable _nametable;
|
||||
|
||||
internal bool Trace;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constructors
|
||||
|
||||
internal HtmlNodeNavigator()
|
||||
{
|
||||
_doc = new HtmlDocument();
|
||||
_nametable = new HtmlNameTable();
|
||||
Reset();
|
||||
}
|
||||
|
||||
internal HtmlNodeNavigator(HtmlDocument doc, HtmlNode currentNode)
|
||||
{
|
||||
if (currentNode == null)
|
||||
{
|
||||
throw new ArgumentNullException("currentNode");
|
||||
}
|
||||
|
||||
if (currentNode.OwnerDocument != doc)
|
||||
{
|
||||
throw new ArgumentException(HtmlDocument.HtmlExceptionRefNotChild);
|
||||
}
|
||||
|
||||
if (doc == null)
|
||||
{
|
||||
// keep in message, currentNode.OwnerDocument also null.
|
||||
throw new Exception("Oops! The HtmlDocument cannot be null.");
|
||||
}
|
||||
|
||||
#if TRACE_NAVIGATOR
|
||||
InternalTrace(null);
|
||||
#endif
|
||||
|
||||
_doc = doc;
|
||||
_nametable = new HtmlNameTable();
|
||||
Reset();
|
||||
_currentnode = currentNode;
|
||||
}
|
||||
|
||||
private HtmlNodeNavigator(HtmlNodeNavigator nav)
|
||||
{
|
||||
if (nav == null)
|
||||
{
|
||||
throw new ArgumentNullException("nav");
|
||||
}
|
||||
#if TRACE_NAVIGATOR
|
||||
InternalTrace(null);
|
||||
#endif
|
||||
_doc = nav._doc;
|
||||
_currentnode = nav._currentnode;
|
||||
_attindex = nav._attindex;
|
||||
_nametable = nav._nametable; // REVIEW: should we do this?
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the HtmlNavigator and loads an HTML document from a stream.
|
||||
/// </summary>
|
||||
/// <param name="stream">The input stream.</param>
|
||||
public HtmlNodeNavigator(Stream stream)
|
||||
{
|
||||
_doc = new HtmlDocument();
|
||||
_nametable = new HtmlNameTable();
|
||||
_doc.Load(stream);
|
||||
Reset();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the HtmlNavigator and loads an HTML document from a stream.
|
||||
/// </summary>
|
||||
/// <param name="stream">The input stream.</param>
|
||||
/// <param name="detectEncodingFromByteOrderMarks">Indicates whether to look for byte order marks at the beginning of the stream.</param>
|
||||
public HtmlNodeNavigator(Stream stream, bool detectEncodingFromByteOrderMarks)
|
||||
{
|
||||
_doc = new HtmlDocument();
|
||||
_nametable = new HtmlNameTable();
|
||||
_doc.Load(stream, detectEncodingFromByteOrderMarks);
|
||||
Reset();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the HtmlNavigator and loads an HTML document from a stream.
|
||||
/// </summary>
|
||||
/// <param name="stream">The input stream.</param>
|
||||
/// <param name="encoding">The character encoding to use.</param>
|
||||
public HtmlNodeNavigator(Stream stream, Encoding encoding)
|
||||
{
|
||||
_doc = new HtmlDocument();
|
||||
_nametable = new HtmlNameTable();
|
||||
_doc.Load(stream, encoding);
|
||||
Reset();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the HtmlNavigator and loads an HTML document from a stream.
|
||||
/// </summary>
|
||||
/// <param name="stream">The input stream.</param>
|
||||
/// <param name="encoding">The character encoding to use.</param>
|
||||
/// <param name="detectEncodingFromByteOrderMarks">Indicates whether to look for byte order marks at the beginning of the stream.</param>
|
||||
public HtmlNodeNavigator(Stream stream, Encoding encoding, bool detectEncodingFromByteOrderMarks)
|
||||
{
|
||||
_doc = new HtmlDocument();
|
||||
_nametable = new HtmlNameTable();
|
||||
_doc.Load(stream, encoding, detectEncodingFromByteOrderMarks);
|
||||
Reset();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the HtmlNavigator and loads an HTML document from a stream.
|
||||
/// </summary>
|
||||
/// <param name="stream">The input stream.</param>
|
||||
/// <param name="encoding">The character encoding to use.</param>
|
||||
/// <param name="detectEncodingFromByteOrderMarks">Indicates whether to look for byte order marks at the beginning of the stream.</param>
|
||||
/// <param name="buffersize">The minimum buffer size.</param>
|
||||
public HtmlNodeNavigator(Stream stream, Encoding encoding, bool detectEncodingFromByteOrderMarks, int buffersize)
|
||||
{
|
||||
_doc = new HtmlDocument();
|
||||
_nametable = new HtmlNameTable();
|
||||
_doc.Load(stream, encoding, detectEncodingFromByteOrderMarks, buffersize);
|
||||
Reset();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the HtmlNavigator and loads an HTML document from a TextReader.
|
||||
/// </summary>
|
||||
/// <param name="reader">The TextReader used to feed the HTML data into the document.</param>
|
||||
public HtmlNodeNavigator(TextReader reader)
|
||||
{
|
||||
_doc = new HtmlDocument();
|
||||
_nametable = new HtmlNameTable();
|
||||
_doc.Load(reader);
|
||||
Reset();
|
||||
}
|
||||
|
||||
#if !(NETSTANDARD1_3 || NETSTANDARD1_6)
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the HtmlNavigator and loads an HTML document from a file.
|
||||
/// </summary>
|
||||
/// <param name="path">The complete file path to be read.</param>
|
||||
public HtmlNodeNavigator(string path)
|
||||
{
|
||||
_doc = new HtmlDocument();
|
||||
_nametable = new HtmlNameTable();
|
||||
_doc.Load(path);
|
||||
Reset();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the HtmlNavigator and loads an HTML document from a file.
|
||||
/// </summary>
|
||||
/// <param name="path">The complete file path to be read.</param>
|
||||
/// <param name="detectEncodingFromByteOrderMarks">Indicates whether to look for byte order marks at the beginning of the file.</param>
|
||||
public HtmlNodeNavigator(string path, bool detectEncodingFromByteOrderMarks)
|
||||
{
|
||||
_doc = new HtmlDocument();
|
||||
_nametable = new HtmlNameTable();
|
||||
_doc.Load(path, detectEncodingFromByteOrderMarks);
|
||||
Reset();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the HtmlNavigator and loads an HTML document from a file.
|
||||
/// </summary>
|
||||
/// <param name="path">The complete file path to be read.</param>
|
||||
/// <param name="encoding">The character encoding to use.</param>
|
||||
public HtmlNodeNavigator(string path, Encoding encoding)
|
||||
{
|
||||
_doc = new HtmlDocument();
|
||||
_nametable = new HtmlNameTable();
|
||||
_doc.Load(path, encoding);
|
||||
Reset();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the HtmlNavigator and loads an HTML document from a file.
|
||||
/// </summary>
|
||||
/// <param name="path">The complete file path to be read.</param>
|
||||
/// <param name="encoding">The character encoding to use.</param>
|
||||
/// <param name="detectEncodingFromByteOrderMarks">Indicates whether to look for byte order marks at the beginning of the file.</param>
|
||||
public HtmlNodeNavigator(string path, Encoding encoding, bool detectEncodingFromByteOrderMarks)
|
||||
{
|
||||
_doc = new HtmlDocument();
|
||||
_nametable = new HtmlNameTable();
|
||||
_doc.Load(path, encoding, detectEncodingFromByteOrderMarks);
|
||||
Reset();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the HtmlNavigator and loads an HTML document from a file.
|
||||
/// </summary>
|
||||
/// <param name="path">The complete file path to be read.</param>
|
||||
/// <param name="encoding">The character encoding to use.</param>
|
||||
/// <param name="detectEncodingFromByteOrderMarks">Indicates whether to look for byte order marks at the beginning of the file.</param>
|
||||
/// <param name="buffersize">The minimum buffer size.</param>
|
||||
public HtmlNodeNavigator(string path, Encoding encoding, bool detectEncodingFromByteOrderMarks, int buffersize)
|
||||
{
|
||||
_doc = new HtmlDocument();
|
||||
_nametable = new HtmlNameTable();
|
||||
_doc.Load(path, encoding, detectEncodingFromByteOrderMarks, buffersize);
|
||||
Reset();
|
||||
}
|
||||
#endif
|
||||
|
||||
#endregion
|
||||
|
||||
#region Properties
|
||||
|
||||
/// <summary>
|
||||
/// Gets the base URI for the current node.
|
||||
/// Always returns string.Empty in the case of HtmlNavigator implementation.
|
||||
/// </summary>
|
||||
public override string BaseURI
|
||||
{
|
||||
get
|
||||
{
|
||||
#if TRACE_NAVIGATOR
|
||||
InternalTrace(">");
|
||||
#endif
|
||||
return _nametable.GetOrAdd(string.Empty);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the current HTML document.
|
||||
/// </summary>
|
||||
public HtmlDocument CurrentDocument
|
||||
{
|
||||
get { return _doc; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the current HTML node.
|
||||
/// </summary>
|
||||
public HtmlNode CurrentNode
|
||||
{
|
||||
get { return _currentnode; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether the current node has child nodes.
|
||||
/// </summary>
|
||||
public override bool HasAttributes
|
||||
{
|
||||
get
|
||||
{
|
||||
#if TRACE_NAVIGATOR
|
||||
InternalTrace(">" + (_currentnode.Attributes.Count > 0));
|
||||
#endif
|
||||
return (_currentnode.Attributes.Count > 0);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether the current node has child nodes.
|
||||
/// </summary>
|
||||
public override bool HasChildren
|
||||
{
|
||||
get
|
||||
{
|
||||
#if TRACE_NAVIGATOR
|
||||
InternalTrace(">" + (_currentnode.ChildNodes.Count > 0));
|
||||
#endif
|
||||
return (_currentnode.ChildNodes.Count > 0);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether the current node is an empty element.
|
||||
/// </summary>
|
||||
public override bool IsEmptyElement
|
||||
{
|
||||
get
|
||||
{
|
||||
#if TRACE_NAVIGATOR
|
||||
InternalTrace(">" + !HasChildren);
|
||||
#endif
|
||||
// REVIEW: is this ok?
|
||||
return !HasChildren;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the name of the current HTML node without the namespace prefix.
|
||||
/// </summary>
|
||||
public override string LocalName
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_attindex != -1)
|
||||
{
|
||||
#if TRACE_NAVIGATOR
|
||||
InternalTrace("att>" + _currentnode.Attributes[_attindex].Name);
|
||||
#endif
|
||||
return _nametable.GetOrAdd(_currentnode.Attributes[_attindex].Name);
|
||||
}
|
||||
|
||||
#if TRACE_NAVIGATOR
|
||||
InternalTrace("node>" + _currentnode.Name);
|
||||
#endif
|
||||
return _nametable.GetOrAdd(_currentnode.Name);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the qualified name of the current node.
|
||||
/// </summary>
|
||||
public override string Name
|
||||
{
|
||||
get
|
||||
{
|
||||
#if TRACE_NAVIGATOR
|
||||
InternalTrace(">" + _currentnode.Name);
|
||||
#endif
|
||||
return _nametable.GetOrAdd(_currentnode.Name);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the namespace URI (as defined in the W3C Namespace Specification) of the current node.
|
||||
/// Always returns string.Empty in the case of HtmlNavigator implementation.
|
||||
/// </summary>
|
||||
public override string NamespaceURI
|
||||
{
|
||||
get
|
||||
{
|
||||
#if TRACE_NAVIGATOR
|
||||
InternalTrace(">");
|
||||
#endif
|
||||
return _nametable.GetOrAdd(string.Empty);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the <see cref="XmlNameTable"/> associated with this implementation.
|
||||
/// </summary>
|
||||
public override XmlNameTable NameTable
|
||||
{
|
||||
get
|
||||
{
|
||||
#if TRACE_NAVIGATOR
|
||||
InternalTrace(null);
|
||||
#endif
|
||||
return _nametable;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the type of the current node.
|
||||
/// </summary>
|
||||
public override XPathNodeType NodeType
|
||||
{
|
||||
get
|
||||
{
|
||||
switch (_currentnode.NodeType)
|
||||
{
|
||||
case HtmlNodeType.Comment:
|
||||
#if TRACE_NAVIGATOR
|
||||
InternalTrace(">" + XPathNodeType.Comment);
|
||||
#endif
|
||||
return XPathNodeType.Comment;
|
||||
|
||||
case HtmlNodeType.Document:
|
||||
#if TRACE_NAVIGATOR
|
||||
InternalTrace(">" + XPathNodeType.Root);
|
||||
#endif
|
||||
return XPathNodeType.Root;
|
||||
|
||||
case HtmlNodeType.Text:
|
||||
#if TRACE_NAVIGATOR
|
||||
InternalTrace(">" + XPathNodeType.Text);
|
||||
#endif
|
||||
return XPathNodeType.Text;
|
||||
|
||||
case HtmlNodeType.Element:
|
||||
{
|
||||
if (_attindex != -1)
|
||||
{
|
||||
#if TRACE_NAVIGATOR
|
||||
InternalTrace(">" + XPathNodeType.Attribute);
|
||||
#endif
|
||||
return XPathNodeType.Attribute;
|
||||
}
|
||||
|
||||
#if TRACE_NAVIGATOR
|
||||
InternalTrace(">" + XPathNodeType.Element);
|
||||
#endif
|
||||
return XPathNodeType.Element;
|
||||
}
|
||||
|
||||
default:
|
||||
throw new NotImplementedException("Internal error: Unhandled HtmlNodeType: " +
|
||||
_currentnode.NodeType);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the prefix associated with the current node.
|
||||
/// Always returns string.Empty in the case of HtmlNavigator implementation.
|
||||
/// </summary>
|
||||
public override string Prefix
|
||||
{
|
||||
get
|
||||
{
|
||||
#if TRACE_NAVIGATOR
|
||||
InternalTrace(null);
|
||||
#endif
|
||||
return _nametable.GetOrAdd(string.Empty);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the text value of the current node.
|
||||
/// </summary>
|
||||
public override string Value
|
||||
{
|
||||
get
|
||||
{
|
||||
#if TRACE_NAVIGATOR
|
||||
InternalTrace("nt=" + _currentnode.NodeType);
|
||||
#endif
|
||||
switch (_currentnode.NodeType)
|
||||
{
|
||||
case HtmlNodeType.Comment:
|
||||
#if TRACE_NAVIGATOR
|
||||
InternalTrace(">" + ((HtmlCommentNode) _currentnode).Comment);
|
||||
#endif
|
||||
return ((HtmlCommentNode) _currentnode).Comment;
|
||||
|
||||
case HtmlNodeType.Document:
|
||||
#if TRACE_NAVIGATOR
|
||||
InternalTrace(">");
|
||||
#endif
|
||||
return "";
|
||||
|
||||
case HtmlNodeType.Text:
|
||||
#if TRACE_NAVIGATOR
|
||||
InternalTrace(">" + ((HtmlTextNode) _currentnode).Text);
|
||||
#endif
|
||||
return ((HtmlTextNode) _currentnode).Text;
|
||||
|
||||
case HtmlNodeType.Element:
|
||||
{
|
||||
if (_attindex != -1)
|
||||
{
|
||||
#if TRACE_NAVIGATOR
|
||||
InternalTrace(">" + _currentnode.Attributes[_attindex].Value);
|
||||
#endif
|
||||
return _currentnode.Attributes[_attindex].Value;
|
||||
}
|
||||
|
||||
return _currentnode.InnerText;
|
||||
}
|
||||
|
||||
default:
|
||||
throw new NotImplementedException("Internal error: Unhandled HtmlNodeType: " +
|
||||
_currentnode.NodeType);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the xml:lang scope for the current node.
|
||||
/// Always returns string.Empty in the case of HtmlNavigator implementation.
|
||||
/// </summary>
|
||||
public override string XmlLang
|
||||
{
|
||||
get
|
||||
{
|
||||
#if TRACE_NAVIGATOR
|
||||
InternalTrace(null);
|
||||
#endif
|
||||
return _nametable.GetOrAdd(string.Empty);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Public Methods
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new HtmlNavigator positioned at the same node as this HtmlNavigator.
|
||||
/// </summary>
|
||||
/// <returns>A new HtmlNavigator object positioned at the same node as the original HtmlNavigator.</returns>
|
||||
public override XPathNavigator Clone()
|
||||
{
|
||||
#if TRACE_NAVIGATOR
|
||||
InternalTrace(null);
|
||||
#endif
|
||||
return new HtmlNodeNavigator(this);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the value of the HTML attribute with the specified LocalName and NamespaceURI.
|
||||
/// </summary>
|
||||
/// <param name="localName">The local name of the HTML attribute.</param>
|
||||
/// <param name="namespaceURI">The namespace URI of the attribute. Unsupported with the HtmlNavigator implementation.</param>
|
||||
/// <returns>The value of the specified HTML attribute. String.Empty or null if a matching attribute is not found or if the navigator is not positioned on an element node.</returns>
|
||||
public override string GetAttribute(string localName, string namespaceURI)
|
||||
{
|
||||
#if TRACE_NAVIGATOR
|
||||
InternalTrace("localName=" + localName + ", namespaceURI=" + namespaceURI);
|
||||
#endif
|
||||
HtmlAttribute att = _currentnode.Attributes[localName];
|
||||
if (att == null)
|
||||
{
|
||||
#if TRACE_NAVIGATOR
|
||||
InternalTrace(">null");
|
||||
#endif
|
||||
return null;
|
||||
}
|
||||
|
||||
#if TRACE_NAVIGATOR
|
||||
InternalTrace(">" + att.Value);
|
||||
#endif
|
||||
return att.Value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the value of the namespace node corresponding to the specified local name.
|
||||
/// Always returns string.Empty for the HtmlNavigator implementation.
|
||||
/// </summary>
|
||||
/// <param name="name">The local name of the namespace node.</param>
|
||||
/// <returns>Always returns string.Empty for the HtmlNavigator implementation.</returns>
|
||||
public override string GetNamespace(string name)
|
||||
{
|
||||
#if TRACE_NAVIGATOR
|
||||
InternalTrace("name=" + name);
|
||||
#endif
|
||||
return string.Empty;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Determines whether the current HtmlNavigator is at the same position as the specified HtmlNavigator.
|
||||
/// </summary>
|
||||
/// <param name="other">The HtmlNavigator that you want to compare against.</param>
|
||||
/// <returns>true if the two navigators have the same position, otherwise, false.</returns>
|
||||
public override bool IsSamePosition(XPathNavigator other)
|
||||
{
|
||||
HtmlNodeNavigator nav = other as HtmlNodeNavigator;
|
||||
if (nav == null)
|
||||
{
|
||||
#if TRACE_NAVIGATOR
|
||||
InternalTrace(">false");
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
|
||||
#if TRACE_NAVIGATOR
|
||||
InternalTrace(">" + (nav._currentnode == _currentnode));
|
||||
#endif
|
||||
return (nav._currentnode == _currentnode);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Moves to the same position as the specified HtmlNavigator.
|
||||
/// </summary>
|
||||
/// <param name="other">The HtmlNavigator positioned on the node that you want to move to.</param>
|
||||
/// <returns>true if successful, otherwise false. If false, the position of the navigator is unchanged.</returns>
|
||||
public override bool MoveTo(XPathNavigator other)
|
||||
{
|
||||
HtmlNodeNavigator nav = other as HtmlNodeNavigator;
|
||||
if (nav == null)
|
||||
{
|
||||
#if TRACE_NAVIGATOR
|
||||
InternalTrace(">false (nav is not an HtmlNodeNavigator)");
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
|
||||
#if TRACE_NAVIGATOR
|
||||
InternalTrace("moveto oid=" + nav.GetHashCode()
|
||||
+ ", n:" + nav._currentnode.Name
|
||||
+ ", a:" + nav._attindex);
|
||||
#endif
|
||||
|
||||
if (nav._doc == _doc)
|
||||
{
|
||||
_currentnode = nav._currentnode;
|
||||
_attindex = nav._attindex;
|
||||
#if TRACE_NAVIGATOR
|
||||
InternalTrace(">true");
|
||||
#endif
|
||||
return true;
|
||||
}
|
||||
|
||||
// we don't know how to handle that
|
||||
#if TRACE_NAVIGATOR
|
||||
InternalTrace(">false (???)");
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Moves to the HTML attribute with matching LocalName and NamespaceURI.
|
||||
/// </summary>
|
||||
/// <param name="localName">The local name of the HTML attribute.</param>
|
||||
/// <param name="namespaceURI">The namespace URI of the attribute. Unsupported with the HtmlNavigator implementation.</param>
|
||||
/// <returns>true if the HTML attribute is found, otherwise, false. If false, the position of the navigator does not change.</returns>
|
||||
public override bool MoveToAttribute(string localName, string namespaceURI)
|
||||
{
|
||||
#if TRACE_NAVIGATOR
|
||||
InternalTrace("localName=" + localName + ", namespaceURI=" + namespaceURI);
|
||||
#endif
|
||||
int index = _currentnode.Attributes.GetAttributeIndex(localName);
|
||||
if (index == -1)
|
||||
{
|
||||
#if TRACE_NAVIGATOR
|
||||
InternalTrace(">false");
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
|
||||
_attindex = index;
|
||||
#if TRACE_NAVIGATOR
|
||||
InternalTrace(">true");
|
||||
#endif
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Moves to the first sibling of the current node.
|
||||
/// </summary>
|
||||
/// <returns>true if the navigator is successful moving to the first sibling node, false if there is no first sibling or if the navigator is currently positioned on an attribute node.</returns>
|
||||
public override bool MoveToFirst()
|
||||
{
|
||||
if (_currentnode.ParentNode == null)
|
||||
{
|
||||
#if TRACE_NAVIGATOR
|
||||
InternalTrace(">false");
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
|
||||
if (_currentnode.ParentNode.FirstChild == null)
|
||||
{
|
||||
#if TRACE_NAVIGATOR
|
||||
InternalTrace(">false");
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
|
||||
_currentnode = _currentnode.ParentNode.FirstChild;
|
||||
#if TRACE_NAVIGATOR
|
||||
InternalTrace(">true");
|
||||
#endif
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Moves to the first HTML attribute.
|
||||
/// </summary>
|
||||
/// <returns>true if the navigator is successful moving to the first HTML attribute, otherwise, false.</returns>
|
||||
public override bool MoveToFirstAttribute()
|
||||
{
|
||||
if (!HasAttributes)
|
||||
{
|
||||
#if TRACE_NAVIGATOR
|
||||
InternalTrace(">false");
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
|
||||
_attindex = 0;
|
||||
#if TRACE_NAVIGATOR
|
||||
InternalTrace(">true");
|
||||
#endif
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Moves to the first child of the current node.
|
||||
/// </summary>
|
||||
/// <returns>true if there is a first child node, otherwise false.</returns>
|
||||
public override bool MoveToFirstChild()
|
||||
{
|
||||
if (!_currentnode.HasChildNodes)
|
||||
{
|
||||
#if TRACE_NAVIGATOR
|
||||
InternalTrace(">false");
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
|
||||
_currentnode = _currentnode.ChildNodes[0];
|
||||
#if TRACE_NAVIGATOR
|
||||
InternalTrace(">true");
|
||||
#endif
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Moves the XPathNavigator to the first namespace node of the current element.
|
||||
/// Always returns false for the HtmlNavigator implementation.
|
||||
/// </summary>
|
||||
/// <param name="scope">An XPathNamespaceScope value describing the namespace scope.</param>
|
||||
/// <returns>Always returns false for the HtmlNavigator implementation.</returns>
|
||||
public override bool MoveToFirstNamespace(XPathNamespaceScope scope)
|
||||
{
|
||||
#if TRACE_NAVIGATOR
|
||||
InternalTrace(null);
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Moves to the node that has an attribute of type ID whose value matches the specified string.
|
||||
/// </summary>
|
||||
/// <param name="id">A string representing the ID value of the node to which you want to move. This argument does not need to be atomized.</param>
|
||||
/// <returns>true if the move was successful, otherwise false. If false, the position of the navigator is unchanged.</returns>
|
||||
public override bool MoveToId(string id)
|
||||
{
|
||||
#if TRACE_NAVIGATOR
|
||||
InternalTrace("id=" + id);
|
||||
#endif
|
||||
HtmlNode node = _doc.GetElementbyId(id);
|
||||
if (node == null)
|
||||
{
|
||||
#if TRACE_NAVIGATOR
|
||||
InternalTrace(">false");
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
|
||||
_currentnode = node;
|
||||
#if TRACE_NAVIGATOR
|
||||
InternalTrace(">true");
|
||||
#endif
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Moves the XPathNavigator to the namespace node with the specified local name.
|
||||
/// Always returns false for the HtmlNavigator implementation.
|
||||
/// </summary>
|
||||
/// <param name="name">The local name of the namespace node.</param>
|
||||
/// <returns>Always returns false for the HtmlNavigator implementation.</returns>
|
||||
public override bool MoveToNamespace(string name)
|
||||
{
|
||||
#if TRACE_NAVIGATOR
|
||||
InternalTrace("name=" + name);
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Moves to the next sibling of the current node.
|
||||
/// </summary>
|
||||
/// <returns>true if the navigator is successful moving to the next sibling node, false if there are no more siblings or if the navigator is currently positioned on an attribute node. If false, the position of the navigator is unchanged.</returns>
|
||||
public override bool MoveToNext()
|
||||
{
|
||||
if (_currentnode.NextSibling == null)
|
||||
{
|
||||
#if TRACE_NAVIGATOR
|
||||
InternalTrace(">false");
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
|
||||
#if TRACE_NAVIGATOR
|
||||
InternalTrace("_c=" + _currentnode.CloneNode(false).OuterHtml);
|
||||
InternalTrace("_n=" + _currentnode.NextSibling.CloneNode(false).OuterHtml);
|
||||
#endif
|
||||
_currentnode = _currentnode.NextSibling;
|
||||
#if TRACE_NAVIGATOR
|
||||
InternalTrace(">true");
|
||||
#endif
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Moves to the next HTML attribute.
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public override bool MoveToNextAttribute()
|
||||
{
|
||||
#if TRACE_NAVIGATOR
|
||||
InternalTrace(null);
|
||||
#endif
|
||||
if (_attindex >= (_currentnode.Attributes.Count - 1))
|
||||
{
|
||||
#if TRACE_NAVIGATOR
|
||||
InternalTrace(">false");
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
|
||||
_attindex++;
|
||||
#if TRACE_NAVIGATOR
|
||||
InternalTrace(">true");
|
||||
#endif
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Moves the XPathNavigator to the next namespace node.
|
||||
/// Always returns falsefor the HtmlNavigator implementation.
|
||||
/// </summary>
|
||||
/// <param name="scope">An XPathNamespaceScope value describing the namespace scope.</param>
|
||||
/// <returns>Always returns false for the HtmlNavigator implementation.</returns>
|
||||
public override bool MoveToNextNamespace(XPathNamespaceScope scope)
|
||||
{
|
||||
#if TRACE_NAVIGATOR
|
||||
InternalTrace(null);
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Moves to the parent of the current node.
|
||||
/// </summary>
|
||||
/// <returns>true if there is a parent node, otherwise false.</returns>
|
||||
public override bool MoveToParent()
|
||||
{
|
||||
if (_currentnode.ParentNode == null)
|
||||
{
|
||||
#if TRACE_NAVIGATOR
|
||||
InternalTrace(">false");
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
|
||||
_currentnode = _currentnode.ParentNode;
|
||||
#if TRACE_NAVIGATOR
|
||||
InternalTrace(">true");
|
||||
#endif
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Moves to the previous sibling of the current node.
|
||||
/// </summary>
|
||||
/// <returns>true if the navigator is successful moving to the previous sibling node, false if there is no previous sibling or if the navigator is currently positioned on an attribute node.</returns>
|
||||
public override bool MoveToPrevious()
|
||||
{
|
||||
if (_currentnode.PreviousSibling == null)
|
||||
{
|
||||
#if TRACE_NAVIGATOR
|
||||
InternalTrace(">false");
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
|
||||
_currentnode = _currentnode.PreviousSibling;
|
||||
#if TRACE_NAVIGATOR
|
||||
InternalTrace(">true");
|
||||
#endif
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Moves to the root node to which the current node belongs.
|
||||
/// </summary>
|
||||
public override void MoveToRoot()
|
||||
{
|
||||
_currentnode = _doc.DocumentNode;
|
||||
#if TRACE_NAVIGATOR
|
||||
InternalTrace(null);
|
||||
#endif
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Internal Methods
|
||||
#if TRACE_NAVIGATOR
|
||||
[Conditional("TRACE")]
|
||||
internal void InternalTrace(object traceValue)
|
||||
{
|
||||
if (!Trace)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
#if !(NETSTANDARD1_3 || NETSTANDARD1_6)
|
||||
StackFrame sf = new StackFrame(1);
|
||||
string name = sf.GetMethod().Name;
|
||||
#else
|
||||
string name = "";
|
||||
#endif
|
||||
string nodename = _currentnode == null ? "(null)" : _currentnode.Name;
|
||||
string nodevalue;
|
||||
if (_currentnode == null)
|
||||
{
|
||||
nodevalue = "(null)";
|
||||
}
|
||||
else
|
||||
{
|
||||
switch (_currentnode.NodeType)
|
||||
{
|
||||
case HtmlNodeType.Comment:
|
||||
nodevalue = ((HtmlCommentNode) _currentnode).Comment;
|
||||
break;
|
||||
|
||||
case HtmlNodeType.Document:
|
||||
nodevalue = "";
|
||||
break;
|
||||
|
||||
case HtmlNodeType.Text:
|
||||
nodevalue = ((HtmlTextNode) _currentnode).Text;
|
||||
break;
|
||||
|
||||
default:
|
||||
nodevalue = _currentnode.CloneNode(false).OuterHtml;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
HtmlAgilityPack.Trace.WriteLine(string.Format("oid={0},n={1},a={2},v={3},{4}", GetHashCode(), nodename, _attindex, nodevalue, traceValue), "N!" + name);
|
||||
}
|
||||
#endif
|
||||
#endregion
|
||||
|
||||
#region Private Methods
|
||||
|
||||
private void Reset()
|
||||
{
|
||||
#if TRACE_NAVIGATOR
|
||||
InternalTrace(null);
|
||||
#endif
|
||||
_currentnode = _doc.DocumentNode;
|
||||
_attindex = -1;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
#endif
|
||||
35
Source/MyDb/HtmlAgilityPack.Shared/HtmlNodeType.cs
Normal file
35
Source/MyDb/HtmlAgilityPack.Shared/HtmlNodeType.cs
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
// Description: Html Agility Pack - HTML Parsers, selectors, traversors, manupulators.
|
||||
// Website & Documentation: http://html-agility-pack.net
|
||||
// Forum & Issues: https://github.com/zzzprojects/html-agility-pack
|
||||
// License: https://github.com/zzzprojects/html-agility-pack/blob/master/LICENSE
|
||||
// More projects: http://www.zzzprojects.com/
|
||||
// Copyright © ZZZ Projects Inc. 2014 - 2017. All rights reserved.
|
||||
|
||||
namespace HtmlAgilityPack
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents the type of a node.
|
||||
/// </summary>
|
||||
public enum HtmlNodeType
|
||||
{
|
||||
/// <summary>
|
||||
/// The root of a document.
|
||||
/// </summary>
|
||||
Document,
|
||||
|
||||
/// <summary>
|
||||
/// An HTML element.
|
||||
/// </summary>
|
||||
Element,
|
||||
|
||||
/// <summary>
|
||||
/// An HTML comment.
|
||||
/// </summary>
|
||||
Comment,
|
||||
|
||||
/// <summary>
|
||||
/// A text node is always the child of an element or a document node.
|
||||
/// </summary>
|
||||
Text,
|
||||
}
|
||||
}
|
||||
98
Source/MyDb/HtmlAgilityPack.Shared/HtmlParseError.cs
Normal file
98
Source/MyDb/HtmlAgilityPack.Shared/HtmlParseError.cs
Normal file
|
|
@ -0,0 +1,98 @@
|
|||
// Description: Html Agility Pack - HTML Parsers, selectors, traversors, manupulators.
|
||||
// Website & Documentation: http://html-agility-pack.net
|
||||
// Forum & Issues: https://github.com/zzzprojects/html-agility-pack
|
||||
// License: https://github.com/zzzprojects/html-agility-pack/blob/master/LICENSE
|
||||
// More projects: http://www.zzzprojects.com/
|
||||
// Copyright © ZZZ Projects Inc. 2014 - 2017. All rights reserved.
|
||||
|
||||
namespace HtmlAgilityPack
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents a parsing error found during document parsing.
|
||||
/// </summary>
|
||||
public class HtmlParseError
|
||||
{
|
||||
#region Fields
|
||||
|
||||
private HtmlParseErrorCode _code;
|
||||
private int _line;
|
||||
private int _linePosition;
|
||||
private string _reason;
|
||||
private string _sourceText;
|
||||
private int _streamPosition;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constructors
|
||||
|
||||
internal HtmlParseError(
|
||||
HtmlParseErrorCode code,
|
||||
int line,
|
||||
int linePosition,
|
||||
int streamPosition,
|
||||
string sourceText,
|
||||
string reason)
|
||||
{
|
||||
_code = code;
|
||||
_line = line;
|
||||
_linePosition = linePosition;
|
||||
_streamPosition = streamPosition;
|
||||
_sourceText = sourceText;
|
||||
_reason = reason;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Properties
|
||||
|
||||
/// <summary>
|
||||
/// Gets the type of error.
|
||||
/// </summary>
|
||||
public HtmlParseErrorCode Code
|
||||
{
|
||||
get { return _code; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the line number of this error in the document.
|
||||
/// </summary>
|
||||
public int Line
|
||||
{
|
||||
get { return _line; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the column number of this error in the document.
|
||||
/// </summary>
|
||||
public int LinePosition
|
||||
{
|
||||
get { return _linePosition; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a description for the error.
|
||||
/// </summary>
|
||||
public string Reason
|
||||
{
|
||||
get { return _reason; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the the full text of the line containing the error.
|
||||
/// </summary>
|
||||
public string SourceText
|
||||
{
|
||||
get { return _sourceText; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the absolute stream position of this error in the document, relative to the start of the document.
|
||||
/// </summary>
|
||||
public int StreamPosition
|
||||
{
|
||||
get { return _streamPosition; }
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
40
Source/MyDb/HtmlAgilityPack.Shared/HtmlParseErrorCode.cs
Normal file
40
Source/MyDb/HtmlAgilityPack.Shared/HtmlParseErrorCode.cs
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
// Description: Html Agility Pack - HTML Parsers, selectors, traversors, manupulators.
|
||||
// Website & Documentation: http://html-agility-pack.net
|
||||
// Forum & Issues: https://github.com/zzzprojects/html-agility-pack
|
||||
// License: https://github.com/zzzprojects/html-agility-pack/blob/master/LICENSE
|
||||
// More projects: http://www.zzzprojects.com/
|
||||
// Copyright © ZZZ Projects Inc. 2014 - 2017. All rights reserved.
|
||||
|
||||
namespace HtmlAgilityPack
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents the type of parsing error.
|
||||
/// </summary>
|
||||
public enum HtmlParseErrorCode
|
||||
{
|
||||
/// <summary>
|
||||
/// A tag was not closed.
|
||||
/// </summary>
|
||||
TagNotClosed,
|
||||
|
||||
/// <summary>
|
||||
/// A tag was not opened.
|
||||
/// </summary>
|
||||
TagNotOpened,
|
||||
|
||||
/// <summary>
|
||||
/// There is a charset mismatch between stream and declared (META) encoding.
|
||||
/// </summary>
|
||||
CharsetMismatch,
|
||||
|
||||
/// <summary>
|
||||
/// An end tag was not required.
|
||||
/// </summary>
|
||||
EndTagNotRequired,
|
||||
|
||||
/// <summary>
|
||||
/// An end tag is invalid at this position.
|
||||
/// </summary>
|
||||
EndTagInvalidHere
|
||||
}
|
||||
}
|
||||
81
Source/MyDb/HtmlAgilityPack.Shared/HtmlTextNode.cs
Normal file
81
Source/MyDb/HtmlAgilityPack.Shared/HtmlTextNode.cs
Normal file
|
|
@ -0,0 +1,81 @@
|
|||
// Description: Html Agility Pack - HTML Parsers, selectors, traversors, manupulators.
|
||||
// Website & Documentation: http://html-agility-pack.net
|
||||
// Forum & Issues: https://github.com/zzzprojects/html-agility-pack
|
||||
// License: https://github.com/zzzprojects/html-agility-pack/blob/master/LICENSE
|
||||
// More projects: http://www.zzzprojects.com/
|
||||
// Copyright © ZZZ Projects Inc. 2014 - 2017. All rights reserved.
|
||||
|
||||
namespace HtmlAgilityPack
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents an HTML text node.
|
||||
/// </summary>
|
||||
public class HtmlTextNode : HtmlNode
|
||||
{
|
||||
#region Fields
|
||||
|
||||
private string _text;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constructors
|
||||
|
||||
internal HtmlTextNode(HtmlDocument ownerdocument, int index)
|
||||
:
|
||||
base(HtmlNodeType.Text, ownerdocument, index)
|
||||
{
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Properties
|
||||
|
||||
/// <summary>
|
||||
/// Gets or Sets the HTML between the start and end tags of the object. In the case of a text node, it is equals to OuterHtml.
|
||||
/// </summary>
|
||||
public override string InnerHtml
|
||||
{
|
||||
get { return OuterHtml; }
|
||||
set { _text = value; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or Sets the object and its content in HTML.
|
||||
/// </summary>
|
||||
public override string OuterHtml
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_text == null)
|
||||
{
|
||||
return base.OuterHtml;
|
||||
}
|
||||
|
||||
return _text;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or Sets the text of the node.
|
||||
/// </summary>
|
||||
public string Text
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_text == null)
|
||||
{
|
||||
return base.OuterHtml;
|
||||
}
|
||||
|
||||
return _text;
|
||||
}
|
||||
set
|
||||
{
|
||||
_text = value;
|
||||
SetChanged();
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
132
Source/MyDb/HtmlAgilityPack.Shared/HtmlWeb.Xpath.cs
Normal file
132
Source/MyDb/HtmlAgilityPack.Shared/HtmlWeb.Xpath.cs
Normal file
|
|
@ -0,0 +1,132 @@
|
|||
// Description: Html Agility Pack - HTML Parsers, selectors, traversors, manupulators.
|
||||
// Website & Documentation: http://html-agility-pack.net
|
||||
// Forum & Issues: https://github.com/zzzprojects/html-agility-pack
|
||||
// License: https://github.com/zzzprojects/html-agility-pack/blob/master/LICENSE
|
||||
// More projects: http://www.zzzprojects.com/
|
||||
// Copyright © ZZZ Projects Inc. 2014 - 2017. All rights reserved.
|
||||
|
||||
#if !(NETSTANDARD1_3 || NETSTANDARD1_6) && !METRO
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Xml;
|
||||
using System.Xml.Serialization;
|
||||
using System.Xml.Xsl;
|
||||
|
||||
namespace HtmlAgilityPack
|
||||
{
|
||||
public partial class HtmlWeb
|
||||
{
|
||||
/// <summary>
|
||||
/// Creates an instance of the given type from the specified Internet resource.
|
||||
/// </summary>
|
||||
/// <param name="htmlUrl">The requested URL, such as "http://Myserver/Mypath/Myfile.asp".</param>
|
||||
/// <param name="xsltUrl">The URL that specifies the XSLT stylesheet to load.</param>
|
||||
/// <param name="xsltArgs">An <see cref="XsltArgumentList"/> containing the namespace-qualified arguments used as input to the transform.</param>
|
||||
/// <param name="type">The requested type.</param>
|
||||
/// <returns>An newly created instance.</returns>
|
||||
public object CreateInstance(string htmlUrl, string xsltUrl, XsltArgumentList xsltArgs, Type type)
|
||||
{
|
||||
return CreateInstance(htmlUrl, xsltUrl, xsltArgs, type, null);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates an instance of the given type from the specified Internet resource.
|
||||
/// </summary>
|
||||
/// <param name="htmlUrl">The requested URL, such as "http://Myserver/Mypath/Myfile.asp".</param>
|
||||
/// <param name="xsltUrl">The URL that specifies the XSLT stylesheet to load.</param>
|
||||
/// <param name="xsltArgs">An <see cref="XsltArgumentList"/> containing the namespace-qualified arguments used as input to the transform.</param>
|
||||
/// <param name="type">The requested type.</param>
|
||||
/// <param name="xmlPath">A file path where the temporary XML before transformation will be saved. Mostly used for debugging purposes.</param>
|
||||
/// <returns>An newly created instance.</returns>
|
||||
public object CreateInstance(string htmlUrl, string xsltUrl, XsltArgumentList xsltArgs, Type type,
|
||||
string xmlPath)
|
||||
{
|
||||
StringWriter sw = new StringWriter();
|
||||
XmlTextWriter writer = new XmlTextWriter(sw);
|
||||
if (xsltUrl == null)
|
||||
{
|
||||
LoadHtmlAsXml(htmlUrl, writer);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (xmlPath == null)
|
||||
{
|
||||
LoadHtmlAsXml(htmlUrl, xsltUrl, xsltArgs, writer);
|
||||
}
|
||||
else
|
||||
{
|
||||
LoadHtmlAsXml(htmlUrl, xsltUrl, xsltArgs, writer, xmlPath);
|
||||
}
|
||||
}
|
||||
|
||||
writer.Flush();
|
||||
StringReader sr = new StringReader(sw.ToString());
|
||||
XmlTextReader reader = new XmlTextReader(sr);
|
||||
XmlSerializer serializer = new XmlSerializer(type);
|
||||
object o;
|
||||
try
|
||||
{
|
||||
o = serializer.Deserialize(reader);
|
||||
}
|
||||
catch (InvalidOperationException ex)
|
||||
{
|
||||
throw new Exception(ex + ", --- xml:" + sw);
|
||||
}
|
||||
|
||||
return o;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Loads an HTML document from an Internet resource and saves it to the specified XmlTextWriter, after an XSLT transformation.
|
||||
/// </summary>
|
||||
/// <param name="htmlUrl">The requested URL, such as "http://Myserver/Mypath/Myfile.asp".</param>
|
||||
/// <param name="xsltUrl">The URL that specifies the XSLT stylesheet to load.</param>
|
||||
/// <param name="xsltArgs">An XsltArgumentList containing the namespace-qualified arguments used as input to the transform.</param>
|
||||
/// <param name="writer">The XmlTextWriter to which you want to save.</param>
|
||||
public void LoadHtmlAsXml(string htmlUrl, string xsltUrl, XsltArgumentList xsltArgs, XmlTextWriter writer)
|
||||
{
|
||||
LoadHtmlAsXml(htmlUrl, xsltUrl, xsltArgs, writer, null);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Loads an HTML document from an Internet resource and saves it to the specified XmlTextWriter, after an XSLT transformation.
|
||||
/// </summary>
|
||||
/// <param name="htmlUrl">The requested URL, such as "http://Myserver/Mypath/Myfile.asp". May not be null.</param>
|
||||
/// <param name="xsltUrl">The URL that specifies the XSLT stylesheet to load.</param>
|
||||
/// <param name="xsltArgs">An XsltArgumentList containing the namespace-qualified arguments used as input to the transform.</param>
|
||||
/// <param name="writer">The XmlTextWriter to which you want to save.</param>
|
||||
/// <param name="xmlPath">A file path where the temporary XML before transformation will be saved. Mostly used for debugging purposes.</param>
|
||||
public void LoadHtmlAsXml(string htmlUrl, string xsltUrl, XsltArgumentList xsltArgs, XmlTextWriter writer,
|
||||
string xmlPath)
|
||||
{
|
||||
if (htmlUrl == null)
|
||||
{
|
||||
throw new ArgumentNullException("htmlUrl");
|
||||
}
|
||||
|
||||
HtmlDocument doc = Load(htmlUrl);
|
||||
|
||||
if (xmlPath != null)
|
||||
{
|
||||
XmlTextWriter w = new XmlTextWriter(xmlPath, doc.Encoding);
|
||||
doc.Save(w);
|
||||
w.Close();
|
||||
}
|
||||
|
||||
if (xsltArgs == null)
|
||||
{
|
||||
xsltArgs = new XsltArgumentList();
|
||||
}
|
||||
|
||||
// add some useful variables to the xslt doc
|
||||
xsltArgs.AddParam("url", "", htmlUrl);
|
||||
xsltArgs.AddParam("requestDuration", "", RequestDuration);
|
||||
xsltArgs.AddParam("fromCache", "", FromCache);
|
||||
|
||||
XslCompiledTransform xslt = new XslCompiledTransform();
|
||||
xslt.Load(xsltUrl);
|
||||
xslt.Transform(doc, xsltArgs, writer);
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
2572
Source/MyDb/HtmlAgilityPack.Shared/HtmlWeb.cs
Normal file
2572
Source/MyDb/HtmlAgilityPack.Shared/HtmlWeb.cs
Normal file
File diff suppressed because it is too large
Load Diff
30
Source/MyDb/HtmlAgilityPack.Shared/HtmlWebException.cs
Normal file
30
Source/MyDb/HtmlAgilityPack.Shared/HtmlWebException.cs
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
// Description: Html Agility Pack - HTML Parsers, selectors, traversors, manupulators.
|
||||
// Website & Documentation: http://html-agility-pack.net
|
||||
// Forum & Issues: https://github.com/zzzprojects/html-agility-pack
|
||||
// License: https://github.com/zzzprojects/html-agility-pack/blob/master/LICENSE
|
||||
// More projects: http://www.zzzprojects.com/
|
||||
// Copyright © ZZZ Projects Inc. 2014 - 2017. All rights reserved.
|
||||
|
||||
using System;
|
||||
|
||||
namespace HtmlAgilityPack
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents an exception thrown by the HtmlWeb utility class.
|
||||
/// </summary>
|
||||
public class HtmlWebException : Exception
|
||||
{
|
||||
#region Constructors
|
||||
|
||||
/// <summary>
|
||||
/// Creates an instance of the HtmlWebException.
|
||||
/// </summary>
|
||||
/// <param name="message">The exception's message.</param>
|
||||
public HtmlWebException(string message)
|
||||
: base(message)
|
||||
{
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
41
Source/MyDb/HtmlAgilityPack.Shared/IOLibrary.cs
Normal file
41
Source/MyDb/HtmlAgilityPack.Shared/IOLibrary.cs
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
// Description: Html Agility Pack - HTML Parsers, selectors, traversors, manupulators.
|
||||
// Website & Documentation: http://html-agility-pack.net
|
||||
// Forum & Issues: https://github.com/zzzprojects/html-agility-pack
|
||||
// License: https://github.com/zzzprojects/html-agility-pack/blob/master/LICENSE
|
||||
// More projects: http://www.zzzprojects.com/
|
||||
// Copyright © ZZZ Projects Inc. 2014 - 2017. All rights reserved.
|
||||
|
||||
#if !METRO
|
||||
using System.IO;
|
||||
|
||||
namespace HtmlAgilityPack
|
||||
{
|
||||
internal struct IOLibrary
|
||||
{
|
||||
#region Internal Methods
|
||||
|
||||
internal static void CopyAlways(string source, string target)
|
||||
{
|
||||
if (!File.Exists(source))
|
||||
return;
|
||||
Directory.CreateDirectory(Path.GetDirectoryName(target));
|
||||
MakeWritable(target);
|
||||
File.Copy(source, target, true);
|
||||
}
|
||||
#if !PocketPC && !WINDOWS_PHONE
|
||||
internal static void MakeWritable(string path)
|
||||
{
|
||||
if (!File.Exists(path))
|
||||
return;
|
||||
File.SetAttributes(path, File.GetAttributes(path) & ~FileAttributes.ReadOnly);
|
||||
}
|
||||
#else
|
||||
internal static void MakeWritable(string path)
|
||||
{
|
||||
}
|
||||
#endif
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
@ -0,0 +1,45 @@
|
|||
// Description: Html Agility Pack - HTML Parsers, selectors, traversors, manupulators.
|
||||
// Website & Documentation: http://html-agility-pack.net
|
||||
// Forum & Issues: https://github.com/zzzprojects/html-agility-pack
|
||||
// License: https://github.com/zzzprojects/html-agility-pack/blob/master/LICENSE
|
||||
// More projects: http://www.zzzprojects.com/
|
||||
// Copyright © ZZZ Projects Inc. 2014 - 2017. All rights reserved.
|
||||
|
||||
#if METRO
|
||||
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace System
|
||||
{
|
||||
/// <summary>
|
||||
/// The exception that is thrown when a program contains invalid Microsoft intermediate language (MSIL) or metadata. Generally this indicates a bug in the compiler that generated the program.
|
||||
/// </summary>
|
||||
/// <filterpriority>2</filterpriority>
|
||||
[ComVisible(true)]
|
||||
public sealed class InvalidProgramException : Exception
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="T:System.InvalidProgramException"/> class with default properties.
|
||||
/// </summary>
|
||||
public InvalidProgramException()
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="T:System.InvalidProgramException"/> class with a specified error message.
|
||||
/// </summary>
|
||||
/// <param name="message">The error message that explains the reason for the exception. </param>
|
||||
public InvalidProgramException(string message) : base(message)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="T:System.InvalidProgramException"/> class with a specified error message and a reference to the inner exception that is the cause of this exception.
|
||||
/// </summary>
|
||||
/// <param name="message">The error message that explains the reason for the exception. </param><param name="inner">The exception that is the cause of the current exception. If the <paramref name="inner"/> parameter is not a null reference (Nothing in Visual Basic), the current exception is raised in a catch block that handles the inner exception. </param>
|
||||
public InvalidProgramException(string message, Exception inner) : base(message, inner)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
143
Source/MyDb/HtmlAgilityPack.Shared/Metro/HtmlWeb.cs
Normal file
143
Source/MyDb/HtmlAgilityPack.Shared/Metro/HtmlWeb.cs
Normal file
|
|
@ -0,0 +1,143 @@
|
|||
#if METRO
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Net;
|
||||
using System.Net.Http;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace HtmlAgilityPack
|
||||
{
|
||||
/// <summary>
|
||||
/// Used for downloading and parsing html from the internet
|
||||
/// </summary>
|
||||
public class HtmlWeb
|
||||
{
|
||||
/// <summary>
|
||||
/// Allows for setting document defaults before loading
|
||||
/// </summary>
|
||||
public Action<HtmlDocument> PreHandleDocument { get; set; }
|
||||
|
||||
#region Instance Methods
|
||||
|
||||
/// <summary>
|
||||
/// Begins the process of downloading an internet resource
|
||||
/// </summary>
|
||||
/// <param name="url">Url to the html document</param>
|
||||
public async Task<HtmlDocument> LoadFromWebAsync(string url)
|
||||
{
|
||||
return await LoadFromWebAsync(new Uri(url), null, null);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Begins the process of downloading an internet resource
|
||||
/// </summary>
|
||||
/// <param name="url">Url to the html document</param>
|
||||
/// <param name="encoding">The encoding to use while downloading the document</param>
|
||||
public async Task<HtmlDocument> LoadFromWebAsync(string url, Encoding encoding)
|
||||
{
|
||||
return await LoadFromWebAsync(new Uri(url), encoding, null);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Begins the process of downloading an internet resource
|
||||
/// </summary>
|
||||
/// <param name="url">Url to the html document</param>
|
||||
/// <param name="encoding">The encoding to use while downloading the document</param>
|
||||
/// <param name="userName">Username to use for credentials in the web request</param>
|
||||
/// <param name="password">Password to use for credentials in the web request</param>
|
||||
public async Task<HtmlDocument> LoadFromWebAsync(string url, Encoding encoding, string userName, string password)
|
||||
{
|
||||
return await LoadFromWebAsync(new Uri(url), encoding, new NetworkCredential(userName, password));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Begins the process of downloading an internet resource
|
||||
/// </summary>
|
||||
/// <param name="url">Url to the html document</param>
|
||||
/// <param name="encoding">The encoding to use while downloading the document</param>
|
||||
/// <param name="userName">Username to use for credentials in the web request</param>
|
||||
/// <param name="password">Password to use for credentials in the web request</param>
|
||||
/// <param name="domain">Domain to use for credentials in the web request</param>
|
||||
public async Task<HtmlDocument> LoadFromWebAsync(string url, Encoding encoding, string userName, string password, string domain)
|
||||
{
|
||||
return await LoadFromWebAsync(new Uri(url), encoding, new NetworkCredential(userName, password, domain));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Begins the process of downloading an internet resource
|
||||
/// </summary>
|
||||
/// <param name="url">Url to the html document</param>
|
||||
/// <param name="userName">Username to use for credentials in the web request</param>
|
||||
/// <param name="password">Password to use for credentials in the web request</param>
|
||||
/// <param name="domain">Domain to use for credentials in the web request</param>
|
||||
public async Task<HtmlDocument> LoadFromWebAsync(string url, string userName, string password, string domain)
|
||||
{
|
||||
return await LoadFromWebAsync(new Uri(url), null, new NetworkCredential(userName, password, domain));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Begins the process of downloading an internet resource
|
||||
/// </summary>
|
||||
/// <param name="url">Url to the html document</param>
|
||||
/// <param name="userName">Username to use for credentials in the web request</param>
|
||||
/// <param name="password">Password to use for credentials in the web request</param>
|
||||
public async Task<HtmlDocument> LoadFromWebAsync(string url, string userName, string password)
|
||||
{
|
||||
return await LoadFromWebAsync(new Uri(url), null, new NetworkCredential(userName, password));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Begins the process of downloading an internet resource
|
||||
/// </summary>
|
||||
/// <param name="url">Url to the html document</param>
|
||||
/// <param name="credentials">The credentials to use for authenticating the web request</param>
|
||||
public async Task<HtmlDocument> LoadFromWebAsync(string url, NetworkCredential credentials)
|
||||
{
|
||||
return await LoadFromWebAsync(new Uri(url), null, credentials);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Begins the process of downloading an internet resource
|
||||
/// </summary>
|
||||
/// <param name="uri">Url to the html document</param>
|
||||
/// <param name="encoding">The encoding to use while downloading the document</param>
|
||||
/// <param name="credentials">The credentials to use for authenticating the web request</param>
|
||||
public async Task<HtmlDocument> LoadFromWebAsync(Uri uri, Encoding encoding, NetworkCredential credentials)
|
||||
{
|
||||
var clientHandler = new HttpClientHandler();
|
||||
if (credentials == null)
|
||||
clientHandler.UseDefaultCredentials = true;
|
||||
else
|
||||
clientHandler.Credentials = credentials;
|
||||
|
||||
var client = new HttpClient(clientHandler);
|
||||
|
||||
var e = await client.GetAsync(uri);
|
||||
if (e.StatusCode == HttpStatusCode.OK)
|
||||
{
|
||||
var html = string.Empty;
|
||||
if (encoding != null)
|
||||
{
|
||||
using (var sr = new StreamReader(await e.Content.ReadAsStreamAsync(), encoding))
|
||||
{
|
||||
html = sr.ReadToEnd();
|
||||
}
|
||||
}
|
||||
else
|
||||
html = await e.Content.ReadAsStringAsync();
|
||||
|
||||
var doc = new HtmlDocument();
|
||||
if (PreHandleDocument != null)
|
||||
PreHandleDocument(doc);
|
||||
doc.LoadHtml(html);
|
||||
return doc;
|
||||
}
|
||||
|
||||
throw new Exception("Error downloading html");
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
|
@ -0,0 +1,18 @@
|
|||
#if METRO
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace HtmlAgilityPack
|
||||
{
|
||||
public class InvalidProgramException : System.Exception
|
||||
{
|
||||
public InvalidProgramException(string message)
|
||||
: base(message)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
694
Source/MyDb/HtmlAgilityPack.Shared/MimeTypeMap.cs
Normal file
694
Source/MyDb/HtmlAgilityPack.Shared/MimeTypeMap.cs
Normal file
|
|
@ -0,0 +1,694 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace HtmlAgilityPack
|
||||
{
|
||||
internal static class MimeTypeMap
|
||||
{
|
||||
// code take here : https://github.com/samuelneff/MimeTypeMap/blob/master/src/MimeTypes/MimeTypeMap.cs
|
||||
// On MIT License
|
||||
|
||||
public static IDictionary<string, string> Mappings = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase) {
|
||||
|
||||
// maps both ways,
|
||||
// extension -> mime type
|
||||
// and
|
||||
// mime type -> extension
|
||||
//
|
||||
// any mime types on left side not pre-loaded on right side, are added automatically
|
||||
// some mime types can map to multiple extensions, so to get a deterministic mapping,
|
||||
// add those to the dictionary specifcially
|
||||
//
|
||||
// combination of values from Windows 7 Registry and
|
||||
// from C:\Windows\System32\inetsrv\config\applicationHost.config
|
||||
// some added, including .7z and .dat
|
||||
//
|
||||
// Some added based on http://www.iana.org/assignments/media-types/media-types.xhtml
|
||||
// which lists mime types, but not extensions
|
||||
//
|
||||
{".323", "text/h323"},
|
||||
{".3g2", "video/3gpp2"},
|
||||
{".3gp", "video/3gpp"},
|
||||
{".3gp2", "video/3gpp2"},
|
||||
{".3gpp", "video/3gpp"},
|
||||
{".7z", "application/x-7z-compressed"},
|
||||
{".aa", "audio/audible"},
|
||||
{".AAC", "audio/aac"},
|
||||
{".aaf", "application/octet-stream"},
|
||||
{".aax", "audio/vnd.audible.aax"},
|
||||
{".ac3", "audio/ac3"},
|
||||
{".aca", "application/octet-stream"},
|
||||
{".accda", "application/msaccess.addin"},
|
||||
{".accdb", "application/msaccess"},
|
||||
{".accdc", "application/msaccess.cab"},
|
||||
{".accde", "application/msaccess"},
|
||||
{".accdr", "application/msaccess.runtime"},
|
||||
{".accdt", "application/msaccess"},
|
||||
{".accdw", "application/msaccess.webapplication"},
|
||||
{".accft", "application/msaccess.ftemplate"},
|
||||
{".acx", "application/internet-property-stream"},
|
||||
{".AddIn", "text/xml"},
|
||||
{".ade", "application/msaccess"},
|
||||
{".adobebridge", "application/x-bridge-url"},
|
||||
{".adp", "application/msaccess"},
|
||||
{".ADT", "audio/vnd.dlna.adts"},
|
||||
{".ADTS", "audio/aac"},
|
||||
{".afm", "application/octet-stream"},
|
||||
{".ai", "application/postscript"},
|
||||
{".aif", "audio/aiff"},
|
||||
{".aifc", "audio/aiff"},
|
||||
{".aiff", "audio/aiff"},
|
||||
{".air", "application/vnd.adobe.air-application-installer-package+zip"},
|
||||
{".amc", "application/mpeg"},
|
||||
{".anx", "application/annodex"},
|
||||
{".apk", "application/vnd.android.package-archive" },
|
||||
{".application", "application/x-ms-application"},
|
||||
{".art", "image/x-jg"},
|
||||
{".asa", "application/xml"},
|
||||
{".asax", "application/xml"},
|
||||
{".ascx", "application/xml"},
|
||||
{".asd", "application/octet-stream"},
|
||||
{".asf", "video/x-ms-asf"},
|
||||
{".ashx", "application/xml"},
|
||||
{".asi", "application/octet-stream"},
|
||||
{".asm", "text/plain"},
|
||||
{".asmx", "application/xml"},
|
||||
{".aspx", "application/xml"},
|
||||
{".asr", "video/x-ms-asf"},
|
||||
{".asx", "video/x-ms-asf"},
|
||||
{".atom", "application/atom+xml"},
|
||||
{".au", "audio/basic"},
|
||||
{".avi", "video/x-msvideo"},
|
||||
{".axa", "audio/annodex"},
|
||||
{".axs", "application/olescript"},
|
||||
{".axv", "video/annodex"},
|
||||
{".bas", "text/plain"},
|
||||
{".bcpio", "application/x-bcpio"},
|
||||
{".bin", "application/octet-stream"},
|
||||
{".bmp", "image/bmp"},
|
||||
{".c", "text/plain"},
|
||||
{".cab", "application/octet-stream"},
|
||||
{".caf", "audio/x-caf"},
|
||||
{".calx", "application/vnd.ms-office.calx"},
|
||||
{".cat", "application/vnd.ms-pki.seccat"},
|
||||
{".cc", "text/plain"},
|
||||
{".cd", "text/plain"},
|
||||
{".cdda", "audio/aiff"},
|
||||
{".cdf", "application/x-cdf"},
|
||||
{".cer", "application/x-x509-ca-cert"},
|
||||
{".cfg", "text/plain"},
|
||||
{".chm", "application/octet-stream"},
|
||||
{".class", "application/x-java-applet"},
|
||||
{".clp", "application/x-msclip"},
|
||||
{".cmd", "text/plain"},
|
||||
{".cmx", "image/x-cmx"},
|
||||
{".cnf", "text/plain"},
|
||||
{".cod", "image/cis-cod"},
|
||||
{".config", "application/xml"},
|
||||
{".contact", "text/x-ms-contact"},
|
||||
{".coverage", "application/xml"},
|
||||
{".cpio", "application/x-cpio"},
|
||||
{".cpp", "text/plain"},
|
||||
{".crd", "application/x-mscardfile"},
|
||||
{".crl", "application/pkix-crl"},
|
||||
{".crt", "application/x-x509-ca-cert"},
|
||||
{".cs", "text/plain"},
|
||||
{".csdproj", "text/plain"},
|
||||
{".csh", "application/x-csh"},
|
||||
{".csproj", "text/plain"},
|
||||
{".css", "text/css"},
|
||||
{".csv", "text/csv"},
|
||||
{".cur", "application/octet-stream"},
|
||||
{".cxx", "text/plain"},
|
||||
{".dat", "application/octet-stream"},
|
||||
{".datasource", "application/xml"},
|
||||
{".dbproj", "text/plain"},
|
||||
{".dcr", "application/x-director"},
|
||||
{".def", "text/plain"},
|
||||
{".deploy", "application/octet-stream"},
|
||||
{".der", "application/x-x509-ca-cert"},
|
||||
{".dgml", "application/xml"},
|
||||
{".dib", "image/bmp"},
|
||||
{".dif", "video/x-dv"},
|
||||
{".dir", "application/x-director"},
|
||||
{".disco", "text/xml"},
|
||||
{".divx", "video/divx"},
|
||||
{".dll", "application/x-msdownload"},
|
||||
{".dll.config", "text/xml"},
|
||||
{".dlm", "text/dlm"},
|
||||
{".doc", "application/msword"},
|
||||
{".docm", "application/vnd.ms-word.document.macroEnabled.12"},
|
||||
{".docx", "application/vnd.openxmlformats-officedocument.wordprocessingml.document"},
|
||||
{".dot", "application/msword"},
|
||||
{".dotm", "application/vnd.ms-word.template.macroEnabled.12"},
|
||||
{".dotx", "application/vnd.openxmlformats-officedocument.wordprocessingml.template"},
|
||||
{".dsp", "application/octet-stream"},
|
||||
{".dsw", "text/plain"},
|
||||
{".dtd", "text/xml"},
|
||||
{".dtsConfig", "text/xml"},
|
||||
{".dv", "video/x-dv"},
|
||||
{".dvi", "application/x-dvi"},
|
||||
{".dwf", "drawing/x-dwf"},
|
||||
{".dwg", "application/acad"},
|
||||
{".dwp", "application/octet-stream"},
|
||||
{".dxf", "application/x-dxf" },
|
||||
{".dxr", "application/x-director"},
|
||||
{".eml", "message/rfc822"},
|
||||
{".emz", "application/octet-stream"},
|
||||
{".eot", "application/vnd.ms-fontobject"},
|
||||
{".eps", "application/postscript"},
|
||||
{".es", "application/ecmascript"},
|
||||
{".etl", "application/etl"},
|
||||
{".etx", "text/x-setext"},
|
||||
{".evy", "application/envoy"},
|
||||
{".exe", "application/octet-stream"},
|
||||
{".exe.config", "text/xml"},
|
||||
{".fdf", "application/vnd.fdf"},
|
||||
{".fif", "application/fractals"},
|
||||
{".filters", "application/xml"},
|
||||
{".fla", "application/octet-stream"},
|
||||
{".flac", "audio/flac"},
|
||||
{".flr", "x-world/x-vrml"},
|
||||
{".flv", "video/x-flv"},
|
||||
{".fsscript", "application/fsharp-script"},
|
||||
{".fsx", "application/fsharp-script"},
|
||||
{".generictest", "application/xml"},
|
||||
{".gif", "image/gif"},
|
||||
{".gpx", "application/gpx+xml"},
|
||||
{".group", "text/x-ms-group"},
|
||||
{".gsm", "audio/x-gsm"},
|
||||
{".gtar", "application/x-gtar"},
|
||||
{".gz", "application/x-gzip"},
|
||||
{".h", "text/plain"},
|
||||
{".hdf", "application/x-hdf"},
|
||||
{".hdml", "text/x-hdml"},
|
||||
{".hhc", "application/x-oleobject"},
|
||||
{".hhk", "application/octet-stream"},
|
||||
{".hhp", "application/octet-stream"},
|
||||
{".hlp", "application/winhlp"},
|
||||
{".hpp", "text/plain"},
|
||||
{".hqx", "application/mac-binhex40"},
|
||||
{".hta", "application/hta"},
|
||||
{".htc", "text/x-component"},
|
||||
{".htm", "text/html"},
|
||||
{".html", "text/html"},
|
||||
{".htt", "text/webviewhtml"},
|
||||
{".hxa", "application/xml"},
|
||||
{".hxc", "application/xml"},
|
||||
{".hxd", "application/octet-stream"},
|
||||
{".hxe", "application/xml"},
|
||||
{".hxf", "application/xml"},
|
||||
{".hxh", "application/octet-stream"},
|
||||
{".hxi", "application/octet-stream"},
|
||||
{".hxk", "application/xml"},
|
||||
{".hxq", "application/octet-stream"},
|
||||
{".hxr", "application/octet-stream"},
|
||||
{".hxs", "application/octet-stream"},
|
||||
{".hxt", "text/html"},
|
||||
{".hxv", "application/xml"},
|
||||
{".hxw", "application/octet-stream"},
|
||||
{".hxx", "text/plain"},
|
||||
{".i", "text/plain"},
|
||||
{".ico", "image/x-icon"},
|
||||
{".ics", "application/octet-stream"},
|
||||
{".idl", "text/plain"},
|
||||
{".ief", "image/ief"},
|
||||
{".iii", "application/x-iphone"},
|
||||
{".inc", "text/plain"},
|
||||
{".inf", "application/octet-stream"},
|
||||
{".ini", "text/plain"},
|
||||
{".inl", "text/plain"},
|
||||
{".ins", "application/x-internet-signup"},
|
||||
{".ipa", "application/x-itunes-ipa"},
|
||||
{".ipg", "application/x-itunes-ipg"},
|
||||
{".ipproj", "text/plain"},
|
||||
{".ipsw", "application/x-itunes-ipsw"},
|
||||
{".iqy", "text/x-ms-iqy"},
|
||||
{".isp", "application/x-internet-signup"},
|
||||
{".ite", "application/x-itunes-ite"},
|
||||
{".itlp", "application/x-itunes-itlp"},
|
||||
{".itms", "application/x-itunes-itms"},
|
||||
{".itpc", "application/x-itunes-itpc"},
|
||||
{".IVF", "video/x-ivf"},
|
||||
{".jar", "application/java-archive"},
|
||||
{".java", "application/octet-stream"},
|
||||
{".jck", "application/liquidmotion"},
|
||||
{".jcz", "application/liquidmotion"},
|
||||
{".jfif", "image/pjpeg"},
|
||||
{".jnlp", "application/x-java-jnlp-file"},
|
||||
{".jpb", "application/octet-stream"},
|
||||
{".jpe", "image/jpeg"},
|
||||
{".jpeg", "image/jpeg"},
|
||||
{".jpg", "image/jpeg"},
|
||||
{".js", "application/javascript"},
|
||||
{".json", "application/json"},
|
||||
{".jsx", "text/jscript"},
|
||||
{".jsxbin", "text/plain"},
|
||||
{".latex", "application/x-latex"},
|
||||
{".library-ms", "application/windows-library+xml"},
|
||||
{".lit", "application/x-ms-reader"},
|
||||
{".loadtest", "application/xml"},
|
||||
{".lpk", "application/octet-stream"},
|
||||
{".lsf", "video/x-la-asf"},
|
||||
{".lst", "text/plain"},
|
||||
{".lsx", "video/x-la-asf"},
|
||||
{".lzh", "application/octet-stream"},
|
||||
{".m13", "application/x-msmediaview"},
|
||||
{".m14", "application/x-msmediaview"},
|
||||
{".m1v", "video/mpeg"},
|
||||
{".m2t", "video/vnd.dlna.mpeg-tts"},
|
||||
{".m2ts", "video/vnd.dlna.mpeg-tts"},
|
||||
{".m2v", "video/mpeg"},
|
||||
{".m3u", "audio/x-mpegurl"},
|
||||
{".m3u8", "audio/x-mpegurl"},
|
||||
{".m4a", "audio/m4a"},
|
||||
{".m4b", "audio/m4b"},
|
||||
{".m4p", "audio/m4p"},
|
||||
{".m4r", "audio/x-m4r"},
|
||||
{".m4v", "video/x-m4v"},
|
||||
{".mac", "image/x-macpaint"},
|
||||
{".mak", "text/plain"},
|
||||
{".man", "application/x-troff-man"},
|
||||
{".manifest", "application/x-ms-manifest"},
|
||||
{".map", "text/plain"},
|
||||
{".master", "application/xml"},
|
||||
{".mbox", "application/mbox"},
|
||||
{".mda", "application/msaccess"},
|
||||
{".mdb", "application/x-msaccess"},
|
||||
{".mde", "application/msaccess"},
|
||||
{".mdp", "application/octet-stream"},
|
||||
{".me", "application/x-troff-me"},
|
||||
{".mfp", "application/x-shockwave-flash"},
|
||||
{".mht", "message/rfc822"},
|
||||
{".mhtml", "message/rfc822"},
|
||||
{".mid", "audio/mid"},
|
||||
{".midi", "audio/mid"},
|
||||
{".mix", "application/octet-stream"},
|
||||
{".mk", "text/plain"},
|
||||
{".mk3d", "video/x-matroska-3d"},
|
||||
{".mka", "audio/x-matroska"},
|
||||
{".mkv", "video/x-matroska"},
|
||||
{".mmf", "application/x-smaf"},
|
||||
{".mno", "text/xml"},
|
||||
{".mny", "application/x-msmoney"},
|
||||
{".mod", "video/mpeg"},
|
||||
{".mov", "video/quicktime"},
|
||||
{".movie", "video/x-sgi-movie"},
|
||||
{".mp2", "video/mpeg"},
|
||||
{".mp2v", "video/mpeg"},
|
||||
{".mp3", "audio/mpeg"},
|
||||
{".mp4", "video/mp4"},
|
||||
{".mp4v", "video/mp4"},
|
||||
{".mpa", "video/mpeg"},
|
||||
{".mpe", "video/mpeg"},
|
||||
{".mpeg", "video/mpeg"},
|
||||
{".mpf", "application/vnd.ms-mediapackage"},
|
||||
{".mpg", "video/mpeg"},
|
||||
{".mpp", "application/vnd.ms-project"},
|
||||
{".mpv2", "video/mpeg"},
|
||||
{".mqv", "video/quicktime"},
|
||||
{".ms", "application/x-troff-ms"},
|
||||
{".msg", "application/vnd.ms-outlook"},
|
||||
{".msi", "application/octet-stream"},
|
||||
{".mso", "application/octet-stream"},
|
||||
{".mts", "video/vnd.dlna.mpeg-tts"},
|
||||
{".mtx", "application/xml"},
|
||||
{".mvb", "application/x-msmediaview"},
|
||||
{".mvc", "application/x-miva-compiled"},
|
||||
{".mxp", "application/x-mmxp"},
|
||||
{".nc", "application/x-netcdf"},
|
||||
{".nsc", "video/x-ms-asf"},
|
||||
{".nws", "message/rfc822"},
|
||||
{".ocx", "application/octet-stream"},
|
||||
{".oda", "application/oda"},
|
||||
{".odb", "application/vnd.oasis.opendocument.database"},
|
||||
{".odc", "application/vnd.oasis.opendocument.chart"},
|
||||
{".odf", "application/vnd.oasis.opendocument.formula"},
|
||||
{".odg", "application/vnd.oasis.opendocument.graphics"},
|
||||
{".odh", "text/plain"},
|
||||
{".odi", "application/vnd.oasis.opendocument.image"},
|
||||
{".odl", "text/plain"},
|
||||
{".odm", "application/vnd.oasis.opendocument.text-master"},
|
||||
{".odp", "application/vnd.oasis.opendocument.presentation"},
|
||||
{".ods", "application/vnd.oasis.opendocument.spreadsheet"},
|
||||
{".odt", "application/vnd.oasis.opendocument.text"},
|
||||
{".oga", "audio/ogg"},
|
||||
{".ogg", "audio/ogg"},
|
||||
{".ogv", "video/ogg"},
|
||||
{".ogx", "application/ogg"},
|
||||
{".one", "application/onenote"},
|
||||
{".onea", "application/onenote"},
|
||||
{".onepkg", "application/onenote"},
|
||||
{".onetmp", "application/onenote"},
|
||||
{".onetoc", "application/onenote"},
|
||||
{".onetoc2", "application/onenote"},
|
||||
{".opus", "audio/ogg"},
|
||||
{".orderedtest", "application/xml"},
|
||||
{".osdx", "application/opensearchdescription+xml"},
|
||||
{".otf", "application/font-sfnt"},
|
||||
{".otg", "application/vnd.oasis.opendocument.graphics-template"},
|
||||
{".oth", "application/vnd.oasis.opendocument.text-web"},
|
||||
{".otp", "application/vnd.oasis.opendocument.presentation-template"},
|
||||
{".ots", "application/vnd.oasis.opendocument.spreadsheet-template"},
|
||||
{".ott", "application/vnd.oasis.opendocument.text-template"},
|
||||
{".oxt", "application/vnd.openofficeorg.extension"},
|
||||
{".p10", "application/pkcs10"},
|
||||
{".p12", "application/x-pkcs12"},
|
||||
{".p7b", "application/x-pkcs7-certificates"},
|
||||
{".p7c", "application/pkcs7-mime"},
|
||||
{".p7m", "application/pkcs7-mime"},
|
||||
{".p7r", "application/x-pkcs7-certreqresp"},
|
||||
{".p7s", "application/pkcs7-signature"},
|
||||
{".pbm", "image/x-portable-bitmap"},
|
||||
{".pcast", "application/x-podcast"},
|
||||
{".pct", "image/pict"},
|
||||
{".pcx", "application/octet-stream"},
|
||||
{".pcz", "application/octet-stream"},
|
||||
{".pdf", "application/pdf"},
|
||||
{".pfb", "application/octet-stream"},
|
||||
{".pfm", "application/octet-stream"},
|
||||
{".pfx", "application/x-pkcs12"},
|
||||
{".pgm", "image/x-portable-graymap"},
|
||||
{".pic", "image/pict"},
|
||||
{".pict", "image/pict"},
|
||||
{".pkgdef", "text/plain"},
|
||||
{".pkgundef", "text/plain"},
|
||||
{".pko", "application/vnd.ms-pki.pko"},
|
||||
{".pls", "audio/scpls"},
|
||||
{".pma", "application/x-perfmon"},
|
||||
{".pmc", "application/x-perfmon"},
|
||||
{".pml", "application/x-perfmon"},
|
||||
{".pmr", "application/x-perfmon"},
|
||||
{".pmw", "application/x-perfmon"},
|
||||
{".png", "image/png"},
|
||||
{".pnm", "image/x-portable-anymap"},
|
||||
{".pnt", "image/x-macpaint"},
|
||||
{".pntg", "image/x-macpaint"},
|
||||
{".pnz", "image/png"},
|
||||
{".pot", "application/vnd.ms-powerpoint"},
|
||||
{".potm", "application/vnd.ms-powerpoint.template.macroEnabled.12"},
|
||||
{".potx", "application/vnd.openxmlformats-officedocument.presentationml.template"},
|
||||
{".ppa", "application/vnd.ms-powerpoint"},
|
||||
{".ppam", "application/vnd.ms-powerpoint.addin.macroEnabled.12"},
|
||||
{".ppm", "image/x-portable-pixmap"},
|
||||
{".pps", "application/vnd.ms-powerpoint"},
|
||||
{".ppsm", "application/vnd.ms-powerpoint.slideshow.macroEnabled.12"},
|
||||
{".ppsx", "application/vnd.openxmlformats-officedocument.presentationml.slideshow"},
|
||||
{".ppt", "application/vnd.ms-powerpoint"},
|
||||
{".pptm", "application/vnd.ms-powerpoint.presentation.macroEnabled.12"},
|
||||
{".pptx", "application/vnd.openxmlformats-officedocument.presentationml.presentation"},
|
||||
{".prf", "application/pics-rules"},
|
||||
{".prm", "application/octet-stream"},
|
||||
{".prx", "application/octet-stream"},
|
||||
{".ps", "application/postscript"},
|
||||
{".psc1", "application/PowerShell"},
|
||||
{".psd", "application/octet-stream"},
|
||||
{".psess", "application/xml"},
|
||||
{".psm", "application/octet-stream"},
|
||||
{".psp", "application/octet-stream"},
|
||||
{".pst", "application/vnd.ms-outlook"},
|
||||
{".pub", "application/x-mspublisher"},
|
||||
{".pwz", "application/vnd.ms-powerpoint"},
|
||||
{".qht", "text/x-html-insertion"},
|
||||
{".qhtm", "text/x-html-insertion"},
|
||||
{".qt", "video/quicktime"},
|
||||
{".qti", "image/x-quicktime"},
|
||||
{".qtif", "image/x-quicktime"},
|
||||
{".qtl", "application/x-quicktimeplayer"},
|
||||
{".qxd", "application/octet-stream"},
|
||||
{".ra", "audio/x-pn-realaudio"},
|
||||
{".ram", "audio/x-pn-realaudio"},
|
||||
{".rar", "application/x-rar-compressed"},
|
||||
{".ras", "image/x-cmu-raster"},
|
||||
{".rat", "application/rat-file"},
|
||||
{".rc", "text/plain"},
|
||||
{".rc2", "text/plain"},
|
||||
{".rct", "text/plain"},
|
||||
{".rdlc", "application/xml"},
|
||||
{".reg", "text/plain"},
|
||||
{".resx", "application/xml"},
|
||||
{".rf", "image/vnd.rn-realflash"},
|
||||
{".rgb", "image/x-rgb"},
|
||||
{".rgs", "text/plain"},
|
||||
{".rm", "application/vnd.rn-realmedia"},
|
||||
{".rmi", "audio/mid"},
|
||||
{".rmp", "application/vnd.rn-rn_music_package"},
|
||||
{".roff", "application/x-troff"},
|
||||
{".rpm", "audio/x-pn-realaudio-plugin"},
|
||||
{".rqy", "text/x-ms-rqy"},
|
||||
{".rtf", "application/rtf"},
|
||||
{".rtx", "text/richtext"},
|
||||
{".rvt", "application/octet-stream" },
|
||||
{".ruleset", "application/xml"},
|
||||
{".s", "text/plain"},
|
||||
{".safariextz", "application/x-safari-safariextz"},
|
||||
{".scd", "application/x-msschedule"},
|
||||
{".scr", "text/plain"},
|
||||
{".sct", "text/scriptlet"},
|
||||
{".sd2", "audio/x-sd2"},
|
||||
{".sdp", "application/sdp"},
|
||||
{".sea", "application/octet-stream"},
|
||||
{".searchConnector-ms", "application/windows-search-connector+xml"},
|
||||
{".setpay", "application/set-payment-initiation"},
|
||||
{".setreg", "application/set-registration-initiation"},
|
||||
{".settings", "application/xml"},
|
||||
{".sgimb", "application/x-sgimb"},
|
||||
{".sgml", "text/sgml"},
|
||||
{".sh", "application/x-sh"},
|
||||
{".shar", "application/x-shar"},
|
||||
{".shtml", "text/html"},
|
||||
{".sit", "application/x-stuffit"},
|
||||
{".sitemap", "application/xml"},
|
||||
{".skin", "application/xml"},
|
||||
{".skp", "application/x-koan" },
|
||||
{".sldm", "application/vnd.ms-powerpoint.slide.macroEnabled.12"},
|
||||
{".sldx", "application/vnd.openxmlformats-officedocument.presentationml.slide"},
|
||||
{".slk", "application/vnd.ms-excel"},
|
||||
{".sln", "text/plain"},
|
||||
{".slupkg-ms", "application/x-ms-license"},
|
||||
{".smd", "audio/x-smd"},
|
||||
{".smi", "application/octet-stream"},
|
||||
{".smx", "audio/x-smd"},
|
||||
{".smz", "audio/x-smd"},
|
||||
{".snd", "audio/basic"},
|
||||
{".snippet", "application/xml"},
|
||||
{".snp", "application/octet-stream"},
|
||||
{".sol", "text/plain"},
|
||||
{".sor", "text/plain"},
|
||||
{".spc", "application/x-pkcs7-certificates"},
|
||||
{".spl", "application/futuresplash"},
|
||||
{".spx", "audio/ogg"},
|
||||
{".src", "application/x-wais-source"},
|
||||
{".srf", "text/plain"},
|
||||
{".SSISDeploymentManifest", "text/xml"},
|
||||
{".ssm", "application/streamingmedia"},
|
||||
{".sst", "application/vnd.ms-pki.certstore"},
|
||||
{".stl", "application/vnd.ms-pki.stl"},
|
||||
{".sv4cpio", "application/x-sv4cpio"},
|
||||
{".sv4crc", "application/x-sv4crc"},
|
||||
{".svc", "application/xml"},
|
||||
{".svg", "image/svg+xml"},
|
||||
{".swf", "application/x-shockwave-flash"},
|
||||
{".step", "application/step"},
|
||||
{".stp", "application/step"},
|
||||
{".t", "application/x-troff"},
|
||||
{".tar", "application/x-tar"},
|
||||
{".tcl", "application/x-tcl"},
|
||||
{".testrunconfig", "application/xml"},
|
||||
{".testsettings", "application/xml"},
|
||||
{".tex", "application/x-tex"},
|
||||
{".texi", "application/x-texinfo"},
|
||||
{".texinfo", "application/x-texinfo"},
|
||||
{".tgz", "application/x-compressed"},
|
||||
{".thmx", "application/vnd.ms-officetheme"},
|
||||
{".thn", "application/octet-stream"},
|
||||
{".tif", "image/tiff"},
|
||||
{".tiff", "image/tiff"},
|
||||
{".tlh", "text/plain"},
|
||||
{".tli", "text/plain"},
|
||||
{".toc", "application/octet-stream"},
|
||||
{".tr", "application/x-troff"},
|
||||
{".trm", "application/x-msterminal"},
|
||||
{".trx", "application/xml"},
|
||||
{".ts", "video/vnd.dlna.mpeg-tts"},
|
||||
{".tsv", "text/tab-separated-values"},
|
||||
{".ttf", "application/font-sfnt"},
|
||||
{".tts", "video/vnd.dlna.mpeg-tts"},
|
||||
{".txt", "text/plain"},
|
||||
{".u32", "application/octet-stream"},
|
||||
{".uls", "text/iuls"},
|
||||
{".user", "text/plain"},
|
||||
{".ustar", "application/x-ustar"},
|
||||
{".vb", "text/plain"},
|
||||
{".vbdproj", "text/plain"},
|
||||
{".vbk", "video/mpeg"},
|
||||
{".vbproj", "text/plain"},
|
||||
{".vbs", "text/vbscript"},
|
||||
{".vcf", "text/x-vcard"},
|
||||
{".vcproj", "application/xml"},
|
||||
{".vcs", "text/plain"},
|
||||
{".vcxproj", "application/xml"},
|
||||
{".vddproj", "text/plain"},
|
||||
{".vdp", "text/plain"},
|
||||
{".vdproj", "text/plain"},
|
||||
{".vdx", "application/vnd.ms-visio.viewer"},
|
||||
{".vml", "text/xml"},
|
||||
{".vscontent", "application/xml"},
|
||||
{".vsct", "text/xml"},
|
||||
{".vsd", "application/vnd.visio"},
|
||||
{".vsi", "application/ms-vsi"},
|
||||
{".vsix", "application/vsix"},
|
||||
{".vsixlangpack", "text/xml"},
|
||||
{".vsixmanifest", "text/xml"},
|
||||
{".vsmdi", "application/xml"},
|
||||
{".vspscc", "text/plain"},
|
||||
{".vss", "application/vnd.visio"},
|
||||
{".vsscc", "text/plain"},
|
||||
{".vssettings", "text/xml"},
|
||||
{".vssscc", "text/plain"},
|
||||
{".vst", "application/vnd.visio"},
|
||||
{".vstemplate", "text/xml"},
|
||||
{".vsto", "application/x-ms-vsto"},
|
||||
{".vsw", "application/vnd.visio"},
|
||||
{".vsx", "application/vnd.visio"},
|
||||
{".vtt", "text/vtt"},
|
||||
{".vtx", "application/vnd.visio"},
|
||||
{".wasm", "application/wasm"},
|
||||
{".wav", "audio/wav"},
|
||||
{".wave", "audio/wav"},
|
||||
{".wax", "audio/x-ms-wax"},
|
||||
{".wbk", "application/msword"},
|
||||
{".wbmp", "image/vnd.wap.wbmp"},
|
||||
{".wcm", "application/vnd.ms-works"},
|
||||
{".wdb", "application/vnd.ms-works"},
|
||||
{".wdp", "image/vnd.ms-photo"},
|
||||
{".webarchive", "application/x-safari-webarchive"},
|
||||
{".webm", "video/webm"},
|
||||
{".webp", "image/webp"}, /* https://en.wikipedia.org/wiki/WebP */
|
||||
{".webtest", "application/xml"},
|
||||
{".wiq", "application/xml"},
|
||||
{".wiz", "application/msword"},
|
||||
{".wks", "application/vnd.ms-works"},
|
||||
{".WLMP", "application/wlmoviemaker"},
|
||||
{".wlpginstall", "application/x-wlpg-detect"},
|
||||
{".wlpginstall3", "application/x-wlpg3-detect"},
|
||||
{".wm", "video/x-ms-wm"},
|
||||
{".wma", "audio/x-ms-wma"},
|
||||
{".wmd", "application/x-ms-wmd"},
|
||||
{".wmf", "application/x-msmetafile"},
|
||||
{".wml", "text/vnd.wap.wml"},
|
||||
{".wmlc", "application/vnd.wap.wmlc"},
|
||||
{".wmls", "text/vnd.wap.wmlscript"},
|
||||
{".wmlsc", "application/vnd.wap.wmlscriptc"},
|
||||
{".wmp", "video/x-ms-wmp"},
|
||||
{".wmv", "video/x-ms-wmv"},
|
||||
{".wmx", "video/x-ms-wmx"},
|
||||
{".wmz", "application/x-ms-wmz"},
|
||||
{".woff", "application/font-woff"},
|
||||
{".woff2", "application/font-woff2"},
|
||||
{".wpl", "application/vnd.ms-wpl"},
|
||||
{".wps", "application/vnd.ms-works"},
|
||||
{".wri", "application/x-mswrite"},
|
||||
{".wrl", "x-world/x-vrml"},
|
||||
{".wrz", "x-world/x-vrml"},
|
||||
{".wsc", "text/scriptlet"},
|
||||
{".wsdl", "text/xml"},
|
||||
{".wvx", "video/x-ms-wvx"},
|
||||
{".x", "application/directx"},
|
||||
{".xaf", "x-world/x-vrml"},
|
||||
{".xaml", "application/xaml+xml"},
|
||||
{".xap", "application/x-silverlight-app"},
|
||||
{".xbap", "application/x-ms-xbap"},
|
||||
{".xbm", "image/x-xbitmap"},
|
||||
{".xdr", "text/plain"},
|
||||
{".xht", "application/xhtml+xml"},
|
||||
{".xhtml", "application/xhtml+xml"},
|
||||
{".xla", "application/vnd.ms-excel"},
|
||||
{".xlam", "application/vnd.ms-excel.addin.macroEnabled.12"},
|
||||
{".xlc", "application/vnd.ms-excel"},
|
||||
{".xld", "application/vnd.ms-excel"},
|
||||
{".xlk", "application/vnd.ms-excel"},
|
||||
{".xll", "application/vnd.ms-excel"},
|
||||
{".xlm", "application/vnd.ms-excel"},
|
||||
{".xls", "application/vnd.ms-excel"},
|
||||
{".xlsb", "application/vnd.ms-excel.sheet.binary.macroEnabled.12"},
|
||||
{".xlsm", "application/vnd.ms-excel.sheet.macroEnabled.12"},
|
||||
{".xlsx", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"},
|
||||
{".xlt", "application/vnd.ms-excel"},
|
||||
{".xltm", "application/vnd.ms-excel.template.macroEnabled.12"},
|
||||
{".xltx", "application/vnd.openxmlformats-officedocument.spreadsheetml.template"},
|
||||
{".xlw", "application/vnd.ms-excel"},
|
||||
{".xml", "text/xml"},
|
||||
{".xmp", "application/octet-stream" },
|
||||
{".xmta", "application/xml"},
|
||||
{".xof", "x-world/x-vrml"},
|
||||
{".XOML", "text/plain"},
|
||||
{".xpm", "image/x-xpixmap"},
|
||||
{".xps", "application/vnd.ms-xpsdocument"},
|
||||
{".xrm-ms", "text/xml"},
|
||||
{".xsc", "application/xml"},
|
||||
{".xsd", "text/xml"},
|
||||
{".xsf", "text/xml"},
|
||||
{".xsl", "text/xml"},
|
||||
{".xslt", "text/xml"},
|
||||
{".xsn", "application/octet-stream"},
|
||||
{".xss", "application/xml"},
|
||||
{".xspf", "application/xspf+xml"},
|
||||
{".xtp", "application/octet-stream"},
|
||||
{".xwd", "image/x-xwindowdump"},
|
||||
{".z", "application/x-compress"},
|
||||
{".zip", "application/zip"},
|
||||
|
||||
{"application/fsharp-script", ".fsx"},
|
||||
{"application/msaccess", ".adp"},
|
||||
{"application/msword", ".doc"},
|
||||
{"application/octet-stream", ".bin"},
|
||||
{"application/onenote", ".one"},
|
||||
{"application/postscript", ".eps"},
|
||||
{"application/step", ".step"},
|
||||
{"application/vnd.ms-excel", ".xls"},
|
||||
{"application/vnd.ms-powerpoint", ".ppt"},
|
||||
{"application/vnd.ms-works", ".wks"},
|
||||
{"application/vnd.visio", ".vsd"},
|
||||
{"application/x-director", ".dir"},
|
||||
{"application/x-shockwave-flash", ".swf"},
|
||||
{"application/x-x509-ca-cert", ".cer"},
|
||||
{"application/x-zip-compressed", ".zip"},
|
||||
{"application/xhtml+xml", ".xhtml"},
|
||||
{"application/xml", ".xml"}, // anomoly, .xml -> text/xml, but application/xml -> many thingss, but all are xml, so safest is .xml
|
||||
{"audio/aac", ".AAC"},
|
||||
{"audio/aiff", ".aiff"},
|
||||
{"audio/basic", ".snd"},
|
||||
{"audio/mid", ".midi"},
|
||||
{"audio/wav", ".wav"},
|
||||
{"audio/x-m4a", ".m4a"},
|
||||
{"audio/x-mpegurl", ".m3u"},
|
||||
{"audio/x-pn-realaudio", ".ra"},
|
||||
{"audio/x-smd", ".smd"},
|
||||
{"image/bmp", ".bmp"},
|
||||
{"image/jpeg", ".jpg"},
|
||||
{"image/pict", ".pic"},
|
||||
{"image/png", ".png"}, //Defined in [RFC-2045], [RFC-2048]
|
||||
{"image/x-png", ".png"}, //See https://www.w3.org/TR/PNG/#A-Media-type :"It is recommended that implementations also recognize the media type "image/x-png"."
|
||||
{"image/tiff", ".tiff"},
|
||||
{"image/x-macpaint", ".mac"},
|
||||
{"image/x-quicktime", ".qti"},
|
||||
{"message/rfc822", ".eml"},
|
||||
{"text/html", ".html"},
|
||||
{"text/plain", ".txt"},
|
||||
{"text/scriptlet", ".wsc"},
|
||||
{"text/xml", ".xml"},
|
||||
{"video/3gpp", ".3gp"},
|
||||
{"video/3gpp2", ".3gp2"},
|
||||
{"video/mp4", ".mp4"},
|
||||
{"video/mpeg", ".mpg"},
|
||||
{"video/quicktime", ".mov"},
|
||||
{"video/vnd.dlna.mpeg-tts", ".m2t"},
|
||||
{"video/x-dv", ".dv"},
|
||||
{"video/x-la-asf", ".lsf"},
|
||||
{"video/x-ms-asf", ".asf"},
|
||||
{"x-world/x-vrml", ".xof"}
|
||||
|
||||
};
|
||||
}
|
||||
}
|
||||
494
Source/MyDb/HtmlAgilityPack.Shared/MixedCodeDocument.cs
Normal file
494
Source/MyDb/HtmlAgilityPack.Shared/MixedCodeDocument.cs
Normal file
|
|
@ -0,0 +1,494 @@
|
|||
// Description: Html Agility Pack - HTML Parsers, selectors, traversors, manupulators.
|
||||
// Website & Documentation: http://html-agility-pack.net
|
||||
// Forum & Issues: https://github.com/zzzprojects/html-agility-pack
|
||||
// License: https://github.com/zzzprojects/html-agility-pack/blob/master/LICENSE
|
||||
// More projects: http://www.zzzprojects.com/
|
||||
// Copyright © ZZZ Projects Inc. 2014 - 2017. All rights reserved.
|
||||
|
||||
#if !METRO
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
|
||||
namespace HtmlAgilityPack
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents a document with mixed code and text. ASP, ASPX, JSP, are good example of such documents.
|
||||
/// </summary>
|
||||
public class MixedCodeDocument
|
||||
{
|
||||
#region Fields
|
||||
|
||||
private int _c;
|
||||
internal MixedCodeDocumentFragmentList _codefragments;
|
||||
private MixedCodeDocumentFragment _currentfragment;
|
||||
internal MixedCodeDocumentFragmentList _fragments;
|
||||
private int _index;
|
||||
private int _line;
|
||||
private int _lineposition;
|
||||
private ParseState _state;
|
||||
private Encoding _streamencoding;
|
||||
internal string _text;
|
||||
internal MixedCodeDocumentFragmentList _textfragments;
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the token representing code end.
|
||||
/// </summary>
|
||||
public string TokenCodeEnd = "%>";
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the token representing code start.
|
||||
/// </summary>
|
||||
public string TokenCodeStart = "<%";
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the token representing code directive.
|
||||
/// </summary>
|
||||
public string TokenDirective = "@";
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the token representing response write directive.
|
||||
/// </summary>
|
||||
public string TokenResponseWrite = "Response.Write ";
|
||||
|
||||
|
||||
private string TokenTextBlock = "TextBlock({0})";
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constructors
|
||||
|
||||
/// <summary>
|
||||
/// Creates a mixed code document instance.
|
||||
/// </summary>
|
||||
public MixedCodeDocument()
|
||||
{
|
||||
_codefragments = new MixedCodeDocumentFragmentList(this);
|
||||
_textfragments = new MixedCodeDocumentFragmentList(this);
|
||||
_fragments = new MixedCodeDocumentFragmentList(this);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Properties
|
||||
|
||||
/// <summary>
|
||||
/// Gets the code represented by the mixed code document seen as a template.
|
||||
/// </summary>
|
||||
public string Code
|
||||
{
|
||||
get
|
||||
{
|
||||
string s = "";
|
||||
int i = 0;
|
||||
foreach (MixedCodeDocumentFragment frag in _fragments)
|
||||
{
|
||||
switch (frag._type)
|
||||
{
|
||||
case MixedCodeDocumentFragmentType.Text:
|
||||
s += TokenResponseWrite + string.Format(TokenTextBlock, i) + "\n";
|
||||
i++;
|
||||
break;
|
||||
|
||||
case MixedCodeDocumentFragmentType.Code:
|
||||
s += ((MixedCodeDocumentCodeFragment) frag).Code + "\n";
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return s;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the list of code fragments in the document.
|
||||
/// </summary>
|
||||
public MixedCodeDocumentFragmentList CodeFragments
|
||||
{
|
||||
get { return _codefragments; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the list of all fragments in the document.
|
||||
/// </summary>
|
||||
public MixedCodeDocumentFragmentList Fragments
|
||||
{
|
||||
get { return _fragments; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the encoding of the stream used to read the document.
|
||||
/// </summary>
|
||||
public Encoding StreamEncoding
|
||||
{
|
||||
get { return _streamencoding; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the list of text fragments in the document.
|
||||
/// </summary>
|
||||
public MixedCodeDocumentFragmentList TextFragments
|
||||
{
|
||||
get { return _textfragments; }
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Public Methods
|
||||
|
||||
/// <summary>
|
||||
/// Create a code fragment instances.
|
||||
/// </summary>
|
||||
/// <returns>The newly created code fragment instance.</returns>
|
||||
public MixedCodeDocumentCodeFragment CreateCodeFragment()
|
||||
{
|
||||
return (MixedCodeDocumentCodeFragment) CreateFragment(MixedCodeDocumentFragmentType.Code);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Create a text fragment instances.
|
||||
/// </summary>
|
||||
/// <returns>The newly created text fragment instance.</returns>
|
||||
public MixedCodeDocumentTextFragment CreateTextFragment()
|
||||
{
|
||||
return (MixedCodeDocumentTextFragment) CreateFragment(MixedCodeDocumentFragmentType.Text);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Loads a mixed code document from a stream.
|
||||
/// </summary>
|
||||
/// <param name="stream">The input stream.</param>
|
||||
public void Load(Stream stream)
|
||||
{
|
||||
Load(new StreamReader(stream));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Loads a mixed code document from a stream.
|
||||
/// </summary>
|
||||
/// <param name="stream">The input stream.</param>
|
||||
/// <param name="detectEncodingFromByteOrderMarks">Indicates whether to look for byte order marks at the beginning of the file.</param>
|
||||
public void Load(Stream stream, bool detectEncodingFromByteOrderMarks)
|
||||
{
|
||||
Load(new StreamReader(stream, detectEncodingFromByteOrderMarks));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Loads a mixed code document from a stream.
|
||||
/// </summary>
|
||||
/// <param name="stream">The input stream.</param>
|
||||
/// <param name="encoding">The character encoding to use.</param>
|
||||
public void Load(Stream stream, Encoding encoding)
|
||||
{
|
||||
Load(new StreamReader(stream, encoding));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Loads a mixed code document from a stream.
|
||||
/// </summary>
|
||||
/// <param name="stream">The input stream.</param>
|
||||
/// <param name="encoding">The character encoding to use.</param>
|
||||
/// <param name="detectEncodingFromByteOrderMarks">Indicates whether to look for byte order marks at the beginning of the file.</param>
|
||||
public void Load(Stream stream, Encoding encoding, bool detectEncodingFromByteOrderMarks)
|
||||
{
|
||||
Load(new StreamReader(stream, encoding, detectEncodingFromByteOrderMarks));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Loads a mixed code document from a stream.
|
||||
/// </summary>
|
||||
/// <param name="stream">The input stream.</param>
|
||||
/// <param name="encoding">The character encoding to use.</param>
|
||||
/// <param name="detectEncodingFromByteOrderMarks">Indicates whether to look for byte order marks at the beginning of the file.</param>
|
||||
/// <param name="buffersize">The minimum buffer size.</param>
|
||||
public void Load(Stream stream, Encoding encoding, bool detectEncodingFromByteOrderMarks, int buffersize)
|
||||
{
|
||||
Load(new StreamReader(stream, encoding, detectEncodingFromByteOrderMarks, buffersize));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Loads a mixed code document from a file.
|
||||
/// </summary>
|
||||
/// <param name="path">The complete file path to be read.</param>
|
||||
public void Load(string path)
|
||||
{
|
||||
#if NETSTANDARD1_3 || NETSTANDARD1_6
|
||||
Load(new StreamReader(File.OpenRead(path)));
|
||||
#else
|
||||
Load(new StreamReader(path));
|
||||
#endif
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Loads a mixed code document from a file.
|
||||
/// </summary>
|
||||
/// <param name="path">The complete file path to be read.</param>
|
||||
/// <param name="detectEncodingFromByteOrderMarks">Indicates whether to look for byte order marks at the beginning of the file.</param>
|
||||
public void Load(string path, bool detectEncodingFromByteOrderMarks)
|
||||
{
|
||||
#if NETSTANDARD1_3 || NETSTANDARD1_6
|
||||
Load(new StreamReader(File.OpenRead(path), detectEncodingFromByteOrderMarks));
|
||||
#else
|
||||
Load(new StreamReader(path, detectEncodingFromByteOrderMarks));
|
||||
#endif
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Loads a mixed code document from a file.
|
||||
/// </summary>
|
||||
/// <param name="path">The complete file path to be read.</param>
|
||||
/// <param name="encoding">The character encoding to use.</param>
|
||||
public void Load(string path, Encoding encoding)
|
||||
{
|
||||
#if NETSTANDARD1_3 || NETSTANDARD1_6
|
||||
Load(new StreamReader(File.OpenRead(path), encoding));
|
||||
#else
|
||||
Load(new StreamReader(path, encoding));
|
||||
#endif
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Loads a mixed code document from a file.
|
||||
/// </summary>
|
||||
/// <param name="path">The complete file path to be read.</param>
|
||||
/// <param name="encoding">The character encoding to use.</param>
|
||||
/// <param name="detectEncodingFromByteOrderMarks">Indicates whether to look for byte order marks at the beginning of the file.</param>
|
||||
public void Load(string path, Encoding encoding, bool detectEncodingFromByteOrderMarks)
|
||||
{
|
||||
#if NETSTANDARD1_3 || NETSTANDARD1_6
|
||||
Load(new StreamReader(File.OpenRead(path), encoding, detectEncodingFromByteOrderMarks));
|
||||
#else
|
||||
Load(new StreamReader(path, encoding, detectEncodingFromByteOrderMarks));
|
||||
#endif
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Loads a mixed code document from a file.
|
||||
/// </summary>
|
||||
/// <param name="path">The complete file path to be read.</param>
|
||||
/// <param name="encoding">The character encoding to use.</param>
|
||||
/// <param name="detectEncodingFromByteOrderMarks">Indicates whether to look for byte order marks at the beginning of the file.</param>
|
||||
/// <param name="buffersize">The minimum buffer size.</param>
|
||||
public void Load(string path, Encoding encoding, bool detectEncodingFromByteOrderMarks, int buffersize)
|
||||
{
|
||||
#if NETSTANDARD1_3 || NETSTANDARD1_6
|
||||
Load(new StreamReader(File.OpenRead(path), encoding, detectEncodingFromByteOrderMarks, buffersize));
|
||||
#else
|
||||
Load(new StreamReader(path, encoding, detectEncodingFromByteOrderMarks, buffersize));
|
||||
#endif
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Loads the mixed code document from the specified TextReader.
|
||||
/// </summary>
|
||||
/// <param name="reader">The TextReader used to feed the HTML data into the document.</param>
|
||||
public void Load(TextReader reader)
|
||||
{
|
||||
_codefragments.Clear();
|
||||
_textfragments.Clear();
|
||||
|
||||
// all pseudo constructors get down to this one
|
||||
using (StreamReader sr = reader as StreamReader)
|
||||
{
|
||||
if (sr != null)
|
||||
{
|
||||
_streamencoding = sr.CurrentEncoding;
|
||||
}
|
||||
|
||||
_text = reader.ReadToEnd();
|
||||
}
|
||||
|
||||
Parse();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Loads a mixed document from a text
|
||||
/// </summary>
|
||||
/// <param name="html">The text to load.</param>
|
||||
public void LoadHtml(string html)
|
||||
{
|
||||
Load(new StringReader(html));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Saves the mixed document to the specified stream.
|
||||
/// </summary>
|
||||
/// <param name="outStream">The stream to which you want to save.</param>
|
||||
public void Save(Stream outStream)
|
||||
{
|
||||
StreamWriter sw = new StreamWriter(outStream, GetOutEncoding());
|
||||
Save(sw);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Saves the mixed document to the specified stream.
|
||||
/// </summary>
|
||||
/// <param name="outStream">The stream to which you want to save.</param>
|
||||
/// <param name="encoding">The character encoding to use.</param>
|
||||
public void Save(Stream outStream, Encoding encoding)
|
||||
{
|
||||
StreamWriter sw = new StreamWriter(outStream, encoding);
|
||||
Save(sw);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Saves the mixed document to the specified file.
|
||||
/// </summary>
|
||||
/// <param name="filename">The location of the file where you want to save the document.</param>
|
||||
public void Save(string filename)
|
||||
{
|
||||
#if NETSTANDARD1_3 || NETSTANDARD1_6
|
||||
StreamWriter sw = new StreamWriter(File.OpenWrite(filename), GetOutEncoding());
|
||||
#else
|
||||
StreamWriter sw = new StreamWriter(filename, false, GetOutEncoding());
|
||||
#endif
|
||||
Save(sw);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Saves the mixed document to the specified file.
|
||||
/// </summary>
|
||||
/// <param name="filename">The location of the file where you want to save the document.</param>
|
||||
/// <param name="encoding">The character encoding to use.</param>
|
||||
public void Save(string filename, Encoding encoding)
|
||||
{
|
||||
#if NETSTANDARD1_3 || NETSTANDARD1_6
|
||||
StreamWriter sw = new StreamWriter(File.OpenWrite(filename), encoding);
|
||||
#else
|
||||
StreamWriter sw = new StreamWriter(filename, false, encoding);
|
||||
#endif
|
||||
Save(sw);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Saves the mixed document to the specified StreamWriter.
|
||||
/// </summary>
|
||||
/// <param name="writer">The StreamWriter to which you want to save.</param>
|
||||
public void Save(StreamWriter writer)
|
||||
{
|
||||
Save((TextWriter) writer);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Saves the mixed document to the specified TextWriter.
|
||||
/// </summary>
|
||||
/// <param name="writer">The TextWriter to which you want to save.</param>
|
||||
public void Save(TextWriter writer)
|
||||
{
|
||||
writer.Flush();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Internal Methods
|
||||
|
||||
internal MixedCodeDocumentFragment CreateFragment(MixedCodeDocumentFragmentType type)
|
||||
{
|
||||
switch (type)
|
||||
{
|
||||
case MixedCodeDocumentFragmentType.Text:
|
||||
return new MixedCodeDocumentTextFragment(this);
|
||||
|
||||
case MixedCodeDocumentFragmentType.Code:
|
||||
return new MixedCodeDocumentCodeFragment(this);
|
||||
|
||||
default:
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
}
|
||||
|
||||
internal Encoding GetOutEncoding()
|
||||
{
|
||||
if (_streamencoding != null)
|
||||
return _streamencoding;
|
||||
return Encoding.UTF8;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Private Methods
|
||||
|
||||
private void IncrementPosition()
|
||||
{
|
||||
_index++;
|
||||
if (_c == 10)
|
||||
{
|
||||
_lineposition = 1;
|
||||
_line++;
|
||||
}
|
||||
else
|
||||
_lineposition++;
|
||||
}
|
||||
|
||||
private void Parse()
|
||||
{
|
||||
_state = ParseState.Text;
|
||||
_index = 0;
|
||||
_currentfragment = CreateFragment(MixedCodeDocumentFragmentType.Text);
|
||||
|
||||
while (_index < _text.Length)
|
||||
{
|
||||
_c = _text[_index];
|
||||
IncrementPosition();
|
||||
|
||||
switch (_state)
|
||||
{
|
||||
case ParseState.Text:
|
||||
if (_index + TokenCodeStart.Length < _text.Length)
|
||||
{
|
||||
if (_text.Substring(_index - 1, TokenCodeStart.Length) == TokenCodeStart)
|
||||
{
|
||||
_state = ParseState.Code;
|
||||
_currentfragment.Length = _index - 1 - _currentfragment.Index;
|
||||
_currentfragment = CreateFragment(MixedCodeDocumentFragmentType.Code);
|
||||
SetPosition();
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case ParseState.Code:
|
||||
if (_index + TokenCodeEnd.Length < _text.Length)
|
||||
{
|
||||
if (_text.Substring(_index - 1, TokenCodeEnd.Length) == TokenCodeEnd)
|
||||
{
|
||||
_state = ParseState.Text;
|
||||
_currentfragment.Length = _index + TokenCodeEnd.Length - _currentfragment.Index;
|
||||
_index += TokenCodeEnd.Length;
|
||||
_lineposition += TokenCodeEnd.Length;
|
||||
_currentfragment = CreateFragment(MixedCodeDocumentFragmentType.Text);
|
||||
SetPosition();
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
_currentfragment.Length = _index - _currentfragment.Index;
|
||||
}
|
||||
|
||||
private void SetPosition()
|
||||
{
|
||||
_currentfragment.Line = _line;
|
||||
_currentfragment._lineposition = _lineposition;
|
||||
_currentfragment.Index = _index - 1;
|
||||
_currentfragment.Length = 0;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Nested type: ParseState
|
||||
|
||||
private enum ParseState
|
||||
{
|
||||
Text,
|
||||
Code
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
|
@ -0,0 +1,60 @@
|
|||
// Description: Html Agility Pack - HTML Parsers, selectors, traversors, manupulators.
|
||||
// Website & Documentation: http://html-agility-pack.net
|
||||
// Forum & Issues: https://github.com/zzzprojects/html-agility-pack
|
||||
// License: https://github.com/zzzprojects/html-agility-pack/blob/master/LICENSE
|
||||
// More projects: http://www.zzzprojects.com/
|
||||
// Copyright © ZZZ Projects Inc. 2014 - 2017. All rights reserved.
|
||||
|
||||
#if !METRO
|
||||
namespace HtmlAgilityPack
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents a fragment of code in a mixed code document.
|
||||
/// </summary>
|
||||
public class MixedCodeDocumentCodeFragment : MixedCodeDocumentFragment
|
||||
{
|
||||
#region Fields
|
||||
|
||||
private string _code;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constructors
|
||||
|
||||
internal MixedCodeDocumentCodeFragment(MixedCodeDocument doc)
|
||||
:
|
||||
base(doc, MixedCodeDocumentFragmentType.Code)
|
||||
{
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Properties
|
||||
|
||||
/// <summary>
|
||||
/// Gets the fragment code text.
|
||||
/// </summary>
|
||||
public string Code
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_code == null)
|
||||
{
|
||||
_code = FragmentText.Substring(Doc.TokenCodeStart.Length,
|
||||
FragmentText.Length - Doc.TokenCodeEnd.Length -
|
||||
Doc.TokenCodeStart.Length - 1).Trim();
|
||||
if (_code.StartsWith("="))
|
||||
{
|
||||
_code = Doc.TokenResponseWrite + _code.Substring(1, _code.Length - 1);
|
||||
}
|
||||
}
|
||||
|
||||
return _code;
|
||||
}
|
||||
set { _code = value; }
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
#endif
|
||||
105
Source/MyDb/HtmlAgilityPack.Shared/MixedCodeDocumentFragment.cs
Normal file
105
Source/MyDb/HtmlAgilityPack.Shared/MixedCodeDocumentFragment.cs
Normal file
|
|
@ -0,0 +1,105 @@
|
|||
// Description: Html Agility Pack - HTML Parsers, selectors, traversors, manupulators.
|
||||
// Website & Documentation: http://html-agility-pack.net
|
||||
// Forum & Issues: https://github.com/zzzprojects/html-agility-pack
|
||||
// License: https://github.com/zzzprojects/html-agility-pack/blob/master/LICENSE
|
||||
// More projects: http://www.zzzprojects.com/
|
||||
// Copyright © ZZZ Projects Inc. 2014 - 2017. All rights reserved.
|
||||
|
||||
#if !METRO
|
||||
namespace HtmlAgilityPack
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents a base class for fragments in a mixed code document.
|
||||
/// </summary>
|
||||
public abstract class MixedCodeDocumentFragment
|
||||
{
|
||||
#region Fields
|
||||
|
||||
internal MixedCodeDocument Doc;
|
||||
private string _fragmentText;
|
||||
internal int Index;
|
||||
internal int Length;
|
||||
private int _line;
|
||||
internal int _lineposition;
|
||||
internal MixedCodeDocumentFragmentType _type;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constructors
|
||||
|
||||
internal MixedCodeDocumentFragment(MixedCodeDocument doc, MixedCodeDocumentFragmentType type)
|
||||
{
|
||||
Doc = doc;
|
||||
_type = type;
|
||||
switch (type)
|
||||
{
|
||||
case MixedCodeDocumentFragmentType.Text:
|
||||
Doc._textfragments.Append(this);
|
||||
break;
|
||||
|
||||
case MixedCodeDocumentFragmentType.Code:
|
||||
Doc._codefragments.Append(this);
|
||||
break;
|
||||
}
|
||||
|
||||
Doc._fragments.Append(this);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Properties
|
||||
|
||||
/// <summary>
|
||||
/// Gets the fragement text.
|
||||
/// </summary>
|
||||
public string FragmentText
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_fragmentText == null)
|
||||
{
|
||||
_fragmentText = Doc._text.Substring(Index, Length);
|
||||
}
|
||||
|
||||
return _fragmentText;
|
||||
}
|
||||
internal set { _fragmentText = value; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the type of fragment.
|
||||
/// </summary>
|
||||
public MixedCodeDocumentFragmentType FragmentType
|
||||
{
|
||||
get { return _type; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the line number of the fragment.
|
||||
/// </summary>
|
||||
public int Line
|
||||
{
|
||||
get { return _line; }
|
||||
internal set { _line = value; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the line position (column) of the fragment.
|
||||
/// </summary>
|
||||
public int LinePosition
|
||||
{
|
||||
get { return _lineposition; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the fragment position in the document's stream.
|
||||
/// </summary>
|
||||
public int StreamPosition
|
||||
{
|
||||
get { return Index; }
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
|
@ -0,0 +1,252 @@
|
|||
// Description: Html Agility Pack - HTML Parsers, selectors, traversors, manupulators.
|
||||
// Website & Documentation: http://html-agility-pack.net
|
||||
// Forum & Issues: https://github.com/zzzprojects/html-agility-pack
|
||||
// License: https://github.com/zzzprojects/html-agility-pack/blob/master/LICENSE
|
||||
// More projects: http://www.zzzprojects.com/
|
||||
// Copyright © ZZZ Projects Inc. 2014 - 2017. All rights reserved.
|
||||
|
||||
#if !METRO
|
||||
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace HtmlAgilityPack
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents a list of mixed code fragments.
|
||||
/// </summary>
|
||||
public class MixedCodeDocumentFragmentList : IEnumerable
|
||||
{
|
||||
#region Fields
|
||||
|
||||
private MixedCodeDocument _doc;
|
||||
private IList<MixedCodeDocumentFragment> _items = new List<MixedCodeDocumentFragment>();
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constructors
|
||||
|
||||
internal MixedCodeDocumentFragmentList(MixedCodeDocument doc)
|
||||
{
|
||||
_doc = doc;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Properties
|
||||
|
||||
///<summary>
|
||||
/// Gets the Document
|
||||
///</summary>
|
||||
public MixedCodeDocument Doc
|
||||
{
|
||||
get { return _doc; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the number of fragments contained in the list.
|
||||
/// </summary>
|
||||
public int Count
|
||||
{
|
||||
get { return _items.Count; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a fragment from the list using its index.
|
||||
/// </summary>
|
||||
public MixedCodeDocumentFragment this[int index]
|
||||
{
|
||||
get { return _items[index]; }
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region IEnumerable Members
|
||||
|
||||
/// <summary>
|
||||
/// Gets an enumerator that can iterate through the fragment list.
|
||||
/// </summary>
|
||||
IEnumerator IEnumerable.GetEnumerator()
|
||||
{
|
||||
return GetEnumerator();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Public Methods
|
||||
|
||||
/// <summary>
|
||||
/// Appends a fragment to the list of fragments.
|
||||
/// </summary>
|
||||
/// <param name="newFragment">The fragment to append. May not be null.</param>
|
||||
public void Append(MixedCodeDocumentFragment newFragment)
|
||||
{
|
||||
if (newFragment == null)
|
||||
{
|
||||
throw new ArgumentNullException("newFragment");
|
||||
}
|
||||
|
||||
_items.Add(newFragment);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets an enumerator that can iterate through the fragment list.
|
||||
/// </summary>
|
||||
public MixedCodeDocumentFragmentEnumerator GetEnumerator()
|
||||
{
|
||||
return new MixedCodeDocumentFragmentEnumerator(_items);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Prepends a fragment to the list of fragments.
|
||||
/// </summary>
|
||||
/// <param name="newFragment">The fragment to append. May not be null.</param>
|
||||
public void Prepend(MixedCodeDocumentFragment newFragment)
|
||||
{
|
||||
if (newFragment == null)
|
||||
{
|
||||
throw new ArgumentNullException("newFragment");
|
||||
}
|
||||
|
||||
_items.Insert(0, newFragment);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Remove a fragment from the list of fragments. If this fragment was not in the list, an exception will be raised.
|
||||
/// </summary>
|
||||
/// <param name="fragment">The fragment to remove. May not be null.</param>
|
||||
public void Remove(MixedCodeDocumentFragment fragment)
|
||||
{
|
||||
if (fragment == null)
|
||||
{
|
||||
throw new ArgumentNullException("fragment");
|
||||
}
|
||||
|
||||
int index = GetFragmentIndex(fragment);
|
||||
if (index == -1)
|
||||
{
|
||||
throw new IndexOutOfRangeException();
|
||||
}
|
||||
|
||||
RemoveAt(index);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Remove all fragments from the list.
|
||||
/// </summary>
|
||||
public void RemoveAll()
|
||||
{
|
||||
_items.Clear();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Remove a fragment from the list of fragments, using its index in the list.
|
||||
/// </summary>
|
||||
/// <param name="index">The index of the fragment to remove.</param>
|
||||
public void RemoveAt(int index)
|
||||
{
|
||||
//MixedCodeDocumentFragment frag = (MixedCodeDocumentFragment) _items[index];
|
||||
_items.RemoveAt(index);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Internal Methods
|
||||
|
||||
internal void Clear()
|
||||
{
|
||||
_items.Clear();
|
||||
}
|
||||
|
||||
internal int GetFragmentIndex(MixedCodeDocumentFragment fragment)
|
||||
{
|
||||
if (fragment == null)
|
||||
{
|
||||
throw new ArgumentNullException("fragment");
|
||||
}
|
||||
|
||||
for (int i = 0; i < _items.Count; i++)
|
||||
{
|
||||
if ((_items[i]) == fragment)
|
||||
{
|
||||
return i;
|
||||
}
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Nested type: MixedCodeDocumentFragmentEnumerator
|
||||
|
||||
/// <summary>
|
||||
/// Represents a fragment enumerator.
|
||||
/// </summary>
|
||||
public class MixedCodeDocumentFragmentEnumerator : IEnumerator
|
||||
{
|
||||
#region Fields
|
||||
|
||||
private int _index;
|
||||
private IList<MixedCodeDocumentFragment> _items;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constructors
|
||||
|
||||
internal MixedCodeDocumentFragmentEnumerator(IList<MixedCodeDocumentFragment> items)
|
||||
{
|
||||
_items = items;
|
||||
_index = -1;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Properties
|
||||
|
||||
/// <summary>
|
||||
/// Gets the current element in the collection.
|
||||
/// </summary>
|
||||
public MixedCodeDocumentFragment Current
|
||||
{
|
||||
get { return (MixedCodeDocumentFragment) (_items[_index]); }
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region IEnumerator Members
|
||||
|
||||
/// <summary>
|
||||
/// Gets the current element in the collection.
|
||||
/// </summary>
|
||||
object IEnumerator.Current
|
||||
{
|
||||
get { return (Current); }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Advances the enumerator to the next element of the collection.
|
||||
/// </summary>
|
||||
/// <returns>true if the enumerator was successfully advanced to the next element; false if the enumerator has passed the end of the collection.</returns>
|
||||
public bool MoveNext()
|
||||
{
|
||||
_index++;
|
||||
return (_index < _items.Count);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the enumerator to its initial position, which is before the first element in the collection.
|
||||
/// </summary>
|
||||
public void Reset()
|
||||
{
|
||||
_index = -1;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
|
@ -0,0 +1,27 @@
|
|||
// Description: Html Agility Pack - HTML Parsers, selectors, traversors, manupulators.
|
||||
// Website & Documentation: http://html-agility-pack.net
|
||||
// Forum & Issues: https://github.com/zzzprojects/html-agility-pack
|
||||
// License: https://github.com/zzzprojects/html-agility-pack/blob/master/LICENSE
|
||||
// More projects: http://www.zzzprojects.com/
|
||||
// Copyright © ZZZ Projects Inc. 2014 - 2017. All rights reserved.
|
||||
|
||||
#if !METRO
|
||||
namespace HtmlAgilityPack
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents the type of fragment in a mixed code document.
|
||||
/// </summary>
|
||||
public enum MixedCodeDocumentFragmentType
|
||||
{
|
||||
/// <summary>
|
||||
/// The fragment contains code.
|
||||
/// </summary>
|
||||
Code,
|
||||
|
||||
/// <summary>
|
||||
/// The fragment contains text.
|
||||
/// </summary>
|
||||
Text,
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
|
@ -0,0 +1,40 @@
|
|||
// Description: Html Agility Pack - HTML Parsers, selectors, traversors, manupulators.
|
||||
// Website & Documentation: http://html-agility-pack.net
|
||||
// Forum & Issues: https://github.com/zzzprojects/html-agility-pack
|
||||
// License: https://github.com/zzzprojects/html-agility-pack/blob/master/LICENSE
|
||||
// More projects: http://www.zzzprojects.com/
|
||||
// Copyright © ZZZ Projects Inc. 2014 - 2017. All rights reserved.
|
||||
|
||||
#if !METRO
|
||||
namespace HtmlAgilityPack
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents a fragment of text in a mixed code document.
|
||||
/// </summary>
|
||||
public class MixedCodeDocumentTextFragment : MixedCodeDocumentFragment
|
||||
{
|
||||
#region Constructors
|
||||
|
||||
internal MixedCodeDocumentTextFragment(MixedCodeDocument doc)
|
||||
:
|
||||
base(doc, MixedCodeDocumentFragmentType.Text)
|
||||
{
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Properties
|
||||
|
||||
/// <summary>
|
||||
/// Gets the fragment text.
|
||||
/// </summary>
|
||||
public string Text
|
||||
{
|
||||
get { return FragmentText; }
|
||||
set { FragmentText = value; }
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
#endif
|
||||
43
Source/MyDb/HtmlAgilityPack.Shared/NameValuePair.cs
Normal file
43
Source/MyDb/HtmlAgilityPack.Shared/NameValuePair.cs
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
// Description: Html Agility Pack - HTML Parsers, selectors, traversors, manupulators.
|
||||
// Website & Documentation: http://html-agility-pack.net
|
||||
// Forum & Issues: https://github.com/zzzprojects/html-agility-pack
|
||||
// License: https://github.com/zzzprojects/html-agility-pack/blob/master/LICENSE
|
||||
// More projects: http://www.zzzprojects.com/
|
||||
// Copyright © ZZZ Projects Inc. 2014 - 2017. All rights reserved.
|
||||
|
||||
#if METRO
|
||||
namespace HtmlAgilityPack
|
||||
{
|
||||
internal class NameValuePair
|
||||
{
|
||||
#region Fields
|
||||
|
||||
internal readonly string Name;
|
||||
internal string Value;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constructors
|
||||
|
||||
internal NameValuePair()
|
||||
{
|
||||
}
|
||||
|
||||
internal NameValuePair(string name)
|
||||
:
|
||||
this()
|
||||
{
|
||||
Name = name;
|
||||
}
|
||||
|
||||
internal NameValuePair(string name, string value)
|
||||
:
|
||||
this(name)
|
||||
{
|
||||
Value = value;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
#endif
|
||||
106
Source/MyDb/HtmlAgilityPack.Shared/NameValuePairList.cs
Normal file
106
Source/MyDb/HtmlAgilityPack.Shared/NameValuePairList.cs
Normal file
|
|
@ -0,0 +1,106 @@
|
|||
// Description: Html Agility Pack - HTML Parsers, selectors, traversors, manupulators.
|
||||
// Website & Documentation: http://html-agility-pack.net
|
||||
// Forum & Issues: https://github.com/zzzprojects/html-agility-pack
|
||||
// License: https://github.com/zzzprojects/html-agility-pack/blob/master/LICENSE
|
||||
// More projects: http://www.zzzprojects.com/
|
||||
// Copyright © ZZZ Projects Inc. 2014 - 2017. All rights reserved.
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace HtmlAgilityPack
|
||||
{
|
||||
internal class NameValuePairList
|
||||
{
|
||||
#region Fields
|
||||
|
||||
internal readonly string Text;
|
||||
private List<KeyValuePair<string, string>> _allPairs;
|
||||
private Dictionary<string, List<KeyValuePair<string, string>>> _pairsWithName;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constructors
|
||||
|
||||
internal NameValuePairList() :
|
||||
this(null)
|
||||
{
|
||||
}
|
||||
|
||||
internal NameValuePairList(string text)
|
||||
{
|
||||
Text = text;
|
||||
_allPairs = new List<KeyValuePair<string, string>>();
|
||||
_pairsWithName = new Dictionary<string, List<KeyValuePair<string, string>>>();
|
||||
|
||||
Parse(text);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Internal Methods
|
||||
|
||||
internal static string GetNameValuePairsValue(string text, string name)
|
||||
{
|
||||
NameValuePairList l = new NameValuePairList(text);
|
||||
return l.GetNameValuePairValue(name);
|
||||
}
|
||||
|
||||
internal List<KeyValuePair<string, string>> GetNameValuePairs(string name)
|
||||
{
|
||||
if (name == null)
|
||||
return _allPairs;
|
||||
return _pairsWithName.ContainsKey(name) ? _pairsWithName[name] : new List<KeyValuePair<string, string>>();
|
||||
}
|
||||
|
||||
internal string GetNameValuePairValue(string name)
|
||||
{
|
||||
if (name == null)
|
||||
throw new ArgumentNullException();
|
||||
List<KeyValuePair<string, string>> al = GetNameValuePairs(name);
|
||||
if (al.Count == 0)
|
||||
return string.Empty;
|
||||
|
||||
// return first item
|
||||
return al[0].Value.Trim();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Private Methods
|
||||
|
||||
private void Parse(string text)
|
||||
{
|
||||
_allPairs.Clear();
|
||||
_pairsWithName.Clear();
|
||||
if (text == null)
|
||||
return;
|
||||
|
||||
string[] p = text.Split(';');
|
||||
foreach (string pv in p)
|
||||
{
|
||||
if (pv.Length == 0)
|
||||
continue;
|
||||
string[] onep = pv.Split(new[] {'='}, 2);
|
||||
if (onep.Length == 0)
|
||||
continue;
|
||||
KeyValuePair<string, string> nvp = new KeyValuePair<string, string>(onep[0].Trim().ToLowerInvariant(),
|
||||
onep.Length < 2 ? "" : onep[1]);
|
||||
|
||||
_allPairs.Add(nvp);
|
||||
|
||||
// index by name
|
||||
List<KeyValuePair<string, string>> al;
|
||||
if (!_pairsWithName.TryGetValue(nvp.Key, out al))
|
||||
{
|
||||
al = new List<KeyValuePair<string, string>>();
|
||||
_pairsWithName.Add(nvp.Key, al);
|
||||
}
|
||||
|
||||
al.Add(nvp);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
17
Source/MyDb/HtmlAgilityPack.Shared/Trace.FullFramework.cs
Normal file
17
Source/MyDb/HtmlAgilityPack.Shared/Trace.FullFramework.cs
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
// Description: Html Agility Pack - HTML Parsers, selectors, traversors, manupulators.
|
||||
// Website & Documentation: http://html-agility-pack.net
|
||||
// Forum & Issues: https://github.com/zzzprojects/html-agility-pack
|
||||
// License: https://github.com/zzzprojects/html-agility-pack/blob/master/LICENSE
|
||||
// More projects: http://www.zzzprojects.com/
|
||||
// Copyright © ZZZ Projects Inc. 2014 - 2017. All rights reserved.
|
||||
|
||||
namespace HtmlAgilityPack
|
||||
{
|
||||
partial class Trace
|
||||
{
|
||||
partial void WriteLineIntern(string message, string category)
|
||||
{
|
||||
System.Diagnostics.Debug.WriteLine(message, category);
|
||||
}
|
||||
}
|
||||
}
|
||||
31
Source/MyDb/HtmlAgilityPack.Shared/Trace.cs
Normal file
31
Source/MyDb/HtmlAgilityPack.Shared/Trace.cs
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
// Description: Html Agility Pack - HTML Parsers, selectors, traversors, manupulators.
|
||||
// Website & Documentation: http://html-agility-pack.net
|
||||
// Forum & Issues: https://github.com/zzzprojects/html-agility-pack
|
||||
// License: https://github.com/zzzprojects/html-agility-pack/blob/master/LICENSE
|
||||
// More projects: http://www.zzzprojects.com/
|
||||
// Copyright © ZZZ Projects Inc. 2014 - 2017. All rights reserved.
|
||||
|
||||
namespace HtmlAgilityPack
|
||||
{
|
||||
internal partial class Trace
|
||||
{
|
||||
internal static Trace _current;
|
||||
|
||||
internal static Trace Current
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_current == null)
|
||||
_current = new Trace();
|
||||
return _current;
|
||||
}
|
||||
}
|
||||
|
||||
partial void WriteLineIntern(string message, string category);
|
||||
|
||||
public static void WriteLine(string message, string category)
|
||||
{
|
||||
Current.WriteLineIntern(message, category);
|
||||
}
|
||||
}
|
||||
}
|
||||
64
Source/MyDb/HtmlAgilityPack.Shared/Utilities.cs
Normal file
64
Source/MyDb/HtmlAgilityPack.Shared/Utilities.cs
Normal file
|
|
@ -0,0 +1,64 @@
|
|||
// Description: Html Agility Pack - HTML Parsers, selectors, traversors, manupulators.
|
||||
// Website & Documentation: http://html-agility-pack.net
|
||||
// Forum & Issues: https://github.com/zzzprojects/html-agility-pack
|
||||
// License: https://github.com/zzzprojects/html-agility-pack/blob/master/LICENSE
|
||||
// More projects: http://www.zzzprojects.com/
|
||||
// Copyright © ZZZ Projects Inc. 2014 - 2017. All rights reserved.
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
|
||||
namespace HtmlAgilityPack
|
||||
{
|
||||
internal static class Utilities
|
||||
{
|
||||
public static TValue GetDictionaryValueOrDefault<TKey, TValue>(Dictionary<TKey, TValue> dict, TKey key, TValue defaultValue = default(TValue)) where TKey : class
|
||||
{
|
||||
TValue value;
|
||||
if (!dict.TryGetValue(key, out value))
|
||||
return defaultValue;
|
||||
return value;
|
||||
}
|
||||
|
||||
#if !(METRO || NETSTANDARD1_3 || NETSTANDARD1_6)
|
||||
internal static object To(this Object @this, Type type)
|
||||
{
|
||||
if (@this != null)
|
||||
{
|
||||
Type targetType = type;
|
||||
|
||||
if (@this.GetType() == targetType)
|
||||
{
|
||||
return @this;
|
||||
}
|
||||
|
||||
TypeConverter converter = TypeDescriptor.GetConverter(@this);
|
||||
if (converter != null)
|
||||
{
|
||||
if (converter.CanConvertTo(targetType))
|
||||
{
|
||||
return converter.ConvertTo(@this, targetType);
|
||||
}
|
||||
}
|
||||
|
||||
converter = TypeDescriptor.GetConverter(targetType);
|
||||
if (converter != null)
|
||||
{
|
||||
if (converter.CanConvertFrom(@this.GetType()))
|
||||
{
|
||||
return converter.ConvertFrom(@this);
|
||||
}
|
||||
}
|
||||
|
||||
if (@this == DBNull.Value)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
return @this;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
170
Source/MyDb/HtmlAgilityPack.Shared/crc32.cs
Normal file
170
Source/MyDb/HtmlAgilityPack.Shared/crc32.cs
Normal file
|
|
@ -0,0 +1,170 @@
|
|||
// Description: Html Agility Pack - HTML Parsers, selectors, traversors, manupulators.
|
||||
// Website & Documentation: http://html-agility-pack.net
|
||||
// Forum & Issues: https://github.com/zzzprojects/html-agility-pack
|
||||
// License: https://github.com/zzzprojects/html-agility-pack/blob/master/LICENSE
|
||||
// More projects: http://www.zzzprojects.com/
|
||||
// Copyright ?ZZZ Projects Inc. 2014 - 2017. All rights reserved.
|
||||
|
||||
using System;
|
||||
|
||||
namespace HtmlAgilityPack
|
||||
{
|
||||
/// <summary>
|
||||
/// A utility class to compute CRC32.
|
||||
/// </summary>
|
||||
[System.Obsolete("This type should not be used; it is intended for internal use in HTML Agility Pack.")]
|
||||
#if !(NETSTANDARD1_3 || NETSTANDARD1_6) || WINDOWS_UWP
|
||||
[CLSCompliant(false)]
|
||||
#endif
|
||||
public class Crc32
|
||||
{
|
||||
#region Fields
|
||||
|
||||
private uint _crc32;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Static Members
|
||||
|
||||
private static uint[] crc_32_tab = // CRC polynomial 0xedb88320
|
||||
{
|
||||
0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419, 0x706af48f,
|
||||
0xe963a535, 0x9e6495a3, 0x0edb8832, 0x79dcb8a4, 0xe0d5e91e, 0x97d2d988,
|
||||
0x09b64c2b, 0x7eb17cbd, 0xe7b82d07, 0x90bf1d91, 0x1db71064, 0x6ab020f2,
|
||||
0xf3b97148, 0x84be41de, 0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7,
|
||||
0x136c9856, 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec, 0x14015c4f, 0x63066cd9,
|
||||
0xfa0f3d63, 0x8d080df5, 0x3b6e20c8, 0x4c69105e, 0xd56041e4, 0xa2677172,
|
||||
0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b, 0x35b5a8fa, 0x42b2986c,
|
||||
0xdbbbc9d6, 0xacbcf940, 0x32d86ce3, 0x45df5c75, 0xdcd60dcf, 0xabd13d59,
|
||||
0x26d930ac, 0x51de003a, 0xc8d75180, 0xbfd06116, 0x21b4f4b5, 0x56b3c423,
|
||||
0xcfba9599, 0xb8bda50f, 0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924,
|
||||
0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d, 0x76dc4190, 0x01db7106,
|
||||
0x98d220bc, 0xefd5102a, 0x71b18589, 0x06b6b51f, 0x9fbfe4a5, 0xe8b8d433,
|
||||
0x7807c9a2, 0x0f00f934, 0x9609a88e, 0xe10e9818, 0x7f6a0dbb, 0x086d3d2d,
|
||||
0x91646c97, 0xe6635c01, 0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e,
|
||||
0x6c0695ed, 0x1b01a57b, 0x8208f4c1, 0xf50fc457, 0x65b0d9c6, 0x12b7e950,
|
||||
0x8bbeb8ea, 0xfcb9887c, 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3, 0xfbd44c65,
|
||||
0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2, 0x4adfa541, 0x3dd895d7,
|
||||
0xa4d1c46d, 0xd3d6f4fb, 0x4369e96a, 0x346ed9fc, 0xad678846, 0xda60b8d0,
|
||||
0x44042d73, 0x33031de5, 0xaa0a4c5f, 0xdd0d7cc9, 0x5005713c, 0x270241aa,
|
||||
0xbe0b1010, 0xc90c2086, 0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f,
|
||||
0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4, 0x59b33d17, 0x2eb40d81,
|
||||
0xb7bd5c3b, 0xc0ba6cad, 0xedb88320, 0x9abfb3b6, 0x03b6e20c, 0x74b1d29a,
|
||||
0xead54739, 0x9dd277af, 0x04db2615, 0x73dc1683, 0xe3630b12, 0x94643b84,
|
||||
0x0d6d6a3e, 0x7a6a5aa8, 0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1,
|
||||
0xf00f9344, 0x8708a3d2, 0x1e01f268, 0x6906c2fe, 0xf762575d, 0x806567cb,
|
||||
0x196c3671, 0x6e6b06e7, 0xfed41b76, 0x89d32be0, 0x10da7a5a, 0x67dd4acc,
|
||||
0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5, 0xd6d6a3e8, 0xa1d1937e,
|
||||
0x38d8c2c4, 0x4fdff252, 0xd1bb67f1, 0xa6bc5767, 0x3fb506dd, 0x48b2364b,
|
||||
0xd80d2bda, 0xaf0a1b4c, 0x36034af6, 0x41047a60, 0xdf60efc3, 0xa867df55,
|
||||
0x316e8eef, 0x4669be79, 0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236,
|
||||
0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f, 0xc5ba3bbe, 0xb2bd0b28,
|
||||
0x2bb45a92, 0x5cb36a04, 0xc2d7ffa7, 0xb5d0cf31, 0x2cd99e8b, 0x5bdeae1d,
|
||||
0x9b64c2b0, 0xec63f226, 0x756aa39c, 0x026d930a, 0x9c0906a9, 0xeb0e363f,
|
||||
0x72076785, 0x05005713, 0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38,
|
||||
0x92d28e9b, 0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21, 0x86d3d2d4, 0xf1d4e242,
|
||||
0x68ddb3f8, 0x1fda836e, 0x81be16cd, 0xf6b9265b, 0x6fb077e1, 0x18b74777,
|
||||
0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c, 0x8f659eff, 0xf862ae69,
|
||||
0x616bffd3, 0x166ccf45, 0xa00ae278, 0xd70dd2ee, 0x4e048354, 0x3903b3c2,
|
||||
0xa7672661, 0xd06016f7, 0x4969474d, 0x3e6e77db, 0xaed16a4a, 0xd9d65adc,
|
||||
0x40df0b66, 0x37d83bf0, 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9,
|
||||
0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6, 0xbad03605, 0xcdd70693,
|
||||
0x54de5729, 0x23d967bf, 0xb3667a2e, 0xc4614ab8, 0x5d681b02, 0x2a6f2b94,
|
||||
0xb40bbe37, 0xc30c8ea1, 0x5a05df1b, 0x2d02ef8d
|
||||
};
|
||||
|
||||
#endregion
|
||||
|
||||
#region Properties
|
||||
|
||||
internal uint CheckSum
|
||||
{
|
||||
get { return _crc32; }
|
||||
set { _crc32 = value; }
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Public Methods
|
||||
|
||||
/// <summary>
|
||||
/// Compute a checksum for a given array of bytes.
|
||||
/// </summary>
|
||||
/// <param name="bytes">The array of bytes to compute the checksum for.</param>
|
||||
/// <returns>The computed checksum.</returns>
|
||||
public static uint CRC32Bytes(byte[] bytes)
|
||||
{
|
||||
uint oldcrc32;
|
||||
oldcrc32 = 0xFFFFFFFF;
|
||||
int len = bytes.Length;
|
||||
|
||||
for (int i = 0; len > 0; i++)
|
||||
{
|
||||
--len;
|
||||
oldcrc32 = UPDC32(bytes[len], oldcrc32);
|
||||
}
|
||||
|
||||
return ~oldcrc32;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Compute a checksum for a given string.
|
||||
/// </summary>
|
||||
/// <param name="text">The string to compute the checksum for.</param>
|
||||
/// <returns>The computed checksum.</returns>
|
||||
public static uint CRC32String(string text)
|
||||
{
|
||||
uint oldcrc32;
|
||||
oldcrc32 = 0xFFFFFFFF;
|
||||
int len = text.Length;
|
||||
ushort uCharVal;
|
||||
byte lowByte, hiByte;
|
||||
|
||||
for (int i = 0; len > 0; i++)
|
||||
{
|
||||
--len;
|
||||
uCharVal = text[len];
|
||||
unchecked
|
||||
{
|
||||
lowByte = (byte) (uCharVal & 0x00ff);
|
||||
hiByte = (byte) (uCharVal >> 8);
|
||||
}
|
||||
|
||||
oldcrc32 = UPDC32(hiByte, oldcrc32);
|
||||
oldcrc32 = UPDC32(lowByte, oldcrc32);
|
||||
}
|
||||
|
||||
return ~oldcrc32;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Internal Methods
|
||||
|
||||
internal uint AddToCRC32(int c)
|
||||
{
|
||||
return AddToCRC32((ushort) c);
|
||||
}
|
||||
|
||||
internal uint AddToCRC32(ushort c)
|
||||
{
|
||||
byte lowByte, hiByte;
|
||||
lowByte = (byte) (c & 0x00ff);
|
||||
hiByte = (byte) (c >> 8);
|
||||
_crc32 = UPDC32(hiByte, _crc32);
|
||||
_crc32 = UPDC32(lowByte, _crc32);
|
||||
return ~_crc32;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Private Methods
|
||||
|
||||
private static uint UPDC32(byte octet, uint crc)
|
||||
{
|
||||
return (crc_32_tab[((crc) ^ (octet)) & 0xff] ^ ((crc) >> 8));
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
351
Source/MyDb/MyDb/MSSQL/SqlDataProvider.cs
Normal file
351
Source/MyDb/MyDb/MSSQL/SqlDataProvider.cs
Normal file
|
|
@ -0,0 +1,351 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data.SqlClient;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using DataParameter = System.Data.SqlClient.SqlParameter;
|
||||
using DataCommand = System.Data.SqlClient.SqlCommand;
|
||||
using DataAdapter = System.Data.SqlClient.SqlDataAdapter;
|
||||
namespace ryCommonDb
|
||||
{
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public class SqlDataProvider:IDbInterface
|
||||
{
|
||||
ryCommonDb.MSSQLDb myDb = new MSSQLDb();
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="sql"></param>
|
||||
/// <returns></returns>
|
||||
public int ConnDb(string sql)
|
||||
{
|
||||
myDb.fv_ConnStr = sql;
|
||||
return myDb.ConnDb();
|
||||
}
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public int CloseDb()
|
||||
{
|
||||
myDb.CloseDb();
|
||||
return 1;
|
||||
}
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="tableName"></param>
|
||||
/// <param name="wheresql"></param>
|
||||
/// <returns></returns>
|
||||
public int GetCount(string tableName, string wheresql)
|
||||
{
|
||||
string m_where = "";
|
||||
if (wheresql != "")
|
||||
{
|
||||
m_where = " where " + wheresql;
|
||||
}
|
||||
string m_order = "(order by id)";
|
||||
string sql= "select count(*) from (select *,(ROW_NUMBER() OVER" + m_order + ") as myrow from " + tableName + m_where + ") as t";
|
||||
return Convert.ToInt32(myDb.ExecuteSQL(sql,(DataParameter[])GetParameter(), "0")[0]);
|
||||
}
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="newPwd"></param>
|
||||
/// <returns></returns>
|
||||
public int ChangePwd(string newPwd)
|
||||
{
|
||||
return -1000;
|
||||
}
|
||||
private List<SQLIitem> list_param = new List<SQLIitem>();
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="name"></param>
|
||||
/// <param name="value"></param>
|
||||
public void AddParameter(string name,object value)
|
||||
{
|
||||
list_param.Add(new SQLIitem(name, value));
|
||||
}
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="name"></param>
|
||||
/// <param name="value"></param>
|
||||
public void ClearParameter(object name, object value)
|
||||
{
|
||||
list_param.Clear();
|
||||
}
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public object[] GetParameter()
|
||||
{
|
||||
DataParameter[] defPar = new DataParameter[list_param.Count];
|
||||
for (int i = 0; i < list_param.Count; i++)
|
||||
{
|
||||
SQLIitem item = (SQLIitem)list_param[i];
|
||||
defPar[i] = new DataParameter("@" + item.Field.TrimStart('@').TrimStart('[').TrimEnd(']'), item.value);
|
||||
}
|
||||
return defPar;
|
||||
}
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="mySQL"></param>
|
||||
/// <returns></returns>
|
||||
public object[] GetParameter(RyQuickSQL mySQL)
|
||||
{
|
||||
DataParameter[] defPar = new DataParameter[mySQL.List.Count + mySQL.List_param.Count];
|
||||
for (int i = 0; i < mySQL.List.Count; i++)
|
||||
{
|
||||
SQLIitem item = (SQLIitem)mySQL.List[i];
|
||||
defPar[i] = new DataParameter("@" + item.Field.TrimStart('@').TrimStart('[').TrimEnd(']'), item.value);
|
||||
}
|
||||
for (int i = mySQL.List.Count; i < mySQL.List.Count + mySQL.List_param.Count; i++)
|
||||
{
|
||||
SQLIitem item = (SQLIitem)mySQL.List_param[i - mySQL.List.Count];
|
||||
defPar[i] = new DataParameter("@" + item.Field.TrimStart('@').TrimStart('[').TrimEnd(']'), item.value);
|
||||
}
|
||||
return defPar;
|
||||
}
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="tableName"></param>
|
||||
/// <param name="wheresql"></param>
|
||||
/// <param name="orderSQL"></param>
|
||||
/// <returns></returns>
|
||||
public string GetPageSQL(string tableName, string wheresql, string orderSQL)
|
||||
{
|
||||
return GetPageSQL("*", tableName, wheresql, orderSQL);
|
||||
}
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="field"></param>
|
||||
/// <param name="tableName"></param>
|
||||
/// <param name="wheresql"></param>
|
||||
/// <param name="orderSQL"></param>
|
||||
/// <returns></returns>
|
||||
public string GetPageSQL(string field, string tableName, string wheresql, string orderSQL)
|
||||
{
|
||||
string m_where = "";
|
||||
if (wheresql != "")
|
||||
{
|
||||
m_where = " where " + wheresql;
|
||||
}
|
||||
string m_order = "(order by id)";
|
||||
if (orderSQL != "")
|
||||
{
|
||||
m_order = "(" + orderSQL + ")";
|
||||
}
|
||||
return "select "+ field + " from (select *,(ROW_NUMBER() OVER" + m_order + ")as myrow from " + tableName + m_where + ") as t where t.myrow between {recordnum1} and {pageendnum1}";
|
||||
}
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="tableName"></param>
|
||||
/// <param name="wheresql"></param>
|
||||
/// <param name="orderSQL"></param>
|
||||
/// <returns></returns>
|
||||
public string GetPageSQL2(string tableName, string wheresql, string orderSQL)
|
||||
{
|
||||
return "";
|
||||
}
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="field"></param>
|
||||
/// <param name="tableName"></param>
|
||||
/// <param name="wheresql"></param>
|
||||
/// <param name="orderSQL"></param>
|
||||
/// <returns></returns>
|
||||
public string GetPageSQL2(string field, string tableName, string wheresql, string orderSQL)
|
||||
{
|
||||
return "";
|
||||
}
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="sql"></param>
|
||||
/// <param name="Parameter"></param>
|
||||
/// <returns></returns>
|
||||
public bool ContainsData(string sql, object[] Parameter)
|
||||
{
|
||||
System.Data.DataSet ds = ReadData(sql, Parameter);
|
||||
if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="sql"></param>
|
||||
/// <param name="Parameter"></param>
|
||||
/// <returns></returns>
|
||||
public System.Data.DataSet ReadData(string sql, object[] Parameter)
|
||||
{
|
||||
try
|
||||
{
|
||||
DataCommand cmd = myDb.SQL_cn.CreateCommand();
|
||||
cmd.Parameters.Clear();
|
||||
if (Parameter != null)
|
||||
cmd.Parameters.AddRange(Parameter);
|
||||
cmd.CommandText = sql;
|
||||
DataAdapter ad = new DataAdapter(cmd);
|
||||
System.Data.DataSet ds = new System.Data.DataSet();
|
||||
ad.Fill(ds);
|
||||
ad.Dispose();
|
||||
cmd.Parameters.Clear();
|
||||
cmd.Dispose();
|
||||
return ds;
|
||||
}
|
||||
catch { return new System.Data.DataSet(); }
|
||||
}
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="sql"></param>
|
||||
/// <param name="mySQL"></param>
|
||||
/// <returns></returns>
|
||||
public System.Data.DataSet ReadData(string sql, RyQuickSQL mySQL)
|
||||
{
|
||||
return ReadData(sql,GetParameter(mySQL));
|
||||
}
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="sql"></param>
|
||||
/// <returns></returns>
|
||||
public System.Data.DataSet ReadData(string sql)
|
||||
{
|
||||
object[] Parameter = null;
|
||||
return ReadData(sql, Parameter);
|
||||
}
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="tableName"></param>
|
||||
/// <param name="id"></param>
|
||||
/// <returns></returns>
|
||||
public System.Data.DataSet ReadData(string tableName, string id)
|
||||
{
|
||||
object[] Parameter = null;
|
||||
return ReadData("select * from " + tableName + " where id=" + id, Parameter);
|
||||
}
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="sql"></param>
|
||||
/// <param name="Parameter"></param>
|
||||
/// <returns></returns>
|
||||
public int ExecuteNonQuery(string sql, object[] Parameter)
|
||||
{
|
||||
DataCommand cmd = myDb.SQL_cn.CreateCommand();
|
||||
cmd.Parameters.Clear();
|
||||
if(Parameter!=null)
|
||||
cmd.Parameters.AddRange(Parameter);
|
||||
cmd.CommandText = sql;
|
||||
int i= cmd.ExecuteNonQuery();
|
||||
cmd.Parameters.Clear();
|
||||
cmd.Dispose();
|
||||
return i;
|
||||
}
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="sql"></param>
|
||||
/// <param name="mySQL"></param>
|
||||
/// <returns></returns>
|
||||
public int ExecuteNonQuery(string sql, RyQuickSQL mySQL)
|
||||
{
|
||||
return ExecuteNonQuery(sql,GetParameter(mySQL));
|
||||
}
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="sql"></param>
|
||||
/// <returns></returns>
|
||||
public int ExecuteNonQuery(string sql)
|
||||
{
|
||||
object[] pram = null;
|
||||
return ExecuteNonQuery(sql, pram);
|
||||
}
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="tableName"></param>
|
||||
/// <param name="id"></param>
|
||||
/// <returns></returns>
|
||||
public int DelById(string tableName, string id)
|
||||
{
|
||||
object[] param = null;
|
||||
return ExecuteNonQuery("delete from " + tableName + " where id=" + id, param);
|
||||
}
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="mySQL"></param>
|
||||
/// <returns></returns>
|
||||
public int CreateDb(RyQuickSQL mySQL)
|
||||
{
|
||||
string tmpSQL = "CREATE TABLE " + mySQL.TableName + " ([ID] INTEGER PRIMARY KEY,";
|
||||
for (int i = 0; i < mySQL.List.Count; i++)
|
||||
{
|
||||
SQLIitem item = (SQLIitem)mySQL.List[i];
|
||||
if (item.value is string)
|
||||
{
|
||||
if (item.len == 0)
|
||||
{
|
||||
tmpSQL += "[" + item.Field + "] [nvarchar](max),";
|
||||
}
|
||||
else
|
||||
{ tmpSQL += "[" + item.Field + "] [nvarchar]("+ item.len + "),"; }
|
||||
}
|
||||
else if (item.value is int || item.value is Int64)
|
||||
{
|
||||
tmpSQL += "[" + item.Field + "] [int] 0,";
|
||||
}
|
||||
else if (item.value is double || item.value is float)
|
||||
{
|
||||
tmpSQL += "[" + item.Field + "] [float] 0,";
|
||||
}
|
||||
else if (item.value is DateTime)
|
||||
{
|
||||
tmpSQL += "[" + item.Field + "] [DATETIME],";
|
||||
}
|
||||
}
|
||||
object[] param = null;
|
||||
return ExecuteNonQuery(tmpSQL.Substring(0, tmpSQL.Length - 1) + ")", param);
|
||||
}
|
||||
SqlTransaction tr;
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public void BeginTransaction()
|
||||
{
|
||||
tr = myDb.SQL_cn.BeginTransaction();
|
||||
}
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public void Commit()
|
||||
{
|
||||
tr.Commit();
|
||||
}
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public void Free()
|
||||
{
|
||||
list_param.Clear();
|
||||
myDb.CloseDb();
|
||||
}
|
||||
}
|
||||
}
|
||||
529
Source/MyDb/MyDb/MSSQL/clsMSSQLDb.cs
Normal file
529
Source/MyDb/MyDb/MSSQL/clsMSSQLDb.cs
Normal file
|
|
@ -0,0 +1,529 @@
|
|||
//--------------------------日期:2014-2-22
|
||||
//--------------------------版本:1.0.0.0
|
||||
//--------------------------作者:itrycn
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.Data;
|
||||
using System.Data.SqlClient;
|
||||
using System.ComponentModel;
|
||||
namespace ryCommonDb
|
||||
{
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public class MSSQLDb : IDisposable
|
||||
{
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="errorStr"></param>
|
||||
/// <param name="errorId"></param>
|
||||
public delegate void ErrorHandler(object sender, string errorStr,string errorId);
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
[Description("发生错误时发生")]
|
||||
public event ErrorHandler OnError;
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public SqlConnection SQL_cn;
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public string fv_ConnStr = "";
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public MSSQLDb()
|
||||
{
|
||||
}
|
||||
/// <summary>
|
||||
/// 连接数据库
|
||||
/// </summary>
|
||||
/// <param name="ConnStr">数据库连接字符串</param>
|
||||
/// <returns></returns>
|
||||
public MSSQLDb(string ConnStr)
|
||||
{
|
||||
fv_ConnStr = ConnStr;
|
||||
}
|
||||
/// <summary>
|
||||
/// 连接数据库
|
||||
/// </summary>
|
||||
/// <param name="DataSource">数据源</param>
|
||||
/// <param name="DbName">数据库名称</param>
|
||||
/// <param name="uId">用户id</param>
|
||||
/// <param name="pwd">用户密码</param>
|
||||
public MSSQLDb(string DataSource, string DbName, string uId, string pwd)
|
||||
{
|
||||
if (uId == "")
|
||||
{
|
||||
fv_ConnStr = "Data Source=" + DataSource + ";database=" + DbName + ";Integrated Security=True;Pooling=False";
|
||||
}
|
||||
else
|
||||
{
|
||||
fv_ConnStr = "Data Source=" + DataSource + ";database=" + DbName + ";uid=" + uId + ";pwd=" + pwd;
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
~MSSQLDb()
|
||||
{
|
||||
CloseDb();
|
||||
}
|
||||
/// <summary>
|
||||
/// 连接数据库
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public int ConnDb()
|
||||
{
|
||||
try
|
||||
{
|
||||
SQL_cn = new SqlConnection()
|
||||
{
|
||||
ConnectionString = fv_ConnStr,
|
||||
};
|
||||
SQL_cn.Open();
|
||||
return 1;
|
||||
}
|
||||
catch(Exception ex)
|
||||
{
|
||||
OnError?.Invoke(this,ex.Message,"errorconn");
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// 关闭数据库
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public void CloseDb()
|
||||
{
|
||||
try
|
||||
{
|
||||
if (SQL_cn != null && SQL_cn.State != ConnectionState.Closed)
|
||||
{
|
||||
SQL_cn.Close();
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
OnError?.Invoke(this, "关闭数据库出错", "errorclose");
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// 运行SQL命令
|
||||
/// </summary>
|
||||
/// <param name="SQLText">SQL语句</param>
|
||||
/// <param name="commandParameters">SQL命令参数</param>
|
||||
/// <returns>运行失败,则返回-1,否则返回影响的行数</returns>
|
||||
public int ExecuteNonQuery(string SQLText, SqlParameter[] commandParameters)
|
||||
{
|
||||
try
|
||||
{
|
||||
#region 数据库
|
||||
{
|
||||
SqlCommand cm = SQL_cn.CreateCommand();
|
||||
cm.Parameters.Clear();
|
||||
cm.CommandText = SQLText;
|
||||
if (commandParameters.Length > 0)
|
||||
{
|
||||
foreach (SqlParameter parm in commandParameters)
|
||||
{ cm.Parameters.Add(parm); }
|
||||
}
|
||||
cm.Connection = SQL_cn;
|
||||
int i = cm.ExecuteNonQuery();
|
||||
cm.Parameters.Clear();
|
||||
cm.Dispose();
|
||||
return i;
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
OnError?.Invoke(this, ex.Message, "errorconn");
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// 运行SQL命令
|
||||
/// </summary>
|
||||
/// <param name="SQLText">SQL语句</param>
|
||||
/// <returns>运行失败,则返回-1,否则返回影响的行数</returns>
|
||||
public int ExecuteNonQuery(string SQLText)
|
||||
{
|
||||
try
|
||||
{
|
||||
#region 数据库
|
||||
{
|
||||
SqlCommand cm = SQL_cn.CreateCommand();
|
||||
cm.Parameters.Clear();
|
||||
cm.CommandText = SQLText;
|
||||
cm.Connection = SQL_cn;
|
||||
int i = cm.ExecuteNonQuery();
|
||||
cm.Dispose();
|
||||
return i;
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
catch(Exception ex)
|
||||
{
|
||||
OnError?.Invoke(this,ex.Message,"errrorconn");
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// 运行SQL命令,并返回结果
|
||||
/// </summary>
|
||||
/// <param name="SQLText">SQL语句</param>
|
||||
/// <param name="commandParameters">SQL命令参数</param>
|
||||
/// <returns>运行失败,则返回null,否则返回以数组显示的字符串</returns>
|
||||
public string[] ExecuteSQL(string SQLText, SqlParameter[] commandParameters)
|
||||
{
|
||||
try
|
||||
{
|
||||
#region 数据库
|
||||
{
|
||||
SqlCommand cm = SQL_cn.CreateCommand();
|
||||
cm.Parameters.Clear();
|
||||
cm.CommandText = SQLText;
|
||||
if (commandParameters.Length > 0)
|
||||
{
|
||||
cm.Parameters.AddRange(commandParameters);
|
||||
}
|
||||
SqlDataReader reader = cm.ExecuteReader();
|
||||
string[] resultStr = null;
|
||||
while (reader.Read())
|
||||
{
|
||||
resultStr = new string[reader.FieldCount];
|
||||
for (int i = 0; i < reader.FieldCount; i++)
|
||||
{
|
||||
resultStr[i] = reader[i].ToString();
|
||||
}
|
||||
break;
|
||||
}
|
||||
reader.Close();
|
||||
cm.Dispose();
|
||||
return resultStr;
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
catch(Exception ex)
|
||||
{
|
||||
OnError?.Invoke(this, ex.Message, "errorconn");
|
||||
return null;
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// 运行SQL命令,并返回结果
|
||||
/// </summary>
|
||||
/// <param name="SQLText">SQL语句</param>
|
||||
/// <param name="commandParameters">SQL命令参数</param>
|
||||
/// <param name="DefFristValue">数组第一个默认的值</param>
|
||||
/// <returns>运行失败,则返回null,否则返回以数组显示的字符串</returns>
|
||||
public string[] ExecuteSQL(string SQLText, SqlParameter[] commandParameters, string DefFristValue)
|
||||
{
|
||||
try
|
||||
{
|
||||
#region 数据库
|
||||
{
|
||||
SqlCommand cm = SQL_cn.CreateCommand();
|
||||
cm.Parameters.Clear();
|
||||
cm.CommandText = SQLText;
|
||||
if (commandParameters.Length > 0)
|
||||
{
|
||||
cm.Parameters.AddRange(commandParameters);
|
||||
}
|
||||
SqlDataReader reader = cm.ExecuteReader();
|
||||
string[] resultStr = null;
|
||||
while (reader.Read())
|
||||
{
|
||||
resultStr = new string[reader.FieldCount];
|
||||
for (int i = 0; i < reader.FieldCount; i++)
|
||||
{
|
||||
resultStr[i] = reader[i].ToString();
|
||||
}
|
||||
break;
|
||||
}
|
||||
if (resultStr == null)
|
||||
{
|
||||
resultStr = new string[1];
|
||||
resultStr[0] = DefFristValue;
|
||||
}
|
||||
cm.Parameters.Clear();
|
||||
reader.Close();
|
||||
cm.Dispose();
|
||||
return resultStr;
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
catch(Exception ex)
|
||||
{
|
||||
string[] resultStr = null;
|
||||
resultStr = new string[1];
|
||||
resultStr[0] = DefFristValue;
|
||||
OnError?.Invoke(this, ex.Message, "errorconn");
|
||||
return resultStr;
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// 运行SQL命令,并返回结果
|
||||
/// </summary>
|
||||
/// <param name="SQLText">SQL语句</param>
|
||||
/// <returns>运行失败,则返回null,否则返回以数组显示的字符串</returns>
|
||||
public string[] ExecuteSQL(string SQLText)
|
||||
{
|
||||
try
|
||||
{
|
||||
#region 数据库
|
||||
{
|
||||
SqlCommand cm = SQL_cn.CreateCommand();
|
||||
cm.Parameters.Clear();
|
||||
cm.CommandText = SQLText;
|
||||
SqlDataReader reader = cm.ExecuteReader();
|
||||
string[] resultStr = null;
|
||||
while (reader.Read())
|
||||
{
|
||||
resultStr = new string[reader.FieldCount];
|
||||
for (int i = 0; i < reader.FieldCount; i++)
|
||||
{
|
||||
resultStr[i] = reader[i].ToString();
|
||||
}
|
||||
break;
|
||||
}
|
||||
reader.Close();
|
||||
cm.Dispose();
|
||||
return resultStr;
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
catch(Exception ex)
|
||||
{
|
||||
OnError?.Invoke(this, ex.Message, "errorconn");
|
||||
return null;
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// 运行SQL命令,并返回结果
|
||||
/// </summary>
|
||||
/// <param name="SQLText">SQL语句</param>
|
||||
/// <param name="DefFristValue">数组第一个默认的值</param>
|
||||
/// <returns>运行失败,则返回DefFristValue,否则返回以数组显示的字符串</returns>
|
||||
public string[] ExecuteSQL(string SQLText, string DefFristValue)
|
||||
{
|
||||
try
|
||||
{
|
||||
#region 数据库
|
||||
{
|
||||
SqlCommand cm = SQL_cn.CreateCommand();
|
||||
cm.Parameters.Clear();
|
||||
cm.CommandText = SQLText;
|
||||
SqlDataReader reader = cm.ExecuteReader();
|
||||
string[] resultStr = null;
|
||||
while (reader.Read())
|
||||
{
|
||||
resultStr = new string[reader.FieldCount];
|
||||
for (int i = 0; i < reader.FieldCount; i++)
|
||||
{
|
||||
resultStr[i] = reader[i].ToString();
|
||||
}
|
||||
break;
|
||||
}
|
||||
reader.Close();
|
||||
cm.Dispose();
|
||||
if (resultStr == null)
|
||||
{
|
||||
resultStr = new string[1];
|
||||
resultStr[0] = DefFristValue;
|
||||
}
|
||||
return resultStr;
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
catch(Exception ex)
|
||||
{
|
||||
OnError?.Invoke(this, ex.Message, "errorconn");
|
||||
string[] resultStr = null;
|
||||
resultStr = new string[1];
|
||||
resultStr[0] = DefFristValue;
|
||||
return resultStr;
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// 清空指定表的所有数据
|
||||
/// </summary>
|
||||
/// <param name="TableName">表名</param>
|
||||
/// <returns>运行失败,则返回-1,否则返回影响的行数</returns>
|
||||
public int ClearTableData(string TableName)
|
||||
{
|
||||
try
|
||||
{
|
||||
#region 数据库
|
||||
{
|
||||
SqlCommand cm = SQL_cn.CreateCommand();
|
||||
cm.Parameters.Clear();
|
||||
cm.CommandText = "delete from " + TableName;
|
||||
cm.Connection = SQL_cn;
|
||||
int i = cm.ExecuteNonQuery();
|
||||
cm.Dispose();
|
||||
return i;
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
catch(Exception ex)
|
||||
{
|
||||
OnError?.Invoke(this, ex.Message, "errorconn");
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// 判断指定值是否存在
|
||||
/// </summary>
|
||||
/// <param name="TableName">表名</param>
|
||||
/// <param name="valueField">指定值所属字段</param>
|
||||
/// <param name="value">指定值</param>
|
||||
/// <param name="curId">当前id,如果是新增记录,请填写-1</param>
|
||||
/// <returns></returns>
|
||||
public bool IsExistValue(string TableName, string valueField, string value, int curId)
|
||||
{
|
||||
try
|
||||
{
|
||||
#region 数据库
|
||||
{
|
||||
SqlCommand cm = SQL_cn.CreateCommand();
|
||||
cm.Parameters.Clear();
|
||||
cm.CommandText = "select * from " + TableName + " where " + valueField + "=@tvalue";
|
||||
cm.Parameters.AddWithValue("@tvalue", DbType.String);
|
||||
cm.Parameters["@tvalue"].Value = value;
|
||||
SqlDataReader reader = cm.ExecuteReader();
|
||||
bool result = false;
|
||||
while (reader.Read())
|
||||
{
|
||||
if (curId < 0)
|
||||
{
|
||||
result = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (reader["id"].ToString() == curId.ToString())
|
||||
{
|
||||
result = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
result = true;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
reader.Close();
|
||||
cm.Dispose();
|
||||
return result;
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
catch(Exception ex)
|
||||
{
|
||||
OnError?.Invoke(this, ex.Message, "errorconn");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// 判断SQL语句是否有结果返回
|
||||
/// </summary>
|
||||
/// <param name="SQLText">SQL语句</param>
|
||||
/// <param name="commandParameters">SQL命令参数</param>
|
||||
/// <returns>运行失败,则返回-1;存在结果,返回1;不存在结果,返回0</returns>
|
||||
public int ExecuteReadResult(string SQLText, SqlParameter[] commandParameters)
|
||||
{
|
||||
try
|
||||
{
|
||||
#region 数据库
|
||||
{
|
||||
SqlCommand cm = SQL_cn.CreateCommand();
|
||||
cm.Parameters.Clear();
|
||||
cm.CommandText = SQLText;
|
||||
if (commandParameters.Length > 0)
|
||||
{
|
||||
cm.Parameters.AddRange(commandParameters);
|
||||
//foreach (SQLiteParameter parm in commandParameters)
|
||||
//{ cm.Parameters.Add(parm); }
|
||||
}
|
||||
SqlDataReader reader = cm.ExecuteReader();
|
||||
int i = 0;
|
||||
while (reader.Read())
|
||||
{
|
||||
i = 1;
|
||||
break;
|
||||
}
|
||||
reader.Close();
|
||||
cm.Parameters.Clear();
|
||||
cm.Dispose();
|
||||
return i;
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
catch(Exception ex)
|
||||
{
|
||||
OnError?.Invoke(this, ex.Message, "errorconn");
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// 判断SQL语句是否有结果返回
|
||||
/// </summary>
|
||||
/// <param name="SQLText">SQL语句</param>
|
||||
/// <returns>运行失败,则返回-1;存在结果,返回1;不存在结果,返回0</returns>
|
||||
public int ExecuteReadResult(string SQLText)
|
||||
{
|
||||
try
|
||||
{
|
||||
#region 数据库
|
||||
{
|
||||
SqlCommand cm = SQL_cn.CreateCommand();
|
||||
cm.Parameters.Clear();
|
||||
cm.CommandText = SQLText;
|
||||
SqlDataReader reader = cm.ExecuteReader();
|
||||
int i = 0;
|
||||
while (reader.Read())
|
||||
{
|
||||
i = 1;
|
||||
break;
|
||||
}
|
||||
reader.Close();
|
||||
cm.Dispose();
|
||||
return i;
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
catch(Exception ex)
|
||||
{
|
||||
OnError?.Invoke(this, ex.Message, "errorconn");
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
private bool disposed = false;
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public virtual void Dispose()
|
||||
{
|
||||
if (!this.disposed)
|
||||
{
|
||||
try
|
||||
{
|
||||
CloseDb();
|
||||
// release scarce resource here
|
||||
}
|
||||
finally
|
||||
{
|
||||
this.disposed = true;
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -17,7 +17,7 @@
|
|||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>..\..\Bin\Debug\CommonControls\.NET4\</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<DefineConstants>TRACE;DEBUG;FX40</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||
|
|
@ -79,11 +79,54 @@
|
|||
<Compile Include="FileFuns\RyFiles.cs" />
|
||||
<Compile Include="FileFuns\TxtFileEncoder.cs" />
|
||||
<Compile Include="HardWare\Network.cs" />
|
||||
<Compile Include="HtmlAgilityPack.Shared\crc32.cs" />
|
||||
<Compile Include="HtmlAgilityPack.Shared\EncodingFoundException.cs" />
|
||||
<Compile Include="HtmlAgilityPack.Shared\HtmlAttribute.cs" />
|
||||
<Compile Include="HtmlAgilityPack.Shared\HtmlAttributeCollection.cs" />
|
||||
<Compile Include="HtmlAgilityPack.Shared\HtmlCmdLine.cs" />
|
||||
<Compile Include="HtmlAgilityPack.Shared\HtmlCommentNode.cs" />
|
||||
<Compile Include="HtmlAgilityPack.Shared\HtmlConsoleListener.cs" />
|
||||
<Compile Include="HtmlAgilityPack.Shared\HtmlDocument.cs" />
|
||||
<Compile Include="HtmlAgilityPack.Shared\HtmlDocument.PathMethods.cs" />
|
||||
<Compile Include="HtmlAgilityPack.Shared\HtmlDocument.Xpath.cs" />
|
||||
<Compile Include="HtmlAgilityPack.Shared\HtmlElementFlag.cs" />
|
||||
<Compile Include="HtmlAgilityPack.Shared\HtmlEntity.cs" />
|
||||
<Compile Include="HtmlAgilityPack.Shared\HtmlNameTable.cs" />
|
||||
<Compile Include="HtmlAgilityPack.Shared\HtmlNode.cs" />
|
||||
<Compile Include="HtmlAgilityPack.Shared\HtmlNode.Encapsulator.cs" />
|
||||
<Compile Include="HtmlAgilityPack.Shared\HtmlNode.Xpath.cs" />
|
||||
<Compile Include="HtmlAgilityPack.Shared\HtmlNodeCollection.cs" />
|
||||
<Compile Include="HtmlAgilityPack.Shared\HtmlNodeNavigator.cs" />
|
||||
<Compile Include="HtmlAgilityPack.Shared\HtmlNodeType.cs" />
|
||||
<Compile Include="HtmlAgilityPack.Shared\HtmlParseError.cs" />
|
||||
<Compile Include="HtmlAgilityPack.Shared\HtmlParseErrorCode.cs" />
|
||||
<Compile Include="HtmlAgilityPack.Shared\HtmlTextNode.cs" />
|
||||
<Compile Include="HtmlAgilityPack.Shared\HtmlWeb.cs" />
|
||||
<Compile Include="HtmlAgilityPack.Shared\HtmlWeb.Xpath.cs" />
|
||||
<Compile Include="HtmlAgilityPack.Shared\HtmlWebException.cs" />
|
||||
<Compile Include="HtmlAgilityPack.Shared\InvalidProgramException.cs" />
|
||||
<Compile Include="HtmlAgilityPack.Shared\IOLibrary.cs" />
|
||||
<Compile Include="HtmlAgilityPack.Shared\Metro\HtmlWeb.cs" />
|
||||
<Compile Include="HtmlAgilityPack.Shared\Metro\InvalidProgramException.cs" />
|
||||
<Compile Include="HtmlAgilityPack.Shared\MimeTypeMap.cs" />
|
||||
<Compile Include="HtmlAgilityPack.Shared\MixedCodeDocument.cs" />
|
||||
<Compile Include="HtmlAgilityPack.Shared\MixedCodeDocumentCodeFragment.cs" />
|
||||
<Compile Include="HtmlAgilityPack.Shared\MixedCodeDocumentFragment.cs" />
|
||||
<Compile Include="HtmlAgilityPack.Shared\MixedCodeDocumentFragmentList.cs" />
|
||||
<Compile Include="HtmlAgilityPack.Shared\MixedCodeDocumentFragmentType.cs" />
|
||||
<Compile Include="HtmlAgilityPack.Shared\MixedCodeDocumentTextFragment.cs" />
|
||||
<Compile Include="HtmlAgilityPack.Shared\NameValuePair.cs" />
|
||||
<Compile Include="HtmlAgilityPack.Shared\NameValuePairList.cs" />
|
||||
<Compile Include="HtmlAgilityPack.Shared\Trace.cs" />
|
||||
<Compile Include="HtmlAgilityPack.Shared\Trace.FullFramework.cs" />
|
||||
<Compile Include="HtmlAgilityPack.Shared\Utilities.cs" />
|
||||
<Compile Include="Msg\MsgClient.cs" />
|
||||
<Compile Include="Msg\RyMemoryShare.cs" />
|
||||
<Compile Include="MyDb\DataProvider.cs" />
|
||||
<Compile Include="MyDb\DbExtension.cs" />
|
||||
<Compile Include="MyDb\DbInterface.cs" />
|
||||
<Compile Include="MyDb\MSSQL\clsMSSQLDb.cs" />
|
||||
<Compile Include="MyDb\MSSQL\SqlDataProvider.cs" />
|
||||
<Compile Include="MyDb\ryQuickSQL.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="Properties\Resources.Designer.cs">
|
||||
|
|
@ -157,6 +200,13 @@
|
|||
<DependentUpon>FrmCapture.cs</DependentUpon>
|
||||
</EmbeddedResource>
|
||||
</ItemGroup>
|
||||
<ItemGroup />
|
||||
<ItemGroup>
|
||||
<None Include="HtmlAgilityPack.Shared\HtmlAgilityPack.Shared.projitems" />
|
||||
<None Include="HtmlAgilityPack.Shared\HtmlAgilityPack.Shared.projitems.vspscc" />
|
||||
<None Include="HtmlAgilityPack.Shared\HtmlAgilityPack.Shared.shproj" />
|
||||
<None Include="HtmlAgilityPack.Shared\HtmlAgilityPack.Shared.shproj.vspscc" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||
Other similar extension points exist, see Microsoft.Common.targets.
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup>
|
||||
<ProjectView>ProjectFiles</ProjectView>
|
||||
<ProjectView>ShowAllFiles</ProjectView>
|
||||
</PropertyGroup>
|
||||
</Project>
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
using System;
|
||||
// 有关程序集的一般信息由以下
|
||||
// 控制。更改这些特性值可修改
|
||||
// 与程序集关联的信息。
|
||||
|
|
@ -13,7 +13,7 @@ using System.Runtime.InteropServices;
|
|||
[assembly: AssemblyCopyright("Copyright © 2010-2021")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
|
||||
[assembly:CLSCompliant(false)]
|
||||
//将 ComVisible 设置为 false 将使此程序集中的类型
|
||||
//对 COM 组件不可见。 如果需要从 COM 访问此程序集中的类型,
|
||||
//请将此类型的 ComVisible 特性设置为 true。
|
||||
|
|
@ -32,5 +32,5 @@ using System.Runtime.InteropServices;
|
|||
//可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值,
|
||||
// 方法是按如下所示使用“*”: :
|
||||
// [assembly: AssemblyVersion("1.0.*")]
|
||||
[assembly: AssemblyVersion("3.0.2107.2901")]
|
||||
[assembly: AssemblyFileVersion("3.0.2107.2901")]
|
||||
[assembly: AssemblyVersion("3.0.2108.2101")]
|
||||
[assembly: AssemblyFileVersion("3.0.2108.2101")]
|
||||
|
|
@ -78,15 +78,7 @@ namespace ryCommon
|
|||
/// </summary>
|
||||
public void ShowModal()
|
||||
{
|
||||
Form parent_form = null;
|
||||
for (int i = 0; i < Application.OpenForms.Count; i++)
|
||||
{
|
||||
var form = Application.OpenForms[i];
|
||||
if (form.Focused)
|
||||
{
|
||||
parent_form = form;
|
||||
}
|
||||
}
|
||||
Form parent_form = parent;
|
||||
if (parent_form != null) { parent_form.Enabled = false; }
|
||||
sub_Form.FormClosing += new FormClosingEventHandler((object t, FormClosingEventArgs e1) =>
|
||||
{
|
||||
|
|
|
|||
79
Source/MyDb/WebP/Native.WebPDecoder.cs
Normal file
79
Source/MyDb/WebP/Native.WebPDecoder.cs
Normal file
|
|
@ -0,0 +1,79 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace LibwebpSharp.Native
|
||||
{
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public static class WebPDecoder
|
||||
{
|
||||
/// <summary>
|
||||
/// Return the decoder's version number
|
||||
/// </summary>
|
||||
/// <returns>Hexadecimal using 8bits for each of major/minor/revision. E.g: v2.5.7 is 0x020507</returns>
|
||||
[DllImport("libwebp", CharSet = CharSet.Auto)]
|
||||
public static extern int WebPGetDecoderVersion();
|
||||
|
||||
/// <summary>
|
||||
/// This function will validate the WebP image header and retrieve the image height and width. Pointers *width and *height can be passed NULL if deemed irrelevant
|
||||
/// </summary>
|
||||
/// <param name="data">Pointer to WebP image data</param>
|
||||
/// <param name="data_size">This is the size of the memory block pointed to by data containing the image data</param>
|
||||
/// <param name="width">The range is limited currently from 1 to 16383</param>
|
||||
/// <param name="height">The range is limited currently from 1 to 16383</param>
|
||||
/// <returns>1 if success, otherwise error code returned in the case of (a) formatting error(s).</returns>
|
||||
[DllImport("libwebp", CharSet = CharSet.Auto)]
|
||||
public static extern int WebPGetInfo(IntPtr data, UInt32 data_size, ref int width, ref int height);
|
||||
|
||||
/// <summary>
|
||||
/// Decodes WEBP images pointed to by *data and returns RGB samples into a pre-allocated buffer
|
||||
/// </summary>
|
||||
/// <param name="data">Pointer to WebP image data</param>
|
||||
/// <param name="data_size">This is the size of the memory block pointed to by data containing the image data</param>
|
||||
/// <param name="output_buffer">Pointer to decoded WebP image</param>
|
||||
/// <param name="output_buffer_size">Size of allocated buffer</param>
|
||||
/// <param name="output_stride">Specifies the distance between scanlines</param>
|
||||
/// <returns>output_buffer if function succeeds; NULL otherwise</returns>
|
||||
[DllImport("libwebp", CharSet = CharSet.Auto)]
|
||||
public static extern IntPtr WebPDecodeRGBInto(IntPtr data, UInt32 data_size, IntPtr output_buffer, int output_buffer_size, int output_stride);
|
||||
|
||||
/// <summary>
|
||||
/// Decodes WEBP images pointed to by *data and returns RGBA samples into a pre-allocated buffer
|
||||
/// </summary>
|
||||
/// <param name="data">Pointer to WebP image data</param>
|
||||
/// <param name="data_size">This is the size of the memory block pointed to by data containing the image data</param>
|
||||
/// <param name="output_buffer">Pointer to decoded WebP image</param>
|
||||
/// <param name="output_buffer_size">Size of allocated buffer</param>
|
||||
/// <param name="output_stride">Specifies the distance between scanlines</param>
|
||||
/// <returns>output_buffer if function succeeds; NULL otherwise</returns>
|
||||
[DllImport("libwebp", CharSet = CharSet.Auto)]
|
||||
public static extern IntPtr WebPDecodeRGBAInto(IntPtr data, UInt32 data_size, IntPtr output_buffer, int output_buffer_size, int output_stride);
|
||||
|
||||
/// <summary>
|
||||
/// Decodes WEBP images pointed to by *data and returns BGR samples into a pre-allocated buffer
|
||||
/// </summary>
|
||||
/// <param name="data">Pointer to WebP image data</param>
|
||||
/// <param name="data_size">This is the size of the memory block pointed to by data containing the image data</param>
|
||||
/// <param name="output_buffer">Pointer to decoded WebP image</param>
|
||||
/// <param name="output_buffer_size">Size of allocated buffer</param>
|
||||
/// <param name="output_stride">Specifies the distance between scanlines</param>
|
||||
/// <returns>output_buffer if function succeeds; NULL otherwise</returns>
|
||||
[DllImport("libwebp", CharSet = CharSet.Auto)]
|
||||
public static extern IntPtr WebPDecodeBGRInto(IntPtr data, UInt32 data_size, IntPtr output_buffer, int output_buffer_size, int output_stride);
|
||||
|
||||
/// <summary>
|
||||
/// Decodes WEBP images pointed to by *data and returns BGRA samples into a pre-allocated buffer
|
||||
/// </summary>
|
||||
/// <param name="data">Pointer to WebP image data</param>
|
||||
/// <param name="data_size">This is the size of the memory block pointed to by data containing the image data</param>
|
||||
/// <param name="output_buffer">Pointer to decoded WebP image</param>
|
||||
/// <param name="output_buffer_size">Size of allocated buffer</param>
|
||||
/// <param name="output_stride">Specifies the distance between scanlines</param>
|
||||
/// <returns>output_buffer if function succeeds; NULL otherwise</returns>
|
||||
[DllImport("libwebp", CharSet = CharSet.Auto)]
|
||||
public static extern IntPtr WebPDecodeBGRAInto(IntPtr data, UInt32 data_size, IntPtr output_buffer, int output_buffer_size, int output_stride);
|
||||
}
|
||||
}
|
||||
20
Source/MyDb/WebP/Native.WebPEncoder.cs
Normal file
20
Source/MyDb/WebP/Native.WebPEncoder.cs
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace LibwebpSharp.Native
|
||||
{
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public static class WebPEncoder
|
||||
{
|
||||
/// <summary>
|
||||
/// Return the decoder's version number
|
||||
/// </summary>
|
||||
/// <returns>Hexadecimal using 8bits for each of major/minor/revision. E.g: v2.5.7 is 0x020507</returns>
|
||||
[DllImport("libwebp", CharSet = CharSet.Auto)]
|
||||
public static extern int WebPGetEncoderVersion();
|
||||
}
|
||||
}
|
||||
95
Source/MyDb/WebP/Utilities.cs
Normal file
95
Source/MyDb/WebP/Utilities.cs
Normal file
|
|
@ -0,0 +1,95 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.IO;
|
||||
using System.Drawing;
|
||||
using System.Drawing.Imaging;
|
||||
|
||||
namespace LibwebpSharp
|
||||
{
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public static class Utilities
|
||||
{
|
||||
/// <summary>
|
||||
/// Copy data from managed to unmanaged memory
|
||||
/// </summary>
|
||||
/// <param name="data">The data you want to copy</param>
|
||||
/// <returns>Pointer to the location of the unmanaged data</returns>
|
||||
public static IntPtr CopyDataToUnmanagedMemory(byte[] data)
|
||||
{
|
||||
// Initialize unmanged memory to hold the array
|
||||
int size = Marshal.SizeOf(data[0]) * data.Length;
|
||||
IntPtr pnt = Marshal.AllocHGlobal(size);
|
||||
// Copy the array to unmanaged memory
|
||||
Marshal.Copy(data, 0, pnt, data.Length);
|
||||
return pnt;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get data from unmanaged memory back to managed memory
|
||||
/// </summary>
|
||||
/// <param name="source">A Pointer where the data lifes</param>
|
||||
/// <param name="lenght">How many bytes you want to copy</param>
|
||||
/// <returns></returns>
|
||||
public static byte[] GetDataFromUnmanagedMemory(IntPtr source, int lenght)
|
||||
{
|
||||
// Initialize managed memory to hold the array
|
||||
byte[] data = new byte[lenght];
|
||||
// Copy the array back to managed memory
|
||||
Marshal.Copy(source, data, 0, lenght);
|
||||
return data;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get a file from the disk and copy it into a managed byte array
|
||||
/// </summary>
|
||||
/// <param name="path">The path to the file</param>
|
||||
/// <returns>A byte array containing the file</returns>
|
||||
public static byte[] CopyFileToManagedArray(string path)
|
||||
{
|
||||
// Load file from disk and copy it into a byte array
|
||||
FileStream fs = new FileStream(path, FileMode.Open, FileAccess.Read);
|
||||
byte[] data = new byte[fs.Length];
|
||||
fs.Read(data, 0, (int)fs.Length);
|
||||
fs.Close();
|
||||
return data;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Convert raw image data into a Bitmap object
|
||||
/// </summary>
|
||||
/// <param name="data">The byte array containing the image data</param>
|
||||
/// <param name="imgWidth">The width of your image</param>
|
||||
/// <param name="imgHeight">The height of your image</param>
|
||||
/// <param name="format">The PixelFormat the Bitmap should use</param>
|
||||
/// <returns>The Bitmap object conating you image</returns>
|
||||
public static Bitmap ConvertDataToBitmap(byte[] data, int imgWidth, int imgHeight, PixelFormat format)
|
||||
{
|
||||
// Create the Bitmap to the know height, width and format
|
||||
Bitmap bmp = new Bitmap(imgWidth, imgHeight, format);
|
||||
// Create a BitmapData and Lock all pixels to be written
|
||||
BitmapData bmpData = bmp.LockBits( new Rectangle(0, 0, bmp.Width, bmp.Height), ImageLockMode.WriteOnly, bmp.PixelFormat);
|
||||
//Copy the data from the byte array into BitmapData.Scan0
|
||||
Marshal.Copy(data, 0, bmpData.Scan0, data.Length);
|
||||
//Unlock the pixels
|
||||
bmp.UnlockBits(bmpData);
|
||||
//Return the bitmap
|
||||
return bmp;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Calculate the needed size for a bitmap
|
||||
/// </summary>
|
||||
/// <param name="imgWidth">The image width</param>
|
||||
/// <param name="imgHeight">The image height</param>
|
||||
/// <param name="format">The pixel format you want to use</param>
|
||||
/// <returns>The bitmap size in bytes</returns>
|
||||
public static int CalculateBitmapSize(int imgWidth, int imgHeight, PixelFormat format)
|
||||
{
|
||||
return imgWidth * imgHeight * Image.GetPixelFormatSize(format) / 8;
|
||||
}
|
||||
}
|
||||
}
|
||||
287
Source/MyDb/WebP/WebPDecoder.cs
Normal file
287
Source/MyDb/WebP/WebPDecoder.cs
Normal file
|
|
@ -0,0 +1,287 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.IO;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Drawing;
|
||||
using System.Drawing.Imaging;
|
||||
|
||||
namespace LibwebpSharp
|
||||
{
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public class WebPDecoder
|
||||
{
|
||||
private enum decodeType
|
||||
{
|
||||
RGB,
|
||||
RGBA,
|
||||
BGR,
|
||||
BGRA,
|
||||
YUV
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
/// The decoder's version number
|
||||
/// </summary>
|
||||
/// <returns>The version as major.minor.revision</returns>
|
||||
public string GetDecoderVersion()
|
||||
{
|
||||
int version = Native.WebPDecoder.WebPGetDecoderVersion();
|
||||
return String.Format("{0}.{1}.{2}", (version >> 16) & 0xff, (version >> 8) & 0xff, version & 0xff);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Validate the WebP image header and retrieve the image height and width
|
||||
/// </summary>
|
||||
/// <param name="path">The path to the WebP image file</param>
|
||||
/// <param name="imgWidth">Returns the width of the WebP image</param>
|
||||
/// <param name="imgHeight">Returnsthe height of the WebP image</param>
|
||||
/// <returns>True if the WebP image header is valid, otherwise false</returns>
|
||||
public bool GetInfo(string path, out int imgWidth, out int imgHeight)
|
||||
{
|
||||
bool retValue = false;
|
||||
int width = 0;
|
||||
int height = 0;
|
||||
IntPtr pnt = IntPtr.Zero;
|
||||
|
||||
try
|
||||
{
|
||||
byte[] data = Utilities.CopyFileToManagedArray(path);
|
||||
pnt = Utilities.CopyDataToUnmanagedMemory(data);
|
||||
int ret = Native.WebPDecoder.WebPGetInfo(pnt, (uint)data.Length, ref width, ref height);
|
||||
if (ret == 1)
|
||||
{
|
||||
retValue = true;
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
throw;
|
||||
}
|
||||
finally
|
||||
{
|
||||
// Free the unmanaged memory.
|
||||
Marshal.FreeHGlobal(pnt);
|
||||
}
|
||||
|
||||
imgWidth = width;
|
||||
imgHeight = height;
|
||||
return retValue;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Decode the WebP image into a RGB Bitmap
|
||||
/// </summary>
|
||||
/// <param name="path">The path to the WebP image file</param>
|
||||
/// <returns>A Bitmap object with the decoded WebP image.
|
||||
/// Note that a Bitmap object use the BGR format, so if you display the Bitmap in a picturebox red and blue are mixed up</returns>
|
||||
public Bitmap DecodeRGB(string path)
|
||||
{
|
||||
return decode(path, decodeType.RGB, PixelFormat.Format24bppRgb);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Decode the WebP image into a RGBA Bitmap
|
||||
/// </summary>
|
||||
/// <param name="path">The path to the WebP image file</param>
|
||||
/// <returns>A Bitmap object with the decoded WebP image.
|
||||
/// Note that a Bitmap object use the ABGR format, so if you display the Bitmap in a picturebox red and blue are mixed up</returns>
|
||||
public Bitmap DecodeRGBA(string path)
|
||||
{
|
||||
return decode(path, decodeType.RGBA, PixelFormat.Format32bppArgb);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Decode the WebP image into a BGR Bitmap
|
||||
/// </summary>
|
||||
/// <param name="path">The path to the WebP image file</param>
|
||||
/// <returns>A Bitmap object with the decoded WebP image</returns>
|
||||
public Bitmap DecodeBGR(string path)
|
||||
{
|
||||
return decode(path, decodeType.BGR, PixelFormat.Format24bppRgb);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Decode the WebP image into a BGRA Bitmap
|
||||
/// </summary>
|
||||
/// <param name="path">The path to the WebP image file</param>
|
||||
/// <returns>A Bitmap object with the decoded WebP image</returns>
|
||||
public Bitmap DecodeBGRA(string path)
|
||||
{
|
||||
return decode(path, decodeType.BGRA, PixelFormat.Format32bppArgb);
|
||||
}
|
||||
/// <summary>
|
||||
/// Decode the WebP image into a BGRA Bitmap
|
||||
/// </summary>
|
||||
/// <param name="fs">The path to the WebP image file</param>
|
||||
/// <returns>A Bitmap object with the decoded WebP image</returns>
|
||||
public Bitmap DecodeBGRA(Stream fs)
|
||||
{
|
||||
byte[] data = new byte[fs.Length];
|
||||
fs.Read(data, 0, (int)fs.Length);
|
||||
fs.Close();
|
||||
return decode(data, decodeType.BGRA, PixelFormat.Format32bppArgb);
|
||||
}
|
||||
/// <summary>
|
||||
/// Decode the WebP image file into raw RGB image data
|
||||
/// </summary>
|
||||
/// <param name="path">The path to the WebP image file</param>
|
||||
/// <param name="imgWidth">Returns the width of the WebP image</param>
|
||||
/// <param name="imgHeight">Returns the height of the WebP image</param>
|
||||
/// <returns>A byte array containing the raw decoded image data</returns>
|
||||
public byte[] DecodeRGB(string path, out int imgWidth, out int imgHeight)
|
||||
{
|
||||
return decode(path, decodeType.RGB, PixelFormat.Format24bppRgb, out imgWidth, out imgHeight);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Decode the WebP image file into raw RGBA image data
|
||||
/// </summary>
|
||||
/// <param name="path">The path to the WebP image file</param>
|
||||
/// <param name="imgWidth">Returns the width of the WebP image</param>
|
||||
/// <param name="imgHeight">Returns the height of the WebP image</param>
|
||||
/// <returns>A byte array containing the raw decoded image data</returns>
|
||||
public byte[] DecodeRGBA(string path, out int imgWidth, out int imgHeight)
|
||||
{
|
||||
return decode(path, decodeType.RGBA, PixelFormat.Format32bppArgb, out imgWidth, out imgHeight);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Decode the WebP image file into raw BGR image data
|
||||
/// </summary>
|
||||
/// <param name="path">The path to the WebP image file</param>
|
||||
/// <param name="imgWidth">Returns the width of the WebP image</param>
|
||||
/// <param name="imgHeight">Returns the height of the WebP image</param>
|
||||
/// <returns>A byte array containing the raw decoded image data</returns>
|
||||
public byte[] DecodeBGR(string path, out int imgWidth, out int imgHeight)
|
||||
{
|
||||
return decode(path, decodeType.BGR, PixelFormat.Format24bppRgb, out imgWidth, out imgHeight);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Decode the WebP image file into raw BGRA image data
|
||||
/// </summary>
|
||||
/// <param name="path">The path to the WebP image file</param>
|
||||
/// <param name="imgWidth">Returns the width of the WebP image</param>
|
||||
/// <param name="imgHeight">Returns the height of the WebP image</param>
|
||||
/// <returns>A byte array containing the raw decoded image data</returns>
|
||||
public byte[] DecodeBGRA(string path, out int imgWidth, out int imgHeight)
|
||||
{
|
||||
return decode(path, decodeType.BGRA, PixelFormat.Format32bppArgb, out imgWidth, out imgHeight);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Internal convert method to get a Bitmap from a WebP image file
|
||||
/// </summary>
|
||||
/// <param name="path">The path to the WebP image file</param>
|
||||
/// <param name="type">The color type you want to convert to</param>
|
||||
/// <param name="format">The PixelFormat the Bitmap should use</param>
|
||||
/// <returns></returns>
|
||||
private Bitmap decode(string path, decodeType type, PixelFormat format)
|
||||
{
|
||||
int width = 0;
|
||||
int height = 0;
|
||||
byte[] data = decode(path, type, format, out width, out height);
|
||||
return Utilities.ConvertDataToBitmap(data, width, height, format);
|
||||
}
|
||||
/// <summary>
|
||||
/// Internal convert method to get a Bitmap from a WebP image file
|
||||
/// </summary>
|
||||
/// <param name="fs_data">webp文件数据</param>
|
||||
/// <param name="type">The color type you want to convert to</param>
|
||||
/// <param name="format">The PixelFormat the Bitmap should use</param>
|
||||
/// <returns></returns>
|
||||
private Bitmap decode(byte[] fs_data, decodeType type, PixelFormat format)
|
||||
{
|
||||
byte[] data = decode(fs_data, type, format, out int width, out int height);
|
||||
return Utilities.ConvertDataToBitmap(data, width, height, format);
|
||||
}
|
||||
/// <summary>
|
||||
/// Internal convert method to get a byte array from a WebP image file
|
||||
/// </summary>
|
||||
/// <param name="path">The path to the WebP image file</param>
|
||||
/// <param name="type">The color type you want to convert to</param>
|
||||
/// <param name="format">The PixelFormat you want to use</param>
|
||||
/// <param name="imgWidth">Returns the width of the WebP image</param>
|
||||
/// <param name="imgHeight">Returns the height of the WebP image</param>
|
||||
/// <returns></returns>
|
||||
private byte[] decode(string path, decodeType type, PixelFormat format, out int imgWidth, out int imgHeight)
|
||||
{
|
||||
return decode(Utilities.CopyFileToManagedArray(path), type, format,out imgWidth,out imgHeight);
|
||||
}
|
||||
/// <summary>
|
||||
/// Internal convert method to get a byte array from a WebP image file
|
||||
/// </summary>
|
||||
/// <param name="managedData">The path to the WebP image file</param>
|
||||
/// <param name="type">The color type you want to convert to</param>
|
||||
/// <param name="format">The PixelFormat you want to use</param>
|
||||
/// <param name="imgWidth">Returns the width of the WebP image</param>
|
||||
/// <param name="imgHeight">Returns the height of the WebP image</param>
|
||||
/// <returns></returns>
|
||||
private byte[] decode(byte[] managedData, decodeType type, PixelFormat format, out int imgWidth, out int imgHeight)
|
||||
{
|
||||
int width = 0;
|
||||
int height = 0;
|
||||
IntPtr data = IntPtr.Zero;
|
||||
IntPtr output_buffer = IntPtr.Zero;
|
||||
IntPtr result = IntPtr.Zero;
|
||||
|
||||
try
|
||||
{
|
||||
// Copy data to unmanaged memory
|
||||
data = Utilities.CopyDataToUnmanagedMemory(managedData);
|
||||
|
||||
// Get image width and height
|
||||
int ret = Native.WebPDecoder.WebPGetInfo(data, (uint)managedData.Length, ref width, ref height);
|
||||
|
||||
// Get image data lenght
|
||||
UInt32 data_size = (UInt32)managedData.Length;
|
||||
|
||||
// Calculate bitmap size for decoded WebP image
|
||||
int output_buffer_size = Utilities.CalculateBitmapSize(width, height, format);
|
||||
|
||||
// Allocate unmanaged memory to decoded WebP image
|
||||
output_buffer = Marshal.AllocHGlobal(output_buffer_size);
|
||||
|
||||
// Calculate distance between scanlines
|
||||
int output_stride = (width * Image.GetPixelFormatSize(format)) / 8;
|
||||
|
||||
// Convert image
|
||||
switch (type)
|
||||
{
|
||||
case decodeType.RGB:
|
||||
result = Native.WebPDecoder.WebPDecodeRGBInto(data, data_size, output_buffer, output_buffer_size, output_stride);
|
||||
break;
|
||||
case decodeType.RGBA:
|
||||
result = Native.WebPDecoder.WebPDecodeRGBAInto(data, data_size, output_buffer, output_buffer_size, output_stride);
|
||||
break;
|
||||
case decodeType.BGR:
|
||||
result = Native.WebPDecoder.WebPDecodeBGRInto(data, data_size, output_buffer, output_buffer_size, output_stride);
|
||||
break;
|
||||
case decodeType.BGRA:
|
||||
result = Native.WebPDecoder.WebPDecodeBGRAInto(data, data_size, output_buffer, output_buffer_size, output_stride);
|
||||
break;
|
||||
}
|
||||
|
||||
// Set out values
|
||||
imgWidth = width;
|
||||
imgHeight = height;
|
||||
|
||||
// Copy data back to managed memory and return
|
||||
return Utilities.GetDataFromUnmanagedMemory(result, output_buffer_size);
|
||||
}
|
||||
catch
|
||||
{
|
||||
throw;
|
||||
}
|
||||
finally
|
||||
{
|
||||
// Free unmanaged memory
|
||||
Marshal.FreeHGlobal(data);
|
||||
Marshal.FreeHGlobal(output_buffer);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
22
Source/MyDb/WebP/WebPEncoder.cs
Normal file
22
Source/MyDb/WebP/WebPEncoder.cs
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace LibwebpSharp
|
||||
{
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public class WebPEncoder
|
||||
{
|
||||
/// <summary>
|
||||
/// The encoder's version number
|
||||
/// </summary>
|
||||
/// <returns>The version as major.minor.revision</returns>
|
||||
public string GetEncoderVersion()
|
||||
{
|
||||
int version = Native.WebPEncoder.WebPGetEncoderVersion();
|
||||
return String.Format("{0}.{1}.{2}", (version >> 16) & 0xff, (version >> 8) & 0xff, version & 0xff);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -80,7 +80,6 @@ namespace ryControls
|
|||
{
|
||||
return SelectName;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
SelectName = value;
|
||||
|
|
|
|||
|
|
@ -1,190 +1,190 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Drawing;
|
||||
using System.Drawing.Drawing2D;
|
||||
|
||||
namespace Sheng.Winform.Controls
|
||||
{
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Drawing;
|
||||
using System.Drawing.Drawing2D;
|
||||
|
||||
namespace Sheng.Winform.Controls
|
||||
{
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public static class Office2010Renderer
|
||||
{
|
||||
/// </summary>
|
||||
public static class Office2010Renderer
|
||||
{
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="bounds"></param>
|
||||
/// <param name="baseColor"></param>
|
||||
/// <returns></returns>
|
||||
public static Brush CreateDisabledBackgroundBrush(Rectangle bounds, Color baseColor)
|
||||
{
|
||||
Color color = Color.FromArgb(75, baseColor);
|
||||
SolidBrush brush = new SolidBrush(color);
|
||||
return brush;
|
||||
}
|
||||
/// <returns></returns>
|
||||
public static Brush CreateDisabledBackgroundBrush(Rectangle bounds, Color baseColor)
|
||||
{
|
||||
Color color = Color.FromArgb(75, baseColor);
|
||||
SolidBrush brush = new SolidBrush(color);
|
||||
return brush;
|
||||
}
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="bounds"></param>
|
||||
/// <param name="baseColor"></param>
|
||||
/// <returns></returns>
|
||||
public static Brush CreateBackgroundBrush(Rectangle bounds, Color baseColor)
|
||||
{
|
||||
Color color = baseColor;
|
||||
|
||||
Color[] colors = new Color[3];
|
||||
colors[0] = Color.Transparent;
|
||||
colors[1] = Color.Transparent;
|
||||
colors[2] = Color.FromArgb(60, color);
|
||||
|
||||
//要向上移一个像素,否则上面会多出一个像素的空白,原因不明
|
||||
//bounds.X -= 1;
|
||||
//bounds.Y -= 1;
|
||||
|
||||
LinearGradientBrush brush = new LinearGradientBrush(bounds, Color.Empty, Color.Empty,
|
||||
LinearGradientMode.Vertical);
|
||||
|
||||
//渐变位置百分比
|
||||
float[] relativePositions = { 0f, 0.75f, 1f, };
|
||||
|
||||
/// <returns></returns>
|
||||
public static Brush CreateBackgroundBrush(Rectangle bounds, Color baseColor)
|
||||
{
|
||||
Color color = baseColor;
|
||||
|
||||
Color[] colors = new Color[3];
|
||||
colors[0] = Color.Transparent;
|
||||
colors[1] = Color.Transparent;
|
||||
colors[2] = Color.FromArgb(60, color);
|
||||
|
||||
//要向上移一个像素,否则上面会多出一个像素的空白,原因不明
|
||||
//bounds.X -= 1;
|
||||
//bounds.Y -= 1;
|
||||
|
||||
LinearGradientBrush brush = new LinearGradientBrush(bounds, Color.Empty, Color.Empty,
|
||||
LinearGradientMode.Vertical);
|
||||
|
||||
//渐变位置百分比
|
||||
float[] relativePositions = { 0f, 0.75f, 1f, };
|
||||
|
||||
ColorBlend colorBlend = new ColorBlend
|
||||
{
|
||||
Colors = colors,
|
||||
Positions = relativePositions
|
||||
};
|
||||
brush.InterpolationColors = colorBlend;
|
||||
|
||||
return brush;
|
||||
}
|
||||
};
|
||||
brush.InterpolationColors = colorBlend;
|
||||
|
||||
return brush;
|
||||
}
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="bounds"></param>
|
||||
/// <param name="baseColor"></param>
|
||||
/// <returns></returns>
|
||||
public static Brush CreateBorderBrush(Rectangle bounds, Color baseColor)
|
||||
{
|
||||
Color color = baseColor;
|
||||
Color colorStart = Color.FromArgb(125, color);
|
||||
|
||||
LinearGradientBrush brush = new LinearGradientBrush(bounds, colorStart, color,
|
||||
LinearGradientMode.Vertical);
|
||||
|
||||
return brush;
|
||||
}
|
||||
/// <returns></returns>
|
||||
public static Brush CreateBorderBrush(Rectangle bounds, Color baseColor)
|
||||
{
|
||||
Color color = baseColor;
|
||||
Color colorStart = Color.FromArgb(125, color);
|
||||
|
||||
LinearGradientBrush brush = new LinearGradientBrush(bounds, colorStart, color,
|
||||
LinearGradientMode.Vertical);
|
||||
|
||||
return brush;
|
||||
}
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="bounds"></param>
|
||||
/// <param name="baseColor"></param>
|
||||
/// <returns></returns>
|
||||
public static Brush CreateHoveredBackgroundBrush(Rectangle bounds, Color baseColor)
|
||||
{
|
||||
//过渡色的路径点和配色参见png设计图
|
||||
//需要五个过度色点,就是分成四段,分别占34%,33%,16%,17%
|
||||
|
||||
Color color = baseColor;
|
||||
|
||||
Color[] colors = new Color[5];
|
||||
colors[0] = Color.FromArgb(125, color);
|
||||
colors[1] = color;
|
||||
colors[2] = color;
|
||||
colors[3] = Color.FromArgb(221, color);
|
||||
colors[4] = Color.Transparent;
|
||||
|
||||
//要向上移一个像素,否则上面会多出一个像素的空白,原因不明
|
||||
bounds.X -= 1;
|
||||
bounds.Y -= 1;
|
||||
|
||||
LinearGradientBrush brush = new LinearGradientBrush(bounds, Color.Empty, Color.Empty,
|
||||
LinearGradientMode.Vertical);
|
||||
|
||||
//渐变位置百分比
|
||||
float[] relativePositions = { 0f, 0.20f, 0.67f, 0.75f, 1f, };
|
||||
|
||||
/// <returns></returns>
|
||||
public static Brush CreateHoveredBackgroundBrush(Rectangle bounds, Color baseColor)
|
||||
{
|
||||
//过渡色的路径点和配色参见png设计图
|
||||
//需要五个过度色点,就是分成四段,分别占34%,33%,16%,17%
|
||||
|
||||
Color color = baseColor;
|
||||
|
||||
Color[] colors = new Color[5];
|
||||
colors[0] = Color.FromArgb(125, color);
|
||||
colors[1] = color;
|
||||
colors[2] = color;
|
||||
colors[3] = Color.FromArgb(221, color);
|
||||
colors[4] = Color.Transparent;
|
||||
|
||||
//要向上移一个像素,否则上面会多出一个像素的空白,原因不明
|
||||
bounds.X -= 1;
|
||||
bounds.Y -= 1;
|
||||
|
||||
LinearGradientBrush brush = new LinearGradientBrush(bounds, Color.Empty, Color.Empty,
|
||||
LinearGradientMode.Vertical);
|
||||
|
||||
//渐变位置百分比
|
||||
float[] relativePositions = { 0f, 0.20f, 0.67f, 0.75f, 1f, };
|
||||
|
||||
ColorBlend colorBlend = new ColorBlend
|
||||
{
|
||||
Colors = colors,
|
||||
Positions = relativePositions
|
||||
};
|
||||
brush.InterpolationColors = colorBlend;
|
||||
|
||||
return brush;
|
||||
}
|
||||
};
|
||||
brush.InterpolationColors = colorBlend;
|
||||
|
||||
return brush;
|
||||
}
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="bounds"></param>
|
||||
/// <param name="baseColor"></param>
|
||||
/// <returns></returns>
|
||||
public static Brush CreateHoveredBorderBrush(Rectangle bounds, Color baseColor)
|
||||
{
|
||||
Color color = baseColor;
|
||||
|
||||
Color colorEnd = Color.FromArgb(125, color);
|
||||
|
||||
LinearGradientBrush brush = new LinearGradientBrush(bounds, color, colorEnd,
|
||||
LinearGradientMode.Vertical);
|
||||
|
||||
return brush;
|
||||
}
|
||||
/// <returns></returns>
|
||||
public static Brush CreateHoveredBorderBrush(Rectangle bounds, Color baseColor)
|
||||
{
|
||||
Color color = baseColor;
|
||||
|
||||
Color colorEnd = Color.FromArgb(125, color);
|
||||
|
||||
LinearGradientBrush brush = new LinearGradientBrush(bounds, color, colorEnd,
|
||||
LinearGradientMode.Vertical);
|
||||
|
||||
return brush;
|
||||
}
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="bounds"></param>
|
||||
/// <param name="baseColor"></param>
|
||||
/// <returns></returns>
|
||||
public static Brush CreateSelectedBackgroundBrush(Rectangle bounds, Color baseColor)
|
||||
{
|
||||
//过渡色的路径点和配色参见png设计图
|
||||
//需要五个过度色点,就是分成四段,分别占34%,33%,16%,17%
|
||||
|
||||
Color color = baseColor;
|
||||
|
||||
Color[] colors = new Color[5];
|
||||
colors[0] = color;
|
||||
colors[1] = color;
|
||||
colors[2] = color;
|
||||
colors[3] = Color.FromArgb(221, color);
|
||||
colors[4] = Color.Transparent;
|
||||
|
||||
//要向上移一个像素,否则上面会多出一个像素的空白,原因不明
|
||||
//bounds.X -= 1;
|
||||
//bounds.Y -= 1;
|
||||
|
||||
LinearGradientBrush brush = new LinearGradientBrush(bounds, Color.Empty, Color.Empty,
|
||||
LinearGradientMode.Vertical);
|
||||
|
||||
//渐变位置百分比
|
||||
float[] relativePositions = { 0f, 0.30f, 0.67f, 0.75f, 1f };
|
||||
|
||||
/// <returns></returns>
|
||||
public static Brush CreateSelectedBackgroundBrush(Rectangle bounds, Color baseColor)
|
||||
{
|
||||
//过渡色的路径点和配色参见png设计图
|
||||
//需要五个过度色点,就是分成四段,分别占34%,33%,16%,17%
|
||||
|
||||
Color color = baseColor;
|
||||
|
||||
Color[] colors = new Color[5];
|
||||
colors[0] = color;
|
||||
colors[1] = color;
|
||||
colors[2] = color;
|
||||
colors[3] = Color.FromArgb(221, color);
|
||||
colors[4] = Color.Transparent;
|
||||
|
||||
//要向上移一个像素,否则上面会多出一个像素的空白,原因不明
|
||||
//bounds.X -= 1;
|
||||
//bounds.Y -= 1;
|
||||
|
||||
LinearGradientBrush brush = new LinearGradientBrush(bounds, Color.Empty, Color.Empty,
|
||||
LinearGradientMode.Vertical);
|
||||
|
||||
//渐变位置百分比
|
||||
float[] relativePositions = { 0f, 0.30f, 0.67f, 0.75f, 1f };
|
||||
|
||||
ColorBlend colorBlend = new ColorBlend
|
||||
{
|
||||
Colors = colors,
|
||||
Positions = relativePositions
|
||||
};
|
||||
brush.InterpolationColors = colorBlend;
|
||||
|
||||
return brush;
|
||||
}
|
||||
};
|
||||
brush.InterpolationColors = colorBlend;
|
||||
|
||||
return brush;
|
||||
}
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="bounds"></param>
|
||||
/// <param name="baseColor"></param>
|
||||
/// <returns></returns>
|
||||
public static Brush CreateSelectedBorderBrush(Rectangle bounds, Color baseColor)
|
||||
{
|
||||
Color color = baseColor;
|
||||
|
||||
Color colorEnd = Color.FromArgb(125, color);
|
||||
|
||||
LinearGradientBrush brush = new LinearGradientBrush(bounds, color, colorEnd,
|
||||
LinearGradientMode.Vertical);
|
||||
|
||||
return brush;
|
||||
}
|
||||
}
|
||||
}
|
||||
/// <returns></returns>
|
||||
public static Brush CreateSelectedBorderBrush(Rectangle bounds, Color baseColor)
|
||||
{
|
||||
Color color = baseColor;
|
||||
|
||||
Color colorEnd = Color.FromArgb(125, color);
|
||||
|
||||
LinearGradientBrush brush = new LinearGradientBrush(bounds, color, colorEnd,
|
||||
LinearGradientMode.Vertical);
|
||||
|
||||
return brush;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user