Ejemplo n.º 1
0
        private async void CheckInButton_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                xProcessingIcon.Visibility = Visibility.Visible;
                if (SourceControlIntegration.BusyInProcessWhileDownloading)
                {
                    Reporter.ToUser(eUserMsgKeys.StaticInfoMessage, "Please wait for current process to end.");
                    return;
                }
                SourceControlIntegration.BusyInProcessWhileDownloading = true;
                List <SourceControlFileInfo> SelectedFiles = mFiles.Where(x => x.Selected == true).ToList();
                if (SelectedFiles == null || SelectedFiles.Count == 0)
                {
                    Reporter.ToUser(eUserMsgKeys.SourceControlMissingSelectionToCheckIn);
                    return;
                }
                if (CommentsTextBox.Text.Length == 0)
                {
                    Reporter.ToUser(eUserMsgKeys.AskToAddCheckInComment);
                    return;
                }
                if (Reporter.ToUser(eUserMsgKeys.SourceControlChkInConfirmtion, SelectedFiles.Count) == MessageBoxResult.No)
                {
                    return;
                }
                string Comments = CommentsTextBox.Text.ToString();
                // performing on the another thread
                await Task.Run(() =>
                {
                    App.MainWindow.Dispatcher.Invoke(() =>
                    {
                        SaveAllDirtyFiles(SelectedFiles);
                    });
                    //performing cleanup for the solution folder to clean old locks left by faild check ins
                    SourceControlIntegration.CleanUp(App.UserProfile.Solution.SourceControl, App.UserProfile.Solution.Folder);
                    List <string> pathsToCommit = new List <string>();
                    foreach (SourceControlFileInfo fi in SelectedFiles)
                    {
                        switch (fi.Status)
                        {
                        case SourceControlFileInfo.eRepositoryItemStatus.New:
                            SourceControlIntegration.AddFile(App.UserProfile.Solution.SourceControl, fi.Path);
                            pathsToCommit.Add(fi.Path);
                            break;

                        case SourceControlFileInfo.eRepositoryItemStatus.Modified:
                            if (fi.Locked && fi.LockedOwner != App.UserProfile.Solution.SourceControl.SourceControlUser && Reporter.ToUser(eUserMsgKeys.SourceControlCheckInLockedByAnotherUser, fi.Path, fi.LockedOwner, fi.LockComment) == MessageBoxResult.Yes)
                            {
                                SourceControlIntegration.UpdateFile(App.UserProfile.Solution.SourceControl, fi.Path);
                                pathsToCommit.Add(fi.Path);
                            }
                            else if (fi.Locked && fi.LockedOwner == App.UserProfile.Solution.SourceControl.SourceControlUser && Reporter.ToUser(eUserMsgKeys.SourceControlCheckInLockedByMe, fi.Path, fi.LockedOwner, fi.LockComment) == MessageBoxResult.Yes)
                            {
                                SourceControlIntegration.UpdateFile(App.UserProfile.Solution.SourceControl, fi.Path);
                                pathsToCommit.Add(fi.Path);
                            }
                            else if (!fi.Locked)
                            {
                                SourceControlIntegration.UpdateFile(App.UserProfile.Solution.SourceControl, fi.Path);
                                pathsToCommit.Add(fi.Path);
                            }
                            break;

                        case SourceControlFileInfo.eRepositoryItemStatus.ModifiedAndResolved:
                            pathsToCommit.Add(fi.Path);
                            SourceControlIntegration.UpdateFile(App.UserProfile.Solution.SourceControl, fi.Path);
                            break;

                        case SourceControlFileInfo.eRepositoryItemStatus.Deleted:
                            SourceControlIntegration.DeleteFile(App.UserProfile.Solution.SourceControl, fi.Path);
                            pathsToCommit.Add(fi.Path);
                            break;

                        default:
                            throw new Exception("Unknown file status to check-in - " + fi.Name);
                        }
                    }

                    bool conflictHandled = false;
                    bool CommitSuccess   = false;

                    CommitSuccess = SourceControlIntegration.CommitChanges(App.UserProfile.Solution.SourceControl, pathsToCommit, Comments, App.UserProfile.Solution.ShowIndicationkForLockedItems, ref conflictHandled);

                    AfterCommitProcess(CommitSuccess, conflictHandled);


                    TriggerSourceControlIconChanged(SelectedFiles);
                });

                xProcessingIcon.Visibility = Visibility.Collapsed;
                if (SourceControlIntegration.conflictFlag)
                {
                    SourceControlIntegration.conflictFlag = false;
                }
            }
            finally
            {
                xProcessingIcon.Visibility = Visibility.Collapsed;
                SourceControlIntegration.BusyInProcessWhileDownloading = false;
            }
        }