public override async Task <PageNavigationResult> OnPageLeavingAsync(WizardLeavingArgs args) { UserSettings.AddToTopOfMruList(((Wizard)this.Wizard).UserSettings.MruEndpoints, this.Endpoint); try { if (!UserSettings.GenerateCSharpClient && !UserSettings.GenerateCSharpController && !UserSettings.GenerateTypeScriptClient) { throw new Exception("Should check one of the checkboxes for generating!"); } this.SpecificationTempPath = await GetSpecification(); return(await base.OnPageLeavingAsync(args)); } catch (Exception e) { return(await Task.FromResult <PageNavigationResult>( new PageNavigationResult { ErrorMessage = e.Message, IsSuccess = false, ShowMessageBoxOnFailure = true })); } }
public override Task <PageNavigationResult> OnPageLeavingAsync(WizardLeavingArgs args) { if (this.IsCustomDomain && this.MyDomainViewModel.IsValid) { UserSettings.AddToTopOfMruList(this.Wizard.UserSettings.MruMyDomains, this.MyDomainViewModel.MyDomain.ToString()); } return(base.OnPageLeavingAsync(args)); }
public void AddToTopOfMruList_ShouldAddToTopWithoutDuplicatingOrExceedingMax() { // Create an instance of UserSettings var userSettings = new UserSettings(); var endpoint1 = "https://service1/$metadata"; var endpoint2 = "https://service2/$metadata"; var endpoint3 = "https://service3/$metadata"; var endpoint4 = "https://service4/$metadata"; var endpoint5 = "https://service5/$metadata"; var endpoint6 = "https://service6/$metadata"; var endpoint7 = "https://service7/$metadata"; var endpoint8 = "https://service8/$metadata"; var endpoint9 = "https://service9/$metadata"; var endpoint10 = "https://service10/$metadata"; var endpoint11 = "https://service11/$metadata"; // Add an endpoint. UserSettings.AddToTopOfMruList(userSettings?.MruEndpoints, endpoint1); Assert.AreEqual(1, userSettings.MruEndpoints.Count); // Add another endpoint.The latest endpoint to be added is at the top of the MruList. UserSettings.AddToTopOfMruList(userSettings?.MruEndpoints, endpoint2); Assert.AreEqual(2, userSettings.MruEndpoints.Count); Assert.AreEqual(endpoint2, userSettings.MruEndpoints[0]); Assert.AreEqual(endpoint1, userSettings.MruEndpoints[1]); // Add duplicate endpoint, Count should remain the same. But the item is moved to top of the MruList. UserSettings.AddToTopOfMruList(userSettings?.MruEndpoints, endpoint1); Assert.AreEqual(2, userSettings.MruEndpoints.Count); Assert.AreEqual(endpoint1, userSettings.MruEndpoints[0]); Assert.AreEqual(endpoint2, userSettings.MruEndpoints[1]); //Add 9 more endpoints. Total should not exceed 10 UserSettings.AddToTopOfMruList(userSettings?.MruEndpoints, endpoint3); UserSettings.AddToTopOfMruList(userSettings?.MruEndpoints, endpoint4); UserSettings.AddToTopOfMruList(userSettings?.MruEndpoints, endpoint5); UserSettings.AddToTopOfMruList(userSettings?.MruEndpoints, endpoint6); UserSettings.AddToTopOfMruList(userSettings?.MruEndpoints, endpoint7); UserSettings.AddToTopOfMruList(userSettings?.MruEndpoints, endpoint8); UserSettings.AddToTopOfMruList(userSettings?.MruEndpoints, endpoint9); UserSettings.AddToTopOfMruList(userSettings?.MruEndpoints, endpoint10); UserSettings.AddToTopOfMruList(userSettings?.MruEndpoints, endpoint11); Assert.AreEqual(10, userSettings.MruEndpoints.Count); //endpoint11 is the latest so on top in the MruList Assert.AreEqual(endpoint11, userSettings.MruEndpoints[0]); //endpoint2 is the least recent hence removed from the list Assert.IsFalse(userSettings.MruEndpoints.Contains(endpoint2)); // Reset User Settings ResetUserSettings(); }
public override Task <PageNavigationResult> OnPageLeavingAsync(WizardLeavingArgs args) { UserSettings.AddToTopOfMruList(((Wizard)this.Wizard).UserSettings.MruEndpoints, this.Endpoint); try { this.MetadataTempPath = GetMetadata(out var version); this.EdmxVersion = version; return(base.OnPageLeavingAsync(args)); } catch (Exception e) { return(Task.FromResult <PageNavigationResult>( new PageNavigationResult() { ErrorMessage = e.Message, IsSuccess = false, ShowMessageBoxOnFailure = true })); } }
public override async Task <PageNavigationResult> OnPageLeavingAsync(WizardLeavingArgs args) { UserSettings.AddToTopOfMruList(((Wizard)this.Wizard).UserSettings.MruEndpoints, this.Endpoint); try { if (!UserSettings.GenerateCSharpClient && !UserSettings.GenerateCSharpController && !UserSettings.GenerateTypeScriptClient) { throw new Exception("Should check one of the checkboxes for generating!"); } this.SpecificationTempPath = await GetSpecificationAsync(); // convert from OData specification if (this.UserSettings.ConvertFromOdata) { var csdl = File.ReadAllText(this.SpecificationTempPath); var model = CsdlReader.Parse(XElement.Parse(csdl).CreateReader()); if ((this.UserSettings.OpenApiConvertSettings.ServiceRoot == null || this.UserSettings.OpenApiConvertSettings.ServiceRoot.Host.Contains("localhost")) && this.UserSettings.Endpoint.StartsWith("http", StringComparison.Ordinal)) { this.UserSettings.OpenApiConvertSettings.ServiceRoot = new Uri(this.UserSettings.Endpoint.TrimEnd("$metadata".ToCharArray())); } var document = model.ConvertToOpenApi(this.UserSettings.OpenApiConvertSettings); var outputJson = document.SerializeAsJson(this.UserSettings.OpenApiSpecVersion); File.WriteAllText(this.SpecificationTempPath, outputJson); } return(await base.OnPageLeavingAsync(args)); } catch (Exception e) { return(await Task.FromResult <PageNavigationResult>( new PageNavigationResult { ErrorMessage = e.Message, IsSuccess = false, ShowMessageBoxOnFailure = true })); } }
public override Task <PageNavigationResult> OnPageLeavingAsync(WizardLeavingArgs args) { SaveToUserSettings(); var wizard = this.Wizard as ODataConnectedServiceWizard; UserSettings.AddToTopOfMruList(wizard?.UserSettings?.MruEndpoints, this.Endpoint); try { this.MetadataTempPath = GetMetadata(out var version); this.EdmxVersion = version; PageLeaving?.Invoke(this, EventArgs.Empty); return(base.OnPageLeavingAsync(args)); } catch (Exception e) { return(Task.FromResult( new PageNavigationResult { ErrorMessage = e.Message, IsSuccess = false, ShowMessageBoxOnFailure = true })); } }
public override async Task <PageNavigationResult> OnPageLeavingAsync(WizardLeavingArgs args) { PageNavigationResult result; using (this.Wizard.Context.StartBusyIndicator(Resources.DesignTimeAuthenticationViewModel_AuthenticatingProgress)) { string error = null; if (this.Authentication.RefreshToken == null) { // New identity or a existing identity w/no refresh token error = this.AuthenticateUser(); if (error == null && this.Authentication.EnvironmentType == EnvironmentType.Custom) { UserSettings.AddToTopOfMruList(this.Wizard.UserSettings.MruMyDomains, this.Authentication.MyDomain.ToString()); } } else if (this.Authentication.AccessToken == null) { // Existing identity w/no access token try { await AuthenticationHelper.RefreshAccessTokenAsync(this.Authentication); } catch (ForceException ex) { if (ex.Error == Error.InvalidGrant) // Expired refresh token { this.Authentication.RefreshToken = null; error = this.AuthenticateUser(); } else { error = ex.Message; } } } // else - Existing identity w/access and refresh token if (error == null) { UserSettings.AddToTopOfMruList(this.Wizard.UserSettings.MruDesignTimeAuthentications, this.Authentication); result = PageNavigationResult.Success; if (this.PageLeaving != null) { this.PageLeaving(this, EventArgs.Empty); } } else { result = new PageNavigationResult() { ErrorMessage = error, ShowMessageBoxOnFailure = true }; } } return(result); }