コード例 #1
0
ファイル: App.xaml.cs プロジェクト: SciGit/scigit-client
        public App()
        {
            bool owned;
            mutex = new Mutex(true, "SciGitApplicationMutex", out owned);
            string[] args = Environment.GetCommandLineArgs();
            // Process context menu commands (of the form --{command} {file})
            // If there is no instance open, then process the arguments after everything has loaded.
            if (!owned) {
              if (args.Length == 3 && args[1] != "--hostname") {
            var pipeClient = new NamedPipeClientStream(".", "sciGitPipe", PipeDirection.Out);
            try {
              pipeClient.Connect(1000);
              var ss = new StreamString(pipeClient);
              ss.WriteString(args[1]);
              ss.WriteString(args[2]);
            } catch (Exception e) {
              Logger.LogException(e);
              MessageBox.Show("Please wait for the SciGit client to connect.", "Error");
            }
              } else {
            MessageBox.Show("An instance of SciGit is already open.", "Existing Instance");
              }
              Environment.Exit(0);
            }

            // Should the settings be upgraded?
            if (Settings.Default.NewInstall) {
              Settings.Default.Upgrade();
              Settings.Default.NewInstall = false;
              Settings.Default.Save();
            }

            // See if the user provided a custom hostname.
            for (int i = 1; i < args.Length; i++) {
              if (args[i] == "--hostname" && i+1 < args.Length) {
            Hostname = args[i + 1];
            return;
              }
            }

            AppDomain.CurrentDomain.UnhandledException += (sender, ex) =>
            Util.HandleException(ex.ExceptionObject as Exception);

            #if STAGE
            Hostname = Settings.Default.StageHostname;
            #else
            Hostname = Settings.Default.SciGitHostname;
            #endif
        }
コード例 #2
0
 public ShellCommandHandler(CommandHandler cmdHandler)
 {
     pipeServer = new NamedPipeServerStream("sciGitPipe", PipeDirection.In, 1, PipeTransmissionMode.Byte,
                                      PipeOptions.Asynchronous);
       pipeThread = new Thread(() => {
     while (true) {
       try {
     var ar = pipeServer.BeginWaitForConnection(null, null);
     pipeServer.EndWaitForConnection(ar);
     var ss = new StreamString(pipeServer);
     string verb = ss.ReadString();
     string filename = ss.ReadString();
     cmdHandler(verb, filename);
     pipeServer.Disconnect();
       } catch (ObjectDisposedException) {
     break;
       } catch (IOException) {
     break;
       } catch (Exception e) {
     Logger.LogException(e);
       }
     }
       });
 }