Пример #1
0
        public async Task ReApplyTokens(PlanDTO plan)
        {
            var planMTSF = plan.SubPlans.FirstOrDefault();

            if (planMTSF != null)
            {
                var googleActivity = planMTSF.Activities.FirstOrDefault();
                if (googleActivity != null)
                {
                    var curentGToken = googleTokens.AuthTokens.Where(t => t.Id == googleActivity.AuthTokenId).FirstOrDefault();
                    if (curentGToken == null)
                    {
                        var gToken = googleTokens.AuthTokens.Where(t => t.ExternalAccountName == "*****@*****.**").FirstOrDefault();
                        if (gToken != null)
                        {
                            await _hubCommunicator.ApplyNewToken(googleActivity.Id, gToken.Id);
                        }
                    }
                }

                var atlassianActivity = planMTSF.Activities[4];
                if (atlassianActivity != null)
                {
                    var curentAToken = atlassianTokens.AuthTokens.Where(t => t.Id == atlassianActivity.AuthTokenId).FirstOrDefault();
                    if (curentAToken == null)
                    {
                        var aToken = atlassianTokens.AuthTokens.FirstOrDefault();
                        if (aToken != null)
                        {
                            await _hubCommunicator.ApplyNewToken(atlassianActivity.Id, aToken.Id);
                        }
                    }
                }

                foreach (var slack in planMTSF.Activities.Where(term => term.ActivityTemplate.TerminalName == "terminalSlack"))
                {
                    var curentSToken = slackTokens.AuthTokens.FirstOrDefault(t => t.Id == slack.AuthTokenId);
                    if (curentSToken == null)
                    {
                        var sToken = slackTokens.AuthTokens.FirstOrDefault();
                        if (sToken != null)
                        {
                            await _hubCommunicator.ApplyNewToken(slack.Id, sToken.Id);
                        }
                    }
                }
            }
        }