Initial develop commit

Initial develop commit
This commit is contained in:
Saúl Piña
2016-03-06 18:12:26 -05:00
parent 07cb83b5b9
commit ef79a1c2c1
28 changed files with 3637 additions and 2 deletions

368
sandbox/Program.cs Normal file
View File

@@ -0,0 +1,368 @@
////
/// Program.cs
///
/// Copyright (c) 2016 Saúl Piña <sauljabin@gmail.com>.
///
/// This file is part of xmlrpcwsc.
///
/// xmlrpcwsc is free software: you can redistribute it and/or modify
/// it under the terms of the GNU Lesser General Public License as published by
/// the Free Software Foundation, either version 3 of the License, or
/// (at your option) any later version.
///
/// xmlrpcwsc is distributed in the hope that it will be useful,
/// but WITHOUT ANY WARRANTY; without even the implied warranty of
/// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
/// GNU Lesser General Public License for more details.
///
/// You should have received a copy of the GNU Lesser General Public License
/// along with xmlrpcwsc. If not, see <http://www.gnu.org/licenses/>.
////
using System;
using XmlRpc;
using System.Xml;
using System.Collections.Generic;
using System.Text;
using System.IO;
namespace sandbox {
/// <summary>
/// This class, test the xmlrpc component on odoo 9
/// </summary>
class MainClass {
public static string Url = "http://localhost:8069/xmlrpc/2", db = "odoo", pass = "admin", user = "admin";
public static void TestRequestXml() {
XmlRpcRequest request = new XmlRpcRequest("version");
request.AddParam(false);
request.AddParam(3);
request.AddParam(4.9);
request.AddParam(DateTime.Now);
request.AddParam(DateTime.UtcNow);
request.AddParam(Encoding.UTF8.GetBytes("hello"));
Dictionary<string, object> dictest = new Dictionary<string, object>();
dictest.Add("hello", "hello");
// request.AddParam(dictest);
List<object> listtest = new List<object>();
listtest.Add(3);
listtest.Add("hello");
listtest.Add(dictest);
request.AddParam(listtest);
XmlDocument xmlRequest = RequestFactory.BuildRequest(request);
xmlRequest.Save(Console.Out);
XmlRpcClient client = new XmlRpcClient();
client.AppName = "Test";
Console.WriteLine("\n");
Console.WriteLine(client.GetUserAgent());
}
public static void TestReadVersion() {
XmlRpcClient client = new XmlRpcClient();
client.Url = Url;
client.Path = "common";
XmlRpcResponse response = client.Execute("version");
Console.WriteLine("version");
Console.WriteLine("REQUEST: ");
client.WriteRequest(Console.Out);
Console.WriteLine();
Console.WriteLine();
Console.WriteLine("RESPONSE: ");
client.WriteResponse(Console.Out);
Console.WriteLine();
Console.WriteLine();
if (response.IsFault()) {
Console.WriteLine(response.GetFaultString());
} else {
Console.WriteLine(response.GetString());
}
}
public static void TestReadRecords() {
XmlRpcClient client = new XmlRpcClient();
client.Url = Url;
client.Path = "common";
// LOGIN
XmlRpcRequest requestLogin = new XmlRpcRequest("authenticate");
requestLogin.AddParams(db, user, pass, XmlRpcParameter.EmptyStruct());
XmlRpcResponse responseLogin = client.Execute(requestLogin);
// Console.WriteLine("authenticate");
// Console.WriteLine("REQUEST: ");
// client.WriteRequest(Console.Out);
// Console.WriteLine();
// Console.WriteLine();
// Console.WriteLine("RESPONSE: ");
// client.WriteResponse(Console.Out);
Console.WriteLine();
Console.WriteLine();
Console.WriteLine("LOGIN: ");
if (responseLogin.IsFault()) {
Console.WriteLine(responseLogin.GetFaultString());
} else {
Console.WriteLine(responseLogin.GetString());
}
// SEARCH
client.Path = "object";
XmlRpcRequest requestSearch = new XmlRpcRequest("execute_kw");
requestSearch.AddParams(db, responseLogin.GetInt(), pass, "res.partner", "search",
XmlRpcParameter.AsArray(
XmlRpcParameter.AsArray(
XmlRpcParameter.AsArray("is_company", "=", true), XmlRpcParameter.AsArray("customer", "=", true)
)
)
);
requestSearch.AddParamStruct(
XmlRpcParameter.AsMember("limit", 2)
);
XmlRpcResponse responseSearch = client.Execute(requestSearch);
// Console.WriteLine();
// Console.WriteLine();
// Console.WriteLine("search");
// Console.WriteLine("REQUEST: ");
// client.WriteRequest(Console.Out);
// Console.WriteLine();
// Console.WriteLine();
// Console.WriteLine("RESPONSE: ");
// client.WriteResponse(Console.Out);
Console.WriteLine();
Console.WriteLine();
Console.WriteLine("SEARCH: ");
if (responseSearch.IsFault()) {
Console.WriteLine(responseSearch.GetFaultString());
} else {
Console.WriteLine(responseSearch.GetString());
}
// READ
XmlRpcRequest requestRead = new XmlRpcRequest("execute_kw");
requestRead.AddParams(db, responseLogin.GetInt(), pass, "res.partner", "read",
XmlRpcParameter.AsArray(
responseSearch.GetArray()
)
);
requestRead.AddParamStruct(XmlRpcParameter.AsMember("fields",
XmlRpcParameter.AsArray("name")
)
);
XmlRpcResponse responseRead = client.Execute(requestRead);
// Console.WriteLine();
// Console.WriteLine();
// Console.WriteLine("read");
// Console.WriteLine("REQUEST: ");
// client.WriteRequest(Console.Out);
// Console.WriteLine();
// Console.WriteLine();
// Console.WriteLine("RESPONSE: ");
// client.WriteResponse(Console.Out);
Console.WriteLine();
Console.WriteLine();
Console.WriteLine("READ: ");
if (responseRead.IsFault()) {
Console.WriteLine(responseRead.GetFaultString());
} else {
Console.WriteLine(responseRead.GetString());
}
}
public static void TestResponseXml() {
XmlDocument testDoc = new XmlDocument();
// testDoc.AppendChild(testDoc.CreateElement("methodResponse"));
// testDoc.LoadXml("<methodResponse><fault><value><struct><member><name>faultCode</name><value><int>1</int></value></member><member><name>faultString</name><value><string>Error</string></value></member></struct></value></fault></methodResponse>");
testDoc.LoadXml("<methodResponse><params><param><value><array><data><value><int>7</int></value><value><int>11</int></value><value><int>8</int></value><value><int>44</int></value><value><int>10</int></value><value><int>12</int></value></data></array></value></param></params></methodResponse>");
testDoc.Save(Console.Out);
XmlRpcResponse response = ResponseFactory.BuildResponse(testDoc);
if (response.IsFault()) {
Console.WriteLine(response.GetFaultString());
} else {
Console.WriteLine();
Console.WriteLine();
Console.WriteLine(response.GetString());
}
}
public static void TestCreateRecord() {
XmlRpcClient client = new XmlRpcClient();
client.Url = Url;
client.Path = "common";
// LOGIN
XmlRpcRequest requestLogin = new XmlRpcRequest("authenticate");
requestLogin.AddParams(db, user, pass, XmlRpcParameter.EmptyStruct());
XmlRpcResponse responseLogin = client.Execute(requestLogin);
// Console.WriteLine("authenticate");
// Console.WriteLine("REQUEST: ");
// client.WriteRequest(Console.Out);
// Console.WriteLine();
// Console.WriteLine();
// Console.WriteLine("RESPONSE: ");
// client.WriteResponse(Console.Out);
Console.WriteLine();
Console.WriteLine();
Console.WriteLine("LOGIN: ");
if (responseLogin.IsFault()) {
Console.WriteLine(responseLogin.GetFaultString());
} else {
Console.WriteLine(responseLogin.GetString());
}
// CREATE
client.Path = "object";
XmlRpcRequest requestCreate = new XmlRpcRequest("execute_kw");
requestCreate.AddParams(db, responseLogin.GetInt(), pass, "res.partner", "create",
XmlRpcParameter.AsArray(
XmlRpcParameter.AsStruct(
XmlRpcParameter.AsMember("name", "Albert Einstein")
, XmlRpcParameter.AsMember("image", Convert.ToBase64String(File.ReadAllBytes("img/einstein.jpg")))
, XmlRpcParameter.AsMember("email", "albert.einstein@email.com")
)
)
);
XmlRpcResponse responseCreate = client.Execute(requestCreate);
// Console.WriteLine();
// Console.WriteLine();
// Console.WriteLine("create");
// Console.WriteLine("REQUEST: ");
// client.WriteRequest(Console.Out);
// Console.WriteLine();
// Console.WriteLine();
// Console.WriteLine("RESPONSE: ");
// client.WriteResponse(Console.Out);
Console.WriteLine();
Console.WriteLine();
Console.WriteLine("READ: ");
if (responseCreate.IsFault()) {
Console.WriteLine(responseCreate.GetFaultString());
} else {
Console.WriteLine(responseCreate.GetString());
}
}
public static void TestSearchReadRecords() {
XmlRpcClient client = new XmlRpcClient();
client.Url = Url;
client.Path = "common";
// LOGIN
XmlRpcRequest requestLogin = new XmlRpcRequest("authenticate");
requestLogin.AddParams(db, user, pass, XmlRpcParameter.EmptyStruct());
XmlRpcResponse responseLogin = client.Execute(requestLogin);
// Console.WriteLine("authenticate");
// Console.WriteLine("REQUEST: ");
// client.WriteRequest(Console.Out);
// Console.WriteLine();
// Console.WriteLine();
// Console.WriteLine("RESPONSE: ");
// client.WriteResponse(Console.Out);
Console.WriteLine();
Console.WriteLine();
Console.WriteLine("LOGIN: ");
if (responseLogin.IsFault()) {
Console.WriteLine(responseLogin.GetFaultString());
} else {
Console.WriteLine(responseLogin.GetString());
}
// SEARCH
client.Path = "object";
XmlRpcRequest requestSearch = new XmlRpcRequest("execute_kw");
requestSearch.AddParams(db, responseLogin.GetInt(), pass, "res.partner", "search_read",
XmlRpcParameter.AsArray(
XmlRpcParameter.AsArray(
// XmlRpcParameter.AsArray("is_company", "=", true), XmlRpcRequest.AsArray("customer", "=", true)
XmlRpcParameter.AsArray("name", "ilike", "t")
)
),
XmlRpcParameter.AsStruct(
XmlRpcParameter.AsMember("fields", XmlRpcParameter.AsArray("name","email"))
// ,XmlRpcParameter.AsMember("limit", 2)
)
);
XmlRpcResponse responseSearch = client.Execute(requestSearch);
// Console.WriteLine();
// Console.WriteLine();
// Console.WriteLine("search");
// Console.WriteLine("REQUEST: ");
// client.WriteRequest(Console.Out);
// Console.WriteLine();
// Console.WriteLine();
// Console.WriteLine("RESPONSE: ");
// client.WriteResponse(Console.Out);
Console.WriteLine();
Console.WriteLine();
Console.WriteLine("SEARCH: ");
if (responseSearch.IsFault()) {
Console.WriteLine(responseSearch.GetFaultString());
} else {
Console.WriteLine(responseSearch.GetString());
}
}
public static void Main(string[] args) {
TestRequestXml();
// TestResponseXml();
// TestReadVersion();
// TestReadRecords();
// TestCreateRecord();
// TestSearchReadRecords();
Console.ReadKey();
}
}
}

View File

@@ -0,0 +1,48 @@
////
/// AssemblyInfo.cs
///
/// Copyright (c) 2016 Saúl Piña <sauljabin@gmail.com>.
///
/// This file is part of xmlrpcwsc.
///
/// xmlrpcwsc is free software: you can redistribute it and/or modify
/// it under the terms of the GNU Lesser General Public License as published by
/// the Free Software Foundation, either version 3 of the License, or
/// (at your option) any later version.
///
/// xmlrpcwsc is distributed in the hope that it will be useful,
/// but WITHOUT ANY WARRANTY; without even the implied warranty of
/// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
/// GNU Lesser General Public License for more details.
///
/// You should have received a copy of the GNU Lesser General Public License
/// along with xmlrpcwsc. If not, see <http://www.gnu.org/licenses/>.
////
using System.Reflection;
using System.Runtime.CompilerServices;
// Information about this assembly is defined by the following attributes.
// Change them to the values specific to your project.
[assembly: AssemblyTitle("sandbox")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("sandbox")]
[assembly: AssemblyCopyright("Copyright (c) 2016 Saúl Piña")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// The assembly version has the format "{Major}.{Minor}.{Build}.{Revision}".
// The form "{Major}.{Minor}.*" will automatically update the build and revision,
// and "{Major}.{Minor}.{Build}.*" will update just the revision.
[assembly: AssemblyVersion("1.0.0")]
// The following attributes are used to specify the signing key for the assembly,
// if desired. See the Mono documentation for more information about signing.
//[assembly: AssemblyDelaySign(false)]
//[assembly: AssemblyKeyFile("")]

43
sandbox/sandbox.csproj Normal file
View File

@@ -0,0 +1,43 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{5B413D0A-0AC7-44BE-A4BF-0C824864C486}</ProjectGuid>
<OutputType>Exe</OutputType>
<RootNamespace>sandbox</RootNamespace>
<AssemblyName>sandbox</AssemblyName>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>..\build\</OutputPath>
<DefineConstants>DEBUG;</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<Externalconsole>true</Externalconsole>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>full</DebugType>
<Optimize>true</Optimize>
<OutputPath>..\build\</OutputPath>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<Externalconsole>true</Externalconsole>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Xml" />
<Reference Include="xmlrpcwsc">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\build\xmlrpcwsc.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
</Project>