Exemplo n.º 1
0
        private static Workspace GetWorkspace(WorkspaceInfo workspaceInfo)
        {
            string tfsName     = workspaceInfo.ServerUri.AbsoluteUri;
            var    credentials = System.Net.CredentialCache.DefaultCredentials; //new System.Net.NetworkCredential(userName, password, domain);
            var    projects    = new TfsTeamProjectCollection(TfsTeamProjectCollection.GetFullyQualifiedUriForName(tfsName), credentials, new UICredentialsProvider());

            return(workspaceInfo.GetWorkspace(projects));
        }
Exemplo n.º 2
0
        private Workspace GetWorkspace(WorkspaceInfo wsi)
        {
            TfsTeamProjectCollection tpc = new TfsTeamProjectCollection(wsi.ServerUri);

            //CommonHelper.WriteMessage(string.Format("Get Workspace."));

            Workspace ws = wsi.GetWorkspace(tpc);

            return(ws);
        }
Exemplo n.º 3
0
        void TfsProjectDiff(string[] args)
        {
            // Figure out the workspace information based on the local cache.
            WorkspaceInfo wsInfo = Workstation.Current.GetLocalWorkspaceInfo(Environment.CurrentDirectory);

            if (wsInfo == null)
            {
                Console.Error.WriteLine("The current directory is not mapped.");
                Environment.Exit(1);
            }

            // Now we can get to the workspace.
            TeamFoundationServer tfs = new TeamFoundationServer(wsInfo.ServerUri.AbsoluteUri,
                                                                new System.Net.NetworkCredential(@"snd\alanjmcf_cp", "acpsbjorg"));

            tfs.Authenticate();
            Workspace workspace = wsInfo.GetWorkspace(tfs);

            try {
                // Display the differences for the current directory and all of its descendants
                // (fully recursive).
                if (args.Length == 0)
                {
                    // Display the differences between what's in the workspace compared to latest.
                    DisplayCurrentDiff(workspace);
                }
                else
                {
                    // Display the differences between the two specified versions.
                    if (args.Length != 2)
                    {
                        Console.Error.WriteLine("Usage: projectdiff <versionspec> <versionspec>");
                        Console.Error.WriteLine("Example: projectdiff D04/06/06 T");
                        Console.Error.WriteLine("         compare midnight April 6, 2006 and latest");
                        Console.Error.WriteLine("Example: projectdiff W T");
                        Console.Error.WriteLine("         compare what's in the workspace to latest");
                        Environment.Exit(1);
                    }

                    // Parse the
                    VersionSpec version1 = ParseVersionSpec(args[0], workspace);
                    VersionSpec version2 = ParseVersionSpec(args[1], workspace);

                    DisplayVersionDiff(workspace, version1, version2);
                }
            } catch (TeamFoundationServerException e) {
                // If something goes wrong, such as not having access to the server, display
                // the appropriate error message.
                Console.Error.WriteLine(e.Message);
                Environment.Exit(1);
            }
        }
Exemplo n.º 4
0
 private void CheckOutFromTFS(string fileName)
 {
     using (TfsTeamProjectCollection pc = TfsTeamProjectCollectionFactory.GetTeamProjectCollection(new Uri(tfsServer)))
     {
         if (pc != null)
         {
             WorkspaceInfo workspaceInfo = Workstation.Current.GetLocalWorkspaceInfo(fileName);
             if (null != workspaceInfo)
             {
                 Workspace workspace = workspaceInfo.GetWorkspace(pc);
                 workspace.PendEdit(fileName);
             }
         }
     }
 }
Exemplo n.º 5
0
        public Workspace GetLocalWorkspace(string localItem, TfsServerConnection serverConnection)
        {
            Workspace MyWorkspace;

            if (!Workstation.Current.IsMapped(localItem))
            {
                throw new BuildException(String.Format("Unable to determine the Workspace to use, the path {0} does not map to a workspace.", localItem));
            }

            WorkspaceInfo MyWorkSpaceInfo = Workstation.Current.GetLocalWorkspaceInfo(localItem);

            MyWorkspace = MyWorkSpaceInfo.GetWorkspace(serverConnection.TFS);

            return(MyWorkspace);
        }
Exemplo n.º 6
0
        protected override bool Execute(WorkspaceInfo workspaceInfo)
        {
            using var collection = new TfsTeamProjectCollection(workspaceInfo.ServerUri);

            var workspace = workspaceInfo.GetWorkspace(collection);

            // Use the first project:
            var project = workspace.GetTeamProjectForLocalPath(workspaceInfo.MappedPaths.First());

            // Extract GUID from ArtifactUri "vstfs:///Classification/TeamProject/{Guid}":
            var projectId = Path.GetFileName(project.ArtifactUri.GetPath());

            Url = collection.Uri.ToString() + "/" + projectId;

            return(true);
        }
Exemplo n.º 7
0
        public static Workspace GetWorkspace(WorkspaceInfo info)
        {
            lock (getWorkspaceLock) {
                Workspace workspace;
                if (!tfsWorkspaceCache.TryGetValue(info.Name, out workspace))
                {
                    workspace = info.GetWorkspace(new TfsTeamProjectCollection(info.ServerUri));
                    tfsWorkspaceCache.TryAdd(info.Name, workspace);
                    var changes = workspace.GetPendingChanges();
                    pendingChangesCache.TryAdd(workspace, changes.ToDictionary(x => x.LocalItem));
                    workspace.VersionControlServer.PendingChangesChanged += PendingChangesModified;
                }

                return(workspace);
            }
        }
Exemplo n.º 8
0
        private void GetPathAndScope(string szFile,
                                     out VersionControlServer sourceControl,
                                     out Workspace workspace)
        {
            // Figure out the server based on either the argument or the
            // current directory.
            WorkspaceInfo wsInfo = null;

            workspace = null;
            if (!VersionControlPath.IsServerItem(szFile))
            {
                wsInfo = Workstation.Current.GetLocalWorkspaceInfo(szFile);
            }

            TeamFoundationServer tfs = null;

            if (wsInfo == null)
            {
                wsInfo = Workstation.Current.GetLocalWorkspaceInfo(Environment.CurrentDirectory);
            }

            if (wsInfo != null)
            {
                //Just in case our local file is hooked to a different server
                m_szServerAddress = wsInfo.ServerUri.AbsoluteUri;
            }

            tfs = TeamFoundationServerFactory.GetServer(m_szServerAddress);

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

            // Pick up the label scope, if supplied.
            string scope = VersionControlPath.RootFolder;

            // The scope must be a server path, so we convert it here if
            // the user specified a local path.
            if (!VersionControlPath.IsServerItem(szFile))
            {
                workspace = wsInfo.GetWorkspace(tfs);
                scope     = workspace.GetServerItemForLocalItem(szFile);
            }
            else
            {
                scope = szFile;
            }
        }
Exemplo n.º 9
0
        public static Workspace GetWorkspace(string path)
        {
            try
            {
                // First try the cached worksapces
                foreach (Workspace workspace in Workspaces)
                {
                    if (workspace.IsLocalPathMapped(path))
                    {
                        return(workspace);
                    }
                }
            }
            catch
            {
            }

            // Otherwise try to create a new workspace
            try
            {
                // Get workspace info for the desired file
                Workstation local = Workstation.Current;
                if (local != null)
                {
                    WorkspaceInfo workspaceInfo = local.GetLocalWorkspaceInfo(path);
                    if (workspaceInfo != null)
                    {
                        // TODO: This only uses the local users credentials
                        // (we can either consider passing in credentials or
                        // also trying to use the build host - like VS - to
                        // obtain them)
                        TeamFoundationServer server    = new TeamFoundationServer(workspaceInfo.ServerUri.ToString());
                        Workspace            workspace = workspaceInfo.GetWorkspace(server);
                        Workspaces.Add(workspace);
                        return(workspace);
                    }
                }
            }
            catch
            {
            }

            return(null);
        }
Exemplo n.º 10
0
        protected override bool Execute(WorkspaceInfo workspaceInfo)
        {
            var result = new List <TaskItem>();

            using (var collection = new TfsTeamProjectCollection(workspaceInfo.ServerUri))
            {
                var vcServer    = collection.GetService <VersionControlServer>();
                var changesetId = vcServer.GetLatestChangesetId().ToString();

                var workspace     = workspaceInfo.GetWorkspace(collection);
                var collectionUrl = collection.Uri.ToString();

                // TODO: eliminate redundant mappings - we can use RepositoryRoot calculation here
                // E.g. A\B -> $/X/A/B, A\C -> $/X/A/C can be reduced to A -> $/X/A

                foreach (var folder in workspace.Folders)
                {
                    if (!folder.IsCloaked)
                    {
                        var project = workspace.GetTeamProjectForLocalPath(folder.LocalItem);

                        // Extract GUID from ArtifactUri "vstfs:///Classification/TeamProject/{Guid}":
                        var projectId = Path.GetFileName(project.ArtifactUri.GetPath());

                        // SourceLink.Vsts will map each source root to:
                        // {RepositoryUrl}/_versionControl?path={ServerPath}&version={RevisionId}
                        var item = new TaskItem(folder.LocalItem);
                        item.SetMetadata("SourceControl", "tfvc");
                        item.SetMetadata("CollectionUrl", collectionUrl);
                        item.SetMetadata("ProjectId", projectId);
                        item.SetMetadata("ServerPath", folder.ServerItem);
                        item.SetMetadata("RevisionId", changesetId);
                        result.Add(item);
                    }
                }

                Mapping = result.ToArray();
                return(true);
            }
        }
Exemplo n.º 11
0
        /// <summary>
        /// Création d'un label lors de la publication
        /// </summary>
        /// <param name="model"></param>
        private void CreateLabel(CandleModel model, string modelFileName)
        {
            if (model == null || modelFileName == null)
            {
                return;
            }

            try
            {
                DTE dte = GetService <DTE>();

                string solutionFolder = Path.GetDirectoryName(modelFileName);

                // Récupère les caractèristiques du workspace contenant le fichier contenant le modèle
                if (Workstation.Current == null)
                {
                    throw new Exception("TFS not installed");
                }

                WorkspaceInfo wi = Workstation.Current.GetLocalWorkspaceInfo(solutionFolder);
                if (wi == null)
                {
                    LogError("The current solution is not in a Team System workspace");
                    return;
                }

                // Récupèration du server TFS à partir des infos du workspace
                TeamFoundationServer tfs = TeamFoundationServerFactory.GetServer(wi.ServerUri.AbsoluteUri);

                // Création d'un label sur la solution
                VersionControlServer vcs = tfs.GetService(typeof(VersionControlServer)) as VersionControlServer;
                vcs.NonFatalError += new ExceptionEventHandler(vcs_NonFatalError);
                // On prend tous les fichiers de la solution
                ItemSpec      itemSpec      = new ItemSpec(solutionFolder, RecursionType.Full);
                LabelItemSpec labelItemSpec = new LabelItemSpec(itemSpec, VersionSpec.Latest, false);

                string changeSet = "-";
                // Calcul du nom du label
                string labelName = String.Format(labelNameFormat, DateTime.Now, wi.OwnerName, wi.Computer, model.Version, model.Version.Revision, changeSet);
                // Calcul du commentaire
                string labelComment = String.Format(labelCommentFormat, DateTime.Now, wi.OwnerName, wi.Computer, model.Version, model.Version.Revision, changeSet);

                //Checkin
                if (forceCheckin)
                {
                    Workspace ws = wi.GetWorkspace(tfs);

                    PendingChange[] pendingChanges = ws.GetPendingChanges(new ItemSpec[] { itemSpec }, false);
                    if (pendingChanges.Length > 0)
                    {
                        changeSet = ws.CheckIn(pendingChanges, labelComment).ToString();

                        // Mise à jour de l'explorateur de solution (icones)
                        Microsoft.VisualStudio.Shell.ServiceProvider serviceProvider = new Microsoft.VisualStudio.Shell.ServiceProvider((Microsoft.VisualStudio.OLE.Interop.IServiceProvider)dte);
                        IVersionControlProvider versionControlProvider = (IVersionControlProvider)serviceProvider.GetService(typeof(IVersionControlProvider));
                        if (versionControlProvider != null)
                        {
                            versionControlProvider.RefreshStatus();
                        }

                        // On intègre le changeset dans le commentaire
                        labelName    = String.Format(labelNameFormat, DateTime.Now, wi.OwnerName, wi.Computer, model.Version, model.Version.Revision, changeSet);
                        labelComment = String.Format(labelCommentFormat, DateTime.Now, wi.OwnerName, wi.Computer, model.Version, model.Version.Revision, changeSet);
                    }
                }

                string scope;
                string label;
                LabelSpec.Parse(labelName, null, false, out label, out scope);
                VersionControlLabel vcl = new VersionControlLabel(vcs, label, null, scope, labelComment);

                // Et on applique le label.
                LabelResult[] results = vcs.CreateLabel(vcl, new LabelItemSpec[] { labelItemSpec }, childOption);
            }
            catch (Exception ex)
            {
                LogError(ex);
                nbErrors++;
            }

            if (nbErrors > 0 && stopOnError)
            {
                throw new PublishingException();
            }
        }
Exemplo n.º 12
0
        private static void GetPathAndScope(String[] args,
                                            out String path, out String scope,
                                            out VersionControlServer sourceControl)
        {
            // This little app takes either no args or a file path and optionally a scope.
            if (args.Length > 2 ||
                args.Length == 1 && args[0] == "/?")
            {
                Console.WriteLine("Usage: labelhist");
                Console.WriteLine("       labelhist path [label scope]");
                Console.WriteLine();
                Console.WriteLine("With no arguments, all label names and comments are displayed.");
                Console.WriteLine("If a path is specified, only the labels containing that path");
                Console.WriteLine("are displayed.");
                Console.WriteLine("If a scope is supplied, only labels at or below that scope will");
                Console.WriteLine("will be displayed.");
                Console.WriteLine();
                Console.WriteLine("Examples: labelhist c:\\projects\\secret\\notes.txt");
                Console.WriteLine("          labelhist $/secret/notes.txt");
                Console.WriteLine("          labelhist c:\\projects\\secret\\notes.txt $/secret");
                Environment.Exit(1);
            }

            // Figure out the server based on either the argument or the
            // current directory.
            WorkspaceInfo wsInfo = null;

            if (args.Length < 1)
            {
                path = null;
            }
            else
            {
                path = args[0];
                try
                {
                    if (!VersionControlPath.IsServerItem(path))
                    {
                        wsInfo = Workstation.Current.GetLocalWorkspaceInfo(path);
                    }
                }
                catch (Exception e)
                {
                    // The user provided a bad path argument.
                    Console.Error.WriteLine(e.Message);
                    Environment.Exit(1);
                }
            }

            TeamFoundationServer tfs = null;

            if (wsInfo == null)
            {
                wsInfo = Workstation.Current.GetLocalWorkspaceInfo(Environment.CurrentDirectory);
            }

            // Stop if we couldn't figure out the server.
            if (wsInfo == null)
            {
                //Console.Error.WriteLine("Unable to determine the server.");
                //Environment.Exit(1);
                //tfs = TeamFoundationServerFactory.GetServer("http://tfsappserver:8080");
                tfs = TeamFoundationServerFactory.GetServer("http://tfs.radiantsystems.com:8080");
            }
            else
            {
                tfs = TeamFoundationServerFactory.GetServer(wsInfo.ServerUri.AbsoluteUri);
            }
            //    TeamFoundationServerFactory.GetServer(wsInfo.ServerName);
            // RTM: wsInfo.ServerUri.AbsoluteUri);
            sourceControl = (VersionControlServer)tfs.GetService(typeof(VersionControlServer));

            // Pick up the label scope, if supplied.
            scope = VersionControlPath.RootFolder;
            if (args.Length == 2)
            {
                // The scope must be a server path, so we convert it here if
                // the user specified a local path.
                if (!VersionControlPath.IsServerItem(args[1]))
                {
                    Workspace workspace = wsInfo.GetWorkspace(tfs);
                    scope = workspace.GetServerItemForLocalItem(args[1]);
                }
                else
                {
                    scope = args[1];
                }
            }
        }
Exemplo n.º 13
0
        public Workspace GetWorkspace(WorkspaceInfo workspaceInfo, TfsTeamProjectCollection tfsTeamProjectCollection)
        {
            this.Logger().Trace("GetWorkspace  ProjectCollection: {0} Workspace: {1}", tfsTeamProjectCollection.Name, workspaceInfo.Name);

            return(workspaceInfo.GetWorkspace(tfsTeamProjectCollection));
        }