Пример #1
0
 public AsyncService(int port, TCPService service)
 {
     // set up port and determine IP Address
     this.port      = port;
     this.ipAddress = IPAddress.Parse("127.0.0.1");
     this.service   = service;
 } // AsyncService ctor
Пример #2
0
        /// <summary>
        /// Initializes a new instance of the MainViewModel class.
        /// </summary>
        public MainViewModel(IDataService dataService)
        {
            _dataService    = dataService;
            _messageManager = MessageManager.Instence;
            TCPService tcp = new TCPService();

            tcp.StartSocket();
            _messageManager.GetMessage += GetMessage;
            _messageManager.AliveSocketPool.SocketPoolChanged += AliveSocketPool_SocketPoolChanged;
            SocketList = new ObservableCollection <KeyValuePair <string, Socket> >(_messageManager.AliveSocketPool);
        }
Пример #3
0
 public override void Stop()
 {
     // Stop listening for new clients.
     if (LinkStatus)
     {
         Console.WriteLine("Closing the TCP linking.");
         TCPClient.Close();
     }
     Console.WriteLine("Stopping the TCP linking service.");
     TCPService.Stop();
     Status     = false;
     LinkStatus = false;
 }
Пример #4
0
 public Transform AddClass(string name)
 {
     if (!classesDict.ContainsKey(name) || classesDict[name] == null)
     {
         var cls       = Instantiate(classPrefab, classesTransform);
         int currLayer = (GameObject.Find("#" + (GameObject.Find("TCPService").GetComponent <TCPService>().GetDiagCount() - 1))).layer;
         cls.layer = currLayer;
         TCPService.SetLayerRecursively(cls, currLayer);
         var tmp = cls.GetComponentInChildren <TextMeshProUGUI>();
         cls.name          = tmp.text = name;
         classesDict[name] = cls.transform;
     }
     return(classesDict[name]);
 }
        private void ReadConfiguration(string configFilePath)
        {
            Xmlconfig myXmlcfg = new Xmlconfig(configFilePath, false);

            cpuImportance     = myXmlcfg.Settings["Cpu"]["ImportanceFactor"].floatValue;
            cpuThresholdValue = myXmlcfg.Settings["Cpu"]["ThresholdValue"].intValue;
            ramImportance     = myXmlcfg.Settings["Ram"]["ImportanceFactor"].floatValue;
            ramThresholdValue = myXmlcfg.Settings["Ram"]["ThresholdValue"].intValue;

            myTCPServices.Clear();

            if (myXmlcfg.Settings.GetNamedChildrenCount("TCPService") > 0)
            {
                foreach (ConfigSetting cs in myXmlcfg.Settings.GetNamedChildren("TCPService"))
                {
                    TCPService myTCPService = new TCPService();
                    myTCPService.serviceName           = cs["Name"].Value;
                    myTCPService.serviceIPAddress      = cs["IPAddress"].Value;
                    myTCPService.servicePort           = cs["Port"].intValue;
                    myTCPService.serviceMaxConnections = cs["MaxConnections"].intValue;
                    myTCPService.serviceImportance     = cs["ImportanceFactor"].floatValue;
                    myTCPServices.Add(myTCPService);
                }
            }

            readAgentStatusFromConfig         = myXmlcfg.Settings["ReadAgentStatusFromConfig"].boolValue;
            readAgentStatusFromConfigInterval = myXmlcfg.Settings["ReadAgentStatusFromConfigInterval"].intValue;
            agentStatus = myXmlcfg.Settings["AgentStatus"].Value;

            if (myXmlcfg.Settings["Interval"].intValue.ToString().Trim() != "0")
            {
                interval = myXmlcfg.Settings["Interval"].intValue;
            }
            else
            {
                WriteConfiguration(configFilePath);
            }


            if (agentStatus.Length == 0)
            {
                readAgentStatusFromConfig         = false;
                readAgentStatusFromConfigInterval = 5;
                agentStatus = "Normal";
                throw new Exception("Configuration not complete.");
            }

            //myXmlcfg.Dispose();
        }
        static void Main(string[] args)
        {
            IPAddress   ip = IPAddress.Parse("127.0.0.1");
            TcpListener serverWelcomingSocket = new TcpListener(ip, 4646);

            serverWelcomingSocket.Start();

            while (true)
            {
                TcpClient serverConnectionSocket = serverWelcomingSocket.AcceptTcpClient();
                Console.WriteLine("Starting a new connection!");
                TCPService service = new TCPService(serverConnectionSocket);

                Task.Factory.StartNew(() => service.SendReceiveData());
            }
        }
        private void WriteConfiguration(string configFilePath)
        {
            // Backup config file
            try
            {
                File.Move(configFilePath, configFilePath + ".bak");
            }
            catch { }

            Xmlconfig myXmlcfg = new Xmlconfig(configFilePath, true);

            myXmlcfg.Settings["Cpu"]["ImportanceFactor"].floatValue = cpuImportance;
            myXmlcfg.Settings["Cpu"]["ThresholdValue"].intValue     = cpuThresholdValue;
            myXmlcfg.Settings["Ram"]["ImportanceFactor"].floatValue = ramImportance;
            myXmlcfg.Settings["Ram"]["ThresholdValue"].floatValue   = ramThresholdValue;

            if (myTCPServices.Count == 0)
            {
                // Demo TCPService
                TCPService myTCPService = new TCPService();
                myXmlcfg.Settings["TCPService"]["Name"].Value                  = myTCPService.serviceName;
                myXmlcfg.Settings["TCPService"]["IPAddress"].Value             = myTCPService.serviceIPAddress;
                myXmlcfg.Settings["TCPService"]["Port"].intValue               = myTCPService.servicePort;
                myXmlcfg.Settings["TCPService"]["MaxConnections"].intValue     = myTCPService.serviceMaxConnections;
                myXmlcfg.Settings["TCPService"]["ImportanceFactor"].floatValue = myTCPService.serviceImportance;
            }
            else
            {
                foreach (TCPService myTCPService in myTCPServices)
                {
                    myXmlcfg.Settings["TCPService"]["Name"].Value                  = myTCPService.serviceName;
                    myXmlcfg.Settings["TCPService"]["IPAddress"].Value             = myTCPService.serviceIPAddress;
                    myXmlcfg.Settings["TCPService"]["Port"].intValue               = myTCPService.servicePort;
                    myXmlcfg.Settings["TCPService"]["MaxConnections"].intValue     = myTCPService.serviceMaxConnections;
                    myXmlcfg.Settings["TCPService"]["ImportanceFactor"].floatValue = myTCPService.serviceImportance;
                }
            }

            myXmlcfg.Settings["ReadAgentStatusFromConfig"].boolValue        = readAgentStatusFromConfig;
            myXmlcfg.Settings["ReadAgentStatusFromConfigInterval"].intValue = readAgentStatusFromConfigInterval;
            myXmlcfg.Settings["AgentStatus"].Value = agentStatus;

            myXmlcfg.Settings["Interval"].intValue = interval;

            myXmlcfg.Save(configFilePath);
            myXmlcfg.Dispose();
        }
Пример #8
0
    public void AddMessage(string from, string to, string message, int lineNo, bool dashed = false)
    {
        var msg       = Instantiate(messagePrefab, messagesTransform);
        int currLayer = (GameObject.Find("#" + (GameObject.Find("TCPService").GetComponent <TCPService>().GetDiagCount() - 1))).layer;

        msg.layer = currLayer;
        TCPService.SetLayerRecursively(msg, currLayer);
        var label     = msg.transform.Find("label");
        var msgScript = msg.GetComponent <Message>();
        var fromClass = AddClass(from);
        var toClass   = AddClass(to);

        msgScript.fromClass = fromClass.GetComponent <RectTransform>();
        msgScript.toClass   = toClass.GetComponent <RectTransform>();
        msgScript.dashed    = dashed;
        msgScript.line      = lineNo;
        msgScript.name      = message;
        label.GetComponent <TextMeshProUGUI>().text = message;
    }
Пример #9
0
        public static void Main(string[] args)
        {
            var network = new TCPService();

            network.Start();
        }
Пример #10
0
    public void AddLoop(IList tmpBounds, GameObject tmpObject)
    {
        bool existingLoop = false;
        Loop tmpLoop      = null;

        //subloop scaling resize;
        int subloop = 0;

        List <Transform> subloopObjectList = new List <Transform>();

        if (loopsTransform.childCount > 0)
        {
            for (int i = 0; i < loopsTransform.childCount; i++)
            {
                Transform item = loopsTransform.GetChild(i);

                IList itemBounds = item.GetComponent <Loop>().getBounds();

                if ((System.Convert.ToInt32(itemBounds[0].ToString()) == System.Convert.ToInt32(tmpBounds[0].ToString())) &&
                    (System.Convert.ToInt32(itemBounds[1].ToString()) == System.Convert.ToInt32(tmpBounds[1].ToString())))
                {
                    existingLoop = true;

                    tmpLoop = item.GetComponent <Loop>();
                }


                if (!existingLoop)
                {
                    bool fromBottom = ((System.Convert.ToInt32(itemBounds[0].ToString()) >= System.Convert.ToInt32(tmpBounds[0].ToString())));
                    bool fromTop    = ((System.Convert.ToInt32(itemBounds[1].ToString()) <= System.Convert.ToInt32(tmpBounds[1].ToString())));

                    Debug.LogWarning("SUBLOOP CONDITION:" + System.Convert.ToInt32(itemBounds[0].ToString()) + "  |  " + System.Convert.ToInt32(tmpBounds[0].ToString()));
                    Debug.LogWarning("SUBLOOP CONDITION:" + System.Convert.ToInt32(itemBounds[1].ToString()) + "  |  " + System.Convert.ToInt32(tmpBounds[1].ToString()));


                    if (fromBottom && fromTop)
                    {
                        Debug.LogWarning("SUBLOOP ADD:" + subloop);
                        subloop += 1;

                        subloopObjectList.Add(item);
                    }
                }
            }
        }

        if (!existingLoop)
        {
            var loop      = Instantiate(loopPrefab, loopsTransform);
            int currLayer = (GameObject.Find("#" + (GameObject.Find("TCPService").GetComponent <TCPService>().GetDiagCount() - 1))).layer;
            loop.layer = currLayer;
            TCPService.SetLayerRecursively(loop, currLayer);


            loopsListAll.Add(loop);

            // get loop object script
            var lopScript = loop.GetComponent <Loop>();

            // init Object
            lopScript.setBounds(tmpBounds);
            lopScript.addLoopObject(tmpObject);

            Debug.LogWarning("SUBLOOP LOOP:" + subloop);


            for (int i = 0; i < subloop; i++)
            {
                subloopObjectList[i].GetComponent <Loop>().decreaseLevel();
            }
        }
        else
        {
            tmpLoop.addLoopObject(tmpObject);
        }
    }