PageRenderTime 42ms CodeModel.GetById 16ms RepoModel.GetById 1ms app.codeStats 0ms

/src/MarkPad/App.xaml.cs

https://github.com/bcott/DownmarkerWPF
C# | 60 lines | 47 code | 11 blank | 2 comment | 7 complexity | c4fa6817ee02332312b2fcdfe1ab5291 MD5 | raw file
Possible License(s): CC-BY-SA-3.0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using System.Linq;
  5. using System.Reflection;
  6. using MarkPad.Events;
  7. using MarkPad.Infrastructure;
  8. using MarkPad.Preview;
  9. namespace MarkPad
  10. {
  11. public partial class App : ISingleInstanceApp
  12. {
  13. private const string Unique = "There can be only one MARKPAD!!! (We ignore crappy sequels here)";
  14. private readonly AppBootstrapper bootstrapper;
  15. public App()
  16. {
  17. InitializeComponent();
  18. HtmlPreview.Init();
  19. bootstrapper = new AppBootstrapper();
  20. }
  21. public void HandleArguments(string[] args)
  22. {
  23. if (args.Length == 2)
  24. {
  25. var filePath = args[1];
  26. bootstrapper.GetEventAggregator().Publish(new FileOpenEvent(filePath));
  27. }
  28. }
  29. [STAThread]
  30. public static void Main()
  31. {
  32. var directoryName = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location);
  33. if (directoryName != null && Directory.GetCurrentDirectory() != directoryName)
  34. Directory.SetCurrentDirectory(directoryName);
  35. if (SingleInstance<App>.InitializeAsFirstInstance(Unique))
  36. {
  37. new App().Run();
  38. // Allow single instance code to perform cleanup operations
  39. SingleInstance<App>.Cleanup();
  40. }
  41. }
  42. public bool SignalExternalCommandLineArgs(IList<string> args)
  43. {
  44. // handle command line arguments of second instance
  45. HandleArguments(args.ToArray());
  46. return true;
  47. }
  48. }
  49. }