示例#1
0
        static void Main(string[] args)
        {
            Console.WindowWidth = 100;
            Console.BufferWidth = 100;
            Console.Title       = "WireCloud";
            LogWriter.startingMessage();

            string    linksPath = Environment.CurrentDirectory + "\\Links.txt";
            LinkTable linkTable = new LinkTable(linksPath);

            string          devicesPath     = Environment.CurrentDirectory + "\\Devices.txt";
            DeviceContainer deviceContainer = new DeviceContainer(devicesPath, linkTable);
            int             managerPortNumber;
            Thread          managerThread;

            if (args.Length > 0)
            {
                if (Int32.TryParse(args[0], out managerPortNumber))
                {
                    managerThread = new Thread(() => new CloudManager(linkTable, managerPortNumber));
                }
                else
                {
                    managerThread = new Thread(() => new CloudManager(linkTable, 56012));
                }
            }
            else
            {
                managerThread = new Thread(() => new CloudManager(linkTable, 56012));
            }

            managerThread.Start();
            deviceContainer.initializeSockets();
            deviceContainer.run();
        }
示例#2
0
 public DeviceContainer(string configurationFilePath, LinkTable linkTable)
 {
     try
     {
         this.linkTable = linkTable;
         string[] deviceDefinitions = System.IO.File.ReadAllLines(configurationFilePath);
         deviceList = new List <Device>();
         foreach (string definition in deviceDefinitions)
         {
             string[] definitionParameters = definition.Split('.');
             string   deviceType           = definitionParameters[0];
             string   IDNumber             = definitionParameters[1];
             int      listenFromPortNumber = Int32.Parse(definitionParameters[2]);
             int      sendToPortNumber     = Int32.Parse(definitionParameters[3]);
             this.addDevice(deviceType, IDNumber, listenFromPortNumber, sendToPortNumber);
         }
     }
     catch (System.IO.FileNotFoundException ex)
     {
         Console.WriteLine("Add proper config file (Devices.txt) and restart program");
         while (true)
         {
             ;
         }
     }
 }
示例#3
0
        public CloudManager(LinkTable linkTable, int port)
        {
            IPEndPoint managingEndPoint = new IPEndPoint(IPAddress.Any, 0);
            EndPoint   manager          = (EndPoint)managingEndPoint;

            Socket     orderingSocket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
            IPEndPoint endPoint       = new IPEndPoint(IPAddress.Parse("127.0.0.1"), port);

            orderingSocket.Bind(endPoint);
            LogWriter.notificationMessage("Manager communication ready", true);
            while (true)
            {
                byte[] buffer          = new byte[orderingSocket.SendBufferSize];
                int    readBytesNumber = orderingSocket.ReceiveFrom(buffer, ref manager);
                byte[] receivedData    = new byte[readBytesNumber];
                Array.Copy(buffer, receivedData, readBytesNumber);
                ManagementDataObjects.MdoForCloud mdoForCloud = ByteToMdoForCloud(receivedData);

                LogWriter.newOrderFromManager();

                bool decision;
                if (mdoForCloud.Command.Equals("LinkDown"))
                {
                    decision = false;
                }
                else if (mdoForCloud.Command.Equals("LinkUp"))
                {
                    decision = true;
                }
                else
                {
                    LogWriter.generalMessage("Invalid command", true);
                    continue;
                }

                if (!linkTable.controlSpecificLink(mdoForCloud.DeviceFrom, mdoForCloud.DeviceTo, decision))
                {
                    LogWriter.generalMessage("Order had no effect", true);
                }
            }
        }