-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Inital commit of the XML RPC Client Library
- Loading branch information
1 parent
d9c767e
commit f06037a
Showing
11 changed files
with
2,795 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
XmlRpcClient | ||
============ | ||
This is XML RPC Client Library in C#.NET |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
|
||
Microsoft Visual Studio Solution File, Format Version 11.00 | ||
# Visual Studio 2010 | ||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "XMLRPCClient", "XMLRPCClient\XMLRPCClient.csproj", "{CF207A79-E0CD-4CAB-BE7B-DDE7E37BE195}" | ||
EndProject | ||
Global | ||
GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||
Debug|Any CPU = Debug|Any CPU | ||
Release|Any CPU = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||
{CF207A79-E0CD-4CAB-BE7B-DDE7E37BE195}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{CF207A79-E0CD-4CAB-BE7B-DDE7E37BE195}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{CF207A79-E0CD-4CAB-BE7B-DDE7E37BE195}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{CF207A79-E0CD-4CAB-BE7B-DDE7E37BE195}.Release|Any CPU.Build.0 = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(SolutionProperties) = preSolution | ||
HideSolutionNode = FALSE | ||
EndGlobalSection | ||
EndGlobal |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
using System.Reflection; | ||
using System.Runtime.CompilerServices; | ||
using System.Runtime.InteropServices; | ||
|
||
// General Information about an assembly is controlled through the following | ||
// set of attributes. Change these attribute values to modify the information | ||
// associated with an assembly. | ||
[assembly: AssemblyTitle("XMLRPCClient")] | ||
[assembly: AssemblyDescription("XML PRC Client Library")] | ||
[assembly: AssemblyConfiguration("")] | ||
[assembly: AssemblyCompany("Guangyu Zhang")] | ||
[assembly: AssemblyProduct("XML RPC Client Library")] | ||
[assembly: AssemblyCopyright("Copyright © Guangyu Zhang 2014")] | ||
[assembly: AssemblyTrademark("")] | ||
[assembly: AssemblyCulture("")] | ||
|
||
// Setting ComVisible to false makes the types in this assembly not visible | ||
// to COM components. If you need to access a type in this assembly from | ||
// COM, set the ComVisible attribute to true on that type. | ||
[assembly: ComVisible(false)] | ||
|
||
// The following GUID is for the ID of the typelib if this project is exposed to COM | ||
[assembly: Guid("608d636d-5210-455b-8c2b-3f35488193a1")] | ||
|
||
// Version information for an assembly consists of the following four values: | ||
// | ||
// Major Version | ||
// Minor Version | ||
// Build Number | ||
// Revision | ||
// | ||
// You can specify all the values or you can default the Build and Revision Numbers | ||
// by using the '*' as shown below: | ||
// [assembly: AssemblyVersion("1.0.*")] | ||
[assembly: AssemblyVersion("1.0.0.0")] | ||
[assembly: AssemblyFileVersion("1.0.0.0")] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||
<PropertyGroup> | ||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> | ||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> | ||
<ProductVersion>8.0.30703</ProductVersion> | ||
<SchemaVersion>2.0</SchemaVersion> | ||
<ProjectGuid>{CF207A79-E0CD-4CAB-BE7B-DDE7E37BE195}</ProjectGuid> | ||
<OutputType>Library</OutputType> | ||
<AppDesignerFolder>Properties</AppDesignerFolder> | ||
<RootNamespace>XMLRPCClient</RootNamespace> | ||
<AssemblyName>XMLRPCClient</AssemblyName> | ||
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion> | ||
<FileAlignment>512</FileAlignment> | ||
</PropertyGroup> | ||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> | ||
<DebugSymbols>true</DebugSymbols> | ||
<DebugType>full</DebugType> | ||
<Optimize>false</Optimize> | ||
<OutputPath>bin\Debug\</OutputPath> | ||
<DefineConstants>DEBUG;TRACE</DefineConstants> | ||
<ErrorReport>prompt</ErrorReport> | ||
<WarningLevel>4</WarningLevel> | ||
</PropertyGroup> | ||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> | ||
<DebugType>pdbonly</DebugType> | ||
<Optimize>true</Optimize> | ||
<OutputPath>bin\Release\</OutputPath> | ||
<DefineConstants>TRACE</DefineConstants> | ||
<ErrorReport>prompt</ErrorReport> | ||
<WarningLevel>4</WarningLevel> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<Reference Include="System" /> | ||
<Reference Include="System.Core" /> | ||
<Reference Include="System.Runtime.Serialization" /> | ||
<Reference Include="System.Xml.Linq" /> | ||
<Reference Include="System.Data.DataSetExtensions" /> | ||
<Reference Include="Microsoft.CSharp" /> | ||
<Reference Include="System.Data" /> | ||
<Reference Include="System.Xml" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<Compile Include="Properties\AssemblyInfo.cs" /> | ||
<Compile Include="XmlHelper.cs" /> | ||
<Compile Include="XmlRpcClient.cs" /> | ||
</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. | ||
<Target Name="BeforeBuild"> | ||
</Target> | ||
<Target Name="AfterBuild"> | ||
</Target> | ||
--> | ||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,278 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Xml; | ||
using System.Xml.Linq; | ||
using System.Runtime.Serialization; | ||
|
||
namespace XMLRPCClient | ||
{ | ||
public static class XmlHelper | ||
{ | ||
//XmlRpc requires tags for int's http://www.xmlrpc.com/spec | ||
public static string getFullXML(XDocument xdoc) | ||
{ | ||
try | ||
{ | ||
string xml; | ||
using (System.IO.MemoryStream memStream = new System.IO.MemoryStream()) | ||
{ | ||
XmlWriter writer = XmlWriter.Create(memStream); | ||
xdoc.Save(writer); | ||
writer.Close(); | ||
memStream.Position = 0; | ||
|
||
xml = System.Text.Encoding.ASCII.GetString(memStream.GetBuffer(), 0, Convert.ToInt32(memStream.Length)).TrimEnd('\0'); | ||
xml = xml.Trim(); | ||
memStream.Close(); | ||
xml = xml.Replace("<", "<"); | ||
xml = xml.Replace(">", ">"); | ||
return xml; | ||
} | ||
} | ||
catch (Exception ex) | ||
{ | ||
throw ex; | ||
} | ||
} | ||
public static string removeXMLNodeTags(string message) | ||
{ | ||
message = message.Replace("<", "<"); | ||
message = message.Replace(">", ">"); | ||
|
||
return message; | ||
} | ||
public static string ReplaceXmlTag(string message) | ||
{ | ||
message = message.Replace("<", "["); | ||
message = message.Replace(">", "]"); | ||
return message; | ||
|
||
} | ||
public static string getFullXML(XElement xElement) | ||
{ | ||
XDocument xdoc = new XDocument(new XDeclaration("1.0", "ISO-8859-1", String.Empty), xElement); | ||
|
||
//xdoc.AddAfterSelf(xElement); | ||
return getFullXML(xdoc); | ||
} | ||
|
||
public static string ConvertDataContractToText(object dataContractOjbect) | ||
{ | ||
string value = ""; | ||
value = getFullXML(RemoveAllNamespaces(dataContractOjbect)); | ||
|
||
return value; | ||
} | ||
public static XElement RemoveAllNamespaces(object dataContractObject) | ||
{ | ||
try | ||
{ | ||
Type objectType = dataContractObject.GetType(); | ||
DataContractSerializer dcs = new DataContractSerializer(objectType); | ||
|
||
String text; | ||
using (System.IO.MemoryStream memoryStream = new System.IO.MemoryStream()) | ||
{ | ||
dcs.WriteObject(memoryStream, dataContractObject); | ||
text = System.Text.Encoding.ASCII.GetString(memoryStream.ToArray()); | ||
XElement xelement = XmlHelper.RemoveAllXElementNamespaces(XElement.Parse(text)); | ||
|
||
return xelement; | ||
} | ||
} | ||
catch (Exception ex) | ||
{ | ||
throw ex; | ||
} | ||
|
||
} | ||
|
||
private static XElement RemoveAllXElementNamespaces(XElement xmlDocument) | ||
{ | ||
try | ||
{ | ||
if (!xmlDocument.HasElements) | ||
{ | ||
XElement xElement = new XElement(xmlDocument.Name.LocalName); | ||
xElement.Value = xmlDocument.Value; | ||
return xElement; | ||
} | ||
return new XElement(xmlDocument.Name.LocalName, xmlDocument.Elements().Select(el => RemoveAllXElementNamespaces(el))); | ||
} | ||
catch (Exception ex) | ||
{ | ||
throw ex; | ||
} | ||
} | ||
|
||
public static String RemoveXmlDeclarations(string possibleXmlText) | ||
{ | ||
|
||
try | ||
{ | ||
if (possibleXmlText.Contains("<?xml version")) | ||
{ | ||
int startTagLocation = possibleXmlText.IndexOf("<?xml version"); | ||
int endTagLocation = possibleXmlText.IndexOf(">", startTagLocation); | ||
possibleXmlText = possibleXmlText.Remove(startTagLocation, endTagLocation - startTagLocation + 1); | ||
possibleXmlText = RemoveXmlDeclarations(possibleXmlText); | ||
|
||
} | ||
return possibleXmlText; | ||
} | ||
catch (Exception ex) | ||
{ | ||
throw ex; | ||
} | ||
} | ||
} | ||
[DataContract(Name = "methodCall")] | ||
public class MethodCall | ||
{ | ||
public MethodCall(string username, string password, string methodName) | ||
{ | ||
MethodName = methodName; | ||
methodParameterList = new List<MethodParameter>(); | ||
methodParameterList.Add(new MethodParameter(username)); | ||
methodParameterList.Add(new MethodParameter(password)); | ||
} | ||
|
||
[DataMember(Name = "methodName", Order = 1)] | ||
public string MethodName { get; set; } | ||
|
||
[DataMember(Name = "params", Order = 2)] | ||
public List<MethodParameter> methodParameterList { get; set; } | ||
|
||
public string Request | ||
{ | ||
get | ||
{ | ||
XElement xElement = XmlHelper.RemoveAllNamespaces(this); | ||
return XmlHelper.getFullXML(xElement); | ||
} | ||
} | ||
} | ||
|
||
[DataContract(Name = "param")] | ||
public class MethodParameter | ||
{ | ||
public MethodParameter() | ||
{ } | ||
public MethodParameter(string valueToSet) | ||
{ | ||
value = valueToSet; | ||
} | ||
|
||
|
||
[DataMember(IsRequired = true)] | ||
public string value { get; set; } | ||
} | ||
|
||
[DataContract(Name = "param")] | ||
public class MethodIntArrayParameter : MethodParameter | ||
{ | ||
public MethodIntArrayParameter() | ||
{ } | ||
public MethodIntArrayParameter(string[] valueToSet) | ||
{ | ||
StringBuilder sb = new StringBuilder("<array><data>"); | ||
foreach (string x in valueToSet) | ||
{ | ||
sb.Append("<value><i4>"); | ||
sb.Append(x); | ||
sb.Append("</i4></value>"); | ||
} | ||
sb.Append("</data></array>"); | ||
value = sb.ToString(); | ||
} | ||
|
||
public MethodIntArrayParameter(int[] valueToSet) | ||
{ | ||
StringBuilder sb = new StringBuilder("<array><data>"); | ||
foreach (int x in valueToSet) | ||
{ | ||
sb.Append("<value><i4>"); | ||
sb.Append(x.ToString()); | ||
sb.Append("</i4></value>"); | ||
} | ||
sb.Append("</data></array>"); | ||
value = sb.ToString(); | ||
} | ||
} | ||
|
||
[DataContract(Name = "param")] | ||
public class MethodStringArrayParameter : MethodParameter | ||
{ | ||
public MethodStringArrayParameter() | ||
{ } | ||
public MethodStringArrayParameter(string[] valueToSet) | ||
{ | ||
StringBuilder sb = new StringBuilder(valueToSet.Count()); | ||
foreach (string x in valueToSet) | ||
{ | ||
sb.Append(x + ","); | ||
//value = "<i4>" + valueToSet.ToString() + "</i4>"; | ||
} | ||
value = sb.ToString(); | ||
} | ||
} | ||
|
||
[DataContract(Name = "param")] | ||
public class MethodDateTimeArrayParameter : MethodParameter | ||
{ | ||
public MethodDateTimeArrayParameter(DateTime [] valueToSet) | ||
{ | ||
StringBuilder sb = new StringBuilder("<array><data>"); | ||
foreach (DateTime x in valueToSet) | ||
{ | ||
sb.Append("<value><dateTime.iso8601>"); | ||
sb.Append(x.ToString("yyyyMMddTHH:mm:ss")); | ||
sb.Append("</dateTime.iso8601></value>"); | ||
} | ||
sb.Append("</data></array>"); | ||
value = sb.ToString(); | ||
} | ||
public MethodDateTimeArrayParameter(string[] valueToSet) | ||
{ | ||
StringBuilder sb = new StringBuilder("<array><data>"); | ||
foreach (string x in valueToSet) | ||
{ | ||
sb.Append("<value><dateTime.iso8601>"); | ||
sb.Append(x); | ||
sb.Append("</dateTime.iso8601></value>"); | ||
} | ||
sb.Append("</data></array>"); | ||
value = sb.ToString(); | ||
} | ||
} | ||
|
||
[DataContract(Name = "param")] | ||
public class MethodIntegerParameter : MethodParameter | ||
{ | ||
public MethodIntegerParameter(int valueToSet) | ||
{ | ||
value = "<i4>" + valueToSet.ToString() + "</i4>"; | ||
} | ||
public MethodIntegerParameter(string valueToSet) | ||
{ | ||
value = "<i4>" + valueToSet + "</i4>"; | ||
} | ||
} | ||
|
||
|
||
[DataContract(Name = "param")] | ||
public class MethodDateTimeParameter : MethodParameter | ||
{ | ||
public MethodDateTimeParameter(DateTime valueToSet) | ||
{ | ||
value = "<dateTime.iso8601>" + valueToSet.ToString("yyyyMMddTHH:mm:ss") + "</dateTime.iso8601>"; | ||
} | ||
public MethodDateTimeParameter(string valueToSet) | ||
{ | ||
value = "<dateTime.iso8601>" + valueToSet + "</dateTime.iso8601>"; | ||
} | ||
} | ||
} | ||
|
Oops, something went wrong.