Exemplo n.º 1
0
        private void OnFileDistributed(FileDistributeMessage message)
        {
            WatcherChangeTypes changeType  = message.ChangeType;
            string             path        = message.Path;
            string             fileName    = message.FileName;
            string             oldFileName = null;
            bool isDirectory = message.IsDirectory;

            byte[] fileData = null;
            if (changeType == WatcherChangeTypes.Renamed)
            {
                oldFileName = message.OldFileName;
            }
            if (changeType != WatcherChangeTypes.Deleted && !isDirectory)
            {
                fileData = message.FileData;
            }
            this.FileDistributed(this, changeType, path, fileName, oldFileName, isDirectory, fileData);
        }
Exemplo n.º 2
0
        public static void ProcessThread()
        {
            Log <RCServerService> .Logger.Info("FileDistributor >> Started...");

            while (!FileDistributor._exit)
            {
                FileDistributor._queueEvent.WaitOne();
                if (FileDistributor._exit)
                {
                    return;
                }
                FileDistributor.FileChangedInfo fileChangedInfo;
                lock (FileDistributor._queue.SyncRoot)
                {
                    if (FileDistributor._queue.Count == 0)
                    {
                        FileDistributor._queueEvent.Reset();
                        continue;
                    }
                    fileChangedInfo = (FileDistributor.FileChangedInfo)FileDistributor._queue.Dequeue();
                }
                IEnumerable <int> cliendIDList = Base.ClientServer.GetCliendIDList();
                foreach (int num in cliendIDList)
                {
                    bool                flag2  = false;
                    RCClient            client = Base.ClientServer.GetClient(num);
                    RCProcessCollection rcprocessCollection = client.ProcessList as RCProcessCollection;
                    foreach (RCProcess rcprocess in rcprocessCollection)
                    {
                        if (rcprocess.WorkingDirectory.IndexOf(fileChangedInfo.pathName) >= 0)
                        {
                            flag2 = true;
                            break;
                        }
                    }
                    if (flag2)
                    {
                        try
                        {
                            byte[] array = null;
                            if (fileChangedInfo.changeType != WatcherChangeTypes.Deleted && !fileChangedInfo.isDirectory)
                            {
                                string path = string.Concat(new string[]
                                {
                                    Directory.GetCurrentDirectory(),
                                    "\\DistributeFiles\\",
                                    fileChangedInfo.pathName,
                                    "\\",
                                    fileChangedInfo.fileName
                                });
                                FileStream fileStream = File.Open(path, FileMode.Open, FileAccess.Read, FileShare.Read);
                                array = new byte[fileStream.Length];
                                fileStream.Read(array, 0, (int)fileStream.Length);
                                fileStream.Close();
                            }
                            FileDistributeMessage message = new FileDistributeMessage(fileChangedInfo.changeType, fileChangedInfo.pathName, fileChangedInfo.fileName, fileChangedInfo.oldFileName, fileChangedInfo.isDirectory, array);
                            Base.ClientServer.SendMessage <FileDistributeMessage>(num, message);
                            Log <RCServerService> .Logger.InfoFormat("FileDistributor >> [{0}] : {1} {2}\\{3}.", new object[]
                            {
                                fileChangedInfo.changeType,
                                fileChangedInfo.isDirectory ? "Dir " : "File ",
                                fileChangedInfo.pathName,
                                fileChangedInfo.fileName
                            });
                        }
                        catch (Exception ex)
                        {
                            Log <RCServerService> .Logger.ErrorFormat("FileDistributor >> {0}\\{1} : {2}", fileChangedInfo.pathName, fileChangedInfo.fileName, ex.Message);
                        }
                    }
                }
            }
        }