private void InitializeEndpoints() { List <MacEndpoint> macEndpoints = new List <MacEndpoint>(); IList <Endpoint> endpoints = null; //get endpoints from disk if (!FileSystemService.Instance.FileExists(_filePath)) { FileSystemService.Instance.CreateDirectory(FileSystemService.Instance.FilesStoragePath); endpoints = EndpointService.Instance.CurrentEndpoints; var json = JsonConvert.SerializeObject(endpoints); FileSystemService.Instance.WriteFile(_filePath, json); } else { var json = FileSystemService.Instance.ReadFile(_filePath); if (!string.IsNullOrEmpty(json)) { var eps = JsonConvert.DeserializeObject <IList <Endpoint> >(json); if (eps != null && eps.Count > 0) { endpoints = eps; } } } //if we got endpoints back from disk, convert them for usage in the UI if (endpoints != null && endpoints.Count > 0) { //TODO figure out how to read from disk var environments = endpoints.Select(x => x.Environment) .Distinct() .ToList(); foreach (var env in environments) { MacEndpoint meb = new MacEndpoint() { Endpoints = new List <MacEndpoint>() }; meb.Environment = env; meb.Name = string.Empty; foreach (var e in endpoints .Where(x => x.Environment == env) .ToList()) { meb.Endpoints.Add(MacEndpoint.GetMacEndpoint(e)); } macEndpoints.Add(meb); } CurrentEndpoints = macEndpoints; } }
public IList <string> GetEnvironments() { return(new List <string>() { MacEndpoint.GetEnvironment(CoreLib.Authentication.Environment.Dev), MacEndpoint.GetEnvironment(CoreLib.Authentication.Environment.QA), MacEndpoint.GetEnvironment(CoreLib.Authentication.Environment.UAT), MacEndpoint.GetEnvironment(CoreLib.Authentication.Environment.Production), MacEndpoint.GetEnvironment(CoreLib.Authentication.Environment.Mock), }); }
public MSALAuthenticationService(MacEndpoint endpoint) { _endpoint = endpoint; MsalClientApplication = PublicClientApplicationBuilder .Create(_endpoint.ClientId) .WithAuthority(_endpoint.Authority) .WithLogging( Logging, LogLevel.Verbose, enablePiiLogging: true, enableDefaultPlatformLogging: true) .WithRedirectUri( $"msauth.{_endpoint.PackageName}://auth") .Build(); }
public void AddEndpoint(MacEndpoint macEndpoint) { var isUpdate = false; //save to disk var endpoints = GetEndpoints(); var endpoint = macEndpoint.ToEndpoint(); if (!endpoints.Any(x => x.Name == endpoint.Name && x.Environment == endpoint.Environment)) { var editep = endpoints.SingleOrDefault(x => x.Name == endpoint.Name && x.Environment == endpoint.Environment); //if existing item, remove the list and we'll replace with the new edited one if (editep != null) { var index = endpoints.IndexOf(editep); endpoints.RemoveAt(index); isUpdate = true; } } endpoints.Add(endpoint); var json = JsonConvert.SerializeObject(endpoints); FileSystemService.Instance.WriteFile(_filePath, json); var rootNode = CurrentEndpoints.SingleOrDefault(x => x.Name == string.Empty && x.Environment == macEndpoint.Environment); //update UI if (isUpdate) { //if the item already exists just update it if (rootNode != null) { var umep = rootNode.Endpoints.SingleOrDefault(x => x.Name == macEndpoint.Name && x.Environment == macEndpoint.Environment); if (umep != null) { var index = rootNode.Endpoints.IndexOf(umep); rootNode.Endpoints.RemoveAt(index); rootNode.Endpoints.Add(macEndpoint); //todo fix ordering } } } else { //check of the root node already exists for an environment, if so add as a child, if not add the root node and then the add the child if (CurrentEndpoints.Any(x => x.Environment == macEndpoint.Environment && x.Name == string.Empty)) { if (rootNode != null) { rootNode.Endpoints.Add(macEndpoint); } } else { MacEndpoint meb = new MacEndpoint() { Endpoints = new List <MacEndpoint>() }; meb.Environment = macEndpoint.Environment; meb.Name = string.Empty; meb.Endpoints.Add(macEndpoint); CurrentEndpoints.Add(meb); } } }