├── XmlRpc.sln.DotSettings ├── XmlRpc.Tests ├── Structs.cs ├── MethodCalls.cs ├── Properties │ └── AssemblyInfo.cs └── XmlRpc.Tests.csproj ├── XmlRpc ├── Methods │ ├── SystemListMethods.cs │ ├── SystemMethodHelp.cs │ ├── SystemMethodSignature.cs │ ├── XmlRpcMethodCall-1Param.cs │ ├── XmlRpcMethodCall-2Params.cs │ ├── XmlRpcMethodCall-3PArams.cs │ ├── XmlRpcMethodCall-4Params.cs │ ├── XmlRpcMethodCall-5Params.cs │ └── XmlRpcMethodCall-0Params.cs ├── Types │ ├── Structs │ │ ├── ParseStruct.snippet │ │ ├── FaultStruct.cs │ │ └── BaseStruct.cs │ ├── XmlRpcI4.cs │ ├── XmlRpcInt.cs │ ├── XmlRpcDouble.cs │ ├── XmlRpcString.cs │ ├── XmlRpcBase64.cs │ ├── XmlRpcStruct.cs │ ├── XmlRpcBoolean.cs │ ├── XmlRpcDateTime.cs │ ├── XmlRpcArray.cs │ └── XmlRpcType.cs ├── Properties │ ├── AssemblyInfo.cs │ └── Annotations.cs ├── Testing │ ├── ReflectionUtils.cs │ ├── MethodCalls.cs │ └── Structs.cs ├── IXmlRpcClient.cs ├── XmlRpcElements.cs └── XmlRpc.csproj ├── XmlRpc.nuspec ├── XmlRpc.sln ├── .gitattributes ├── .gitignore ├── XmlRpc.symbols.nuspec ├── README.md └── LICENSE.md /XmlRpc.sln.DotSettings: -------------------------------------------------------------------------------- 1 | 2 | True -------------------------------------------------------------------------------- /XmlRpc.Tests/Structs.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.VisualStudio.TestTools.UnitTesting; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using XmlRpc.Types.Structs; 6 | 7 | namespace XmlRpc.Tests 8 | { 9 | [TestClass] 10 | public class Structs 11 | { 12 | [TestMethod] 13 | public void AreRoundTripSave() 14 | { 15 | Testing.Structs.AreRoundTripSave((success, type, reason) => Assert.IsTrue(success, type + reason), typeof(BaseStruct).Assembly); 16 | } 17 | } 18 | } -------------------------------------------------------------------------------- /XmlRpc/Methods/SystemListMethods.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using XmlRpc.Types; 5 | 6 | namespace XmlRpc.Methods 7 | { 8 | /// 9 | /// Represents a call to the system.listMethods method. 10 | /// 11 | public sealed class SystemListMethods : XmlRpcMethodCall, XmlRpcString[]> 12 | { 13 | /// 14 | /// Gets the name of the method this call is for. 15 | /// 16 | public override string MethodName 17 | { 18 | get { return "system.listMethods"; } 19 | } 20 | } 21 | } -------------------------------------------------------------------------------- /XmlRpc/Types/Structs/ParseStruct.snippet: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 |
6 | Struct ParseXml 7 | Banane9 8 | Snippet for the body of the parseXml method that implementors of the BaseStruct class have to override. 9 | parsestruct 10 |
11 | 12 | 13 | 24 | 25 | 26 |
27 |
28 | -------------------------------------------------------------------------------- /XmlRpc/Types/XmlRpcI4.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | 5 | namespace XmlRpc.Types 6 | { 7 | /// 8 | /// Represents an XmlRpcType containing an int. 9 | /// 10 | public sealed class XmlRpcI4 : XmlRpcInt 11 | { 12 | /// 13 | /// The name of Elements of this type. 14 | /// 15 | public override string ContentElementName 16 | { 17 | get { return XmlRpcElements.I4Element; } 18 | } 19 | 20 | /// 21 | /// Creates a new instance of the class with Value set to the default value for int. 22 | /// 23 | public XmlRpcI4() 24 | { } 25 | 26 | /// 27 | /// Creates a new instance of the class with the given value. 28 | /// 29 | /// The int encapsulated by this. 30 | public XmlRpcI4(int value) 31 | : base(value) 32 | 33 | { } 34 | } 35 | } -------------------------------------------------------------------------------- /XmlRpc/Methods/SystemMethodHelp.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using XmlRpc.Types; 5 | 6 | namespace XmlRpc.Methods 7 | { 8 | /// 9 | /// Represents a call to the system.methodHelp method. 10 | /// 11 | public sealed class SystemMethodHelp : XmlRpcMethodCall 12 | { 13 | /// 14 | /// Gets the name of the method this call is for. 15 | /// 16 | public override string MethodName 17 | { 18 | get { return "system.methodHelp"; } 19 | } 20 | 21 | /// 22 | /// Gets or sets the name of the method that the help is wanted for. 23 | /// 24 | public string TargetMethod 25 | { 26 | get { return param1.Value; } 27 | set { param1.Value = value; } 28 | } 29 | 30 | /// 31 | /// Creates a new instance of the class with the given target method name. 32 | /// 33 | /// The name of the method that the help is wanted for. 34 | public SystemMethodHelp(string targetMethod) 35 | : base(targetMethod) 36 | { } 37 | } 38 | } -------------------------------------------------------------------------------- /XmlRpc.Tests/MethodCalls.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.VisualStudio.TestTools.UnitTesting; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using XmlRpc.Methods; 6 | 7 | namespace XmlRpc.Tests 8 | { 9 | [TestClass] 10 | public class MethodCalls 11 | { 12 | private const string call = @" 13 | system.methodHelp 14 | 15 | 16 | 17 | system.listMethods 18 | 19 | 20 | 21 | "; 22 | 23 | private const string response = @" 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | "; 32 | 33 | [TestMethod] 34 | public void AreRoundTripSave() 35 | { 36 | Testing.MethodCalls.AreRoundTripSave((success, type, reason) => Assert.IsTrue(success, type + reason), typeof(SystemListMethods).Assembly); 37 | } 38 | 39 | [TestMethod] 40 | public void SerializesCorrectly() 41 | { 42 | var methodCall = new SystemMethodHelp("system.listMethods"); 43 | Assert.AreEqual(call, methodCall.GenerateCallXml().ToString()); 44 | Assert.AreEqual(response, methodCall.GenerateResponseXml().ToString()); 45 | } 46 | } 47 | } -------------------------------------------------------------------------------- /XmlRpc/Methods/SystemMethodSignature.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using XmlRpc.Types; 5 | 6 | namespace XmlRpc.Methods 7 | { 8 | /// 9 | /// Represents a call to the system.methodSignature method. 10 | /// 11 | public sealed class SystemMethodSignature 12 | : XmlRpcMethodCall, XmlRpcString[]>, XmlRpcArray[]> 13 | { 14 | /// 15 | /// Gets or sets the login used for authentication. 16 | /// 17 | public override string MethodName 18 | { 19 | get { return "system.methodSignature"; } 20 | } 21 | 22 | /// 23 | /// Gets or sets the name of the method that the signatures are wanted for. 24 | /// 25 | public string TargetMethod 26 | { 27 | get { return param1.Value; } 28 | set { param1.Value = value; } 29 | } 30 | 31 | /// 32 | /// Creates a new instance of the class with the given target method name. 33 | /// 34 | /// The name of the method that the signatures are wanted for. 35 | public SystemMethodSignature(string targetMethod) 36 | : base(targetMethod) 37 | { } 38 | } 39 | } -------------------------------------------------------------------------------- /XmlRpc.nuspec: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | XmlRpc 5 | 2.1.1 6 | XmlRpc 7 | Banane9 8 | Banane9 9 | https://github.com/Banane9/XmlRpc/blob/master/LICENSE.md 10 | https://github.com/Banane9/XmlRpc 11 | false 12 | Library for interfacing with a server using XmlRpc 13 | Library for interfacing with a server using XmlRpc. 14 | Fixed derpy bug with MethodCall ParseResponseXml. 15 | en 16 | xmlrpc xml remote server function web request control 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /XmlRpc.Tests/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // Allgemeine Informationen über eine Assembly werden über folgende 6 | // Attribute gesteuert. Ändern Sie diese Attributwerte, um die Informationen zu ändern, 7 | // die einer Assembly zugeordnet sind. 8 | [assembly: AssemblyTitle("XmlRpc.Tests")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("XmlRpc.Tests")] 13 | [assembly: AssemblyCopyright("Copyright © 2014")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Wenn ComVisible auf "false" festgelegt wird, sind die Typen innerhalb dieser Assembly 18 | // für COM-Komponenten unsichtbar. Wenn Sie auf einen Typ in dieser Assembly von 19 | // COM aus zugreifen müssen, sollten Sie das ComVisible-Attribut für diesen Typ auf "True" festlegen. 20 | [assembly: ComVisible(false)] 21 | 22 | // Die folgende GUID bestimmt die ID der Typbibliothek, wenn dieses Projekt für COM verfügbar gemacht wird 23 | [assembly: Guid("821f36bd-6c92-4158-b33f-f81831d85f56")] 24 | 25 | // Versionsinformationen für eine Assembly bestehen aus den folgenden vier Werten: 26 | // 27 | // Hauptversion 28 | // Nebenversion 29 | // Buildnummer 30 | // Revision 31 | // 32 | // Sie können alle Werte angeben oder die standardmäßigen Build- und Revisionsnummern 33 | // durch Einsatz von '*', wie in nachfolgendem Beispiel: 34 | // [Assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.0.0.0")] 36 | [assembly: AssemblyFileVersion("1.0.0.0")] 37 | -------------------------------------------------------------------------------- /XmlRpc/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Reflection; 5 | using System.Runtime.InteropServices; 6 | 7 | // Allgemeine Informationen über eine Assembly werden über die folgenden 8 | // Attribute gesteuert. Ändern Sie diese Attributwerte, um die Informationen zu ändern, 9 | // die mit einer Assembly verknüpft sind. 10 | 11 | [assembly: AssemblyTitle("XmlRpc")] 12 | [assembly: AssemblyDescription("Implementation of the Xml-Rpc Spec.")] 13 | [assembly: AssemblyConfiguration("")] 14 | [assembly: AssemblyCompany("Banane9")] 15 | [assembly: AssemblyProduct("XmlRpc")] 16 | [assembly: AssemblyCopyright("Copyright © Banane9 2014")] 17 | [assembly: AssemblyTrademark("")] 18 | [assembly: AssemblyCulture("")] 19 | 20 | // Durch Festlegen von ComVisible auf "false" werden die Typen in dieser Assembly unsichtbar 21 | // für COM-Komponenten. Wenn Sie auf einen Typ in dieser Assembly von 22 | // COM zugreifen müssen, legen Sie das ComVisible-Attribut für diesen Typ auf "true" fest. 23 | 24 | [assembly: ComVisible(false)] 25 | 26 | // Die folgende GUID bestimmt die ID der Typbibliothek, wenn dieses Projekt für COM verfügbar gemacht wird 27 | 28 | [assembly: Guid("5e546fe3-3da8-4fa2-b018-60071bfdcbc6")] 29 | 30 | // Versionsinformationen für eine Assembly bestehen aus den folgenden vier Werten: 31 | // 32 | // Hauptversion 33 | // Nebenversion 34 | // Buildnummer 35 | // Revision 36 | // 37 | // Sie können alle Werte angeben oder die standardmäßigen Build- und Revisionsnummern 38 | // übernehmen, indem Sie "*" eingeben: 39 | // [assembly: AssemblyVersion("1.0.*")] 40 | [assembly: AssemblyVersion("2.1.*")] 41 | [assembly: AssemblyFileVersion("2.0.0.0")] -------------------------------------------------------------------------------- /XmlRpc/Types/XmlRpcInt.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Xml.Linq; 5 | 6 | namespace XmlRpc.Types 7 | { 8 | /// 9 | /// Represents an XmlRpcType containing an int. 10 | /// 11 | public class XmlRpcInt : XmlRpcType 12 | { 13 | /// 14 | /// The name of value content elements for this XmlRpc type. 15 | /// 16 | public override string ContentElementName 17 | { 18 | get { return XmlRpcElements.IntElement; } 19 | } 20 | 21 | /// 22 | /// Creates a new instance of the class with Value set to the default value for int. 23 | /// 24 | public XmlRpcInt() 25 | { } 26 | 27 | /// 28 | /// Creates a new instance of the class with the given value. 29 | /// 30 | /// The int encapsulated by this. 31 | public XmlRpcInt(int value) 32 | : base(value) 33 | { } 34 | 35 | /// 36 | /// Sets the Value property with the information contained in the value-XElement. 37 | /// 38 | /// The element containing the information. 39 | /// Whether it was successful or not. 40 | protected override bool parseXml(XElement xElement) 41 | { 42 | int value; 43 | 44 | if (int.TryParse(xElement.Elements().First().Value, out value)) 45 | { 46 | Value = value; 47 | return true; 48 | } 49 | 50 | return false; 51 | } 52 | } 53 | } -------------------------------------------------------------------------------- /XmlRpc/Types/XmlRpcDouble.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Xml.Linq; 5 | 6 | namespace XmlRpc.Types 7 | { 8 | /// 9 | /// Represents an XmlRpcType containing a double. 10 | /// 11 | public sealed class XmlRpcDouble : XmlRpcType 12 | { 13 | /// 14 | /// The name of value content elements for this XmlRpc type. 15 | /// 16 | public override string ContentElementName 17 | { 18 | get { return XmlRpcElements.DoubleElement; } 19 | } 20 | 21 | /// 22 | /// Creates a new instance of the class with Value set to the default value for double. 23 | /// 24 | public XmlRpcDouble() 25 | { } 26 | 27 | /// 28 | /// Creates a new instance of the class with the given value. 29 | /// 30 | /// The double encapsulated by this. 31 | public XmlRpcDouble(double value) 32 | : base(value) 33 | { } 34 | 35 | /// 36 | /// Sets the Value property with the information contained in the value-XElement. 37 | /// 38 | /// The element containing the information. 39 | /// Whether it was successful or not. 40 | protected override bool parseXml(XElement xElement) 41 | { 42 | double value; 43 | 44 | if (double.TryParse(xElement.Elements().First().Value, out value)) 45 | { 46 | Value = value; 47 | return true; 48 | } 49 | 50 | return false; 51 | } 52 | } 53 | } -------------------------------------------------------------------------------- /XmlRpc.sln: -------------------------------------------------------------------------------- 1 | 2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 2013 4 | VisualStudioVersion = 12.0.30501.0 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "XmlRpc", "XmlRpc\XmlRpc.csproj", "{A2E6F931-5BB9-4786-BE35-CEBA3FB72791}" 7 | EndProject 8 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{F1A24E14-7C97-4524-924D-A0347775F70B}" 9 | ProjectSection(SolutionItems) = preProject 10 | .gitattributes = .gitattributes 11 | .gitignore = .gitignore 12 | README.md = README.md 13 | XmlRpc.1.1.nuspec = XmlRpc.1.1.nuspec 14 | EndProjectSection 15 | EndProject 16 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "XmlRpc.Tests", "XmlRpc.Tests\XmlRpc.Tests.csproj", "{C8034D5C-53AD-4096-B1E3-421155647A82}" 17 | EndProject 18 | Global 19 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 20 | Debug|Any CPU = Debug|Any CPU 21 | Release|Any CPU = Release|Any CPU 22 | EndGlobalSection 23 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 24 | {A2E6F931-5BB9-4786-BE35-CEBA3FB72791}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 25 | {A2E6F931-5BB9-4786-BE35-CEBA3FB72791}.Debug|Any CPU.Build.0 = Debug|Any CPU 26 | {A2E6F931-5BB9-4786-BE35-CEBA3FB72791}.Release|Any CPU.ActiveCfg = Release|Any CPU 27 | {A2E6F931-5BB9-4786-BE35-CEBA3FB72791}.Release|Any CPU.Build.0 = Release|Any CPU 28 | {C8034D5C-53AD-4096-B1E3-421155647A82}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 29 | {C8034D5C-53AD-4096-B1E3-421155647A82}.Debug|Any CPU.Build.0 = Debug|Any CPU 30 | {C8034D5C-53AD-4096-B1E3-421155647A82}.Release|Any CPU.ActiveCfg = Release|Any CPU 31 | {C8034D5C-53AD-4096-B1E3-421155647A82}.Release|Any CPU.Build.0 = Release|Any CPU 32 | EndGlobalSection 33 | GlobalSection(SolutionProperties) = preSolution 34 | HideSolutionNode = FALSE 35 | EndGlobalSection 36 | EndGlobal 37 | -------------------------------------------------------------------------------- /XmlRpc/Types/XmlRpcString.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Xml.Linq; 5 | 6 | namespace XmlRpc.Types 7 | { 8 | /// 9 | /// Represents an XmlRpcType containing a string. 10 | /// 11 | public sealed class XmlRpcString : XmlRpcType 12 | { 13 | /// 14 | /// The name of value content elements for this XmlRpc type. 15 | /// 16 | public override string ContentElementName 17 | { 18 | get { return XmlRpcElements.StringElement; } 19 | } 20 | 21 | /// 22 | /// Creates a new instance of the class with Value set to an empty string. 23 | /// 24 | public XmlRpcString() 25 | : base(string.Empty) 26 | { } 27 | 28 | /// 29 | /// Creates a new instance of the class with the given value. 30 | /// 31 | /// The string encapsulated by this. 32 | public XmlRpcString(string value) 33 | : base(value) 34 | { } 35 | 36 | /// 37 | /// Checks whether the value-XElement has content fitting with this XmlRpc type. 38 | /// 39 | /// The element to check. 40 | /// Whether it has fitting content or not. 41 | protected override bool hasValueCorrectContent(XElement xElement) 42 | { 43 | return (!xElement.HasElements && !xElement.IsEmpty) || base.hasValueCorrectContent(xElement); 44 | } 45 | 46 | /// 47 | /// Sets the Value property with the information contained in the value-XElement. 48 | /// 49 | /// The element containing the information. 50 | /// Whether it was successful or not. 51 | protected override bool parseXml(XElement xElement) 52 | { 53 | if (xElement.HasElements) 54 | Value = xElement.Elements().First().Value; 55 | else if (!xElement.IsEmpty) 56 | Value = xElement.Value; 57 | else 58 | return false; 59 | 60 | return true; 61 | } 62 | } 63 | } -------------------------------------------------------------------------------- /XmlRpc/Testing/ReflectionUtils.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | 5 | namespace XmlRpc.Testing 6 | { 7 | internal static class ReflectionUtils 8 | { 9 | public static object GetDefaultValue(this Type t) 10 | { 11 | if (t == null) 12 | return null; 13 | 14 | return t.IsValueType ? Activator.CreateInstance(t) : null; 15 | } 16 | 17 | public static bool InheritsOrImplements(this Type child, Type parent) 18 | { 19 | parent = resolveGenericTypeDefinition(parent); 20 | 21 | var currentChild = child.IsGenericType 22 | ? child.GetGenericTypeDefinition() 23 | : child; 24 | 25 | while (currentChild != typeof(object)) 26 | { 27 | if (parent == currentChild || hasAnyInterfaces(parent, currentChild)) 28 | return true; 29 | 30 | currentChild = currentChild.BaseType != null 31 | && currentChild.BaseType.IsGenericType 32 | ? currentChild.BaseType.GetGenericTypeDefinition() 33 | : currentChild.BaseType; 34 | 35 | if (currentChild == null) 36 | return false; 37 | } 38 | return false; 39 | } 40 | 41 | private static bool hasAnyInterfaces(Type parent, Type child) 42 | { 43 | return child.GetInterfaces() 44 | .Any(childInterface => 45 | { 46 | var currentInterface = childInterface.IsGenericType 47 | ? childInterface.GetGenericTypeDefinition() 48 | : childInterface; 49 | 50 | return currentInterface == parent; 51 | }); 52 | } 53 | 54 | private static Type resolveGenericTypeDefinition(Type parent) 55 | { 56 | var shouldUseGenericType = !(parent.IsGenericType && parent.GetGenericTypeDefinition() != parent); 57 | 58 | if (parent.IsGenericType && shouldUseGenericType) 59 | parent = parent.GetGenericTypeDefinition(); 60 | return parent; 61 | } 62 | } 63 | } -------------------------------------------------------------------------------- /XmlRpc/Types/XmlRpcBase64.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Xml.Linq; 5 | 6 | namespace XmlRpc.Types 7 | { 8 | /// 9 | /// Represents an XmlRpcType containing a byte array that is formatted as base64 string. 10 | /// 11 | public sealed class XmlRpcBase64 : XmlRpcType 12 | { 13 | /// 14 | /// The name of value content elements for this XmlRpc type. 15 | /// 16 | public override string ContentElementName 17 | { 18 | get { return XmlRpcElements.Base64Element; } 19 | } 20 | 21 | /// 22 | /// Creates a new instance of the class with a zero-length byte array for the Value property. 23 | /// 24 | public XmlRpcBase64() 25 | : base(new byte[0]) 26 | { } 27 | 28 | /// 29 | /// Creates a new instance of the class with the given value. 30 | /// 31 | /// The data encapsulated by this. 32 | public XmlRpcBase64(byte[] value) 33 | : base(value) 34 | { } 35 | 36 | /// 37 | /// Generates an XElement from the Value. Default implementation creates an XElement with the ElementName and the content from Value. 38 | /// 39 | /// The generated Xml. 40 | public override XElement GenerateXml() 41 | { 42 | return new XElement(XName.Get(XmlRpcElements.ValueElement), 43 | new XElement(XName.Get(ContentElementName), Convert.ToBase64String(Value))); 44 | } 45 | 46 | /// 47 | /// Sets the Value property with the information contained in the value-XElement. 48 | /// 49 | /// The element containing the information. 50 | /// Whether it was successful or not. 51 | protected override bool parseXml(XElement xElement) 52 | { 53 | try 54 | { 55 | Value = Convert.FromBase64String(xElement.Elements().First().Value); 56 | return true; 57 | } 58 | catch 59 | { 60 | return false; 61 | } 62 | } 63 | } 64 | } -------------------------------------------------------------------------------- /XmlRpc/Types/XmlRpcStruct.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Xml.Linq; 5 | using XmlRpc.Types.Structs; 6 | 7 | namespace XmlRpc.Types 8 | { 9 | /// 10 | /// Represents an XmlRpcType containing a xml rpc struct that is derived from . 11 | /// 12 | /// The Type of the struct. Also the Type of the Value property. 13 | public sealed class XmlRpcStruct : XmlRpcType 14 | where TXmlRpcStruct : BaseStruct, new() 15 | { 16 | /// 17 | /// The name of value content elements for this XmlRpc type. 18 | /// 19 | public override string ContentElementName 20 | { 21 | get { return XmlRpcElements.StructElement; } 22 | } 23 | 24 | /// 25 | /// Creates a new instance of the class with a new TXmlRpcType. 26 | /// 27 | public XmlRpcStruct() 28 | : base(new TXmlRpcStruct()) 29 | { } 30 | 31 | /// 32 | /// Creates a new instance of the class with the given value. 33 | /// 34 | /// The struct encapsulated by this. 35 | public XmlRpcStruct(TXmlRpcStruct value) 36 | : base(value) 37 | { } 38 | 39 | /// 40 | /// Generates a value-XElement capsuling the struct. 41 | /// 42 | /// The generated Xml. 43 | public override XElement GenerateXml() 44 | { 45 | return new XElement(XName.Get(XmlRpcElements.ValueElement), 46 | Value.GenerateXml()); 47 | } 48 | 49 | /// 50 | /// Sets the Value property with the information contained in the value-XElement. 51 | /// 52 | /// The element containing the information. 53 | /// Whether it was successful or not. 54 | protected override bool parseXml(XElement xElement) 55 | { 56 | if (Value == null) 57 | Value = new TXmlRpcStruct(); 58 | 59 | return Value.ParseXml(xElement.Elements().First()); 60 | } 61 | } 62 | } -------------------------------------------------------------------------------- /XmlRpc/Types/XmlRpcBoolean.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Xml.Linq; 5 | 6 | namespace XmlRpc.Types 7 | { 8 | /// 9 | /// Represents an XmlRpcType containing a boolean. 10 | /// 11 | public sealed class XmlRpcBoolean : XmlRpcType 12 | { 13 | /// 14 | /// The name of Elements of this type. 15 | /// 16 | public override string ContentElementName 17 | { 18 | get { return XmlRpcElements.BooleanElement; } 19 | } 20 | 21 | /// 22 | /// Creates a new instance of the class with Value set to the default value for bool. 23 | /// 24 | public XmlRpcBoolean() 25 | { } 26 | 27 | /// 28 | /// Creates a new instance of the class with the given value. 29 | /// 30 | /// The bool encapsulated by this. 31 | public XmlRpcBoolean(bool value) 32 | : base(value) 33 | { } 34 | 35 | /// 36 | /// Generates a value-XElement containing the information stored in this XmlRpc type. 37 | /// 38 | /// The generated Xml. 39 | public override XElement GenerateXml() 40 | { 41 | return new XElement(XName.Get(XmlRpcElements.ValueElement), 42 | new XElement(XName.Get(ContentElementName), Value ? 1 : 0)); 43 | } 44 | 45 | /// 46 | /// Sets the Value property with the information contained in the value-XElement. 47 | /// 48 | /// The element containing the information. 49 | /// Whether it was successful or not. 50 | protected override bool parseXml(XElement xElement) 51 | { 52 | switch (xElement.Elements().First().Value.ToLower()) 53 | { 54 | case "false": 55 | case "0": 56 | Value = false; 57 | break; 58 | 59 | case "true": 60 | case "1": 61 | Value = true; 62 | break; 63 | 64 | default: 65 | return false; 66 | } 67 | 68 | return true; 69 | } 70 | } 71 | } -------------------------------------------------------------------------------- /XmlRpc/Types/Structs/FaultStruct.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Xml.Linq; 5 | 6 | namespace XmlRpc.Types.Structs 7 | { 8 | /// 9 | /// Gets the struct returned when a method call has a fault. 10 | /// 11 | public sealed class FaultStruct : BaseStruct 12 | { 13 | /// 14 | /// Backing field for the FaultCode property. 15 | /// 16 | private readonly XmlRpcInt faultCode = new XmlRpcInt(); 17 | 18 | /// 19 | /// Backing field for the FaultString property. 20 | /// 21 | private readonly XmlRpcString faultString = new XmlRpcString(); 22 | 23 | /// 24 | /// Gets the fault code. 25 | /// 26 | public int FaultCode 27 | { 28 | get { return faultCode.Value; } 29 | } 30 | 31 | /// 32 | /// Gets the description of the fault. 33 | /// 34 | public string FaultString 35 | { 36 | get { return faultString.Value; } 37 | } 38 | 39 | /// 40 | /// Generates an XElement storing the information in this struct. 41 | /// 42 | /// The generated XElement. 43 | public override XElement GenerateXml() 44 | { 45 | return new XElement(XName.Get(XmlRpcElements.StructElement), 46 | makeMemberElement("faultCode", faultCode), 47 | makeMemberElement("faultString", faultString)); 48 | } 49 | 50 | /// 51 | /// Fills the property of this struct that has the correct name with the information contained in the member-XElement. 52 | /// 53 | /// The member element storing the information. 54 | /// Whether it was successful or not. 55 | protected override bool parseXml(XElement member) 56 | { 57 | XElement value = getMemberValueElement(member); 58 | 59 | switch (getMemberName(member)) 60 | { 61 | case "faultCode": 62 | if (!faultCode.ParseXml(value)) 63 | return false; 64 | break; 65 | 66 | case "faultString": 67 | if (!faultString.ParseXml(value)) 68 | return false; 69 | break; 70 | 71 | default: 72 | return false; 73 | } 74 | 75 | return true; 76 | } 77 | } 78 | } -------------------------------------------------------------------------------- /XmlRpc/Methods/XmlRpcMethodCall-1Param.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Xml.Linq; 5 | using XmlRpc.Types; 6 | 7 | namespace XmlRpc.Methods 8 | { 9 | /// 10 | /// Abstract base class for method calls that have one parameter and the base classes for those that have more. 11 | /// 12 | /// The XmlRpcType of the parameter. 13 | /// The type of the parameter value. 14 | /// The returned XmlRpcType. 15 | /// The type of the return value. 16 | public abstract class XmlRpcMethodCall : XmlRpcMethodCall 17 | where TParam1 : XmlRpcType, new() 18 | where TReturn : XmlRpcType, new() 19 | { 20 | /// 21 | /// Field for the first parameter. 22 | /// 23 | protected TParam1 param1 = new TParam1(); 24 | 25 | /// 26 | /// Creates a new instance of the class with the given value for the parameter. 27 | /// 28 | /// The parameter's value. 29 | protected XmlRpcMethodCall(TParam1Base param1) 30 | { 31 | this.param1.Value = param1; 32 | } 33 | 34 | /// 35 | /// Generates Xml containing the parameter data. 36 | /// 37 | /// To be overridden by classes that add more parameters to add theirs. 38 | /// 39 | /// An XElement containing the parameter data. 40 | protected override XElement generateCallParamsXml() 41 | { 42 | XElement paramsElement = base.generateCallParamsXml(); 43 | paramsElement.Add(makeParamElement(param1)); 44 | return paramsElement; 45 | } 46 | 47 | /// 48 | /// Fills the properties of this method call with the information contained in the XElement. 49 | /// 50 | /// The params element storing the information. 51 | /// Whether it was successful or not. 52 | protected override bool parseCallParamsXml(XElement paramsElement) 53 | { 54 | if (!parseCallParamXml(paramsElement, param1)) 55 | return false; 56 | 57 | return base.parseCallParamsXml(paramsElement); 58 | } 59 | } 60 | } -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | ############################################################################### 2 | # Set default behavior to automatically normalize line endings. 3 | ############################################################################### 4 | * text=auto 5 | 6 | ############################################################################### 7 | # Set default behavior for command prompt diff. 8 | # 9 | # This is need for earlier builds of msysgit that does not have it on by 10 | # default for csharp files. 11 | # Note: This is only used by command line 12 | ############################################################################### 13 | #*.cs diff=csharp 14 | 15 | ############################################################################### 16 | # Set the merge driver for project and solution files 17 | # 18 | # Merging from the command prompt will add diff markers to the files if there 19 | # are conflicts (Merging from VS is not affected by the settings below, in VS 20 | # the diff markers are never inserted). Diff markers may cause the following 21 | # file extensions to fail to load in VS. An alternative would be to treat 22 | # these files as binary and thus will always conflict and require user 23 | # intervention with every merge. To do so, just uncomment the entries below 24 | ############################################################################### 25 | #*.sln merge=binary 26 | #*.csproj merge=binary 27 | #*.vbproj merge=binary 28 | #*.vcxproj merge=binary 29 | #*.vcproj merge=binary 30 | #*.dbproj merge=binary 31 | #*.fsproj merge=binary 32 | #*.lsproj merge=binary 33 | #*.wixproj merge=binary 34 | #*.modelproj merge=binary 35 | #*.sqlproj merge=binary 36 | #*.wwaproj merge=binary 37 | 38 | ############################################################################### 39 | # behavior for image files 40 | # 41 | # image files are treated as binary by default. 42 | ############################################################################### 43 | #*.jpg binary 44 | #*.png binary 45 | #*.gif binary 46 | 47 | ############################################################################### 48 | # diff behavior for common document formats 49 | # 50 | # Convert binary document formats to text before diffing them. This feature 51 | # is only available from the command line. Turn it on by uncommenting the 52 | # entries below. 53 | ############################################################################### 54 | #*.doc diff=astextplain 55 | #*.DOC diff=astextplain 56 | #*.docx diff=astextplain 57 | #*.DOCX diff=astextplain 58 | #*.dot diff=astextplain 59 | #*.DOT diff=astextplain 60 | #*.pdf diff=astextplain 61 | #*.PDF diff=astextplain 62 | #*.rtf diff=astextplain 63 | #*.RTF diff=astextplain 64 | -------------------------------------------------------------------------------- /XmlRpc/IXmlRpcClient.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | 5 | namespace XmlRpc 6 | { 7 | /// 8 | /// EventHandler for the ConnectionDroppedUnexpectedly event. 9 | /// 10 | /// The xml rpc client of which the connection dropped. 11 | /// The Exception that caused the connection to be dropped. 12 | public delegate void ConnectionDroppedUnexpectedlyEventHandler(IXmlRpcClient sender, Exception cause); 13 | 14 | /// 15 | /// EventHandler for the MethodResponse event. 16 | /// 17 | /// The xml rpc client that received the method response. 18 | /// The handle of the method call that the response is for. 19 | /// The xml formatted content of the method response. 20 | public delegate void MethodResponseEventHandler(IXmlRpcClient sender, uint requestHandle, string methodResponse); 21 | 22 | /// 23 | /// EventHandler for the ServerCallback event. 24 | /// 25 | /// The xml rpc client that reveived the server callback. 26 | /// The xml formatted content of the method response. 27 | public delegate void ServerCallbackEventHandler(IXmlRpcClient sender, string serverCallback); 28 | 29 | /// 30 | /// Interface for XmlRpc Clients. 31 | /// 32 | public interface IXmlRpcClient 33 | { 34 | /// 35 | /// Gets client's name. 36 | /// 37 | string Name { get; } 38 | 39 | /// 40 | /// Stop reading data from the interface connection. 41 | /// 42 | void EndReceive(); 43 | 44 | /// 45 | /// Send an Xml formatted request to the XmlRpc interface. 46 | /// 47 | /// The xml formatted request. 48 | /// The handle associated with the request. 49 | uint SendRequest(string request); 50 | 51 | /// 52 | /// Start reading data from the interface connection. 53 | /// 54 | void StartReceive(); 55 | 56 | /// 57 | /// Fires when the connection drops unexpectedly. 58 | /// 59 | event ConnectionDroppedUnexpectedlyEventHandler ConnectionDroppedUnexpectedly; 60 | 61 | /// 62 | /// Fires when a MethodResponse is received. 63 | /// 64 | event MethodResponseEventHandler MethodResponse; 65 | 66 | /// 67 | /// Fires when a ServerCallback is received. 68 | /// 69 | event ServerCallbackEventHandler ServerCallback; 70 | } 71 | } -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | 4 | # User-specific files 5 | *.suo 6 | *.user 7 | *.sln.docstates 8 | 9 | # Build results 10 | 11 | [Dd]ebug/ 12 | [Rr]elease/ 13 | x64/ 14 | build/ 15 | [Bb]in/ 16 | [Oo]bj/ 17 | 18 | # Enable "build/" folder in the NuGet Packages folder since NuGet packages use it for MSBuild targets 19 | !packages/*/build/ 20 | 21 | # MSTest test Results 22 | [Tt]est[Rr]esult*/ 23 | [Bb]uild[Ll]og.* 24 | 25 | *_i.c 26 | *_p.c 27 | *.ilk 28 | *.meta 29 | *.obj 30 | *.pch 31 | *.pdb 32 | *.pgc 33 | *.pgd 34 | *.rsp 35 | *.sbr 36 | *.tlb 37 | *.tli 38 | *.tlh 39 | *.tmp 40 | *.tmp_proj 41 | *.log 42 | *.vspscc 43 | *.vssscc 44 | .builds 45 | *.pidb 46 | *.log 47 | *.scc 48 | 49 | # Visual C++ cache files 50 | ipch/ 51 | *.aps 52 | *.ncb 53 | *.opensdf 54 | *.sdf 55 | *.cachefile 56 | 57 | # Visual Studio profiler 58 | *.psess 59 | *.vsp 60 | *.vspx 61 | 62 | # Guidance Automation Toolkit 63 | *.gpState 64 | 65 | # ReSharper is a .NET coding add-in 66 | _ReSharper*/ 67 | *.[Rr]e[Ss]harper 68 | 69 | # TeamCity is a build add-in 70 | _TeamCity* 71 | 72 | # DotCover is a Code Coverage Tool 73 | *.dotCover 74 | 75 | # NCrunch 76 | *.ncrunch* 77 | .*crunch*.local.xml 78 | 79 | # Installshield output folder 80 | [Ee]xpress/ 81 | 82 | # DocProject is a documentation generator add-in 83 | DocProject/buildhelp/ 84 | DocProject/Help/*.HxT 85 | DocProject/Help/*.HxC 86 | DocProject/Help/*.hhc 87 | DocProject/Help/*.hhk 88 | DocProject/Help/*.hhp 89 | DocProject/Help/Html2 90 | DocProject/Help/html 91 | 92 | # Click-Once directory 93 | publish/ 94 | 95 | # Publish Web Output 96 | *.Publish.xml 97 | 98 | # NuGet Packages Directory 99 | ## TODO: If you have NuGet Package Restore enabled, uncomment the next line 100 | #packages/ 101 | 102 | # Windows Azure Build Output 103 | csx 104 | *.build.csdef 105 | 106 | # Windows Store app package directory 107 | AppPackages/ 108 | 109 | # Others 110 | sql/ 111 | *.Cache 112 | ClientBin/ 113 | [Ss]tyle[Cc]op.* 114 | ~$* 115 | *~ 116 | *.dbmdl 117 | *.[Pp]ublish.xml 118 | *.pfx 119 | *.publishsettings 120 | 121 | # RIA/Silverlight projects 122 | Generated_Code/ 123 | 124 | # Backup & report files from converting an old project file to a newer 125 | # Visual Studio version. Backup files are not needed, because we have git ;-) 126 | _UpgradeReport_Files/ 127 | Backup*/ 128 | UpgradeLog*.XML 129 | UpgradeLog*.htm 130 | 131 | # SQL Server files 132 | App_Data/*.mdf 133 | App_Data/*.ldf 134 | 135 | 136 | #LightSwitch generated files 137 | GeneratedArtifacts/ 138 | _Pvt_Extensions/ 139 | ModelManifest.xml 140 | 141 | # ========================= 142 | # Windows detritus 143 | # ========================= 144 | 145 | # Windows image file caches 146 | Thumbs.db 147 | ehthumbs.db 148 | 149 | # Folder config file 150 | Desktop.ini 151 | 152 | # Recycle Bin used on file shares 153 | $RECYCLE.BIN/ 154 | 155 | # Mac desktop service store files 156 | .DS_Store 157 | *.nupkg 158 | -------------------------------------------------------------------------------- /XmlRpc/XmlRpcElements.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | 5 | namespace XmlRpc 6 | { 7 | /// 8 | /// Contains constant names for the various elements that make up the XmlRpc messages. 9 | /// 10 | public static class XmlRpcElements 11 | { 12 | /// 13 | /// data 14 | /// 15 | public const string ArrayDataElement = "data"; 16 | 17 | /// 18 | /// array 19 | /// 20 | public const string ArrayElement = "array"; 21 | 22 | /// 23 | /// base64 24 | /// 25 | public const string Base64Element = "base64"; 26 | 27 | /// 28 | /// boolean 29 | /// 30 | public const string BooleanElement = "boolean"; 31 | 32 | /// 33 | /// dateTime.iso8601 34 | /// 35 | public const string DateTimeElement = "dateTime.iso8601"; 36 | 37 | /// 38 | /// double 39 | /// 40 | public const string DoubleElement = "double"; 41 | 42 | /// 43 | /// fault 44 | /// 45 | public const string FaultElement = "fault"; 46 | 47 | /// 48 | /// i4 49 | /// 50 | public const string I4Element = "i4"; 51 | 52 | /// 53 | /// int 54 | /// 55 | public const string IntElement = "int"; 56 | 57 | /// 58 | /// methodCall 59 | /// 60 | public const string MethodCallElement = "methodCall"; 61 | 62 | /// 63 | /// methodName 64 | /// 65 | public const string MethodNameElement = "methodName"; 66 | 67 | /// 68 | /// methodResponse 69 | /// 70 | public const string MethodResponseElement = "methodResponse"; 71 | 72 | /// 73 | /// param 74 | /// 75 | public const string ParamElement = "param"; 76 | 77 | /// 78 | /// params 79 | /// 80 | public const string ParamsElement = "params"; 81 | 82 | /// 83 | /// string 84 | /// 85 | public const string StringElement = "string"; 86 | 87 | /// 88 | /// struct 89 | /// 90 | public const string StructElement = "struct"; 91 | 92 | /// 93 | /// member 94 | /// 95 | public const string StructMemberElement = "member"; 96 | 97 | /// 98 | /// name 99 | /// 100 | public const string StructMemberNameElement = "name"; 101 | 102 | /// 103 | /// value 104 | /// 105 | public const string ValueElement = "value"; 106 | } 107 | } -------------------------------------------------------------------------------- /XmlRpc/Methods/XmlRpcMethodCall-2Params.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Xml.Linq; 5 | using XmlRpc.Types; 6 | 7 | namespace XmlRpc.Methods 8 | { 9 | /// 10 | /// Abstract base class for method calls that have two parameters and the base classes for those that have more. 11 | /// 12 | /// The XmlRpcType of the first parameter. 13 | /// The type of the first parameter value. 14 | /// The XmlRpcType of the second parameter. 15 | /// The type of the second parameter value. 16 | /// The returned XmlRpcType. 17 | /// The type of the return value. 18 | public abstract class XmlRpcMethodCall : XmlRpcMethodCall 19 | where TParam1 : XmlRpcType, new() 20 | where TParam2 : XmlRpcType, new() 21 | where TReturn : XmlRpcType, new() 22 | { 23 | /// 24 | /// Field for the second parameter. 25 | /// 26 | protected TParam2 param2 = new TParam2(); 27 | 28 | /// 29 | /// Creates a new instance of the 30 | /// class with the given values for the parameters. 31 | /// 32 | /// The first parameter's value. 33 | /// The second parameter's value. 34 | protected XmlRpcMethodCall(TParam1Base param1, TParam2Base param2) 35 | : base(param1) 36 | { 37 | this.param2.Value = param2; 38 | } 39 | 40 | /// 41 | /// Generates Xml containing the parameter data. 42 | /// 43 | /// To be overridden by classes that add more parameters to add theirs. 44 | /// 45 | /// An XElement containing the parameter data. 46 | protected override XElement generateCallParamsXml() 47 | { 48 | XElement paramsElement = base.generateCallParamsXml(); 49 | paramsElement.Add(makeParamElement(param2)); 50 | return paramsElement; 51 | } 52 | 53 | /// 54 | /// Fills the properties of this method call with the information contained in the XElement. 55 | /// 56 | /// The params element storing the information. 57 | /// Whether it was successful or not. 58 | protected override bool parseCallParamsXml(XElement paramsElement) 59 | { 60 | if (!parseCallParamXml(paramsElement, param2)) 61 | return false; 62 | 63 | return base.parseCallParamsXml(paramsElement); 64 | } 65 | } 66 | } -------------------------------------------------------------------------------- /XmlRpc/Types/XmlRpcDateTime.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text.RegularExpressions; 5 | using System.Xml.Linq; 6 | 7 | namespace XmlRpc.Types 8 | { 9 | /// 10 | /// Represents an XmlRpcType containing a DateTime. 11 | /// 12 | public sealed class XmlRpcDateTime : XmlRpcType 13 | { 14 | /// 15 | /// The name of Elements of this type. 16 | /// 17 | public override string ContentElementName 18 | { 19 | get { return XmlRpcElements.DateTimeElement; } 20 | } 21 | 22 | /// 23 | /// Creates a new instance of the class with Value set to the defaut value for DateTime. 24 | /// 25 | public XmlRpcDateTime() 26 | { } 27 | 28 | /// 29 | /// Creates a new instance of the class with the given value. 30 | /// 31 | /// The DateTime encapsulated by this. 32 | public XmlRpcDateTime(DateTime value) 33 | : base(value) 34 | { } 35 | 36 | /// 37 | /// Generates a value-XElement containing the information stored in this date time. 38 | /// 39 | /// The generated Xml. 40 | public override XElement GenerateXml() 41 | { 42 | string date = string.Format("{0}{1}{2}T{3}:{4}:{5}", Value.Year, Value.Month, Value.Day, Value.Hour, Value.Minute, Value.Second); 43 | 44 | return new XElement(XName.Get(XmlRpcElements.ValueElement), 45 | new XElement(XName.Get(ContentElementName), date)); 46 | } 47 | 48 | /// 49 | /// Sets the Value property with the information contained in the value-XElement. 50 | /// 51 | /// The element containing the information. 52 | /// Whether it was successful or not. 53 | protected override bool parseXml(XElement xElement) 54 | { 55 | string date = xElement.Value; //formatted according to ISO-8601 yyyymmddThh:mm:ss (the T is a literal). 56 | int yearLength = date.IndexOf('T') - 4; 57 | 58 | //Rudamentary check for correct format. 59 | if (!Regex.IsMatch(@"\d{" + yearLength + @"}[0-1]\d[0-1]\dT[0-2]\d:[0-5]\d:[0-5]\d", date)) 60 | return false; 61 | 62 | try 63 | { 64 | int year = int.Parse(date.Remove(yearLength)); 65 | int month = int.Parse(date.Remove(0, yearLength).Remove(2)); 66 | int day = int.Parse(date.Remove(0, yearLength + 2).Remove(2)); 67 | int hour = int.Parse(date.Remove(0, yearLength + 5).Remove(2)); 68 | int minute = int.Parse(date.Remove(0, yearLength + 8).Remove(2)); 69 | int second = int.Parse(date.Remove(yearLength + 11).Remove(2)); 70 | 71 | Value = new DateTime(year, month, day, hour, minute, second); 72 | 73 | return true; 74 | } 75 | catch 76 | { 77 | return false; 78 | } 79 | } 80 | } 81 | } -------------------------------------------------------------------------------- /XmlRpc/Methods/XmlRpcMethodCall-3PArams.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Xml.Linq; 5 | using XmlRpc.Types; 6 | 7 | namespace XmlRpc.Methods 8 | { 9 | /// 10 | /// Abstract base class for method calls that have three parameters and the base classes for those that have more. 11 | /// 12 | /// The XmlRpcType of the first parameter. 13 | /// The type of the first parameter value. 14 | /// The XmlRpcType of the second parameter. 15 | /// The type of the second parameter value. 16 | /// The XmlRpcType of the third parameter. 17 | /// The type of the third parameter value. 18 | /// The returned XmlRpcType. 19 | /// The type of the return value. 20 | public abstract class XmlRpcMethodCall 21 | : XmlRpcMethodCall 22 | where TParam1 : XmlRpcType, new() 23 | where TParam2 : XmlRpcType, new() 24 | where TParam3 : XmlRpcType, new() 25 | where TReturn : XmlRpcType, new() 26 | { 27 | /// 28 | /// Field for the third parameter. 29 | /// 30 | protected TParam3 param3 = new TParam3(); 31 | 32 | /// 33 | /// Creates a new instance of the 34 | /// class with the given values for the parameters. 35 | /// 36 | /// The first parameter's value. 37 | /// The second parameter's value. 38 | /// The third parameter's value. 39 | protected XmlRpcMethodCall(TParam1Base param1, TParam2Base param2, TParam3Base param3) 40 | : base(param1, param2) 41 | { 42 | this.param3.Value = param3; 43 | } 44 | 45 | /// 46 | /// Generates Xml containing the parameter data. 47 | /// 48 | /// To be overridden by classes that add more parameters to add theirs. 49 | /// 50 | /// An XElement containing the parameter data. 51 | protected override XElement generateCallParamsXml() 52 | { 53 | XElement paramsElement = base.generateCallParamsXml(); 54 | paramsElement.Add(makeParamElement(param3)); 55 | return paramsElement; 56 | } 57 | 58 | /// 59 | /// Fills the properties of this method call with the information contained in the XElement. 60 | /// 61 | /// The params element storing the information. 62 | /// Whether it was successful or not. 63 | protected override bool parseCallParamsXml(XElement paramsElement) 64 | { 65 | if (!parseCallParamXml(paramsElement, param3)) 66 | return false; 67 | 68 | return base.parseCallParamsXml(paramsElement); 69 | } 70 | } 71 | } -------------------------------------------------------------------------------- /XmlRpc/Types/XmlRpcArray.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Xml.Linq; 6 | 7 | namespace XmlRpc.Types 8 | { 9 | /// 10 | /// Represents an XmlRpcType containing an array of XmlRpcTypes that derive from TBase. 11 | /// For example for a string array, TArray would be XmlRpcString and TBase would be string. 12 | /// TBase enforces TArray. TArray has to be XmlRpcString because it derives from XmlRpcType<string> 13 | /// 14 | /// TArray[] is the Type of the Value property. 15 | /// TBase is the base type that TArray has to derive from. 16 | public class XmlRpcArray : XmlRpcType, IEnumerable 17 | where TArray : XmlRpcType, new() 18 | { 19 | /// 20 | /// The name of Elements of this type. 21 | /// 22 | public override string ContentElementName 23 | { 24 | get { return "array"; } 25 | } 26 | 27 | /// 28 | /// Creates a new instance of the class with the given value. 29 | /// 30 | /// The array encapsulated by this. 31 | public XmlRpcArray(params TArray[] value) 32 | : base(value) 33 | { } 34 | 35 | /// 36 | /// Creates a new instance of the class with a zero-length TArray array for the Value property. 37 | /// 38 | public XmlRpcArray() 39 | : base(new TArray[0]) 40 | { } 41 | 42 | /// 43 | /// Generates an XElement from the Value. Default implementation creates an XElement with the ElementName and the content from Value. 44 | /// 45 | /// The generated Xml. 46 | public override XElement GenerateXml() 47 | { 48 | return new XElement(XmlRpcElements.ValueElement, 49 | new XElement(XName.Get(ContentElementName), 50 | new XElement(XName.Get("data"), 51 | Value.Select(value => value.GenerateXml()).ToArray()))); 52 | } 53 | 54 | /// 55 | /// Returns an enumerator that iterates the Array. 56 | /// 57 | /// An enumerator that iterates the Array. 58 | public IEnumerator GetEnumerator() 59 | { 60 | return Value.Select(value => value.Value).GetEnumerator(); 61 | } 62 | 63 | IEnumerator IEnumerable.GetEnumerator() 64 | { 65 | return GetEnumerator(); 66 | } 67 | 68 | /// 69 | /// Sets the Value property with the information contained in the value-XElement. 70 | /// 71 | /// The element containing the information. 72 | /// Whether it was successful or not. 73 | protected override bool parseXml(XElement xElement) 74 | { 75 | var content = new List(); 76 | 77 | if (!xElement.Elements().First().Elements().First().Name.LocalName.Equals(XmlRpcElements.ArrayDataElement)) 78 | return false; 79 | 80 | foreach (XElement valueElement in xElement.Elements().First().Elements().First().Elements()) 81 | { 82 | var value = new TArray(); 83 | 84 | if (!value.ParseXml(valueElement)) 85 | return false; 86 | 87 | content.Add(value); 88 | } 89 | 90 | Value = content.ToArray(); 91 | 92 | return true; 93 | } 94 | } 95 | } -------------------------------------------------------------------------------- /XmlRpc/XmlRpc.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Debug 6 | AnyCPU 7 | {A2E6F931-5BB9-4786-BE35-CEBA3FB72791} 8 | Library 9 | Properties 10 | XmlRpc 11 | XmlRpc 12 | v4.0 13 | 512 14 | 15 | 16 | true 17 | full 18 | false 19 | bin\Debug\ 20 | DEBUG;TRACE 21 | prompt 22 | 4 23 | bin\Debug\XmlRpc.xml 24 | 25 | 26 | pdbonly 27 | true 28 | bin\Release\ 29 | TRACE 30 | prompt 31 | 4 32 | bin\Release\XmlRpc.xml 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 79 | -------------------------------------------------------------------------------- /XmlRpc/Methods/XmlRpcMethodCall-4Params.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Xml.Linq; 5 | using XmlRpc.Types; 6 | 7 | namespace XmlRpc.Methods 8 | { 9 | /// 10 | /// Abstract base class for method calls that have fourth parameters and the base classes for those that have more. 11 | /// 12 | /// The XmlRpcType of the first parameter. 13 | /// The type of the first parameter value. 14 | /// The XmlRpcType of the second parameter. 15 | /// The type of the second parameter value. 16 | /// The XmlRpcType of the third parameter. 17 | /// The type of the third parameter value. 18 | /// The XmlRpcType of the fourth parameter. 19 | /// The type of the fourth parameter value. 20 | /// The returned XmlRpcType. 21 | /// The type of the return value. 22 | public abstract class XmlRpcMethodCall 23 | : XmlRpcMethodCall 24 | where TParam1 : XmlRpcType, new() 25 | where TParam2 : XmlRpcType, new() 26 | where TParam3 : XmlRpcType, new() 27 | where TParam4 : XmlRpcType, new() 28 | where TReturn : XmlRpcType, new() 29 | { 30 | /// 31 | /// Field for the fourth parameter. 32 | /// 33 | protected TParam4 param4 = new TParam4(); 34 | 35 | /// 36 | /// Creates a new instance of the 37 | /// 38 | /// class with the given values for the parameters. 39 | /// 40 | /// The first parameter's value. 41 | /// The second parameter's value. 42 | /// The third parameter's value. 43 | /// The fourth parameter's value. 44 | protected XmlRpcMethodCall(TParam1Base param1, TParam2Base param2, TParam3Base param3, TParam4Base param4) 45 | : base(param1, param2, param3) 46 | { 47 | this.param4.Value = param4; 48 | } 49 | 50 | /// 51 | /// Generates Xml containing the parameter data. 52 | /// 53 | /// To be overridden by classes that add more parameters to add theirs. 54 | /// 55 | /// An XElement containing the parameter data. 56 | protected override XElement generateCallParamsXml() 57 | { 58 | XElement paramsElement = base.generateCallParamsXml(); 59 | paramsElement.Add(makeParamElement(param4)); 60 | return paramsElement; 61 | } 62 | 63 | /// 64 | /// Fills the properties of this method call with the information contained in the XElement. 65 | /// 66 | /// The params element storing the information. 67 | /// Whether it was successful or not. 68 | protected override bool parseCallParamsXml(XElement paramsElement) 69 | { 70 | if (!parseCallParamXml(paramsElement, param4)) 71 | return false; 72 | 73 | return base.parseCallParamsXml(paramsElement); 74 | } 75 | } 76 | } -------------------------------------------------------------------------------- /XmlRpc/Methods/XmlRpcMethodCall-5Params.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Xml.Linq; 5 | using XmlRpc.Types; 6 | 7 | namespace XmlRpc.Methods 8 | { 9 | /// 10 | /// Abstract base class for method calls that have fourth parameters and the base classes for those that have more. 11 | /// 12 | /// The XmlRpcType of the first parameter. 13 | /// The type of the first parameter value. 14 | /// The XmlRpcType of the second parameter. 15 | /// The type of the second parameter value. 16 | /// The XmlRpcType of the third parameter. 17 | /// The type of the third parameter value. 18 | /// The XmlRpcType of the fourth parameter. 19 | /// The type of the fourth parameter value. 20 | /// The XmlRpcType of the fifth parameter. 21 | /// The type of the fifth parameter value. 22 | /// The returned XmlRpcType. 23 | /// The type of the return value. 24 | public abstract class XmlRpcMethodCall 25 | : XmlRpcMethodCall 26 | where TParam1 : XmlRpcType, new() 27 | where TParam2 : XmlRpcType, new() 28 | where TParam3 : XmlRpcType, new() 29 | where TParam4 : XmlRpcType, new() 30 | where TParam5 : XmlRpcType, new() 31 | where TReturn : XmlRpcType, new() 32 | { 33 | /// 34 | /// Field for the fourth parameter. 35 | /// 36 | protected TParam5 param5 = new TParam5(); 37 | 38 | /// 39 | /// Creates a new instance of the 40 | /// 43 | /// class with the given values for the parameters. 44 | /// 45 | /// The first parameter's value. 46 | /// The second parameter's value. 47 | /// The third parameter's value. 48 | /// The fourth parameter's value. 49 | /// The fith parameter's value. 50 | protected XmlRpcMethodCall(TParam1Base param1, TParam2Base param2, TParam3Base param3, TParam4Base param4, TParam5Base param5) 51 | : base(param1, param2, param3, param4) 52 | { 53 | this.param5.Value = param5; 54 | } 55 | 56 | /// 57 | /// Generates Xml containing the parameter data. 58 | /// 59 | /// To be overridden by classes that add more parameters to add theirs. 60 | /// 61 | /// An XElement containing the parameter data. 62 | protected override XElement generateCallParamsXml() 63 | { 64 | XElement paramsElement = base.generateCallParamsXml(); 65 | paramsElement.Add(makeParamElement(param5)); 66 | return paramsElement; 67 | } 68 | 69 | /// 70 | /// Fills the properties of this method call with the information contained in the XElement. 71 | /// 72 | /// The params element storing the information. 73 | /// Whether it was successful or not. 74 | protected override bool parseCallParamsXml(XElement paramsElement) 75 | { 76 | if (!parseCallParamXml(paramsElement, param5)) 77 | return false; 78 | 79 | return base.parseCallParamsXml(paramsElement); 80 | } 81 | } 82 | } -------------------------------------------------------------------------------- /XmlRpc.symbols.nuspec: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | XmlRpc 5 | 2.1.1 6 | XmlRpc 7 | Banane9 8 | Banane9 9 | https://github.com/Banane9/XmlRpc/blob/master/LICENSE.md 10 | https://github.com/Banane9/XmlRpc 11 | false 12 | Library for interfacing with a server using XmlRpc 13 | Library for interfacing with a server using XmlRpc. 14 | Fixed derpy bug with MethodCall ParseResponseXml. 15 | en 16 | xmlrpc xml remote server function web request control 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | -------------------------------------------------------------------------------- /XmlRpc/Types/XmlRpcType.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Xml.Linq; 5 | 6 | namespace XmlRpc.Types 7 | { 8 | /// 9 | /// Abstract base class for all XmlRpcTypes. 10 | /// 11 | /// The Type of the Value property. 12 | public abstract class XmlRpcType 13 | { 14 | /// 15 | /// The name of value content elements for this XmlRpc type. 16 | /// 17 | public abstract string ContentElementName { get; } 18 | 19 | /// 20 | /// Gets or sets the Value contained by this XmlRpcType. 21 | /// 22 | public TValue Value { get; set; } 23 | 24 | /// 25 | /// Creates a new instance of the class with Value set to the default value for TValue. 26 | /// 27 | protected XmlRpcType() 28 | { 29 | Value = default(TValue); 30 | } 31 | 32 | /// 33 | /// Creates a new instance of the class with the given value. 34 | /// 35 | /// The value. 36 | protected XmlRpcType(TValue value) 37 | { 38 | Value = value; 39 | } 40 | 41 | /// 42 | /// Generates a value-XElement containing the information stored in this XmlRpc type. 43 | /// 44 | /// Default implementation creates an XElement with the ContentElementName and the content from Value, and wraps it in a value element. 45 | /// 46 | /// The generated Xml. 47 | public virtual XElement GenerateXml() 48 | { 49 | return new XElement(XName.Get(XmlRpcElements.ValueElement), 50 | new XElement(XName.Get(ContentElementName), Value)); 51 | } 52 | 53 | /// 54 | /// Sets the Value property with the information contained in the value-XElement. 55 | /// 56 | /// The element containing the information. 57 | /// Whether it was successful or not. 58 | public bool ParseXml(XElement xElement) 59 | { 60 | if (!isValueElement(xElement) || !hasValueCorrectContent(xElement)) 61 | return false; 62 | 63 | return parseXml(xElement); 64 | } 65 | 66 | /// 67 | /// Returns a string representation of the Type. 68 | /// 69 | /// A string representation of the Type. 70 | public override string ToString() 71 | { 72 | return GenerateXml().ToString(); 73 | } 74 | 75 | /// 76 | /// Checks whether the given XElement has the local name corresponding to a value element. 77 | /// 78 | /// The element to check. 79 | /// Whether it has the correct local name. 80 | protected static bool isValueElement(XElement xElement) 81 | { 82 | return xElement.Name.LocalName.Equals(XmlRpcElements.ValueElement); 83 | } 84 | 85 | /// 86 | /// Checks whether the value-XElement has content fitting with this XmlRpc type. 87 | /// 88 | /// Can be overridden if a single child element with the correct name is not the desired check. 89 | /// Validity of the XElement will have already been verified. 90 | /// 91 | /// The element to check. 92 | /// Whether it has fitting content or not. 93 | protected virtual bool hasValueCorrectContent(XElement xElement) 94 | { 95 | return (xElement.HasElements && xElement.Elements().Count() == 1 && xElement.Elements().First().Name.LocalName.Equals(ContentElementName)) 96 | || (!xElement.HasElements && !xElement.IsEmpty); 97 | } 98 | 99 | /// 100 | /// Sets the Value property with the information contained in the value-XElement. 101 | /// 102 | /// Gets called by the ParseXml method to do the actual parsing. Validity of the XElement will have already been verified. 103 | /// 104 | /// The element containing the information. 105 | /// Whether it was successful or not. 106 | protected abstract bool parseXml(XElement xElement); 107 | } 108 | } -------------------------------------------------------------------------------- /XmlRpc.Tests/XmlRpc.Tests.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Debug 5 | AnyCPU 6 | {C8034D5C-53AD-4096-B1E3-421155647A82} 7 | Library 8 | Properties 9 | XmlRpc.Tests 10 | XmlRpc.Tests 11 | v4.0 12 | 512 13 | {3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} 14 | 10.0 15 | $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) 16 | $(ProgramFiles)\Common Files\microsoft shared\VSTT\$(VisualStudioVersion)\UITestExtensionPackages 17 | False 18 | UnitTest 19 | 20 | 21 | true 22 | full 23 | false 24 | bin\Debug\ 25 | DEBUG;TRACE 26 | prompt 27 | 4 28 | 29 | 30 | pdbonly 31 | true 32 | bin\Release\ 33 | TRACE 34 | prompt 35 | 4 36 | 37 | 38 | 39 | 40 | 3.5 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | {a2e6f931-5bb9-4786-be35-ceba3fb72791} 65 | XmlRpc 66 | 67 | 68 | 69 | 70 | 71 | 72 | False 73 | 74 | 75 | False 76 | 77 | 78 | False 79 | 80 | 81 | False 82 | 83 | 84 | 85 | 86 | 87 | 88 | 95 | -------------------------------------------------------------------------------- /XmlRpc/Types/Structs/BaseStruct.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Xml.Linq; 5 | 6 | namespace XmlRpc.Types.Structs 7 | { 8 | /// 9 | /// Abstract base class for all xml rpc structs. 10 | /// 11 | public abstract class BaseStruct 12 | { 13 | /// 14 | /// Generates an XElement storing the information in this struct. 15 | /// 16 | /// The generated XElement. 17 | public abstract XElement GenerateXml(); 18 | 19 | /// 20 | /// Fills the properties of this struct with the information contained in the XElement. 21 | /// 22 | /// The struct element storing the information. 23 | /// Whether it was successful or not. 24 | public bool ParseXml(XElement xElement) 25 | { 26 | isStructElement(xElement); 27 | 28 | foreach (XElement member in xElement.Elements()) 29 | { 30 | if (!isValidMemberElement(member)) 31 | return false; 32 | 33 | if (!parseXml(member)) 34 | return false; 35 | } 36 | 37 | return true; 38 | } 39 | 40 | /// 41 | /// Returns a string representation of the struct. 42 | /// 43 | /// A string representation of the struct. 44 | public override string ToString() 45 | { 46 | return GenerateXml().ToString(); 47 | } 48 | 49 | /// 50 | /// Gets the name of the member from a member element. 51 | /// 52 | /// The member element to get the name from. 53 | /// The name of the member. 54 | protected static string getMemberName(XElement member) 55 | { 56 | isValidMemberElement(member); 57 | 58 | return member.Element(XName.Get(XmlRpcElements.StructMemberNameElement)).Value; 59 | } 60 | 61 | /// 62 | /// Gets the value element of a member from a member element. 63 | /// 64 | /// The member element to get the value from. 65 | /// The value element of the member or null if not a valid member. 66 | protected static XElement getMemberValueElement(XElement member) 67 | { 68 | return isValidMemberElement(member) ? member.Element(XName.Get(XmlRpcElements.ValueElement)) : null; 69 | } 70 | 71 | /// 72 | /// Checks whether the given XElement has the local name corresponding to a struct element. 73 | /// 74 | /// The element to check. 75 | /// Whether it has the correct local name. 76 | protected static bool isStructElement(XElement xElement) 77 | { 78 | return xElement.Name.LocalName.Equals(XmlRpcElements.StructElement); 79 | } 80 | 81 | /// 82 | /// Checks if an element is a valid member element. 83 | /// 84 | /// The element to check. 85 | protected static bool isValidMemberElement(XElement member) 86 | { 87 | return member.Name.LocalName.Equals(XmlRpcElements.StructMemberElement) 88 | && member.HasElements 89 | && member.Elements(XName.Get(XmlRpcElements.StructMemberNameElement)).Any() 90 | && member.Elements(XName.Get(XmlRpcElements.ValueElement)).Any(); 91 | } 92 | 93 | /// 94 | /// Creates a member element from the name and the value content element. 95 | /// 96 | /// The name of the member. 97 | /// The value XmlRpcType. 98 | /// The XmlRpType's base type. 99 | /// The member element with the given name and value content. 100 | protected static XElement makeMemberElement(string name, XmlRpcType value) 101 | { 102 | return new XElement(XName.Get(XmlRpcElements.StructMemberElement), makeNameXElement(name), value.GenerateXml()); 103 | } 104 | 105 | /// 106 | /// Fills the property of this struct that has the correct name with the information contained in the member-XElement. 107 | /// 108 | /// The member element storing the information. 109 | /// Whether it was successful or not. 110 | protected abstract bool parseXml(XElement member); 111 | 112 | /// 113 | /// Creates a name element with the given content. 114 | /// 115 | /// The value of the name element. 116 | /// The name element with the given value. 117 | private static XElement makeNameXElement(string name) 118 | { 119 | return new XElement(XName.Get(XmlRpcElements.StructMemberNameElement), name); 120 | } 121 | } 122 | } -------------------------------------------------------------------------------- /XmlRpc/Testing/MethodCalls.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Reflection; 5 | using XmlRpc.Methods; 6 | 7 | namespace XmlRpc.Testing 8 | { 9 | /// 10 | /// Contains convenience methods to test MethodCalls. 11 | /// 12 | public static class MethodCalls 13 | { 14 | /// 15 | /// Takes an Assembly and an action that is performed on the result of the round-trip check, and checks every derivative 16 | /// that doesn't have generic parameters and isn't abstract for round-trip safety. 17 | /// 18 | /// This assumes that all the XmlRpcType<> that are supposed to be checked, are private fields of the class, and are the only things that are serialized. 19 | /// 20 | /// The assemblies to check the types in. 21 | /// 22 | /// The action that is performed on the results of the round-trip check. 23 | /// First parameter is whether it was successful, second is the Type of the tested MethodCall, third is the reason it failed (if it did). 24 | /// 25 | public static void AreRoundTripSave(Action assertIsTrue, params Assembly[] assemblies) 26 | { 27 | foreach (var assembly in assemblies) 28 | { 29 | var methodCallTypes = 30 | assembly.GetExportedTypes().Where(t => t.InheritsOrImplements(typeof(XmlRpcMethodCall<,>)) && !t.IsAbstract && !t.ContainsGenericParameters); 31 | foreach (var methodCallType in methodCallTypes) 32 | { 33 | var filledMethod = fillMethod(methodCallType); 34 | var generatedCallXml = filledMethod.GetType().GetMethod("GenerateCallXml").Invoke(filledMethod, new object[0]); 35 | var generatedCallXmlString = generatedCallXml.ToString(); 36 | var generatedResponseXml = filledMethod.GetType().GetMethod("GenerateResponseXml").Invoke(filledMethod, new object[0]); 37 | 38 | var methodInstance = createMethodInstance(methodCallType); 39 | 40 | if (!(bool)methodInstance.GetType().GetMethod("ParseCallXml").Invoke(methodInstance, new[] { generatedCallXml })) 41 | assertIsTrue(false, methodCallType, "Failed Call Parsing."); 42 | 43 | if (!(bool)methodInstance.GetType().GetMethod("ParseResponseXml").Invoke(methodInstance, new[] { generatedResponseXml })) 44 | assertIsTrue(false, methodCallType, "Failed Response Parsing"); 45 | 46 | var generatedCallAfterParsing = methodInstance.GetType().GetMethod("GenerateCallXml").Invoke(methodInstance, new object[0]); 47 | var generatedResponseAfterParsing = methodInstance.GetType().GetMethod("GenerateResponseXml").Invoke(methodInstance, new object[0]); 48 | 49 | assertIsTrue( 50 | generatedCallXmlString.Equals(generatedCallAfterParsing.ToString()) 51 | && generatedResponseXml.ToString().Equals(generatedResponseAfterParsing.ToString()), 52 | methodCallType, "Failed Equality Check"); 53 | } 54 | } 55 | } 56 | 57 | private static object createMethodInstance(Type type) 58 | { 59 | var constructor = type.GetConstructors().First(); 60 | var parameters = constructor.GetParameters().Select(parameter => 61 | { 62 | if (parameter.ParameterType.IsArray) 63 | return Array.CreateInstance(parameter.ParameterType.GetElementType(), 0); 64 | 65 | if (parameter.ParameterType.InheritsOrImplements(typeof(IEnumerable<>)) 66 | && parameter.ParameterType != typeof(string)) 67 | { 68 | return typeof(Enumerable).GetMethod("Empty") 69 | .MakeGenericMethod(parameter.ParameterType.GetGenericArguments()[0]) 70 | .Invoke(null, new object[0]); 71 | } 72 | 73 | return parameter.ParameterType.GetDefaultValue(); 74 | }).ToArray(); 75 | 76 | return Activator.CreateInstance(type, parameters); 77 | } 78 | 79 | private static object fillMethod(Type methodCallType) 80 | { 81 | var methodInstance = createMethodInstance(methodCallType); 82 | 83 | var contentFields = Structs.getContentFields(methodCallType); 84 | 85 | foreach (var contentField in contentFields) 86 | { 87 | var contentFieldValue = contentField.GetValue(methodInstance); 88 | var contentFieldValueValue = contentFieldValue.GetType().GetProperty("Value"); 89 | var valueValueType = contentFieldValueValue.PropertyType; 90 | var value = Structs.resolveXmlRpcType(valueValueType); 91 | 92 | contentFieldValueValue.GetSetMethod().Invoke(contentFieldValue, new[] { value }); 93 | contentField.SetValue(methodInstance, contentFieldValue); 94 | } 95 | 96 | return methodInstance; 97 | } 98 | } 99 | } -------------------------------------------------------------------------------- /XmlRpc/Testing/Structs.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Reflection; 5 | using XmlRpc.Types; 6 | using XmlRpc.Types.Structs; 7 | 8 | namespace XmlRpc.Testing 9 | { 10 | /// 11 | /// Contains convenience methods to test Structs. 12 | /// 13 | public static class Structs 14 | { 15 | /// 16 | /// Takes an Assembly and an action that is performed on the result of the round-trip check, and checks every derivative 17 | /// that doesn't have generic parameters and isn't abstract for round-trip safety. 18 | /// 19 | /// This assumes that all the XmlRpcType<> that are supposed to be checked, are private fields of the class, and are the only things that is serialized. 20 | /// 21 | /// The assemblies to check the types in. 22 | /// 23 | /// The action that is performed on the results of the round-trip check. 24 | /// First parameter is whether it was successful, second is the Type of the tested Struct, third is the reason it failed (if it did). 25 | /// 26 | public static void AreRoundTripSave(Action assertIsTrue, params Assembly[] assemblies) 27 | { 28 | foreach (var assembly in assemblies) 29 | { 30 | var structTypes = assembly.GetExportedTypes().Where(t => t.InheritsOrImplements(typeof(BaseStruct)) && !t.IsAbstract && !t.ContainsGenericParameters); 31 | foreach (var structType in structTypes) 32 | { 33 | var filledStruct = (BaseStruct)fillStruct(structType); 34 | var generatedXml = filledStruct.GenerateXml(); 35 | 36 | var structInstance = (BaseStruct)Activator.CreateInstance(structType); 37 | if (!structInstance.ParseXml(generatedXml)) 38 | assertIsTrue(false, structType, "Failed Parsing."); 39 | 40 | assertIsTrue(generatedXml.ToString().Equals(structInstance.GenerateXml().ToString()), structType, "Failed Equality Check"); 41 | } 42 | } 43 | } 44 | 45 | internal static object fillStruct(Type structType) 46 | { 47 | var structInstance = Activator.CreateInstance(structType); 48 | var contentFields = getContentFields(structType); 49 | 50 | foreach (var contentField in contentFields) 51 | { 52 | var contentFieldValue = contentField.GetValue(structInstance); 53 | var contentFieldValueValue = contentFieldValue.GetType().GetProperty("Value"); 54 | var valueValueType = contentFieldValueValue.PropertyType; 55 | var value = resolveXmlRpcType(valueValueType); 56 | 57 | contentFieldValueValue.GetSetMethod().Invoke(contentFieldValue, new[] { value }); 58 | contentField.SetValue(structInstance, contentFieldValue); 59 | } 60 | 61 | return structInstance; 62 | } 63 | 64 | internal static IEnumerable getContentFields(Type type) 65 | { 66 | foreach (var f in type.GetFields(BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public) 67 | .Where(field => field.FieldType.InheritsOrImplements(typeof(XmlRpcType<>)))) 68 | yield return f; 69 | 70 | if (type.BaseType == typeof(object)) 71 | yield break; 72 | 73 | foreach (var f in getContentFields(type.BaseType)) 74 | yield return f; 75 | } 76 | 77 | internal static object resolveXmlRpcType(Type type) 78 | { 79 | var value = new object(); 80 | 81 | if (type == typeof(string)) 82 | value = TestValues.TString; 83 | else if (type == typeof(int)) 84 | value = TestValues.TInt; 85 | else if (type == typeof(double)) 86 | value = TestValues.TDouble; 87 | else if (type == typeof(bool)) 88 | value = TestValues.TBool; 89 | else if (type == typeof(DateTime)) 90 | value = TestValues.TDateTime; 91 | else if (type == typeof(byte[])) // Base64 92 | value = TestValues.TByteArray; 93 | else if (type.InheritsOrImplements(typeof(BaseStruct))) 94 | value = fillStruct(type); 95 | else if (type.HasElementType && type.GetElementType().InheritsOrImplements(typeof(XmlRpcType<>))) 96 | { 97 | var genericList = Activator.CreateInstance(typeof(List<>).MakeGenericType(type.GetElementType())); 98 | 99 | var capsuledType = Activator.CreateInstance(type.GetElementType(), 100 | type.GetElementType().InheritsOrImplements(typeof(XmlRpcStruct<>)) 101 | ? fillStruct(type.GetElementType().GetGenericArguments()[0]) 102 | : resolveXmlRpcType(type.GetElementType().GetProperty("Value").PropertyType)); 103 | 104 | genericList.GetType().GetMethod("Add").Invoke(genericList, new[] { capsuledType }); 105 | value = typeof(Enumerable).GetMethod("ToArray").MakeGenericMethod(type.GetElementType()).Invoke(null, new[] { genericList }); 106 | } 107 | 108 | return value; 109 | } 110 | 111 | private static class TestValues 112 | { 113 | public static readonly bool TBool = true; 114 | public static readonly byte[] TByteArray = { 4, 2 }; 115 | public static readonly DateTime TDateTime = new DateTime(1970, 1, 1, 0, 0, 1); 116 | public static readonly double TDouble = 42; 117 | public static readonly int TInt = 42; 118 | public static readonly string TString = "Test"; 119 | } 120 | } 121 | } -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | XmlRpc 2 | ====== 3 | 4 | Implementation of the [XmlRpc Spec](http://xmlrpc.scripting.com/spec.html). Originally part of the ManiaNet project. 5 | 6 | -------------------------------------------------------------------------------------------------------------------------------- 7 | 8 | ## Usage ## 9 | 10 | For a real-world usage example, check [here](https://github.com/ManiaDotNet/DedicatedServer/tree/master/ManiaNet.DedicatedServer/XmlRpc) and [here](https://github.com/ManiaDotNet/ServerController/blob/master/ManiaNet.DedicatedServer.Controller/ServerController.cs#L146). 11 | 12 | -------------------------------------------------------------------------------------------------------------------------------- 13 | 14 | ### Method Calls ### 15 | 16 | ##### Definition ##### 17 | 18 | ``` CSharp 19 | using XmlRpc.Methods; 20 | using XmlRpc.Types; 21 | 22 | /// 23 | /// Represents a call to the AddGuest method. 24 | /// Simply derive from XmlRpcMethodCall<> and pass it the generic paramameters corresponding to your method. 25 | /// This works like Func<>, in that the last parameter pair is the return value and before that, you have the arguments. 26 | /// 27 | public sealed class AddGuest : XmlRpcMethodCall 28 | { 29 | /// 30 | /// Gets or sets the login that will be added to the guestlist. 31 | /// For convenience, you should provide properties to change the parameter values (for calls). 32 | /// For callback methods, a readonly property is better, so that one consumer can't modify the values for others. 33 | /// 34 | public string Login 35 | { 36 | get { return param1.Value; } 37 | set { param1.Value = value; } 38 | } 39 | 40 | /// 41 | /// Gets the name of the method this call is for. 42 | /// This has to be overridden and will be the name inside the `` tag. 43 | /// 44 | public override string MethodName 45 | { 46 | get { return "AddGuest"; } 47 | } 48 | 49 | /// 50 | /// Creates a new instance of the class for the given login. 51 | /// The MethodCall has to be constructed using the base's constructor. 52 | /// It will automatically set the parameter fields to the given values. 53 | /// For callback methods, there should also be a parameterless constructor to simplify usage. 54 | /// 55 | /// The login that will be added to the guestlist. 56 | public AddGuest(string login) 57 | : base(login) 58 | { } 59 | } 60 | ``` 61 | 62 | ##### Usage ##### 63 | 64 | ``` CSharp 65 | var addGuest = new AddGuest("banane9"); 66 | 67 | // Assuming xmlRpcClient implements IXmlRpcClient, 68 | // this will send the Xml representing the MethodCall to the server. 69 | uint handle = xmlRpcClient.SendRequest(addGuest.GenerateXml().ToString()); 70 | ``` 71 | 72 | One then has to wait for the MethodResponse event with the matching handle to fire, and that will contain the response to that method. 73 | 74 | For an implementation of a CallMethod<> function that does this and automatically has the function parse the response, check [here](https://github.com/ManiaDotNet/ServerController/blob/master/ManiaNet.DedicatedServer.Controller/ServerController.cs#L146) on the ManiaNet project again. 75 | 76 | -------------------------------------------------------------------------------------------------------------------------------- 77 | 78 | ### Custom Structs ### 79 | 80 | ##### Definition ##### 81 | 82 | This is the content of the [FaultStruct.cs](https://github.com/Banane9/XmlRpc/blob/master/XmlRpc/Types/Structs/FaultStruct.cs) file with some additional comments. 83 | 84 | 85 | ``` CSharp 86 | /// 87 | /// Gets the struct returned when a method call has a fault. 88 | /// Simply derive from BaseStruct. 89 | /// 90 | public sealed class FaultStruct : BaseStruct 91 | { 92 | // Add some private fields for your content 93 | 94 | /// 95 | /// Backing field for the FaultCode property. 96 | /// 97 | private XmlRpcInt faultCode = new XmlRpcInt(); 98 | 99 | /// 100 | /// Backing field for the FaultString property. 101 | /// 102 | private XmlRpcString faultString = new XmlRpcString(); 103 | 104 | // And some properties to get the values for returned structs; 105 | // or get/set them for call-parameter structs. 106 | 107 | /// 108 | /// Gets the fault code. 109 | /// 110 | public int FaultCode 111 | { 112 | get { return faultCode.Value; } 113 | } 114 | 115 | /// 116 | /// Gets the description of the fault. 117 | /// 118 | public string FaultString 119 | { 120 | get { return faultString.Value; } 121 | } 122 | 123 | /// 124 | /// Generates an XElement storing the information in this struct. 125 | /// The order of the members doesn't matter, but casing in the name does. 126 | /// 127 | /// The generated XElement. 128 | public override XElement GenerateXml() 129 | { 130 | return new XElement(XName.Get(XmlRpcElements.StructElement), 131 | makeMemberElement("faultCode", faultCode), 132 | makeMemberElement("faultString", faultString)); 133 | } 134 | 135 | /// 136 | /// Fills the property of this struct that has the correct name with the information contained in the member-XElement. 137 | /// This method will be called for every member element when parsing the Xml. 138 | /// 139 | /// The member element storing the information. 140 | /// Whether it was successful or not. 141 | protected override bool parseXml(XElement member) 142 | { 143 | XElement value = getMemberValueElement(member); 144 | 145 | switch (getMemberName(member)) 146 | { 147 | case "faultCode": 148 | if (!faultCode.ParseXml(value)) 149 | return false; 150 | break; 151 | 152 | 153 | case "faultString": 154 | if (!faultString.ParseXml(value)) 155 | return false; 156 | break; 157 | 158 | default: 159 | return false; 160 | } 161 | 162 | return true; 163 | } 164 | } 165 | 166 | ``` 167 | 168 | For convenience, there's a [.snippet file](https://github.com/Banane9/XmlRpc/blob/master/XmlRpc/Types/Structs/ParseStruct.snippet) for the scaffolding of the `parseXml` method. 169 | 170 | ##### Usage ##### 171 | 172 | For usage, the `BaseStruct`-derived Type has to be wrapped in `XmlRpcStruct<>`. 173 | 174 | ``` CSharp 175 | // MethodCall definition 176 | public sealed class ReturnFaultStruct : MethodCall, FaultStruct> 177 | 178 | // Field (for example in another struct). 179 | private XmlRpcStruct fault = new XmlRpcStruct(); 180 | ``` 181 | 182 | -------------------------------------------------------------------------------------------------------------------------------- 183 | 184 | ### Types ### 185 | 186 | You shouldn't have to define any of those, as all from the XmlRpc spec are included. But in case your application has to deal with custom ones, simply follow the implementation of the spec ones, [here](https://github.com/Banane9/XmlRpc/tree/master/XmlRpc/Types). 187 | 188 | -------------------------------------------------------------------------------------------------------------------------------- 189 | 190 | ## License ## 191 | 192 | ##### [LGPL V2.1](https://github.com/Banane9/XmlRpc/tree/master/LICENSE.md) ##### 193 | -------------------------------------------------------------------------------- /XmlRpc/Methods/XmlRpcMethodCall-0Params.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Xml.Linq; 5 | using XmlRpc.Annotations; 6 | using XmlRpc.Types; 7 | using XmlRpc.Types.Structs; 8 | 9 | namespace XmlRpc.Methods 10 | { 11 | /// 12 | /// Abstract base class for method calls that don't have parameters and the base classes for those that do. 13 | /// 14 | /// The returned XmlRpcType. 15 | /// The type of the return value. 16 | public abstract class XmlRpcMethodCall 17 | where TReturn : XmlRpcType, new() 18 | { 19 | /// 20 | /// Backing field for the Fault property. 21 | /// 22 | private readonly XmlRpcStruct fault = new XmlRpcStruct(); 23 | 24 | /// 25 | /// Backing field for the Returned property. 26 | /// 27 | private readonly TReturn returned = new TReturn(); 28 | 29 | /// 30 | /// Gets the fault information. 31 | /// 32 | [NotNull, UsedImplicitly] 33 | public FaultStruct Fault 34 | { 35 | get { return fault.Value; } 36 | } 37 | 38 | /// 39 | /// Gets whether there was a fault with the method call or not. 40 | /// 41 | public bool HadFault { get; private set; } 42 | 43 | /// 44 | /// Gets the name of the method this call is for. 45 | /// 46 | public abstract string MethodName { get; } 47 | 48 | /// 49 | /// Gets the return value of the call. 50 | /// 51 | [NotNull, UsedImplicitly] 52 | public TReturnBase ReturnValue 53 | { 54 | get { return returned.Value; } 55 | } 56 | 57 | /// 58 | /// Generates the Xml to send to the server for executing the method call. 59 | /// 60 | /// An XElement containing the method call. 61 | public XElement GenerateCallXml() 62 | { 63 | return new XElement(XName.Get(XmlRpcElements.MethodCallElement), 64 | new XElement(XName.Get(XmlRpcElements.MethodNameElement), MethodName), 65 | generateCallParamsXml()); 66 | } 67 | 68 | /// 69 | /// Generates an XElement storing the information for the method response. 70 | /// 71 | /// The generated XElement. 72 | public XElement GenerateResponseXml() 73 | { 74 | return new XElement(XName.Get(XmlRpcElements.MethodResponseElement), 75 | HadFault 76 | ? new XElement(XName.Get(XmlRpcElements.FaultElement), fault.GenerateXml()) 77 | : new XElement(XName.Get(XmlRpcElements.ParamsElement), 78 | new XElement(XName.Get(XmlRpcElements.ParamElement), 79 | returned.GenerateXml()))); 80 | } 81 | 82 | /// 83 | /// Fills the parameters of this method call with the information contained in the XElement. 84 | /// 85 | /// The method call element storing the information. 86 | /// Whether it was successful or not. 87 | [UsedImplicitly] 88 | public bool ParseCallXml(XElement xElement) 89 | { 90 | if (!xElement.Name.LocalName.Equals(XmlRpcElements.MethodCallElement) 91 | || !xElement.HasElements 92 | || xElement.Elements().Count() != 2) 93 | return false; 94 | 95 | XElement methodNameElement = xElement.Elements().First(); 96 | 97 | if (!methodNameElement.Name.LocalName.Equals(XmlRpcElements.MethodNameElement) 98 | || methodNameElement.IsEmpty 99 | || !methodNameElement.Value.Equals(MethodName)) 100 | return false; 101 | 102 | methodNameElement.Remove(); 103 | XElement paramsElement = xElement.Elements().First(); 104 | 105 | if (!paramsElement.Name.LocalName.Equals(XmlRpcElements.ParamsElement)) 106 | return false; 107 | 108 | XElement[] reversedParams = paramsElement.Elements().Reverse().ToArray(); 109 | paramsElement.RemoveAll(); 110 | paramsElement.Add(new object[] { reversedParams }); 111 | 112 | return parseCallParamsXml(paramsElement); 113 | } 114 | 115 | /// 116 | /// Fills the Returned or Fault information from the given method response data. 117 | /// 118 | /// This makes IsCompleted true and the method call has to be Reset before using this again. 119 | /// 120 | /// The XElement containing the method response. 121 | /// Whether it was successful or not. 122 | public bool ParseResponseXml(XElement xElement) 123 | { 124 | if (!xElement.Name.LocalName.Equals(XmlRpcElements.MethodResponseElement) || xElement.Elements().Count() != 1) 125 | return false; 126 | 127 | XElement child = xElement.Elements().First(); 128 | 129 | if (child.Elements().Count() != 1 || (!child.Name.LocalName.Equals(XmlRpcElements.ParamsElement) && !child.Name.LocalName.Equals(XmlRpcElements.FaultElement))) 130 | return false; 131 | 132 | XElement value = child.Elements().First().Elements().First(); 133 | 134 | if (value == null) 135 | return false; 136 | 137 | switch (child.Name.LocalName) 138 | { 139 | case XmlRpcElements.ParamsElement: 140 | if (!returned.ParseXml(value)) 141 | return false; 142 | HadFault = false; 143 | break; 144 | 145 | case XmlRpcElements.FaultElement: 146 | if (!fault.ParseXml(value)) 147 | return false; 148 | HadFault = true; 149 | break; 150 | 151 | default: 152 | return false; 153 | } 154 | 155 | return true; 156 | } 157 | 158 | /// 159 | /// Returns a string representation of the method call. 160 | /// 161 | /// A string representing the method call. 162 | public override string ToString() 163 | { 164 | return GenerateCallXml().ToString(); 165 | } 166 | 167 | /// 168 | /// Checks whether a given XElement is a valid param element. 169 | /// 170 | /// The element to check. 171 | /// Whether the given XElement is a valid param element. 172 | protected static bool isValidParamElement(XElement xElement) 173 | { 174 | return xElement != null 175 | && xElement.Name.LocalName.Equals(XmlRpcElements.ParamElement) 176 | && xElement.Elements().Count() == 1 177 | && xElement.Elements().First().Name.LocalName.Equals(XmlRpcElements.ValueElement); 178 | } 179 | 180 | /// 181 | /// Creates a param-Element with the given XmlRpcType's value as content. 182 | /// 183 | /// The type of the value. 184 | /// The XmlRpcType to be wrapped. 185 | /// A param-Element containing the value as content. 186 | protected static XElement makeParamElement(XmlRpcType value) 187 | { 188 | return new XElement(XName.Get(XmlRpcElements.ParamElement), value.GenerateXml()); 189 | } 190 | 191 | /// 192 | /// Fills the parameter properties of this method call with the information contained in the XElement. 193 | /// 194 | /// The XmlRpcType of the parameter. 195 | /// The XElement containing the information. 196 | /// The parameter. 197 | /// Whether it was successful or not. 198 | protected static bool parseCallParamXml(XElement paramsElement, XmlRpcType param) 199 | { 200 | if (!paramsElement.HasElements) 201 | return false; 202 | 203 | XElement paramElement = paramsElement.Elements().First(); 204 | 205 | if (!isValidParamElement(paramElement)) 206 | return false; 207 | 208 | paramElement.Remove(); 209 | 210 | return param.ParseXml(paramElement.Elements().First()); 211 | } 212 | 213 | /// 214 | /// Generates Xml containing the call parameter data. 215 | /// 216 | /// To be overridden by classes that add more call parameters to add theirs. 217 | /// 218 | /// An XElement containing the call parameter data. 219 | protected virtual XElement generateCallParamsXml() 220 | { 221 | return new XElement(XName.Get(XmlRpcElements.ParamsElement)); 222 | } 223 | 224 | /// 225 | /// Fills the parameter properties of this method call with the information contained in the XElement. 226 | /// 227 | /// The params element storing the information. 228 | /// Whether it was successful or not. 229 | protected virtual bool parseCallParamsXml(XElement paramsElement) 230 | { 231 | return !paramsElement.HasElements; 232 | } 233 | } 234 | } -------------------------------------------------------------------------------- /XmlRpc/Properties/Annotations.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | #pragma warning disable 1591 4 | // ReSharper disable UnusedMember.Global 5 | // ReSharper disable UnusedParameter.Local 6 | // ReSharper disable MemberCanBePrivate.Global 7 | // ReSharper disable UnusedAutoPropertyAccessor.Global 8 | // ReSharper disable IntroduceOptionalParameters.Global 9 | // ReSharper disable MemberCanBeProtected.Global 10 | // ReSharper disable InconsistentNaming 11 | 12 | namespace XmlRpc.Annotations 13 | { 14 | /// 15 | /// Indicates that the value of the marked element could be null sometimes, 16 | /// so the check for null is necessary before its usage 17 | /// 18 | /// 19 | /// [CanBeNull] public object Test() { return null; } 20 | /// public void UseTest() { 21 | /// var p = Test(); 22 | /// var s = p.ToString(); // Warning: Possible 'System.NullReferenceException' 23 | /// } 24 | /// 25 | [AttributeUsage( 26 | AttributeTargets.Method | AttributeTargets.Parameter | 27 | AttributeTargets.Property | AttributeTargets.Delegate | 28 | AttributeTargets.Field, AllowMultiple = false, Inherited = true)] 29 | public sealed class CanBeNullAttribute : Attribute { } 30 | 31 | /// 32 | /// Indicates that the value of the marked element could never be null 33 | /// 34 | /// 35 | /// [NotNull] public object Foo() { 36 | /// return null; // Warning: Possible 'null' assignment 37 | /// } 38 | /// 39 | [AttributeUsage( 40 | AttributeTargets.Method | AttributeTargets.Parameter | 41 | AttributeTargets.Property | AttributeTargets.Delegate | 42 | AttributeTargets.Field, AllowMultiple = false, Inherited = true)] 43 | public sealed class NotNullAttribute : Attribute { } 44 | 45 | /// 46 | /// Indicates that the marked method builds string by format pattern and (optional) arguments. 47 | /// Parameter, which contains format string, should be given in constructor. The format string 48 | /// should be in -like form 49 | /// 50 | /// 51 | /// [StringFormatMethod("message")] 52 | /// public void ShowError(string message, params object[] args) { /* do something */ } 53 | /// public void Foo() { 54 | /// ShowError("Failed: {0}"); // Warning: Non-existing argument in format string 55 | /// } 56 | /// 57 | [AttributeUsage( 58 | AttributeTargets.Constructor | AttributeTargets.Method, 59 | AllowMultiple = false, Inherited = true)] 60 | public sealed class StringFormatMethodAttribute : Attribute 61 | { 62 | /// 63 | /// Specifies which parameter of an annotated method should be treated as format-string 64 | /// 65 | public StringFormatMethodAttribute(string formatParameterName) 66 | { 67 | FormatParameterName = formatParameterName; 68 | } 69 | 70 | public string FormatParameterName { get; private set; } 71 | } 72 | 73 | /// 74 | /// Indicates that the function argument should be string literal and match one 75 | /// of the parameters of the caller function. For example, ReSharper annotates 76 | /// the parameter of 77 | /// 78 | /// 79 | /// public void Foo(string param) { 80 | /// if (param == null) 81 | /// throw new ArgumentNullException("par"); // Warning: Cannot resolve symbol 82 | /// } 83 | /// 84 | [AttributeUsage(AttributeTargets.Parameter, AllowMultiple = false, Inherited = true)] 85 | public sealed class InvokerParameterNameAttribute : Attribute { } 86 | 87 | /// 88 | /// Indicates that the method is contained in a type that implements 89 | /// interface 90 | /// and this method is used to notify that some property value changed 91 | /// 92 | /// 93 | /// The method should be non-static and conform to one of the supported signatures: 94 | /// 95 | /// NotifyChanged(string) 96 | /// NotifyChanged(params string[]) 97 | /// NotifyChanged{T}(Expression{Func{T}}) 98 | /// NotifyChanged{T,U}(Expression{Func{T,U}}) 99 | /// SetProperty{T}(ref T, T, string) 100 | /// 101 | /// 102 | /// 103 | /// public class Foo : INotifyPropertyChanged { 104 | /// public event PropertyChangedEventHandler PropertyChanged; 105 | /// [NotifyPropertyChangedInvocator] 106 | /// protected virtual void NotifyChanged(string propertyName) { ... } 107 | /// 108 | /// private string _name; 109 | /// public string Name { 110 | /// get { return _name; } 111 | /// set { _name = value; NotifyChanged("LastName"); /* Warning */ } 112 | /// } 113 | /// } 114 | /// 115 | /// Examples of generated notifications: 116 | /// 117 | /// NotifyChanged("Property") 118 | /// NotifyChanged(() => Property) 119 | /// NotifyChanged((VM x) => x.Property) 120 | /// SetProperty(ref myField, value, "Property") 121 | /// 122 | /// 123 | [AttributeUsage(AttributeTargets.Method, AllowMultiple = false, Inherited = true)] 124 | public sealed class NotifyPropertyChangedInvocatorAttribute : Attribute 125 | { 126 | public NotifyPropertyChangedInvocatorAttribute() { } 127 | public NotifyPropertyChangedInvocatorAttribute(string parameterName) 128 | { 129 | ParameterName = parameterName; 130 | } 131 | 132 | public string ParameterName { get; private set; } 133 | } 134 | 135 | /// 136 | /// Describes dependency between method input and output 137 | /// 138 | /// 139 | ///

Function Definition Table syntax:

140 | /// 141 | /// FDT ::= FDTRow [;FDTRow]* 142 | /// FDTRow ::= Input => Output | Output <= Input 143 | /// Input ::= ParameterName: Value [, Input]* 144 | /// Output ::= [ParameterName: Value]* {halt|stop|void|nothing|Value} 145 | /// Value ::= true | false | null | notnull | canbenull 146 | /// 147 | /// If method has single input parameter, it's name could be omitted.
148 | /// Using halt (or void/nothing, which is the same) 149 | /// for method output means that the methos doesn't return normally.
150 | /// canbenull annotation is only applicable for output parameters.
151 | /// You can use multiple [ContractAnnotation] for each FDT row, 152 | /// or use single attribute with rows separated by semicolon.
153 | ///
154 | /// 155 | /// 156 | /// [ContractAnnotation("=> halt")] 157 | /// public void TerminationMethod() 158 | /// 159 | /// 160 | /// [ContractAnnotation("halt <= condition: false")] 161 | /// public void Assert(bool condition, string text) // regular assertion method 162 | /// 163 | /// 164 | /// [ContractAnnotation("s:null => true")] 165 | /// public bool IsNullOrEmpty(string s) // string.IsNullOrEmpty() 166 | /// 167 | /// 168 | /// // A method that returns null if the parameter is null, and not null if the parameter is not null 169 | /// [ContractAnnotation("null => null; notnull => notnull")] 170 | /// public object Transform(object data) 171 | /// 172 | /// 173 | /// [ContractAnnotation("s:null=>false; =>true,result:notnull; =>false, result:null")] 174 | /// public bool TryParse(string s, out Person result) 175 | /// 176 | /// 177 | [AttributeUsage(AttributeTargets.Method, AllowMultiple = true, Inherited = true)] 178 | public sealed class ContractAnnotationAttribute : Attribute 179 | { 180 | public ContractAnnotationAttribute([NotNull] string contract) 181 | : this(contract, false) { } 182 | 183 | public ContractAnnotationAttribute([NotNull] string contract, bool forceFullStates) 184 | { 185 | Contract = contract; 186 | ForceFullStates = forceFullStates; 187 | } 188 | 189 | public string Contract { get; private set; } 190 | public bool ForceFullStates { get; private set; } 191 | } 192 | 193 | /// 194 | /// Indicates that marked element should be localized or not 195 | /// 196 | /// 197 | /// [LocalizationRequiredAttribute(true)] 198 | /// public class Foo { 199 | /// private string str = "my string"; // Warning: Localizable string 200 | /// } 201 | /// 202 | [AttributeUsage(AttributeTargets.All, AllowMultiple = false, Inherited = true)] 203 | public sealed class LocalizationRequiredAttribute : Attribute 204 | { 205 | public LocalizationRequiredAttribute() : this(true) { } 206 | public LocalizationRequiredAttribute(bool required) 207 | { 208 | Required = required; 209 | } 210 | 211 | public bool Required { get; private set; } 212 | } 213 | 214 | /// 215 | /// Indicates that the value of the marked type (or its derivatives) 216 | /// cannot be compared using '==' or '!=' operators and Equals() 217 | /// should be used instead. However, using '==' or '!=' for comparison 218 | /// with null is always permitted. 219 | /// 220 | /// 221 | /// [CannotApplyEqualityOperator] 222 | /// class NoEquality { } 223 | /// class UsesNoEquality { 224 | /// public void Test() { 225 | /// var ca1 = new NoEquality(); 226 | /// var ca2 = new NoEquality(); 227 | /// if (ca1 != null) { // OK 228 | /// bool condition = ca1 == ca2; // Warning 229 | /// } 230 | /// } 231 | /// } 232 | /// 233 | [AttributeUsage( 234 | AttributeTargets.Interface | AttributeTargets.Class | 235 | AttributeTargets.Struct, AllowMultiple = false, Inherited = true)] 236 | public sealed class CannotApplyEqualityOperatorAttribute : Attribute { } 237 | 238 | /// 239 | /// When applied to a target attribute, specifies a requirement for any type marked 240 | /// with the target attribute to implement or inherit specific type or types. 241 | /// 242 | /// 243 | /// [BaseTypeRequired(typeof(IComponent)] // Specify requirement 244 | /// public class ComponentAttribute : Attribute { } 245 | /// [Component] // ComponentAttribute requires implementing IComponent interface 246 | /// public class MyComponent : IComponent { } 247 | /// 248 | [AttributeUsage(AttributeTargets.Class, AllowMultiple = true, Inherited = true)] 249 | [BaseTypeRequired(typeof(Attribute))] 250 | public sealed class BaseTypeRequiredAttribute : Attribute 251 | { 252 | public BaseTypeRequiredAttribute([NotNull] Type baseType) 253 | { 254 | BaseType = baseType; 255 | } 256 | 257 | [NotNull] public Type BaseType { get; private set; } 258 | } 259 | 260 | /// 261 | /// Indicates that the marked symbol is used implicitly 262 | /// (e.g. via reflection, in external library), so this symbol 263 | /// will not be marked as unused (as well as by other usage inspections) 264 | /// 265 | [AttributeUsage(AttributeTargets.All, AllowMultiple = false, Inherited = true)] 266 | public sealed class UsedImplicitlyAttribute : Attribute 267 | { 268 | public UsedImplicitlyAttribute() 269 | : this(ImplicitUseKindFlags.Default, ImplicitUseTargetFlags.Default) { } 270 | 271 | public UsedImplicitlyAttribute(ImplicitUseKindFlags useKindFlags) 272 | : this(useKindFlags, ImplicitUseTargetFlags.Default) { } 273 | 274 | public UsedImplicitlyAttribute(ImplicitUseTargetFlags targetFlags) 275 | : this(ImplicitUseKindFlags.Default, targetFlags) { } 276 | 277 | public UsedImplicitlyAttribute( 278 | ImplicitUseKindFlags useKindFlags, ImplicitUseTargetFlags targetFlags) 279 | { 280 | UseKindFlags = useKindFlags; 281 | TargetFlags = targetFlags; 282 | } 283 | 284 | public ImplicitUseKindFlags UseKindFlags { get; private set; } 285 | public ImplicitUseTargetFlags TargetFlags { get; private set; } 286 | } 287 | 288 | /// 289 | /// Should be used on attributes and causes ReSharper 290 | /// to not mark symbols marked with such attributes as unused 291 | /// (as well as by other usage inspections) 292 | /// 293 | [AttributeUsage(AttributeTargets.Class, AllowMultiple = false, Inherited = true)] 294 | public sealed class MeansImplicitUseAttribute : Attribute 295 | { 296 | public MeansImplicitUseAttribute() 297 | : this(ImplicitUseKindFlags.Default, ImplicitUseTargetFlags.Default) { } 298 | 299 | public MeansImplicitUseAttribute(ImplicitUseKindFlags useKindFlags) 300 | : this(useKindFlags, ImplicitUseTargetFlags.Default) { } 301 | 302 | public MeansImplicitUseAttribute(ImplicitUseTargetFlags targetFlags) 303 | : this(ImplicitUseKindFlags.Default, targetFlags) { } 304 | 305 | public MeansImplicitUseAttribute( 306 | ImplicitUseKindFlags useKindFlags, ImplicitUseTargetFlags targetFlags) 307 | { 308 | UseKindFlags = useKindFlags; 309 | TargetFlags = targetFlags; 310 | } 311 | 312 | [UsedImplicitly] public ImplicitUseKindFlags UseKindFlags { get; private set; } 313 | [UsedImplicitly] public ImplicitUseTargetFlags TargetFlags { get; private set; } 314 | } 315 | 316 | [Flags] 317 | public enum ImplicitUseKindFlags 318 | { 319 | Default = Access | Assign | InstantiatedWithFixedConstructorSignature, 320 | /// Only entity marked with attribute considered used 321 | Access = 1, 322 | /// Indicates implicit assignment to a member 323 | Assign = 2, 324 | /// 325 | /// Indicates implicit instantiation of a type with fixed constructor signature. 326 | /// That means any unused constructor parameters won't be reported as such. 327 | /// 328 | InstantiatedWithFixedConstructorSignature = 4, 329 | /// Indicates implicit instantiation of a type 330 | InstantiatedNoFixedConstructorSignature = 8, 331 | } 332 | 333 | /// 334 | /// Specify what is considered used implicitly 335 | /// when marked with 336 | /// or 337 | /// 338 | [Flags] 339 | public enum ImplicitUseTargetFlags 340 | { 341 | Default = Itself, 342 | Itself = 1, 343 | /// Members of entity marked with attribute are considered used 344 | Members = 2, 345 | /// Entity marked with attribute and all its members considered used 346 | WithMembers = Itself | Members 347 | } 348 | 349 | /// 350 | /// This attribute is intended to mark publicly available API 351 | /// which should not be removed and so is treated as used 352 | /// 353 | [MeansImplicitUse] 354 | public sealed class PublicAPIAttribute : Attribute 355 | { 356 | public PublicAPIAttribute() { } 357 | public PublicAPIAttribute([NotNull] string comment) 358 | { 359 | Comment = comment; 360 | } 361 | 362 | [NotNull] public string Comment { get; private set; } 363 | } 364 | 365 | /// 366 | /// Tells code analysis engine if the parameter is completely handled 367 | /// when the invoked method is on stack. If the parameter is a delegate, 368 | /// indicates that delegate is executed while the method is executed. 369 | /// If the parameter is an enumerable, indicates that it is enumerated 370 | /// while the method is executed 371 | /// 372 | [AttributeUsage(AttributeTargets.Parameter, Inherited = true)] 373 | public sealed class InstantHandleAttribute : Attribute { } 374 | 375 | /// 376 | /// Indicates that a method does not make any observable state changes. 377 | /// The same as System.Diagnostics.Contracts.PureAttribute 378 | /// 379 | /// 380 | /// [Pure] private int Multiply(int x, int y) { return x * y; } 381 | /// public void Foo() { 382 | /// const int a = 2, b = 2; 383 | /// Multiply(a, b); // Waring: Return value of pure method is not used 384 | /// } 385 | /// 386 | [AttributeUsage(AttributeTargets.Method, Inherited = true)] 387 | public sealed class PureAttribute : Attribute { } 388 | 389 | /// 390 | /// Indicates that a parameter is a path to a file or a folder 391 | /// within a web project. Path can be relative or absolute, 392 | /// starting from web root (~) 393 | /// 394 | [AttributeUsage(AttributeTargets.Parameter)] 395 | public class PathReferenceAttribute : Attribute 396 | { 397 | public PathReferenceAttribute() { } 398 | public PathReferenceAttribute([PathReference] string basePath) 399 | { 400 | BasePath = basePath; 401 | } 402 | 403 | [NotNull] public string BasePath { get; private set; } 404 | } 405 | 406 | // ASP.NET MVC attributes 407 | 408 | [AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)] 409 | public sealed class AspMvcAreaMasterLocationFormatAttribute : Attribute 410 | { 411 | public AspMvcAreaMasterLocationFormatAttribute(string format) { } 412 | } 413 | 414 | [AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)] 415 | public sealed class AspMvcAreaPartialViewLocationFormatAttribute : Attribute 416 | { 417 | public AspMvcAreaPartialViewLocationFormatAttribute(string format) { } 418 | } 419 | 420 | [AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)] 421 | public sealed class AspMvcAreaViewLocationFormatAttribute : Attribute 422 | { 423 | public AspMvcAreaViewLocationFormatAttribute(string format) { } 424 | } 425 | 426 | [AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)] 427 | public sealed class AspMvcMasterLocationFormatAttribute : Attribute 428 | { 429 | public AspMvcMasterLocationFormatAttribute(string format) { } 430 | } 431 | 432 | [AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)] 433 | public sealed class AspMvcPartialViewLocationFormatAttribute : Attribute 434 | { 435 | public AspMvcPartialViewLocationFormatAttribute(string format) { } 436 | } 437 | 438 | [AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)] 439 | public sealed class AspMvcViewLocationFormatAttribute : Attribute 440 | { 441 | public AspMvcViewLocationFormatAttribute(string format) { } 442 | } 443 | 444 | /// 445 | /// ASP.NET MVC attribute. If applied to a parameter, indicates that the parameter 446 | /// is an MVC action. If applied to a method, the MVC action name is calculated 447 | /// implicitly from the context. Use this attribute for custom wrappers similar to 448 | /// System.Web.Mvc.Html.ChildActionExtensions.RenderAction(HtmlHelper, String) 449 | /// 450 | [AttributeUsage(AttributeTargets.Parameter | AttributeTargets.Method)] 451 | public sealed class AspMvcActionAttribute : Attribute 452 | { 453 | public AspMvcActionAttribute() { } 454 | public AspMvcActionAttribute([NotNull] string anonymousProperty) 455 | { 456 | AnonymousProperty = anonymousProperty; 457 | } 458 | 459 | [NotNull] public string AnonymousProperty { get; private set; } 460 | } 461 | 462 | /// 463 | /// ASP.NET MVC attribute. Indicates that a parameter is an MVC area. 464 | /// Use this attribute for custom wrappers similar to 465 | /// System.Web.Mvc.Html.ChildActionExtensions.RenderAction(HtmlHelper, String) 466 | /// 467 | [AttributeUsage(AttributeTargets.Parameter)] 468 | public sealed class AspMvcAreaAttribute : PathReferenceAttribute 469 | { 470 | public AspMvcAreaAttribute() { } 471 | public AspMvcAreaAttribute([NotNull] string anonymousProperty) 472 | { 473 | AnonymousProperty = anonymousProperty; 474 | } 475 | 476 | [NotNull] public string AnonymousProperty { get; private set; } 477 | } 478 | 479 | /// 480 | /// ASP.NET MVC attribute. If applied to a parameter, indicates that 481 | /// the parameter is an MVC controller. If applied to a method, 482 | /// the MVC controller name is calculated implicitly from the context. 483 | /// Use this attribute for custom wrappers similar to 484 | /// System.Web.Mvc.Html.ChildActionExtensions.RenderAction(HtmlHelper, String, String) 485 | /// 486 | [AttributeUsage(AttributeTargets.Parameter | AttributeTargets.Method)] 487 | public sealed class AspMvcControllerAttribute : Attribute 488 | { 489 | public AspMvcControllerAttribute() { } 490 | public AspMvcControllerAttribute([NotNull] string anonymousProperty) 491 | { 492 | AnonymousProperty = anonymousProperty; 493 | } 494 | 495 | [NotNull] public string AnonymousProperty { get; private set; } 496 | } 497 | 498 | /// 499 | /// ASP.NET MVC attribute. Indicates that a parameter is an MVC Master. 500 | /// Use this attribute for custom wrappers similar to 501 | /// System.Web.Mvc.Controller.View(String, String) 502 | /// 503 | [AttributeUsage(AttributeTargets.Parameter)] 504 | public sealed class AspMvcMasterAttribute : Attribute { } 505 | 506 | /// 507 | /// ASP.NET MVC attribute. Indicates that a parameter is an MVC model type. 508 | /// Use this attribute for custom wrappers similar to 509 | /// System.Web.Mvc.Controller.View(String, Object) 510 | /// 511 | [AttributeUsage(AttributeTargets.Parameter)] 512 | public sealed class AspMvcModelTypeAttribute : Attribute { } 513 | 514 | /// 515 | /// ASP.NET MVC attribute. If applied to a parameter, indicates that 516 | /// the parameter is an MVC partial view. If applied to a method, 517 | /// the MVC partial view name is calculated implicitly from the context. 518 | /// Use this attribute for custom wrappers similar to 519 | /// System.Web.Mvc.Html.RenderPartialExtensions.RenderPartial(HtmlHelper, String) 520 | /// 521 | [AttributeUsage(AttributeTargets.Parameter | AttributeTargets.Method)] 522 | public sealed class AspMvcPartialViewAttribute : PathReferenceAttribute { } 523 | 524 | /// 525 | /// ASP.NET MVC attribute. Allows disabling all inspections 526 | /// for MVC views within a class or a method. 527 | /// 528 | [AttributeUsage(AttributeTargets.Class | AttributeTargets.Method)] 529 | public sealed class AspMvcSupressViewErrorAttribute : Attribute { } 530 | 531 | /// 532 | /// ASP.NET MVC attribute. Indicates that a parameter is an MVC display template. 533 | /// Use this attribute for custom wrappers similar to 534 | /// System.Web.Mvc.Html.DisplayExtensions.DisplayForModel(HtmlHelper, String) 535 | /// 536 | [AttributeUsage(AttributeTargets.Parameter)] 537 | public sealed class AspMvcDisplayTemplateAttribute : Attribute { } 538 | 539 | /// 540 | /// ASP.NET MVC attribute. Indicates that a parameter is an MVC editor template. 541 | /// Use this attribute for custom wrappers similar to 542 | /// System.Web.Mvc.Html.EditorExtensions.EditorForModel(HtmlHelper, String) 543 | /// 544 | [AttributeUsage(AttributeTargets.Parameter)] 545 | public sealed class AspMvcEditorTemplateAttribute : Attribute { } 546 | 547 | /// 548 | /// ASP.NET MVC attribute. Indicates that a parameter is an MVC template. 549 | /// Use this attribute for custom wrappers similar to 550 | /// System.ComponentModel.DataAnnotations.UIHintAttribute(System.String) 551 | /// 552 | [AttributeUsage(AttributeTargets.Parameter)] 553 | public sealed class AspMvcTemplateAttribute : Attribute { } 554 | 555 | /// 556 | /// ASP.NET MVC attribute. If applied to a parameter, indicates that the parameter 557 | /// is an MVC view. If applied to a method, the MVC view name is calculated implicitly 558 | /// from the context. Use this attribute for custom wrappers similar to 559 | /// System.Web.Mvc.Controller.View(Object) 560 | /// 561 | [AttributeUsage(AttributeTargets.Parameter | AttributeTargets.Method)] 562 | public sealed class AspMvcViewAttribute : PathReferenceAttribute { } 563 | 564 | /// 565 | /// ASP.NET MVC attribute. When applied to a parameter of an attribute, 566 | /// indicates that this parameter is an MVC action name 567 | /// 568 | /// 569 | /// [ActionName("Foo")] 570 | /// public ActionResult Login(string returnUrl) { 571 | /// ViewBag.ReturnUrl = Url.Action("Foo"); // OK 572 | /// return RedirectToAction("Bar"); // Error: Cannot resolve action 573 | /// } 574 | /// 575 | [AttributeUsage(AttributeTargets.Parameter | AttributeTargets.Property)] 576 | public sealed class AspMvcActionSelectorAttribute : Attribute { } 577 | 578 | [AttributeUsage( 579 | AttributeTargets.Parameter | AttributeTargets.Property | 580 | AttributeTargets.Field, Inherited = true)] 581 | public sealed class HtmlElementAttributesAttribute : Attribute 582 | { 583 | public HtmlElementAttributesAttribute() { } 584 | public HtmlElementAttributesAttribute([NotNull] string name) 585 | { 586 | Name = name; 587 | } 588 | 589 | [NotNull] public string Name { get; private set; } 590 | } 591 | 592 | [AttributeUsage( 593 | AttributeTargets.Parameter | AttributeTargets.Field | 594 | AttributeTargets.Property, Inherited = true)] 595 | public sealed class HtmlAttributeValueAttribute : Attribute 596 | { 597 | public HtmlAttributeValueAttribute([NotNull] string name) 598 | { 599 | Name = name; 600 | } 601 | 602 | [NotNull] public string Name { get; private set; } 603 | } 604 | 605 | // Razor attributes 606 | 607 | /// 608 | /// Razor attribute. Indicates that a parameter or a method is a Razor section. 609 | /// Use this attribute for custom wrappers similar to 610 | /// System.Web.WebPages.WebPageBase.RenderSection(String) 611 | /// 612 | [AttributeUsage(AttributeTargets.Parameter | AttributeTargets.Method, Inherited = true)] 613 | public sealed class RazorSectionAttribute : Attribute { } 614 | } -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | GNU LESSER GENERAL PUBLIC LICENSE 2 | Version 2.1, February 1999 3 | 4 | Copyright (C) 1991, 1999 Free Software Foundation, Inc. 5 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 6 | Everyone is permitted to copy and distribute verbatim copies 7 | of this license document, but changing it is not allowed. 8 | 9 | (This is the first released version of the Lesser GPL. It also counts 10 | as the successor of the GNU Library Public License, version 2, hence 11 | the version number 2.1.) 12 | 13 | Preamble 14 | 15 | The licenses for most software are designed to take away your 16 | freedom to share and change it. By contrast, the GNU General Public 17 | Licenses are intended to guarantee your freedom to share and change 18 | free software--to make sure the software is free for all its users. 19 | 20 | This license, the Lesser General Public License, applies to some 21 | specially designated software packages--typically libraries--of the 22 | Free Software Foundation and other authors who decide to use it. You 23 | can use it too, but we suggest you first think carefully about whether 24 | this license or the ordinary General Public License is the better 25 | strategy to use in any particular case, based on the explanations below. 26 | 27 | When we speak of free software, we are referring to freedom of use, 28 | not price. Our General Public Licenses are designed to make sure that 29 | you have the freedom to distribute copies of free software (and charge 30 | for this service if you wish); that you receive source code or can get 31 | it if you want it; that you can change the software and use pieces of 32 | it in new free programs; and that you are informed that you can do 33 | these things. 34 | 35 | To protect your rights, we need to make restrictions that forbid 36 | distributors to deny you these rights or to ask you to surrender these 37 | rights. These restrictions translate to certain responsibilities for 38 | you if you distribute copies of the library or if you modify it. 39 | 40 | For example, if you distribute copies of the library, whether gratis 41 | or for a fee, you must give the recipients all the rights that we gave 42 | you. You must make sure that they, too, receive or can get the source 43 | code. If you link other code with the library, you must provide 44 | complete object files to the recipients, so that they can relink them 45 | with the library after making changes to the library and recompiling 46 | it. And you must show them these terms so they know their rights. 47 | 48 | We protect your rights with a two-step method: (1) we copyright the 49 | library, and (2) we offer you this license, which gives you legal 50 | permission to copy, distribute and/or modify the library. 51 | 52 | To protect each distributor, we want to make it very clear that 53 | there is no warranty for the free library. Also, if the library is 54 | modified by someone else and passed on, the recipients should know 55 | that what they have is not the original version, so that the original 56 | author's reputation will not be affected by problems that might be 57 | introduced by others. 58 | 59 | Finally, software patents pose a constant threat to the existence of 60 | any free program. We wish to make sure that a company cannot 61 | effectively restrict the users of a free program by obtaining a 62 | restrictive license from a patent holder. Therefore, we insist that 63 | any patent license obtained for a version of the library must be 64 | consistent with the full freedom of use specified in this license. 65 | 66 | Most GNU software, including some libraries, is covered by the 67 | ordinary GNU General Public License. This license, the GNU Lesser 68 | General Public License, applies to certain designated libraries, and 69 | is quite different from the ordinary General Public License. We use 70 | this license for certain libraries in order to permit linking those 71 | libraries into non-free programs. 72 | 73 | When a program is linked with a library, whether statically or using 74 | a shared library, the combination of the two is legally speaking a 75 | combined work, a derivative of the original library. The ordinary 76 | General Public License therefore permits such linking only if the 77 | entire combination fits its criteria of freedom. The Lesser General 78 | Public License permits more lax criteria for linking other code with 79 | the library. 80 | 81 | We call this license the "Lesser" General Public License because it 82 | does Less to protect the user's freedom than the ordinary General 83 | Public License. It also provides other free software developers Less 84 | of an advantage over competing non-free programs. These disadvantages 85 | are the reason we use the ordinary General Public License for many 86 | libraries. However, the Lesser license provides advantages in certain 87 | special circumstances. 88 | 89 | For example, on rare occasions, there may be a special need to 90 | encourage the widest possible use of a certain library, so that it becomes 91 | a de-facto standard. To achieve this, non-free programs must be 92 | allowed to use the library. A more frequent case is that a free 93 | library does the same job as widely used non-free libraries. In this 94 | case, there is little to gain by limiting the free library to free 95 | software only, so we use the Lesser General Public License. 96 | 97 | In other cases, permission to use a particular library in non-free 98 | programs enables a greater number of people to use a large body of 99 | free software. For example, permission to use the GNU C Library in 100 | non-free programs enables many more people to use the whole GNU 101 | operating system, as well as its variant, the GNU/Linux operating 102 | system. 103 | 104 | Although the Lesser General Public License is Less protective of the 105 | users' freedom, it does ensure that the user of a program that is 106 | linked with the Library has the freedom and the wherewithal to run 107 | that program using a modified version of the Library. 108 | 109 | The precise terms and conditions for copying, distribution and 110 | modification follow. Pay close attention to the difference between a 111 | "work based on the library" and a "work that uses the library". The 112 | former contains code derived from the library, whereas the latter must 113 | be combined with the library in order to run. 114 | 115 | GNU LESSER GENERAL PUBLIC LICENSE 116 | TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 117 | 118 | 0. This License Agreement applies to any software library or other 119 | program which contains a notice placed by the copyright holder or 120 | other authorized party saying it may be distributed under the terms of 121 | this Lesser General Public License (also called "this License"). 122 | Each licensee is addressed as "you". 123 | 124 | A "library" means a collection of software functions and/or data 125 | prepared so as to be conveniently linked with application programs 126 | (which use some of those functions and data) to form executables. 127 | 128 | The "Library", below, refers to any such software library or work 129 | which has been distributed under these terms. A "work based on the 130 | Library" means either the Library or any derivative work under 131 | copyright law: that is to say, a work containing the Library or a 132 | portion of it, either verbatim or with modifications and/or translated 133 | straightforwardly into another language. (Hereinafter, translation is 134 | included without limitation in the term "modification".) 135 | 136 | "Source code" for a work means the preferred form of the work for 137 | making modifications to it. For a library, complete source code means 138 | all the source code for all modules it contains, plus any associated 139 | interface definition files, plus the scripts used to control compilation 140 | and installation of the library. 141 | 142 | Activities other than copying, distribution and modification are not 143 | covered by this License; they are outside its scope. The act of 144 | running a program using the Library is not restricted, and output from 145 | such a program is covered only if its contents constitute a work based 146 | on the Library (independent of the use of the Library in a tool for 147 | writing it). Whether that is true depends on what the Library does 148 | and what the program that uses the Library does. 149 | 150 | 1. You may copy and distribute verbatim copies of the Library's 151 | complete source code as you receive it, in any medium, provided that 152 | you conspicuously and appropriately publish on each copy an 153 | appropriate copyright notice and disclaimer of warranty; keep intact 154 | all the notices that refer to this License and to the absence of any 155 | warranty; and distribute a copy of this License along with the 156 | Library. 157 | 158 | You may charge a fee for the physical act of transferring a copy, 159 | and you may at your option offer warranty protection in exchange for a 160 | fee. 161 | 162 | 2. You may modify your copy or copies of the Library or any portion 163 | of it, thus forming a work based on the Library, and copy and 164 | distribute such modifications or work under the terms of Section 1 165 | above, provided that you also meet all of these conditions: 166 | 167 | a) The modified work must itself be a software library. 168 | 169 | b) You must cause the files modified to carry prominent notices 170 | stating that you changed the files and the date of any change. 171 | 172 | c) You must cause the whole of the work to be licensed at no 173 | charge to all third parties under the terms of this License. 174 | 175 | d) If a facility in the modified Library refers to a function or a 176 | table of data to be supplied by an application program that uses 177 | the facility, other than as an argument passed when the facility 178 | is invoked, then you must make a good faith effort to ensure that, 179 | in the event an application does not supply such function or 180 | table, the facility still operates, and performs whatever part of 181 | its purpose remains meaningful. 182 | 183 | (For example, a function in a library to compute square roots has 184 | a purpose that is entirely well-defined independent of the 185 | application. Therefore, Subsection 2d requires that any 186 | application-supplied function or table used by this function must 187 | be optional: if the application does not supply it, the square 188 | root function must still compute square roots.) 189 | 190 | These requirements apply to the modified work as a whole. If 191 | identifiable sections of that work are not derived from the Library, 192 | and can be reasonably considered independent and separate works in 193 | themselves, then this License, and its terms, do not apply to those 194 | sections when you distribute them as separate works. But when you 195 | distribute the same sections as part of a whole which is a work based 196 | on the Library, the distribution of the whole must be on the terms of 197 | this License, whose permissions for other licensees extend to the 198 | entire whole, and thus to each and every part regardless of who wrote 199 | it. 200 | 201 | Thus, it is not the intent of this section to claim rights or contest 202 | your rights to work written entirely by you; rather, the intent is to 203 | exercise the right to control the distribution of derivative or 204 | collective works based on the Library. 205 | 206 | In addition, mere aggregation of another work not based on the Library 207 | with the Library (or with a work based on the Library) on a volume of 208 | a storage or distribution medium does not bring the other work under 209 | the scope of this License. 210 | 211 | 3. You may opt to apply the terms of the ordinary GNU General Public 212 | License instead of this License to a given copy of the Library. To do 213 | this, you must alter all the notices that refer to this License, so 214 | that they refer to the ordinary GNU General Public License, version 2, 215 | instead of to this License. (If a newer version than version 2 of the 216 | ordinary GNU General Public License has appeared, then you can specify 217 | that version instead if you wish.) Do not make any other change in 218 | these notices. 219 | 220 | Once this change is made in a given copy, it is irreversible for 221 | that copy, so the ordinary GNU General Public License applies to all 222 | subsequent copies and derivative works made from that copy. 223 | 224 | This option is useful when you wish to copy part of the code of 225 | the Library into a program that is not a library. 226 | 227 | 4. You may copy and distribute the Library (or a portion or 228 | derivative of it, under Section 2) in object code or executable form 229 | under the terms of Sections 1 and 2 above provided that you accompany 230 | it with the complete corresponding machine-readable source code, which 231 | must be distributed under the terms of Sections 1 and 2 above on a 232 | medium customarily used for software interchange. 233 | 234 | If distribution of object code is made by offering access to copy 235 | from a designated place, then offering equivalent access to copy the 236 | source code from the same place satisfies the requirement to 237 | distribute the source code, even though third parties are not 238 | compelled to copy the source along with the object code. 239 | 240 | 5. A program that contains no derivative of any portion of the 241 | Library, but is designed to work with the Library by being compiled or 242 | linked with it, is called a "work that uses the Library". Such a 243 | work, in isolation, is not a derivative work of the Library, and 244 | therefore falls outside the scope of this License. 245 | 246 | However, linking a "work that uses the Library" with the Library 247 | creates an executable that is a derivative of the Library (because it 248 | contains portions of the Library), rather than a "work that uses the 249 | library". The executable is therefore covered by this License. 250 | Section 6 states terms for distribution of such executables. 251 | 252 | When a "work that uses the Library" uses material from a header file 253 | that is part of the Library, the object code for the work may be a 254 | derivative work of the Library even though the source code is not. 255 | Whether this is true is especially significant if the work can be 256 | linked without the Library, or if the work is itself a library. The 257 | threshold for this to be true is not precisely defined by law. 258 | 259 | If such an object file uses only numerical parameters, data 260 | structure layouts and accessors, and small macros and small inline 261 | functions (ten lines or less in length), then the use of the object 262 | file is unrestricted, regardless of whether it is legally a derivative 263 | work. (Executables containing this object code plus portions of the 264 | Library will still fall under Section 6.) 265 | 266 | Otherwise, if the work is a derivative of the Library, you may 267 | distribute the object code for the work under the terms of Section 6. 268 | Any executables containing that work also fall under Section 6, 269 | whether or not they are linked directly with the Library itself. 270 | 271 | 6. As an exception to the Sections above, you may also combine or 272 | link a "work that uses the Library" with the Library to produce a 273 | work containing portions of the Library, and distribute that work 274 | under terms of your choice, provided that the terms permit 275 | modification of the work for the customer's own use and reverse 276 | engineering for debugging such modifications. 277 | 278 | You must give prominent notice with each copy of the work that the 279 | Library is used in it and that the Library and its use are covered by 280 | this License. You must supply a copy of this License. If the work 281 | during execution displays copyright notices, you must include the 282 | copyright notice for the Library among them, as well as a reference 283 | directing the user to the copy of this License. Also, you must do one 284 | of these things: 285 | 286 | a) Accompany the work with the complete corresponding 287 | machine-readable source code for the Library including whatever 288 | changes were used in the work (which must be distributed under 289 | Sections 1 and 2 above); and, if the work is an executable linked 290 | with the Library, with the complete machine-readable "work that 291 | uses the Library", as object code and/or source code, so that the 292 | user can modify the Library and then relink to produce a modified 293 | executable containing the modified Library. (It is understood 294 | that the user who changes the contents of definitions files in the 295 | Library will not necessarily be able to recompile the application 296 | to use the modified definitions.) 297 | 298 | b) Use a suitable shared library mechanism for linking with the 299 | Library. A suitable mechanism is one that (1) uses at run time a 300 | copy of the library already present on the user's computer system, 301 | rather than copying library functions into the executable, and (2) 302 | will operate properly with a modified version of the library, if 303 | the user installs one, as long as the modified version is 304 | interface-compatible with the version that the work was made with. 305 | 306 | c) Accompany the work with a written offer, valid for at 307 | least three years, to give the same user the materials 308 | specified in Subsection 6a, above, for a charge no more 309 | than the cost of performing this distribution. 310 | 311 | d) If distribution of the work is made by offering access to copy 312 | from a designated place, offer equivalent access to copy the above 313 | specified materials from the same place. 314 | 315 | e) Verify that the user has already received a copy of these 316 | materials or that you have already sent this user a copy. 317 | 318 | For an executable, the required form of the "work that uses the 319 | Library" must include any data and utility programs needed for 320 | reproducing the executable from it. However, as a special exception, 321 | the materials to be distributed need not include anything that is 322 | normally distributed (in either source or binary form) with the major 323 | components (compiler, kernel, and so on) of the operating system on 324 | which the executable runs, unless that component itself accompanies 325 | the executable. 326 | 327 | It may happen that this requirement contradicts the license 328 | restrictions of other proprietary libraries that do not normally 329 | accompany the operating system. Such a contradiction means you cannot 330 | use both them and the Library together in an executable that you 331 | distribute. 332 | 333 | 7. You may place library facilities that are a work based on the 334 | Library side-by-side in a single library together with other library 335 | facilities not covered by this License, and distribute such a combined 336 | library, provided that the separate distribution of the work based on 337 | the Library and of the other library facilities is otherwise 338 | permitted, and provided that you do these two things: 339 | 340 | a) Accompany the combined library with a copy of the same work 341 | based on the Library, uncombined with any other library 342 | facilities. This must be distributed under the terms of the 343 | Sections above. 344 | 345 | b) Give prominent notice with the combined library of the fact 346 | that part of it is a work based on the Library, and explaining 347 | where to find the accompanying uncombined form of the same work. 348 | 349 | 8. You may not copy, modify, sublicense, link with, or distribute 350 | the Library except as expressly provided under this License. Any 351 | attempt otherwise to copy, modify, sublicense, link with, or 352 | distribute the Library is void, and will automatically terminate your 353 | rights under this License. However, parties who have received copies, 354 | or rights, from you under this License will not have their licenses 355 | terminated so long as such parties remain in full compliance. 356 | 357 | 9. You are not required to accept this License, since you have not 358 | signed it. However, nothing else grants you permission to modify or 359 | distribute the Library or its derivative works. These actions are 360 | prohibited by law if you do not accept this License. Therefore, by 361 | modifying or distributing the Library (or any work based on the 362 | Library), you indicate your acceptance of this License to do so, and 363 | all its terms and conditions for copying, distributing or modifying 364 | the Library or works based on it. 365 | 366 | 10. Each time you redistribute the Library (or any work based on the 367 | Library), the recipient automatically receives a license from the 368 | original licensor to copy, distribute, link with or modify the Library 369 | subject to these terms and conditions. You may not impose any further 370 | restrictions on the recipients' exercise of the rights granted herein. 371 | You are not responsible for enforcing compliance by third parties with 372 | this License. 373 | 374 | 11. If, as a consequence of a court judgment or allegation of patent 375 | infringement or for any other reason (not limited to patent issues), 376 | conditions are imposed on you (whether by court order, agreement or 377 | otherwise) that contradict the conditions of this License, they do not 378 | excuse you from the conditions of this License. If you cannot 379 | distribute so as to satisfy simultaneously your obligations under this 380 | License and any other pertinent obligations, then as a consequence you 381 | may not distribute the Library at all. For example, if a patent 382 | license would not permit royalty-free redistribution of the Library by 383 | all those who receive copies directly or indirectly through you, then 384 | the only way you could satisfy both it and this License would be to 385 | refrain entirely from distribution of the Library. 386 | 387 | If any portion of this section is held invalid or unenforceable under any 388 | particular circumstance, the balance of the section is intended to apply, 389 | and the section as a whole is intended to apply in other circumstances. 390 | 391 | It is not the purpose of this section to induce you to infringe any 392 | patents or other property right claims or to contest validity of any 393 | such claims; this section has the sole purpose of protecting the 394 | integrity of the free software distribution system which is 395 | implemented by public license practices. Many people have made 396 | generous contributions to the wide range of software distributed 397 | through that system in reliance on consistent application of that 398 | system; it is up to the author/donor to decide if he or she is willing 399 | to distribute software through any other system and a licensee cannot 400 | impose that choice. 401 | 402 | This section is intended to make thoroughly clear what is believed to 403 | be a consequence of the rest of this License. 404 | 405 | 12. If the distribution and/or use of the Library is restricted in 406 | certain countries either by patents or by copyrighted interfaces, the 407 | original copyright holder who places the Library under this License may add 408 | an explicit geographical distribution limitation excluding those countries, 409 | so that distribution is permitted only in or among countries not thus 410 | excluded. In such case, this License incorporates the limitation as if 411 | written in the body of this License. 412 | 413 | 13. The Free Software Foundation may publish revised and/or new 414 | versions of the Lesser General Public License from time to time. 415 | Such new versions will be similar in spirit to the present version, 416 | but may differ in detail to address new problems or concerns. 417 | 418 | Each version is given a distinguishing version number. If the Library 419 | specifies a version number of this License which applies to it and 420 | "any later version", you have the option of following the terms and 421 | conditions either of that version or of any later version published by 422 | the Free Software Foundation. If the Library does not specify a 423 | license version number, you may choose any version ever published by 424 | the Free Software Foundation. 425 | 426 | 14. If you wish to incorporate parts of the Library into other free 427 | programs whose distribution conditions are incompatible with these, 428 | write to the author to ask for permission. For software which is 429 | copyrighted by the Free Software Foundation, write to the Free 430 | Software Foundation; we sometimes make exceptions for this. Our 431 | decision will be guided by the two goals of preserving the free status 432 | of all derivatives of our free software and of promoting the sharing 433 | and reuse of software generally. 434 | 435 | NO WARRANTY 436 | 437 | 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO 438 | WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. 439 | EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR 440 | OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY 441 | KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE 442 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 443 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE 444 | LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME 445 | THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 446 | 447 | 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN 448 | WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY 449 | AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU 450 | FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR 451 | CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE 452 | LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING 453 | RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A 454 | FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF 455 | SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH 456 | DAMAGES. 457 | 458 | END OF TERMS AND CONDITIONS 459 | 460 | How to Apply These Terms to Your New Libraries 461 | 462 | If you develop a new library, and you want it to be of the greatest 463 | possible use to the public, we recommend making it free software that 464 | everyone can redistribute and change. You can do so by permitting 465 | redistribution under these terms (or, alternatively, under the terms of the 466 | ordinary General Public License). 467 | 468 | To apply these terms, attach the following notices to the library. It is 469 | safest to attach them to the start of each source file to most effectively 470 | convey the exclusion of warranty; and each file should have at least the 471 | "copyright" line and a pointer to where the full notice is found. 472 | 473 | {description} 474 | Copyright (C) {year} {fullname} 475 | 476 | This library is free software; you can redistribute it and/or 477 | modify it under the terms of the GNU Lesser General Public 478 | License as published by the Free Software Foundation; either 479 | version 2.1 of the License, or (at your option) any later version. 480 | 481 | This library is distributed in the hope that it will be useful, 482 | but WITHOUT ANY WARRANTY; without even the implied warranty of 483 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 484 | Lesser General Public License for more details. 485 | 486 | You should have received a copy of the GNU Lesser General Public 487 | License along with this library; if not, write to the Free Software 488 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 489 | USA 490 | 491 | Also add information on how to contact you by electronic and paper mail. 492 | 493 | You should also get your employer (if you work as a programmer) or your 494 | school, if any, to sign a "copyright disclaimer" for the library, if 495 | necessary. Here is a sample; alter the names: 496 | 497 | Yoyodyne, Inc., hereby disclaims all copyright interest in the 498 | library `Frob' (a library for tweaking knobs) written by James Random 499 | Hacker. 500 | 501 | {signature of Ty Coon}, 1 April 1990 502 | Ty Coon, President of Vice 503 | 504 | That's all there is to it! 505 | --------------------------------------------------------------------------------