Beispiel #1
0
        public void Update()
        {
            if (!IPC.Updated)
            {
                return;
            }

            IPC.Updated = false;

            List <string> fileNameVec = FileSystem.ListFilesInDirectory(Globals.IpcPath);

            foreach (string fileNameCurrent in fileNameVec)
            {
                string fileNameEveryone = "";
                if (fileNameCurrent.Length >= 8)
                {
                    fileNameEveryone = fileNameCurrent.Substring(0, 8);
                }

                if (fileNameCurrent.Length > selfName.Length || fileNameEveryone == "everyone")
                {
                    if (IPC.FileNameProcessedMap.ContainsKey(fileNameCurrent) && IPC.FileNameProcessedMap[fileNameCurrent] == true)
                    {
                        continue;
                    }
                    else
                    {
                        IPC.FileNameProcessedMap[fileNameCurrent] = true;
                    }

                    string fileName   = "";
                    string fileNameID = "";
                    if (fileNameEveryone != "everyone")
                    {
                        fileName   = fileNameCurrent.Substring(0, selfName.Length);
                        fileNameID = fileNameCurrent.Substring(selfName.Length, fileNameCurrent.Length - selfName.Length);
                    }

                    if (fileName == selfName || fileNameEveryone == "everyone")
                    {
                        Thread.Sleep(20);

                        List <string> lines = FileSystem.ReadTextFile(Globals.IpcPath + "\\" + fileNameCurrent);
                        // FileSystem.DeleteFile(Globals.IpcPath + "\\" + fileNameCurrent);

                        string[] messageVec  = lines[0].Split('!');
                        string   messageHead = messageVec[0];
                        string   messageBody = messageVec[1];

                        Console.WriteLine("message received " + " " + messageHead + " " + messageBody + " " + fileNameCurrent);

                        if (!responseMap.ContainsKey(messageHead))
                        {
                            if (commandMap.ContainsKey(messageHead))
                            {
                                commandMap[messageHead](messageBody);
                            }
                        }
                        else
                        {
                            Func <string, int> func = responseMap[messageHead];
                            responseMap.Remove(messageHead);
                            func(messageBody);
                        }
                    }
                }
            }

            IPC.Updated = true;
        }