/// <summary>
        /// Loads a specific dependency definition file.
        /// </summary>
        /// <param name="name">The source control folder path for the component.</param>
        /// <param name="version">The component version.</param>
        /// <returns>The loaded dependency definition xml file</returns>
        public XDocument LoadComponentTarget(IComponentName name, IComponentVersion version)
        {
            ValidateComponentName(name);
            ValidateComponentVersion(version);

            foreach (var dependencyDefinitionFileName in ValidDependencyDefinitionFileNames)
            {
                var dependencyDefinitionFileLocation = VersionControlPath.Combine(name.ToString(), dependencyDefinitionFileName);
                if (!VersionControlServer.ServerItemExists(dependencyDefinitionFileLocation, version.TfsVersionSpec, DeletedState.Any, ItemType.File))
                {
                    Logger.Instance().Log(TraceLevel.Verbose, "{0}: Dependency definition file {1} for component {2}#{3} was not found", ResolverType, dependencyDefinitionFileLocation, name, version);
                    continue;
                }

                var item = VersionControlServer.GetItem(dependencyDefinitionFileLocation, version.TfsVersionSpec, DeletedState.Any, true);
                using (var content = item.DownloadFile())
                {
                    var xdoc = XDocument.Load(content);
                    Logger.Instance().Log(TraceLevel.Info, "{0}: Loading dependency definition file {1} for component {2}#{3} finished successfully", ResolverType, dependencyDefinitionFileLocation, name, version);
                    return(xdoc);
                }
            }

            return(null);
        }
        /// <summary>
        /// Determines whether a version control folder exists having a specific version
        /// </summary>
        /// <param name="name">The name of the component</param>
        /// <param name="version">The name of the component (branch folder)</param>
        /// <returns>true if the branch folder exists at the version; false otherwise</returns>
        public bool ComponentExists(IComponentName name, IComponentVersion version)
        {
            ValidateComponentName(name);
            ValidateComponentVersion(version);

            // Check if folder exists in source control
            if (!VersionControlServer.ServerItemExists(name.ToString(), version.TfsVersionSpec, DeletedState.NonDeleted, ItemType.Folder))
            {
                Logger.Instance().Log(TraceLevel.Warning, "{0}: Component {1}#{2} was not found in source control", ResolverType, name, version);
                return(false);
            }

            // Check if component.targets exists inside folder
            var folderItems = VersionControlServer.GetItems(VersionControlPath.Combine(name.ToString(), "*"), version.TfsVersionSpec, RecursionType.OneLevel);

            foreach (Item item in folderItems.Items)
            {
                var itemName = VersionControlPath.GetFileName(item.ServerItem);

                foreach (var dependencyDefinitionFileName in ValidDependencyDefinitionFileNames)
                {
                    if (string.Equals(itemName, dependencyDefinitionFileName, StringComparison.OrdinalIgnoreCase))
                    {
                        Logger.Instance().Log(TraceLevel.Info, "{0}: Component {1}#{2} was found in source control", ResolverType, name, version);
                        return(true);
                    }
                }
            }

            Logger.Instance().Log(TraceLevel.Warning, "{0}: Component {1}#{2} was not found in source control", ResolverType, name, version);
            return(false);
        }
예제 #3
0
        /// <summary>
        /// Resolves the provided script parameter to either a server stored
        /// PS file or an inline script for direct execution.
        /// </summary>
        /// <param name="context">The activity context</param>
        /// <returns>An executable powershell script</returns>
        internal string ResolveScript(CodeActivityContext context)
        {
            var script = this.Script.Get(context);

            if (string.IsNullOrWhiteSpace(script))
            {
                throw new ArgumentNullException("context", "Script");
            }

            if (VersionControlPath.IsServerItem(script))
            {
                var workspace = this.BuildWorkspace.Get(context);

                if (workspace == null)
                {
                    throw new ArgumentNullException("context", "BuildWorkspace");
                }

                var workspaceFilePath = workspace.GetLocalItemForServerItem(script);
                if (!File.Exists(workspaceFilePath))
                {
                    throw new FileNotFoundException("Script", string.Format(CultureInfo.CurrentCulture, "Workspace local path {0} for source path {1} was not found", script, workspaceFilePath));
                }

                var arguments = this.Arguments.Get(context);
                script = "& '" + workspaceFilePath + "' " + arguments;
            }

            return(script);
        }
        /// <summary>
        /// Returns all components found in the repository.
        /// </summary>
        /// <returns>List with components</returns>
        public IEnumerable <IComponentName> GetAvailableComponentNames()
        {
            var availableComponents = new List <IComponentName>();

            Logger.Instance().Log(TraceLevel.Info, "{0}: Querying available components...", ResolverType);

            var items = VersionControlServer.GetItems(VersionControlPath.Combine(PathPrefix, "*"));

            foreach (var item in items.Items)
            {
                if (item.ItemType.Equals(ItemType.Folder))
                {
                    var componentName = VersionControlPath.GetFileName(item.ServerItem);

                    if (!string.Equals(componentName, "BuildProcessTemplates", StringComparison.OrdinalIgnoreCase))
                    {
                        availableComponents.Add(new ComponentName(componentName));
                        Logger.Instance().Log(TraceLevel.Info, "{0}: Found component {1}", ResolverType, componentName);
                    }
                }
            }

            Logger.Instance().Log(TraceLevel.Info, "{0}: Querying components finished successfully", ResolverType);

            return(availableComponents);
        }
예제 #5
0
 static void Main(string[] args)
 {
     try
     {
         Uri    serverUri  = new Uri(args[0]);
         string serverPath = args[1];
         string localPath  = args[2];
         for (int i = 0; i < 5; i++)
         {
             string uniqueId = Guid.NewGuid().ToString();
             if (i > 0)
             {
                 Console.WriteLine();
             }
             Console.WriteLine("Creating a workspace and checking in with id " + uniqueId);
             TfsTeamProjectCollection connection = new TfsTeamProjectCollection(serverUri);
             VersionControlServer     vcs        = connection.GetService <VersionControlServer>();
             string    uniqueServerPath          = VersionControlPath.Combine(serverPath, uniqueId);
             string    uniqueFolder = Path.Combine(localPath, uniqueId);
             Workspace workspace    = vcs.CreateWorkspace(uniqueId, vcs.AuthorizedUser, "", new WorkingFolder[] {
                 new WorkingFolder(uniqueServerPath, uniqueFolder)
             });
             Console.WriteLine("Created TFS workspace " + uniqueId);
             CheckinLocalFolder(serverUri, localPath, uniqueId);
         }
     }
     catch (Exception e)
     {
         Console.WriteLine("Failed: " + e);
     }
 }
예제 #6
0
        public override void BasicActionHandler(MigrationAction action, ChangeGroup group)
        {
            try
            {
                VersionControlPath.GetFullPath(action.Path, true);
                if (!string.IsNullOrEmpty(action.FromPath))
                {
                    VersionControlPath.GetFullPath(action.FromPath, true);
                }
            }
            catch (Exception e)
            {
                MigrationConflict pathTooLongConflict = VCInvalidPathConflictType.CreateConflict(action, e.Message, action.Path);

                List <MigrationAction>   returnActions;
                ConflictResolutionResult resolutionResult = ((TfsVCAnalysisProvider)AnalysisProvider).ConflictManager.TryResolveNewConflict(
                    group.SourceId, pathTooLongConflict, out returnActions);
                if (resolutionResult.Resolved)
                {
                    switch (resolutionResult.ResolutionType)
                    {
                    case ConflictResolutionType.SkipConflictedChangeAction:
                        return;

                    default:
                        Debug.Fail("Unknown resolution result");
                        return;
                    }
                }
                return;
            }
            base.BasicActionHandler(action, group);
        }
        /// <summary>
        /// Loads a specific dependency definition file.
        /// </summary>
        /// <param name="name">The name of the binary repository component.</param>
        /// <param name="version">The component version.</param>
        /// <returns>The loaded dependency definition xml file</returns>
        public XDocument LoadComponentTarget(IComponentName name, IComponentVersion version)
        {
            ValidateComponentName(name);
            ValidateComponentVersion(version);

            foreach (var dependencyDefinitionFileName in ValidDependencyDefinitionFileNames)
            {
                var dependencyDefinitionFileLocation = VersionControlPath.Combine(VersionControlPath.Combine(VersionControlPath.Combine(PathPrefix, name.ToString()), version.ToString()), dependencyDefinitionFileName);

                if (!VersionControlServer.ServerItemExists(dependencyDefinitionFileLocation, ItemType.File))
                {
                    Logger.Instance().Log(TraceLevel.Verbose, "{0}: Dependency definition file {1} for component {2}#{3} was not found", ResolverType, dependencyDefinitionFileLocation, name, version);
                    continue;
                }

                var dependencyDefinitionFileStream = VersionControlServer.GetItem(dependencyDefinitionFileLocation, VersionSpec.Latest).DownloadFile();
                var xdoc = XDocument.Load(dependencyDefinitionFileStream);

                // Close the previously opened filestream to ensure a cleanup
                dependencyDefinitionFileStream.Close();

                Logger.Instance().Log(TraceLevel.Info, "{0}: Loading dependency definition file {1} for component {2}#{3} finished successfully", ResolverType, dependencyDefinitionFileLocation, name, version);
                return(xdoc);
            }

            return(null);
        }
예제 #8
0
    public override void Run()
    {
        RecursionType rtype   = OptionRecursive ? RecursionType.Full : RecursionType.None;
        VersionSpec   version = VersionFromString(OptionVersion);

        List <ItemSpec> itemSpecs = new List <ItemSpec>();

        foreach (string item in Arguments)
        {
            string fpath = (VersionControlPath.IsServerItem(item))? item : Path.GetFullPath(item);
            itemSpecs.Add(new ItemSpec(fpath, rtype));
        }

        BranchHistoryTreeItem[][] treeItemsArray = VersionControlServer.GetBranchHistory(itemSpecs.ToArray(), version);
        foreach (BranchHistoryTreeItem[] treeItems in treeItemsArray)
        {
            //Console.WriteLine("New TreeItem");
            foreach (BranchHistoryTreeItem treeItem in treeItems)
            {
                //Console.WriteLine("Relative: " + treeItem.Relative);
                //Console.WriteLine(treeItem.Relative.ServerItem);
                foreach (Object obj in treeItem.Children)
                {
                    BranchRelative branch   = obj as BranchRelative;
                    Item           fromItem = branch.BranchFromItem;
                    Console.WriteLine(fromItem.ServerItem);
                    Item toItem = branch.BranchToItem;
                    Console.Write(">> \t" + toItem.ServerItem);
                    Console.WriteLine("\tBranched from version " + fromItem.ChangesetId + " <<");
                }
            }
        }
    }
        /// <summary>
        /// Downloads a component from source control to a local path.
        /// </summary>
        /// <param name="source">Path to source location</param>
        /// <param name="destination">Path to destination folder</param>
        /// <param name="watermark">The watermark can be used to perform incremental updates and cleanup operations</param>
        /// <param name="force">Indicates that we want to force a get operation and all files have to be overwritten</param>
        /// <param name="settings">Setting which contain the version to fetch</param>
        public void Download(string source, string destination, IDependencyDownloaderWatermark watermark, bool force, ISettings <DownloaderValidSettings> settings)
        {
            if (string.IsNullOrEmpty(source))
            {
                throw new InvalidComponentException(
                          "Source control path to component folder was empty in DownloaderSourceControlCopy");
            }

            if (string.IsNullOrEmpty(destination))
            {
                throw new InvalidComponentException(
                          "Destination path for component was empty in DownloaderSourceControlCopy");
            }

            if (null == watermark)
            {
                throw new ArgumentNullException("watermark");
            }

            if (null == settings)
            {
                throw new ArgumentNullException("settings");
            }

            var versionString = settings.GetSetting(DownloaderValidSettings.VersionString);

            if (string.IsNullOrEmpty(versionString))
            {
                throw new InvalidComponentException(
                          "Version string for component was empty in DownloaderSourceControlCopy");
            }

            var folderMappings = InitializeMappings(settings.GetSetting(DownloaderValidSettings.FolderMappings));
            var includeFilter  = InitializeIncludeFilter(settings.GetSetting(DownloaderValidSettings.IncludedFilesFilter));
            var excludeFilter  = InitializeExcludeFilter(settings.GetSetting(DownloaderValidSettings.ExcludedFilesFilter));

            // ReSharper disable PossibleMultipleEnumeration
            if (folderMappings.Any())
            // ReSharper restore PossibleMultipleEnumeration
            {
                // ReSharper disable PossibleMultipleEnumeration
                foreach (var mapping in folderMappings)
                // ReSharper restore PossibleMultipleEnumeration
                {
                    var subSource = VersionControlPath.Combine(source, mapping.Key);
                    var subDest   = Path.Combine(destination, mapping.Value);
                    Logger.Instance().Log(TraceLevel.Info, "{0}: Downloading component" +
                                          " subfolder {1} with source control version '{2}' to {3}", DownloadType, mapping.Key, versionString, subDest);
                    DownloadFolder(source, subSource, subDest, versionString, includeFilter, excludeFilter, watermark, force);
                }

                Logger.Instance().Log(TraceLevel.Info, "{0}: Component {1} download finished successfully", DownloadType, source);
            }
            else
            {
                Logger.Instance().Log(TraceLevel.Info, "{0}: Downloading component {1} with source control version '{2}' to {3}", DownloadType, source, versionString, destination);
                DownloadFolder(source, source, destination, versionString, includeFilter, excludeFilter, watermark, force);
                Logger.Instance().Log(TraceLevel.Info, "{0}: Component {1} download finished successfully", DownloadType, source);
            }
        }
        // This common method used for both folders and files places the item in the SubItems list
        // of the appropriate parent folder, and also adds the item to the directSubItems list to be
        // returned on this call if and only if item is a direct child of the folderDiffItem argument
        // of GetFolderSubDiffItems().
        private void ProcessSubItem(
            TfsVCDiffItem tfsDiffItem,
            TfsVCDiffItem topFolderDiffItem,
            List <IVCDiffItem> directSubItems,
            bool addSubItemToContainingFolderItem)
        {
            string containingFolderPath = VersionControlPath.GetFolderName(tfsDiffItem.ServerPath);

            if (addSubItemToContainingFolderItem)
            {
                TfsVCDiffItem containingFolderItem;
                if (!m_cachedFolderItems.TryGetValue(containingFolderPath, out containingFolderItem))
                {
                    TraceManager.TraceWarning(String.Format(CultureInfo.InvariantCulture, TfsVCAdapterResource.ContainingFolderNotFound,
                                                            tfsDiffItem.ServerPath));
                    return;
                }

                containingFolderItem.SubItems.Add(tfsDiffItem);
            }

            if (string.Equals(topFolderDiffItem.ServerPath, containingFolderPath, StringComparison.InvariantCultureIgnoreCase))
            {
                directSubItems.Add(tfsDiffItem);
            }
        }
        /// <summary>
        /// Checks if source control folder contains a dependency definition file.
        /// </summary>
        /// <param name="sourceControlPath">The source control path to check.</param>
        /// <param name="dependencyDefinitonFilenameList">The list of valid dependency definition file names.</param>
        /// <returns>True if it contains a dependency definition file. False otherwise.</returns>
        public bool IsDependencyDefinitionFilePresentInFolder(string sourceControlPath, string dependencyDefinitonFilenameList)
        {
            if (null == _tpc)
            {
                throw new InvalidOperationException("The connection is currently closed");
            }

            var vss = _tpc.GetService <VersionControlServer>();

            if (null == vss)
            {
                throw new InvalidOperationException("The connection to the version control server could not be established");
            }

            var items = vss.GetItems(VersionControlPath.Combine(sourceControlPath, "*"), VersionSpec.Latest, RecursionType.OneLevel);
            var dependencyDefinitionFilenames = dependencyDefinitonFilenameList.Split(';');

            foreach (var item in items.Items)
            {
                if (dependencyDefinitionFilenames.Any(x => x.Equals(VersionControlPath.GetFileName(item.ServerItem), StringComparison.OrdinalIgnoreCase)))
                {
                    return(true);
                }
            }

            return(false);
        }
예제 #12
0
        private static string GetConfigurationFileLocation(string teamProjectName, string buildType)
        {
            var buildServer     = ServiceHelper.GetService <IBuildServer>();
            var buildDefinition = buildServer.GetBuildDefinition(teamProjectName, buildType);

            return(VersionControlPath.Combine(buildDefinition.ConfigurationFolderPath, "Deployment/"));
        }
예제 #13
0
        public static string GetName(Item item)
        {
            Contract.Requires(item != null);
            string name = VersionControlPath.GetFileName(item.ServerItem);

            return(name);
        }
예제 #14
0
    public override void Run()
    {
        string path = Environment.CurrentDirectory;

        if (Arguments.Length > 0)
        {
            path = Arguments[0];
        }
        if (!VersionControlPath.IsServerItem(path))
        {
            path = Path.GetFullPath(path);
        }

        // process command options
        RecursionType rtype  = OptionRecursive ? RecursionType.Full : RecursionType.OneLevel;
        DeletedState  dstate = OptionDeleted ? DeletedState.Any : DeletedState.NonDeleted;

        ItemSpec itemSpec = new ItemSpec(path, rtype);
        ItemSet  itemSet  = VersionControlServer.GetItems(itemSpec, VersionFromString(OptionVersion), dstate, ItemType.Any, false);

        Item[] items = itemSet.Items;

        foreach (Item item in items)
        {
            Console.Write(item.ServerItem);
            if ((item.ItemType == ItemType.Folder) && (!item.ServerItem.EndsWith(Path.DirectorySeparatorChar.ToString())))
            {
                Console.Write("/");
            }
            Console.WriteLine();
        }

        Console.WriteLine(items.Length + " item(s)");
    }
        private static void CheckinLocalFolder(VersionControlServer vcs, string serverPath, string localPath, string uniqueId)
        {
            string uniqueServerPath = VersionControlPath.Combine(serverPath, uniqueId);
            string uniqueFolder     = Path.Combine(localPath, uniqueId);
            string uniqueFile       = Path.Combine(uniqueFolder, uniqueId + ".txt");

            // Create a local folder with a file in it
            Directory.CreateDirectory(uniqueFolder);
            using (TextWriter output = new StreamWriter(uniqueFile))
            {
                output.WriteLine("This is " + uniqueId);
                output.Close();
            }
            Console.WriteLine("Created file " + uniqueFile);
            Workspace workspace = vcs.CreateWorkspace(uniqueId, vcs.AuthorizedUser, "", new WorkingFolder[] {
                new WorkingFolder(uniqueServerPath, uniqueFolder)
            });

            Console.WriteLine("Created TFS workspace " + uniqueId);
            workspace.PendAdd(uniqueFolder, true);
            PendingChange[] pendingChanges = workspace.GetPendingChanges();
            Console.WriteLine("Pended changes:");
            foreach (PendingChange pendingChange in pendingChanges)
            {
                Console.WriteLine(" " + pendingChange.LocalItem + " (" + pendingChange.ChangeType + ")");
            }
            int changeset = workspace.CheckIn(pendingChanges, "Test from id " + uniqueId);

            Console.WriteLine("Checked in " + pendingChanges.Length + " as changeset " + changeset);
        }
예제 #16
0
        public static void UnCloak(Workspace workspace, string serverItem)
        {
            string        localItem = null;
            WorkingFolder mapping   = null;

            foreach (WorkingFolder workingFolder in workspace.Folders)
            {
                if (workingFolder.Type == WorkingFolderType.Cloak)
                {
                    if (serverItem != null && (VersionControlPath.Equals(workingFolder.ServerItem, serverItem) || VersionControlPath.Equals(workingFolder.DisplayServerItem, serverItem)))
                    {
                        localItem = workingFolder.LocalItem;
                        mapping   = workingFolder;
                        break;
                    }
                    if (localItem != null && Microsoft.TeamFoundation.Common.FileSpec.Equals(workingFolder.LocalItem, localItem))
                    {
                        serverItem = workingFolder.ServerItem;
                        mapping    = workingFolder;
                        break;
                    }
                }
            }

            if (mapping != null)
            {
                workspace.DeleteMapping(mapping);
            }
        }
예제 #17
0
        /// <summary>
        /// Find the mapping entry for the given path.
        /// </summary>
        /// <param name="serverPath"></param>
        /// <returns>Null if the path is not mapped or cloaked. Otherwise, return the mapping entry.</returns>
        internal MappingEntry FindMappedPath(string serverPath)
        {
            MappingEntry mostSpecificMapping = null;

            foreach (MappingEntry current in ConfigurationService.Filters)
            {
                if (VersionControlPath.IsSubItem(serverPath, VersionControlPath.GetFullPath(current.Path)))
                {
                    if (mostSpecificMapping == null ||
                        VersionControlPath.IsSubItem(VersionControlPath.GetFullPath(current.Path),
                                                     VersionControlPath.GetFullPath(mostSpecificMapping.Path)))
                    {
                        mostSpecificMapping = current;
                    }
                }
            }

            if ((mostSpecificMapping != null) && (!mostSpecificMapping.Cloak))
            {
                return(mostSpecificMapping);
            }
            else
            {
                return(null);
            }
        }
예제 #18
0
    public void UnmapWorkfolder(Workspace workspace, string item)
    {
        if (!VersionControlPath.IsServerItem(item))
        {
            item = Path.GetFullPath(item);
        }

        List <WorkingFolder> folders = new List <WorkingFolder>(workspace.Folders);
        string msg = String.Empty;

        for (int i = 0; i < folders.Count; ++i)
        {
            WorkingFolder folder = folders[i];

            if (item == folder.ServerItem || item == folder.LocalItem)
            {
                msg = String.Format("Removed: {0} => {1}",
                                    folder.ServerItem, folder.LocalItem);
                folders.RemoveAt(i);
                break;
            }
        }

        workspace.Update(workspace.Name, workspace.Comment, folders.ToArray());
        if (!String.IsNullOrEmpty(msg))
        {
            Console.WriteLine(msg);
        }
    }
        /// <summary>
        /// Determines whether a version control folder exists having a specific version
        /// </summary>
        /// <param name="name">The name of the component</param>
        /// <param name="version">The version for the component</param>
        /// <returns>True if a version folder exists at the version; false otherwise</returns>
        public bool ComponentExists(IComponentName name, IComponentVersion version)
        {
            ValidateComponentName(name);
            ValidateComponentVersion(version);

            if (VersionControlServer.ServerItemExists(VersionControlPath.Combine(PathPrefix, name.ToString()), VersionSpec.Latest, DeletedState.NonDeleted, ItemType.Folder))
            {
                var path = VersionControlPath.Combine(VersionControlPath.Combine(PathPrefix, name.ToString()), version.ToString());

                if (VersionControlServer.ServerItemExists(path, VersionSpec.Latest, DeletedState.NonDeleted, ItemType.Folder))
                {
                    // Check if component.targets exists inside folder
                    var folderItems = VersionControlServer.GetItems(VersionControlPath.Combine(path, "*"));
                    foreach (var item in folderItems.Items)
                    {
                        var itemName = VersionControlPath.GetFileName(item.ServerItem);

                        foreach (var dependencyDefinitionFileName in ValidDependencyDefinitionFileNames)
                        {
                            if (string.Equals(itemName, dependencyDefinitionFileName, StringComparison.OrdinalIgnoreCase))
                            {
                                Logger.Instance().Log(TraceLevel.Info, "{0}: Component {1}#{2} was found in binary repository", ResolverType, name, version);
                                return(true);
                            }

                            Logger.Instance().Log(TraceLevel.Verbose, "{0}: Dependency definition file {1} for component {2}#{3} was not found in binary repository", ResolverType, dependencyDefinitionFileName, name, version);
                        }
                    }
                }
            }

            Logger.Instance().Log(TraceLevel.Warning, "{0}: Component {1}#{2} was not found in binary repository", ResolverType, name, version);
            return(false);
        }
 internal static string GetItemName(PendingChange pendingChange, bool useServerPath)
 {
     if (useServerPath || string.IsNullOrEmpty(pendingChange.LocalItem))
     {
         return(VersionControlPath.GetFileName(pendingChange.ServerItem));
     }
     return(FileSpec.GetFileName(pendingChange.LocalItem));
 }
        /// <summary>
        /// Gets the local folder name of the dependency definition file. In case of a version control item the local item is determined first.
        /// </summary>
        /// <param name="workspace">Workspace to use</param>
        /// <param name="componentTargetsFileName">Version control item or full local file name</param>
        /// <returns></returns>
        private static string GetOutputFolder(Workspace workspace, String componentTargetsFileName)
        {
            var compTargetsLocalFileName = VersionControlPath.IsValidPath(componentTargetsFileName)
                                               ? workspace.TryGetLocalItemForServerItem(componentTargetsFileName)
                                               : componentTargetsFileName;

            return(Path.GetDirectoryName(compTargetsLocalFileName));
        }
예제 #22
0
        public static string GetName(Item item)
        {
            FoundationContract.Requires <ArgumentException>(item != null);

            var name = VersionControlPath.GetFileName(item.ServerItem);

            return(name);
        }
예제 #23
0
        public static string GetName(Item item)
        {
            Assert.IsTrue(item != null);

            var name = VersionControlPath.GetFileName(item.ServerItem);

            return(name);
        }
예제 #24
0
        /// <summary>
        /// Loads BinaryRepositoryTeamProject, BinaryRepositoryTeamProjectCollectionUrl and RelativeOutputPath from TFS registry.
        /// Loads WorkSpace and DependencyDefinitionPath from Activity Context
        /// </summary>
        /// <param name="context">The activity context.</param>
        /// <returns>Settings collection</returns>
        /// <exception cref="DependencyServiceException">If no output path could be determined or if the dependency definition path is invalid</exception>
        private ISettings <ServiceValidSettings> LoadSettingsFromTfsRegistry(CodeActivityContext context)
        {
            var workspaceValue      = context.GetValue(Workspace);
            var workspaceNameValue  = workspaceValue.Name;
            var workspaceOwnerValue = workspaceValue.OwnerName;
            var tfsUri = workspaceValue.VersionControlServer.TeamProjectCollection.Uri;
            var dependencyDefinitionPathValue = context.GetValue(DependencyDefinitionPath);

            DependencyManagerSettings.Instance.Load(tfsUri.AbsoluteUri);

            // Validate activity parameters
            if (!dependencyDefinitionPathValue.StartsWith(VersionControlPath.RootFolder) || !dependencyDefinitionPathValue.Contains(VersionControlPath.Separator.ToString(CultureInfo.InvariantCulture)))
            {
                throw new DependencyServiceException(string.Format("DependencyDefinitionPath:\n\"{0}\" does not seem like a valid path!\nExample: $\\Path_To_Dependency_Definition_File\\component.targets or C:\\Path_To_Dependency_Definition_File\\component.targets", dependencyDefinitionPathValue));
            }

            string outputFolder;

            if (VersionControlPath.IsValidPath(dependencyDefinitionPathValue))
            {
                outputFolder = workspaceValue.TryGetLocalItemForServerItem(dependencyDefinitionPathValue);
            }
            else
            {
                outputFolder = Path.GetDirectoryName(dependencyDefinitionPathValue);
            }

            if (string.IsNullOrEmpty(outputFolder))
            {
                throw new DependencyServiceException(string.Format("Output base folder could not be determined based on dependency definition path {0}", dependencyDefinitionPathValue));
            }

            // Lousy way to create a semicolon separated list of possible and allowed filenames: component.targets
            // I don't know why the filename of the initial definition is included but better keep it that way...
            var dependencyDefinitionFileNameList = string.Join(";", DependencyManagerSettings.Instance.ValidDependencyDefinitionFileExtension.Select(x => string.Concat("component", x)));
            var defaultDefinitionFilename        = Path.GetFileName(dependencyDefinitionPathValue);

            if (defaultDefinitionFilename != null && !dependencyDefinitionFileNameList.Contains(defaultDefinitionFilename))
            {
                dependencyDefinitionFileNameList = string.Concat(
                    Path.GetFileName(dependencyDefinitionPathValue), ";", dependencyDefinitionFileNameList);
            }

            // create Settings
            ISettings <ServiceValidSettings> settings = new Settings <ServiceValidSettings>();

            settings.AddSetting(new KeyValuePair <ServiceValidSettings, string>(ServiceValidSettings.DefaultTeamProjectCollection, tfsUri.AbsoluteUri));
            settings.AddSetting(new KeyValuePair <ServiceValidSettings, string>(ServiceValidSettings.DefaultWorkspaceName, workspaceNameValue));
            settings.AddSetting(new KeyValuePair <ServiceValidSettings, string>(ServiceValidSettings.DefaultWorkspaceOwner, workspaceOwnerValue));
            settings.AddSetting(new KeyValuePair <ServiceValidSettings, string>(ServiceValidSettings.DefaultOutputBaseFolder, outputFolder));
            settings.AddSetting(new KeyValuePair <ServiceValidSettings, string>(ServiceValidSettings.DefaultRelativeOutputPath, DependencyManagerSettings.Instance.RelativeOutputPath));
            settings.AddSetting(new KeyValuePair <ServiceValidSettings, string>(ServiceValidSettings.DefaultDependencyDefinitionFilename, dependencyDefinitionFileNameList));
            settings.AddSetting(new KeyValuePair <ServiceValidSettings, string>(ServiceValidSettings.BinaryTeamProjectCollectionUrl, DependencyManagerSettings.Instance.BinaryRepositoryTeamProjectCollectionUrl));
            settings.AddSetting(new KeyValuePair <ServiceValidSettings, string>(ServiceValidSettings.BinaryRepositoryTeamProject, DependencyManagerSettings.Instance.BinaryRepositoryTeamProject));

            return(settings);
        }
예제 #25
0
        public static void BranchToFolder(Workspace workspace, IEnumerable <string> items, string folder, VersionSpec versionSpec)
        {
            foreach (var item in items)
            {
                string fileName   = VersionControlPath.GetFileName(item);
                string folderPath = VersionControlPath.Combine(folder, fileName);

                workspace.PendBranch(item, folderPath, versionSpec);
            }
        }
예제 #26
0
        private void backgroundWorker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
        {
            if (BackgroundWorkEnded != null)
            {
                BackgroundWorkEnded(this, EventArgs.Empty);
            }

            if (e.Cancelled)
            {
                return;
            }

            TempItemSet[] itemSets = e.Result as TempItemSet[];
            if (itemSets != null)
            {
                treeView.BeginUpdate();
                TreeNodeServerItem treeNodeServerFolder = null;
                foreach (TempItemSet itemSet in itemSets)
                {
                    if (itemSet.QueryPath != null)
                    {
                        if (treeNodeServerFolder != null && !VersionControlPath.IsSubItem(itemSet.QueryPath, treeNodeServerFolder.ServerItem))
                        {
                            treeNodeServerFolder = null;
                        }
                        TreeNodeServerItem treeNodeServerFolder2;
                        if (TryFindNodeByServerItem(itemSet.QueryPath, treeNodeServerFolder, out treeNodeServerFolder2) && NodeNeedsExpansion(treeNodeServerFolder2))
                        {
                            treeNodeServerFolder2.Nodes.Clear();
                            foreach (ExtendedItem i in itemSet.Items)
                            {
                                AttachTreeNode(treeNodeServerFolder2, i);
                            }
                            if (!treeNodeServerFolder2.IsExpanded && m_navigateToWhenLoaded == null)
                            {
                                treeNodeServerFolder2.Expand();
                            }
                            treeNodeServerFolder = treeNodeServerFolder2;
                        }
                    }
                }
                if (m_navigateToWhenLoaded != null)
                {
                    TreeNodeServerItem treeNodeServerFolder3;
                    TryFindNodeByServerItem(m_navigateToWhenLoaded, null, out treeNodeServerFolder3);
                    if (treeNodeServerFolder3 != null)
                    {
                        treeNodeServerFolder3.EnsureVisible();
                        treeView.SelectedNode = treeNodeServerFolder3;
                    }
                    m_navigateToWhenLoaded = null;
                }
                treeView.EndUpdate();
            }
        }
예제 #27
0
        private void Open_Click(object sender, EventArgs e)
        {
            var name          = VersionControlPath.GetFileName(item.ServerItem);
            var localFileName = Path.GetTempPath();

            localFileName = Path.Combine(localFileName, name);
            item.DownloadFile(localFileName);
            var startInfo = new ProcessStartInfo(localFileName);

            Process.Start(startInfo);
        }
예제 #28
0
 /// <summary>
 /// Check to see if an item is a sub item in cloak list.
 /// </summary>
 /// <param name="item"></param>
 /// <param name="cloakList"></param>
 /// <returns></returns>
 private bool isCloaked(string item, List <string> cloakList)
 {
     foreach (string cloakedPath in cloakList)
     {
         if (VersionControlPath.IsSubItem(item, cloakedPath))
         {
             return(true);
         }
     }
     return(false);
 }
예제 #29
0
        internal static void OpenSolutionWithWorkspace(Workspace workspace, string serverItem, VersionSpec spec)
        {
            serverItem = VersionControlPath.GetFullPath(serverItem);
            WorkingFolder folderForServerItem1;

            try
            {
                folderForServerItem1 = workspace.TryGetWorkingFolderForServerItem(serverItem);
            }
            catch (Exception ex)
            {
                Output.Exception(ex);
                return;
            }
            if (folderForServerItem1 != null)
            {
                if (folderForServerItem1.IsCloaked)
                {
                    int num1 = (int)Error(UIHost.DefaultParentWindow, GuiResources.Format("SolutionIsCloaked", (object)VersionControlPath.GetFileName(serverItem)), string.Empty, MessageBoxButtons.OK, MessageBoxIcon.Hand);
                }
                else
                {
                    try
                    {
                        VssProvider.OpenFromSCC(serverItem, FileSpec.GetDirectoryName(folderForServerItem1.LocalItem), spec.DisplayString, VersionControlOpenFromSccOverwrite.openscc_open_local_version);
                    }
                    catch (Exception ex)
                    {
                        Output.Exception(ex);
                    }
                }
            }
            else
            {
                string folderName = VersionControlPath.GetFolderName(serverItem);
                using (var dialogSetLocalFolder = (Form)TeamControlFactory.CreateDialogSetLocalFolder(workspace, folderName))
                {
                    if (UIHost.ShowModalDialog((Form)dialogSetLocalFolder) != DialogResult.OK)
                    {
                        return;
                    }
                }
                try
                {
                    WorkingFolder folderForServerItem2 = workspace.GetWorkingFolderForServerItem(serverItem);
                    VssProvider.OpenFromSCC(serverItem, FileSpec.GetDirectoryName(folderForServerItem2.LocalItem), spec.DisplayString, VersionControlOpenFromSccOverwrite.openscc_open_local_version);
                }
                catch (Exception ex)
                {
                    Output.Exception(ex);
                }
            }
        }
        /// <summary>
        /// Returns all versions for a component found in the repository.
        /// </summary>
        /// <param name="name">The component name.</param>
        /// <returns>The list of versions</returns>
        public IEnumerable <IComponentVersion> GetAvailableVersions(IComponentName name)
        {
            ValidateComponentName(name);

            Logger.Instance().Log(TraceLevel.Info, "{0}: Querying available component versions...", ResolverType);

            var availableVersions = new List <IComponentVersion>();

            if (VersionControlServer.ServerItemExists(VersionControlPath.Combine(PathPrefix, name.ToString()), VersionSpec.Latest, DeletedState.NonDeleted, ItemType.Folder))
            {
                var versionItems = VersionControlServer.GetItems(VersionControlPath.Combine(VersionControlPath.Combine(PathPrefix, name.ToString()), "*"));

                foreach (var version in versionItems.Items)
                {
                    if (version.ItemType.Equals(ItemType.Folder))
                    {
                        // Check if component.targets exists inside folder
                        var folderItems = VersionControlServer.GetItems(VersionControlPath.Combine(VersionControlPath.Combine(VersionControlPath.Combine(PathPrefix, name.ToString()), VersionControlPath.GetFileName(version.ServerItem)), "*"));
                        var dependencyDefinitionFileFound = false;

                        foreach (var item in folderItems.Items)
                        {
                            var itemName = VersionControlPath.GetFileName(item.ServerItem);

                            foreach (var dependencyDefinitionFileName in ValidDependencyDefinitionFileNames)
                            {
                                if (string.Equals(itemName, dependencyDefinitionFileName, StringComparison.OrdinalIgnoreCase))
                                {
                                    Logger.Instance().Log(TraceLevel.Info, "{0}: Found version {1}", ResolverType, VersionControlPath.GetFileName(version.ServerItem));
                                    availableVersions.Add(new ComponentVersion(VersionControlPath.GetFileName(version.ServerItem)));
                                    dependencyDefinitionFileFound = true;
                                }
                            }
                        }

                        if (!dependencyDefinitionFileFound)
                        {
                            Logger.Instance().Log(TraceLevel.Warning, "{0}: Skipping version {1} (Dependency definition file is not present)", ResolverType, VersionControlPath.GetFileName(version.ServerItem));
                        }
                    }
                }
            }
            else
            {
                Logger.Instance().Log(TraceLevel.Error, "{0}: Directory {1} for component {2} does not exist", ResolverType, VersionControlPath.Combine(PathPrefix, name.ToString()), name);
                throw new InvalidComponentException(string.Format("Could not find component {0} in binary repository", name));
            }

            Logger.Instance().Log(TraceLevel.Info, "{0}: Querying component versions finished successfully", ResolverType);

            return(availableVersions);
        }
 public bool HasItem(VersionControlPath serverPath)
 {
     return cachedItems.Any(c => c.ServerPath == serverPath);
 }
 public ExtendedItem GetItem(VersionControlPath serverPath)
 {
     return cachedItems.Single(c => c.ServerPath == serverPath);
 }
 private void ShowMappingPath(VersionControlPath serverPath)
 {
     if (!IsMapped(serverPath))
     {
         _localFolder.Text = GettextCatalog.GetString("Not Mapped");
         return;
     }
     var mappedFolder = _currentWorkspace.Folders.First(f => serverPath.IsChildOrEqualTo(f.ServerItem));
     if (string.Equals(serverPath, mappedFolder.ServerItem, StringComparison.Ordinal))
         _localFolder.Text = mappedFolder.LocalItem;
     else
     {
         string rest = serverPath.ChildPart(mappedFolder.ServerItem);
         _localFolder.Text = Path.Combine(mappedFolder.LocalItem, rest);
     }
 }