private void OnWebSocketMessage(object s, MessageEventArgs e) { if (e.IsText) { WatchDogMessage m = WatchDogMessage.FromString(e.Data, global.DropboxBasePath); if (m.Type == WatchDogMessageType.Lock) { global.files.setStatus(m.getLocalPath(), FileStatus.EditByOther, true); global.files.setEditor(m.getLocalPath(), m.User); /*if (global.files.isOpening(m.getLocalPath())) * { * MessageBox.Show("Warning: " + m.User + " starts to edit the file \"" + m.Path + "\" that you are opening.", "ConflictReaper"); * }*/ } else { /*if (global.files.isOpening(m.getLocalPath())) * { * MessageBox.Show("The file \"" + m.getLocalPath() + "\" that you are opening has been changed by " + m.User + ".\r\nPlease close the file so that the Dropbox Client can update it.", "ConflictReaper"); + global.files.setStatus(m.getLocalPath(), FileStatus.EditByOther, false); + global.files.setEditor(m.getLocalPath(), null); + } + else + {*/ //netcputest.start(); //测量Dropbox客户端下载流量 int totalRecvBytes = 0; int time = 0; FlowMeasureDevice device = flowMeasureDevicePool.getDevice(); device.getPorts(DropBoxProcessIds); bool end = false; new Thread(new ThreadStart(() => { while (!end) { Thread.Sleep(300); device.getPorts(DropBoxProcessIds); } })).Start(); device.Start(); while (time < m.Time) { Thread.Sleep(1000); time++; totalRecvBytes += device.NetRecvBytes; } device.Stop(); end = true; global.files.setStatus(m.getLocalPath(), FileStatus.EditByOther, false); global.files.setEditor(m.getLocalPath(), null); bool End = dropboxclient.IsUpdated(m.getLocalPath()); if (totalRecvBytes < 10000 && !End) { //global.files.setStatus(m.getLocalPath(), FileStatus.Uncheck, true); dropboxclient.Download(m.getLocalPath()); } //netcputest.stop(); //} } } }
private void setFileSystemWatcher() { FileSaveWatcher = new FileSystemWatcher(); FileSaveWatcher.Path = global.DropboxPath; FileSaveWatcher.NotifyFilter = NotifyFilters.LastWrite | NotifyFilters.FileName | NotifyFilters.CreationTime | NotifyFilters.DirectoryName | NotifyFilters.Size; FileSaveWatcher.Changed += (s, e) => { new Thread(new ThreadStart(() => { if (global.files.isEditing(e.FullPath)) { global.files.setStatus(e.FullPath, FileStatus.Edit, false); Debug.WriteLine(DateTime.Now.ToString("HH:mm:ss")); //netcputest.start(); int totalSendBytes = 0; int time = 0; int count = 0; FlowMeasureDevice device = flowMeasureDevicePool.getDevice(); device.getPorts(DropBoxProcessIds); device.Start(); bool end = false; new Thread(new ThreadStart(() => { while (!end) { device.getPorts(DropBoxProcessIds); Thread.Sleep(300); } })).Start(); //do //{ while (count < 3) { Thread.Sleep(5000); Debug.WriteLine("loop " + device.NetSendBytes); if (device.NetSendBytes < 10000) { count++; } else { count = 0; } time += 5; totalSendBytes += device.NetSendBytes; device.Refresh(); } //} while (!dropboxclient.IsUpdated(e.FullPath)); end = true; device.Stop(); WatchDogMessage message = new WatchDogMessage(WatchDogMessageType.UnLock, global.User, e.FullPath, time, totalSendBytes, global.DropboxBasePath); sendMessage(message); //netcputest.stop(); } })).Start(); }; FileSaveWatcher.IncludeSubdirectories = true; FileSaveWatcher.Filter = ""; FileSaveWatcher.EnableRaisingEvents = true; }