Ejemplo n.º 1
0
        /// <summary>
        /// Performs adding documents to source control</summary>
        /// <param name="doing">True iff doing the command</param>
        /// <returns>True iff any documents added or can be added</returns>
        protected virtual bool DoAdd(bool doing)
        {
            if (SourceControlService == null || !SourceControlService.Enabled ||
                SourceControlContext == null)
            {
                return(false);
            }

            int addedCount = 0;

            foreach (IResource resource in SourceControlContext.Resources)
            {
                SourceControlStatus status = GetStatus(resource);
                if (status != SourceControlStatus.NotControlled &&
                    status != SourceControlStatus.FileDoesNotExist)
                {
                    return(false);
                }
                addedCount++;
                if (doing)
                {
                    SourceControlService.Add(resource.Uri);
                }
            }

            return(addedCount != 0);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Performs refresh of documents' status</summary>
        /// <param name="doing">True iff doing the command</param>
        /// <returns>True iff any documents refreshed or can be refreshed</returns>
        protected virtual bool DoRefresh(bool doing)
        {
            if (SourceControlService == null || !SourceControlService.Enabled ||
                SourceControlContext == null)
            {
                return(false);
            }

            if (!doing)
            {
                foreach (IResource resource in SourceControlContext.Resources)
                {
                    return(true);
                }

                return(false);
            }

            var uris = new List <Uri>();

            foreach (IResource resource in SourceControlContext.Resources)
            {
                GetSourceControlledUri(resource, uris);
            }
            SourceControlService.RefreshStatus(uris);

            return(uris.Count > 0); // something to refresh?
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Performs reconciliation of documents</summary>
        /// <param name="doing">True iff doing the command</param>
        /// <returns>True iff any documents reconciled or can be reconciled</returns>
        protected virtual bool DoReconcile(bool doing)
        {
            if (SourceControlService == null || SourceControlContext == null)
            {
                return(false);
            }

            if (!doing)
            {
                foreach (IResource resource in SourceControlContext.Resources)
                {
                    return(true);
                }

                return(false);
            }

            var uris = new List <Uri>();

            foreach (IResource resource in SourceControlContext.Resources)
            {
                uris.Add(resource.Uri);
            }

            var modifiled       = new List <Uri>();
            var localNotInDepot = new List <Uri>();

            using (new WaitCursor())
            {
                foreach (Uri uri in SourceControlService.GetModifiedFiles(uris))
                {
                    if (SourceControlService.GetStatus(uri) != SourceControlStatus.CheckedOut)
                    {
                        modifiled.Add(uri);
                    }
                }

                foreach (Uri uri in uris)
                {
                    if (!modifiled.Contains(uri))
                    {
                        if (SourceControlService.GetStatus(uri) == SourceControlStatus.FileDoesNotExist)
                        {
                            localNotInDepot.Add(uri);
                        }
                    }
                }
            }

            using (var form = new ReconcileForm(SourceControlService, modifiled, localNotInDepot))
            {
                if (m_mainForm != null)
                {
                    form.Icon = m_mainForm.Icon;
                }
                form.ShowDialog();
            }

            return(true);
        }
Ejemplo n.º 4
0
        private void documentService_DocumentSaved(object sender, DocumentEventArgs e)
        {
            if (SourceControlService == null)
            {
                return;
            }

            if (RefreshStatusOnSave)
            {
                SourceControlService.RefreshStatus(e.Document.Uri);
            }

            if (e.Kind != DocumentEventType.SavedAs)
            {
                return;
            }


            if (SourceControlService.GetStatus(e.Document.Uri) == SourceControlStatus.NotControlled)
            {
                string       message = string.Format("Add document {0} to version control?".Localize(), e.Document.Uri.AbsolutePath);
                DialogResult result  = MessageBox.Show(GetDialogOwner(), message, "Add document to Version Control".Localize(), MessageBoxButtons.YesNo);
                if (result == DialogResult.Yes)
                {
                    SourceControlService.Add(e.Document.Uri);
                }
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Performs synchronizing local files with files under source control</summary>
        /// <param name="doing">True iff doing the command</param>
        /// <returns>True iff any documents synchronized or can be synchronized</returns>
        protected virtual bool DoSync(bool doing)
        {
            if (SourceControlService == null || SourceControlContext == null)
            {
                return(false);
            }

            int count = 0;

            foreach (IResource resource in SourceControlContext.Resources)
            {
                ++count;
                if (GetStatus(resource) != SourceControlStatus.CheckedIn)
                {
                    return(false);
                }

                if (SourceControlService.IsSynched(resource.Uri))
                {
                    return(false);
                }

                if (doing)
                {
                    SourceControlService.GetLatestVersion(resource.Uri);
                    Reload(resource);
                }
            }
            return(count != 0);
        }
        /// <summary>
        /// Handle document dirty changed event</summary>
        /// <param name="sender">Document registry</param>
        /// <param name="e">Event arguments</param>
        protected virtual void OnDocumentDirtyChanged(object sender, EventArgs e)
        {
            IDocument document = sender as IDocument;

            if (SourceControlService == null || document == null || !document.Dirty || CheckoutOnEditBehavior == CheckoutOnEditBehavior.Never)
            {
                return;
            }

            if (SourceControlService.GetStatus(document.Uri) == SourceControlStatus.CheckedIn)
            {
                if (CheckoutOnEditBehavior == CheckoutOnEditBehavior.Always)
                {
                    TestCheckedIn(sender);
                    return;
                }

                string message = string.Format("Check out the file\r\n\r\n{0}\r\n\r\nto be able to save the changes?".Localize(),
                                               document.Uri.LocalPath);

                var result = MessageBoxes.Show(message, "Check Out File".Localize("this is the title of a dialog box that is asking a question"),
                                               MessageBoxButton.YesNo, MessageBoxImage.Question);
                if (result == MessageBoxResult.Yes)
                {
                    TestCheckedIn(sender);
                }
            }
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Performs checking out documents from source control</summary>
        /// <param name="doing">True iff doing the command</param>
        /// <returns>True iff any documents checked out or can be checked out</returns>
        protected virtual bool DoCheckOut(bool doing)
        {
            if (SourceControlService == null || !SourceControlService.Enabled ||
                SourceControlContext == null)
            {
                return(false);
            }

            int checkedOutCount = 0;

            foreach (IResource resource in SourceControlContext.Resources)
            {
                if (GetStatus(resource) != SourceControlStatus.CheckedIn)
                {
                    return(false);
                }

                if (SourceControlService.IsLocked(resource.Uri))
                {
                    return(false);
                }
                checkedOutCount++;
                if (doing)
                {
                    SourceControlService.CheckOut(resource.Uri);
                }
            }
            return(checkedOutCount != 0);
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Performs custom actions when a document's Dirty property changes</summary>
        /// <param name="sender">Sender</param>
        /// <param name="e">Event args</param>
        protected virtual void OnDocumentDirtyChanged(object sender, EventArgs e)
        {
            IDocument document = sender as IDocument;

            if (SourceControlService == null || document == null || !document.Dirty || CheckoutOnEditBehavior == CheckoutOnEditBehavior.Never)
            {
                return;
            }

            if (SourceControlService.GetStatus(document.Uri) == SourceControlStatus.CheckedIn)
            {
                if (CheckoutOnEditBehavior == CheckoutOnEditBehavior.Always)
                {
                    TestCheckedIn(sender);
                    return;
                }

                var message = new StringBuilder();
                message.AppendLine("Check out this file to be able to save the changes?".Localize());
                message.AppendLine(document.Uri.LocalPath);

                DialogResult result = MessageBox.Show(
                    GetDialogOwner(),
                    message.ToString(),
                    "Check Out File".Localize(), MessageBoxButtons.YesNo);

                if (result == DialogResult.Yes)
                {
                    TestCheckedIn(sender);
                }
            }
        }
Ejemplo n.º 9
0
        public CheckInViewModel(SourceControlService sourceControlService, IEnumerable<IResource> toCheckIn)
        {
            Title = "Check In Files".Localize();

            m_sourceControlService = sourceControlService;
            m_checkInItems = toCheckIn.Select(x => new CheckInItem(this, x)).ToList();

            Items = new ListCollectionView(m_checkInItems);
        }
Ejemplo n.º 10
0
        public ReconcileViewModel(SourceControlService sourceControlService, IEnumerable<Uri> modified, IEnumerable<Uri> notInDepot)
        {
            Title = "Reconcile Offline Work".Localize();

            m_sourceControlService = sourceControlService;
            m_modified = modified.Select(x => new CheckableItem(this, x)).ToList();
            m_notInDepot = notInDepot.Select(x => new CheckableItem(this, x)).ToList();

            Modified = new ListCollectionView(m_modified);
            NotInDepot = new ListCollectionView(m_notInDepot);
        }
        /// <summary>
        /// Get the source control status of an item</summary>
        /// <param name="resource">URI representing the path to item</param>
        /// <returns>Status of item</returns>
        protected virtual SourceControlStatus GetStatus(IResource resource)
        {
            Uri uri = resource.Uri;

            if (uri != null)
            {
                return(SourceControlService.GetStatus(new Uri(uri.LocalPath)));
            }

            return(SourceControlStatus.FileDoesNotExist);
        }
Ejemplo n.º 12
0
        /// <summary>
        /// Performs connecting to source control</summary>
        /// <param name="doing">True iff doing the command</param>
        /// <returns>True iff successfully connected to source control or can be connected</returns>
        protected virtual bool DoConnection(bool doing)
        {
            if (SourceControlService == null)
            {
                return(false);
            }

            return(doing
                ? SourceControlService.Connect()
                : SourceControlService.CanConfigure);
        }
Ejemplo n.º 13
0
        private void documentService_DocumentSaved(object sender, DocumentEventArgs e)
        {
            if (e.Kind != DocumentEventType.SavedAs || SourceControlService == null)
            {
                return;
            }

            if (SourceControlService.GetStatus(e.Document.Uri) == SourceControlStatus.NotControlled)
            {
                string message = "Add document ".Localize() + e.Document.Uri.AbsolutePath + " to version control?".Localize();
                var    result  = MessageBoxes.Show(message, " Add document to Version Control".Localize(), MessageBoxButton.YesNo, MessageBoxImage.Question);
                if (result == MessageBoxResult.Yes)
                {
                    SourceControlService.Add(e.Document.Uri);
                }
            }
        }
Ejemplo n.º 14
0
        /// <summary>
        /// Tests if the resource is checked-in and needs checking out</summary>
        private void TestCheckedIn(object obj)
        {
            if (SourceControlService == null)
            {
                return;
            }
            IResource resource = obj.As <IResource>();

            if (resource == null)
            {
                return;
            }

            if (SourceControlService.GetStatus(resource.Uri) == SourceControlStatus.CheckedIn)
            {
                SourceControlService.CheckOut(resource.Uri);
            }
        }
        private void documentService_DocumentSaved(object sender, DocumentEventArgs e)
        {
            if (e.Kind != DocumentEventType.SavedAs || SourceControlService == null)
            {
                return;
            }

            if (SourceControlService.GetStatus(e.Document.Uri) == SourceControlStatus.NotControlled)
            {
                string message = string.Format("Add document {0} to version control?".Localize(), e.Document.Uri.AbsolutePath);
                var    result  = MessageBoxes.Show(message, "Add Document to Version Control".Localize("this is the title of a dialog box that is asking a question"),
                                                   MessageBoxButton.YesNo, MessageBoxImage.Question);
                if (result == MessageBoxResult.Yes)
                {
                    SourceControlService.Add(e.Document.Uri);
                }
            }
        }
Ejemplo n.º 16
0
        /// <summary>
        /// Performs reverting local files to files under source control</summary>
        /// <param name="doing">True iff doing the command</param>
        /// <returns>True iff any documents reverted or can be reverted</returns>
        protected virtual bool DoRevert(bool doing)
        {
            if (SourceControlService == null || SourceControlContext == null)
            {
                return(false);
            }

            foreach (IResource resource in SourceControlContext.Resources)
            {
                SourceControlStatus status = GetStatus(resource);
                if (status != SourceControlStatus.CheckedOut && status != SourceControlStatus.Added)
                {
                    return(false);
                }
            }

            if (doing)
            {
                // user must confirm revert
                DialogResult dialogResult = MessageBox.Show(m_mainForm,
                                                            "All changes will be lost. Do you want to proceed?".Localize(),
                                                            "Proceed with Revert?".Localize(),
                                                            MessageBoxButtons.YesNo);
                if (dialogResult == DialogResult.Yes)
                {
                    foreach (IResource resource in SourceControlContext.Resources)
                    {
                        SourceControlStatus status = GetStatus(resource);
                        if (status == SourceControlStatus.CheckedOut || status == SourceControlStatus.Added)
                        {
                            SourceControlService.Revert(resource.Uri);
                            Reload(resource);
                        }
                    }
                }
            }

            return(true);
        }
        /// <summary>
        /// Perform the Revert command</summary>
        /// <param name="doing">True to perform the Revert; false to test whether Revert can be done</param>
        /// <returns>True iff Revert can be done or was done</returns>
        protected virtual bool DoRevert(bool doing)
        {
            if (SourceControlService == null || SourceControlContext == null)
            {
                return(false);
            }

            foreach (IResource resource in SourceControlContext.Resources)
            {
                SourceControlStatus status = GetStatus(resource);
                if (status != SourceControlStatus.CheckedOut && status != SourceControlStatus.Added && status != SourceControlStatus.Deleted)
                {
                    return(false);
                }
            }

            if (doing)
            {
                // user must confirm revert
                var dialogResult = MessageBoxes.Show("All Changes will be lost. Do you want to proceed?".Localize(),
                                                     "Proceed with Revert?".Localize(),
                                                     MessageBoxButton.YesNo, MessageBoxImage.Question);
                if (dialogResult == MessageBoxResult.Yes)
                {
                    foreach (IResource resource in SourceControlContext.Resources.ToArray())
                    {
                        SourceControlStatus status = GetStatus(resource);
                        if (status == SourceControlStatus.CheckedOut || status == SourceControlStatus.Added || status == SourceControlStatus.Deleted)
                        {
                            SourceControlService.Revert(resource.Uri);
                            Reload(resource);
                        }
                    }
                }
            }

            return(true);
        }