protected override void OnOpen() { string cookies = Context.Headers.Get("cookie"); user = cookies.Substring(cookies.IndexOf("user") + 5).Split(';')[0]; global.WebSocketSessionsMap.Add(user, ID); global.updateCoWorkers(user, true); foreach (string file in global.files.EditingFiles()) { WatchDogMessage m = new WatchDogMessage(WatchDogMessageType.Lock, global.User, file, global.DropboxBasePath); Send(m.ToString()); } }
private void sendMessage(WatchDogMessage message) { string sharedfolder = null; foreach (SharedFolderMetadata folder in SharedFolders) { if (folder.PathLower != null && message.Path.ToLower().StartsWith(folder.PathLower)) { sharedfolder = folder.SharedFolderId; break; } } if (sharedfolder != null) { foreach (SharedUser user in global.Folder_coWorkers[sharedfolder]) { sendMessage(user.Email, message.ToString()); } } }
public static WatchDogMessage FromString(string value, string basepath) { WatchDogMessage message = new WatchDogMessage(basepath); string[] param = value.Split(','); if (param.Length != 3 && param.Length != 5) { throw new WatchDogMessageException("Error Message Params Count."); } message.User = param[1]; message.Path = param[2]; if (param[0].Equals("LOCK")) { message.Type = WatchDogMessageType.Lock; } else if (param[0].Equals("UNLOCK")) { message.Type = WatchDogMessageType.UnLock; try { message.Time = int.Parse(param[3]); } catch (Exception) { throw new WatchDogMessageException("Prase Time Failed."); } try { message.Flow = int.Parse(param[4]); } catch (Exception) { throw new WatchDogMessageException("Prase Flow Failed."); } } else { throw new WatchDogMessageException("Unknown Message Type."); } return(message); }
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(); //} } } }
public MainWindow() { InitializeComponent(); AppDomain.CurrentDomain.AssemblyResolve += Resolver; initNotifyIcon(); this.ResizeMode = ResizeMode.NoResize; this.Closing += (o, e) => { exitProgram(); }; this.Loaded += (o, e) => { mswin.Owner = this; Process[] procs = Process.GetProcessesByName("Dropbox"); if (procs.Length == 0) { MessageBox.Show("Dropbox is not running!", "ConflictReaper"); this.Hide(); exitProgram(); } DropBoxProcessIds = new int[procs.Length]; for (int i = 0; i < procs.Length; i++) { DropBoxProcessIds[i] = procs[i].Id; } keyboardHook = new KeyboardHook(); keyboardHook.InstallHook(); }; this.LocationChanged += (o, e) => { mswin.Left = Left + (Width - mswin.Width) / 2; mswin.Top = Top + (Height - mswin.Height) / 2; }; global.OnRefresh += RefreshDatagrid; global.files.OnProcessExit += (s, e) => { WatchDogMessage message = new WatchDogMessage(WatchDogMessageType.UnLock, global.User, e.filename, 0, 0, global.DropboxBasePath); sendMessage(message); }; global.files.OnFileEdit += (s, e) => { WatchDogMessage message = new WatchDogMessage(WatchDogMessageType.Lock, global.User, e.filename, global.DropboxBasePath); sendMessage(message); }; KeyboardHook.OnKeyboardInput += (s, e) => { KeyboardHook.HookStruct data = e.hookData; int key = data.vkCode; if (e.wParam == 256) { if (key == 162 || key == 163) { isCtrlDown = true; return; } if (key == 164 || key == 165) { isAltDown = true; return; } if (key == 160 || key == 161) { isShiftDown = true; return; } if ((isAltDown == false && isShiftDown == false && isCtrlDown == false && ((key >= 48 && key <= 57) || (key >= 65 && key <= 90) || (key >= 186 && key <= 192) || (key >= 219 && key <= 222) || key == 8 || key == 9 || key == 13 || key == 32 || key == 46)) || isCtrlDown == true && (key == 86 || key == 88)) { int FocusedProcessId; GetWindowThreadProcessId(GetForegroundWindow(), out FocusedProcessId); //if (global.ProcessesThatOpenFile.Contains(FocusedProcessId)) //{ string title = Process.GetProcessById(FocusedProcessId).MainWindowTitle; System.Diagnostics.Debug.WriteLine(title); global.files.FileEdit(title); //} } } if (e.wParam == 257) { if (key == 162 || key == 163) { isCtrlDown = false; return; } if (key == 164 || key == 165) { isAltDown = false; return; } if (key == 160 || key == 161) { isShiftDown = false; return; } } }; FileOpenMonitorInterface.OnFileOpening += (object sender, FileOpeningEventArg e) => { String Filename = null; int procId; if (e.filename.StartsWith("CreateFile")) { procId = e.id; Filename = e.filename.Substring(11); if (!File.Exists(Filename)) { return; } } else { string[] Args = e.filename.Split('|'); procId = int.Parse(Args[3]); HookInjector injector = new HookInjector(procId, Args[4]); injector.Inject(); int start = Args[2].IndexOf('\"', 1) + 2; Filename = praseFilename(Args[2], start); if (Filename != null && Filename.StartsWith(global.DropboxPath)) { Process proc = Process.GetProcessById(procId); if (global.ProcessesThatOpenFile.Contains(proc.Id)) { proc.Exited += (s, earg) => { Thread.Sleep(500); global.files.ProcessExit(proc.Id); global.ProcessesThatOpenFile.Remove(proc.Id); } } ; } } if (Filename != null && Filename.StartsWith(global.DropboxPath)) { if (!global.ProcessesThatOpenFile.Contains(procId)) { global.ProcessesThatOpenFile.Add(procId); } global.files.setStatus(Filename, FileStatus.Open, true); global.files.ProcessOpen(procId, Filename); } }; ConflictReaperWebSocketHandler.OnLockChange += OnWebSocketMessage; emailBox.Text = Properties.Settings.Default.email; passwordBox.Password = Properties.Settings.Default.pwd; pathBox.Text = Properties.Settings.Default.dropboxPath; global.User = Properties.Settings.Default.user; }
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; }