public async Task <bool> CreateOrUpdateAsync <T>(string Action, T Value) where T : IBaseObject { bool result = false; this.logger?.Log($"RestDataService.CreateOrUpdateAsync(): entered"); TypedBaseClient <T> client = this.getClient <T>(this.EndpointRegister.GetEndpoint(Action)); result = await client.CreateOrUpdateAsync(Value); this.logger?.Log($"RestDataService.CreateOrUpdateAsync(): exited with result '{result}'"); return(result); }
public async Task <IEnumerable <T> > GetAllAsync <T>(string Action, params object[] Parameters) where T : IBaseObject { IEnumerable <T> result = default; this.logger?.Log($"RestDataService.GetAllAsync(): entered"); string parameters = this.convertParameters(Parameters); TypedBaseClient <T> client = this.getClient <T>(this.EndpointRegister.GetEndpoint(Action)); result = await client.GetAllAsync(); this.logger?.Log($"RestDataService.GetAllAsync(): exited with result '{result}'"); return(result); }
public async Task <bool> DeleteAsync <T>(string Action, params object[] Parameters) where T : IBaseObject { bool result = false; string parameters = this.convertParameters(Parameters); this.logger?.Log($"RestDataService.DeleteAsync(): entered"); TypedBaseClient <T> client = this.getClient <T>(this.EndpointRegister.GetEndpoint(Action) + parameters); //TODO: parameters here?!? result = await client.DeleteAsync(Parameters[0]); this.logger?.Log($"RestDataService.DeleteAsync(): exited with result '{result}'"); return(result); }
//TODO: add method to add and or find an appropriate client #region getClient private TypedBaseClient <T> getClient <T>(string ResourceUri) where T : IBaseObject { this.logger?.Log($"RestDataService.getClient(): entered"); TypedBaseClient <T> result = default; lock (this.lockSync) { if (!this.clients.ContainsKey(typeof(T))) { this.logger?.Log($"RestDataService.getClient(): client resource has to be created"); string url = string.Empty; if (ResourceUri != null) { this.logger?.Log($"RestDataService.getClient(): resource Uri not empty: '{ResourceUri}'"); url = this.baseUri.ToString().AppendPathSegment(ResourceUri); } else { this.logger?.Log($"RestDataService.getClient(): resource Uri empty", Contracts.Logger.Enums.LogLevel.Warning); url = this.baseUri.ToString(); } this.logger?.Log($"RestDataService.getClient(): whole Uri is '{url}'"); try { this.logger?.Log($"RestDataService.getClient(): Attempting to create a client: 'new TypedBaseClient<T>(new Uri({url}), {this.logger}, {this.overrideMessageHandler});'"); TypedBaseClient <T> client = new TypedBaseClient <T>(new Uri(url), this.logger, this.overrideMessageHandler); this.logger?.Log($"RestDataService.getClient(): client created successfully, adding authentication header"); client.AddAuthenticationHeader(this.authenticationString); this.logger?.Log($"RestDataService.getClient(): authentication header added, next up: add to clients dict"); this.clients.Add(typeof(T), client); //TODO: add Uri; //TODO: make less specific this.logger?.Log($"RestDataService.getClient(): Client successfully created and added"); } catch (Exception ex) { this.logger?.Log($"RestDataService.getClient(): Client creation failed with Exception: '{ex.Message}'", Contracts.Logger.Enums.LogLevel.Error); } } else { this.logger?.Log($"RestDataService.getClient(): client for Type '{typeof(T)}' is buffered."); } result = (TypedBaseClient <T>) this.clients[typeof(T)]; } this.logger?.Log($"RestDataService.getClient(): exited with result '{result}'"); return(result); }