public void Execute(TeamFoundationWorkspace ws)
        {
            if (ws == null)
            {
                AppOutput.ConsoleWriteLine("---- Invalide ws config");
            }

            var files = GetLocalFiles();

            AppOutput.ConsoleWriteLine("Tfs inclider: filesFound: " + files.Count());

            var paddingChanges = ws.GetPendingChanges().Select(p => p.LocalItem);

            foreach (var file in files)
            {
                var serverPath       = ws.TryGetServerItemForLocalItem(file);
                var serverItemExists = ws.VersionControlServer.ServerItemExists(serverPath, ItemType.File);
                if (!serverItemExists && !paddingChanges.Contains(file))
                {
                    ws.PendAdd(file);
                    AppOutput.ConsoleWriteLine("    Exluded file: " + file);
                }
            }

            AppOutput.ConsoleWriteLine("Finished");
        }
Exemple #2
0
        public bool AddToTFVC(string[] _files, WorkItem _wi, Workspace _ws)
        {
            try
             {
                 _ws.Get();
                 // Now add everything.
                 _ws.PendAdd(_files, false);
                 WorkItemCheckinInfo[] _wici = new WorkItemCheckinInfo[1];

                 _wici[0] = new WorkItemCheckinInfo(_wi, WorkItemCheckinAction.Associate);

                 if (_ws.CheckIn(_ws.GetPendingChanges(), null, null, _wici, null) > 0)
                 {
                     _ws.Delete();
                     return true;

                 }
                 else
                 {
                     return false;
                 }

             }
             catch
             {
                 return false;
             }
        }
        private MenuItem CreateAddFileMenuItem(ExtendedItem item)
        {
            MenuItem addItem = new MenuItem(GettextCatalog.GetString("Add new item"));

            addItem.Activated += (sender, e) =>
            {
                var path = item.LocalItem;
                if (string.IsNullOrEmpty(path))
                {
                    path = _currentWorkspace.GetLocalPathForServerPath(item.ServerPath);
                }

                using (Xwt.OpenFileDialog openFileDialog = new Xwt.OpenFileDialog("Browse For File"))
                {
                    openFileDialog.CurrentFolder = path;
                    openFileDialog.Multiselect   = true;
                    if (openFileDialog.Run())
                    {
                        List <FilePath> files = new List <FilePath>();
                        foreach (var fileName in openFileDialog.FileNames)
                        {
                            //Check if file is in other folder
                            if (!string.Equals(Path.GetDirectoryName(fileName), path))
                            {
                                var newPath = Path.Combine(path, Path.GetFileName(fileName));
                                File.Copy(fileName, newPath);
                                files.Add(newPath);
                            }
                            else
                            {
                                files.Add(fileName);
                            }
                        }
                        _currentWorkspace.PendAdd(files, false);
                        CheckInDialog.Open(new List <ExtendedItem> {
                            item
                        }, _currentWorkspace);
                    }
                }
            };
            return(addItem);
        }
Exemple #4
0
        /// <summary>
        /// 'Pends' the add of a new folder and file and then checks it into the 
        /// repository.
        /// </summary>
        /// <param name="workspace">Version control workspace to use when 
        /// adding the folder and file.</param>
        /// <param name="newFilename">Full path to the file to add (the path
        /// of the folder will be derived from the file's path.</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 AddNewFile(Workspace workspace, String newFilename)
        {
            Debug.Assert(workspace != null);
            Debug.Assert(!String.IsNullOrEmpty(newFilename));
            Debug.Assert(!File.Exists(newFilename));

            if (!workspace.HasCheckInPermission)
            {
                throw new SecurityException(
                    String.Format("{0} does not have check-in permission for workspace: {1}",
                        workspace.VersionControlServer.AuthenticatedUser,
                        workspace.DisplayName));
            }

            try
            {
                // create the new file
                using (var streamWriter = new StreamWriter(newFilename))
                {
                    streamWriter.WriteLine("Revision 1");
                }

                // Now pend the add of our new folder and file
                workspace.PendAdd(Path.GetDirectoryName(newFilename), true);

                // Show our pending changes
                var pendingAdds = new List<PendingChange>((IEnumerable<PendingChange>)
                    workspace.GetPendingChanges());

                pendingAdds.ForEach(delegate(PendingChange add)
                {
                    Console.WriteLine("\t{1}: {0}",
                        add.LocalItem, PendingChange.GetLocalizedStringForChangeType(add.ChangeType));
                });

                // Checkin the items we added
                int changesetForAdd = workspace.CheckIn(pendingAdds.ToArray(), "Initial check-in");
                Console.WriteLine("Checked in changeset {0}", changesetForAdd);
            }
            catch (IOException ex)
            {
                Console.Error.WriteLine("Error writing {1}: {0}", ex.Message, newFilename);
                throw;
            }
            catch (VersionControlException ex)
            {
                Console.Error.WriteLine("Error adding file: {0}", ex.Message);
                throw;
            }
        }
Exemple #5
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);
    }
Exemple #6
-1
        private static bool AddMissingFile(XDocument xml, FileInfo file, string rootPath, string relativePath, string linkPath, Workspace workspace)
        {
            var compileName = XName.Get("Compile", ProjectNs);
            var newFilePath = Path.Combine(relativePath, file.NewName);

            var itemGroup = xml.Descendants(compileName).FirstOrDefault().Parent;

            if (itemGroup.Descendants(compileName).Any(x => x.Attributes().Any(a => a.Value.Contains(newFilePath))))
            {
                return false;
            }

            if (!string.IsNullOrEmpty(file.OldName))
            {
                var oldFilePath = Path.Combine(relativePath, file.OldName);
                var oldCompileInfo = itemGroup.Descendants(compileName).FirstOrDefault(x => x.Attributes().Any(a => a.Value.Contains(oldFilePath)));

                if (oldCompileInfo != null)
                {
                    oldCompileInfo.Remove();
                    if (workspace != null)
                    {
                        workspace.PendDelete(Path.Combine(rootPath, oldFilePath));
                    }
                    else
                    {
                        var oldFileInfo = new System.IO.FileInfo(Path.Combine(rootPath, oldFilePath));
                        oldFileInfo.Delete();
                    }
                }
            }

            var compileInfo = new XElement(compileName);
            compileInfo.Add(new XAttribute(XName.Get("Include"), newFilePath));
            if (linkPath != null)
            {
                var fileLinkPath = Path.Combine(linkPath, file.NewName);
                compileInfo.Add(new XElement(XName.Get("Link", ProjectNs), fileLinkPath));
            }
            itemGroup.Add(compileInfo);
            if (workspace != null && linkPath == null)
            {
                workspace.PendAdd(Path.Combine(rootPath, newFilePath));
            }
            return true;
        }
Exemple #7
-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);
    }