Esempio n. 1
0
        public void SendToQueue(IModel channel, Subscription subscription)
        {
            var byteMessage = ProtoSerialization.SerializeAndGetBytes(subscription);

            channel.BasicPublish(exchange: brokerSubscriptionsQueueName, routingKey: "", basicProperties: null, body: byteMessage);
            Logger.Log($"Sent subscriptions: {subscription}");
        }
Esempio n. 2
0
    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);
    }
Esempio n. 3
0
        private static void SendToQueue(IModel channel, IBasicProperties properties, Publication publication)
        {
            var bytes = ProtoSerialization.SerializeAndGetBytes(publication);

            channel.BasicPublish(exchange: "", routingKey: exchangeAgent, basicProperties: properties, body: bytes);
            Logger.Log($" [*] Sent publication: {publication} |");
        }
Esempio n. 4
0
        public void ForwardSubscription(Subscription subscription)
        {
            if (subscription.ForwardNumber == (Constants.NumberOfBrokers - 1))
            {
                return;
            }
            string forwardId = GetNextBrokerId(subscription);
            var    s         = new Subscription
            {
                Id            = subscription.Id,
                SenderId      = $"B{brokerId}",
                Filter        = subscription.Filter,
                ForwardNumber = subscription.ForwardNumber + 1
            };

            var brokerSubscriptionsQueueName = $"Subscriptions_{forwardId}";

            using (var connection = factory.CreateConnection())
            {
                using (var channel = connection.CreateModel())
                {
                    channel.ExchangeDeclare(exchange: brokerSubscriptionsQueueName, type: "direct");

                    var byteMessage = ProtoSerialization.SerializeAndGetBytes(s);
                    channel.BasicPublish(exchange: brokerSubscriptionsQueueName, routingKey: "", basicProperties: null, body: byteMessage);
                    Logger.Log($" [*] Forwarded subscription: {s}");
                }
            }
        }
Esempio n. 5
0
        private static void SendForwardsPublication(Publication publication, string receiverId)
        {
            var body = ProtoSerialization.SerializeAndGetBytes(publication);

            ChanelPublicationsForward.BasicPublish(exchange: forwardPublicationsExchange,
                                                   routingKey: receiverId,
                                                   basicProperties: null,
                                                   body: body);
            Logger.Log($" [x] Sent forward publication to {receiverId} : {publication}");
        }
Esempio n. 6
0
    static public STLevel Instance()
    {
        if (_instance == null)
        {
            GameObject level = GameObject.Find("Level");

            if (level == null)
            {
                Debug.LogError("Error get Level");
                return(null);
            }

            _instance = level.GetComponent <STLevel>();


            _instance.RootNode = GameObject.Instantiate(_instance.RootNode) as STRootNode;
            //	GameObject obj = GameObject.Find ("RootNode");
            //	_instance.RootNode = obj.GetComponent <STRootNode> ();

            if (_instance.RootNode == null)
            {
                Debug.LogError("Error getting root node");
                return(null);
            }

//			public GameObject Node;
//			public GameObject Leaf;
//			public GameObject ActiveNode;

//			_instance.RootNode.mVisual.ActiveNode.renderer.enabled = false;
//			_instance.RootNode.mVisual.Leaf.renderer.enabled = false;
//			_instance.RootNode.mVisual.Node.renderer.enabled = false;


            _instance.NodesNet = GameObject.Instantiate(_instance.NodesNet) as STNodesNet;

            if (_instance.NodesNet == null)
            {
                Debug.LogError("Error getting nodes net");
                return(null);
            }

            _instance.Control   = GameObject.Find("Background").GetComponent <STControl>();
            _instance.SkinsMngr = GameObject.Instantiate(_instance.SkinsMngr) as STSkinsManager;

            if (_instance.SkinsMngr == null)
            {
                Debug.LogError("Error getting skins manager");
                return(null);
            }

            sLevelSerializer = new ProtoSerialization();
        }
        return(_instance);
    }
Esempio n. 7
0
        private static void SendToConsumerQueue(IModel channel, Publication publication, string receiverId)
        {
            Logger.Log($" [*] Send to consumer", true);
            Logger.Log($" [*] Send to consumer {publication}");

            var bytes = ProtoSerialization.SerializeAndGetBytes(publication);

            channel.QueueDeclare(queue: receiverId, durable: true, exclusive: false, autoDelete: false, arguments: null);
            var properties = channel.CreateBasicProperties();

            properties.Persistent = true;
            channel.BasicPublish(exchange: "", routingKey: receiverId, basicProperties: properties, body: bytes);
        }
        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();
        }
Esempio n. 9
0
        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);
            }
        }
Esempio n. 10
0
    public static bool SaveData(STSerializedLevel obj, ProtoSerialization serializer, string fileName, bool shouldRewrite)
    {
        string fullPath = Path.Combine(AppDocumentPath, (fileName + LevelsExtention));
        //Debug.Log("Save Serialized Data to : " + fullPath);
        bool ret = false;

        if (File.Exists(fullPath))
        {
            Debug.Log("Save Serialized Data Delete Old File");
            if (shouldRewrite == false)
            {
                return(false);
            }


            File.Delete(fullPath);
        }

        FileStream fs = new FileStream(fullPath, FileMode.Create);

        if (fs != null)
        {
            //ProtoSerialization pSerializer = serializer as ProtoSerialization;
            serializer.Serialize(fs, obj);

//			if (pSerializer.CanSerialize (typeof ( STSerializedLevel)))
//			{
//				Debug.Log ("CAN SER");
//			}
//			else
//				Debug.Log ("CAN NOT SER");
//
            ret = true;


            Debug.Log("Save Serialization Complete");
            if (fs != null)
            {
                fs.Close();
            }
        }
        else
        {
            Debug.Log("FS ERROR");
        }


        return(ret);
    }
Esempio n. 11
0
        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);
        }
Esempio n. 12
0
        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);
        }