Ejemplo n.º 1
1
        public static bool TryCheckout(Workspace workspace, string path)
        {
            if (workspace == null)
            {
                return false;
            }

            try
            {
                // Mark the file as a pending edit
                workspace.PendEdit(path);
            }
            catch
            {
                return false;
            }

            return true;
        }
 internal static void Open(List <ExtendedItem> items, Microsoft.TeamFoundation.VersionControl.Client.Workspace workspace)
 {
     using (var dialog = new CheckOutDialog())
     {
         dialog.FillStore(items);
         if (dialog.Run(Xwt.Toolkit.CurrentEngine.WrapWindow(MessageService.RootWindow)) == Command.Ok)
         {
             var itemsToCheckOut = dialog.SelectedItems;
             using (var progress = VersionControlService.GetProgressMonitor("Check Out", VersionControlOperationType.Pull))
             {
                 progress.BeginTask("Check Out", itemsToCheckOut.Count);
                 foreach (var item in itemsToCheckOut)
                 {
                     var path = item.IsInWorkspace ? item.LocalItem : workspace.GetLocalPathForServerPath(item.ServerPath);
                     workspace.Get(new GetRequest(item.ServerPath, RecursionType.Full, VersionSpec.Latest), GetOptions.None, progress);
                     progress.Log.WriteLine("Check out item: " + item.ServerPath);
                     var failures = workspace.PendEdit(new List <FilePath> {
                         path
                     }, RecursionType.Full, dialog.LockLevel);
                     if (failures != null && failures.Any())
                     {
                         if (failures.Any(f => f.SeverityType == SeverityType.Error))
                         {
                             foreach (var failure in failures.Where(f => f.SeverityType == SeverityType.Error))
                             {
                                 progress.ReportError(failure.Code, new Exception(failure.Message));
                             }
                             break;
                         }
                         foreach (var failure in failures.Where(f => f.SeverityType == SeverityType.Warning))
                         {
                             progress.ReportWarning(failure.Message);
                         }
                     }
                 }
                 progress.EndTask();
                 progress.ReportSuccess("Finish Check Out.");
             }
         }
     }
 }
Ejemplo n.º 3
0
        /// <summary>
        /// 'Pends' a change to a file that was previously checked-in and then checks
        /// that change into the repository.
        /// </summary>
        /// <param name="workspace">Version control workspace to use when 
        /// changing the folder and file.</param>
        /// <param name="newFilename">Full path to the file to change</param>
        /// <exception cref="SecurityException">If the user doesn't have
        /// check-in permission for the specified <paramref name="workspace"/>.</exception>
        /// <exception cref="IOException">If there's a problem creating the file.</exception>
        /// <exception cref="VersionControlException">If </exception>
        private static void ModifyFile(Workspace workspace, String newFilename)
        {
            Debug.Assert(workspace != null);
            Debug.Assert(!String.IsNullOrEmpty(newFilename));

            try
            {
                // Checkout and modify the file
                workspace.PendEdit(newFilename);

                using (var streamWriter = new StreamWriter(newFilename))
                {
                    streamWriter.WriteLine("Revision 2");
                }

                // Get the pending change and check in the new revision.
                var pendingChanges = workspace.GetPendingChanges();
                int changesetForChange = workspace.CheckIn(pendingChanges, "Modified file contents");
                Console.WriteLine("Checked in changeset {0}", changesetForChange);
            }
            catch (IOException ex)
            {
                Console.Error.WriteLine("Error writing {1}: {0}", ex.Message, newFilename);
                throw;
            }
            catch (VersionControlException ex)
            {
                Console.Error.WriteLine("Error modifying file: {0}", ex.Message);
                throw;
            }
        }
Ejemplo n.º 4
0
    public override void Run()
    {
        // must get server<->local mappings for GetServerItemForLocalItem
        workspace = GetWorkspaceFromCache();
        workspace.RefreshMappings();

        // by default, if nothing specified we process all changes
        if ((!OptionModified) && (!OptionDeleted) && (!OptionAdded))
            {
                OptionModified = OptionAdded = OptionDeleted = true;
            }

        Online(Arguments);
        if (OptionPreview) return;

        int changes = 0;
        changes += workspace.PendAdd(addedFiles.ToArray(), false);
        changes += workspace.PendEdit(editedFiles.ToArray(), RecursionType.None);
        changes += workspace.PendDelete(deletedFiles.ToArray(), RecursionType.None);
        Console.WriteLine("{0} pending changes.", changes);
    }
Ejemplo n.º 5
-1
    public override void Run()
    {
        workspace = GetWorkspaceFromCache();
        workspace.RefreshMappings();

        if (Arguments.Length < 1)
            {
                Console.WriteLine("No changeset specified.");
                Environment.Exit((int)ExitCode.Failure);
            }

        int cid = Convert.ToInt32(Arguments[0]);
        Changeset changeset = VersionControlServer.GetChangeset(cid, true, false);

        // fetch all items in one fell swoop
        List<int> ids = new List<int>();
        foreach (Change change in changeset.Changes)
            {
                if ((change.ChangeType & ChangeType.Add) == ChangeType.Add)
                    {
                        if (change.Item.ItemType != ItemType.Folder)
                            {
                                string localItem = workspace.GetLocalItemForServerItem(change.Item.ServerItem);
                                Console.WriteLine("Undo add: " + change.Item.ServerItem);
                                deletedFiles.Add(localItem);
                            }

                        continue;
                    }

                ids.Add(change.Item.ItemId);
            }

        ProcessEdits(changeset, ids.ToArray(), cid);

        if (OptionPreview) return;

        changeCount += workspace.PendAdd(addedFiles.ToArray(), false);
        changeCount += workspace.PendEdit(editedFiles.ToArray(), RecursionType.None);
        changeCount += workspace.PendDelete(deletedFiles.ToArray(), RecursionType.None);
        Console.WriteLine("{0} pending changes.", changeCount);
    }