コード例 #1
0
ファイル: RpcService.cs プロジェクト: ewin66/Safety-JM-Server
        /// <summary>
        /// 启动RPC服务器
        /// </summary>
        /// <returns></returns>
        public static bool StartRpcServer(string remoteIp, int remotePort, string localIp, int localPort)
        {
            _remoteIp   = remoteIp;
            _remotePort = remotePort;
            _localIp    = localIp;
            _localPort  = localPort;

            System.Reflection.Assembly.Load("Sys.Safety.WebApi, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null");
            int rpcModel = Basic.Framework.Configuration.ConfigurationManager.FileConfiguration.GetInt("RpcModel", 1);

            if (rpcModel == 1)
            {
                _rpcModel = RpcModel.WebApiModel;
            }
            else if (rpcModel == 2)
            {
                _rpcModel = RpcModel.gRPCModel;
            }

            _client = RpcFactory.CreateRpcClient(_rpcModel, _remoteIp, _remotePort);
            _server = RpcFactory.CreateRpcServer(_rpcModel);
            _server.RegistCallback(OnRpcMessageArrived);

            _server.Start(_localIp, _localPort);
            return(true);
        }
コード例 #2
0
 public RpcThreadPayload(RpcModel model, int startIndex, int requestSize, int threadCountSize)
 {
     StartIndex      = startIndex;
     Model           = model;
     RequestSize     = requestSize;
     ThreadCountSize = threadCountSize;
 }
コード例 #3
0
        static async Task Main(string[] args)
        {
            var rabbitBus = RabbitHutch.CreateBus(RabbitConfig, _ => { });

            var logger = new LoggerConfiguration()
                         .WriteTo.Console()
                         .CreateLogger();

            var bus = new BusModel(rabbitBus.Advanced);
            var rpc = new RpcModel(rabbitBus.Advanced);

            var logic = new BusinessLogic(bus, rpc, logger);

            await rpc.RegisterHandlerAsync("toxon.micro.router.register", async (requestMessage, _) =>
            {
                var request = JsonMessage.Read <RegisterRouteRequest>(requestMessage);

                var response = await logic.RegisterRoute(request);

                return(JsonMessage.Write(new RegisterRouteResponse {
                    Done = response
                }));
            });

            await bus.RegisterHandlerAsync("toxon.micro.router.route", (message, _) => logic.RouteBusMessage(message));

            await rpc.RegisterHandlerAsync("toxon.micro.router.route", (message, _) => logic.RouteRpcMessage(message));

            logic.Start();

            Console.WriteLine("Running Router... press enter to exit!");
            Console.ReadLine();
        }
コード例 #4
0
ファイル: Program.cs プロジェクト: gdimazp/OdooXmlRpc
        static void Main(string[] args)
        {
            IConfiguration config = new ConfigurationBuilder()
                                    .AddJsonFile("appsettings.json", true, true)
                                    .Build();

            var rpcConnnectionSettings = new RpcConnectionSetting();

            config.GetSection("OdooConnection").Bind(rpcConnnectionSettings);

            var odooConn = new RpcConnection(rpcConnnectionSettings);


            var rpcContext = new RpcContext(odooConn, "res.partner");

            rpcContext
            .AddField("id")
            .AddField("name");

            var data = rpcContext.Execute(false);

            var partner_1 = new RpcModel("res.partner", odooConn);

            var method_response = partner_1.CallMethod("find_or_create", new object[1] {
                "*****@*****.**"
            });


            //res.partner - Write
            var partner = new RpcContext(odooConn, "res.partner");

            partner.AddFields(new[] { "name", "phone", "email" });

            var results = partner.Execute(false, order: "id desc");

            //var results = partner.Execute(false, offset:1, limit:2, order: "id desc");
            foreach (var result in results)
            {
                result.SetFieldValue("phone", "55-66-666");
                result.Save();
            }

            //res.partner - Create
            RpcRecord record = new RpcRecord(odooConn, "stock.quant", -1, new List <RpcField>
            {
                new RpcField {
                    FieldName = "product_id"
                },
                new RpcField {
                    FieldName = "reserved_quantity"
                },
                new RpcField {
                    FieldName = "location_id"
                }
            });

            record.SetFieldValue("product_id", 52);
            record.SetFieldValue("reserved_quantity", 333);
            record.SetFieldValue("location_id", 8);
            record.Save();
        }