Ejemplo n.º 1
0
        private void processDiffQueue()
        {
            if (!_requestedDiff.Any())
            {
                return;
            }

            DiffRequest diffRequest = _requestedDiff.Peek();

            try
            {
                SnapshotSerializer serializer = new SnapshotSerializer();
                Snapshot           snapshot;
                try
                {
                    snapshot = serializer.DeserializeFromDisk(diffRequest.GitPID);
                }
                catch (Exception ex)
                {
                    ExceptionHandlers.Handle("Cannot read serialized Snapshot object", ex);
                    MessageBox.Show(
                        "Make sure that diff tool was launched from Merge Request Helper which is still running",
                        "Cannot create a discussion",
                        MessageBoxButtons.OK, MessageBoxIcon.Error,
                        MessageBoxDefaultButton.Button1, MessageBoxOptions.ServiceNotification);
                    return;
                }

                if (_storageFactory == null || _storageFactory.ParentFolder != snapshot.TempFolder)
                {
                    Trace.TraceWarning("[MainForm] File Storage folder was changed after launching diff tool");
                    MessageBox.Show("It seems that file storage folder was changed after launching diff tool. " +
                                    "Please restart diff tool.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning,
                                    MessageBoxDefaultButton.Button1, MessageBoxOptions.ServiceNotification);
                    return;
                }

                Core.Matching.MatchInfo matchInfo;
                try
                {
                    DiffArgumentParser diffArgumentParser = new DiffArgumentParser(diffRequest.DiffArguments);
                    matchInfo = diffArgumentParser.Parse(getDiffTempFolder(snapshot));
                    Debug.Assert(matchInfo != null);
                }
                catch (ArgumentException ex)
                {
                    ExceptionHandlers.Handle("Cannot parse diff tool arguments", ex);
                    MessageBox.Show("Bad arguments passed from diff tool", "Cannot create a discussion",
                                    MessageBoxButtons.OK, MessageBoxIcon.Error,
                                    MessageBoxDefaultButton.Button1, MessageBoxOptions.ServiceNotification);
                    return;
                }

                ProjectKey          projectKey = new ProjectKey(snapshot.Host, snapshot.Project);
                ILocalCommitStorage storage    = getCommitStorage(projectKey, false);
                if (storage.Git == null)
                {
                    Trace.TraceError("[MainForm] storage.Git is null");
                    Debug.Assert(false);
                    return;
                }

                DataCache dataCache = getDataCacheByName(snapshot.DataCacheName);
                if (dataCache == null || getCurrentUser() == null)
                {
                    // It is unexpected to get here when we are not connected to a host
                    Debug.Assert(false);
                    return;
                }

                DiffCallHandler handler = new DiffCallHandler(storage.Git, _modificationNotifier, getCurrentUser(),
                                                              (mrk) =>
                {
                    dataCache.DiscussionCache?.RequestUpdate(mrk,
                                                             Constants.DiscussionCheckOnNewThreadFromDiffToolInterval, null);
                });
                handler.Handle(matchInfo, snapshot);
            }
            finally
            {
                if (_requestedDiff.Any())
                {
                    _requestedDiff.Dequeue();
                    BeginInvoke(new Action(() => processDiffQueue()));
                }
            }
        }
Ejemplo n.º 2
0
        private static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            var arguments = Environment.GetCommandLineArgs();

            if (arguments.Length < 2)
            {
                using (Mutex mutex = new Mutex(false, "Global\\" + mutex1_guid))
                {
                    if (!mutex.WaitOne(0, false))
                    {
                        return;
                    }

                    Application.ThreadException += (sender, e) => HandleUnhandledException(e.Exception);
                    setupTraceListener("mrHelper.main.log");

                    try
                    {
                        Application.Run(new MainForm());
                    }
                    catch (Exception ex) // whatever unhandled exception
                    {
                        HandleUnhandledException(ex);
                    }
                }
            }
            else if (arguments[1] == "diff")
            {
                using (Mutex mutex = new Mutex(false, "Global\\" + mutex2_guid))
                {
                    if (!mutex.WaitOne(0, false))
                    {
                        return;
                    }

                    Application.ThreadException += (sender, e) => HandleUnhandledException(e.Exception);
                    setupTraceListener("mrHelper.diff.log");

                    DiffArgumentParser diffArgumentParser = new DiffArgumentParser(arguments);
                    DiffToolInfo       diffToolInfo;
                    try
                    {
                        diffToolInfo = diffArgumentParser.Parse();
                    }
                    catch (ArgumentException ex)
                    {
                        ExceptionHandlers.Handle(ex, "Cannot parse diff tool arguments");
                        MessageBox.Show("Bad arguments, see details in logs", "Error",
                                        MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return;
                    }

                    int gitPID = mrHelper.Core.Interprocess.Helpers.GetGitParentProcessId(Process.GetCurrentProcess().Id);

                    SnapshotSerializer serializer = new SnapshotSerializer();
                    Snapshot           snapshot;
                    try
                    {
                        snapshot = serializer.DeserializeFromDisk(gitPID);
                    }
                    catch (System.IO.IOException ex)
                    {
                        ExceptionHandlers.Handle(ex, "Cannot de-serialize snapshot");
                        MessageBox.Show("Cannot create a discussion. "
                                        + "Make sure that you use diff tool instance launched from mrHelper and mrHelper is still running.");
                        return;
                    }

                    IInterprocessCallHandler diffCallHandler = new DiffCallHandler(diffToolInfo);
                    try
                    {
                        diffCallHandler.Handle(snapshot);
                    }
                    catch (Exception ex) // whatever unhandled exception
                    {
                        HandleUnhandledException(ex);
                    }
                }
            }
        }