private static void LauncherLightWorker() { IModel channel = OverallInformations.conn.CreateModel(); channel.ExchangeDeclare(exchange: OverallInformations.LauncherServerClientExchange, type: "direct", durable: false, autoDelete: true, arguments: null); channel.QueueDeclare(queue: OverallInformations.LauncherLightQueueName, durable: false, exclusive: false, autoDelete: true, arguments: null); channel.QueueBind(queue: OverallInformations.LauncherLightQueueName, exchange: OverallInformations.LauncherServerClientExchange, routingKey: OverallInformations.LauncherLightRouterKey, arguments: null); channel.BasicQos(prefetchSize: 0, prefetchCount: 1, global: false); EventingBasicConsumer consumer = new EventingBasicConsumer(channel); LauncherService LauncherServiceInstance = new LauncherService(); consumer.Received += (model, ea) => { IBasicProperties deliverdProps = ea.BasicProperties; IBasicProperties replyProps = channel.CreateBasicProperties(); replyProps.CorrelationId = deliverdProps.CorrelationId; byte[] deliveredBody = ea.Body; string response = null; try { string message = Encoding.UTF8.GetString(deliveredBody); Request01 IncomingContent = Newtonsoft.Json.JsonConvert.DeserializeObject<Request01>(message); if (!OverallInformations.IsAllowedReceiveRequestFromClient) { response = "#"; } else if (IncomingContent.RequestType == "Launcher.CheckVersion") { if (IncomingContent.Parameters[0] == OverallInformations.ClientVersion) { response = "OK"; } else { response = "Out"; } } else if (IncomingContent.RequestType == "Launcher.AddClient") { response = LauncherServiceInstance.AddClient(IncomingContent.Parameters[0]); } else if (IncomingContent.RequestType == "Launcher.Login") { ResponseStruct LoginResult = LauncherServiceInstance.Login(IncomingContent.Parameters[0], IncomingContent.Parameters[1], IncomingContent.Parameters[2]); response = Newtonsoft.Json.JsonConvert.SerializeObject(LoginResult); } else if (IncomingContent.RequestType == "Launcher.Register") { ResponseStruct RegisterResult = LauncherServiceInstance.Register(IncomingContent.Parameters[0], IncomingContent.Parameters[1], IncomingContent.Parameters[2]); response = Newtonsoft.Json.JsonConvert.SerializeObject(RegisterResult); } else if (IncomingContent.RequestType == "Launcher.Logout") { ResponseStruct LogoutResult = LauncherServiceInstance.Logout(IncomingContent.Parameters[0]); response = Newtonsoft.Json.JsonConvert.SerializeObject(LogoutResult); } else if (IncomingContent.RequestType == "Launcher.SendChat") { ResponseStruct SendChatResult = LauncherServiceInstance.SendChat(IncomingContent.Parameters[0], IncomingContent.Parameters[1]); response = Newtonsoft.Json.JsonConvert.SerializeObject(SendChatResult); } else { response = ""; } } catch (Exception e) { OutputMessage(String.Format("[Server]: LauncherLightWorker() | Error: {0}", e.Message), MessageType.Error); response = ""; } finally { byte[] responseBytes = Encoding.UTF8.GetBytes(response); channel.BasicPublish(exchange: OverallInformations.LauncherServerClientExchange, routingKey: deliverdProps.ReplyTo, basicProperties: replyProps, body: responseBytes); channel.BasicAck(deliveryTag: ea.DeliveryTag, multiple: false); } }; channel.BasicConsume(queue: OverallInformations.LauncherLightQueueName, noAck: false, consumer: consumer); }
private static void LauncherImageWorker() { IModel channel = OverallInformations.conn.CreateModel(); channel.ExchangeDeclare(exchange: OverallInformations.LauncherServerClientExchange, type: "direct", durable: false, autoDelete: true, arguments: null); channel.QueueDeclare(queue: OverallInformations.LauncherImageQueueName, durable: false, exclusive: false, autoDelete: true, arguments: null); channel.QueueBind(queue: OverallInformations.LauncherImageQueueName, exchange: OverallInformations.LauncherServerClientExchange, routingKey: OverallInformations.LauncherImageRouterKey, arguments: null); channel.BasicQos(prefetchSize: 0, prefetchCount: 1, global: false); EventingBasicConsumer consumer = new EventingBasicConsumer(channel); LauncherService LauncherServiceInstance = new LauncherService(); Base64Utils base64Utils = new Base64Utils(); consumer.Received += (model, ea) => { IBasicProperties deliverdProps = ea.BasicProperties; IBasicProperties replyProps = channel.CreateBasicProperties(); replyProps.CorrelationId = deliverdProps.CorrelationId; byte[] deliveredBody = ea.Body; try { string message = Encoding.UTF8.GetString(deliveredBody); Request01 IncomingContent = Newtonsoft.Json.JsonConvert.DeserializeObject<Request01>(message); if (IncomingContent.RequestType == "Launcher.Image") { if (OverallInformations.IsAllowedReceiveRequestFromClient && OverallInformations.IsAllowedReceiveImageFromClient) { LauncherServiceInstance.SaveImage(IncomingContent.Parameters[0], base64Utils.Base64ToImage(IncomingContent.Parameters[1])); } } } catch (Exception e) { OutputMessage(String.Format("[Server]: LauncherImageWorker() | Error: {0}", e.Message), MessageType.Error); } finally { channel.BasicAck(deliveryTag: ea.DeliveryTag, multiple: false); } }; channel.BasicConsume(queue: OverallInformations.LauncherImageQueueName, noAck: false, consumer: consumer); }