Пример #1
0
        internal async Task <VoteLbResponse> VoteAction(ChooserLbMessage chooser)
        {
            var distribuitor = new Distributor(new VoteSender());

            distribuitor.FormateNodeList(3);
            var message = distribuitor.FormateMessage(chooser);

            var response = await distribuitor.Send(distribuitor.Executor, message);

            try
            {
                var voteresponse = JsonConvert.DeserializeObject <NodeVoteResponse>(response);
                return(new VoteLbResponse
                {
                    Status = voteresponse.Status,
                    Block = voteresponse.Block,
                    Message = voteresponse.Message,
                    ProcessedTime = voteresponse.ProcessedTime
                });
            }
            catch (AggregateException ex)
            {
                return(new VoteLbResponse {
                    Status = false, Message = "Eroare de conectare la server LB:" + ex.InnerException.ToString(), ProcessedTime = DateTime.Now
                });
            }
        }
        public NodeRegResponse RegistrationAction(RegistrationMessage message)
        {
            var nodeMessage = new NodeRegMessage {
                Message = message
            };

            NodeData worker;
            var      neighbors = Distributor.FormateNodeList(3, out worker);

            nodeMessage.NeighBours = neighbors;

            var serializedMessage = JsonConvert.SerializeObject(nodeMessage);
            var content           = new StringContent(serializedMessage, Encoding.UTF8, "application/json");

            try
            {
                var response         = worker.Sender.PostAsync(new Uri(new Uri(worker.IpAddress), "api/Register"), content).Result.Content.ReadAsStringAsync();
                var responseFromNode = JsonConvert.DeserializeObject <NodeRegResponse>(response.Result);
                return(responseFromNode);
            }
            catch (AggregateException e)
            {
                return(new NodeRegResponse {
                    Status = false, Message = "Eroare de connectare la server LB:" + e.InnerException.ToString(), ProcessedTime = DateTime.Now
                });
            }
        }
        public string VoteAction(ChooserLbMessage message)
        {
            var      _storage = NodeStorage.GetInstance();
            NodeData worker;
            var      selected_Nodes = Distributor.FormateNodeList(3, out worker);
            var      neighbors      = Mapping.Mapper.Map <List <NodeNeighbor> >(selected_Nodes);

            var request_data = new NodeVoteMessage()
            {
                Message    = message,
                Neighbours = neighbors
            };

            var serialized = JsonConvert.SerializeObject(request_data);
            var content    = new StringContent(serialized, Encoding.UTF8, "application/json");

            try
            {
                var response = worker.Sender.PostAsync(new Uri(new Uri(worker.IpAddress), "api/Vote"), content).Result;
                return(response.Content.ReadAsStringAsync().Result);
            }
            catch (Exception e)
            {
                return("Error connection to Node" + e.Message);
            }
        }
Пример #4
0
        public void FormateNodeListTest()
        {
            List <NodeData> node_list = new List <NodeData>
            {
                new NodeData()
                {
                    NodeId = "N00-1", Name = "Node1"
                },
                new NodeData()
                {
                    NodeId = "N00-2", Name = "Node2"
                },
                new NodeData()
                {
                    NodeId = "N00-3", Name = "Node3"
                },
                new NodeData()
                {
                    NodeId = "N00-4", Name = "Node4"
                },
                new NodeData()
                {
                    NodeId = "N00-5", Name = "Node5"
                },
                new NodeData()
                {
                    NodeId = "N00-6", Name = "Node6"
                },
                new NodeData()
                {
                    NodeId = "N00-7", Name = "Node7"
                },
            };

            var _storage = NodeStorage.GetInstance();


            foreach (var item in node_list)
            {
                _storage.AddNode(item);
            }

            NodeData selectedNode;
            var      selected_nodes = Distributor.FormateNodeList(3, out selectedNode);

            var outputList = Mapper.Mapping.Mapper.Map <List <NodeNeighbor> >(selected_nodes);

            Assert.IsNotNull(outputList);
        }