Пример #1
0
 private static void CopyQueryFolder(WorkItemQuery queryFolder,
                                     string sourceProjectName, string sourceTeamName,
                                     string targetProjectName, string targetTeamName)
 {
     WriteLine($"{queryFolder.path}");
     if (!queryFolder.isFolder || queryFolder.children.Length == 0)
     {
         return;
     }
     foreach (var childQueryFolder in queryFolder.children.Where(o => o.isFolder))
     {
         var childQueryFolderObject = TfsStatic.GetWorkItemQuery(true, childQueryFolder.id, QueryExpand.minimal, 1);
         CopyQueryFolder(childQueryFolderObject, sourceProjectName, sourceTeamName, targetProjectName, targetTeamName);
     }
     foreach (var query in queryFolder.children.Where(o => !o.isFolder))
     {
         WriteLine($"\t- {query.name}");
         QueryTools.CopyQuery(new Tools.Parameters.CopyQueryParameters
         {
             QueryId           = query.id,
             QueryReplacements = _config.Queries,
         }, sourceProjectName, sourceTeamName, targetProjectName, targetTeamName);
     }
 }
Пример #2
0
        private static void MigrateDashboard()
        {
            if (string.IsNullOrEmpty(_config.SourceDashboardName))
            {
                WriteLine($"{nameof(AppConfig.SourceDashboardName)} is missing for Dashboard Migration!", ConsoleColor.Red);
                return;
            }
            if (string.IsNullOrEmpty(_config.TargetDashboardName))
            {
                WriteLine($"{nameof(AppConfig.TargetDashboardName)} is missing for Dashboard Migration!", ConsoleColor.Red);
                return;
            }
            if (TargetDashboardExists() && !_config.DeleteTargetDashboardIfExists)
            {
                WriteLine($"Target dashboard '{_config.TargetDashboardName}' in the team '{_config.TargetTeamName}' already exists and DeleteTargetDashboardIfExists=false.", ConsoleColor.Red);
                return;
            }
            var output     = string.Empty;
            var dashboards = TfsStatic.GetDashboards(true, _config.SourceTeamName, _config.SourceAsProject);
            var dashboard  = dashboards.value.FirstOrDefault(o => o.name.Equals(_config.SourceDashboardName));

            if (dashboard == null)
            {
                WriteLine($"Unable to find the dashboard '{_config.SourceDashboardName}' in the team '{_config.SourceTeamName}'.", ConsoleColor.Red);
                return;
            }
            WriteLine($"Source Dashboard: {dashboard.name} ({dashboard.id})");
            WriteLine($"Target Dashboard: {_config.TargetDashboardName}");
            WriteLine($"Source Team Name: {_config.SourceTeamName}");
            WriteLine($"Target Team Name: {_config.TargetTeamName}");
            var dashboardInfo = TfsStatic.GetDashboard(true, _config.SourceTeamName, _config.SourceAsProject, dashboard.id);

            dashboardInfo.name = _config.TargetDashboardName;

            WriteLine($"Widgets: {dashboardInfo.widgets.Length}");
            foreach (var widget in dashboardInfo.widgets)
            {
#if DEBUG
                WriteLine($"[{GetWidgetPositionDisplay(widget)}] {widget.name} | {widget.contributionId}");
#else
                WriteLine($"[{GetWidgetPositionDisplay(widget)}] {widget.name}");
#endif
                try
                {
                    bool processorFound = false;
                    RunMarkdownReplacementsOnName(widget, _config);
                    foreach (var processor in WidgetProcessors)
                    {
                        if (widget.contributionId.Equals(processor.ContributionId, StringComparison.InvariantCultureIgnoreCase))
                        {
                            WriteLine($"\tprocessing");
                            processor.Run(widget, _config);
                            processorFound = true;
                            continue;
                        }
                    }
                    if (!processorFound)
                    {
                        if (_config.NullSettingsWhereNoSupportedProcessorExists)
                        {
                            widget.settings = null;
                        }
                        WriteLine($"No processor for '{widget.contributionId}' found.", ConsoleColor.DarkYellow);
                    }
                }
                catch (Exception ex)
                {
                    WriteFileProgress($"ERROR: {{{_config.TargetTeamName}}}[{GetWidgetPositionDisplay(widget)}] {widget.name} - {ex.Message}");
                }
            }

            WriteLine();
            WriteLine();
            if (_config.UpdateQueriesOnly)
            {
                WriteLine($"Skipping dashboard creation, UpdateQueriesOnly=true.");
                WriteFileProgress($"Skipping dashboard for {_config.TargetTeamName}/{_config.TargetDashboardName}.");
            }
            else
            {
                DeleteDashboardIfExists();
                Write($"Creating dashboard '{_config.TargetDashboardName}' in the team '{_config.TargetTeamName}'...");
                DashboardInfo newDashboardInfo;
                int           tryCount = 0;
                while (true)
                {
                    try
                    {
                        newDashboardInfo = TfsStatic.CreateDashboard(false, _config.TargetTeamName, _config.TargetAsProject, dashboardInfo);
                        break;
                    }
                    catch
                    {
                        tryCount++;
                        if (tryCount >= 5)
                        {
                            WriteFileProgress($"Dashboard creation failed for {_config.TargetTeamName}/{_config.TargetDashboardName}...CreateDashboard");
                            throw;
                        }
                    }
                    Thread.Sleep(2500);
                }
                var teamNameUrl = _config.TargetTeamName.Replace(" ", "%20");
                if (newDashboardInfo.url.IndexOf(teamNameUrl) > -1)
                {
                    var url = newDashboardInfo.url.Remove(newDashboardInfo.url.IndexOf(teamNameUrl), teamNameUrl.Length + 1);
                    url = url.Replace("_apis/Dashboard/Dashboards", "_dashboards/dashboard");
                    WriteLine(url);
                }
                else if (newDashboardInfo.url.IndexOf("/") > -1)
                {
                    WriteLine(newDashboardInfo.url.Remove(0, newDashboardInfo.url.LastIndexOf("/") + 1));
                }
                WriteLine("Done!", ConsoleColor.Green);
            }
        }