/// <inheritdoc/> public Task <ICreateResponse> CreateAsync <TDocument>(ICreateRequest <TDocument> request, CancellationToken cancellationToken = default(CancellationToken)) where TDocument : class => this.Dispatcher.DispatchAsync <ICreateRequest <TDocument>, CreateRequestParameters, CreateResponse, ICreateResponse>( request, cancellationToken, this.LowLevelDispatch.CreateDispatchAsync <CreateResponse, TDocument> );
public ICreateResponse Create(ICreateRequest request, IScope scope) { var value = request.Type.IsValueType ? Activator.CreateInstance(request.Type) : null; return(new CreatedObjectResponse(value)); }
public ICreateResponse Create(ICreateRequest request, IScope scope) { if (request.Type == typeof(T)) { return(new CreatedObjectResponse(GenerateProxy(scope))); } return(new NotCreatedResponse()); }
public ICreateResponse Create(ICreateRequest request, IScope scope) { if (request.Type != typeof(CancellationToken)) { return(new NotCreatedResponse()); } return(new CreatedObjectResponse(CancellationToken.None)); }
public ICreateResponse Create(ICreateRequest request, IScope scope) { if (request.Type == typeof(void)) { return(new CreatedVoidResponse()); } return(new NotCreatedResponse()); }
public ICreateResponse Create(ICreateRequest request, IScope scope) { if (typeof(T).IsAssignableFrom(request.Type)) { var obj = _func(scope); return(new CreatedObjectResponse(obj)); } return(new NotCreatedResponse()); }
public ICreateResponse Create(ICreateRequest request, IScope scope) { var randomValue = GenerateRandomValue(request.Type); if (randomValue == null) { return(new NotCreatedResponse()); } return(new CreatedObjectResponse(randomValue)); }
public ICreateResponse Create(ICreateRequest request, IScope scope) { if (request.Type != typeof(bool)) { return(new NotCreatedResponse()); } var randomBool = _random.Next(2) == 1; return(new CreatedObjectResponse(randomBool)); }
public ICreateResponse Create(ICreateRequest request, IScope scope) { if (request.Type != typeof(string)) { return(new NotCreatedResponse()); } var randomString = Guid.NewGuid().ToString(); return(new CreatedObjectResponse(randomString)); }
public ICreateResponse Create(ICreateRequest request, IScope scope) { if (!CanCreateObject(request.Type)) { return(new NotCreatedResponse()); } var interceptor = new ScopeInterceptor(scope); var createdObject = _proxyGenerator.CreateInterfaceProxyWithoutTarget(request.Type, interceptor); return(new CreatedObjectResponse(createdObject)); }
/// <summary> /// Adds a script to the request, with a parameter. /// </summary> /// <param name="request">The request. This is the 'this' parameter.</param> /// <param name="scriptName">Name of the script to be called.</param> /// <param name="scriptParameter">Script parameter.</param> /// <returns>The request instanced that was implicitly passed in which is useful for method chaining.</returns> public static ICreateRequest <T> SetScript <T>( this ICreateRequest <T> request, string scriptName, string scriptParameter = null) { request.Script = scriptName; if (!string.IsNullOrEmpty(scriptParameter)) { request.ScriptParameter = scriptParameter; } return(request); }
public object?CreateObject(ICreateRequest request, IScope creationScope) { var response = _factory.Create(request, creationScope); if (!response.HasCreated) { return(_parentScope.CreateObject(request, creationScope)); } _monitor.Log(request, response); return(response.CreatedObject); }
public ICreateResponse Create(ICreateRequest request, IScope scope) { if (!CanInstantiate(request.Type)) { return(new NotCreatedResponse()); } object instance = Instantiate(request.Type, scope); Hydrate(instance, scope); return(new CreatedObjectResponse(instance)); }
public ICreateResponse Create(ICreateRequest request, IScope scope) { if (!request.Type.IsOfGenericTypeDefinition(typeof(Nullable <>))) { return(new NotCreatedResponse()); } var innerType = Nullable.GetUnderlyingType(request.Type) ?? throw new Exception("Error finding underlying nullable type"); var createdObject = scope.CreateObjectFromType(innerType); return(new CreatedObjectResponse(createdObject)); }
public ICreateResponse Create(ICreateRequest request, IScope creationScope) { foreach (var factory in _innerFactories) { var response = factory.Create(request, creationScope); if (response.HasCreated) { return(response); } } return(new NotCreatedResponse()); }
public ICreateResponse Create(ICreateRequest request, IScope scope) { var enumerableInterfaceType = request.Type.GetGenericInterface(typeof(IEnumerable <>)); if (enumerableInterfaceType == null) { return(new NotCreatedResponse()); } var innerType = enumerableInterfaceType.GenericTypeArguments[0]; var enumerable = Activator.CreateInstance(typeof(FactoryEnumerable <>).MakeGenericType(innerType), scope); var createdObject = innerType; return(new CreatedObjectResponse(createdObject)); }
/// <summary> /// Executes a Create Record Request /// </summary> /// <typeparam name="T">The projected type to be created.</typeparam> /// <param name="req">The request record command.</param> /// <returns>A response containing the results of the operation.</returns> public async override Task <ICreateResponse> SendAsync <T>(ICreateRequest <T> req) { HttpResponseMessage response = await ExecuteRequestAsync(req); if (response.IsSuccessStatusCode) { // process response data return OK var resp = new CreateResponse { Messages = new List <ResponseMessage> { new ResponseMessage { Code = "", Message = "OK" } } }; return(resp); } throw new Exception("Unable to complete request"); }
public ICreateResponse Create(ICreateRequest request, IScope scope) { if (scope == _innerScope) { return(new NotCreatedResponse()); } if (!_filter(request)) { return(new NotCreatedResponse()); } var obj = _innerScope.CreateObject(request); if (obj != null) { return(new CreatedObjectResponse(obj)); } return(new NotCreatedResponse()); }
/// <summary> /// Create a record in the database using the CreateRequest object. /// </summary> /// <typeparam name="T">The underlying type of record being created.</typeparam> /// <param name="req">The request object containing the data to be sent.</param> /// <returns></returns> public override async Task <ICreateResponse> SendAsync <T>(ICreateRequest <T> req) { if (string.IsNullOrEmpty(req.Layout)) { throw new ArgumentException("Layout is required on the request."); } var responseMessage = await ExecuteRequestAsync(req); try { var responseJson = await responseMessage.Content.ReadAsStringAsync(); return(JsonConvert.DeserializeObject <CreateResponse>(responseJson)); } catch (Exception ex) { // something bad happened. TODO: improve non-OK response handling throw new Exception($"Non-OK Response: Status = {responseMessage.StatusCode}.", ex); } }
public ICreateResponse Create(ICreateRequest request, IScope scope) { if (request.Type == (typeof(Task))) { return(new CreatedObjectResponse(Task.CompletedTask)); } var taskType = request.Type.GetGenericSubclass(typeof(Task <>)); if (taskType == null) { return(new NotCreatedResponse()); } var innerType = taskType.GenericTypeArguments[0]; var createdObject = scope.CreateObjectFromType(innerType); var taskResult = typeof(Task).GetMethod(nameof(Task.FromResult)) ! .Invoke(null, new object?[] { createdObject }); return(new CreatedObjectResponse(taskResult)); }
/// <summary> /// Helper For Getting Raw Responses from Data API. /// </summary> public Task <HttpResponseMessage> ExecuteRequestAsync <T>(ICreateRequest <T> req) => ExecuteRequestAsync(HttpMethod.Post, CreateEndpoint(req.Layout), req);
/// <summary> /// Specify a layout to use for this request. /// </summary> /// <param name="request">The request. This is the 'this' parameter.</param> /// <param name="instance">Object to pull the layout from using its DataContract attribute.</param> /// <typeparam name="T">The type used for the create request/response.</typeparam> /// <returns>The request instanced that was implicitly passed in which is useful for method chaining.</returns> public static ICreateRequest <T> UseLayout <T>(this ICreateRequest <T> request, T instance) { request.Layout = FileMakerApiClientBase.GetLayoutName(instance); return(request); }
/// <summary> /// Send a Create Record request to the FileMaker API. /// </summary> public abstract Task <ICreateResponse> SendAsync <T>(ICreateRequest <T> req) where T : class, new();
/// <summary> /// Set the data for this request. /// </summary> /// <param name="request">The request. This is the 'this' parameter.</param> /// <param name="data">Object containing the data for this find request record.</param> /// <typeparam name="T">The type used for the create request/response.</typeparam> /// <returns>The request instanced that was implicitly passed in which is useful for method chaining.</returns> public static ICreateRequest <T> SetData <T>(this ICreateRequest <T> request, T data) { request.Data = data; return(request); }
/// <summary> /// Specify a layout to use for this request. /// </summary> /// <param name="request">The request. This is the 'this' parameter.</param> /// <param name="layout">Name of the layout to use</param> /// <typeparam name="T">The type used for the create request/response.</typeparam> /// <returns>The request instanced that was implicitly passed in which is useful for method chaining.</returns> public static ICreateRequest <T> UseLayout <T>(this ICreateRequest <T> request, string layout) { request.Layout = layout; return(request); }
public Task <CreateResponse> CreateAsync <TDocument>(ICreateRequest <TDocument> request, CancellationToken ct = new CancellationToken()) where TDocument : class { throw new NotImplementedException(); }
public CreateResponse Create <TDocument>(ICreateRequest <TDocument> request) where TDocument : class { throw new NotImplementedException(); }
public CreateResponse RunCreateRequest(ICreateRequest request) { _Data.WebShopRecordSet = DataHelper.CreateRecords(_Data.WebShopRecordSet, request.RecordSet); return(new CreateResponse(request)); }
/// <inheritdoc /> public CreateResponse Create <TDocument>(ICreateRequest <TDocument> request) where TDocument : class => DoRequest <ICreateRequest <TDocument>, CreateResponse>(request, request.RequestParameters);
/// <inheritdoc /> public Task <CreateResponse> CreateAsync <TDocument>(ICreateRequest <TDocument> request, CancellationToken ct = default) where TDocument : class => DoRequestAsync <ICreateRequest <TDocument>, CreateResponse>(request, request.RequestParameters, ct);