Ejemplo n.º 1
0
        public static User GetUser(string username)
        {
            Console.WriteLine("User requests : ");
            var rpcClient = new RPCClient("user_queue");

            Console.WriteLine(" [x] Requesting {0}", username);

            string jsonString = rpcClient.Call(username);

            Console.WriteLine(" [.] Got '{0}'", jsonString);

            if (jsonString == "null")
            {
                Console.WriteLine("Cet utilisateur n'existe pas");
                rpcClient.Close();
                return(null);
            }
            JObject userJson = JObject.Parse(jsonString);

            User user = new User();

            user.setPrenom(userJson["prenom"].ToString());
            user.setNom(userJson["nom"].ToString());
            user.setEmail(userJson["mail"].ToString());
            user.setUsername(userJson["username"].ToString());

            rpcClient.Close();
            Console.WriteLine("Connection réussie, bienvenue " + user.getUsername());
            return(user);
        }
Ejemplo n.º 2
0
 public static void Main()
 {
     Console.WriteLine(" [x] Requesting fib(30)");
     using (RPCClient rpcClient = new RPCClient()) {
         string response = rpcClient.Call("30");
         Console.WriteLine(" [.] Got '{0}'", response);
     }
 }
Ejemplo n.º 3
0
    public static void Main()
    {
        var rpcClient = new RPCClient();

        Console.WriteLine(" [x] Requesting fib(30)");
        var response = rpcClient.Call("30");

        Console.WriteLine(" [.] Got '{0}'", response);
        rpcClient.Close();
    }
Ejemplo n.º 4
0
    public static void Main()
    {
        var rpcClient = new RPCClient();

        Console.WriteLine(" [x] Requesting fib(30)");
        var response = rpcClient.Call("30");
        Console.WriteLine(" [.] Got '{0}'", response);

        rpcClient.Close();
    }
Ejemplo n.º 5
0
 public void ExceptionMehodCalled_ReturnsException()
 {
     using (var server = new RPCServer <string, string>(_factory, _converter, "integrationBroker", "rpcTestQueue"))
     {
         server.Start(Exception);
         using (var client = new RPCClient <string, string>(_factory, _converter, "integrationBroker", "rpcTestQueue"))
         {
             Assert.Throws <Exception>(() => client.Call("test"));
         }
     }
 }
Ejemplo n.º 6
0
        static void Main(string[] args)
        {
            RPCClient client = new RPCClient();

            if (client.Connection("127.0.0.1", 3000))
            {
                client.Disconn += Client_Disconn;
                client.MsgOut  += Client_MsgOut;
                client.RegModule(new Client());
                Console.Write("输入你的昵称:");
                if (client.Call <TalkService, bool>(p => p.IsLogIn(Console.ReadLine())))
                {
                    while (true)
                    {
                        string msg = Console.ReadLine();
                        client.Call <TalkService>(p => p.SendALL(msg));
                    }
                }
            }
        }
Ejemplo n.º 7
0
 static void Main(string[] args)
 {
     RPCClient client = new RPCClient();
     if (client.Connection("127.0.0.1", 3000))
     {
         client.Disconn += Client_Disconn;
         client.MsgOut += Client_MsgOut;
         client.RegModule(new Client());
         Console.Write("输入你的昵称:");
         if (client.Call<TalkService, bool>(p => p.IsLogIn(Console.ReadLine())))
         {
             while (true)
             {                       
                 string msg = Console.ReadLine();
                 client.Call<TalkService>(p => p.SendALL(msg));
               
             }
         }
     }
 }
Ejemplo n.º 8
0
        public void PingMehodCalled_RturnsArgument()
        {
            using (var server = new RPCServer <string, string>(_factory, _converter, "integrationBroker", "rpcTestQueue"))
            {
                server.Start(Ping);
                using (var client = new RPCClient <string, string>(_factory, _converter, "integrationBroker", "rpcTestQueue"))
                {
                    var result = client.Call("test");

                    Assert.AreEqual("test", result);
                }
            }
        }
        public bool ReleaseItem(ItemLine line)
        {
            bool result = false;

            if (line != null)
            {
                RPCClient rpcClient = new RPCClient();
                string    response  = rpcClient.Call(JsonConvert.SerializeObject(line), "stock_queue");
                rpcClient.Close();
                result = (Boolean.TryParse(response, out bool parsingRes) && parsingRes);
            }
            return(result);
        }
Ejemplo n.º 10
0
    public static void Main( string[] args )
    {
        var rpcClient = new RPCClient();

        var n = args.Length > 0 ? args[0] : "30";
        Console.WriteLine( " [x] Requesting fib({0})", n );
        var response = rpcClient.Call( n );
        Console.WriteLine( " [.] Got '{0}'", response );

        rpcClient.Close();

        Console.WriteLine( " Press [enter] to exit." );
        Console.ReadLine();
    }
Ejemplo n.º 11
0
        public static Bill CreateBill(User user, List <ItemLine> lines)
        {
            Bill result = null;

            if (user != null && lines != null)
            {
                RPCClient   rpcClient = new RPCClient();
                BillRequest request   = new BillRequest(lines, user);
                string      response  = rpcClient.Call(JsonConvert.SerializeObject(request), "bill_queue");
                rpcClient.Close();
                result = JsonConvert.DeserializeObject <Bill>(response);
            }
            return(result);
        }
        public static User GetUser(string username)
        {
            var rpcClient = new RPCClient();
            var response  = rpcClient.Call(username, "user_queue");

            rpcClient.Close();

            try
            {
                return(JsonConvert.DeserializeObject <User>(response));
            } catch (Exception)
            {
                return(null);
            }
        }
Ejemplo n.º 13
0
    public static void Main()
    {
        var rpcClient = new RPCClient();

        var message = "Hello World! " + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss ffff");

        Console.WriteLine(message);

        Console.WriteLine(rpcClient.Call(message));

        rpcClient.Close();

        Console.WriteLine(" Press [enter] to exit.");
        Console.ReadLine();
    }
Ejemplo n.º 14
0
    public static void Main(string[] args)
    {
        var rpcClient = new RPCClient();

        var n = args.Length > 0 ? args[0] : "30";

        Console.WriteLine(" [x] Requesting fib({0})", n);
        var response = rpcClient.Call(n);

        Console.WriteLine(" [.] Got '{0}'", response);

        rpcClient.Close();

        Console.WriteLine(" Press [enter] to exit.");
        Console.ReadLine();
    }
Ejemplo n.º 15
0
        public static ItemLine ReserveItem(string itemName, int quantity)
        {
            Console.WriteLine("Product requests : ");
            var rpcClient = new RPCClient("stock_queue");

            Console.WriteLine(" [x] Requesting {0}", itemName);

            string jsonString = rpcClient.Call(itemName);

            Console.WriteLine(" [.] Got '{0}'", jsonString);

            if (jsonString == "null")
            {
                Console.WriteLine("Cet objet n'existe pas");
                rpcClient.Close();
                return(null);
            }

            JObject  itemJson     = JObject.Parse(jsonString);
            ItemLine il           = new ItemLine();
            Item     item         = new Item(itemName, double.Parse(itemJson["prix"].ToString(), CultureInfo.InvariantCulture));
            int      lineQuantity = Int32.Parse(itemJson["quantité"].ToString());

            il.setItem(item);
            il.setQuantite(lineQuantity);

            StreamReader file  = new StreamReader("C:\\Users\\aajin\\source\\repos\\TPSOA\\StockManager\\product.json", true);
            String       json  = file.ReadToEnd();
            var          obj   = JObject.Parse(json);
            int          count = 0;

            //On parcours le JSON pour récupérer la ligne de l'item
            foreach (JObject element in obj["product"])
            {
                string n = element["nom"].ToString();
                if (itemName == n)
                {
                    break;
                }
                count++;
            }
            obj["product"][count]["quantité"] = (int)obj["product"][count]["quantité"] - quantity;
            file.Close();

            File.WriteAllText("C:\\Users\\aajin\\source\\repos\\TPSOA\\StockManager\\product.json", obj.ToString());
            return(il);
        }
        public ItemLine ReserveItem(int quantity, string name)
        {
            ItemLine result = null;

            if (quantity > 0)
            {
                RPCClient rpcClient = new RPCClient();
                JObject   message   = new JObject()
                {
                    { "quantity", quantity },
                    { "name", name }
                };
                string response = rpcClient.Call(message.ToString(), "stock_queue");
                rpcClient.Close();
                result = JsonConvert.DeserializeObject <ItemLine>(response);
            }
            return(result);
        }
Ejemplo n.º 17
0
        public ActionResult <string> Get(int id)
        {
            try
            {
                RPCClient rpcClient = new RPCClient();

                Console.WriteLine(" [x] Requesting fib({0})", id);
                var response = rpcClient.Call(id.ToString());
                Console.WriteLine(" [.] Got '{0}'", response);

                rpcClient.Close();
                return(response);
            }
            catch
            {
                return("404 error");
            }
        }
Ejemplo n.º 18
0
        public TelaPrincipal(string myName, string myIP, string myPort, Action <string> showErrors)
        {
            try
            {
                // objeto para confirmar se os outros estão on
                checkOn   = new RPCClient(myIP, 5672, myName, "confirmarOnline");
                beCheckOn = new RPCReceive(myIP, 5672, getEstado, getContatoAtual);
                // Thread checkOnCallBackThread = new Thread(() => checkOn.CallBack("confirmarOnline"));
                var condicoes = checkOn.Call(myName, myName, "confirmarOnline");
                if (condicoes != null && condicoes.estado == true)
                {
                    throw new Exception("Nome de usuario ja escolhido!");
                }
                // checkOnCallBackThread.Start();
                Thread beCheckOnThread = new Thread(() => beCheckOn.Receive(myName, "confirmarOnline"));
                beCheckOnThread.Start();
                // objeto que manda mensagens quando o destinatário está offline
                sendOffline = new SendOffline(myIP, myPort);
                // objeto que recebe mensagens enviadas enquanto offline
                receiveOffline = new ReceiveOffline(myIP, myPort, ReceiveMessage);
                // inicia thread que irá receber todas as mensagens do tópico *.Nome
                Thread receiveOfflineThread = new Thread(() => receiveOffline.Receive("*." + myName));
                receiveOfflineThread.Start();

                //iniciar servidor grpc
                _com = new GrpcMensageiroCom(
                    myName, myIP, myPort, ReceiveMessage, InsertMessage
                    );
                comThread = new Thread(() => _com.IniciarServidor());
                comThread.Start();
            }
            catch (System.Exception e)
            {
                showErrors(e.Message.ToString());
                // showErrors("IP ou Porta inválidos!");
                throw;
            }
            MyIP       = myIP;
            MyPort     = myPort;
            MyName     = myName;
            ShowErrors = showErrors;
            contatos   = new List <Contato>();
            batePapo   = new Dictionary <string, List <Mensagem> >();
        }
Ejemplo n.º 19
0
    public static void Main(string[] args)
    {
        while (true)
        {
            var rpcClient = new RPCClient();

            var n = args.Length > 0 ? args[0] : "30";
            Console.WriteLine(" [x] Requesting fib({0})", n);
            var response = rpcClient.Call(n);
            Console.WriteLine(" [.] Got '{0}'", response);
            rpcClient.Close();

            Console.WriteLine(" Press [enter] to exit, any other key to continue with a new request.");
            if (Console.ReadKey().Key == ConsoleKey.Enter)
            {
                break;
            }
        }
    }
Ejemplo n.º 20
0
        static void Main(string[] args)
        {
            //args = new string[]{
            //    "First message.",
            //    "Second message..",
            //    "Third message...",
            //    "Fourth message....",
            //    "Fifth message.....",
            //};
            //Publisher.DoSend();
            //EmitLogs.DoSend(args);

            var rpcClient = new RPCClient();

            Console.WriteLine(" [x] Requesting fib(30)");
            var response = rpcClient.Call("30");

            Console.WriteLine(" [.] Got '{0}'", response);

            rpcClient.Close();
        }
Ejemplo n.º 21
0
        static void Main(string[] args)
        {
            var rpcClient = new RPCClient();

            var entity = new ProjectSend.RealtyIntroduce();

            entity.AreaCode = "B024";
            entity.RealtyId = 945;


            var outputMsg = Newtonsoft.Json.JsonConvert.SerializeObject(entity);

            var inputMsg = rpcClient.Call(outputMsg, "koofang.RealtyIntroduce.details", "details");

            Console.WriteLine(inputMsg);
            rpcClient.Close();


            rpcClient = new RPCClient();
            var inputEntity = Newtonsoft.Json.JsonConvert.DeserializeObject <ProjectSend.RealtyIntroduce>(inputMsg);

            if (inputEntity.RentRealtyIntroduceData != null)
            {
                inputEntity.RentRealtyIntroduceData.RealtyTitle = "aaaaaaaaaaaaa";
                inputEntity.RentRealtyIntroduceData.RentPoint   = "aaaaaaaa";
            }
            if (inputEntity.SaleRealtyIntroduceData != null)
            {
                inputEntity.SaleRealtyIntroduceData.RealtyTitle = "aaaaaaaaaaaa";
            }

            outputMsg = Newtonsoft.Json.JsonConvert.SerializeObject(inputEntity);

            inputMsg = rpcClient.Call(outputMsg, "koofang.RealtyIntroduce.modify", "modify");
            Console.WriteLine(inputMsg);

            Console.ReadLine();
            rpcClient.Close();
        }
Ejemplo n.º 22
0
        static void Main(string[] args)
        {
            RPCClient client = new RPCClient();

            if (client.Connection("127.0.0.1", 9952))
            {
                client.OutTime  = 2000;
                client.Disconn += Client_Disconn;
                client.RegModule(new ClientCall());

                Console.WriteLine("input userName:"******"123123")))
                {
                    Console.WriteLine("LogOn Is OK");

                    while (true)
                    {
                        string msg = Console.ReadLine();

                        client.Call <ServerClass>(p => p.SendAll(msg));


                        DateTime time = client.Call <ServerClass, DateTime>(p => p.GetServerTime());

                        Console.WriteLine("Serve time is " + time);

                        int value = 0;

                        client.Call <ServerClass>(p => p.OutRandom(out value));

                        Console.WriteLine("Random value is " + value);

                        Data x = new Data()
                        {
                            Name  = "II",
                            Value = 0
                        };

                        var v = client.Call <ServerClass, Data>(p => p.Return(x));

                        Console.WriteLine("Data Name " + v.Name);

                        var l = client.Call <ServerClass, int>(p => p.RecComputer(10)); //这叫递归吗? 代价太大,深度最好别超过5层 实在没办法记得设置outtime

                        Console.WriteLine("Rec computer value:" + l);

                        var server = client.GetRPC <ServerClass>();

                        var ary = server.array(new string[] { "123", "123" }); //Array + string


                        System.Diagnostics.Stopwatch stop = new System.Diagnostics.Stopwatch();
                        stop.Start();
                        //int j = 0;
                        for (int i = 0; i < 10000; i++)
                        {
                            x = server.Return(x);
                        }
                        stop.Stop();
                        Console.WriteLine("Time:" + stop.ElapsedMilliseconds + " J:" + x.Value);
                    }
                }
            }
        }
Ejemplo n.º 23
0
        static void Main(string[] args)
        {


            RPCClient client = new RPCClient();
            if (client.Connection("127.0.0.1", 9952))
            {
                client.OutTime = 2000;
                client.Disconn += Client_Disconn;
                client.RegModule(new ClientCall());

                Console.WriteLine("input userName:"******"123123")))
                {
                    Console.WriteLine("LogOn Is OK");

                    while (true)
                    {
                        string msg = Console.ReadLine();

                        client.Call<ServerClass>(p => p.SendAll(msg));


                        DateTime time = client.Call<ServerClass, DateTime>(p => p.GetServerTime());

                        Console.WriteLine("Serve time is " + time);

                        int value = 0;

                        client.Call<ServerClass>(p => p.OutRandom(out value));

                        Console.WriteLine("Random value is " + value);

                        Data x = new Data()
                        {
                            Name = "II",
                            Value = 0
                        };

                        var v = client.Call<ServerClass, Data>(p => p.Return(x));

                        Console.WriteLine("Data Name " + v.Name);

                        var l = client.Call<ServerClass, int>(p => p.RecComputer(10)); //这叫递归吗? 代价太大,深度最好别超过5层 实在没办法记得设置outtime

                        Console.WriteLine("Rec computer value:" + l);

                        var server = client.GetRPC<ServerClass>();

                        var ary = server.array(new string[] { "123", "123" }); //Array + string


                        System.Diagnostics.Stopwatch stop = new System.Diagnostics.Stopwatch();
                        stop.Start();
                        //int j = 0;
                        for (int i = 0; i < 10000; i++)
                        {
                            x=server.Return(x);
                        }
                        stop.Stop();
                        Console.WriteLine("Time:" + stop.ElapsedMilliseconds + " J:" + x.Value);



                    }

                }

            }

        }
Ejemplo n.º 24
0
        static void Main(string[] args)
        {
            string option = string.Empty;

            while (!option.Equals("0"))
            {
                Console.Clear();
                Console.WriteLine("RABBIT MQ");
                Console.WriteLine("\n");

                Console.WriteLine("Menú Principal");
                Console.WriteLine();

                Console.WriteLine("1. Envío básico.");
                Console.WriteLine("2. Recepción básica.");
                Console.WriteLine("----------------------------------------------------------------------------------------------------------------------");

                Console.WriteLine("3. Envío de mensajes a dos o más colas.");
                Console.WriteLine("4. Recepción de mensajes desde dos o más colas de trabajo.");
                Console.WriteLine("----------------------------------------------------------------------------------------------------------------------");

                Console.WriteLine("5. Envío de un mensaje a un intercambiador y no directamente a una cola (Transmite mensajes a todos los consumidores).");
                Console.WriteLine("6. Recepción de mensajes desde una o cualquier cola enlazada con el intercambiador especificado.");
                Console.WriteLine("----------------------------------------------------------------------------------------------------------------------");

                Console.WriteLine("7. Envío de un mensaje con clave de enrutamiento. (Filtrar mensajes de acuerdo a su gravedad).");
                Console.WriteLine("8. Recepción de mensajes desde una cola enlazada con la clave de enrutamiento.");
                Console.WriteLine("----------------------------------------------------------------------------------------------------------------------");

                Console.WriteLine("9. Envío de un mensaje con clave de enrutamiento. (Filtrar mensajes de acuerdo a su gravedad).");
                Console.WriteLine("101 - 102 - 103 - 104. Recepción de mensajes desde una colas enlazada con la clave de enrutamiento.");
                Console.WriteLine("----------------------------------------------------------------------------------------------------------------------");

                Console.WriteLine("11. Enviando solicitud y esperar como respuesta la serie de fibonacci del número 30.");
                Console.WriteLine("12. Servidor esperando solicitudes para responder la serie de fibonacci solicitada.");
                Console.WriteLine("----------------------------------------------------------------------------------------------------------------------");

                Console.WriteLine("0. Salir del Programa.");

                option = Console.ReadLine();

                switch (option)
                {
                case "1":
                    BasicCommunication.Send();
                    break;

                case "2":
                    BasicCommunication.Receive();
                    break;

                case "3":
                    NewTask.Send(new string[] { "Primer mensaje que emula procesar durante 1 segundo." });
                    NewTask.Send(new string[] { "Segundo mensaje que emula procesar durante 2 segundos.." });
                    NewTask.Send(new string[] { "Tercer mensaje que emula procesar durante 1 segundo." });
                    break;

                case "4":
                    Worker.Receive();
                    break;

                case "5":
                    EmitLogFanout.Send(new string[] { "Enviando un mensaje al intercambiador, ahora no se envía directamente a la cola. " });
                    break;

                case "6":
                    ReceiveLogsFanout.Receive();
                    break;

                case "7":
                    EmitLogDirect.Send(new string[] { "info", "Mensaje de información." });
                    EmitLogDirect.Send(new string[] { "warning", "Mensaje de advertencia." });
                    EmitLogDirect.Send(new string[] { "error", "Mensaje de error." });
                    EmitLogDirect.Send(new string[] { "personalizado", "Mensaje de clasificación personalizado." });
                    break;

                case "8":
                    ReceiveLogsDirect.Receive(new string[] { "warning", "error", "personalizado" });
                    break;

                case "9":
                    EmitLogTopic.Send(new string[] { "kern.critical", "un mensaje error crítico del kernel." });
                    EmitLogTopic.Send(new string[] { "kern.*", "Mensaje general del kernel." });
                    EmitLogTopic.Send(new string[] { "*.critital", "Mensaje crítico sin importar de quien sea." });
                    break;

                case "101":
                    ReceiveLogsTopic.Receive(new string[] { "#" });
                    break;

                case "102":
                    ReceiveLogsTopic.Receive(new string[] { "kern.*" });
                    break;

                case "103":
                    ReceiveLogsTopic.Receive(new string[] { "*.critical" });
                    break;

                case "104":
                    ReceiveLogsTopic.Receive(new string[] { "kern.*", "*.critical" });
                    break;

                case "11":
                    RPCClient rpcClient = new RPCClient();
                    Console.WriteLine(" [x] Solicitando fib(30)...");
                    var response = rpcClient.Call("30");
                    Console.WriteLine(" [.] Recibido {0}", response);
                    Console.ReadLine();
                    rpcClient.Close();
                    break;

                case "12":
                    RPCServer rpcServer = new RPCServer();
                    rpcServer.Server();
                    break;

                default:
                    break;
                }
            }
        }