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); }
void Close(byte[] serHandle) { var retCode = new CloseServiceHandle(RPCBind).EXEC(serHandle); retCode = new CloseServiceHandle(RPCBind).EXEC(SCHandle); RPCClient.Close(); }
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(); }
public static string RunGamesRemote(dynamic JsonParams, List <double> Vector, int RandSeed) { try { //dynamic JsonMessage = new JObject(Manager.GetParameters().JsonParams); dynamic JsonMessage = new JObject(JsonParams); int x = 0; foreach (var Param in JsonMessage.parameters) { if ((bool)Param.enabled == true) { int ListSize = Param.listsize != null ? (int)Param.listsize : 1; if (ListSize == 1) { Param.Add("value", Vector != null ? Vector[x] : 0); } else { Param.Add("value", Vector != null ? new JArray(Vector.GetRange(x, ListSize)) : new JArray(new double[ListSize])); } x += ListSize; } } JsonMessage.Add("randomseed", RandSeed); RPCClient rpcClient = null; var P = JsonParams.bridge; while (rpcClient == null) { try { rpcClient = new RPCClient((string)P.queuename, (string)P.server, (int)P.port, (string)P.username, (string)P.password, (string)P.amqpurl); } catch { rpcClient = null; } } var response = rpcClient.CallRunGame(JsonMessage.ToString()); rpcClient.Close(); return(response); } catch (Exception e) { return(null); } }
private static async Task InvokeAsync(string n) { var rpcClient = new RPCClient(); Console.WriteLine(" [x] Requesting fib({0})", n); var response = await rpcClient.CallAsync(n.ToString()); Console.WriteLine(" [.] Got '{0}'", response); rpcClient.Close(); }
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); }
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(); }
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); } }
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(); }
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(); }
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); }
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"); } }
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; } } }
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(); }
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(); }
string GetRemoteGameResults(RPCData sendData, string HostName) { try { string message = ""; XmlSerializer xmlSerializer = new XmlSerializer(sendData.GetType()); using (StringWriter textWriter = new StringWriter()) { xmlSerializer.Serialize(textWriter, sendData); message = textWriter.ToString(); } RPCClient rpcClient = null; while (rpcClient == null) { try { rpcClient = new RPCClient(HostName); } catch { rpcClient = null; } } var response = rpcClient.CallRunGame(message); rpcClient.Close(); return(response); } catch (Exception e) { Console.WriteLine(" ERROR: " + e.Message); return("0,0,0,0"); //RunResults[i] } }
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; } } }
static void Main(string[] args) { string strIpaddress = args[0]; string strUserName = args[1]; string strPassword = args[2]; string command = args[3].ToLower(); string strServiceName; string strRemotePath; string strLocalPath; RPCClient RPCClient = new RPCClient(strIpaddress, "13521", ProtocolSequenceType.ncacn_ip_tcp, AuthenticationLevelType.CONNECT, SecurityProviderType.WINNT, strUserName, strPassword); var t = RPCClient.CreateBind(Guid.Parse("551d88b0-b831-4283-a1cd-276559e49f28"), 1, 0, true, true); var d = t.Request(1, new byte[] { 2, 0, 0, 0, 1, 0, 0, 0 }); if (BitConverter.ToInt32(d, 4) == 0) { Console.WriteLine("结果:" + BitConverter.ToInt32(d, 0)); } else { Console.WriteLine("失败"); } RPCClient.Close(); //SC sc; //switch (command) //{ // case "help": // string strHelp = // "[ipaddress] [username] [password] upload [remotePath] strLocalPath" + // "[ipaddress] [username] [password] createservice [servername] [binPath]" + // "[ipaddress] [username] [password] startservice [servername] " + // "[ipaddress] [username] [password] exec"; // Console.WriteLine(strHelp); // break; // case "upload": // strRemotePath = args[4]; // strLocalPath = args[5]; // SMB2Client smb2Client = new SMB2Client(strIpaddress, strUserName, strPassword); // smb2Client.Login(); // var dt = smb2Client.CreateTree(strRemotePath[0] + "$"); // var dF = dt.CreateFile(FilePipePrinterAccessMaskFlags.GENERIC_READ | FilePipePrinterAccessMaskFlags.GENERIC_WRITE, ShareAccessFlags.None, // ECreateDisposition.FILE_OVERWRITE_IF, 0x44, strRemotePath.Substring(3)); // dF.Write(0, File.ReadAllBytes(strLocalPath)); // dF.Close(); // dt.Disconnect(); // smb2Client.Logout(); // break; // case "create": // sc = new SC(strIpaddress, strUserName, strPassword); // strServiceName = args[4]; // strRemotePath = args[5]; // sc.CreateService(strServiceName, strRemotePath); // break; // case "start": // sc = new SC(strIpaddress, strUserName, strPassword); // strServiceName = args[4]; // sc.StartService(strServiceName); // break; // case "exec": // new Exec(strIpaddress, strUserName, strPassword).Start(); // break; // default: Console.WriteLine("unknow command"); break; //} Console.Read(); }