├── .gitattributes ├── .gitignore ├── ProcessMonitor.App ├── App.config ├── App.xaml ├── App.xaml.cs ├── Command │ └── RelayCommand.cs ├── Images │ ├── Icon.ico │ ├── add.png │ ├── clear.png │ ├── connect.png │ ├── disconnect.png │ ├── exit.png │ ├── remove.png │ ├── reset.png │ ├── start.png │ ├── stop.png │ └── update.png ├── Presenters │ ├── AddToWatchPresenter.cs │ ├── IPresenter.cs │ └── MainPresenter.cs ├── ProcessMonitor.App.csproj ├── Properties │ ├── AssemblyInfo.cs │ └── DataSources │ │ └── ProcessMonitor.WatchProcess.datasource ├── Service References │ └── MonitorService │ │ ├── Arrays.xsd │ │ ├── Message1.xsd │ │ ├── ProcessMonitor1.xsd │ │ ├── Reference.cs │ │ ├── Reference.svcmap │ │ ├── configuration.svcinfo │ │ ├── configuration91.svcinfo │ │ ├── service1.wsdl │ │ ├── service2.xsd │ │ └── service21.xsd ├── ViewModels │ ├── ViewModelBase.cs │ └── WatchProcessViewModel.cs └── Views │ ├── AboutView.xaml │ ├── AboutView.xaml.cs │ ├── AddToWatchView.xaml │ ├── AddToWatchView.xaml.cs │ ├── ConnectView.xaml │ ├── ConnectView.xaml.cs │ ├── IAddToWatchView.cs │ ├── IConnectView.cs │ ├── IMainView.cs │ ├── IView.cs │ ├── MainView.xaml │ └── MainView.xaml.cs ├── ProcessMonitor.ConsoleApp ├── App.config ├── ProcessMonitor.ConsoleApp.csproj ├── Program.cs └── Properties │ └── AssemblyInfo.cs ├── ProcessMonitor.Installer ├── Features.wxs ├── Files.wxs ├── License.rtf ├── ProcessMonitor.Installer.wixproj ├── Product.wxs ├── Shortcuts.wxs └── Variables.wxi ├── ProcessMonitor.Service ├── !install.bat ├── !uninstall.bat ├── App.config ├── MonitorService.cs ├── ProcessMonitor.Service.csproj ├── Program.cs ├── ProjectInstaller.cs └── Properties │ └── AssemblyInfo.cs ├── ProcessMonitor.sln ├── ProcessMonitor ├── App.config ├── IMonitor.cs ├── Monitor.cs ├── ProcessMonitor.csproj ├── Properties │ └── AssemblyInfo.cs └── WatchProcess.cs └── README.md /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | 4 | # Custom for Visual Studio 5 | *.cs diff=csharp 6 | *.sln merge=union 7 | *.csproj merge=union 8 | *.vbproj merge=union 9 | *.fsproj merge=union 10 | *.dbproj merge=union 11 | 12 | # Standard to msysgit 13 | *.doc diff=astextplain 14 | *.DOC diff=astextplain 15 | *.docx diff=astextplain 16 | *.DOCX diff=astextplain 17 | *.dot diff=astextplain 18 | *.DOT diff=astextplain 19 | *.pdf diff=astextplain 20 | *.PDF diff=astextplain 21 | *.rtf diff=astextplain 22 | *.RTF diff=astextplain 23 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | [Bb]in/ 2 | [Oo]bj/ 3 | [Dd]ebug/ 4 | [Rr]elease/ 5 | TestResults 6 | packages 7 | 8 | *.com 9 | *.dll 10 | *.exe 11 | *.pdb 12 | *.obj 13 | 14 | *.zip 15 | *.log 16 | 17 | *.mdf 18 | *.ldf 19 | *.suo 20 | *.vssscc 21 | *.vspscc 22 | *.psess 23 | *.vsp 24 | *.user 25 | *.nupkg 26 | *.nuspec 27 | *.diff 28 | *.design 29 | *.pfx 30 | 31 | Thumbs.db -------------------------------------------------------------------------------- /ProcessMonitor.App/App.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 19 | 20 | -------------------------------------------------------------------------------- /ProcessMonitor.App/App.xaml: -------------------------------------------------------------------------------- 1 |  4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /ProcessMonitor.App/App.xaml.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Configuration; 4 | using System.Data; 5 | using System.Linq; 6 | using System.Threading.Tasks; 7 | using System.Windows; 8 | using ProcessMonitor.App.Presenters; 9 | using ProcessMonitor.App.Views; 10 | 11 | namespace ProcessMonitor.App 12 | { 13 | 14 | public partial class App : Application 15 | { 16 | 17 | protected override void OnStartup(StartupEventArgs e) 18 | { 19 | Dispatcher.UnhandledException += (o, args) => 20 | #if DEBUG 21 | MessageBox.Show(args.Exception.ToString()); 22 | #else 23 | MessageBox.Show(args.Exception.Message); 24 | #endif 25 | 26 | MainView mainView = new MainView(); 27 | MainPresenter presenter = new MainPresenter(mainView); 28 | //mainView.Presenter = presenter; 29 | mainView.Show(); 30 | //base.OnStartup(e); 31 | } 32 | 33 | } 34 | 35 | } 36 | -------------------------------------------------------------------------------- /ProcessMonitor.App/Command/RelayCommand.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Windows; 3 | using System.Windows.Input; 4 | 5 | namespace ProcessMonitor.App.Command 6 | { 7 | 8 | public class RelayCommand : ICommand 9 | { 10 | 11 | private readonly Action execute; 12 | private readonly Predicate canExecute; 13 | 14 | public event EventHandler CanExecuteChanged 15 | { 16 | add { CommandManager.RequerySuggested += value; } 17 | remove { CommandManager.RequerySuggested -= value; } 18 | } 19 | 20 | public RelayCommand(Action execute) : this(execute, null) { } 21 | 22 | public RelayCommand(Action execute, Predicate canExecute) 23 | { 24 | this.execute = execute; 25 | this.canExecute = canExecute; 26 | } 27 | 28 | public void Execute(object parameter) 29 | { 30 | execute(parameter); 31 | } 32 | 33 | [System.Diagnostics.DebuggerStepThrough] 34 | public bool CanExecute(object parameter) 35 | { 36 | return canExecute == null ? true : canExecute(parameter); 37 | } 38 | 39 | } 40 | 41 | public class RelayCommand : ICommand 42 | { 43 | 44 | private readonly Action execute; 45 | private readonly Predicate canExecute; 46 | 47 | public event EventHandler CanExecuteChanged 48 | { 49 | add { CommandManager.RequerySuggested += value; } 50 | remove { CommandManager.RequerySuggested -= value; } 51 | } 52 | 53 | public RelayCommand(Action execute) : this(execute, null) { } 54 | 55 | public RelayCommand(Action execute, Predicate canExecute) 56 | { 57 | this.execute = execute; 58 | this.canExecute = canExecute; 59 | } 60 | 61 | public void Execute(T parameter) 62 | { 63 | execute(parameter); 64 | } 65 | 66 | public bool CanExecute(T parameter) 67 | { 68 | return canExecute == null ? true : canExecute(parameter); 69 | } 70 | 71 | void ICommand.Execute(object parameter) 72 | { 73 | Execute((T)parameter); 74 | } 75 | 76 | bool ICommand.CanExecute(object parameter) 77 | { 78 | return CanExecute((T)parameter); 79 | } 80 | 81 | } 82 | 83 | } -------------------------------------------------------------------------------- /ProcessMonitor.App/Images/Icon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sys27/ProcessMonitor/0c87100c6fef906ca538eb7c970d35a98194ae2a/ProcessMonitor.App/Images/Icon.ico -------------------------------------------------------------------------------- /ProcessMonitor.App/Images/add.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sys27/ProcessMonitor/0c87100c6fef906ca538eb7c970d35a98194ae2a/ProcessMonitor.App/Images/add.png -------------------------------------------------------------------------------- /ProcessMonitor.App/Images/clear.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sys27/ProcessMonitor/0c87100c6fef906ca538eb7c970d35a98194ae2a/ProcessMonitor.App/Images/clear.png -------------------------------------------------------------------------------- /ProcessMonitor.App/Images/connect.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sys27/ProcessMonitor/0c87100c6fef906ca538eb7c970d35a98194ae2a/ProcessMonitor.App/Images/connect.png -------------------------------------------------------------------------------- /ProcessMonitor.App/Images/disconnect.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sys27/ProcessMonitor/0c87100c6fef906ca538eb7c970d35a98194ae2a/ProcessMonitor.App/Images/disconnect.png -------------------------------------------------------------------------------- /ProcessMonitor.App/Images/exit.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sys27/ProcessMonitor/0c87100c6fef906ca538eb7c970d35a98194ae2a/ProcessMonitor.App/Images/exit.png -------------------------------------------------------------------------------- /ProcessMonitor.App/Images/remove.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sys27/ProcessMonitor/0c87100c6fef906ca538eb7c970d35a98194ae2a/ProcessMonitor.App/Images/remove.png -------------------------------------------------------------------------------- /ProcessMonitor.App/Images/reset.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sys27/ProcessMonitor/0c87100c6fef906ca538eb7c970d35a98194ae2a/ProcessMonitor.App/Images/reset.png -------------------------------------------------------------------------------- /ProcessMonitor.App/Images/start.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sys27/ProcessMonitor/0c87100c6fef906ca538eb7c970d35a98194ae2a/ProcessMonitor.App/Images/start.png -------------------------------------------------------------------------------- /ProcessMonitor.App/Images/stop.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sys27/ProcessMonitor/0c87100c6fef906ca538eb7c970d35a98194ae2a/ProcessMonitor.App/Images/stop.png -------------------------------------------------------------------------------- /ProcessMonitor.App/Images/update.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sys27/ProcessMonitor/0c87100c6fef906ca538eb7c970d35a98194ae2a/ProcessMonitor.App/Images/update.png -------------------------------------------------------------------------------- /ProcessMonitor.App/Presenters/AddToWatchPresenter.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | using System.Windows.Input; 7 | using ProcessMonitor.App.Command; 8 | using ProcessMonitor.App.MonitorService; 9 | using ProcessMonitor.App.Views; 10 | 11 | namespace ProcessMonitor.App.Presenters 12 | { 13 | 14 | public class AddToWatchPresenter : IPresenter 15 | { 16 | 17 | private IAddToWatchView view; 18 | private MainPresenter presenter; 19 | 20 | public AddToWatchPresenter(IAddToWatchView view, MainPresenter presenter) 21 | { 22 | this.view = view; 23 | this.presenter = presenter; 24 | view.Presenter = this; 25 | UpdateList(); 26 | } 27 | 28 | public void UpdateList() 29 | { 30 | view.SetAllProcesses(presenter.GetAllProcesses()); 31 | } 32 | 33 | public string Process 34 | { 35 | get 36 | { 37 | return view.Process; 38 | } 39 | set 40 | { 41 | view.Process = value; 42 | } 43 | } 44 | 45 | } 46 | 47 | } 48 | -------------------------------------------------------------------------------- /ProcessMonitor.App/Presenters/IPresenter.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace ProcessMonitor.App.Presenters 8 | { 9 | 10 | public interface IPresenter 11 | { 12 | 13 | } 14 | 15 | } 16 | -------------------------------------------------------------------------------- /ProcessMonitor.App/Presenters/MainPresenter.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Configuration; 4 | using System.IO; 5 | using System.Linq; 6 | using System.ServiceModel; 7 | using System.Text; 8 | using System.Threading.Tasks; 9 | using System.Timers; 10 | using System.Windows; 11 | using ProcessMonitor.App.MonitorService; 12 | using ProcessMonitor.App.ViewModels; 13 | using ProcessMonitor.App.Views; 14 | using System.Xml.Linq; 15 | 16 | namespace ProcessMonitor.App.Presenters 17 | { 18 | 19 | public class MainPresenter : IPresenter 20 | { 21 | 22 | private IMonitor monitor; 23 | private MonitorClient monitorClient; 24 | private bool isConnected; 25 | 26 | private Timer timer; 27 | 28 | private IMainView view; 29 | 30 | public MainPresenter(IMainView view) 31 | { 32 | this.view = view; 33 | view.Presenter = this; 34 | monitor = new Monitor(); 35 | timer = new Timer(500); 36 | timer.Elapsed += (o, args) => Update(); 37 | 38 | Update(); 39 | } 40 | 41 | private string ConvertMillisecondsToTime(uint milliseconds) 42 | { 43 | var seconds = milliseconds / 1000; 44 | var format = "{0} {1}"; 45 | 46 | StringBuilder result = new StringBuilder(); 47 | if (seconds >= 3600) 48 | { 49 | result.AppendFormat(format, seconds / 3600, "h"); 50 | seconds %= 3600; 51 | } 52 | if (seconds >= 60) 53 | { 54 | if (result.Length > 0) 55 | result.Append(' '); 56 | 57 | result.AppendFormat(format, seconds / 60, "min"); 58 | seconds %= 60; 59 | } 60 | if (seconds >= 0) 61 | { 62 | if (result.Length > 0) 63 | result.Append(' '); 64 | 65 | result.AppendFormat(format, seconds, "s"); 66 | } 67 | 68 | return result.ToString(); 69 | } 70 | 71 | public void Update() 72 | { 73 | try 74 | { 75 | UpdateWatchList(); 76 | UpdateTotalTime(); 77 | } 78 | catch (TimeoutException te) 79 | { 80 | #if DEBUG 81 | view.ShowError(te.ToString()); 82 | #else 83 | view.ShowError(te.Message); 84 | #endif 85 | } 86 | catch (EndpointNotFoundException enfe) 87 | { 88 | #if DEBUG 89 | view.ShowError(enfe.ToString()); 90 | #else 91 | view.ShowError(enfe.Message); 92 | #endif 93 | } 94 | } 95 | 96 | private void UpdateTotalTime() 97 | { 98 | if (isConnected) 99 | { 100 | //4.5 101 | //monitorClient.GetTotalWorkTimeAsync().ContinueWith(t => view.SetTotalTime(ConvertMillisecondsToTime(t.Result))); 102 | //monitorClient.GetTotalWorkTimeAsync(); 103 | view.SetTotalTime(ConvertMillisecondsToTime(monitorClient.GetTotalWorkTime())); 104 | } 105 | else 106 | { 107 | view.SetTotalTime(ConvertMillisecondsToTime(monitor.GetTotalWorkTime())); 108 | } 109 | } 110 | 111 | private void UpdateWatchList() 112 | { 113 | if (isConnected) 114 | { 115 | view.SetWatchList(monitorClient.GetWatchList().OrderBy(w => w.Process).Select(w => new WatchProcessViewModel(w.Process, ConvertMillisecondsToTime(w.Milliseconds)))); 116 | } 117 | else 118 | { 119 | view.SetWatchList(monitor.GetWatchList().OrderBy(w => w.Process).Select(w => new WatchProcessViewModel(w.Process, ConvertMillisecondsToTime(w.Milliseconds)))); 120 | } 121 | } 122 | 123 | public void Start() 124 | { 125 | try 126 | { 127 | if (isConnected) 128 | { 129 | //monitorClient.StartAsync().ContinueWith(t => Update()); 130 | if (!monitorClient.IsStarted()) 131 | { 132 | monitorClient.Start(); 133 | Update(); 134 | } 135 | } 136 | else 137 | { 138 | if (!monitor.IsStarted()) 139 | { 140 | monitor.Start(); 141 | Update(); 142 | } 143 | } 144 | 145 | timer.Start(); 146 | } 147 | catch (TimeoutException te) 148 | { 149 | #if DEBUG 150 | view.ShowError(te.ToString()); 151 | #else 152 | view.ShowError(te.Message); 153 | #endif 154 | } 155 | catch (EndpointNotFoundException enfe) 156 | { 157 | #if DEBUG 158 | view.ShowError(enfe.ToString()); 159 | #else 160 | view.ShowError(enfe.Message); 161 | #endif 162 | } 163 | } 164 | 165 | public void Stop() 166 | { 167 | try 168 | { 169 | if (isConnected) 170 | { 171 | //monitorClient.StopAsync().ContinueWith(t => Update()); 172 | if (monitorClient.IsStarted()) 173 | { 174 | monitorClient.Stop(); 175 | Update(); 176 | } 177 | } 178 | else 179 | { 180 | if (monitor.IsStarted()) 181 | { 182 | monitor.Stop(); 183 | Update(); 184 | } 185 | } 186 | 187 | timer.Stop(); 188 | } 189 | catch (TimeoutException te) 190 | { 191 | #if DEBUG 192 | view.ShowError(te.ToString()); 193 | #else 194 | view.ShowError(te.Message); 195 | #endif 196 | } 197 | catch (EndpointNotFoundException enfe) 198 | { 199 | #if DEBUG 200 | view.ShowError(enfe.ToString()); 201 | #else 202 | view.ShowError(enfe.Message); 203 | #endif 204 | } 205 | } 206 | 207 | public void Reset() 208 | { 209 | try 210 | { 211 | if (isConnected) 212 | { 213 | //monitorClient.ResetAsync().ContinueWith(t => Update()); 214 | monitorClient.Reset(); 215 | Update(); 216 | } 217 | else 218 | { 219 | monitor.Reset(); 220 | Update(); 221 | } 222 | } 223 | catch (TimeoutException te) 224 | { 225 | #if DEBUG 226 | view.ShowError(te.ToString()); 227 | #else 228 | view.ShowError(te.Message); 229 | #endif 230 | } 231 | catch (EndpointNotFoundException enfe) 232 | { 233 | #if DEBUG 234 | view.ShowError(enfe.ToString()); 235 | #else 236 | view.ShowError(enfe.Message); 237 | #endif 238 | } 239 | } 240 | 241 | public void AddToWatch(string process) 242 | { 243 | try 244 | { 245 | if (isConnected) 246 | { 247 | //monitorClient.AddToWatchAsync(process).ContinueWith(t => Update()); 248 | monitorClient.AddToWatch(process); 249 | Update(); 250 | } 251 | else 252 | { 253 | monitor.AddToWatch(process); 254 | Update(); 255 | } 256 | } 257 | catch (TimeoutException te) 258 | { 259 | #if DEBUG 260 | view.ShowError(te.ToString()); 261 | #else 262 | view.ShowError(te.Message); 263 | #endif 264 | } 265 | catch (EndpointNotFoundException enfe) 266 | { 267 | #if DEBUG 268 | view.ShowError(enfe.ToString()); 269 | #else 270 | view.ShowError(enfe.Message); 271 | #endif 272 | } 273 | } 274 | 275 | public void RemoveWatch(string process) 276 | { 277 | try 278 | { 279 | if (isConnected) 280 | { 281 | //monitorClient.RemoveWatchAsync(process).ContinueWith(t => Update()); 282 | monitorClient.RemoveWatch(process); 283 | Update(); 284 | } 285 | else 286 | { 287 | monitor.RemoveWatch(process); 288 | Update(); 289 | } 290 | } 291 | catch (TimeoutException te) 292 | { 293 | #if DEBUG 294 | view.ShowError(te.ToString()); 295 | #else 296 | view.ShowError(te.Message); 297 | #endif 298 | } 299 | catch (EndpointNotFoundException enfe) 300 | { 301 | #if DEBUG 302 | view.ShowError(enfe.ToString()); 303 | #else 304 | view.ShowError(enfe.Message); 305 | #endif 306 | } 307 | } 308 | 309 | public void ClearWatchs() 310 | { 311 | try 312 | { 313 | if (isConnected) 314 | { 315 | //monitorClient.ClearWatchsAsync().ContinueWith(t => Update()); 316 | monitorClient.ClearWatchs(); 317 | Update(); 318 | } 319 | else 320 | { 321 | monitor.ClearWatchs(); 322 | Update(); 323 | } 324 | } 325 | catch (TimeoutException te) 326 | { 327 | #if DEBUG 328 | view.ShowError(te.ToString()); 329 | #else 330 | view.ShowError(te.Message); 331 | #endif 332 | } 333 | catch (EndpointNotFoundException enfe) 334 | { 335 | #if DEBUG 336 | view.ShowError(enfe.ToString()); 337 | #else 338 | view.ShowError(enfe.Message); 339 | #endif 340 | } 341 | } 342 | 343 | public void LoadWatchs() 344 | { 345 | try 346 | { 347 | if (isConnected) 348 | { 349 | monitorClient.LoadWatchs(); 350 | Update(); 351 | } 352 | else 353 | { 354 | monitor.LoadWatchs(); 355 | Update(); 356 | } 357 | } 358 | catch (TimeoutException te) 359 | { 360 | #if DEBUG 361 | view.ShowError(te.ToString()); 362 | #else 363 | view.ShowError(te.Message); 364 | #endif 365 | } 366 | catch (EndpointNotFoundException enfe) 367 | { 368 | #if DEBUG 369 | view.ShowError(enfe.ToString()); 370 | #else 371 | view.ShowError(enfe.Message); 372 | #endif 373 | } 374 | } 375 | 376 | public void SaveWatchs() 377 | { 378 | try 379 | { 380 | if (isConnected) 381 | { 382 | monitorClient.SaveWatchs(); 383 | Update(); 384 | } 385 | else 386 | { 387 | monitor.SaveWatchs(); 388 | Update(); 389 | } 390 | } 391 | catch (TimeoutException te) 392 | { 393 | #if DEBUG 394 | view.ShowError(te.ToString()); 395 | #else 396 | view.ShowError(te.Message); 397 | #endif 398 | } 399 | catch (EndpointNotFoundException enfe) 400 | { 401 | #if DEBUG 402 | view.ShowError(enfe.ToString()); 403 | #else 404 | view.ShowError(enfe.Message); 405 | #endif 406 | } 407 | } 408 | 409 | public void Download(string path) 410 | { 411 | try 412 | { 413 | if (isConnected) 414 | { 415 | using (var stream = monitorClient.GetStatistics()) 416 | { 417 | using (var inStream = new StreamReader(stream)) 418 | { 419 | using (var outStream = new StreamWriter(path)) 420 | { 421 | outStream.Write(inStream.ReadToEnd()); 422 | } 423 | } 424 | } 425 | } 426 | } 427 | catch (TimeoutException te) 428 | { 429 | #if DEBUG 430 | view.ShowError(te.ToString()); 431 | #else 432 | view.ShowError(te.Message); 433 | #endif 434 | } 435 | catch (EndpointNotFoundException enfe) 436 | { 437 | #if DEBUG 438 | view.ShowError(enfe.ToString()); 439 | #else 440 | view.ShowError(enfe.Message); 441 | #endif 442 | } 443 | } 444 | 445 | public void SaveStatistics() 446 | { 447 | try 448 | { 449 | if (isConnected) 450 | { 451 | monitorClient.SaveStatistics(); 452 | } 453 | else 454 | { 455 | monitor.SaveStatistics(); 456 | } 457 | } 458 | catch (TimeoutException te) 459 | { 460 | #if DEBUG 461 | view.ShowError(te.ToString()); 462 | #else 463 | view.ShowError(te.Message); 464 | #endif 465 | } 466 | catch (EndpointNotFoundException enfe) 467 | { 468 | #if DEBUG 469 | view.ShowError(enfe.ToString()); 470 | #else 471 | view.ShowError(enfe.Message); 472 | #endif 473 | } 474 | } 475 | 476 | public void SetInterval(uint interval) 477 | { 478 | try 479 | { 480 | if (isConnected) 481 | { 482 | monitorClient.SetInterval(interval); 483 | } 484 | else 485 | { 486 | monitor.SetInterval(interval); 487 | } 488 | } 489 | catch (TimeoutException te) 490 | { 491 | #if DEBUG 492 | view.ShowError(te.ToString()); 493 | #else 494 | view.ShowError(te.Message); 495 | #endif 496 | } 497 | catch (EndpointNotFoundException enfe) 498 | { 499 | #if DEBUG 500 | view.ShowError(enfe.ToString()); 501 | #else 502 | view.ShowError(enfe.Message); 503 | #endif 504 | } 505 | } 506 | 507 | public void Connect(string server) 508 | { 509 | try 510 | { 511 | if (!isConnected) 512 | { 513 | monitorClient = new MonitorClient(new BasicHttpBinding() 514 | { 515 | OpenTimeout = TimeSpan.FromSeconds(5), 516 | SendTimeout = TimeSpan.FromSeconds(10), 517 | ReceiveTimeout = TimeSpan.FromSeconds(10), 518 | CloseTimeout = TimeSpan.FromSeconds(5) 519 | }, new EndpointAddress(string.Format(ConfigurationManager.AppSettings["connectionFormat"], server))); 520 | 521 | //monitorClient.Open(); 522 | monitorClient.IsStarted(); 523 | //monitorClient.ChannelFactory.Open(); 524 | 525 | isConnected = true; 526 | Update(); 527 | timer.Start(); 528 | } 529 | } 530 | catch (TimeoutException te) 531 | { 532 | #if DEBUG 533 | view.ShowError(te.ToString()); 534 | #else 535 | view.ShowError(te.Message); 536 | #endif 537 | } 538 | catch (EndpointNotFoundException enfe) 539 | { 540 | #if DEBUG 541 | view.ShowError(enfe.ToString()); 542 | #else 543 | view.ShowError(enfe.Message); 544 | #endif 545 | } 546 | } 547 | 548 | public void Disconnect() 549 | { 550 | try 551 | { 552 | if (isConnected) 553 | { 554 | monitorClient.SaveWatchs(); 555 | monitorClient.SaveStatistics(); 556 | monitorClient.Close(); 557 | 558 | isConnected = false; 559 | Update(); 560 | timer.Stop(); 561 | } 562 | } 563 | catch (TimeoutException te) 564 | { 565 | #if DEBUG 566 | view.ShowError(te.ToString()); 567 | #else 568 | view.ShowError(te.Message); 569 | #endif 570 | } 571 | catch (EndpointNotFoundException enfe) 572 | { 573 | #if DEBUG 574 | view.ShowError(enfe.ToString()); 575 | #else 576 | view.ShowError(enfe.Message); 577 | #endif 578 | } 579 | } 580 | 581 | public IEnumerable GetAllProcesses() 582 | { 583 | IEnumerable result = null; 584 | try 585 | { 586 | if (isConnected) 587 | { 588 | result = monitorClient.GetAllProcesses(); 589 | } 590 | else 591 | { 592 | result = monitor.GetAllProcesses(); 593 | } 594 | } 595 | catch (TimeoutException te) 596 | { 597 | #if DEBUG 598 | view.ShowError(te.ToString()); 599 | #else 600 | view.ShowError(te.Message); 601 | #endif 602 | } 603 | catch (EndpointNotFoundException enfe) 604 | { 605 | #if DEBUG 606 | view.ShowError(enfe.ToString()); 607 | #else 608 | view.ShowError(enfe.Message); 609 | #endif 610 | } 611 | 612 | return result; 613 | } 614 | 615 | public void Exit() 616 | { 617 | monitor.SaveWatchs(); 618 | monitor.SaveStatistics(); 619 | 620 | Application.Current.Shutdown(); 621 | } 622 | 623 | public bool IsStarted 624 | { 625 | get 626 | { 627 | bool result = false; 628 | try 629 | { 630 | if (isConnected) 631 | result = monitorClient.IsStarted(); 632 | else 633 | result = monitor.IsStarted(); 634 | } 635 | catch (TimeoutException te) 636 | { 637 | #if DEBUG 638 | view.ShowError(te.ToString()); 639 | #else 640 | view.ShowError(te.Message); 641 | #endif 642 | } 643 | catch (EndpointNotFoundException enfe) 644 | { 645 | #if DEBUG 646 | view.ShowError(enfe.ToString()); 647 | #else 648 | view.ShowError(enfe.Message); 649 | #endif 650 | } 651 | 652 | return result; 653 | } 654 | } 655 | 656 | public bool IsConnected 657 | { 658 | get 659 | { 660 | return isConnected; 661 | } 662 | } 663 | 664 | } 665 | 666 | } 667 | -------------------------------------------------------------------------------- /ProcessMonitor.App/ProcessMonitor.App.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | AnyCPU 7 | {6736D23A-497B-4FE4-AFDA-F37BC1EF2D69} 8 | WinExe 9 | Properties 10 | ProcessMonitor.App 11 | ProcessMonitor.App 12 | v4.0 13 | 512 14 | {60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} 15 | 4 16 | Client 17 | 18 | 19 | AnyCPU 20 | true 21 | full 22 | false 23 | bin\Debug\ 24 | DEBUG;TRACE 25 | prompt 26 | 4 27 | 28 | 29 | x86 30 | pdbonly 31 | true 32 | bin\Release\ 33 | TRACE 34 | prompt 35 | 4 36 | 37 | 38 | Images\Icon.ico 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 4.0 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | MSBuild:Compile 61 | Designer 62 | 63 | 64 | 65 | 66 | 67 | 68 | App.xaml 69 | Code 70 | 71 | 72 | True 73 | True 74 | Reference.svcmap 75 | 76 | 77 | 78 | 79 | AboutView.xaml 80 | 81 | 82 | AddToWatchView.xaml 83 | 84 | 85 | ConnectView.xaml 86 | 87 | 88 | 89 | 90 | 91 | 92 | MainView.xaml 93 | 94 | 95 | 96 | 97 | Code 98 | 99 | 100 | 101 | 102 | Designer 103 | 104 | 105 | Designer 106 | 107 | 108 | Designer 109 | 110 | 111 | 112 | Designer 113 | 114 | 115 | Designer 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | Designer 127 | MSBuild:Compile 128 | 129 | 130 | Designer 131 | MSBuild:Compile 132 | 133 | 134 | Designer 135 | MSBuild:Compile 136 | 137 | 138 | Designer 139 | MSBuild:Compile 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | 166 | 167 | {f760d1f5-aece-401b-b0d4-67338b1c4502} 168 | ProcessMonitor 169 | 170 | 171 | 172 | 173 | 174 | 175 | 176 | 177 | 178 | 179 | 180 | 181 | 182 | WCF Proxy Generator 183 | Reference.cs 184 | 185 | 186 | 187 | 194 | -------------------------------------------------------------------------------- /ProcessMonitor.App/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Resources; 3 | using System.Runtime.CompilerServices; 4 | using System.Runtime.InteropServices; 5 | using System.Windows; 6 | 7 | // General Information about an assembly is controlled through the following 8 | // set of attributes. Change these attribute values to modify the information 9 | // associated with an assembly. 10 | [assembly: AssemblyTitle("Process Monitor")] 11 | [assembly: AssemblyDescription("")] 12 | [assembly: AssemblyConfiguration("")] 13 | [assembly: AssemblyCompany("")] 14 | [assembly: AssemblyProduct("Process Monitor")] 15 | [assembly: AssemblyCopyright("Copyright © eXit 2012")] 16 | [assembly: AssemblyTrademark("")] 17 | [assembly: AssemblyCulture("")] 18 | 19 | // Setting ComVisible to false makes the types in this assembly not visible 20 | // to COM components. If you need to access a type in this assembly from 21 | // COM, set the ComVisible attribute to true on that type. 22 | [assembly: ComVisible(false)] 23 | 24 | //In order to begin building localizable applications, set 25 | //CultureYouAreCodingWith in your .csproj file 26 | //inside a . For example, if you are using US english 27 | //in your source files, set the to en-US. Then uncomment 28 | //the NeutralResourceLanguage attribute below. Update the "en-US" in 29 | //the line below to match the UICulture setting in the project file. 30 | 31 | //[assembly: NeutralResourcesLanguage("en-US", UltimateResourceFallbackLocation.Satellite)] 32 | 33 | 34 | [assembly: ThemeInfo( 35 | ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located 36 | //(used if a resource is not found in the page, 37 | // or application resource dictionaries) 38 | ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located 39 | //(used if a resource is not found in the page, 40 | // app, or any theme specific resource dictionaries) 41 | )] 42 | 43 | 44 | // Version information for an assembly consists of the following four values: 45 | // 46 | // Major Version 47 | // Minor Version 48 | // Build Number 49 | // Revision 50 | // 51 | // You can specify all the values or you can default the Build and Revision Numbers 52 | // by using the '*' as shown below: 53 | // [assembly: AssemblyVersion("1.0.*")] 54 | [assembly: AssemblyVersion("1.0.0.0")] 55 | [assembly: AssemblyFileVersion("1.0.0.0")] 56 | -------------------------------------------------------------------------------- /ProcessMonitor.App/Properties/DataSources/ProcessMonitor.WatchProcess.datasource: -------------------------------------------------------------------------------- 1 |  2 | 8 | 9 | ProcessMonitor.WatchProcess, ProcessMonitor, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null 10 | -------------------------------------------------------------------------------- /ProcessMonitor.App/Service References/MonitorService/Arrays.xsd: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /ProcessMonitor.App/Service References/MonitorService/Message1.xsd: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /ProcessMonitor.App/Service References/MonitorService/ProcessMonitor1.xsd: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /ProcessMonitor.App/Service References/MonitorService/Reference.cs: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // 3 | // Этот код создан программой. 4 | // Исполняемая версия:4.0.30319.17929 5 | // 6 | // Изменения в этом файле могут привести к неправильной работе и будут потеряны в случае 7 | // повторной генерации кода. 8 | // 9 | //------------------------------------------------------------------------------ 10 | 11 | namespace ProcessMonitor.App.MonitorService { 12 | 13 | 14 | [System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "4.0.0.0")] 15 | [System.ServiceModel.ServiceContractAttribute(ConfigurationName="MonitorService.IMonitor")] 16 | public interface IMonitor { 17 | 18 | [System.ServiceModel.OperationContractAttribute(Action="http://tempuri.org/IMonitor/Start", ReplyAction="http://tempuri.org/IMonitor/StartResponse")] 19 | void Start(); 20 | 21 | [System.ServiceModel.OperationContractAttribute(Action="http://tempuri.org/IMonitor/Stop", ReplyAction="http://tempuri.org/IMonitor/StopResponse")] 22 | void Stop(); 23 | 24 | [System.ServiceModel.OperationContractAttribute(Action="http://tempuri.org/IMonitor/AddToWatch", ReplyAction="http://tempuri.org/IMonitor/AddToWatchResponse")] 25 | void AddToWatch(string process); 26 | 27 | [System.ServiceModel.OperationContractAttribute(Action="http://tempuri.org/IMonitor/RemoveWatch", ReplyAction="http://tempuri.org/IMonitor/RemoveWatchResponse")] 28 | void RemoveWatch(string process); 29 | 30 | [System.ServiceModel.OperationContractAttribute(Action="http://tempuri.org/IMonitor/ClearWatchs", ReplyAction="http://tempuri.org/IMonitor/ClearWatchsResponse")] 31 | void ClearWatchs(); 32 | 33 | [System.ServiceModel.OperationContractAttribute(Action="http://tempuri.org/IMonitor/Reset", ReplyAction="http://tempuri.org/IMonitor/ResetResponse")] 34 | void Reset(); 35 | 36 | [System.ServiceModel.OperationContractAttribute(Action="http://tempuri.org/IMonitor/GetTotalWorkTime", ReplyAction="http://tempuri.org/IMonitor/GetTotalWorkTimeResponse")] 37 | uint GetTotalWorkTime(); 38 | 39 | [System.ServiceModel.OperationContractAttribute(Action="http://tempuri.org/IMonitor/GetWatchList", ReplyAction="http://tempuri.org/IMonitor/GetWatchListResponse")] 40 | ProcessMonitor.WatchProcess[] GetWatchList(); 41 | 42 | [System.ServiceModel.OperationContractAttribute(Action="http://tempuri.org/IMonitor/LoadWatchs", ReplyAction="http://tempuri.org/IMonitor/LoadWatchsResponse")] 43 | void LoadWatchs(); 44 | 45 | [System.ServiceModel.OperationContractAttribute(Action="http://tempuri.org/IMonitor/SaveWatchs", ReplyAction="http://tempuri.org/IMonitor/SaveWatchsResponse")] 46 | void SaveWatchs(); 47 | 48 | [System.ServiceModel.OperationContractAttribute(Action="http://tempuri.org/IMonitor/SaveStatistics", ReplyAction="http://tempuri.org/IMonitor/SaveStatisticsResponse")] 49 | void SaveStatistics(); 50 | 51 | [System.ServiceModel.OperationContractAttribute(Action="http://tempuri.org/IMonitor/GetInterval", ReplyAction="http://tempuri.org/IMonitor/GetIntervalResponse")] 52 | uint GetInterval(); 53 | 54 | [System.ServiceModel.OperationContractAttribute(Action="http://tempuri.org/IMonitor/SetInterval", ReplyAction="http://tempuri.org/IMonitor/SetIntervalResponse")] 55 | void SetInterval(uint interval); 56 | 57 | [System.ServiceModel.OperationContractAttribute(Action="http://tempuri.org/IMonitor/IsStarted", ReplyAction="http://tempuri.org/IMonitor/IsStartedResponse")] 58 | bool IsStarted(); 59 | 60 | [System.ServiceModel.OperationContractAttribute(Action="http://tempuri.org/IMonitor/GetStatistics", ReplyAction="http://tempuri.org/IMonitor/GetStatisticsResponse")] 61 | System.IO.Stream GetStatistics(); 62 | 63 | [System.ServiceModel.OperationContractAttribute(Action="http://tempuri.org/IMonitor/GetAllProcesses", ReplyAction="http://tempuri.org/IMonitor/GetAllProcessesResponse")] 64 | string[] GetAllProcesses(); 65 | } 66 | 67 | [System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "4.0.0.0")] 68 | public interface IMonitorChannel : ProcessMonitor.App.MonitorService.IMonitor, System.ServiceModel.IClientChannel { 69 | } 70 | 71 | [System.Diagnostics.DebuggerStepThroughAttribute()] 72 | [System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "4.0.0.0")] 73 | public partial class MonitorClient : System.ServiceModel.ClientBase, ProcessMonitor.App.MonitorService.IMonitor { 74 | 75 | public MonitorClient() { 76 | } 77 | 78 | public MonitorClient(string endpointConfigurationName) : 79 | base(endpointConfigurationName) { 80 | } 81 | 82 | public MonitorClient(string endpointConfigurationName, string remoteAddress) : 83 | base(endpointConfigurationName, remoteAddress) { 84 | } 85 | 86 | public MonitorClient(string endpointConfigurationName, System.ServiceModel.EndpointAddress remoteAddress) : 87 | base(endpointConfigurationName, remoteAddress) { 88 | } 89 | 90 | public MonitorClient(System.ServiceModel.Channels.Binding binding, System.ServiceModel.EndpointAddress remoteAddress) : 91 | base(binding, remoteAddress) { 92 | } 93 | 94 | public void Start() { 95 | base.Channel.Start(); 96 | } 97 | 98 | public void Stop() { 99 | base.Channel.Stop(); 100 | } 101 | 102 | public void AddToWatch(string process) { 103 | base.Channel.AddToWatch(process); 104 | } 105 | 106 | public void RemoveWatch(string process) { 107 | base.Channel.RemoveWatch(process); 108 | } 109 | 110 | public void ClearWatchs() { 111 | base.Channel.ClearWatchs(); 112 | } 113 | 114 | public void Reset() { 115 | base.Channel.Reset(); 116 | } 117 | 118 | public uint GetTotalWorkTime() { 119 | return base.Channel.GetTotalWorkTime(); 120 | } 121 | 122 | public ProcessMonitor.WatchProcess[] GetWatchList() { 123 | return base.Channel.GetWatchList(); 124 | } 125 | 126 | public void LoadWatchs() { 127 | base.Channel.LoadWatchs(); 128 | } 129 | 130 | public void SaveWatchs() { 131 | base.Channel.SaveWatchs(); 132 | } 133 | 134 | public void SaveStatistics() { 135 | base.Channel.SaveStatistics(); 136 | } 137 | 138 | public uint GetInterval() { 139 | return base.Channel.GetInterval(); 140 | } 141 | 142 | public void SetInterval(uint interval) { 143 | base.Channel.SetInterval(interval); 144 | } 145 | 146 | public bool IsStarted() { 147 | return base.Channel.IsStarted(); 148 | } 149 | 150 | public System.IO.Stream GetStatistics() { 151 | return base.Channel.GetStatistics(); 152 | } 153 | 154 | public string[] GetAllProcesses() { 155 | return base.Channel.GetAllProcesses(); 156 | } 157 | } 158 | } 159 | -------------------------------------------------------------------------------- /ProcessMonitor.App/Service References/MonitorService/Reference.svcmap: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | false 5 | true 6 | 7 | false 8 | false 9 | false 10 | 11 | 12 | true 13 | Auto 14 | true 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | -------------------------------------------------------------------------------- /ProcessMonitor.App/Service References/MonitorService/configuration.svcinfo: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /ProcessMonitor.App/Service References/MonitorService/configuration91.svcinfo: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | BasicHttpBinding_IMonitor 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | StrongWildcard 29 | 30 | 31 | 32 | 33 | 34 | 65536 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | System.ServiceModel.Configuration.XmlDictionaryReaderQuotasElement 44 | 45 | 46 | 0 47 | 48 | 49 | 0 50 | 51 | 52 | 0 53 | 54 | 55 | 0 56 | 57 | 58 | 0 59 | 60 | 61 | System.Text.UTF8Encoding 62 | 63 | 64 | Buffered 65 | 66 | 67 | 68 | 69 | 70 | Text 71 | 72 | 73 | System.ServiceModel.Configuration.BasicHttpSecurityElement 74 | 75 | 76 | None 77 | 78 | 79 | System.ServiceModel.Configuration.HttpTransportSecurityElement 80 | 81 | 82 | None 83 | 84 | 85 | None 86 | 87 | 88 | System.Security.Authentication.ExtendedProtection.Configuration.ExtendedProtectionPolicyElement 89 | 90 | 91 | Never 92 | 93 | 94 | TransportSelected 95 | 96 | 97 | (Коллекция) 98 | 99 | 100 | 101 | 102 | 103 | System.ServiceModel.Configuration.BasicHttpMessageSecurityElement 104 | 105 | 106 | UserName 107 | 108 | 109 | Default 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | http://192.168.1.100:4325/ProcessMonitor 119 | 120 | 121 | 122 | 123 | 124 | basicHttpBinding 125 | 126 | 127 | BasicHttpBinding_IMonitor 128 | 129 | 130 | MonitorService.IMonitor 131 | 132 | 133 | System.ServiceModel.Configuration.AddressHeaderCollectionElement 134 | 135 | 136 | <Header /> 137 | 138 | 139 | System.ServiceModel.Configuration.IdentityElement 140 | 141 | 142 | System.ServiceModel.Configuration.UserPrincipalNameElement 143 | 144 | 145 | 146 | 147 | 148 | System.ServiceModel.Configuration.ServicePrincipalNameElement 149 | 150 | 151 | 152 | 153 | 154 | System.ServiceModel.Configuration.DnsElement 155 | 156 | 157 | 158 | 159 | 160 | System.ServiceModel.Configuration.RsaElement 161 | 162 | 163 | 164 | 165 | 166 | System.ServiceModel.Configuration.CertificateElement 167 | 168 | 169 | 170 | 171 | 172 | System.ServiceModel.Configuration.CertificateReferenceElement 173 | 174 | 175 | My 176 | 177 | 178 | LocalMachine 179 | 180 | 181 | FindBySubjectDistinguishedName 182 | 183 | 184 | 185 | 186 | 187 | False 188 | 189 | 190 | BasicHttpBinding_IMonitor 191 | 192 | 193 | 194 | 195 | 196 | 197 | 198 | 199 | 200 | 201 | -------------------------------------------------------------------------------- /ProcessMonitor.App/Service References/MonitorService/service1.wsdl: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | 166 | 167 | 168 | 169 | 170 | 171 | 172 | 173 | 174 | 175 | 176 | 177 | 178 | 179 | 180 | 181 | 182 | 183 | 184 | 185 | 186 | 187 | 188 | 189 | 190 | 191 | 192 | 193 | 194 | 195 | 196 | 197 | 198 | 199 | 200 | 201 | 202 | 203 | 204 | 205 | 206 | 207 | 208 | 209 | 210 | 211 | 212 | 213 | 214 | 215 | 216 | 217 | 218 | 219 | 220 | 221 | 222 | 223 | 224 | 225 | 226 | 227 | 228 | 229 | 230 | 231 | 232 | 233 | 234 | 235 | 236 | 237 | 238 | 239 | 240 | 241 | 242 | 243 | 244 | 245 | 246 | 247 | 248 | 249 | 250 | 251 | 252 | 253 | 254 | 255 | 256 | 257 | 258 | 259 | 260 | 261 | 262 | 263 | 264 | 265 | 266 | 267 | 268 | 269 | 270 | 271 | 272 | 273 | 274 | 275 | 276 | 277 | 278 | 279 | 280 | 281 | 282 | 283 | 284 | 285 | 286 | 287 | 288 | 289 | 290 | 291 | 292 | 293 | 294 | 295 | 296 | 297 | 298 | 299 | 300 | 301 | 302 | 303 | 304 | 305 | 306 | 307 | 308 | 309 | 310 | 311 | 312 | 313 | 314 | 315 | 316 | 317 | 318 | 319 | 320 | 321 | 322 | 323 | 324 | 325 | 326 | -------------------------------------------------------------------------------- /ProcessMonitor.App/Service References/MonitorService/service2.xsd: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | 166 | 167 | 168 | 169 | 170 | 171 | 172 | 173 | 174 | 175 | 176 | 177 | 178 | 179 | 180 | 181 | 182 | 183 | 184 | -------------------------------------------------------------------------------- /ProcessMonitor.App/Service References/MonitorService/service21.xsd: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | -------------------------------------------------------------------------------- /ProcessMonitor.App/ViewModels/ViewModelBase.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.ComponentModel; 3 | 4 | namespace ProcessMonitor.App.ViewModels 5 | { 6 | 7 | public abstract class ViewModelBase : INotifyPropertyChanged 8 | { 9 | 10 | public event PropertyChangedEventHandler PropertyChanged; 11 | 12 | protected virtual void OnPropertyChanged(string property) 13 | { 14 | if (PropertyChanged != null) 15 | PropertyChanged(this, new PropertyChangedEventArgs(property)); 16 | } 17 | 18 | } 19 | 20 | } -------------------------------------------------------------------------------- /ProcessMonitor.App/ViewModels/WatchProcessViewModel.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace ProcessMonitor.App.ViewModels 8 | { 9 | 10 | public class WatchProcessViewModel : ViewModelBase 11 | { 12 | 13 | private string process; 14 | private string time; 15 | 16 | public WatchProcessViewModel(string process, string milliseconds) 17 | { 18 | this.process = process; 19 | this.time = milliseconds; 20 | } 21 | 22 | public string Process 23 | { 24 | get 25 | { 26 | return process; 27 | } 28 | set 29 | { 30 | process = value; 31 | OnPropertyChanged("Process"); 32 | } 33 | } 34 | 35 | public string Milliseconds 36 | { 37 | get 38 | { 39 | return time; 40 | } 41 | set 42 | { 43 | time = value; 44 | OnPropertyChanged("Milliseconds"); 45 | } 46 | } 47 | 48 | } 49 | 50 | } 51 | -------------------------------------------------------------------------------- /ProcessMonitor.App/Views/AboutView.xaml: -------------------------------------------------------------------------------- 1 |  6 | 7 | 17 | 18 | 101 | 104 | 107 | 108 | 111 | 114 | 117 | 120 | 121 | 124 | 127 | 128 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | -------------------------------------------------------------------------------- /ProcessMonitor.App/Views/MainView.xaml.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | using System.Windows; 7 | using System.Windows.Controls; 8 | using System.Windows.Data; 9 | using System.Windows.Documents; 10 | using System.Windows.Input; 11 | using System.Windows.Media; 12 | using System.Windows.Media.Imaging; 13 | using System.Windows.Shapes; 14 | using ProcessMonitor.App.Command; 15 | using ProcessMonitor.App.Presenters; 16 | using ProcessMonitor.App.ViewModels; 17 | 18 | namespace ProcessMonitor.App.Views 19 | { 20 | 21 | public partial class MainView : Window, IMainView 22 | { 23 | 24 | private MainPresenter presenter; 25 | 26 | private RelayCommand startMonitorCommand; 27 | private RelayCommand stopMonitorCommand; 28 | private RelayCommand resetMonitorCommand; 29 | private RelayCommand addWatchCommand; 30 | private RelayCommand removeWatchCommand; 31 | private RelayCommand clearWatchsCommand; 32 | private RelayCommand loadWatchCommand; 33 | private RelayCommand saveWatchCommand; 34 | private RelayCommand openStatisticsCommand; 35 | private RelayCommand downloadStatisticsCommand; 36 | private RelayCommand saveStatisticsCommand; 37 | private RelayCommand updateCommand; 38 | private RelayCommand connectCommand; 39 | private RelayCommand disconnectCommand; 40 | private RelayCommand aboutCommand; 41 | private RelayCommand exitCommand; 42 | 43 | public MainView() 44 | { 45 | InitializeComponent(); 46 | this.DataContext = this; 47 | } 48 | 49 | protected override void OnClosed(EventArgs e) 50 | { 51 | presenter.Exit(); 52 | //base.OnClosed(e); 53 | } 54 | 55 | public void ShowError(string message) 56 | { 57 | Dispatcher.BeginInvoke(new Action(() => MessageBox.Show(this, message, "Error", MessageBoxButton.OK, MessageBoxImage.Error))); 58 | } 59 | 60 | public void SetWatchList(IEnumerable watchList) 61 | { 62 | Dispatcher.BeginInvoke(new Action(() => 63 | { 64 | var selectedIndex = watchListBox.SelectedIndex; 65 | watchListBox.ItemsSource = watchList; 66 | watchListBox.SelectedIndex = selectedIndex; 67 | })); 68 | } 69 | 70 | public void SetTotalTime(string time) 71 | { 72 | Dispatcher.BeginInvoke(new Action(() => totalTimeBox.Text = string.Format("Total time: {0}", time))); 73 | //totalTimeBox.Text = string.Format("Total time: {0}", time); 74 | } 75 | 76 | public IPresenter Presenter 77 | { 78 | get 79 | { 80 | return presenter; 81 | } 82 | set 83 | { 84 | presenter = (MainPresenter)value; 85 | } 86 | } 87 | 88 | public ICommand StartMonitorCommand 89 | { 90 | get 91 | { 92 | if (startMonitorCommand == null) 93 | startMonitorCommand = new RelayCommand(o => presenter.Start(), o => presenter != null && !presenter.IsStarted); 94 | 95 | return startMonitorCommand; 96 | } 97 | } 98 | 99 | public ICommand StopMonitorCommand 100 | { 101 | get 102 | { 103 | if (stopMonitorCommand == null) 104 | stopMonitorCommand = new RelayCommand(o => presenter.Stop(), o => presenter != null && presenter.IsStarted); 105 | 106 | return stopMonitorCommand; 107 | } 108 | } 109 | 110 | public ICommand ResetMonitorCommand 111 | { 112 | get 113 | { 114 | if (resetMonitorCommand == null) 115 | resetMonitorCommand = new RelayCommand(o => presenter.Reset()); 116 | 117 | return resetMonitorCommand; 118 | } 119 | } 120 | 121 | public ICommand AddWatchCommand 122 | { 123 | get 124 | { 125 | if (addWatchCommand == null) 126 | addWatchCommand = new RelayCommand(o => 127 | { 128 | AddToWatchView addView = new AddToWatchView() { Owner = this }; 129 | AddToWatchPresenter addPresenter = new AddToWatchPresenter(addView, this.presenter); 130 | if (addView.ShowDialog() == true) 131 | { 132 | presenter.AddToWatch(addPresenter.Process); 133 | } 134 | }); 135 | 136 | return addWatchCommand; 137 | } 138 | } 139 | 140 | public ICommand RemoveWatchCommand 141 | { 142 | get 143 | { 144 | if (removeWatchCommand == null) 145 | removeWatchCommand = new RelayCommand(o => 146 | { 147 | var process = watchListBox.SelectedItem as WatchProcessViewModel; 148 | if (process != null) 149 | { 150 | presenter.RemoveWatch(process.Process); 151 | } 152 | }, o => watchListBox.SelectedItem != null); 153 | 154 | return removeWatchCommand; 155 | } 156 | } 157 | 158 | public ICommand ClearWatchsCommand 159 | { 160 | get 161 | { 162 | if (clearWatchsCommand == null) 163 | clearWatchsCommand = new RelayCommand(o => presenter.ClearWatchs()); 164 | 165 | return clearWatchsCommand; 166 | } 167 | } 168 | 169 | public ICommand LoadWatchsCommand 170 | { 171 | get 172 | { 173 | if (loadWatchCommand == null) 174 | loadWatchCommand = new RelayCommand(o => presenter.LoadWatchs()); 175 | 176 | return loadWatchCommand; 177 | } 178 | } 179 | 180 | public ICommand SaveWatchsCommand 181 | { 182 | get 183 | { 184 | if (saveWatchCommand == null) 185 | saveWatchCommand = new RelayCommand(o => presenter.SaveWatchs()); 186 | 187 | return saveWatchCommand; 188 | } 189 | } 190 | 191 | public ICommand OpenStatisticsCommand 192 | { 193 | get 194 | { 195 | return openStatisticsCommand; 196 | } 197 | } 198 | 199 | public ICommand DownloadStatisticsCommand 200 | { 201 | get 202 | { 203 | if (downloadStatisticsCommand == null) 204 | downloadStatisticsCommand = new RelayCommand(o => 205 | { 206 | Microsoft.Win32.SaveFileDialog sfd = new Microsoft.Win32.SaveFileDialog() 207 | { 208 | FileName = "remoteStatistics.xml", 209 | Filter = "XML|*.xml", 210 | Title = "Save statistics" 211 | }; 212 | if (sfd.ShowDialog(this) == true) 213 | { 214 | presenter.Download(sfd.FileName); 215 | } 216 | }, o => presenter != null && presenter.IsConnected); 217 | 218 | return downloadStatisticsCommand; 219 | } 220 | } 221 | 222 | public ICommand SaveStatisticsCommand 223 | { 224 | get 225 | { 226 | if (saveStatisticsCommand == null) 227 | saveStatisticsCommand = new RelayCommand(o => presenter.SaveStatistics()); 228 | 229 | return saveStatisticsCommand; 230 | } 231 | } 232 | 233 | public ICommand UpdateCommand 234 | { 235 | get 236 | { 237 | if (updateCommand == null) 238 | updateCommand = new RelayCommand(o => presenter.Update()); 239 | 240 | return updateCommand; 241 | } 242 | } 243 | 244 | public ICommand ConnectCommand 245 | { 246 | get 247 | { 248 | if (connectCommand == null) 249 | connectCommand = new RelayCommand(o => 250 | { 251 | ConnectView connectView = new ConnectView() { Owner = this }; 252 | //ConnectPresenter connectPresenter = new ConnectPresenter(connectView); 253 | if (connectView.ShowDialog() == true) 254 | { 255 | //presenter.Connect(connectPresenter.Server); 256 | presenter.Connect(connectView.Server); 257 | } 258 | }, o => presenter != null && !presenter.IsConnected); 259 | 260 | return connectCommand; 261 | } 262 | } 263 | 264 | public ICommand DisconnectCommand 265 | { 266 | get 267 | { 268 | if (disconnectCommand == null) 269 | disconnectCommand = new RelayCommand(o => presenter.Disconnect(), o => presenter != null && presenter.IsConnected); 270 | 271 | return disconnectCommand; 272 | } 273 | } 274 | 275 | public ICommand AboutCommand 276 | { 277 | get 278 | { 279 | if (aboutCommand == null) 280 | aboutCommand = new RelayCommand(o => 281 | { 282 | AboutView aboutView = new AboutView() { Owner = this }; 283 | aboutView.ShowDialog(); 284 | }); 285 | 286 | return aboutCommand; 287 | } 288 | } 289 | 290 | public ICommand ExitCommand 291 | { 292 | get 293 | { 294 | if (exitCommand == null) 295 | exitCommand = new RelayCommand(o => presenter.Exit()); 296 | 297 | return exitCommand; 298 | } 299 | } 300 | 301 | } 302 | 303 | } 304 | -------------------------------------------------------------------------------- /ProcessMonitor.ConsoleApp/App.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | -------------------------------------------------------------------------------- /ProcessMonitor.ConsoleApp/ProcessMonitor.ConsoleApp.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | AnyCPU 7 | {5FFE7D09-E3C9-4A31-A762-D67649B7A728} 8 | Exe 9 | Properties 10 | ProcessMonitor.ConsoleApp 11 | ProcessMonitor.ConsoleApp 12 | v4.0 13 | 512 14 | Client 15 | 16 | 17 | AnyCPU 18 | true 19 | full 20 | false 21 | bin\Debug\ 22 | DEBUG;TRACE 23 | prompt 24 | 4 25 | 26 | 27 | AnyCPU 28 | pdbonly 29 | true 30 | bin\Release\ 31 | TRACE 32 | prompt 33 | 4 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | {f760d1f5-aece-401b-b0d4-67338b1c4502} 56 | ProcessMonitor 57 | 58 | 59 | 60 | 67 | -------------------------------------------------------------------------------- /ProcessMonitor.ConsoleApp/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Net; 5 | using System.ServiceModel; 6 | using System.Text; 7 | using System.Threading.Tasks; 8 | 9 | namespace ProcessMonitor.ConsoleApp 10 | { 11 | 12 | class Program 13 | { 14 | 15 | static void Main(string[] args) 16 | { 17 | Console.WriteLine("Run:"); 18 | Console.WriteLine("1 - Local Monitor"); 19 | Console.WriteLine("2 - Service"); 20 | 21 | var input = Console.ReadLine(); 22 | if (input == "1") 23 | { 24 | Monitor monitor = new Monitor(); 25 | monitor.AddToWatch("explorer"); 26 | monitor.AddToWatch("calc"); 27 | monitor.AddToWatch("chrome"); 28 | monitor.Start(); 29 | 30 | Console.ReadLine(); 31 | } 32 | else if (input == "2") 33 | { 34 | string address = string.Empty; ; 35 | foreach (IPAddress item in Dns.GetHostAddresses(Dns.GetHostName())) 36 | { 37 | //if (!item.IsIPv6LinkLocal) 38 | // if (!item.IsIPv6Multicast) 39 | // if (!item.IsIPv6SiteLocal) 40 | // if (!item.IsIPv6Teredo) 41 | // address = item.ToString(); 42 | if (!item.IsIPv6LinkLocal && !item.IsIPv6Multicast && !item.IsIPv6SiteLocal && !item.IsIPv6Teredo) 43 | address = item.ToString(); 44 | } 45 | 46 | Monitor monitor = new Monitor(); 47 | using (ServiceHost host = new ServiceHost(monitor, new Uri(string.Format("http://{0}:4325/", address)))) 48 | { 49 | host.Open(); 50 | monitor.Start(); 51 | Console.WriteLine("Opened..."); 52 | 53 | Console.ReadLine(); 54 | } 55 | } 56 | } 57 | 58 | } 59 | 60 | } 61 | -------------------------------------------------------------------------------- /ProcessMonitor.ConsoleApp/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("ProcessMonitor.ConsoleApp")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("ProcessMonitor.ConsoleApp")] 13 | [assembly: AssemblyCopyright("Copyright © 2012")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("ddad05b4-eb43-426c-bd4e-16790f2237be")] 24 | 25 | // Version information for an assembly consists of the following four values: 26 | // 27 | // Major Version 28 | // Minor Version 29 | // Build Number 30 | // Revision 31 | // 32 | // You can specify all the values or you can default the Build and Revision Numbers 33 | // by using the '*' as shown below: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.0.0.0")] 36 | [assembly: AssemblyFileVersion("1.0.0.0")] 37 | -------------------------------------------------------------------------------- /ProcessMonitor.Installer/Features.wxs: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /ProcessMonitor.Installer/Files.wxs: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | -------------------------------------------------------------------------------- /ProcessMonitor.Installer/License.rtf: -------------------------------------------------------------------------------- 1 | {\rtf1\ansi\ansicpg1251\deff0\nouicompat\deflang1058{\fonttbl{\f0\fnil\fcharset0 Calibri;}} 2 | {\colortbl ;\red0\green0\blue255;} 3 | {\*\generator Riched20 6.2.8400}\viewkind4\uc1 4 | \pard\sa200\sl276\slmult1\f0\fs22\lang9 Apache License, Version 2.0 Apache License Version 2.0, January 2004 http://www.apache.org/licenses/\par 5 | \b\fs24 TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION\par 6 | \b0\fs22 1. Definitions.\par 7 | "License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document.\par 8 | "Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License.\par 9 | "Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity.\par 10 | "You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License.\par 11 | "Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files.\par 12 | "Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types.\par 13 | "Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below).\par 14 | "Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof.\par 15 | "Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution."\par 16 | "Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work.\par 17 | 2. Grant of Copyright License.\par 18 | Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form.\par 19 | 3. Grant of Patent License.\par 20 | Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed.\par 21 | 4. Redistribution.\par 22 | You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions:\par 23 | You must give any other recipients of the Work or Derivative Works a copy of this License; and You must cause any modified files to carry prominent notices stating that You changed the files; and You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License. You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License.\par 24 | 5. Submission of Contributions.\par 25 | Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions.\par 26 | 6. Trademarks.\par 27 | This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file.\par 28 | 7. Disclaimer of Warranty.\par 29 | Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License.\par 30 | 8. Limitation of Liability.\par 31 | In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages.\par 32 | 9. Accepting Warranty or Additional Liability.\par 33 | While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability.\par 34 | END OF TERMS AND CONDITIONS\par 35 | APPENDIX: How to apply the Apache License to your work\par 36 | To apply the Apache License to your work, attach the following boilerplate notice, with the fields enclosed by brackets "[]" replaced with your own identifying information. (Don't include the brackets!) The text should be enclosed in the appropriate comment syntax for the file format. We also recommend that a file or class name and description of purpose be included on the same "printed page" as the copyright notice for easier identification within third-party archives.\par 37 | Copyright 2012 Dmitry Kischenko\par 38 | Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at\par 39 | {{\field{\*\fldinst{HYPERLINK http://www.apache.org/licenses/LICENSE-2.0 }}{\fldrslt{http://www.apache.org/licenses/LICENSE-2.0\ul0\cf0}}}}\f0\fs22\par 40 | Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.\par 41 | } 42 | -------------------------------------------------------------------------------- /ProcessMonitor.Installer/ProcessMonitor.Installer.wixproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | Debug 5 | x86 6 | 3.6 7 | 06183a70-0a9a-4b9a-9191-68c6b170fafa 8 | 2.0 9 | ProcessMonitor.Installer 10 | Package 11 | $(MSBuildExtensionsPath32)\Microsoft\WiX\v3.x\Wix.targets 12 | $(MSBuildExtensionsPath)\Microsoft\WiX\v3.x\Wix.targets 13 | 14 | 15 | bin\$(Configuration)\ 16 | obj\$(Configuration)\ 17 | Debug 18 | 19 | 20 | bin\$(Configuration)\ 21 | obj\$(Configuration)\ 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | ProcessMonitor.App 34 | {6736d23a-497b-4fe4-afda-f37bc1ef2d69} 35 | True 36 | True 37 | Binaries;Content;Satellites 38 | INSTALLFOLDER 39 | 40 | 41 | ProcessMonitor.Service 42 | {716f20cd-0b60-40ad-bfed-c2965ca9089a} 43 | True 44 | True 45 | Binaries;Content;Satellites 46 | INSTALLFOLDER 47 | 48 | 49 | ProcessMonitor 50 | {f760d1f5-aece-401b-b0d4-67338b1c4502} 51 | True 52 | True 53 | Binaries;Content;Satellites 54 | INSTALLFOLDER 55 | 56 | 57 | 58 | 59 | $(WixExtDir)\WixNetFxExtension.dll 60 | WixNetFxExtension 61 | 62 | 63 | $(WixExtDir)\WixUIExtension.dll 64 | WixUIExtension 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 80 | -------------------------------------------------------------------------------- /ProcessMonitor.Installer/Product.wxs: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | = 501)]]> 40 | 41 | 42 | 43 | 44 | 45 | -------------------------------------------------------------------------------- /ProcessMonitor.Installer/Shortcuts.wxs: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /ProcessMonitor.Installer/Variables.wxi: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /ProcessMonitor.Service/!install.bat: -------------------------------------------------------------------------------- 1 | C:\Windows\Microsoft.NET\Framework\v4.0.30319\installutil ProcessMonitor.Service.exe 2 | net start MonitorService 3 | pause -------------------------------------------------------------------------------- /ProcessMonitor.Service/!uninstall.bat: -------------------------------------------------------------------------------- 1 | net stop MonitorService 2 | C:\Windows\Microsoft.NET\Framework\v4.0.30319\installutil /u ProcessMonitor.Service.exe 3 | pause -------------------------------------------------------------------------------- /ProcessMonitor.Service/App.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | -------------------------------------------------------------------------------- /ProcessMonitor.Service/MonitorService.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.ComponentModel; 4 | using System.Configuration; 5 | using System.Data; 6 | using System.Diagnostics; 7 | using System.Linq; 8 | using System.Net; 9 | using System.ServiceModel; 10 | using System.ServiceProcess; 11 | using System.Text; 12 | using System.Threading.Tasks; 13 | using System.Timers; 14 | 15 | namespace ProcessMonitor.Service 16 | { 17 | 18 | internal class MonitorService : ServiceBase 19 | { 20 | 21 | private Monitor monitor; 22 | private ServiceHost serviceHost; 23 | 24 | private Timer saveTimer; 25 | 26 | public MonitorService() 27 | { 28 | var time = double.Parse(ConfigurationManager.AppSettings["saveTimer"]); 29 | 30 | string address = string.Empty; 31 | foreach (IPAddress item in Dns.GetHostAddresses(Dns.GetHostName())) 32 | { 33 | if (!item.IsIPv6LinkLocal && !item.IsIPv6Multicast && !item.IsIPv6SiteLocal && !item.IsIPv6Teredo) 34 | address = item.ToString(); 35 | } 36 | 37 | monitor = new Monitor(); 38 | serviceHost = new ServiceHost(monitor, new Uri(string.Format("http://{0}:4325/", address))); 39 | saveTimer = new Timer(time); 40 | saveTimer.Elapsed += (o, args) => 41 | { 42 | monitor.SaveWatchs(); 43 | monitor.SaveStatistics(); 44 | }; 45 | } 46 | 47 | protected override void Dispose(bool disposing) 48 | { 49 | if (disposing) 50 | { 51 | saveTimer.Dispose(); 52 | monitor.Dispose(); 53 | } 54 | base.Dispose(disposing); 55 | } 56 | 57 | protected override void OnStart(string[] args) 58 | { 59 | serviceHost.Open(); 60 | monitor.Start(); 61 | saveTimer.Start(); 62 | } 63 | 64 | protected override void OnContinue() 65 | { 66 | monitor.Start(); 67 | saveTimer.Start(); 68 | } 69 | 70 | protected override void OnPause() 71 | { 72 | saveTimer.Stop(); 73 | monitor.Stop(); 74 | } 75 | 76 | protected override void OnStop() 77 | { 78 | monitor.Stop(); 79 | saveTimer.Stop(); 80 | serviceHost.Close(); 81 | } 82 | 83 | protected override void OnShutdown() 84 | { 85 | monitor.Stop(); 86 | saveTimer.Stop(); 87 | serviceHost.Close(); 88 | } 89 | 90 | } 91 | 92 | } 93 | -------------------------------------------------------------------------------- /ProcessMonitor.Service/ProcessMonitor.Service.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | AnyCPU 7 | {716F20CD-0B60-40AD-BFED-C2965CA9089A} 8 | WinExe 9 | Properties 10 | ProcessMonitor.Service 11 | ProcessMonitor.Service 12 | v4.0 13 | 512 14 | publish\ 15 | true 16 | Disk 17 | false 18 | Foreground 19 | 7 20 | Days 21 | false 22 | false 23 | true 24 | 0 25 | 1.0.0.%2a 26 | false 27 | false 28 | true 29 | Client 30 | 31 | 32 | AnyCPU 33 | true 34 | full 35 | false 36 | bin\Debug\ 37 | DEBUG;TRACE 38 | prompt 39 | 4 40 | 41 | 42 | x86 43 | pdbonly 44 | true 45 | bin\Release\ 46 | TRACE 47 | prompt 48 | 4 49 | 50 | 51 | ProcessMonitor.Service.Program 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | Component 71 | 72 | 73 | 74 | Component 75 | 76 | 77 | 78 | 79 | 80 | PreserveNewest 81 | 82 | 83 | PreserveNewest 84 | 85 | 86 | 87 | 88 | 89 | {f760d1f5-aece-401b-b0d4-67338b1c4502} 90 | ProcessMonitor 91 | 92 | 93 | 94 | 95 | False 96 | Microsoft .NET Framework 4.5 %28x86 and x64%29 97 | true 98 | 99 | 100 | False 101 | .NET Framework 3.5 SP1 Client Profile 102 | false 103 | 104 | 105 | False 106 | .NET Framework 3.5 SP1 107 | false 108 | 109 | 110 | 111 | 118 | -------------------------------------------------------------------------------- /ProcessMonitor.Service/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.ServiceProcess; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | 8 | namespace ProcessMonitor.Service 9 | { 10 | 11 | static class Program 12 | { 13 | 14 | static void Main() 15 | { 16 | ServiceBase.Run(new MonitorService()); 17 | } 18 | 19 | } 20 | 21 | 22 | } 23 | -------------------------------------------------------------------------------- /ProcessMonitor.Service/ProjectInstaller.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections; 3 | using System.Collections.Generic; 4 | using System.ComponentModel; 5 | using System.Configuration.Install; 6 | using System.Linq; 7 | using System.ServiceProcess; 8 | using System.Threading.Tasks; 9 | 10 | namespace ProcessMonitor.Service 11 | { 12 | 13 | [RunInstaller(true)] 14 | public class ProjectInstaller : Installer 15 | { 16 | 17 | private ServiceProcessInstaller serviceProcessInstaller; 18 | private ServiceInstaller serviceInstaller; 19 | 20 | public ProjectInstaller() 21 | { 22 | serviceProcessInstaller = new ServiceProcessInstaller() 23 | { 24 | Account = ServiceAccount.LocalSystem 25 | }; 26 | serviceInstaller = new ServiceInstaller() 27 | { 28 | DisplayName = "Process Monitor", 29 | ServiceName = "MonitorService", 30 | StartType = ServiceStartMode.Automatic 31 | }; 32 | Installers.AddRange(new Installer[] { serviceProcessInstaller, serviceInstaller }); 33 | } 34 | 35 | } 36 | 37 | } 38 | -------------------------------------------------------------------------------- /ProcessMonitor.Service/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("Process Monitor Service")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("Process Monitor")] 13 | [assembly: AssemblyCopyright("Copyright © 2012")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("fce222f1-b460-4aca-b90c-87c2eb926b9a")] 24 | 25 | // Version information for an assembly consists of the following four values: 26 | // 27 | // Major Version 28 | // Minor Version 29 | // Build Number 30 | // Revision 31 | // 32 | // You can specify all the values or you can default the Build and Revision Numbers 33 | // by using the '*' as shown below: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.0.0.0")] 36 | [assembly: AssemblyFileVersion("1.0.0.0")] 37 | -------------------------------------------------------------------------------- /ProcessMonitor.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 2012 4 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ProcessMonitor", "ProcessMonitor\ProcessMonitor.csproj", "{F760D1F5-AECE-401B-B0D4-67338B1C4502}" 5 | EndProject 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ProcessMonitor.Service", "ProcessMonitor.Service\ProcessMonitor.Service.csproj", "{716F20CD-0B60-40AD-BFED-C2965CA9089A}" 7 | EndProject 8 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ProcessMonitor.App", "ProcessMonitor.App\ProcessMonitor.App.csproj", "{6736D23A-497B-4FE4-AFDA-F37BC1EF2D69}" 9 | EndProject 10 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ProcessMonitor.ConsoleApp", "ProcessMonitor.ConsoleApp\ProcessMonitor.ConsoleApp.csproj", "{5FFE7D09-E3C9-4A31-A762-D67649B7A728}" 11 | EndProject 12 | Project("{930C7802-8A8C-48F9-8165-68863BCCD9DD}") = "ProcessMonitor.Installer", "ProcessMonitor.Installer\ProcessMonitor.Installer.wixproj", "{06183A70-0A9A-4B9A-9191-68C6B170FAFA}" 13 | EndProject 14 | Global 15 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 16 | Debug|Any CPU = Debug|Any CPU 17 | Release|Any CPU = Release|Any CPU 18 | EndGlobalSection 19 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 20 | {F760D1F5-AECE-401B-B0D4-67338B1C4502}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 21 | {F760D1F5-AECE-401B-B0D4-67338B1C4502}.Debug|Any CPU.Build.0 = Debug|Any CPU 22 | {F760D1F5-AECE-401B-B0D4-67338B1C4502}.Release|Any CPU.ActiveCfg = Release|Any CPU 23 | {F760D1F5-AECE-401B-B0D4-67338B1C4502}.Release|Any CPU.Build.0 = Release|Any CPU 24 | {716F20CD-0B60-40AD-BFED-C2965CA9089A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 25 | {716F20CD-0B60-40AD-BFED-C2965CA9089A}.Debug|Any CPU.Build.0 = Debug|Any CPU 26 | {716F20CD-0B60-40AD-BFED-C2965CA9089A}.Release|Any CPU.ActiveCfg = Release|Any CPU 27 | {716F20CD-0B60-40AD-BFED-C2965CA9089A}.Release|Any CPU.Build.0 = Release|Any CPU 28 | {6736D23A-497B-4FE4-AFDA-F37BC1EF2D69}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 29 | {6736D23A-497B-4FE4-AFDA-F37BC1EF2D69}.Debug|Any CPU.Build.0 = Debug|Any CPU 30 | {6736D23A-497B-4FE4-AFDA-F37BC1EF2D69}.Release|Any CPU.ActiveCfg = Release|Any CPU 31 | {6736D23A-497B-4FE4-AFDA-F37BC1EF2D69}.Release|Any CPU.Build.0 = Release|Any CPU 32 | {5FFE7D09-E3C9-4A31-A762-D67649B7A728}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 33 | {5FFE7D09-E3C9-4A31-A762-D67649B7A728}.Debug|Any CPU.Build.0 = Debug|Any CPU 34 | {5FFE7D09-E3C9-4A31-A762-D67649B7A728}.Release|Any CPU.ActiveCfg = Release|Any CPU 35 | {5FFE7D09-E3C9-4A31-A762-D67649B7A728}.Release|Any CPU.Build.0 = Release|Any CPU 36 | {06183A70-0A9A-4B9A-9191-68C6B170FAFA}.Debug|Any CPU.ActiveCfg = Debug|x86 37 | {06183A70-0A9A-4B9A-9191-68C6B170FAFA}.Release|Any CPU.ActiveCfg = Release|x86 38 | EndGlobalSection 39 | GlobalSection(SolutionProperties) = preSolution 40 | HideSolutionNode = FALSE 41 | EndGlobalSection 42 | EndGlobal 43 | -------------------------------------------------------------------------------- /ProcessMonitor/App.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | -------------------------------------------------------------------------------- /ProcessMonitor/IMonitor.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.IO; 4 | using System.ServiceModel; 5 | 6 | namespace ProcessMonitor 7 | { 8 | 9 | [ServiceContract] 10 | public interface IMonitor 11 | { 12 | 13 | [OperationContract] 14 | void Start(); 15 | 16 | [OperationContract] 17 | void Stop(); 18 | 19 | [OperationContract] 20 | void AddToWatch(string process); 21 | 22 | [OperationContract] 23 | void RemoveWatch(string process); 24 | 25 | [OperationContract] 26 | void ClearWatchs(); 27 | 28 | [OperationContract] 29 | void Reset(); 30 | 31 | [OperationContract] 32 | uint GetTotalWorkTime(); 33 | 34 | [OperationContract] 35 | WatchProcess[] GetWatchList(); 36 | 37 | [OperationContract] 38 | void LoadWatchs(); 39 | 40 | [OperationContract] 41 | void SaveWatchs(); 42 | 43 | [OperationContract] 44 | void SaveStatistics(); 45 | 46 | [OperationContract] 47 | uint GetInterval(); 48 | 49 | [OperationContract] 50 | void SetInterval(uint interval); 51 | 52 | [OperationContract] 53 | bool IsStarted(); 54 | 55 | [OperationContract] 56 | Stream GetStatistics(); 57 | 58 | [OperationContract] 59 | string[] GetAllProcesses(); 60 | 61 | } 62 | 63 | } 64 | -------------------------------------------------------------------------------- /ProcessMonitor/Monitor.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.ComponentModel; 4 | using System.Configuration; 5 | using System.Diagnostics; 6 | using System.IO; 7 | using System.Linq; 8 | using System.ServiceModel; 9 | using System.Text; 10 | using System.Threading.Tasks; 11 | using System.Timers; 12 | using System.Xml.Linq; 13 | 14 | namespace ProcessMonitor 15 | { 16 | 17 | [ServiceBehavior(InstanceContextMode = InstanceContextMode.Single, ConcurrencyMode = ConcurrencyMode.Multiple)] 18 | public class Monitor : IMonitor, IDisposable 19 | { 20 | 21 | private bool isDisposed; 22 | 23 | private Timer timer; 24 | private uint interval = 1000; 25 | private HashSet watchList; 26 | private uint totalWorkTime = 0; 27 | private DateTime startTime; 28 | 29 | public Monitor() 30 | { 31 | startTime = DateTime.Now; 32 | watchList = new HashSet(); 33 | LoadWatchs(); 34 | 35 | timer = new Timer(interval); 36 | timer.Elapsed += WatchLoop; 37 | } 38 | 39 | ~Monitor() 40 | { 41 | Dispose(false); 42 | } 43 | 44 | public void Dispose() 45 | { 46 | Dispose(true); 47 | GC.SuppressFinalize(this); 48 | } 49 | 50 | protected virtual void Dispose(bool disposing) 51 | { 52 | if (!isDisposed) 53 | { 54 | if (disposing) 55 | { 56 | timer.Dispose(); 57 | } 58 | 59 | isDisposed = true; 60 | } 61 | } 62 | 63 | private void WatchLoop(object o, ElapsedEventArgs args) 64 | { 65 | totalWorkTime += interval; 66 | 67 | var strings = watchList.Select(wp => wp.Process); 68 | var processes = Process.GetProcesses().Select(p => p.ProcessName).OrderBy(s => s).ToList(); 69 | for (int i = 0; i < processes.Count; i++) 70 | { 71 | for (int j = i + 1; j < processes.Count; j++) 72 | { 73 | if (processes[j] == processes[i]) 74 | { 75 | processes.RemoveAt(j); 76 | j--; 77 | } 78 | } 79 | } 80 | processes = processes.Where(p => strings.Contains(p)).ToList(); 81 | if (processes.Count() > 0) 82 | { 83 | foreach (var process in processes) 84 | { 85 | var watch = watchList.FirstOrDefault(p => p.Process == process); 86 | if (watch != null) 87 | { 88 | watch.Milliseconds += interval; 89 | } 90 | } 91 | } 92 | } 93 | 94 | public void Start() 95 | { 96 | if (!timer.Enabled) 97 | { 98 | startTime = DateTime.Now; 99 | timer.Start(); 100 | } 101 | } 102 | 103 | public void Stop() 104 | { 105 | if (timer.Enabled) 106 | timer.Stop(); 107 | 108 | SaveWatchs(); 109 | SaveStatistics(); 110 | } 111 | 112 | public void AddToWatch(string process) 113 | { 114 | lock (watchList) 115 | { 116 | watchList.Add(new WatchProcess(process)); 117 | } 118 | } 119 | 120 | public void RemoveWatch(string process) 121 | { 122 | lock (watchList) 123 | { 124 | watchList.Remove(new WatchProcess(process)); 125 | } 126 | } 127 | 128 | public void ClearWatchs() 129 | { 130 | lock (watchList) 131 | { 132 | watchList.Clear(); 133 | } 134 | } 135 | 136 | public void Reset() 137 | { 138 | foreach (var watch in watchList) 139 | { 140 | watch.Milliseconds = 0; 141 | } 142 | totalWorkTime = 0; 143 | } 144 | 145 | public WatchProcess[] GetWatchList() 146 | { 147 | return watchList.ToArray(); 148 | } 149 | 150 | public string[] GetAllProcesses() 151 | { 152 | var processes = Process.GetProcesses().Select(p => p.ProcessName).OrderBy(s => s).ToList(); 153 | for (int i = 0; i < processes.Count; i++) 154 | { 155 | for (int j = i + 1; j < processes.Count; j++) 156 | { 157 | if (processes[i] == processes[j]) 158 | { 159 | processes.RemoveAt(j); 160 | j--; 161 | } 162 | } 163 | } 164 | 165 | return processes.ToArray(); 166 | } 167 | 168 | public void LoadWatchs() 169 | { 170 | if (string.IsNullOrWhiteSpace(ConfigurationManager.AppSettings["watchsPath"])) 171 | throw new ArgumentException("path"); 172 | var path = Path.Combine(Path.GetTempPath(), ConfigurationManager.AppSettings["statisticsFolder"], ConfigurationManager.AppSettings["watchsPath"]); 173 | 174 | if (File.Exists(path)) 175 | { 176 | XDocument doc = XDocument.Load(path); 177 | foreach (var watch in doc.Root.Elements("process")) 178 | { 179 | watchList.Add(new WatchProcess(watch.Value)); 180 | } 181 | } 182 | } 183 | 184 | public void SaveWatchs() 185 | { 186 | if (watchList.Count > 0) 187 | { 188 | if (string.IsNullOrWhiteSpace(ConfigurationManager.AppSettings["watchsPath"])) 189 | throw new ArgumentException("path"); 190 | if (string.IsNullOrWhiteSpace(ConfigurationManager.AppSettings["statisticsFolder"])) 191 | throw new ArgumentException("folder"); 192 | 193 | var dir = Path.Combine(Path.GetTempPath(), ConfigurationManager.AppSettings["statisticsFolder"]); 194 | if (!Directory.Exists(dir)) 195 | Directory.CreateDirectory(dir); 196 | var path = Path.Combine(dir, ConfigurationManager.AppSettings["watchsPath"]); 197 | 198 | XDocument doc = new XDocument(new XDeclaration("1.0", "UTF-8", null)); 199 | XElement root = new XElement("watchs"); 200 | foreach (var watch in watchList.OrderBy(w => w.Process)) 201 | { 202 | root.Add(new XElement("process", watch.Process)); 203 | } 204 | doc.Add(root); 205 | doc.Save(path); 206 | } 207 | } 208 | 209 | public void SaveStatistics() 210 | { 211 | if (string.IsNullOrWhiteSpace(ConfigurationManager.AppSettings["statisticsPath"])) 212 | throw new ArgumentException("path"); 213 | if (string.IsNullOrWhiteSpace(ConfigurationManager.AppSettings["statisticsFolder"])) 214 | throw new ArgumentException("folder"); 215 | 216 | var dir = Path.Combine(Path.GetTempPath(), ConfigurationManager.AppSettings["statisticsFolder"]); 217 | if (!Directory.Exists(dir)) 218 | Directory.CreateDirectory(dir); 219 | var path = Path.Combine(dir, ConfigurationManager.AppSettings["statisticsPath"]); 220 | 221 | XDocument doc; 222 | if (File.Exists(path)) 223 | { 224 | doc = XDocument.Load(path); 225 | 226 | var currentEl = doc.Root.Elements("watchList").Where(el => el.Attribute("startTime").Value == startTime.ToString()).FirstOrDefault(); 227 | if (currentEl != null) 228 | { 229 | currentEl.Remove(); 230 | } 231 | } 232 | else 233 | { 234 | doc = new XDocument(new XDeclaration("1.0", "UTF-8", null), new XElement("lists")); 235 | } 236 | 237 | XElement elWatch = new XElement("watchList", new XAttribute("startTime", startTime.ToString()), new XAttribute("stopTime", DateTime.Now.ToString()), new XAttribute("totalTime", totalWorkTime)); 238 | if (totalWorkTime != 0) 239 | { 240 | lock (watchList) 241 | { 242 | foreach (var watch in watchList) 243 | { 244 | if (watch.Milliseconds != 0) 245 | { 246 | elWatch.Add(new XElement("watch", new XElement("process", watch.Process), new XElement("time", watch.Milliseconds))); 247 | } 248 | } 249 | } 250 | } 251 | doc.Root.Add(elWatch); 252 | 253 | doc.Save(path); 254 | } 255 | 256 | public Stream GetStatistics() 257 | { 258 | if (string.IsNullOrWhiteSpace(ConfigurationManager.AppSettings["statisticsPath"])) 259 | throw new ArgumentException("path"); 260 | var path = Path.Combine(Path.GetTempPath(), ConfigurationManager.AppSettings["statisticsFolder"], ConfigurationManager.AppSettings["statisticsPath"]); 261 | 262 | return new FileStream(path, FileMode.Open, FileAccess.Read); 263 | } 264 | 265 | public uint GetTotalWorkTime() 266 | { 267 | return totalWorkTime; 268 | } 269 | 270 | public uint GetInterval() 271 | { 272 | return interval; 273 | } 274 | 275 | public void SetInterval(uint interval) 276 | { 277 | this.interval = interval; 278 | } 279 | 280 | public bool IsStarted() 281 | { 282 | return timer.Enabled; 283 | } 284 | 285 | } 286 | 287 | } 288 | -------------------------------------------------------------------------------- /ProcessMonitor/ProcessMonitor.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | AnyCPU 7 | {F760D1F5-AECE-401B-B0D4-67338B1C4502} 8 | Library 9 | Properties 10 | ProcessMonitor 11 | ProcessMonitor 12 | v4.0 13 | 512 14 | Client 15 | 16 | 17 | true 18 | full 19 | false 20 | bin\Debug\ 21 | DEBUG;TRACE 22 | prompt 23 | 4 24 | 25 | 26 | pdbonly 27 | true 28 | bin\Release\ 29 | TRACE 30 | prompt 31 | 4 32 | x86 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 63 | -------------------------------------------------------------------------------- /ProcessMonitor/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("Process Monitor")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("Process Monitor")] 13 | [assembly: AssemblyCopyright("Copyright © eXit 2012")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("b81abee9-5511-4bb6-a98c-8a32032765cb")] 24 | 25 | // Version information for an assembly consists of the following four values: 26 | // 27 | // Major Version 28 | // Minor Version 29 | // Build Number 30 | // Revision 31 | // 32 | // You can specify all the values or you can default the Build and Revision Numbers 33 | // by using the '*' as shown below: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.0.0.0")] 36 | [assembly: AssemblyFileVersion("1.0.0.0")] 37 | -------------------------------------------------------------------------------- /ProcessMonitor/WatchProcess.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Runtime.Serialization; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | 8 | namespace ProcessMonitor 9 | { 10 | 11 | [DataContract] 12 | public class WatchProcess 13 | { 14 | 15 | private string process; 16 | private uint milliseconds; 17 | 18 | public WatchProcess() 19 | { 20 | 21 | } 22 | 23 | public WatchProcess(string process) 24 | { 25 | this.process = process; 26 | } 27 | 28 | public override bool Equals(object obj) 29 | { 30 | var p = obj as WatchProcess; 31 | if (p == null) 32 | return false; 33 | 34 | return this.process == p.Process; 35 | } 36 | 37 | public override int GetHashCode() 38 | { 39 | return process.GetHashCode(); 40 | } 41 | 42 | public override string ToString() 43 | { 44 | return string.Format("{0} ({1})", process, milliseconds); 45 | } 46 | 47 | [DataMember] 48 | public string Process 49 | { 50 | get 51 | { 52 | return process; 53 | } 54 | set 55 | { 56 | process = value; 57 | } 58 | } 59 | 60 | [DataMember] 61 | public uint Milliseconds 62 | { 63 | get 64 | { 65 | return milliseconds; 66 | } 67 | set 68 | { 69 | milliseconds = value; 70 | } 71 | } 72 | 73 | } 74 | 75 | } 76 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ProcessMonitor 2 | ===== 3 | ProcessMonitor is desktop app that allows you to watch processes. It has a service that can be installed on a remote computer and you can connect to this service via WCF and monitors running processes. Also it has installer that installs the service and the desktop app. All code is written on C#. 4 | 5 | ### Structure of projects 6 | 7 | 1. ProcessMonitor.App - a desktop app. 8 | 2. ProcessMonitor.ConsoleApp - a console app. 9 | 3. ProcessMonitor.Installer - a WiX installer. 10 | 4. ProcessMonitor.Service - a WCF service. 11 | 5. ProcessMonitor - a shared library with code. 12 | --------------------------------------------------------------------------------