Vous êtes sur la page 1sur 2

using using using using using using

System; System.Collections.Generic; System.Collections; System.Linq; System.Text; CookComputing.XmlRpc;

namespace openerpIntegration { class Program { static void Main(string[] args) { string dbname = "dbname", userName = "admin", pwd = "admin"; //Login to openerp IOpenErpLogin rpcClientLogin = XmlRpcProxyGen.Create<IOpenErpLogin>( ); int userid = rpcClientLogin.login(dbname, userName, pwd); Console.WriteLine("Logged in userid {0}", userid); //add uom IOpenErp rpcClient = XmlRpcProxyGen.Create<IOpenErp>(); XmlRpcStruct addPairFields = new XmlRpcStruct(); addPairFields.Add("name", "val"); int resAdd = rpcClient.create(dbname, userid, pwd, "product.uom.cate g", "create", addPairFields); Console.WriteLine("Added recordid {0}", resAdd); //search uom String[] condition = new String[] { "id", "=", resAdd.ToString() }; ArrayList lstFilters = new ArrayList(); lstFilters.Add(condition); Object[] resSearch = rpcClient.search(dbname, userid, pwd, "product. uom.categ", "search", lstFilters.ToArray()); Console.WriteLine("Found recordid {0}", resSearch[0]); //edit uom XmlRpcStruct writePairFields = new XmlRpcStruct(); writePairFields.Add("name", "val1"); int[] writeToIds = new int[] { resAdd }; bool resWrite = rpcClient.write(dbname, 1, pwd, "product.uom.categ", "write", writeToIds, writePairFields); Console.WriteLine("Edited record {0}", resWrite); //read uom ArrayList readFromIds = new ArrayList(); readFromIds.Add(resAdd); ArrayList selectFields = new ArrayList(); //selectFields.Add("name"); Object[] resRead = rpcClient.read(dbname, userid, pwd, "product.uom. categ", "read", readFromIds.ToArray(), selectFields.ToArray()); Console.WriteLine("Record details:"); foreach (Object db in resRead) { XmlRpcStruct obj = (XmlRpcStruct)db; foreach (DictionaryEntry d in obj) { Console.WriteLine(d.Key + " : " + d.Value); }

} //delete uom ArrayList deleteIds = new ArrayList(); deleteIds.Add(resAdd); bool resUnlink = rpcClient.unlink(dbname, userid, pwd, "product.uom. categ", "unlink", deleteIds.ToArray()); Console.WriteLine("Deleted record {0}", resUnlink); } } [XmlRpcUrl("http://localhost:8069/xmlrpc/common")] public interface IOpenErpLogin : IXmlRpcProxy { [XmlRpcMethod("login")] int login(string dbName, string dbUser, string dbPwd); } [XmlRpcUrl("http://localhost:8069/xmlrpc/object")] public interface IOpenErp : IXmlRpcProxy { [XmlRpcMethod("execute")] int create(string dbName, int userId, string pwd, string model, string m ethod, XmlRpcStruct fieldValues); [XmlRpcMethod("execute")] Object[] search(string dbName, int userId, string pwd, string model, str ing method, Object[] filters); [XmlRpcMethod("execute")] bool write(string dbName, int userId, string pwd, string model, string m ethod, int[] ids, XmlRpcStruct fieldValues); [XmlRpcMethod("execute")] bool unlink(string dbName, int userId, string dbPwd, string model, strin g method, object[] ids); [XmlRpcMethod("execute")] Object[] read(string dbName, int userId, string dbPwd, string model, str ing method, object[] ids, object[] fields); } }

Vous aimerez peut-être aussi