コード例 #1
0
ファイル: Link.cs プロジェクト: MichalPrzybylski/TSST-15Z
        public bool Equals(Link link)
        {
            bool abbstract = false;
            bool node = false;
            for (int i = 0; i < Ports.Count; i++)
            {
                KeyValuePair<AbstractAddress, NetworkNodeSender> thisObject = Ports.ElementAt(i);
                KeyValuePair<AbstractAddress, NetworkNodeSender> linkObject = link.Ports.ElementAt(i);
                if (thisObject.Key.Equals(linkObject.Key)) //AbstractAddress
                {
                    abbstract = true;
                }
                else return false;
                if (thisObject.Value.Equals(linkObject.Value)) //Node
                {
                    node = true;
                }
                else return false;

            }
            return node && abbstract;
        }
コード例 #2
0
ファイル: Link.cs プロジェクト: MichalPrzybylski/TSST-15Z
 public Link(Link link)
 {
     this.Ports = link.Ports;
     this.IsLinkActive = link.IsLinkActive;
 }
コード例 #3
0
        private void createLink()
        {
            StringBuilder msg = new StringBuilder();

            int src_port = validatePortInput(msg, this.SourcePort, "Źródło - port");
            string src_nodeid = validateNodeIdInput(msg, this.SourceNodeId, "Źródło - nodeid");
            int src_socket = validatePortInput(msg, this.SourceSocket, "Źródło - socket");
            int dst_port = validatePortInput(msg, this.DestinationPort, "Cel - port");
            string dst_nodeid = validateNodeIdInput(msg, this.DestinationNodeId, "Cel - nodeid");
            int dst_socket = validatePortInput(msg, this.DestinationSocket, "Cel - socket");

            if (msg.Length == 0)
            {
                List<AbstractAddress> abstractAddress = new List<AbstractAddress>();
                abstractAddress.Add(new AbstractAddress(src_port, src_nodeid));
                abstractAddress.Add(new AbstractAddress(dst_port, dst_nodeid));
                List<NetworkNodeSender> networkNodeSender = new List<NetworkNodeSender>();
                networkNodeSender.Add(new NetworkNodeSender(src_socket));
                networkNodeSender.Add(new NetworkNodeSender(dst_socket));

                Dictionary<AbstractAddress, NetworkNodeSender> dictionary = new Dictionary<AbstractAddress, NetworkNodeSender>();

                if (abstractAddress[0].Equals(abstractAddress[1]) || networkNodeSender[0].Equals(networkNodeSender[1]))
                {
                    msg.Append("Źródło i cel są takie same");
                }
                else
                {
                    dictionary.Add(abstractAddress[0], networkNodeSender[1]);
                    dictionary.Add(abstractAddress[1], networkNodeSender[0]);

                    Link newLink = new Link(dictionary);

                    List<Link> invalid = this.CloudSetupProcess.TryAddLink(newLink);

                    switch (invalid.Count)
                    {
                        case 0:
                            {
                                msg.Append("Połączenie utworzone");
                                break;
                            }
                        case 1:
                            {
                                msg.Append("Port : ");
                                msg.Append(invalid[0].ToString());
                                msg.Append(" jest zajęty");
                                break;
                            }
                        case 2:
                            {
                                msg.Append("Porty : ");
                                msg.Append(invalid[0].ToString());
                                msg.Append(" , ");
                                msg.Append(invalid[1].ToString());
                                msg.Append(" są zajęte");
                                break;
                            }
                        default:
                            {
                                throw new Exception("Unexpected State of Application");
                            }
                    }
                }

            }

            ConsoleMessage = msg.ToString();
        }
コード例 #4
0
 public LinkCreatedArgs(Link link)
 {
     Link = link;
 }
コード例 #5
0
 private void validatePort(List<Link> invalidPorts, Link port)
 {
     foreach (var item in usedPorts)
     {
         if (item.Equals(port))
         {
             invalidPorts.Add(port);
         }
     }
 }
コード例 #6
0
        public List<Link> TryAddLink(Link src)
        {
            List<Link> occupiedPorts = new List<Link>();
            validatePort(occupiedPorts, src);
            if (occupiedPorts.Count == 0)
            {
                Link link = new Link(src);
                Links.Add(link);
                if (LinkCreated != null)
                {
                    LinkCreated(new LinkCreatedArgs(link));
                }

            }
            return occupiedPorts;
        }
コード例 #7
0
 /// <summary>
 /// Deletes the link from Links
 /// </summary>
 /// <param name="link">The link to delete</param>
 public void DeleteLink(Link link)
 {
     this.Links.Remove(link);
 }