Beispiel #1
0
        public static void Add(
            [ActivityTrigger] VSTSUserIntegrationContext vstsUserIntegrationContext,
            ILogger log
            )
        {
            // Parse the connection string and return a reference to the storage account.
            var connectionString = Environment.GetEnvironmentVariable("SkillsBundleTablesConnectionsString");
            var vstsUserService  = new VstsUserService(connectionString);
            var vstsUserEntity   = new VstsUserEntity(vstsUserIntegrationContext.UserOID, vstsUserIntegrationContext.VstsInstance
                                                      , vstsUserIntegrationContext.VstsUserId);

            vstsUserService.Add(vstsUserEntity);
        }
Beispiel #2
0
        /// <summary>
        /// Assign a user to an available VSTS instance located on the nearest Azure region.
        /// </summary>
        /// <param name="context"></param>
        /// <param name="log"></param>
        /// <returns></returns>
        public static async Task InitializeUserVSTSInstance(
            [OrchestrationTrigger] DurableOrchestrationContext context,
            ILogger log
            )
        {
            log.LogInformation("Start User VSTS Integration");
            var vstsIntegrationContext = context.GetInput <VSTSIntegrationContext>();
            //Check if the user has an assigned VSTS instance
            var userVstsInstanceEntity = await context.CallActivityAsync <VstsUserEntity>("GetUserVSTSInstance", vstsIntegrationContext.UserOID);

            if (userVstsInstanceEntity == null)
            {
                //Get VSTS PAT
                vstsIntegrationContext.VstsPAT =
                    await context.CallActivityAsync <string>("GetKVSecret", Environment.GetEnvironmentVariable("VSTSPATSecretURL"));

                VSTSUserIntegrationContext vstsUserIntegrationContext = new VSTSUserIntegrationContext()
                {
                    UserOID = vstsIntegrationContext.UserOID,
                };
                //Get user best VSTS Azure location
                vstsIntegrationContext.AzureLocation =
                    await context.CallActivityAsync <string>("GetCountryBestAzureLocation", vstsIntegrationContext.CountryCode);

                //Get an available VSTS instance with free slot
                var vstsInstanceEntity = await context.CallActivityAsync <VstsInstanceEntity>("GetAvailableVSTSInstance", vstsIntegrationContext);

                vstsUserIntegrationContext.VstsInstance = vstsInstanceEntity.InstanceName;
                vstsIntegrationContext.VstsInstance     = vstsInstanceEntity.InstanceName;
                // Add the user as a basic VSTS user
                vstsUserIntegrationContext.VstsUserId = await context.CallActivityAsync <string>("AddUserEntitlment", vstsIntegrationContext);

                //Save user VSTS integration information's
                await context.CallActivityAsync <string>("AssignUserVSTSInstance", vstsUserIntegrationContext);
            }
        }