/// <summary> /// Constructor /// </summary> public Tenant(string organization, string environment) { InternalContract.RequireNotNullOrWhitespace(organization, nameof(organization)); InternalContract.RequireNotNullOrWhitespace(environment, nameof(environment)); Organization = organization?.ToLower(); Environment = environment?.ToLower(); Validate($"{Namespace}: 80BAC4F7-6369-4ACD-A34F-413A20E24C27"); }
public AzureBlobClient(string connectionString) { InternalContract.RequireNotNullOrWhiteSpace(connectionString, nameof(connectionString)); var storageAccount = CloudStorageAccount.Parse(connectionString); _blobClient = storageAccount.CreateCloudBlobClient(); FulcrumAssert.IsNotNull(_blobClient, null, "Could not create a cloud blob client."); }
/// <summary> /// Get the cacke key /// </summary> protected static string GetCacheKeyFromId(TId id) { var key = id?.ToString(); InternalContract.Require(key != null, $"Could not extract a cache key for an item of type {typeof(TModel).FullName}."); return(key); }
public async Task <TResponse> PutAsync <TResponse, TBody>(string relativeUrl, TBody instance) where TBody : class { InternalContract.RequireNotNullOrWhitespace(relativeUrl, nameof(relativeUrl)); var response = await SendRequestAsync <TResponse, TBody>(HttpMethod.Post, relativeUrl, null, default(CancellationToken), instance); return(response.Body); }
private static Guid ToGuid(string id) { #pragma warning disable IDE0018 // Inline variable declaration Guid guid; #pragma warning restore IDE0018 // Inline variable declaration InternalContract.Require(Guid.TryParse(id, out guid), $"Expected a Guid in {nameof(id)} but the value was ({id})."); return(guid); }
/// <summary> /// Put the item in the cache. /// </summary> private async Task CacheSetAsync(PageEnvelope <TModel> pageEnvelope, string keyPrefix, CancellationToken token) { InternalContract.RequireNotDefaultValue(pageEnvelope, nameof(pageEnvelope)); InternalContract.RequireValidated(pageEnvelope, nameof(pageEnvelope)); var serializedCacheEnvelope = ToSerializedCacheEnvelope(pageEnvelope); var key = GetCacheKeyForPage(keyPrefix, pageEnvelope.PageInfo.Offset, pageEnvelope.PageInfo.Limit); await Cache.SetAsync(key, serializedCacheEnvelope, CacheOptions, token); }
/// <summary> /// Constructor /// </summary> /// <param name="options"></param> /// <param name="tableMetadata"></param> protected TableBase(IDatabaseOptions options, ISqlTableMetadata tableMetadata) { InternalContract.RequireNotNull(options, nameof(options)); InternalContract.RequireValidated(tableMetadata, nameof(tableMetadata)); Database = new Database(options); TableMetadata = tableMetadata; }
/// <summary> /// Constructor /// </summary> public CircuitBreakerWithThrottling(CircuitBreakerWithThrottlingOptions options) : base(options) { InternalContract.RequireNotNull(options, nameof(options)); InternalContract.RequireValidated(options, nameof(options)); _options = options; _options.ThrottlingCoolDownStrategy.Reset(); }
/// <summary>Read the correlation id header from the <paramref name="request"/> and save it to the execution context. /// Then sends the HTTP request to the inner handler to send to the server as an asynchronous operation.</summary> /// <returns>The response message.</returns> /// <param name="request">The HTTP request message to send to the server.</param> /// <param name="cancellationToken">A cancellation token to cancel operation.</param> protected override async Task <HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken) { InternalContract.RequireNotNull(request, nameof(request)); SaveCorrelationIdToExecutionContext(request); var response = await base.SendAsync(request, cancellationToken); return(response); }
/// <summary> /// Read the correlation id header from the <paramref name="request"/> and save it to the execution context. /// </summary> /// <param name="request">The request that we will read the header from.</param> /// <returns></returns> /// <remarks>This method is made public for testing purposes. Should normally not be called from outside this class.</remarks> public void SaveCorrelationIdToExecutionContext(HttpRequestMessage request) { InternalContract.RequireNotNull(request, nameof(request)); var correlationId = ExtractCorrelationIdFromHeader(request); FulcrumAssert.IsNotNull(_correlationIdValueProvider, $"{Namespace}: 917BF2A8-1C68-45DB-BABB-C4331244C579"); _correlationIdValueProvider.CorrelationId = correlationId ?? Guid.NewGuid().ToString(); }
private string ToUrlParameter(Address address) { InternalContract.RequireNotNull(address, nameof(address)); InternalContract.RequireValidated(address, nameof(address)); var oneLine = $"{address.Row1}, {address.Row2}, {address.PostCode} {address.PostTown}, {address.Country}"; return(Uri.EscapeDataString(oneLine)); }
public async Task <GeocodingResponse> GeocodeAsync(Address address) { InternalContract.RequireNotNull(address, nameof(address)); InternalContract.RequireValidated(address, nameof(address)); var relativeUrl = $"/json?address={ToUrlParameter(address)}"; return(await _restClient.GetAsync <GeocodingResponse>(relativeUrl)); }
protected internal async Task <IEnumerable <TDatabaseItem> > QueryAsync(string statement, object param = null, CancellationToken token = default(CancellationToken)) { InternalContract.RequireNotNullOrWhitespace(statement, nameof(statement)); using (var db = Database.NewSqlConnection()) { return(await db.QueryAsync <TDatabaseItem>(statement, param)); } }
protected internal async Task ExecuteAsync(string statement, object param = null, CancellationToken token = default(CancellationToken)) { InternalContract.RequireNotNullOrWhitespace(statement, nameof(statement)); using (var db = Database.NewSqlConnection()) { await db.ExecuteAsync(statement, param); } }
/// <summary> /// This middleware is a collection of all the middleware features that are provided by Nexus Link. Use <paramref name="options"/> /// to specify exactly how they should behave. /// </summary> /// <param name="next">The inner handler</param> /// <param name="options">Options that controls which features to use and how they should behave.</param> public NexusLinkMiddleware(RequestDelegate next, IOptions <NexusLinkMiddlewareOptions> options) { InternalContract.RequireNotNull(options.Value, nameof(options)); InternalContract.RequireValidated(options.Value, nameof(options)); Next = next; Options = options.Value; }
/// <summary> /// Constructor /// </summary> public CircuitBreaker(CircuitBreakerOptions options) { InternalContract.RequireNotNull(options, nameof(options)); InternalContract.RequireValidated(options, nameof(options)); _options = options; _options.CoolDownStrategy.Reset(); _commonCancellationTokenSource = new CancellationTokenSource(); }
/// <summary> /// Parse a string into a <see cref="IConceptValue"/> object. /// </summary> /// <param name="path">The string to parse</param> public static IConceptValue Parse(string path) { if (!TryParse(path, out var result)) { InternalContract.Fail($"The path ({path}) could not be parsed as a concept value path."); } return(result); }
/// <summary> /// Constructor /// </summary> /// <param name="service"></param> /// <param name="symmetricEncryptionKey"></param> public CrudEncrypt(ICrudable <StorableAsByteArray <TModel, TId>, TId> service, byte[] symmetricEncryptionKey) : base(symmetricEncryptionKey) { InternalContract.RequireNotNull(service, nameof(service)); InternalContract.RequireNotNull(symmetricEncryptionKey, nameof(symmetricEncryptionKey)); _service = new CrudPassThrough <StorableAsByteArray <TModel, TId>, TId>(service); _convenience = new CrudConvenience <TModel, TModel, TId>(this); }
public override async Task ProcessHttpRequestAsync(HttpRequestMessage request, CancellationToken cancellationToken) { InternalContract.RequireNotNull(request, nameof(request)); var token = await GetJwtTokenAsync(); request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", token.AccessToken); await base.ProcessHttpRequestAsync(request, cancellationToken); }
/// <summary> /// Put the item in the cache. /// </summary> private async Task CacheSetAsync(TModel[] itemsArray, int limit, string key, CancellationToken token) { InternalContract.RequireNotDefaultValue(itemsArray, nameof(itemsArray)); var serializedCacheEnvelope = ToSerializedCacheEnvelope(itemsArray); await Cache.SetAsync(key, serializedCacheEnvelope, CacheOptions, token); _limitOfItemsInReadAllCache = limit; }
public Task <IProduct> ReadAsync(IConceptValue id) { InternalContract.RequireNotNull(id, nameof(id)); InternalContract.RequireValidated(id, nameof(id)); var dalProduct = await _productPersistance.ReadAsync(ToDal(id)).ConfigureAwait(false); return(FromDal(dalProduct)); }
/// <summary> /// Check if an item exists in the cache. /// </summary> /// <param name="id">The id for the item</param> /// <param name="token">Propagates notification that operations should be canceled</param> protected async Task <bool> CacheItemExistsAsync(TId id, CancellationToken token) { InternalContract.RequireNotDefaultValue(id, nameof(id)); var key = GetCacheKeyFromId(id); var cachedItem = await Cache.GetAsync(key, token); return(cachedItem != null); }
public static Guid ToGuid(this string source) { InternalContract.RequireNotNull(source, nameof(source)); var success = Guid.TryParse(source, out var valueAsGuid); InternalContract.Require(success, $"Could not parse parameter {nameof(source)} ({source}) of type {nameof(String)} into type {nameof(Guid)}."); return(valueAsGuid); }
public ValueTranslatorHttpSender(IHttpSender httpSender, string translationClientName) { InternalContract.RequireNotNull(httpSender, nameof(httpSender)); InternalContract.RequireNotNullOrWhiteSpace(translationClientName, nameof(translationClientName)); HttpSender = httpSender; TranslationClientName = translationClientName; }
public static int ToInt(this string source) { InternalContract.RequireNotNull(source, nameof(source)); var success = int.TryParse(source, out var valueAsInt); InternalContract.Require(success, $"Could not parse parameter {nameof(source)} ({source}) of type {nameof(String)} into type {nameof(Int32)}."); return(valueAsInt); }
private async Task <AuthenticationToken> FetchJwtFromPlatformTokenRefresher(CancellationToken cancellationToken = default) { InternalContract.RequireNotNull(PlatformTokenRefresher, nameof(PlatformTokenRefresher), $"In order to use {nameof(ClientAuthorizationSettings.AuthorizationTypeEnum.NexusPlatformService)} type," + $" configure {nameof(ServiceAuthenticationHelper)} with a {nameof(PlatformTokenRefresher)}"); return(await PlatformTokenRefresher.GetJwtTokenAsync(cancellationToken)); }
public Task <IStorableProduct> CreateAsync(IStorableProduct storableProduct) { InternalContract.RequireNotNull(storableProduct, nameof(storableProduct)); InternalContract.RequireValidated(storableProduct, nameof(storableProduct)); ThrowConflictIfProductWithIdExists(storableProduct.Id); return(Task.FromResult(storableProduct)); }
/// <summary> /// Find the items specified by the <paramref name="where"/> clause. /// </summary> /// <param name="param">The fields for the <paramref name="where"/> condition.</param> /// <param name="where">The search condition for the SELECT statement.</param> /// <param name="orderBy">An expression for how to order the result.</param> /// <param name="offset">The number of items that will be skipped in result.</param> /// <param name="limit">The maximum number of items to return.</param> /// <returns>The found items.</returns> protected async Task <IEnumerable <TDatabaseItem> > InternalSearchWhereAsync(object param, string where, string orderBy, int offset, int limit) { InternalContract.RequireGreaterThanOrEqualTo(0, offset, nameof(offset)); InternalContract.RequireGreaterThanOrEqualTo(0, limit, nameof(limit)); where = where ?? "1=1"; return(await InternalSearchAsync(param, $"SELECT * FROM [{TableMetadata.TableName}] WHERE ({where})", orderBy, offset, limit)); }
/// <inheritdoc /> public async Task <string> CreateAsync(Applicant item, CancellationToken token = new CancellationToken()) { InternalContract.RequireNotNull(item, nameof(item)); InternalContract.RequireValidated(item, nameof(item)); var lead = new Lead().From(item); var id = await _crmSystem.LeadFunctionality.CreateAsync(lead); return(id.ToIdString()); }
public AzureStorageTable(string connectionString, string name) { InternalContract.RequireNotNullOrWhiteSpace(connectionString, nameof(connectionString)); var storageAccount = CloudStorageAccount.Parse(connectionString); var client = storageAccount.CreateCloudTableClient(); FulcrumAssert.IsNotNull(client, null, "Could not create a cloud table client."); Table = client.GetTableReference(name); }