Exemplo n.º 1
0
        static RpcRecord GetPartner(RpcConnection rpcConnection)
        {
            var rpcContext = new RpcContext(rpcConnection, "res.partner");
            var data       = rpcContext.Execute(true);

            return(data.FirstOrDefault());
        }
 public async void AddMessage(string message, [RpcCaller] RpcConnection caller)
 {
     // RPC method called by the server to add a message that has been
     // sent by the server or another client to the message list
     await RunAsync(() =>
                    Messages.Add($"{caller.Id} said: " + message));
 }
Exemplo n.º 3
0
        /// <summary>
        /// Creates a new Discord RPC Client using the steam uri scheme.
        /// </summary>
        /// <param name="applicationID">The ID of the application created at discord's developers portal.</param>
        /// <param name="steamID">The steam ID of the app. This is used to launch Join / Spectate through steam URI scheme instead of manual launching</param>
        /// <param name="registerUriScheme">Should a URI scheme be registered for Join / Spectate functionality? If false, the Join / Spectate functionality will be disabled.</param>
        /// <param name="pipe">The pipe to connect too. -1 for first available pipe.</param>
        /// <param name="client">The pipe client to use and communicate to discord through</param>
        /// <param name="logger">The logger used to report messages. Its recommended to assign here so it can report the results of RegisterUriScheme.</param>
        public DiscordRpcClient(string applicationID, string steamID, bool registerUriScheme, int pipe, INamedPipeClient client, ILogger logger = null)
        {
            //Store our values
            ApplicationID          = applicationID;
            SteamID                = steamID;
            HasRegisteredUriScheme = registerUriScheme;
            ProcessID              = System.Diagnostics.Process.GetCurrentProcess().Id;
            _pipe   = pipe;
            _logger = logger == null ? new NullLogger() : logger;

            //If we are to register the URI scheme, do so.
            //The UriScheme.RegisterUriScheme function takes steamID as a optional parameter, its null by default.
            //   this means it will handle a null steamID for us :)
            if (registerUriScheme)
            {
                UriScheme.RegisterUriScheme(_logger, applicationID, steamID);
            }

            //Create the RPC client
            connection = new RpcConnection(ApplicationID, ProcessID, TargetPipe, client)
            {
                ShutdownOnly = _shutdownOnly
            };
            connection.Logger = this._logger;
        }
Exemplo n.º 4
0
        private static RpcClientProxy GetProxyInner <T>(ServerUri solvedUri, ResolvableUri contextUri)
        {
            RpcClientInterface intf = RpcClientInterfaceFactory <T> .GetOne();

            if (_channels.Count == 0)
            {
                throw new Exception("You *MUST* Register at least 1 client channel at first");
            }

            RpcClientChannel channel;

            if (!_channels.TryGetValue(solvedUri.Protocol, out channel))
            {
                throw new Exception(string.Format("{0} protocol:'{1}' not found", solvedUri.ToString(), solvedUri.Protocol));
            }

            ResolvableUri r    = contextUri as ResolvableUri;
            string        role = r != null ? r.Service : "";
            RpcConnection conn = GetConnection(solvedUri, role);

            RpcClientProxy proxy = new RpcClientProxy(conn, intf, contextUri);

            proxy.Timeout = channel.Timeout;
            return(proxy);
        }
 public async void OnConnected(RpcConnection connection)
 {
     await RunAsync(() =>
     {
         Messages.Add($"Client connected: {connection.Id}");
         RaisePropertyChanged(nameof(ClientCount));
     });
 }
 public async void OnDisconnected(RpcConnection connection, DisconnectEventArgs args)
 {
     await RunAsync(() =>
     {
         Messages.Add($"Client disconnected: {args.Connection.Id} (Reason: {args.Reason})");
         RaisePropertyChanged(nameof(ClientCount));
     });
 }
Exemplo n.º 7
0
        static bool EditPartner(RpcConnection rpcConnection)
        {
            var partnerService = new PartnerService(rpcConnection);
            var partner        = partnerService.Get(46);

            partner.Email     = "*****@*****.**";
            partner.CountryId = 61;
            return(partnerService.Write(46, partner));
        }
        public async void BroadcastMessage(string message, [RpcCaller] RpcConnection caller)
        {
            // RPC method called by a client to broadcast a message
            // to all other connected clients
            await RunAsync(() =>
                           Messages.Add($"{caller.Id} said: " + message));

            Server.ClientsExcept(caller.Id).AddMessage(message);
        }
Exemplo n.º 9
0
        public void RpcTest()
        {
            var msg = new Message();

            msg.Init(new ArrayPoolSegmentFactory(), false);
            msg.PreAllocate(10);
            msg.Allocate(1); // HACK allocate root pointer after pre-alloc
            msg.SetRoot(new Rpc.Message(msg)
            {
                which = Rpc.Message.Union.join,
                join  = new Join(msg)
                {
                    questionId = 123
                }
            });

            Assert.Equal(
                new StructPointer
            {
                Type         = PointerType.Struct,
                WordOffset   = 0,
                DataWords    = 1,
                PointerWords = 1
            }.ToString(),
                new Pointer(msg.Segments[0][0 | Word.unit]).ToString());

            //var ms = new MemoryStream();
            //msg.SerializeAsync(ms).Wait();

            //msg.Dispose();

            //ms.Position = 0;

            var ms2 = new MemoryStream();
            var rc  = new RpcConnection();

            rc.Init(null, ms2, null);
            rc.Process(msg);

            ms2.Position = 0;
            var msg2    = Message.DecodeAsync(ms2).Result;
            var rpcMsg2 = msg2.GetRoot <Rpc.Message>();

            Assert.Equal(
                Rpc.Message.Union.unimplemented,
                rpcMsg2.which);
            Assert.Equal(
                Rpc.Message.Union.join,
                rpcMsg2.unimplemented.which);
            Assert.Equal(
                123U,
                rpcMsg2
                .unimplemented
                .join
                .questionId);
        }
Exemplo n.º 10
0
        /// <summary>
        /// Creates a new Discord RPC Client which can be used to send Rich Presence and receive Join / Spectate events. This constructor exposes more advance features such as custom NamedPipeClients and Loggers.
        /// </summary>
        /// <param name="applicationID">The ID of the application created at discord's developers portal.</param>
        /// <param name="pipe">The pipe to connect too. If -1, then the client will scan for the first available instance of Discord.</param>
        /// <param name="logger">The logger used to report messages. If null, then a <see cref="NullLogger"/> will be created and logs will be ignored.</param>
        /// <param name="autoEvents">Should events be automatically invoked from the RPC Thread as they arrive from discord?</param>
        /// <param name="client">The pipe client to use and communicate to discord through. If null, the default <see cref="ManagedNamedPipeClient"/> will be used.</param>
        public DiscordRpcClient(string applicationID, int pipe = -1, ILogger logger = null, bool autoEvents = true, INamedPipeClient client = null)
        {
            //Make sure appID is NOT null.
            if (string.IsNullOrEmpty(applicationID))
            {
                throw new ArgumentNullException("applicationID");
            }

            //Ensure we actually have json ahead of time. If statement is pointless, but its there just to ensure there is no unused warnings.
            var jsonConverterType = typeof(Newtonsoft.Json.JsonConverter);

            if (jsonConverterType == null)
            {
                throw new Exception("JsonConverter Type Not Found");
            }

            //Store the properties
            ApplicationID          = applicationID.Trim();
            TargetPipe             = pipe;
            ProcessID              = System.Diagnostics.Process.GetCurrentProcess().Id;
            HasRegisteredUriScheme = false;
            AutoEvents             = autoEvents;
            SkipIdenticalPresence  = true;

            //Validate the process id
            if (ProcessID < 10)
            {
                throw new InvalidOperationException("Process ID must be greater than 10.");
            }

            //Prepare the logger
            _logger = logger ?? new NullLogger();

            //Create the RPC client, giving it the important details
            connection = new RpcConnection(ApplicationID, ProcessID, TargetPipe, client ?? new ManagedNamedPipeClient(), autoEvents ? 0 : 128U)
            {
                ShutdownOnly = _shutdownOnly,
                Logger       = _logger
            };

            //Subscribe to its event
            connection.OnRpcMessage += (sender, msg) =>
            {
                if (OnRpcMessage != null)
                {
                    OnRpcMessage.Invoke(this, msg);
                }

                if (AutoEvents)
                {
                    ProcessMessage(msg);
                }
            };
        }
Exemplo n.º 11
0
        // İş Ortağı Oluşturma
        static RpcRecord CreatePartner(RpcConnection conn)
        {
            // Ref alanından kontak ara
            var rpcContext = new RpcContext(conn, "res.partner");

            rpcContext
            .RpcFilter
            .Or()     // burada tanımlı OR operatörü odoo'nun normal kullanımında olduğu gibi önündeki koşulu birbirine bağlar belirtilmez ise AND operatörü gibi çalışır
            .Equal("company_id", _companyId)
            .Equal("company_id", false)
            .Equal("ref", "TO9930914");

            /*
             * Yukarıdaki koşulun açılımı
             * if (company_id == 1 or company_id == false) and ref= "TO9930914")
             */

            rpcContext
            .AddField("id");
            var data    = rpcContext.Execute(true, limit: 1);
            var partner = data.FirstOrDefault();

            if (partner != null)
            {
                return(partner);
            }

            //İl
            var stateId = GetCountryStateByName(conn, "İstanbul");

            //res.partner - Create
            RpcRecord record = new RpcRecord(conn, "res.partner", -1, new List <RpcField>
            {
                new RpcField {
                    FieldName = "name", Value = "İsmail Eski"
                },
                new RpcField {
                    FieldName = "street", Value = "Merkez"
                },
                new RpcField {
                    FieldName = "street2", Value = "Merkez Mh."
                },
                new RpcField {
                    FieldName = "state_id", Value = stateId
                },
                new RpcField {
                    FieldName = "vat", Value = "TR1234567890"
                }
            });

            record.Save();
            return(record);
        }
 public async void OnDisconnected(RpcConnection connection, DisconnectEventArgs args)
 {
     await RunAsync(async() =>
     {
         Messages.Add($"Disconnected from {connection.Id} (Reason: {args.Reason})");
         await Task.Delay(2000);
         if (_frame.CanGoBack)
         {
             _frame.GoBack();
         }
     });
 }
Exemplo n.º 13
0
        static int CreatePartnerService(RpcConnection rpcConnection)
        {
            var leslie = new Partner
            {
                Name   = "Leslie Morel",
                Active = true,
                Street = "Calle Rafael",
            };
            var partnerService = new PartnerService(rpcConnection);
            var result         = partnerService.Create(leslie);

            return(result);
        }
Exemplo n.º 14
0
Arquivo: test.cs Projeto: demonxjj/TCE
        public static ServerProxy create(string host, int port, bool ssl_enable)
        {
            int type = RpcConstValue.CONNECTION_SOCK;

            if (ssl_enable)
            {
                type |= RpcConstValue.CONNECTION_SSL;
            }
            RpcConnection conn = RpcCommunicator.instance().createConnection(type, host, port);
            ServerProxy   prx  = new ServerProxy(conn);

            return(prx);
        }
Exemplo n.º 15
0
        static RpcRecord CreatePartner(RpcConnection rpcConnection, string model, int?id)
        {
            var partner = new Partner()
            {
                Name   = "Juan Carlos",
                Street = "Calle Sana"
            };

            var recordPartner = partner.ToRpcRecord(rpcConnection, model, id);

            recordPartner.Save();
            return(recordPartner);
        }
Exemplo n.º 16
0
        //Sale Order - Oluşturma
        static RpcRecord WriteSaleOrder(RpcConnection conn)
        {
            //Partner
            var partner = CreatePartner(conn);
            var rnd     = new Random();

            var orderLine = GetSaleOrderLine(conn);

            RpcRecord record = new RpcRecord(conn, "sale.order", -1, new List <RpcField>
            {
                new RpcField {
                    FieldName = "company_id", Value = _companyId
                },
                new RpcField {
                    FieldName = "currency_id", Value = 31
                },
                new RpcField {
                    FieldName = "date_order", Value = "2021-01-28"
                },                                                            // posible
                new RpcField {
                    FieldName = "name", Value = "Örnek Sipariş No:" + rnd.Next(1, 10000).ToString()
                },
                new RpcField {
                    FieldName = "partner_id", Value = partner.Id
                },
                new RpcField {
                    FieldName = "partner_invoice_id", Value = partner.Id
                },
                new RpcField {
                    FieldName = "partner_shipping_id", Value = partner.Id
                },
                new RpcField {
                    FieldName = "picking_policy", Value = "one"
                },
                new RpcField {
                    FieldName = "pricelist_id", Value = 1
                },
                new RpcField {
                    FieldName = "warehouse_id", Value = 1
                },
                new RpcField {
                    FieldName = "state", Value = "sale"
                },                                                 //Onaylı Sipariş ise
                new RpcField {
                    FieldName = "order_line", Value = orderLine.ToArray()
                }
            });

            record.Save();
            return(record);
        }
Exemplo n.º 17
0
        //İl Arama
        static int GetCountryStateByName(RpcConnection conn, string stateName)
        {
            var rpcContext = new RpcContext(conn, "res.country.state");

            rpcContext
            .RpcFilter.Equal("name", stateName);

            rpcContext
            .AddField("id");

            var data = rpcContext.Execute(limit: 1);

            return(data.FirstOrDefault().Id);
        }
Exemplo n.º 18
0
        public override void OnTransactionStart(RpcServerContext context)
        {
            //if (context.ContextUri) {
            RpcConnection        conn = null;
            RpcClientTransaction tx   = conn.CreateTransaction(context.Request);

            tx.SendRequest(
                delegate() {
                context.Return(tx.Response);
            },
                -1

                );
            //}
        }
Exemplo n.º 19
0
        static void Main(string[] args)
        {
            IConfiguration config = new ConfigurationBuilder()
                                    .AddJsonFile("appsettings.json", true, true)
                                    .Build();

            var rpcConnnectionSettings = new RpcConnectionSetting();

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

            //Connection
            var odooConn = new RpcConnection(rpcConnnectionSettings);

            //SaleOrder
            WriteSaleOrder(odooConn);
        }
Exemplo n.º 20
0
        //Ürün Arama
        static RpcRecord GetSearchProductByDefaultCode(RpcConnection conn, string defaultCode)
        {
            var rpcContext = new RpcContext(conn, "product.product");

            rpcContext
            .RpcFilter
            .Or()
            .Equal("company_id", _companyId)
            .Equal("company_id", false)
            .Equal("default_code", defaultCode);

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

            var data = rpcContext.Execute(true, limit: 1);

            return(data.FirstOrDefault());
        }
Exemplo n.º 21
0
 public DiscordRpcClient(
     string applicationID,
     string steamID,
     bool registerUriScheme,
     int pipe,
     INamedPipeClient client)
 {
     this.ApplicationID          = applicationID;
     this.SteamID                = steamID;
     this.HasRegisteredUriScheme = registerUriScheme;
     this.ProcessID              = Process.GetCurrentProcess().Id;
     this._pipe = pipe;
     if (registerUriScheme)
     {
         UriScheme.RegisterUriScheme(applicationID, steamID, (string)null);
     }
     this.connection = new RpcConnection(this.ApplicationID, this.ProcessID, this.TargetPipe, client)
     {
         ShutdownOnly = this._shutdownOnly
     };
     this.connection.Logger = this._logger;
 }
Exemplo n.º 22
0
        static void Main(string[] args)
        {
            IConfiguration config = new ConfigurationBuilder()
                                    .AddJsonFile("appsettings.json", true, true)
                                    .Build();

            var rpcConnnectionSettings = new RpcConnectionSetting();

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

            //Connection
            var odooConn = new RpcConnection(rpcConnnectionSettings);

            //ExecutePartnerService(odooConn);

            //var result =  CreatePartnerService(odooConn);
            //if (result > 0)
            //    Console.WriteLine("Successs");

            var result = EditPartner(odooConn);

            //var result = new PartnerService(odooConn).Remove(50);
            Console.ReadLine();
        }
        public static RpcRecord ToRpcRecord <TEntity>(this TEntity entity, RpcConnection rpcConnection, string model, int?id) where TEntity : class
        {
            var fields = new List <RpcField>();

            foreach (var property in entity.GetType().GetProperties())
            {
                var value = property.GetValue(entity).OdooDataFormat();


                if (value != null)
                {
                    var field = new RpcField()
                    {
                        FieldName = property.Name.ToLowerAndSplitWithUnderscore(),
                        Value     = value
                    };
                    fields.Add(field);
                }
            }

            var record = new RpcRecord(rpcConnection, model, id, fields);

            return(record);
        }
 public ClientSideServerProxy(RpcConnection connection)
 {
     _connection = connection;
 }
Exemplo n.º 25
0
        //private Segment CreateSegment()
        //{
        //  var msg = new Message();
        //  var seg = new Segment().Init(msg, new byte[4096]);

        //}

        public void RpcStrawman()
        {
            RpcConnection con = null;

            var service = con.GetMain <global::Schema.ITestInterface>();
        }
Exemplo n.º 26
0
        // RPC events

        public void OnConnected(RpcConnection connection)
        {
        }
Exemplo n.º 27
0
 public PartnerService(RpcConnection connection) : base(connection, OdooDbSets.Contacts)
 {
 }
Exemplo n.º 28
0
        public async void OnDisconnected(RpcConnection connection)
        {
            GameClientInfo playerInfo;

            if (_players.TryGetValue(connection.Id, out playerInfo))
            {
                // Connection unexpectedly closed without correctly leaving the game
                await _gameServer.LeaveAsync(playerInfo.PlayerId);
                _players.Remove(connection.Id);
            }
        }
Exemplo n.º 29
0
Arquivo: test.cs Projeto: demonxjj/TCE
        //-- interface proxy --

        public ServerProxy(RpcConnection conn)
        {
            this.conn = conn;
        }
Exemplo n.º 30
0
Arquivo: test.cs Projeto: demonxjj/TCE
        //-- interface proxy --

        public ITerminalGatewayServerProxy(RpcConnection conn)
        {
            this.conn = conn;
        }
 public ServerSideClientProxy(GameClientInfo clientInfo, RpcConnection connection)
 {
     PlayerInfo = clientInfo;
     _connection = connection;
 }
Exemplo n.º 32
0
        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();
        }
Exemplo n.º 33
0
 internal RpcClientProxy(RpcConnection conn, RpcClientInterface intf, ResolvableUri toUri)
 {
     _conn             = conn;
     _contextUri       = toUri;
     _serviceInterface = intf;
 }
Exemplo n.º 34
0
Arquivo: test.cs Projeto: demonxjj/TCE
        //-- interface proxy --

        public ITerminalProxy(RpcConnection conn)
        {
            this.conn = conn;
        }