Beispiel #1
0
        private static void launchFromContext(LaunchContext context)
        {
            LaunchOptions options = LaunchOptions.FromContext(context);

            switch (options.Mode)
            {
            case LaunchOptions.LaunchMode.DiffTool:
                onLaunchFromDiffTool(options);
                break;

            case LaunchOptions.LaunchMode.Register:
                if (registerCustomProtocol())
                {
                    integrateInGitExtensions();
                    integrateInSourceTree();
                }
                break;

            case LaunchOptions.LaunchMode.Unregister:
                unregisterCustomProtocol();
                break;

            case LaunchOptions.LaunchMode.Normal:
                if (context.IsRunningSingleInstance)
                {
                    onLaunchMainInstance(options);
                }
                else
                {
                    onLaunchAnotherInstance(context);
                }
                break;

            default:
                Debug.Assert(false);
                break;
            }
        }
Beispiel #2
0
        private static void Main()
        {
            using (LaunchContext context = new LaunchContext())
            {
                Application.ThreadException += (sender, e) => HandleUnhandledException(e.Exception);

                try
                {
                    string currentLogFileName    = getLogFileName(context);
                    CustomTraceListener listener = null;
                    try
                    {
                        listener = new CustomTraceListener(currentLogFileName,
                                                           String.Format("Merge Request Helper {0} started. PID {1}",
                                                                         Application.ProductVersion, Process.GetCurrentProcess().Id));
                        Trace.Listeners.Add(listener);
                    }
                    catch (ArgumentException)
                    {
                        // Cannot do anything good here
                        return;
                    }

                    Directory.SetCurrentDirectory(Path.GetDirectoryName(context.CurrentProcess.MainModule.FileName));
                    ServiceManager = new ServiceManager();

                    FeedbackReporter = new FeedbackReporter(
                        () =>
                    {
                        listener.Flush();
                        listener.Close();
                        Trace.Listeners.Remove(listener);
                    },
                        () =>
                    {
                        try
                        {
                            listener = new CustomTraceListener(currentLogFileName, null);
                            Trace.Listeners.Add(listener);
                        }
                        catch (Exception)
                        {
                            // Cannot do anything good here
                        }
                    },
                        getApplicationDataPath());

                    LaunchOptions options = LaunchOptions.FromContext(context);
                    switch (options.Mode)
                    {
                    case LaunchOptions.LaunchMode.DiffTool:
                        onLaunchFromDiffTool(options);
                        break;

                    case LaunchOptions.LaunchMode.Register:
                        if (registerCustomProtocol())
                        {
                            integrateInGitUI();
                        }
                        break;

                    case LaunchOptions.LaunchMode.Unregister:
                        unregisterCustomProtocol();
                        break;

                    case LaunchOptions.LaunchMode.Normal:
                        if (context.IsRunningSingleInstance)
                        {
                            onLaunchMainInstace(options);
                        }
                        else
                        {
                            onLaunchAnotherInstance(options, context);
                        }
                        break;

                    default:
                        Debug.Assert(false);
                        break;
                    }
                }
                catch (Exception ex) // whatever unhandled exception
                {
                    HandleUnhandledException(ex);
                }
            }
        }