public static bool LoadData(string fileName, ProtoSerialization serializer, out STSerializedLevel out_obj) { string fullPath = Path.Combine(AppDocumentPath, (fileName + LevelsExtention)); bool ret = false; out_obj = null; if (!File.Exists(fullPath)) { Debug.Log("Load Serialization File Not Exist At Path"); return(ret); } FileStream fs = null; Debug.Log("Load Serialization File"); fs = File.OpenRead(fullPath); out_obj = serializer.Deserialize(fs, null, typeof(STSerializedLevel)) as STSerializedLevel; ret = true; Debug.Log("Load Serialization Complete"); if (fs != null) { fs.Close(); } return(ret); }
private static void ConsumePublications(object model, BasicDeliverEventArgs eventArguments) { var body = eventArguments.Body; var publication = ProtoSerialization.Deserialize <Publication>(body); var latency = GetLatency(publication); Latencies.Add(latency); Logger.Log($" [*] Received publication {Latencies.Count}", true); // UpdateAverageLatency(latency); // var routingKey = eventArguments.RoutingKey; Logger.Log($" [*] Received publication {publication}\n Latency:{latency}"); // ShowAverageLatency(); }
private static void ConsumeForwardedPublications(object sender, BasicDeliverEventArgs e) { var publication = ProtoSerialization.Deserialize <Publication>(e.Body); Logger.Log($" [x] Received forwarded publication on routing key {e.RoutingKey}", true); if (SubscriptionsMap[publication.SubscriptionMatchId].SenderId.StartsWith('B')) { SendForwardsPublication(publication, SubscriptionsMap[publication.SubscriptionMatchId].SenderId); } else { SendToConsumerQueue(ChanelPublicationsConsumer, publication, SubscriptionsMap[publication.SubscriptionMatchId].SenderId); } }
private void DealWithSubscriptions(object model, BasicDeliverEventArgs ea) { var subscription = ProtoSerialization.Deserialize <Subscription>(ea.Body); Logger.Log($" [*] Received subscription {subscription}"); Logger.Log($"S {++subscriptionNumber}", true); if (Program.RecieverSubscriptionsMap.ContainsKey(subscription.SenderId)) { Program.RecieverSubscriptionsMap[subscription.SenderId].Add(subscription); } else { Program.RecieverSubscriptionsMap[subscription.SenderId] = new List <Subscription>() { subscription }; } if (!Program.SubscriptionsMap.ContainsKey(subscription.Id)) { Program.SubscriptionsMap.Add(subscription.Id, subscription); } ForwardSubscription(subscription); }
private static void Broker(IModel channelReceiver, IModel channelSender) { var consumer = new EventingBasicConsumer(channelReceiver); consumer.Received += (model, eventArguments) => { var body = eventArguments.Body; var publication = ProtoSerialization.Deserialize <Publication>(body); Logger.Log($" [x] Received publication {publication} "); var matchedSubscriptions = new List <Subscription>(); try { matchedSubscriptions = FilterMessageBasedOnSubscriptions(publication); } catch (Exception e) { Logger.Log(e.Message); } foreach (var subscriptions in matchedSubscriptions) { publication.SubscriptionMatchId = subscriptions.Id; if (subscriptions.SenderId.StartsWith('C')) { SendToConsumerQueue(channelSender, publication, subscriptions.SenderId); } if (subscriptions.SenderId.StartsWith('B')) { SendForwardsPublication(publication, subscriptions.SenderId); } } }; channelReceiver.BasicConsume(queue: receiverQueueName, autoAck: true, consumer: consumer); }