Exemple #1
0
        public void Workspace_RefreshMappings2()
        {
            // need TFS_ envvars for this test
            if (String.IsNullOrEmpty(tfsUrl))
            {
                return;
            }
            TeamFoundationServer tfs = new TeamFoundationServer(tfsUrl, credentials);
            VersionControlServer vcs = (VersionControlServer)tfs.GetService(typeof(VersionControlServer));

            WorkingFolder[] folders    = new WorkingFolder[1];
            string          serverItem = String.Format("$/{0}", Environment.GetEnvironmentVariable("TFS_PROJECT"));

            folders[0] = new WorkingFolder(serverItem, Environment.CurrentDirectory);

            Workspace w1 = vcs.CreateWorkspace("CreateDelete1_Workspace",
                                               Environment.GetEnvironmentVariable("TFS_USERNAME"),
                                               "My Comment", folders, Environment.MachineName);

            //Workstation.Current.UpdateWorkspaceInfoCache(vcs, Environment.GetEnvironmentVariable("TFS_USERNAME"));

            WorkspaceInfo info = Workstation.Current.GetLocalWorkspaceInfo(Environment.CurrentDirectory);
            Workspace     w2   = info.GetWorkspace(tfs);

            // this will talk to the server and get the mapped paths
            // BUT it will fail because we don't pass a full path like in RefreshMappings1
            w2.RefreshMappings();

            string serverItem2 = w2.TryGetServerItemForLocalItem("foo.txt");

            Assert.IsNull(serverItem2);
            w1.Delete();
        }
        public void ConstructorRelativeLocalPath()
        {
            WorkingFolder w1 = new WorkingFolder("$/serverItem", "localItem");

            Assert.AreEqual("$/serverItem", w1.ServerItem);
            Assert.AreEqual(Path.GetFullPath("localItem"), w1.LocalItem);
        }
Exemple #3
0
        public void Workspace_GetViaInfo()
        {
            // need TFS_ envvars for this test
            if (String.IsNullOrEmpty(tfsUrl))
            {
                return;
            }
            TeamFoundationServer tfs = new TeamFoundationServer(tfsUrl, credentials);
            VersionControlServer vcs = (VersionControlServer)tfs.GetService(typeof(VersionControlServer));

            WorkingFolder[] folders    = new WorkingFolder[1];
            string          serverItem = String.Format("$/{0}", Environment.GetEnvironmentVariable("TFS_PROJECT"));

            folders[0] = new WorkingFolder(serverItem, Environment.CurrentDirectory);

            Workspace w1 = vcs.CreateWorkspace("CreateDelete1_Workspace",
                                               Environment.GetEnvironmentVariable("TFS_USERNAME"),
                                               "My Comment", folders, Environment.MachineName);

            //Workstation.Current.UpdateWorkspaceInfoCache(vcs, Environment.GetEnvironmentVariable("TFS_USERNAME"));

            WorkspaceInfo info = Workstation.Current.GetLocalWorkspaceInfo(Environment.CurrentDirectory);
            Workspace     w2   = info.GetWorkspace(tfs);

            // does info.GetWorkspace talk to the server and get the
            // mapped paths or no? ANSWER: NO IT DOESN'T
            string serverItem2 = w2.TryGetServerItemForLocalItem("foo.txt");

            Assert.AreEqual(null, serverItem2);
            w1.Delete();
        }
Exemple #4
0
        public void Workspace_Get()
        {
            // need TFS_ envvars for this test
            if (String.IsNullOrEmpty(tfsUrl))
            {
                return;
            }
            TeamFoundationServer tfs = new TeamFoundationServer(tfsUrl, credentials);
            VersionControlServer vcs = (VersionControlServer)tfs.GetService(typeof(VersionControlServer));

            WorkingFolder[] folders    = new WorkingFolder[1];
            string          serverItem = String.Format("$/{0}", Environment.GetEnvironmentVariable("TFS_PROJECT"));

            folders[0] = new WorkingFolder(serverItem, Environment.CurrentDirectory);

            Workspace w1 = vcs.CreateWorkspace("CreateDelete1_Workspace",
                                               Environment.GetEnvironmentVariable("TFS_USERNAME"),
                                               "My Comment", folders, Environment.MachineName);

            Workspace w2 = vcs.GetWorkspace("CreateDelete1_Workspace");

            Assert.AreEqual("My Comment", w2.Comment);

            w1.Delete();
        }
        public TfsSourceControl(string sourceControlRootPath, string fileSystemPath)
        {
            m_fileSystemPath = fileSystemPath;
            m_sourceControlRootPath = sourceControlRootPath;
            m_workspace = new Lazy<Workspace>(() =>
                                              {
                                                  m_shouldUndo = true;
                                                  Workspace workspace = m_versionControlServer.TryGetWorkspace(m_fileSystemPath);

                                                  
                                                  if (workspace != null)
                                                  {
                                                      Guid lastGuid;
                                                      if (workspace.Name.StartsWith("VersionPatcher") && 
                                                          workspace.Name.Length > "VersionPatcher".Length && 
                                                          Guid.TryParse(workspace.Name.Substring("VersionPatcher".Length),out lastGuid))
                                                      {
                                                          m_removeMapping = true;
                                                      }
                                                  }
                                                  else 
                                                  {
                                                      workspace = m_versionControlServer.CreateWorkspace("VersionPatcher" + Guid.NewGuid());
                                                      var workingFolder = new WorkingFolder(m_sourceControlRootPath, m_fileSystemPath, WorkingFolderType.Map,RecursionType.Full);
                                                      m_removeMapping = true;
                                                      workspace.CreateMapping(workingFolder);
                                                      workspace.Get(LatestVersionSpec.Instance, GetOptions.Preview);
                                                  }

                                                  return workspace;
                                              });
        }
Exemple #6
0
        public void FixtureSetUp()
        {
            tfsUrl = Environment.GetEnvironmentVariable("TFS_URL");
            if (String.IsNullOrEmpty(tfsUrl))
                {
                    Console.WriteLine("Warning: Environment variable TFS_URL not set.");
                    Console.WriteLine("					Some tests cannot be executed without TFS_URL.");
                    return;
                }

            string username = Environment.GetEnvironmentVariable("TFS_USERNAME");
            if (String.IsNullOrEmpty(username))
                {
                    Console.WriteLine("Warning: No TFS user credentials specified.");
                    return;
                }

            credentials = new NetworkCredential(username,
                                                                                    Environment.GetEnvironmentVariable("TFS_PASSWORD"),
                                                                                    Environment.GetEnvironmentVariable("TFS_DOMAIN"));

            // need TFS_ envvars for this test
            if (String.IsNullOrEmpty(tfsUrl)) return;
            TeamFoundationServer tfs = new TeamFoundationServer(tfsUrl, credentials);
            versionControlServer = (VersionControlServer) tfs.GetService(typeof(VersionControlServer));

            WorkingFolder[] folders = new WorkingFolder[1];
            string serverItem = String.Format("$/{0}", Environment.GetEnvironmentVariable("TFS_PROJECT"));
            folders[0] = new WorkingFolder(serverItem, Environment.CurrentDirectory);

            workspace = versionControlServer.CreateWorkspace("UpdateWorkspaceInfoCache_Workspace",
                                                                                Environment.GetEnvironmentVariable("TFS_USERNAME"),
                                                                                "My Comment", folders, Environment.MachineName);
        }
        public void ConstructorRelativeLocalPath()
        {
            WorkingFolder w1 = new WorkingFolder("$/serverItem", "localItem");

            Assert.AreEqual("$/serverItem", w1.ServerItem);
            Assert.AreEqual(Path.GetFullPath("localItem"), w1.LocalItem);
        }
        public void ConstructorValidData()
        {
            string lpath = String.Format("{0}{0}local{0}item", Path.DirectorySeparatorChar);
            WorkingFolder w1 = new WorkingFolder("$/serverItem", lpath);

            Assert.AreEqual("$/serverItem", w1.ServerItem);
            Assert.AreEqual(lpath, w1.LocalItem);
        }
        public void ConstructorValidData()
        {
            string        lpath = String.Format("{0}{0}local{0}item", Path.DirectorySeparatorChar);
            WorkingFolder w1    = new WorkingFolder("$/serverItem", lpath);

            Assert.AreEqual("$/serverItem", w1.ServerItem);
            Assert.AreEqual(lpath, w1.LocalItem);
        }
 internal static WorkingFolder FromXml(XElement element)
 {
     string local = TfsPath.ToPlatformPath(element.Attribute("local").Value);
     string serverItem = element.Attribute("item").Value;
     var workFolder = new WorkingFolder(serverItem, local);
     if (element.Attribute("type") != null)
         workFolder.Type = (WorkingFolderType)Enum.Parse(typeof(WorkingFolderType), element.Attribute("type").Value);
     return workFolder;
 }
        public void DeleteMapping(string strServerPath, string strLocalPath)
        {
            WorkingFolder folder = new WorkingFolder(strServerPath, strLocalPath);

            if(this.Workspace.Folders.Contains(folder))
            {
                this.Workspace.DeleteMapping(folder);
            }
        }
        internal static WorkingFolder FromXml(XElement element)
        {
            string local      = TfsPath.ToPlatformPath(element.Attribute("local").Value);
            string serverItem = element.Attribute("item").Value;
            var    workFolder = new WorkingFolder(serverItem, local);

            if (element.Attribute("type") != null)
            {
                workFolder.Type = (WorkingFolderType)Enum.Parse(typeof(WorkingFolderType), element.Attribute("type").Value);
            }
            return(workFolder);
        }
Exemple #13
0
        internal Workspace(VersionControlServer versionControlServer, string name, 
											 string ownerName, string comment, 
											 WorkingFolder[] folders, string computer)
            : this()
        {
            this.versionControlServer = versionControlServer;
                this.name = name;
                this.ownerName = ownerName;
                this.comment = comment;
                this.folders = folders;
                this.computer = computer;
        }
        internal static Workspace FromXml(RepositoryService versionControl, XElement element)
        {
            string computer = element.Attribute("computer").Value;
            string name     = element.Attribute("name").Value;
            string owner    = element.Attribute("owner").Value;
            //bool isLocal = Convert.ToBoolean(element.Attribute("islocal").Value);

            string   comment        = element.Element(XmlNamespaces.GetMessageElementName("Comment")).Value;
            DateTime lastAccessDate = DateTime.Parse(element.Element(XmlNamespaces.GetMessageElementName("LastAccessDate")).Value);
            var      folders        = new List <WorkingFolder>(element.Element(XmlNamespaces.GetMessageElementName("Folders"))
                                                               .Elements(XmlNamespaces.GetMessageElementName("WorkingFolder"))
                                                               .Select(el => WorkingFolder.FromXml(el)));

            return(new Workspace(versionControl, name, owner, comment, folders, computer)
            {
                LastAccessDate = lastAccessDate
            });
        }
Exemple #15
0
        public void Workspace_TryGetWorkingFolderForServerItem()
        {
            // need TFS_ envvars for this test
            if (String.IsNullOrEmpty(tfsUrl))
            {
                return;
            }
            TeamFoundationServer tfs = new TeamFoundationServer(tfsUrl, credentials);
            VersionControlServer vcs = (VersionControlServer)tfs.GetService(typeof(VersionControlServer));

            WorkingFolder[] folders    = new WorkingFolder[2];
            string          serverItem = String.Format("$/{0}", Environment.GetEnvironmentVariable("TFS_PROJECT"));

            folders[0] = new WorkingFolder(serverItem, Environment.CurrentDirectory);

            string deeper = Path.Combine(Environment.CurrentDirectory, "deeper");

            folders[1] = new WorkingFolder(serverItem + "/deeper", deeper);

            Workspace w1 = vcs.CreateWorkspace("CreateDelete1_Workspace",
                                               Environment.GetEnvironmentVariable("TFS_USERNAME"),
                                               "My Comment", folders, Environment.MachineName);

            WorkspaceInfo info = Workstation.Current.GetLocalWorkspaceInfo(Environment.CurrentDirectory);
            Workspace     w2   = info.GetWorkspace(tfs);

            // this will talk to the server and get the mapped paths
            w2.RefreshMappings();

            {
                string        serverItem1 = String.Format("{0}/deeper/foo.txt", serverItem);
                WorkingFolder folder      = w2.TryGetWorkingFolderForServerItem(serverItem1);
                Assert.AreEqual(deeper, folder.LocalItem);
            }

            {
                string        serverItem1 = String.Format("junk/deeper/foo.txt", serverItem);
                WorkingFolder folder      = w2.TryGetWorkingFolderForServerItem(serverItem1);
                Assert.IsNull(deeper);
            }

            w1.Delete();
        }
Exemple #16
0
        internal static Workspace FromXml(Repository repository, XmlReader reader)
        {
            string elementName = reader.Name;

            string computer = reader.GetAttribute("computer");
            string name     = reader.GetAttribute("name");
            string owner    = reader.GetAttribute("owner");

            string               comment        = "";
            DateTime             lastAccessDate = DateTime.Now;
            List <WorkingFolder> folders        = new List <WorkingFolder>();

            while (reader.Read())
            {
                if (reader.NodeType == XmlNodeType.EndElement && reader.Name == elementName)
                {
                    break;
                }

                if (reader.NodeType == XmlNodeType.Element)
                {
                    switch (reader.Name)
                    {
                    case "WorkingFolder":
                        folders.Add(WorkingFolder.FromXml(repository, reader));
                        break;

                    case "Comment":
                        comment = reader.ReadString();
                        break;

                    case "LastAccessDate":
                        lastAccessDate = reader.ReadElementContentAsDateTime();
                        break;
                    }
                }
            }

            Workspace w = new Workspace(repository.VersionControlServer, name, owner, comment, folders.ToArray(), computer);

            w.lastAccessDate = lastAccessDate;
            return(w);
        }
        public WorkingFolder GetWorkingFolderForServerItem(string serverItem)
        {
            int           maxPath       = 0;
            WorkingFolder workingFolder = null;

            foreach (WorkingFolder folder in Folders)
            {
                if (!serverItem.StartsWith(folder.ServerItem, StringComparison.InvariantCultureIgnoreCase))
                {
                    continue;
                }

                if (folder.LocalItem.Length > maxPath)
                {
                    workingFolder = folder;
                    maxPath       = folder.LocalItem.Length;
                }
            }

            return(workingFolder);
        }
Exemple #18
0
        public void FixtureSetUp()
        {
            tfsUrl = Environment.GetEnvironmentVariable("TFS_URL");
            if (String.IsNullOrEmpty(tfsUrl))
            {
                Console.WriteLine("Warning: Environment variable TFS_URL not set.");
                Console.WriteLine("					Some tests cannot be executed without TFS_URL.");
                return;
            }

            string username = Environment.GetEnvironmentVariable("TFS_USERNAME");

            if (String.IsNullOrEmpty(username))
            {
                Console.WriteLine("Warning: No TFS user credentials specified.");
                return;
            }

            credentials = new NetworkCredential(username,
                                                Environment.GetEnvironmentVariable("TFS_PASSWORD"),
                                                Environment.GetEnvironmentVariable("TFS_DOMAIN"));

            // need TFS_ envvars for this test
            if (String.IsNullOrEmpty(tfsUrl))
            {
                return;
            }
            TeamFoundationServer tfs = new TeamFoundationServer(tfsUrl, credentials);

            versionControlServer = (VersionControlServer)tfs.GetService(typeof(VersionControlServer));

            WorkingFolder[] folders    = new WorkingFolder[1];
            string          serverItem = String.Format("$/{0}", Environment.GetEnvironmentVariable("TFS_PROJECT"));

            folders[0] = new WorkingFolder(serverItem, Environment.CurrentDirectory);

            workspace = versionControlServer.CreateWorkspace("UpdateWorkspaceInfoCache_Workspace",
                                                             Environment.GetEnvironmentVariable("TFS_USERNAME"),
                                                             "My Comment", folders, Environment.MachineName);
        }
        public string GetFile(string soruceTFSLocation, string destinationFileLocation)
        {
            // File and path
            var fileDirectory = Path.GetDirectoryName(destinationFileLocation);
            var fileName = Path.GetFileName(destinationFileLocation);

            if (fileName == null)
            {
                throw new ArgumentException("Filename must not be null");
            }

            var fullPathToFile = Path.Combine(fileDirectory, fileName);

            // Write to the log
            _buildMessageWriter.WriteBuildMessage(string.Format("Getting file from Source: {0}", soruceTFSLocation), BuildMessageImportance.High);

            // Create workspace and working folder
            var tempWorkspace = _workspace.VersionControlServer.CreateWorkspace("Temp_NugetWorkSpace");
            var workingFolder = new WorkingFolder(soruceTFSLocation, fullPathToFile);

            // Map the workspace
            tempWorkspace.CreateMapping(workingFolder);

            // Get the file
            var request = new GetRequest(new ItemSpec(soruceTFSLocation, RecursionType.None), VersionSpec.Latest);
            var status = tempWorkspace.Get(request, GetOptions.GetAll | GetOptions.Overwrite);

            if (!status.NoActionNeeded)
            {
                foreach (var failure in status.GetFailures())
                {
                    _buildMessageWriter.WriteBuildMessage(string.Format("Failed to get file from source: {0} - {1}", soruceTFSLocation, failure.GetFormattedMessage()), BuildMessageImportance.High);
                }
            }

            // Get rid of the workspace
            tempWorkspace.Delete();

            return fullPathToFile;
        }
Exemple #20
0
        public void Workspace_RefreshMappings2()
        {
            // need TFS_ envvars for this test
            if (String.IsNullOrEmpty(tfsUrl)) return;
            TeamFoundationServer tfs = new TeamFoundationServer(tfsUrl, credentials);
            VersionControlServer vcs = (VersionControlServer) tfs.GetService(typeof(VersionControlServer));

            WorkingFolder[] folders = new WorkingFolder[1];
            string serverItem = String.Format("$/{0}", Environment.GetEnvironmentVariable("TFS_PROJECT"));
            folders[0] = new WorkingFolder(serverItem, Environment.CurrentDirectory);

            Workspace w1 = vcs.CreateWorkspace("CreateDelete1_Workspace",
                                                                                 Environment.GetEnvironmentVariable("TFS_USERNAME"),
                                                                                 "My Comment", folders, Environment.MachineName);

            //Workstation.Current.UpdateWorkspaceInfoCache(vcs, Environment.GetEnvironmentVariable("TFS_USERNAME"));

            WorkspaceInfo info = Workstation.Current.GetLocalWorkspaceInfo(Environment.CurrentDirectory);
            Workspace w2 = info.GetWorkspace(tfs);

            // this will talk to the server and get the mapped paths
            // BUT it will fail because we don't pass a full path like in RefreshMappings1
            w2.RefreshMappings();

            string serverItem2 = w2.TryGetServerItemForLocalItem("foo.txt");
            Assert.IsNull(serverItem2);
            w1.Delete();
        }
Exemple #21
0
 public void Map(string teamProject, string sourceProject)
 {
     WorkingFolder[] folders = new WorkingFolder[1];
     folders[0] = new WorkingFolder(sourceProject, teamProject);
     Update(Name, OwnerName, folders);
 }
        public Workspace CreateWorkspace(string name, string owner, string comment,
																		 WorkingFolder[] folders, string computer)
        {
            Workspace w1 = new Workspace(this, name, owner, comment, folders, computer);
            Workspace w2 = repository.CreateWorkspace(w1);
            Workstation.Current.AddCachedWorkspaceInfo(ServerGuid, Uri, w2);
            return w2;
        }
Exemple #23
0
        protected override void Execute(CodeActivityContext context)
        {
            #region Workflow Arguments

            // The TFS source location of the file to get
            var fileToGet = context.GetValue(FileToGet);

            // The current workspace - used to create a new workspace for the get
            var workspace = context.GetValue(Workspace);

            // The local build directory
            var buildDirectory = context.GetValue(BuildDirectory);

            #endregion

            // Version seed file and path
            var versionFileDirectory = string.Format("{0}\\VersionSeed", buildDirectory);
            var filename = Path.GetFileName(fileToGet);
            var fullPathToSeedFile = Path.Combine(versionFileDirectory, filename);

            // Return the value back to the workflow
            context.SetValue(FullPathToSeedFile, fullPathToSeedFile);

            // Write to the log
            context.WriteBuildMessage(string.Format("Getting file from Source: {0}", fileToGet),
                                      BuildMessageImportance.High);
            context.WriteBuildMessage(string.Format("Placing version seed file in: {0}", versionFileDirectory),
                                      BuildMessageImportance.High);

            try
            {
                // Create workspace and working folder
                var tempWorkspace = workspace.VersionControlServer.CreateWorkspace("VersionSeed");
                var workingFolder = new WorkingFolder(fileToGet, fullPathToSeedFile);

                // Map the workspace
                tempWorkspace.CreateMapping(workingFolder);

                // Get the file
                var request = new GetRequest(new ItemSpec(fileToGet, RecursionType.None), VersionSpec.Latest);
                var status = tempWorkspace.Get(request, GetOptions.GetAll | GetOptions.Overwrite);

                if (!status.NoActionNeeded)
                {
                    foreach (var failure in status.GetFailures())
                    {
                        context.WriteBuildMessage(
                            string.Format("Failed to get file from source: {0} - {1}", fileToGet,
                                          failure.GetFormattedMessage()), BuildMessageImportance.High);
                    }
                }

                // Return the value back to the workflow
                context.SetValue(FullPathToSeedFile, fullPathToSeedFile);

                // Get rid of the workspace
                tempWorkspace.Delete();
            }
            catch (Exception)
            {
                context.WriteBuildMessage(string.Format("Seed file exists in '{0}'. Using existing file.", versionFileDirectory),
                    BuildMessageImportance.High);
            }
        }
Exemple #24
0
    public void ProcessWorkspaceNew(string args)
    {
        int semicolon = args.IndexOf(";");
        if (semicolon == -1)
            {
                Console.WriteLine("Failed to parse argument: " + args);
                return;
            }

        string name = args.Substring(0, semicolon);
        string ownerName = args.Substring(semicolon+1);

        Console.WriteLine("Creating workspace: " + name + " for " + ownerName);
        WorkingFolder[] folders = new WorkingFolder[1];
        folders[0] = new WorkingFolder(VersionControlPath.RootFolder, Environment.CurrentDirectory);
        Console.WriteLine("Mapping \"$/\" to " + Environment.CurrentDirectory);

        VersionControlServer.CreateWorkspace(name, ownerName, OptionComment,
                                                                                 folders, Environment.MachineName);

        return;
    }
Exemple #25
0
        /// <summary>
        /// Create a new workspace that has the mapping given 
        /// </summary>
        /// <param name="_sourceControlPath">
        /// Source code to pull from
        /// </param>
        /// <param name="_localPath">
        /// Local folder where source code will be pushed to
        /// </param>
        /// <returns>
        /// Workspace object with mapping
        /// </returns>
        public Workspace GetWorkSpace(string _sourceControlPath, string _localPath)
        {
            // Create a workspace.
            Workspace _ws = _vc.TryGetWorkspace(_localPath);
            if (_ws == null)
            {
                _ws = _vc.CreateWorkspace(DateTime.Now.ToString("yyyymmdd"), _vc.AuthenticatedUser);
            }
            WorkingFolder _myWorkingFolder = new WorkingFolder(_sourceControlPath, _localPath);
            // Create a mapping.
            _ws.CreateMapping(_myWorkingFolder);

            return _ws;
        }
Exemple #26
0
        public void Workspace_GetViaInfo()
        {
            // need TFS_ envvars for this test
            if (String.IsNullOrEmpty(tfsUrl)) return;
            TeamFoundationServer tfs = new TeamFoundationServer(tfsUrl, credentials);
            VersionControlServer vcs = (VersionControlServer) tfs.GetService(typeof(VersionControlServer));

            WorkingFolder[] folders = new WorkingFolder[1];
            string serverItem = String.Format("$/{0}", Environment.GetEnvironmentVariable("TFS_PROJECT"));
            folders[0] = new WorkingFolder(serverItem, Environment.CurrentDirectory);

            Workspace w1 = vcs.CreateWorkspace("CreateDelete1_Workspace",
                                                                                 Environment.GetEnvironmentVariable("TFS_USERNAME"),
                                                                                 "My Comment", folders, Environment.MachineName);

            //Workstation.Current.UpdateWorkspaceInfoCache(vcs, Environment.GetEnvironmentVariable("TFS_USERNAME"));

            WorkspaceInfo info = Workstation.Current.GetLocalWorkspaceInfo(Environment.CurrentDirectory);
            Workspace w2 = info.GetWorkspace(tfs);

            // does info.GetWorkspace talk to the server and get the
            // mapped paths or no? ANSWER: NO IT DOESN'T
            string serverItem2 = w2.TryGetServerItemForLocalItem("foo.txt");
            Assert.AreEqual(null, serverItem2);
            w1.Delete();
        }
Exemple #27
0
 public void Map(string teamProject, string sourceProject)
 {
     WorkingFolder[] folders = new WorkingFolder[1];
     folders[0] = new WorkingFolder(sourceProject, teamProject);
     Update(Name, OwnerName, folders);
 }
Exemple #28
0
        public List<string> GetWorkspaceWorkingFolderServerMappings(string _wsName, string _owner)
        {
            List<string> _serverItemList = new List<string>();
             Workspace _ws = this.GetWorkSpace(_wsName, _owner);
             foreach (WorkingFolder _wf in _ws.Folders)
             {

                 if (!_wf.IsCloaked)
                 {
                     foreach (string _mapping in _serverItemList)
                     {
                         WorkingFolder _mapwf = new WorkingFolder(_mapping, _ws.GetLocalItemForServerItem(_mapping));

                         if (!_wf.ServerItem.Contains(_mapping))
                         {
                             continue;
                         }
                         else
                         {
                             _serverItemList.Remove(_mapping);
                             break;
                         }

                     }

                     _serverItemList.Add(_wf.ServerItem);

                 }
                 else
                 {
                     foreach (string _mapping in _serverItemList)
                     {
                         if (_mapping.Equals(_wf.ServerItem))
                         {
                             _serverItemList.Remove(_mapping);
                             break;
                         }

                         WorkingFolder _mapwf = new WorkingFolder(_mapping, _ws.GetLocalItemForServerItem(_mapping));

                         if (!_wf.ServerItem.Contains(_mapwf.ServerItem))
                         {
                             continue;
                         }
                         else
                         {
                             _serverItemList.Remove(_mapping);
                             foreach (string _child in Directory.GetDirectories(_mapwf.LocalItem))
                             {
                                 _serverItemList.Add(_ws.GetServerItemForLocalItem(_child));
                             }
                             break;
                         }

                     }

                 }
             }

             return _serverItemList;
        }
Exemple #29
0
        public Workspace CreateWorkSpace(string _sourceControlPath, string _localPath)
        {
            TeamFoundationServer tfs = GetTfs();
             VersionControlServer _vc = (VersionControlServer)tfs.GetService(typeof(VersionControlServer));
             // Create a workspace.
             Workspace _ws = _vc.TryGetWorkspace(_localPath);
             if (_ws == null)
             {
                 _ws = _vc.CreateWorkspace(DateTime.Now.ToString("yyyymmdd"), _vc.AuthenticatedUser);
             }
             WorkingFolder _myWorkingFolder = new WorkingFolder(_sourceControlPath, _localPath);
             // Create a mapping.
             _ws.CreateMapping(_myWorkingFolder);

             return _ws;
        }
Exemple #30
0
        public void Update(string newName, string newComment, WorkingFolder[] newMappings)
        {
            Workspace w1 = new Workspace(VersionControlServer, newName, OwnerName,
                                                                     newComment, newMappings, Computer);
            Workspace w2 = Repository.UpdateWorkspace(Name, OwnerName, w1);

            Workstation.Current.UpdateWorkspaceInfoCache(VersionControlServer, OwnerName);
            folders = w2.Folders;
        }
        public void CreateMapping(string strServerPath, string strLocalPath)
        {
            WorkingFolder folder = new WorkingFolder(strServerPath, strLocalPath);

            this.Workspace.CreateMapping(folder);
        }
Exemple #32
0
        public void Workspace_TryGetWorkingFolderForServerItem()
        {
            // need TFS_ envvars for this test
            if (String.IsNullOrEmpty(tfsUrl)) return;
            TeamFoundationServer tfs = new TeamFoundationServer(tfsUrl, credentials);
            VersionControlServer vcs = (VersionControlServer) tfs.GetService(typeof(VersionControlServer));

            WorkingFolder[] folders = new WorkingFolder[2];
            string serverItem = String.Format("$/{0}", Environment.GetEnvironmentVariable("TFS_PROJECT"));
            folders[0] = new WorkingFolder(serverItem, Environment.CurrentDirectory);

            string deeper = Path.Combine(Environment.CurrentDirectory, "deeper");
            folders[1] = new WorkingFolder(serverItem + "/deeper", deeper);

            Workspace w1 = vcs.CreateWorkspace("CreateDelete1_Workspace",
                                                                                 Environment.GetEnvironmentVariable("TFS_USERNAME"),
                                                                                 "My Comment", folders, Environment.MachineName);

            WorkspaceInfo info = Workstation.Current.GetLocalWorkspaceInfo(Environment.CurrentDirectory);
            Workspace w2 = info.GetWorkspace(tfs);

            // this will talk to the server and get the mapped paths
            w2.RefreshMappings();

            {
                string serverItem1 = String.Format("{0}/deeper/foo.txt", serverItem);
                WorkingFolder folder = w2.TryGetWorkingFolderForServerItem(serverItem1);
                Assert.AreEqual(deeper, folder.LocalItem);
            }

            {
                string serverItem1 = String.Format("junk/deeper/foo.txt", serverItem);
                WorkingFolder folder = w2.TryGetWorkingFolderForServerItem(serverItem1);
                Assert.IsNull(deeper);
            }

            w1.Delete();
        }
Exemple #33
0
        /// <summary>
        /// Entry point for the console application.
        /// </summary>
        /// <param name="args">Optional parameter is the Name or Uri of a 
        /// registered project collection to connect to.</param>
        static void Main(string[] args)
        {
            List<RegisteredProjectCollection> projectCollections = null;

            if (args.Count() > 0)
            {
                // try the specified argument as the name or Uri of a registered project collection
                projectCollections = new List<RegisteredProjectCollection>();
                projectCollections.Add(RegisteredInstances.GetProjectCollection(args[1]));
            }
            else
            {
                // get all registered project collections (previously connected to from Team Explorer)
                projectCollections = new List<RegisteredProjectCollection>(
                    (IEnumerable<RegisteredProjectCollection>)(RegisteredInstances.GetProjectCollections()));
            }

            // filter down to only those collections that are currently on-line
            var onlineCollections =
                from collection in projectCollections
                where collection.Offline == false
                select collection;

            // fail if there are no registered collections that are currently on-line
            if (onlineCollections.Count() < 1)
            {
                Console.Error.WriteLine("Error: There are no on-line registered project collections");
                Environment.Exit(1);
            }

            // find a project collection with at least one team project
            foreach (var projectCollection in onlineCollections)
            {
                using (TeamFoundationServer tfs = TeamFoundationServerFactory.GetServer(projectCollection))
                {
                    Workspace workspace = null;
                    Boolean createdWorkspace = false;
                    String newFolder = String.Empty;

                    try
                    {
                        var versionControl = (VersionControlServer)tfs.GetService(typeof(VersionControlServer));

                        var teamProjects = new List<TeamProject>(
                            (IEnumerable<TeamProject>)(versionControl.GetAllTeamProjects(false)));

                        // if there are no team projects in this collection, skip it
                        if (teamProjects.Count < 1) continue;

                        RegisterEventHandlers(versionControl);

                        // Create a workspace
                        String assemblyName = GetAssemblyName();
                        String workspaceName = String.Format("{0}-{1}", Environment.MachineName, assemblyName);

                        try
                        {
                            workspace = versionControl.GetWorkspace(workspaceName,
                                versionControl.AuthenticatedUser);
                        }
                        catch (WorkspaceNotFoundException)
                        {
                            workspace = versionControl.CreateWorkspace(workspaceName,
                                versionControl.AuthenticatedUser);

                            createdWorkspace = true;
                        }

                        var serverFolder = String.Format("$/{0}", teamProjects[0].Name);
                        var localFolder = Path.Combine(Path.GetTempPath(), assemblyName);
                        var workingFolder = new WorkingFolder(serverFolder, localFolder);

                        // Create a workspace mapping
                        workspace.CreateMapping(workingFolder);

                        if (!workspace.HasReadPermission)
                        {
                            throw new SecurityException(
                                String.Format("{0} does not have read permission for {1}",
                                    versionControl.AuthenticatedUser, serverFolder));
                        }

                        // Get the files from the repository
                        workspace.Get();

                        // Create a file
                        newFolder = Path.Combine(workspace.Folders[0].LocalItem, "For Test Purposes");
                        Directory.CreateDirectory(newFolder);
                        String newFilename = Path.Combine(newFolder, "Safe to Delete.txt");

                        AddNewFile(workspace, newFilename);
                        ModifyFile(workspace, newFilename);
                        BranchFile(workspace, newFilename);
                        DeleteFolder(workspace, newFolder);
                    }
                    finally
                    {
                        if ((workspace != null) && createdWorkspace)
                        {
                            workspace.Delete();
                        }

                        if (!String.IsNullOrEmpty(newFolder) && Directory.Exists(newFolder))
                        {
                            Directory.Delete(newFolder, true);
                        }
                    }

                    break;
                }
            }
        }
Exemple #34
0
        public void Workspace_Get()
        {
            // need TFS_ envvars for this test
            if (String.IsNullOrEmpty(tfsUrl)) return;
            TeamFoundationServer tfs = new TeamFoundationServer(tfsUrl, credentials);
            VersionControlServer vcs = (VersionControlServer) tfs.GetService(typeof(VersionControlServer));

            WorkingFolder[] folders = new WorkingFolder[1];
            string serverItem = String.Format("$/{0}", Environment.GetEnvironmentVariable("TFS_PROJECT"));
            folders[0] = new WorkingFolder(serverItem, Environment.CurrentDirectory);

            Workspace w1 = vcs.CreateWorkspace("CreateDelete1_Workspace",
                                                                                 Environment.GetEnvironmentVariable("TFS_USERNAME"),
                                                                                 "My Comment", folders, Environment.MachineName);

            Workspace w2 = vcs.GetWorkspace("CreateDelete1_Workspace");
            Assert.AreEqual("My Comment", w2.Comment);

            w1.Delete();
        }