コード例 #1
0
ファイル: PlannerService.cs プロジェクト: CSMVS/admin
        public async Task <IEnumerable <Idea> > MoveShareableIdeas()
        {
            var movedIdeas = new List <Idea>();
            var globalTeam = await teamService.GetGlobalTeamAsync();

            LogService.LogInfo($"The global team is: {globalTeam?.DisplayName}.");
            var globalPlan = await GetTeamPlanAsync(globalTeam);

            var globalBucket = await GetShareableBucketAsync(globalPlan);

            if (globalBucket == null)
            {
                LogService.LogInfo("Failed to get the global bucket.");
                return(movedIdeas);
            }

            var nonGlobalTeams = await teamService.GetNonGlobalTeamsAsync();

            foreach (var team in nonGlobalTeams)
            {
                var operation = $"Move shareable ideas in team {team.DisplayName}";
                LogService.LogOperationStarted(operation);
                var plan = await GetTeamPlanAsync(team);

                if (plan != null)
                {
                    var ideas = (await GetIdeasInShareableBucketAsync(plan));
                    foreach (var idea in ideas)
                    {
                        var updatedIdea = await MoveIdea(idea, globalBucket.Id, globalPlan.Id);

                        LogService.LogInfo($"Moved idea {updatedIdea.Title}.");
                        movedIdeas.Add(updatedIdea);
                        if (metricIdeaService != null)
                        {
                            updatedIdea.Url = Idea.GetIdeaUrl(globalTeam.Id, globalPlan.Id, updatedIdea.Id);
                            metricIdeaService.UpdateIdeaInMetricIdeaList(idea, updatedIdea);
                        }
                    }
                }
                else
                {
                    LogService.LogInfo($"Failed to get the plan of the team.");
                }
                LogService.LogOperationEnded(operation);
            }
            return(movedIdeas);
        }
コード例 #2
0
ファイル: MetricIdeaService.cs プロジェクト: CSMVS/admin
        public async Task SyncMetricIdeaList()
        {
            var teamService = new TeamsService();
            var teams       = await teamService.GetJoinedTeamsAsync();

            var plannerService = new PlannerService(teamService);
            var globalTeam     = await teamService.GetGlobalTeamAsync();

            var globalIdeas = globalTeam == null ? new Idea[0] : (await plannerService.GetIdeasInTeamAsync(globalTeam))
                              .OrderBy(idea => idea.Id)
                              .ToArray();

            var allIdeas = new List <Idea>();

            foreach (var team in teams)
            {
                var operation = $"Sync ideas in team {team?.DisplayName}";
                LogService.LogOperationStarted(operation);
                var ideas = await plannerService.GetIdeasInTeamAsync(team);

                allIdeas.AddRange(ideas);
                ideas = ideas.Union(globalIdeas)
                        .OrderBy(s => s.Id);
                var items = GetMetricIdeaItemsByTeamID(team.Id)
                            .OrderBy(item => item[SPLists.MetricIdeas.Columns.TaskId]);
                try
                {
                    SyncIdeasAndListItems(ideas, items);
                }
                catch (Exception ex)
                {
                    LogService.LogError(ex);
                }
                LogService.LogOperationEnded(operation);
            }

            // Sync ideas whose metric is other
            {
                var operation = $"Sync ideas whose metric is other";
                LogService.LogOperationStarted(operation);
                var items   = GetOtherMetricIdeaItems();
                var ideaIds = items.Select(i => i[SPLists.MetricIdeas.Columns.TaskId] as string).ToArray();
                var ideas   = allIdeas.Where(i => ideaIds.Contains(i.Id));
                SyncIdeasAndListItems(ideas, items);
                LogService.LogOperationEnded(operation);
            }
        }