private object UpdateUIAzureLogicAppsResourcesAsync(OperationRunner context)
        {
            string tempArmTemplateFilePath           = System.IO.Path.Combine(DataModel.InstallationConfiguration.Azure.ArmTempPath, System.IO.Path.GetFileName(LogicAppsConfiguration.LogicAppsArmTemplateFileName));
            string tempArmTemplateParametersFilePath = System.IO.Path.Combine(DataModel.InstallationConfiguration.Azure.ArmTempPath, System.IO.Path.GetFileName(LogicAppsConfiguration.LogicAppsArmTemplateParametersFileName));

            File.Copy(
                LogicAppsConfiguration.LogicAppsArmTemplateFilePath,
                tempArmTemplateFilePath,
                true);

            DataModel.InstallationConfiguration.PowerApps.SaveConfiguration();
            DataModel.InstallationConfiguration.Azure.SaveConfiguration(new Dictionary <string, string>()
            {
                { LogicAppsConfiguration.LogicAppsArmTemplateParametersFilePath, tempArmTemplateParametersFilePath },
            });

            AzureClient client = new AzureClient(WizardContext.TokenProvider);

            client.SetLogger(context.Logger);

            return(client.CreateResourceGroupDeployment(
                       DataModel.InstallationConfiguration.Azure.SelectedSubscription.Id,
                       DataModel.InstallationConfiguration.Azure.ResourceGroupName,
                       $"UI_Update_Deployment_{Guid.NewGuid().ToString()}",
                       tempArmTemplateFilePath,
                       tempArmTemplateParametersFilePath));
        }
Esempio n. 2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="InstallerConfirmActionsInstallationControl"/> class.
        /// </summary>
        /// <param name="model">The view model to bind to this control.</param>
        /// <param name="context">The wizard context instance.</param>
        public InstallerConfirmActionsInstallationControl(
            InstallerModel model,
            InstallerWizard context)
            : base(model, context)
        {
            InitializeComponent();

            SequentialRunner = new OperationRunner(
                model.OperationsProgress,
                this,
                WizardContext.LogFileStream);
            SequentialRunner.IndeterminateOps = true;

            LogOutputControl        = DetailsRichTextBox;
            SequentialRunner.OnLog += WriteLog;

            SequentialRunner.OnComplete += SequentialRunner_OnComplete;

            DataModel.CurrentOperationRunner = SequentialRunner;

            // TODO: Data binding isn't working
            WizardProgress.PagesSource = DataModel.Progress;

            BuildSummary();

            QueueOperations();

            SequentialRunner.BeginOperationsAsync();
        }
Esempio n. 3
0
        private object BeginLogicAppValidationAsync(OperationRunner context)
        {
            if (!Directory.Exists(DataModel.InstallationConfiguration.Azure.ArmTempPath))
            {
                Directory.CreateDirectory(DataModel.InstallationConfiguration.Azure.ArmTempPath);
            }

            _tempArmTemplateFilePath           = System.IO.Path.Combine(DataModel.InstallationConfiguration.Azure.ArmTempPath, LogicAppsConfiguration.LogicAppsArmTemplateFileName);
            _tempArmTemplateParametersFilePath = System.IO.Path.Combine(DataModel.InstallationConfiguration.Azure.ArmTempPath, LogicAppsConfiguration.LogicAppsArmTemplateParametersFileName);

            File.Copy(
                LogicAppsConfiguration.LogicAppsArmTemplateFilePath,
                _tempArmTemplateFilePath,
                true);

            DataModel.InstallationConfiguration.Azure.SaveConfiguration(new Dictionary <string, string>()
            {
                { LogicAppsConfiguration.LogicAppsArmTemplateParametersFilePath, _tempArmTemplateParametersFilePath },
            });

            AzureClient client = new AzureClient(WizardContext.TokenProvider);

            client.SetLogger(context.Logger);

            return(client.ValidateResourceGroupDeploymentAsync(
                       DataModel.InstallationConfiguration.Azure.SelectedSubscription.Id,
                       DataModel.InstallationConfiguration.Azure.ResourceGroupName,
                       "validateAzureDeploy",
                       _tempArmTemplateFilePath,
                       _tempArmTemplateParametersFilePath).Result);
        }
Esempio n. 4
0
        private object DeployAPIAzureResourcesAsync(OperationRunner context)
        {
            string tempArmTemplateFilePath           = System.IO.Path.Combine(DataModel.InstallationConfiguration.Azure.ArmTempPath, System.IO.Path.GetFileName(AzureConfiguration.AzureArmTemplateFilePath));
            string tempArmTemplateParametersFilePath = System.IO.Path.Combine(DataModel.InstallationConfiguration.Azure.ArmTempPath, System.IO.Path.GetFileName(AzureConfiguration.AzureArmTemplateParametersFilePath));

            File.Copy(
                AzureConfiguration.AzureArmTemplateFilePath,
                tempArmTemplateFilePath,
                true);

            // TODO: Do this better
            // if (!string.IsNullOrWhiteSpace(DataModel.InstallationStatusCache.Status.FunctionApp.ClientSecret)) DataModel.InstallationConfiguration.Azure.FunctionApp.ApplicationRegistrationSecret = new NetworkCredential("applicationRegistrationSecret", DataModel.InstallationStatusCache.Status.FunctionApp.ClientSecret);
            DataModel.InstallationConfiguration.Azure.LogicApps.AADClientId = DataModel.InstallationConfiguration.Azure.FunctionApp.ApplicationId;
            DataModel.InstallationConfiguration.Azure.LogicApps.AADAudience = DataModel.InstallationConfiguration.Azure.FunctionApp.ApplicationId;

            DataModel.InstallationConfiguration.PowerApps.SaveConfiguration();
            DataModel.InstallationConfiguration.Azure.SaveConfiguration(new Dictionary <string, string>()
            {
                { AzureConfiguration.AzureArmTemplateParametersFilePath, tempArmTemplateParametersFilePath },
            });

            AzureClient client = new AzureClient(WizardContext.TokenProvider);

            client.SetLogger(context.Logger);

            return(client.CreateResourceGroupDeployment(
                       DataModel.InstallationConfiguration.Azure.SelectedSubscription.Id,
                       DataModel.InstallationConfiguration.Azure.ResourceGroupName,
                       $"API_Deployment_{Guid.NewGuid().ToString()}",
                       tempArmTemplateFilePath,
                       tempArmTemplateParametersFilePath));
        }
Esempio n. 5
0
        private object SetFunctionAppAuthenticationAsync(OperationRunner context)
        {
            AzureClient client = new AzureClient(WizardContext.TokenProvider);

            client.SetLogger(context.Logger);

            AppServiceAuthSettings authSettings = client.GetAppServiceAuthSettingsAsync(
                DataModel.InstallationConfiguration.Azure.SelectedSubscription.Id,
                DataModel.InstallationConfiguration.Azure.ResourceGroupName,
                DataModel.InstallationConfiguration.Azure.FunctionApp.AppName).Result;

            if (authSettings == null)
            {
                throw new Exception("Could not obtain authentication settings for Azure Function App!");
            }

            authSettings.Enabled              = "true";
            authSettings.DefaultProvider      = "AzureActiveDirectory";
            authSettings.IsAadAutoProvisioned = "false";
            authSettings.ClientId             = DataModel.InstallationConfiguration.Azure.FunctionApp.ApplicationId;
            authSettings.Issuer           = "https://sts.windows.net/" + WizardContext.TokenProvider.GetTenantId() + "/";
            authSettings.AllowedAudiences = new string[] { DataModel.InstallationConfiguration.Azure.FunctionApp.ApplicationId };

            return(client.UpdateAppServiceAuthSettingsAsync(
                       DataModel.InstallationConfiguration.Azure.SelectedSubscription.Id,
                       DataModel.InstallationConfiguration.Azure.ResourceGroupName,
                       DataModel.InstallationConfiguration.Azure.FunctionApp.AppName,
                       authSettings).Result);
        }
        private object UpdateAzureFunctionsAsync(OperationRunner context)
        {
            AzureClient client = new AzureClient(WizardContext.TokenProvider);

            client.SetLogger(context.Logger);

            PublishData publishingProfiles = client.GetAppServicePublishingProfileAsync(
                DataModel.InstallationConfiguration.Azure.SelectedSubscription.Id,
                DataModel.InstallationConfiguration.Azure.ResourceGroupName,
                DataModel.InstallationConfiguration.Azure.FunctionApp.AppName).Result;
            PublishProfile webDeployProfile =
                publishingProfiles
                .Profiles
                .Where(x => x.ProfileName.Contains("Web Deploy"))
                .FirstOrDefault();

            SecureString publishingProfilePassword = new SecureString();

            foreach (char c in webDeployProfile.Password)
            {
                publishingProfilePassword.AppendChar(c);
            }

            publishingProfilePassword.MakeReadOnly();

            return(client.ZipDeployAppServiceAsync(
                       DataModel.InstallationConfiguration.Azure.FunctionApp.AppName,
                       DataModel.InstallationConfiguration.Azure.FunctionApp.AppDeploymentSourceUrl,
                       new NetworkCredential(webDeployProfile.UserName, publishingProfilePassword)).Result);
        }
Esempio n. 7
0
        /// <summary>
        /// Initializes a new instance of the <see cref="DeployPowerAppsInstallationControl"/> class.
        /// </summary>
        /// <param name="model">The view model to bind to this control.</param>
        /// <param name="context">The wizard context instance.</param>
        public DeployPowerAppsInstallationControl(
            InstallerModel model,
            InstallerWizard context)
            : base(model, context)
        {
            InitializeComponent();

            SequentialRunner = new OperationRunner(
                model.OperationsProgress,
                this,
                WizardContext.LogFileStream);

            LogOutputControl        = DetailsRichTextBox;
            SequentialRunner.OnLog += WriteLog;

            SequentialRunner.OnComplete += SequentialRunner_OnComplete;

            DataModel.CurrentOperationRunner    = SequentialRunner;
            DataModel.SuccessFinalStatusMessage = "Advocacy Platform installed successfully.";
            DataModel.FailureFinalStatusMessage = "Advocacy Platform failed to install.";

            // TODO: Data binding isn't working
            WizardProgress.PagesSource = DataModel.Progress;
            OperationsProgressControl.OperationsSource = DataModel.OperationsProgress;

            QueueOperations();

            SequentialRunner.BeginOperationsAsync();
        }
        private void RunGetPowerAppsEnvironmentOperationAsync()
        {
            Task.Run(() =>
            {
                OperationRunner singleRunner = new OperationRunner(
                    null,
                    this,
                    WizardContext.LogFileStream);
                singleRunner.IndeterminateOps = true;
                singleRunner.OnLog           += WriteLog;

                singleRunner.Operations.Enqueue(new Operation()
                {
                    Name = "GetPowerAppsEnvironments",
                    OperationFunction = GetPowerAppsEnvironmentsAsync,
                    ValidateFunction  = (context) =>
                    {
                        return(context.LastOperationStatusCode == 0);
                    },
                    OperationCompletedHandler = (result) =>
                    {
                        GetPowerAppsEnvironmentsResponse response = (GetPowerAppsEnvironmentsResponse)result;

                        DataModel.InstallationConfiguration.PowerApps.Environments = response
                                                                                     .Value
                                                                                     .Select(x => new PowerAppsEnvironment()
                        {
                            DisplayName            = x.Properties.DisplayName,
                            EnvironmentName        = x.Name,
                            OrganizationName       = x.Properties.LinkedEnvironmentMetadata != null ? x.Properties.LinkedEnvironmentMetadata.UniqueName : null,
                            OrganizationDomainName = x.Properties.LinkedEnvironmentMetadata != null ? x.Properties.LinkedEnvironmentMetadata.DomainName : null,
                            WebApplicationUrl      = x.Properties.LinkedEnvironmentMetadata != null ? x.Properties.LinkedEnvironmentMetadata.InstanceUrl : null,
                        }).ToList();

                        PowerAppsEnvironment defaultEnvironment = DataModel
                                                                  .InstallationConfiguration
                                                                  .PowerApps
                                                                  .Environments
                                                                  .Where(x => DataModel.InstallationConfiguration.PowerApps.SelectedEnvironment != null &&
                                                                         string.Compare(x.EnvironmentName, DataModel.InstallationConfiguration.PowerApps.SelectedEnvironment.EnvironmentName, true) == 0)
                                                                  .FirstOrDefault();

                        DataModel.InstallationConfiguration.PowerApps.SelectedEnvironment =
                            defaultEnvironment ??
                            DataModel
                            .InstallationConfiguration
                            .PowerApps
                            .Environments
                            .FirstOrDefault();
                    },
                    ExceptionHandler = (ex) =>
                    {
                        DataModel.StatusMessage = "Failed to acquire PowerApps environments!";
                    },
                });

                singleRunner.RunOperations();
            });
        }
Esempio n. 9
0
        private object GetAzureSubscriptionsAsync(OperationRunner context)
        {
            AzureClient client = new AzureClient(WizardContext.TokenProvider);

            client.SetLogger(context.Logger);

            return(client.GetSubscriptionsAsync().Result);
        }
        private object RemovePowerAppsEnvironmentAsync(OperationRunner context)
        {
            PowerAppsClient client = new PowerAppsClient(WizardContext.TokenProvider);

            client.SetLogger(context.Logger);

            return(client.DeleteEnvironmentAsync(DataModel.InstallationConfiguration.PowerApps.SelectedEnvironment.EnvironmentName).Result);
        }
Esempio n. 11
0
        private object GetPowerAppsEnvironmentsAsync(OperationRunner context)
        {
            PowerAppsClient client = new PowerAppsClient(WizardContext.TokenProvider);

            client.SetLogger(context.Logger);

            return((GetPowerAppsEnvironmentsResponse)client.GetEnvironmentsAsync().Result);
        }
        private object GetAzureResourceGroupsAsync(OperationRunner context)
        {
            AzureClient client = new AzureClient(WizardContext.TokenProvider);

            client.SetLogger(context.Logger);

            return(client.GetResourceGroupsAsync(DataModel.InstallationConfiguration.Azure.SelectedSubscription.Id).Result);
        }
        private object CheckDynamics365CRMSolutionAsync(OperationRunner context)
        {
            DynamicsCrmClient client = new DynamicsCrmClient(
                DataModel.InstallationConfiguration.PowerApps.SelectedEnvironment.OrganizationName,
                DataModel.InstallationConfiguration.PowerApps.SelectedEnvironment.OrganizationDomainName,
                WizardContext.TokenProvider);

            return(client.GetSolutionAsync(DataModel.InstallationConfiguration.DynamicsCrm.SolutionUniqueName).Result);
        }
        private void RunGetAzureResourceGroupsOperationAsync()
        {
            Task.Run(() =>
            {
                OperationRunner singleRunner = new OperationRunner(
                    null,
                    this,
                    WizardContext.LogFileStream);
                singleRunner.IndeterminateOps = true;
                singleRunner.OnLog           += WriteLog;

                singleRunner.Operations.Enqueue(new Operation()
                {
                    Name = "GetAzureResourceGroups",
                    OperationFunction = GetAzureResourceGroupsAsync,
                    ValidateFunction  = (context) =>
                    {
                        return(context.LastOperationStatusCode == 0);
                    },
                    OperationCompletedHandler = (result) =>
                    {
                        Contract.ResourceGroup[] response = (Contract.ResourceGroup[])result;

                        DataModel.InstallationConfiguration.Azure.ResourceGroups = response
                                                                                   .Where(x => x.Tags != null &&
                                                                                          x.Tags.ContainsKey(InstallerModel.ResourceGroupTagKey))
                                                                                   .Select(x => new AzureResourceGroup()
                        {
                            Name     = x.Name,
                            Location = x.Location,
                            Tags     = x.Tags,
                        });

                        AzureResourceGroup defaultResourceGroup = DataModel
                                                                  .InstallationConfiguration
                                                                  .Azure
                                                                  .ResourceGroups
                                                                  .Where(x => string.Compare(x.Name, DataModel.InstallationConfiguration.Azure.ResourceGroupName, StringComparison.Ordinal) == 0)
                                                                  .FirstOrDefault();

                        DataModel.InstallationConfiguration.Azure.SelectedResourceGroup =
                            defaultResourceGroup ??
                            DataModel
                            .InstallationConfiguration
                            .Azure
                            .ResourceGroups
                            .FirstOrDefault();
                    },
                    ExceptionHandler = (ex) =>
                    {
                        DataModel.StatusMessage = "Failed to acquire Azure Resource Groups!";
                    },
                });

                singleRunner.RunOperations();
            });
        }
        private void RunGetAzureSubscriptionsOperationAsync()
        {
            Task.Run(() =>
            {
                OperationRunner singleRunner = new OperationRunner(
                    null,
                    this,
                    WizardContext.LogFileStream);
                singleRunner.IndeterminateOps = true;
                singleRunner.OnLog           += WriteLog;

                singleRunner.Operations.Enqueue(new Operation()
                {
                    Name = "GetAzureSubscriptions",
                    OperationFunction = GetAzureSubscriptionsAsync,
                    ValidateFunction  = (context) =>
                    {
                        return(context.LastOperationStatusCode == 0);
                    },
                    OperationCompletedHandler = (result) =>
                    {
                        Subscription[] response = (Subscription[])result;

                        DataModel.InstallationConfiguration.Azure.CheckedForSubscriptions = true;

                        DataModel.InstallationConfiguration.Azure.Subscriptions = response
                                                                                  .Select(x => new AzureSubscription()
                        {
                            Id   = x.SubscriptionId,
                            Name = x.DisplayName,
                        });

                        AzureSubscription defaultSubscription = DataModel
                                                                .InstallationConfiguration
                                                                .Azure
                                                                .Subscriptions
                                                                .Where(x => DataModel.InstallationConfiguration.Azure.SelectedSubscription != null &&
                                                                       string.Compare(x.Id, DataModel.InstallationConfiguration.Azure.SelectedSubscription.Id, true) == 0)
                                                                .FirstOrDefault();

                        DataModel.InstallationConfiguration.Azure.SelectedSubscription =
                            defaultSubscription ??
                            DataModel
                            .InstallationConfiguration
                            .Azure
                            .Subscriptions
                            .FirstOrDefault();
                    },
                    ExceptionHandler = (ex) =>
                    {
                        DataModel.StatusMessage = "Failed to acquire Azure subscriptions!";
                    },
                });
                singleRunner.RunOperations();
            });
        }
        private object GetPowerAppsEnvironmentLocationsAsync(OperationRunner context)
        {
            context.Logger.LogInformation("Getting PowerApps environments...");

            PowerAppsClient client = new PowerAppsClient(WizardContext.TokenProvider);

            client.SetLogger(context.Logger);

            return(client.GetEnvironmentLocationsAsync().Result);
        }
        private object GetPowerAppsCdsDatabaseLanguagesAsync(OperationRunner context)
        {
            context.Logger.LogInformation("Getting PowerApps Common Data Services database languages...");

            PowerAppsClient client = new PowerAppsClient(WizardContext.TokenProvider);

            client.SetLogger(context.Logger);

            return(client.GetCdsDatabaseLanguagesAsync(
                       DataModel.InstallationConfiguration.PowerApps.SelectedLocation).Result);
        }
Esempio n. 18
0
        private object AuthorizeCDSConnectionAsync(OperationRunner context)
        {
            AzureClient client = new AzureClient(WizardContext.TokenProvider);

            client.SetLogger(context.Logger);

            return(client.AuthenticateApiConnection(
                       DataModel.InstallationConfiguration.Azure.SelectedSubscription.Id,
                       DataModel.InstallationConfiguration.Azure.ResourceGroupName,
                       DataModel.InstallationConfiguration.Azure.LogicApps.CdsConnectionName));
        }
Esempio n. 19
0
        private void WriteArmValidationMessage(string type, OperationRunner runner)
        {
            Dispatcher.BeginInvoke(new Action(() =>
            {
                Span validARMSpan = new Span(new Run($"Proposed {type} Azure deployment is {(runner.LastOperationStatusCode == 0 ? "valid" : "invalid")}.\n"))
                {
                    Foreground = new SolidColorBrush(runner.LastOperationStatusCode == 0 ? Colors.Green : Colors.Red),
                };

                WriteSummaryMessage(new List <Span>()
                {
                    validARMSpan
                });
            }));
        }
        private object RemoveApplicationRegistrationAsync(OperationRunner context)
        {
            AzureClient client = new AzureClient(WizardContext.TokenProvider);

            client.SetLogger(context.Logger);

            AzureApplication application = client.GetApplicationAsync(DataModel.InstallationConfiguration.Azure.FunctionApp.ApplicationRegistrationName).Result;

            if (application == null)
            {
                return(true);
            }

            return(client.DeleteApplicationAsync(application.Id).Result);
        }
Esempio n. 21
0
        private void RunGetAzureSubscriptionsOperation()
        {
            Task.Run(() =>
            {
                OperationRunner singleRunner = new OperationRunner(
                    null,
                    this,
                    WizardContext.LogFileStream);
                singleRunner.IndeterminateOps = true;
                singleRunner.OnLog           += WriteLog;

                singleRunner.Operations.Enqueue(new Operation()
                {
                    Name = "GetAzureSubscriptions",
                    OperationFunction = GetAzureSubscriptionsAsync,
                    ValidateFunction  = (context) =>
                    {
                        return(context.LastOperationStatusCode == 0);
                    },
                    OperationCompletedHandler = (result) =>
                    {
                        Contract.Subscription[] response = (Contract.Subscription[])result;

                        DataModel.InstallationConfiguration.Azure.CheckedForSubscriptions = true;

                        DataModel.InstallationConfiguration.Azure.Subscriptions = response
                                                                                  .Select(x => new AzureSubscription()
                        {
                            Id   = x.SubscriptionId,
                            Name = x.DisplayName,
                        });

                        // Threading is causing issues
                        // string defaultLocation = DataModel.InstallationConfiguration.PowerApps.Locations.Where(x => string.Compare(x, _defaultLocation, StringComparison.Ordinal) == 0).FirstOrDefault();

                        // DataModel.InstallationConfiguration.PowerApps.SelectedLocation =
                        //    (defaultLocation != null ?
                        //        defaultLocation :
                        //            DataModel.InstallationConfiguration.PowerApps.Locations.FirstOrDefault());
                    },
                    ExceptionHandler = (ex) =>
                    {
                        DataModel.StatusMessage = "Failed to acquire Azure subscriptions!";
                    },
                });
                singleRunner.RunOperations();
            });
        }
Esempio n. 22
0
        private object CreatePowerAppsEnvironmentAsync(OperationRunner context)
        {
            PowerAppsClient client = new PowerAppsClient(WizardContext.TokenProvider);

            client.SetLogger(context.Logger);

            return(client.CreateEnvironmentAsync(new CreatePowerAppsEnvironmentRequest()
            {
                Location = DataModel.InstallationConfiguration.PowerApps.SelectedLocation,
                Properties = new NewPowerAppsEnvironmentProperties()
                {
                    DisplayName = DataModel.InstallationConfiguration.PowerApps.EnvironmentDisplayName,
                    EnvironmentSku = DataModel.InstallationConfiguration.PowerApps.SelectedSku,
                },
            }).Result);
        }
Esempio n. 23
0
        private object ImportDynamicsCRMSolutionConfigurationAsync(OperationRunner context)
        {
            string schemaXml = null;
            string dataXml   = null;

            using (Stream fileStream = File.Open(DataModel.InstallationConfiguration.DynamicsCrm.ConfigurationZipFilePath, FileMode.Open))
            {
                using (ZipArchive zipFile = new ZipArchive(fileStream, ZipArchiveMode.Read))
                {
                    ZipArchiveEntry schemaFile = null;
                    ZipArchiveEntry dataFile   = null;

                    foreach (ZipArchiveEntry entry in zipFile.Entries)
                    {
                        if (string.Compare(entry.Name, "data_schema.xml", true) == 0)
                        {
                            schemaFile = entry;
                        }
                        else if (string.Compare(entry.Name, "data.xml", true) == 0)
                        {
                            dataFile = entry;
                        }
                    }

                    if (schemaFile == null || dataFile == null)
                    {
                        throw new Exception("Invalid configuration archive!");
                    }

                    using (StreamReader schemaFileStream = new StreamReader(schemaFile.Open()))
                    {
                        schemaXml = schemaFileStream.ReadToEnd();
                    }

                    using (StreamReader dataFileStream = new StreamReader(dataFile.Open()))
                    {
                        dataXml = dataFileStream.ReadToEnd();
                    }
                }
            }

            _dynamicsCrmClient.ImportEntitiesAsync(
                schemaXml,
                dataXml).Wait();

            return(true);
        }
Esempio n. 24
0
        private object DeployAzureADFunctionAppRegistrationAsync(OperationRunner context)
        {
            AzureClient client = new AzureClient(WizardContext.TokenProvider);

            client.SetLogger(context.Logger);

            AzureApplication application = client.GetApplicationAsync(DataModel.InstallationConfiguration.Azure.FunctionApp.ApplicationRegistrationName).Result;

            if (application != null)
            {
                return(application);
            }

            return(client.CreateApplicationAsync(new AzureApplicationRequestBase()
            {
                DisplayName = DataModel.InstallationConfiguration.Azure.FunctionApp.ApplicationRegistrationName,
                IdentifierUris = new string[]
                {
                    $"https://{DataModel.InstallationConfiguration.Azure.FunctionApp.ApplicationRegistrationName}",
                },
                PasswordCredentials = new AzureApplicationPasswordCredential[]
                {
                    new AzureApplicationPasswordCredential()
                    {
                        StartDateTime = DateTime.Now.ToString("o"),
                        EndDateTime = DateTime.Now.AddYears(1).ToString("o"),
                        SecretText = DataModel.InstallationConfiguration.Azure.FunctionApp.ApplicationRegistrationSecret.Password,
                    },
                },
                RequiredResourceAccess = new AzureApplicationRequiredResourceAccess[]
                {
                    new AzureApplicationRequiredResourceAccess()
                    {
                        ResourceAppId = "00000003-0000-0000-c000-000000000000",
                        ResourceAccess = new ResourceAccess[]
                        {
                            new ResourceAccess()
                            {
                                Id = "e1fe6dd8-ba31-4d61-89e7-88639da4683d",
                                Type = "Scope",
                            },
                        },
                    },
                },
                SignInAudience = "AzureADMyOrg",
            }).Result);
        }
Esempio n. 25
0
        private object CreatePowerAppsCdsDatabaseAsync(OperationRunner context)
        {
            PowerAppsClient client = new PowerAppsClient(WizardContext.TokenProvider);

            client.SetLogger(context.Logger);

            return(client.CreateCdsDatabase(
                       DataModel.InstallationConfiguration.PowerApps.SelectedEnvironment.EnvironmentName,
                       new CreatePowerAppsCdsDatabaseRequest()
            {
                BaseLanguage = DataModel.InstallationConfiguration.PowerApps.SelectedLanguage.LanguageName,
                Currency = new PowerAppsCdsDatabaseCurrencyMinimal()
                {
                    Code = DataModel.InstallationConfiguration.PowerApps.SelectedCurrency.CurrencyName,
                },
            }));
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="AzureFunctionAppInstallationControl"/> class.
        /// </summary>
        /// <param name="model">The view model to bind to this control.</param>
        /// <param name="context">The wizard context instance.</param>
        public AzureFunctionAppInstallationControl(
            InstallerModel model,
            InstallerWizard context)
            : base(model, context)
        {
            InitializeComponent();

            SequentialRunner = new OperationRunner(
                model.OperationsProgress,
                this,
                WizardContext.LogFileStream);
            SequentialRunner.OnLog += WriteLog;

            SetDefaults();

            // TODO: Data binding isn't working
            WizardProgress.PagesSource = DataModel.Progress;
        }
Esempio n. 27
0
        private object EnsureResourceGroupAsync(OperationRunner context)
        {
            AzureClient client = new AzureClient(WizardContext.TokenProvider);

            client.SetLogger(context.Logger);

            bool exists = client.ResourceGroupExistsAsync(
                DataModel.InstallationConfiguration.Azure.SelectedSubscription.Id,
                DataModel.InstallationConfiguration.Azure.ResourceGroupName).Result;

            Contracts.ResourceGroup resourceGroup = null;

            if (exists)
            {
                resourceGroup = client.GetResourceGroupAsync(
                    DataModel.InstallationConfiguration.Azure.SelectedSubscription.Id,
                    DataModel.InstallationConfiguration.Azure.ResourceGroupName).Result;

                if (!resourceGroup.Tags.ContainsKey(InstallerModel.ResourceGroupTagKey))
                {
                    resourceGroup.Tags.Add(InstallerModel.ResourceGroupTagKey, InstallerModel.ResourceGroupTagValue);
                }
                else
                {
                    resourceGroup.Tags[InstallerModel.ResourceGroupTagKey] = InstallerModel.ResourceGroupTagValue;
                }
            }
            else
            {
                resourceGroup = new Contracts.ResourceGroup()
                {
                    Name     = DataModel.InstallationConfiguration.Azure.ResourceGroupName,
                    Location = DataModel.InstallationConfiguration.Azure.ResourceGroupLocation,
                    Tags     = new Dictionary <string, string>()
                    {
                        { InstallerModel.ResourceGroupTagKey, InstallerModel.ResourceGroupTagValue },
                    },
                };
            }

            return(client.CreateOrUpdateResourceGroupAsync(
                       DataModel.InstallationConfiguration.Azure.SelectedSubscription.Id,
                       resourceGroup).Result);
        }
        private void RunGetPowerAppsCdsDatabaseLanguagesAsync()
        {
            Task.Run(() =>
            {
                OperationRunner singleRunner = new OperationRunner(
                    null,
                    this,
                    WizardContext.LogFileStream);
                singleRunner.IndeterminateOps = true;
                singleRunner.OnLog           += WriteLog;

                singleRunner.Operations.Enqueue(new Operation()
                {
                    Name = "GetPowerAppsCdsDatabaseLanguages",
                    OperationFunction = GetPowerAppsCdsDatabaseLanguagesAsync,
                    ValidateFunction  = (context) =>
                    {
                        return(context.LastOperationStatusCode == 0);
                    },
                    OperationCompletedHandler = (result) =>
                    {
                        GetPowerAppsLanguagesResponse response = (GetPowerAppsLanguagesResponse)result;

                        DataModel.InstallationConfiguration.PowerApps.Languages = response.Value.Select(x => new PowerAppsCdsLanguage()
                        {
                            LanguageName = x.Name, LanguageDisplayName = x.Properties.DisplayName
                        }).ToList();

                        PowerAppsCdsLanguage defaultLanguage = DataModel.InstallationConfiguration.PowerApps.Languages.Where(x => x.LanguageName == _defaultLanguage).FirstOrDefault();

                        DataModel.InstallationConfiguration.PowerApps.SelectedLanguage =
                            defaultLanguage != null ?
                            defaultLanguage :
                            DataModel.InstallationConfiguration.PowerApps.Languages.FirstOrDefault();
                    },
                    ExceptionHandler = (ex) =>
                    {
                        DataModel.StatusMessage = "Failed to acquire PowerApps CDS database languages!";
                    },
                });

                singleRunner.RunOperations();
            });
        }
        private object RemoveAzureResourceGroupAsync(OperationRunner context)
        {
            AzureClient client = new AzureClient(WizardContext.TokenProvider);

            client.SetLogger(context.Logger);

            AzureValueCollectionResponse <ResourceLock> resourceLocks = client.GetResourceGroupLocksAsync(
                DataModel.InstallationConfiguration.Azure.SelectedSubscription.Id,
                DataModel.InstallationConfiguration.Azure.SelectedResourceGroup.Name).Result;

            foreach (ResourceLock resourceLock in resourceLocks.Value)
            {
                string result = client.DeleteResourceLockAsync(resourceLock.Id).Result;
            }

            return(client.DeleteResourceGroup(
                       DataModel.InstallationConfiguration.Azure.SelectedSubscription.Id,
                       DataModel.InstallationConfiguration.Azure.SelectedResourceGroup.Name));
        }
Esempio n. 30
0
        private object DeployDynamicsCRMSolutionAsync(OperationRunner context)
        {
            DataModel.ShowStatus    = true;
            DataModel.StatusMessage = "Deploying Advocacy Platform Dynamics 365 CRM managed solution...";

            DataModel.ShowProgress        = true;
            DataModel.OperationInProgress = true;

            DataModel.NextEnabled     = false;
            DataModel.PreviousEnabled = false;

            DynamicsCrmSolution solution = _dynamicsCrmClient.GetSolutionAsync("AdvocacyPlatformSolution").Result;

            if (solution == null)
            {
                return(_dynamicsCrmClient.ImportSolutionAsync(DataModel.InstallationConfiguration.DynamicsCrm.SolutionZipFilePath).Result);
            }

            return(solution);
        }