/// <summary>
        /// Saves this collection to database
        /// </summary>
        /// <returns><b>true</b> if save successful, <b>false</b> otherwise</returns>
        public bool Save()
        {
            Database database = Token.Instance.Database;

            //DELETE ANY CATEGORIES THAT APPEAR IN _ORIGVALUE BUT NOT IN CURRENT LIST
            foreach (int categoryId in _OrigValue)
            {
                if (this.IndexOf(categoryId) < 0)
                {
                    using (DbCommand selectCommand = database.GetSqlStringCommand("DELETE FROM ac_CatalogNodes WHERE CategoryId = @categoryId AND CatalogNodeId = @productId AND CatalogNodeTypeId = 1"))
                    {
                        database.AddInParameter(selectCommand, "@categoryId", System.Data.DbType.Int32, categoryId);
                        database.AddInParameter(selectCommand, "@productId", System.Data.DbType.Int32, _ProductId);
                        database.ExecuteNonQuery(selectCommand);
                    }
                }
            }
            //ADD ANY CATEGORIES THAT DO NOT APPEAR IN _ORIGVALUE
            foreach (int categoryId in this)
            {
                if (_OrigValue.IndexOf(categoryId) < 0)
                {
                    CatalogNode node = new CatalogNode();
                    node.CategoryId      = categoryId;
                    node.CatalogNodeId   = _ProductId;
                    node.CatalogNodeType = CommerceBuilder.Catalog.CatalogNodeType.Product;
                    node.OrderBy         = -1;
                    node.Save();
                }
            }
            //UPDATE THE ORIGVALUE WITH THE SAVED LIST
            _OrigValue = new List <int>();
            _OrigValue.AddRange(this);
            return(true);
        }
Exemplo n.º 2
0
        private IList <TestDetailDto> GetTestDetails(
            CatalogNode teamProjectNode,
            ITestManagementService testService,
            IBuildDetail build)
        {
            var tests = new List <TestDetailDto>();

            try
            {
                var testProject = testService.GetTeamProject(teamProjectNode.Resource.DisplayName);
                var testRuns    = testProject.TestRuns.ByBuild(build.Uri);

                foreach (var testRun in testRuns)
                {
                    foreach (var erroringTest in testRun.QueryResults())
                    {
                        tests.Add(new TestDetailDto(erroringTest.TestCaseTitle,
                                                    erroringTest.DateStarted,
                                                    erroringTest.DateCompleted));
                    }
                }
            }
            catch (Exception e)
            {
                LogService.WriteError(e);
                throw;
            }

            return(tests);
        }
Exemplo n.º 3
0
        private HashSet <CatalogNode> GetParentNodes(int catalogId, CatalogNode node)
        {
            var parentNodeIds = new HashSet <int> {
                node.ParentNodeId
            };

            var nodeRelationTable = _catalogSystem.GetCatalogNodeRelations(catalogId);

            foreach (CatalogRelationDto.CatalogNodeRelationRow relationRow in nodeRelationTable.Rows)
            {
                if (relationRow.ChildNodeId.Equals(node.CatalogNodeId))
                {
                    parentNodeIds.Add(relationRow.ParentNodeId);
                }
            }

            var parentNodes = new HashSet <CatalogNode>();

            foreach (var id in parentNodeIds)
            {
                if (id == 0)
                {
                    continue;
                }
                var parentNode = _catalogSystem.GetCatalogNode(id);
                if (parentNode == null)
                {
                    continue;
                }
                parentNodes.Add(parentNode);
            }

            return(parentNodes);
        }
        /// <summary>
        /// Gets the list of project users in a TFS project
        /// </summary>
        /// <param name="projectCollection">TFS PROJECT COLLECTION</param>
        /// <param name="projectName">TFS PROJECT NAME</param>
        /// <returns></returns>
        public static List <TeamFoundationIdentity> ListContributors(TfsTeamProjectCollection tfsTeamProjectCollection, string projectName)
        {
            List <TeamFoundationIdentity> tfsUsers = new List <TeamFoundationIdentity>();
            IIdentityManagementService    ims      = (IIdentityManagementService)tfsTeamProjectCollection.GetService(typeof(IIdentityManagementService));

            // get the tfs project
            ReadOnlyCollection <CatalogNode> projectNodes = tfsTeamProjectCollection.CatalogNode.QueryChildren(new[] { CatalogResourceTypes.TeamProject }, false, CatalogQueryOptions.None);
            CatalogNode projectCatalogNode = projectNodes.FirstOrDefault(c => c.Resource.DisplayName == projectName);

            if (projectCatalogNode != null && ims != null)
            {
                TeamFoundationIdentity[] groups = ims.ListApplicationGroups(projectName, ReadIdentityOptions.None);
                foreach (TeamFoundationIdentity group in groups)
                {
                    TeamFoundationIdentity sids = ims.ReadIdentity(IdentitySearchFactor.DisplayName, group.DisplayName, MembershipQuery.Expanded, ReadIdentityOptions.IncludeReadFromSource);
                    if (sids != null)
                    {
                        tfsUsers.AddRange(ims.ReadIdentities(sids.Members, MembershipQuery.Expanded, ReadIdentityOptions.None));
                    }
                }
            }

            //Remove any duplicates (by user-id)
            return(tfsUsers.GroupBy(u => u.UniqueName).Select(u => u.First()).ToList());
        }
Exemplo n.º 5
0
        public static WorkItemStore GetWorkItemStore(TfsConfigurationServer tfs, CatalogNode teamProjectColCatalog)
        {
            Guid teamProjectCatalogId = new Guid(teamProjectColCatalog.Resource.Properties["InstanceId"]);
            TfsTeamProjectCollection teamProjectCollection = tfs.GetTeamProjectCollection(teamProjectCatalogId);

            return(new WorkItemStore(teamProjectCollection));
        }
Exemplo n.º 6
0
        private static void ListProjects()
        {
            // URI of the team project collection
            string _myUri = @"https://bupa-international.visualstudio.com";

            TfsConfigurationServer configurationServer =
                TfsConfigurationServerFactory.GetConfigurationServer(new Uri(_myUri));

            CatalogNode catalogNode = configurationServer.CatalogNode;

            ReadOnlyCollection <CatalogNode> tpcNodes = catalogNode.QueryChildren(
                new Guid[] { CatalogResourceTypes.ProjectCollection },
                false, CatalogQueryOptions.None);

            // tpc = Team Project Collection
            foreach (CatalogNode tpcNode in tpcNodes)
            {
                Guid tpcId = new Guid(tpcNode.Resource.Properties["InstanceId"]);
                TfsTeamProjectCollection tpc = configurationServer.GetTeamProjectCollection(tpcId);

                // Get catalog of tp = 'Team Projects' for the tpc = 'Team Project Collection'
                var tpNodes = tpcNode.QueryChildren(
                    new Guid[] { CatalogResourceTypes.TeamProject },
                    false, CatalogQueryOptions.None);

                foreach (var p in tpNodes)
                {
                    Debug.Write(Environment.NewLine + " Team Project : " + p.Resource.DisplayName + " - " + p.Resource.Description + Environment.NewLine);
                }
            }
        }
Exemplo n.º 7
0
        private TimeSpan GetLastSuccesfulBuildTime(IBuildServer buildServer, CatalogNode teamProjectNode,
                                                   IBuildDefinition def)
        {
            var buildTime = new TimeSpan();

            try
            {
                var inProgressBuildDetailSpec = buildServer.CreateBuildDetailSpec(teamProjectNode.Resource.DisplayName, def.Name);

                inProgressBuildDetailSpec.Status = BuildStatus.Succeeded;
                inProgressBuildDetailSpec.MaxBuildsPerDefinition = 1;
                inProgressBuildDetailSpec.QueryOrder             = BuildQueryOrder.FinishTimeDescending;

                var lastSuccesfulBuild = buildServer.QueryBuilds(inProgressBuildDetailSpec).Builds.FirstOrDefault();

                if (lastSuccesfulBuild != null)
                {
                    buildTime = lastSuccesfulBuild.FinishTime - lastSuccesfulBuild.StartTime;
                }
            }
            catch (Exception e)
            {
                LogService.WriteError(e);
                throw;
            }
            return(buildTime);
        }
Exemplo n.º 8
0
        /// <summary>
        /// Creates the site map node.
        /// </summary>
        /// <param name="row">The row.</param>
        /// <returns></returns>
        private SiteMapNode CreateSiteMapNode(CatalogNode node)
        {
            string url  = String.Empty;
            string name = String.Empty;
            string key  = String.Empty;

            string uri = String.Empty;

            if (node.SeoInfo != null && node.SeoInfo.Length > 0)
            {
                foreach (Seo seo in node.SeoInfo)
                {
                    if (seo.LanguageCode.Equals(CMSContext.Current.LanguageName, StringComparison.InvariantCultureIgnoreCase))
                    {
                        url = "~/" + seo.Uri;
                        break;
                    }
                }
            }

            name = StoreHelper.GetNodeDisplayName(node);
            key  = "c_" + node.CatalogNodeId + "_" + node.ParentNodeId + "_" + node.CatalogId;

            if (String.IsNullOrEmpty(url))
            {
                url = NavigationManager.GetUrl("NodeView", "nc", node.ID);
            }

            SiteMapNode newNode = new SiteMapNode(this, key, MakeUrlAbsolute(url), name);

            return(newNode);
        }
 public MyTfsProjectCollection(MyTfsServer myTfsServer, CatalogNode teamProjectCollectionNode)
 {
     try
     {
         _myTfsServer = myTfsServer;
         Name         = teamProjectCollectionNode.Resource.DisplayName;
         ServiceDefinition tpcServiceDefinition = teamProjectCollectionNode.Resource.ServiceReferences["Location"];
         var configLocationService = myTfsServer.GetConfigLocationService();
         var tpcUri = new Uri(configLocationService.LocationForCurrentConnection(tpcServiceDefinition));
         _tfsTeamProjectCollection = TfsTeamProjectCollectionFactory.GetTeamProjectCollection(tpcUri);
         _commonStructureService   = _tfsTeamProjectCollection.GetService <ICommonStructureService>();
         _buildServer = _tfsTeamProjectCollection.GetService <IBuildServer>();
         _tswaClientHyperlinkService = _tfsTeamProjectCollection.GetService <TswaClientHyperlinkService>();
         CurrentUserHasAccess        = true;
     }
     catch (TeamFoundationServiceUnavailableException ex)
     {
         _log.Debug("Can't access " + Name + ". This could be because the project collection is currently offline.", ex);
         CurrentUserHasAccess = false;
     }
     catch (TeamFoundationServerUnauthorizedException ex)
     {
         _log.Debug("Unauthorized access to " + teamProjectCollectionNode, ex);
         CurrentUserHasAccess = false;
     }
 }
Exemplo n.º 10
0
        public static TfsTeamProjectCollection Get_TeamProjectCollection(
            TfsConfigurationServer configurationServer,
            CatalogNode teamProjectCollectionNode)
        {
            Int64 startTicks = Log.DOMAINSERVICES("Enter", Common.LOG_APPNAME);

            Guid collectionId = new Guid(teamProjectCollectionNode.Resource.Properties["InstanceId"]);

            TfsTeamProjectCollection teamProjectCollection;

            try
            {
                teamProjectCollection = configurationServer.GetTeamProjectCollection(collectionId);
            }
            catch (TimeoutException)
            {
                throw;
            }
            catch
            {
                throw;
            }

            Log.DOMAINSERVICES("Exit", Common.LOG_APPNAME, startTicks);

            return(teamProjectCollection);
        }
Exemplo n.º 11
0
    public IEnumerable <ITreeNode> GetChildren(bool refresh)
    {
        ITreeNode[] treeNodes;

        try
        {
            var dataTable  = connection.GetOleDbSchemaTable(OleDbSchemaGuid.Catalogs, null);
            var count      = dataTable.Rows.Count;
            var nameColumn = dataTable.Columns["CATALOG_NAME"];
            treeNodes = new ITreeNode[count];

            for (var i = 0; i < count; i++)
            {
                var name = (string)dataTable.Rows[i][nameColumn];
                treeNodes[i] = new CatalogNode(connection, name);
            }
        }
        catch
        {
            treeNodes    = new ITreeNode[1];
            treeNodes[0] = new CatalogNode(connection, null);
        }

        return(treeNodes);
    }
Exemplo n.º 12
0
        /// <summary>
        /// Gets the catalog node. Results are cached.
        /// </summary>
        /// <param name="uri">The URI.</param>
        /// <param name="languageCode">The language code.</param>
        /// <param name="responseGroup">The response group.</param>
        /// <returns></returns>
        internal static CatalogNode GetCatalogNode(string uri, string languageCode, CatalogNodeResponseGroup responseGroup)
        {
            // Assign new cache key, specific for site guid and response groups requested
            string cacheKey = CatalogCache.CreateCacheKey("catalognode-objects-uri", responseGroup.CacheKey, uri, languageCode);

            CatalogNode node = null;

            // check cache first
            object cachedObject = CatalogCache.Get(cacheKey);

            if (cachedObject != null)
            {
                node = (CatalogNode)cachedObject;
            }

            // Load the object
            if (node == null)
            {
                CatalogNodeDto dto = GetCatalogNodeDto(uri, languageCode, responseGroup);

                // Load node
                if (dto.CatalogNode.Count > 0)
                {
                    node = LoadNode(dto.CatalogNode[0], false, responseGroup);
                }
                else
                {
                    node = new CatalogNode();
                }

                CatalogCache.Insert(cacheKey, node, CatalogConfiguration.Instance.Cache.CatalogNodeTimeout);
            }

            return(node);
        }
Exemplo n.º 13
0
 public MyTfsProjectCollection(CatalogNode teamProjectCollectionNode, TfsConfigurationServer tfsConfigurationServer, NetworkCredential networkCredential)
 {
     try
     {
         Name = teamProjectCollectionNode.Resource.DisplayName;
         ServiceDefinition tpcServiceDefinition = teamProjectCollectionNode.Resource.ServiceReferences["Location"];
         var configLocationService = tfsConfigurationServer.GetService<ILocationService>();
         var tpcUri = new Uri(configLocationService.LocationForCurrentConnection(tpcServiceDefinition));
         _tfsTeamProjectCollection = TfsTeamProjectCollectionFactory.GetTeamProjectCollection(tpcUri, new MyCredentials(networkCredential));
         _commonStructureService = _tfsTeamProjectCollection.GetService<ICommonStructureService>();
         _buildServer = _tfsTeamProjectCollection.GetService<IBuildServer>();
         _tswaClientHyperlinkService = _tfsTeamProjectCollection.GetService<TswaClientHyperlinkService>();
         CurrentUserHasAccess = true;
     }
     catch (TeamFoundationServiceUnavailableException ex)
     {
         _log.Debug("Can't access " + Name + ". This could be because the project collection is currently offline.", ex);
         CurrentUserHasAccess = false;
     }
     catch (TeamFoundationServerUnauthorizedException ex)
     {
         _log.Debug("Unauthorized access to " + teamProjectCollectionNode, ex);
         CurrentUserHasAccess = false;
     }
 }
Exemplo n.º 14
0
        public void createCatalogOfProjects(CatalogNode collectionNode)
        {
            ReadOnlyCollection <CatalogNode> projectNodes = collectionNode.QueryChildren(
                new[] { CatalogResourceTypes.TeamProject },
                false, CatalogQueryOptions.None);

            _projectNodes = projectNodes;
        }
Exemplo n.º 15
0
 public static string GetAssetUrl(CatalogNode node)
 {
     if (node.Assets != null)
     {
         var assetKey = node.Assets.OrderBy(a => a.SortOrder).FirstOrDefault().AssetKey;
         return(GetVirtualPath(assetKey));
     }
     return(DefaultUrl);
 }
Exemplo n.º 16
0
 public static string GetAssetUrl(CatalogNode node)
 {
     if (node.Assets != null)
     {
         var assetKey = node.Assets.OrderBy(a => a.SortOrder).FirstOrDefault().AssetKey;
         return GetVirtualPath(assetKey);
     }
     return DefaultUrl;
 }
Exemplo n.º 17
0
        private IEnumerable<BuildInfoDto> GetBuildInfoDtosPerBuildDefinition(List<IBuildDefinition> buildDefinitionList,
            IBuildServer buildServer, CatalogNode teamProjectNode,
            TfsTeamProjectCollection teamProjectCollection, ITestManagementService testService, DateTime filterDate)
        {
            var buildDtos = new List<BuildInfoDto>();
            try
            {
                Parallel.ForEach(buildDefinitionList, def =>
                {
                    var build = GetBuild(buildServer, teamProjectNode, def, filterDate);

                    if (build == null) return;

                    var buildInfoDto = new BuildInfoDto
                    {
                        Builddefinition = def.Name,
                        FinishBuildDateTime = build.FinishTime,
                        LastBuildTime = new TimeSpan(),
                        PassedNumberOfTests = 0,
                        RequestedByName = build.RequestedFor,
                        RequestedByPictureUrl = "",
                        StartBuildDateTime = build.StartTime,
                        Status = Char.ToLowerInvariant(build.Status.ToString()[0]) + build.Status.ToString().Substring(1),
                        TeamProject = teamProjectNode.Resource.DisplayName,
                        TeamProjectCollection = teamProjectCollection.Name,
                        TotalNumberOfTests = 0,
                        Id = "TFS" + teamProjectNode.Resource.Identifier + def.Id,
                        BuildReportUrl = _helperClass.GetReportUrl(teamProjectCollection.Uri.ToString(), teamProjectNode.Resource.DisplayName, build.Uri.OriginalString)
                    };
                    //Retrieve testruns
                    var testResults = GetTestResults(teamProjectNode, testService, build);

                    if (testResults.ContainsKey("PassedTests"))
                    {
                        buildInfoDto.PassedNumberOfTests = testResults["PassedTests"];
                        buildInfoDto.TotalNumberOfTests = testResults["TotalTests"];
                    }
                    //Add last succeeded build if in progress
                    if (build.Status == BuildStatus.InProgress)
                    {
                        buildInfoDto.LastBuildTime = GetLastSuccesfulBuildTime(buildServer, teamProjectNode, def);
                    }
                    lock (buildDtos)
                    {
                        buildDtos.Add(buildInfoDto);
                    }
                });
            }
            catch (Exception e)
            {
                LogService.WriteError(e);
                throw;
            }

            return buildDtos;
        }
        protected Category GetCategory(Object dataItem)
        {
            CatalogNode node = (CatalogNode)dataItem;

            if (node.CatalogNodeType == CatalogNodeType.Category)
            {
                return((Category)node.ChildObject);
            }
            return(null);
        }
        protected string GetCategoryUrl(Object dateItem)
        {
            CatalogNode node = (CatalogNode)dateItem;

            if (node.CatalogNodeType == CatalogNodeType.Category)
            {
                return((string)node.NavigateUrl);
            }
            return(null);
        }
        protected Webpage GetWebpage(Object dataItem)
        {
            CatalogNode node = (CatalogNode)dataItem;

            if (node.CatalogNodeType == CatalogNodeType.Webpage)
            {
                return((Webpage)node.ChildObject);
            }
            return(null);
        }
        protected Product GetProduct(Object dataItem)
        {
            CatalogNode node = (CatalogNode)dataItem;

            if (node.CatalogNodeType == CatalogNodeType.Product)
            {
                return((Product)node.ChildObject);
            }
            return(null);
        }
        protected Link GetLink(Object dataItem)
        {
            CatalogNode node = (CatalogNode)dataItem;

            if (node.CatalogNodeType == CatalogNodeType.Link)
            {
                return((Link)node.ChildObject);
            }
            return(null);
        }
Exemplo n.º 23
0
 /// <summary>
 /// Gets the display name.
 /// </summary>
 /// <param name="node">The node.</param>
 /// <returns>The display name of the node</returns>
 public static string GetDisplayName(this CatalogNode node)
 {
     if (node == null || node.ItemAttributes == null)
     {
         return(string.Empty);
     }
     return(WebStringHelper.EncodeForWebString((node.ItemAttributes["DisplayName"] != null && !string.IsNullOrEmpty(node.ItemAttributes["DisplayName"].ToString())) ?
                                               node.ItemAttributes["DisplayName"].ToString() :
                                               node.Name));
 }
Exemplo n.º 24
0
 public IEnumerable <CollectionModel> GetCollections()
 {
     using (var server = GetServer())
     {
         CatalogNode configurationServerNode           = server.CatalogNode;
         IReadOnlyCollection <CatalogNode> collections = configurationServerNode.QueryChildren(
             new[] { CatalogResourceTypes.ProjectCollection },
             false, CatalogQueryOptions.None);
         return(Map(collections));
     }
 }
Exemplo n.º 25
0
        public static string GetLastSuccededDropLocation(string projName, string buildDefinitionName)
        {
            projName = GetProjectName(projName);
            var cred = new NetworkCredential("SERVICE_ACCOUNT_NAME", "SERVICE_ACCOUNT_PASSWORD", "SERVICE_ACCOUNT_DOMAIN");

            var configurationServerUri = new Uri("TFS_URL_TILL_COLLECTION");
            TfsConfigurationServer configurationServer =
                TfsConfigurationServerFactory.GetConfigurationServer(configurationServerUri);

            CatalogNode configurationServerNode = configurationServer.CatalogNode;

            // Query the children of the configuration server node for all of the team project collection nodes
            ReadOnlyCollection <CatalogNode> tpcNodes = configurationServerNode.QueryChildren(
                new Guid[] { CatalogResourceTypes.ProjectCollection },
                false,
                CatalogQueryOptions.None);

            foreach (CatalogNode tpcNode in tpcNodes)
            {
                ServiceDefinition tpcServiceDefinition = tpcNode.Resource.ServiceReferences["Location"];

                ILocationService configLocationService = configurationServer.GetService <ILocationService>();
                Uri tpcUri = new Uri(configLocationService.LocationForCurrentConnection(tpcServiceDefinition));

                // Actually connect to the team project collection
                TfsTeamProjectCollection   tpc  = TfsTeamProjectCollectionFactory.GetTeamProjectCollection(tpcUri);
                ITestManagementService     tms  = tpc.GetService <ITestManagementService>();
                ITestManagementTeamProject proj = tms.GetTeamProject(projName);
                IBuildServer tfsBuildServer     = tpc.GetService <IBuildServer>();
                // Reading from XML
                try
                {
                    IBuildServer buildServer = (IBuildServer)tpc.GetService(typeof(IBuildServer));
                    //Specify query
                    IBuildDetailSpec spec = buildServer.CreateBuildDetailSpec(projName.Trim(), buildDefinitionName.Trim());
                    spec.InformationTypes = null;                                // for speed improvement
                    spec.QueryOrder       = BuildQueryOrder.FinishTimeAscending; //get the latest build only
                    spec.QueryOptions     = QueryOptions.All;

                    IBuildDetail bDetail = buildServer.QueryBuilds(spec).Builds.OrderBy(x => x.CompilationStatus == BuildPhaseStatus.Succeeded).Last();
                    LatestTestBuild = bDetail.DropLocation;
                    LoggerUtil.LogMessageToFile("The ip resolve");
                    IPAddress ip   = null;
                    string    arr2 = LatestTestBuild.Split('\\')[2];
                    Network.GetResolvedConnecionIPAddress(LatestTestBuild.Split('\\')[2], out ip);
                    string temp = string.Join(@"\", LatestTestBuild.Split('\\').Select(s => s.Replace(arr2, ip.ToString())).ToArray());
                    LatestTestBuild = temp;
                    LoggerUtil.LogMessageToFile(LatestTestBuild);
                    break;
                }
                catch { }
            }
            return(LatestTestBuild);
        }
 public static string GetAssetUrl(CatalogNode node)
 {
     if (node.Assets != null)
     {
         var asset = node.Assets.OrderBy(a => a.SortOrder).FirstOrDefault();
         if (asset != null)
         {
             return GetAssetUrl(asset.AssetKey);
         }
     }
     return DefaultUrl;
 }
        /// <summary>
        /// Gets the node URL.
        /// </summary>
        /// <param name="node">The node.</param>
        /// <returns></returns>
        public static string GetNodeUrl(CatalogNode node)
        {
            string url = String.Empty;
            Seo    seo = GetLanguageSeo(node.SeoInfo);

            if (seo != null)
            {
                url = "~/" + seo.Uri;
            }

            return(url);
        }
Exemplo n.º 28
0
 /// <summary>
 /// Recalculates the order by for child product objects
 /// </summary>
 private void RecalculateOrderBy(CatalogNode node)
 {
     if (node.CatalogNodeType == CatalogNodeType.Product)
     {
         Product tempProduct = node.ChildObject as Product;
         if (tempProduct != null)
         {
             tempProduct.RecalculateOrderBy();
             tempProduct.Save();
         }
     }
 }
Exemplo n.º 29
0
 public static string GetAssetUrl(CatalogNode node)
 {
     if (node.Assets != null)
     {
         var asset = node.Assets.OrderBy(a => a.SortOrder).FirstOrDefault();
         if (asset != null)
         {
             return(GetAssetUrl(asset.AssetKey));
         }
     }
     return(DefaultUrl);
 }
Exemplo n.º 30
0
        /// <summary>
        /// Creates the catalog node.
        /// </summary>
        /// <param name="dto">The dto.</param>
        /// <returns></returns>
        internal static CatalogNode CreateCatalogNode(CatalogNodeDto dto)
        {
            CatalogNode node = new CatalogNode();

            foreach (CatalogNodeDto.CatalogNodeRow row in dto.CatalogNode)
            {
                node.Name = row.Name;
                //node.NodeId = row.CatalogNodeId;
            }

            return(node);
        }
        /// <summary>
        /// Get the reporting server definitions contained in the child nodes of the catalog
        /// </summary>
        /// <param name="organizationalCatalog">the catalog to browse</param>
        /// <returns>the reporting server defintions</returns>
        /// <remarks>
        /// the reporting server definition are server-level data
        /// </remarks>
        public static ICollection <ReportingServerDefinition> GetReportingServers(CatalogNode organizationalCatalog)
        {
            ReadOnlyCollection <CatalogNode>        reportingServerNode = organizationalCatalog.QueryChildren(new[] { CatalogResourceTypes.ReportingServer }, false, CatalogQueryOptions.None);
            ICollection <ReportingServerDefinition> collection          = new List <ReportingServerDefinition>();

            foreach (CatalogNode item in reportingServerNode)
            {
                ReportingServerDefinition definition = new ReportingServerDefinition();
                definition.Name = item.Resource.DisplayName;
                collection.Add(definition);
            }
            return(collection);
        }
        /// <summary>
        /// Get the test environment definitions contained in the child nodes of the Catalog
        /// </summary>
        /// <param name="organizationalCatalog">The catalog to browse</param>
        /// <returns>a collection of test environment definitions</returns>
        /// <remarks>
        /// test environment definitions are collection-level data
        /// </remarks>
        public static ICollection <TestEnvironmentDefinition> GetTestEnvironments(CatalogNode organizationalCatalog)
        {
            ReadOnlyCollection <CatalogNode>        testEnvironmentNode = organizationalCatalog.QueryChildren(new[] { CatalogResourceTypes.TestEnvironment }, false, CatalogQueryOptions.None);
            ICollection <TestEnvironmentDefinition> collection          = new List <TestEnvironmentDefinition>();

            foreach (CatalogNode item in testEnvironmentNode)
            {
                TestEnvironmentDefinition definition = new TestEnvironmentDefinition();
                definition.Name = item.Resource.DisplayName;
                collection.Add(definition);
            }
            return(collection);
        }
Exemplo n.º 33
0
        internal static CatalogNodeWrapper GetInstance()
        {
            CatalogNode real = default(CatalogNode);

            RealInstanceFactory(ref real);
            var instance = (CatalogNodeWrapper)CatalogNodeWrapper.GetWrapper(real);

            InstanceFactory(ref instance);
            if (instance == null)
            {
                Assert.Inconclusive("Could not Create Test Instance");
            }
            return(instance);
        }
Exemplo n.º 34
0
        void DoStuffForSpecificCatalog(TfsConfigurationServer configurationServer,CatalogNode collectionNode)
        {
            // Use the InstanceId property to get the team project collection
            Guid collectionId = new Guid(collectionNode.Resource.Properties["InstanceId"]);
            TfsTeamProjectCollection teamProjectCollection = configurationServer.GetTeamProjectCollection(collectionId);
            GetChangesets(teamProjectCollection);
            // Print the name of the team project collection
            Console.WriteLine("Collection: " + teamProjectCollection.Name);

            // Get a catalog of team projects for the collection
            ReadOnlyCollection<CatalogNode> projectNodes = collectionNode.QueryChildren(
                new[] { CatalogResourceTypes.TeamProject },
                false, CatalogQueryOptions.None);

            // List the team projects in the collection
            foreach (CatalogNode projectNode in projectNodes)
            {
                Console.WriteLine(" Team Project: " + projectNode.Resource.DisplayName);
            }
        }
Exemplo n.º 35
0
        private IEnumerable<BuildInfoDto> GetBuildInfoDtosPerTeamProject(CatalogNode teamProjectCollectionNode,
            TfsConfigurationServer tfsServer, DateTime filterDate)
        {
            var buildInfoDtos = new List<BuildInfoDto>();
            try
            {
                // Use the InstanceId property to get the team project collection
                var collectionId = new Guid(teamProjectCollectionNode.Resource.Properties["InstanceId"]);
                var teamProjectCollection = tfsServer.GetTeamProjectCollection(collectionId);

                var buildServer = (IBuildServer)teamProjectCollection.GetService(typeof(IBuildServer));
                var testService = teamProjectCollection.GetService<ITestManagementService>();

                // Get a catalog of team projects for the collection
                var teamProjectNodes = teamProjectCollectionNode.QueryChildren(
                    new[] { CatalogResourceTypes.TeamProject },
                    false, CatalogQueryOptions.None);

                // List the team projects in the collection
                Parallel.ForEach(teamProjectNodes, teamProjectNode =>
                {
                    var buildDefinitionList =
                        new List<IBuildDefinition>(buildServer.QueryBuildDefinitions(teamProjectNode.Resource.DisplayName));
                    lock (buildInfoDtos)
                    {
                        buildInfoDtos.AddRange(GetBuildInfoDtosPerBuildDefinition(buildDefinitionList, buildServer,
                            teamProjectNode,
                            teamProjectCollection, testService, filterDate));
                    }
                });
            }
            catch (Exception e)
            {
                LogService.WriteError(e);
                throw;
            }


            return buildInfoDtos;
        }
Exemplo n.º 36
0
        private IEnumerable<BuildInfoDto> GetBuildInfoDtosPerBuildDefinition(List<IBuildDefinition> buildDefinitionList,
            IBuildServer buildServer, CatalogNode teamProjectNode,
            TfsTeamProjectCollection teamProjectCollection, ITestManagementService testService, DateTime filterDate)
        {
            var buildDtos = new List<BuildInfoDto>();
            try
            {
                Parallel.ForEach(buildDefinitionList, def =>
                {
                    var build = GetBuild(buildServer, teamProjectNode, def, filterDate);

                    if (build == null) return;

                    var buildInfoDto = new BuildInfoDto
                    {
                        Builddefinition = def.Name,
                        FinishBuildDateTime = build.FinishTime,
                        LastBuildTime = new TimeSpan(),
                        PassedNumberOfTests = 0,
                        RequestedByName = build.RequestedFor,
                        RequestedByPictureUrl = "",
                        StartBuildDateTime = build.StartTime,
                        Status = Char.ToLowerInvariant(build.Status.ToString()[0]) + build.Status.ToString().Substring(1),
                        TeamProject = teamProjectNode.Resource.DisplayName,
                        TeamProjectCollection = teamProjectCollection.Name,
                        TotalNumberOfTests = 0,
                        Id = "TFS" + teamProjectNode.Resource.Identifier + def.Id,
                        BuildReportUrl = _helperClass.GetReportUrl(teamProjectCollection.Uri.ToString(), teamProjectNode.Resource.DisplayName, build.Uri.OriginalString)
                    };
                    //Retrieve testruns
                    var testResults = GetTestResults(teamProjectNode, testService, build);

                    if (testResults.ContainsKey("PassedTests"))
                    {
                        buildInfoDto.PassedNumberOfTests = testResults["PassedTests"];
                        buildInfoDto.TotalNumberOfTests = testResults["TotalTests"];
                    }
                    //Add last succeeded build if in progress
                    if (build.Status == BuildStatus.InProgress)
                    {
                        buildInfoDto.LastBuildTime = GetLastSuccesfulBuildTime(buildServer, teamProjectNode, def);
                    }
                    lock (buildDtos)
                    {
                        buildDtos.Add(buildInfoDto);
                    }
                });
            }
            catch (Exception e)
            {
                LogService.WriteError(e);
                throw;
            }

            return buildDtos;
        }
Exemplo n.º 37
0
 private static Guid GetCollectionGuid(CatalogNode node)
 {
     return new Guid(node.Resource.Properties["InstanceId"]);
 }
        public void createCatalogOfProjects(CatalogNode collectionNode)
        {
            ReadOnlyCollection<CatalogNode> projectNodes = collectionNode.QueryChildren(
                          new[] { CatalogResourceTypes.TeamProject },
                          false, CatalogQueryOptions.None);

            _projectNodes = projectNodes;
        }
 public Guid guidCollectionId(CatalogNode collectionNode)
 {
     Guid collectionId = new Guid(collectionNode.Resource.Properties["InstanceId"]);
     return collectionId;
 }
Exemplo n.º 40
0
        private TfsTeamProjectCollection GetTeamProjectCollection(CatalogNode node)
        {
            foreach (TfsTeamProjectCollection projectCollection in _TeamProjectCollections.Where(x => x.CatalogNode.Resource.DisplayName == node.Resource.DisplayName))
            {
                return projectCollection;
            }

            Guid collectionId = GetCollectionGuid(node);
            var collection = _Server.GetTeamProjectCollection(collectionId);
            _TeamProjectCollections.Add(collection);

            return collection;
        }
Exemplo n.º 41
0
        private Dictionary<String, int> GetTestResults(CatalogNode teamProjectNode, ITestManagementService testService,
            IBuildDetail build)
        {
            var testResults = new Dictionary<string, int>();
            try
            {
                var testProject = testService.GetTeamProject(teamProjectNode.Resource.DisplayName);

                int passedTests = 0;
                int totalTests = 0;
                bool addTestResults = false;
                foreach (var testRun in testProject.TestRuns.ByBuild(build.Uri).ToList())
                {

                    if (testRun != null)
                    {
                        passedTests += testRun.PassedTests;
                        totalTests += testRun.TotalTests;
                        addTestResults = true;
                    }
                }

                if (addTestResults)
                {
                    testResults.Add("PassedTests", passedTests);
                    testResults.Add("TotalTests", totalTests);
                }

                //var testRun = testProject.TestRuns.ByBuild(build.Uri);

                //if (testRun != null)
                //{
                //    testResults.Add("PassedTests", testRun.PassedTests);
                //    testResults.Add("TotalTests", testRun.TotalTests);
                //}
            }
            catch (Exception e)
            {
                LogService.WriteError(e);
                throw;
            }
            return testResults;
        }
 /// <summary>
 /// Initializes a new <see cref="CatalogNodeWrapper"/>.
 /// </summary>
 /// <param name="node">The wrapped node</param>
 public CatalogNodeWrapper(CatalogNode node)
 {
     _node = node;
 }
 public static WorkItemStore GetWorkItemStore(TfsConfigurationServer tfs, CatalogNode teamProjectColCatalog)
 {
     Guid teamProjectCatalogId = new Guid(teamProjectColCatalog.Resource.Properties["InstanceId"]);
     TfsTeamProjectCollection teamProjectCollection = tfs.GetTeamProjectCollection(teamProjectCatalogId);
     return new WorkItemStore(teamProjectCollection);
 }
Exemplo n.º 44
0
        private TimeSpan GetLastSuccesfulBuildTime(IBuildServer buildServer, CatalogNode teamProjectNode,
            IBuildDefinition def)
        {
            var buildTime = new TimeSpan();
            try
            {
                var inProgressBuildDetailSpec = buildServer.CreateBuildDetailSpec(teamProjectNode.Resource.DisplayName, def.Name);

                inProgressBuildDetailSpec.Status = BuildStatus.Succeeded;
                inProgressBuildDetailSpec.MaxBuildsPerDefinition = 1;
                inProgressBuildDetailSpec.QueryOrder = BuildQueryOrder.FinishTimeDescending;

                var lastSuccesfulBuild = buildServer.QueryBuilds(inProgressBuildDetailSpec).Builds.FirstOrDefault();

                if (lastSuccesfulBuild != null)
                {
                    buildTime = lastSuccesfulBuild.FinishTime - lastSuccesfulBuild.StartTime;
                }
            }
            catch (Exception e)
            {
                LogService.WriteError(e);
                throw;
            }
            return buildTime;
        }
Exemplo n.º 45
0
        private Dictionary<String, int> GetTestResults(CatalogNode teamProjectNode, ITestManagementService testService,
            IBuildDetail build)
        {
            var testResults = new Dictionary<string, int>();
            try
            {
                var testProject = testService.GetTeamProject(teamProjectNode.Resource.DisplayName);
                var testRun = testProject.TestRuns.ByBuild(build.Uri).FirstOrDefault();

                if (testRun != null)
                {
                    testResults.Add("PassedTests", testRun.PassedTests);
                    testResults.Add("TotalTests", testRun.TotalTests);
                }
            }
            catch (Exception e)
            {
                LogService.WriteError(e);
                throw;
            }
            return testResults;
        }
Exemplo n.º 46
0
        private async Task<List<BuildInfoDto>>  GetBuildInfoDtosPerTeamProject(CatalogNode teamProjectCollectionNode,
            TfsConfigurationServer tfsServer, DateTime filterDate)
        {
            var buildInfoDtos = new List<BuildInfoDto>();
            try
            {
                // Use the InstanceId property to get the team project collection
                var collectionId = new Guid(teamProjectCollectionNode.Resource.Properties["InstanceId"]);
                var teamProjectCollection = tfsServer.GetTeamProjectCollection(collectionId);

                var buildServer = (IBuildServer)teamProjectCollection.GetService(typeof(IBuildServer));
                var testService = teamProjectCollection.GetService<ITestManagementService>();



                // Get a catalog of team projects for the collection


                if (tfsServer.ServerDataProvider.ServerVersion == null)
                {


                    var teamProjectNodes = teamProjectCollectionNode.QueryChildren(new[] {CatalogResourceTypes.TeamProject}, false, CatalogQueryOptions.None);

                    // List the team projects in the collection
                    Parallel.ForEach(teamProjectNodes, teamProjectNode =>
                    {
                        var buildDefinitionList = buildServer.QueryBuildDefinitions(teamProjectNode.Resource.DisplayName).ToList();

                        lock (buildInfoDtos)
                        {
                            buildInfoDtos.AddRange(GetBuildInfoDtosPerBuildDefinition(buildDefinitionList, buildServer, teamProjectNode, teamProjectCollection, testService, filterDate));
                        }
                    });
                }
                else
                {
                    var commonStructureService = teamProjectCollection.GetService<ICommonStructureService>();
                    var httpClient = teamProjectCollection.GetClient<BuildHttpClient>();
                    var listAllProjects = commonStructureService.ListAllProjects().ToList();
                    foreach (var project in listAllProjects)
                    {
                        var definitionReferences = await httpClient.GetDefinitionsAsync(project: project.Name).ConfigureAwait(false);
                        
                        var buildInfos = await GetBuildInfoDtosPerBuildDefinitionRest(teamProjectCollection, definitionReferences, httpClient);
                        lock (buildInfoDtos)
                        {
                            buildInfoDtos.AddRange(buildInfos);
                        }
                    }
                }
            }
            catch (Exception e)
            {
                LogService.WriteError(e);
                throw;
            }


            return await Task.FromResult(buildInfoDtos);
        }
Exemplo n.º 47
0
        private IBuildDetail GetBuild(IBuildServer buildServer, CatalogNode teamProjectNode, IBuildDefinition def, DateTime filterDate)
        {
            IBuildDetail build = null;
            try
            {
                var buildDetailSpec = buildServer.CreateBuildDetailSpec(teamProjectNode.Resource.DisplayName, def.Name);

                buildDetailSpec.MaxBuildsPerDefinition = 1;
                buildDetailSpec.QueryOrder = BuildQueryOrder.FinishTimeDescending;
                buildDetailSpec.MinFinishTime = filterDate;

                build = buildServer.QueryBuilds(buildDetailSpec).Builds.FirstOrDefault();
            }
            catch (Exception e)
            {
                LogService.WriteError(e);
                throw;
            }
            return build;
        }