Ejemplo n.º 1
0
        /// <inheritdoc />
        public IDictionary <string, object> ExecuteNoParameters(string connectorName, string procedureName, ILoggingService loggingService = null)
        {
            loggingService?.AddSprocToLogger(connectorName, procedureName, HttpMethodType.GET);
            IOperationResource resource = ResourceFactory.GetResource(connectorName, OperationType.read, procedureName);

            return(resource.ExecuteProc(new Dictionary <string, object>()));
        }
Ejemplo n.º 2
0
        /// <inheritdoc />
        public StoredProcedureParameterDefinition Definition(string connectorName, string procedureName, string parameterName, ILoggingService loggingService = null)
        {
            loggingService?.AddSprocToLogger(connectorName, procedureName, HttpMethodType.GET);
            IOperationResource resource = ResourceFactory.GetResource(connectorName, OperationType.Any, procedureName);

            return(resource.GetStoredProcedureDefinition(parameterName));
        }
Ejemplo n.º 3
0
        /// <inheritdoc />
        public virtual ColumnDefinition Definition(string connectorName, string tableName, string columnName, ILoggingService loggingService = null)
        {
            loggingService?.AddTableToLogger(connectorName, tableName, HttpMethodType.GET);
            IOperationResource resource = ResourceFactory.GetResource(connectorName, OperationType.Any, tableName);

            return(resource.GetColumnDefinition(columnName));
        }
Ejemplo n.º 4
0
        /// <inheritdoc />
        public virtual IQueryable <TViewModel> GetAll <TViewModel>(string connectorName, string tableName, ILoggingService loggingService = null)
        {
            loggingService?.AddTableToLogger(connectorName, tableName, HttpMethodType.GET);
            IOperationResource resource = ResourceFactory.GetResource(connectorName, OperationType.read, tableName);

            //Manually $expand to prevent nulls on non pk joins
            var joinProperties = typeof(TViewModel).GetProperties()
                                 .Where(c => (c.PropertyType.IsClass && c.PropertyType != typeof(string)) ||
                                        (c.PropertyType.IsGenericType && c.PropertyType.GetGenericTypeDefinition() == typeof(IEnumerable <>)))
                                 .Select(c => c.Name);

            IQueryable <dynamic> list;

            if (joinProperties.Any())
            {
                list = resource.GetResourceRecords(new Dictionary <string, string>()
                {
                    { "$expand", string.Join(",", joinProperties) }
                });
            }
            else
            {
                list = resource.GetResourceRecords(new Dictionary <string, string>());
            }

            return(list.ProjectTo <TViewModel>());
        }
Ejemplo n.º 5
0
        /// <inheritdoc />
        public IQueryable <object> GetAll(string connectorName, string viewName, ILoggingService loggingService = null)
        {
            loggingService?.AddViewToLogger(connectorName, viewName);
            IOperationResource resource = ResourceFactory.GetResource(connectorName, OperationType.read, viewName);

            return(resource.GetViewRecords());
        }
Ejemplo n.º 6
0
        /// <inheritdoc />
        public (IQueryable <object> list, int recordLimit) GetAllAndRecordLimit(string connectorName, string viewName, ILoggingService loggingService = null)
        {
            loggingService?.AddViewToLogger(connectorName, viewName);
            IOperationResource resource = ResourceFactory.GetResource(connectorName, OperationType.read, viewName);

            return(resource.GetViewRecords(), resource.Connector.RecordLimit);
        }
Ejemplo n.º 7
0
        public IEnumerable <string> ListSchemas(string connectorName, ILoggingService loggingService = null)
        {
            loggingService?.AddSchemaToLogger(connectorName);
            IOperationResource resource = ResourceFactory.GetResource(connectorName, OperationType.Any, string.Empty);

            return(resource.ListSchemas());
        }
Ejemplo n.º 8
0
        /// <inheritdoc />
        public SchemaDefinition Definition(string connectorName, ILoggingService loggingService = null)
        {
            loggingService?.AddSchemaToLogger(connectorName);
            IOperationResource resource = ResourceFactory.GetResource(connectorName, OperationType.Any, string.Empty);

            return(resource.GetSchemaDefinition());
        }
Ejemplo n.º 9
0
        /// <inheritdoc />
        public virtual object DeleteRow(string connectorName, string tableName, ILoggingService loggingService, params object[] id)
        {
            loggingService?.AddTableToLogger(connectorName, tableName, HttpMethodType.DELETE, id);

            IOperationResource resource = ResourceFactory.GetResource(connectorName, OperationType.delete, tableName);

            return(resource.DeleteResourceRecordById(id));
        }
Ejemplo n.º 10
0
        /// <inheritdoc />
        public virtual object GetById(string connectorName, string tableName, ILoggingService loggingService, params object[] id)
        {
            loggingService?.AddTableToLogger(connectorName, tableName, HttpMethodType.GET, id);

            IOperationResource resource = ResourceFactory.GetResource(connectorName, OperationType.read, tableName);
            var data = resource.GetResourceRecordById(id);

            return(data);
        }
Ejemplo n.º 11
0
        /// <inheritdoc />
        public virtual TViewModel CreateNewRow <TViewModel>(string connectorName, string tableName, TViewModel value, ILoggingService loggingService = null) where TViewModel : class
        {
            loggingService?.AddTableToLogger(connectorName, tableName, HttpMethodType.POST);

            IOperationResource resource = ResourceFactory.GetResource(connectorName, OperationType.write, tableName);
            var data = resource.CreateNewResourceRecord(value);

            return(DynamicObjectExtensions.PopulateModel <TViewModel>(data));
        }
Ejemplo n.º 12
0
        /// <inheritdoc />
        public IDictionary <string, object> Execute(string connectorName, string procedureName, JToken parameters, ILoggingService loggingService = null)
        {
            loggingService?.AddSprocToLogger(connectorName, procedureName, HttpMethodType.POST);
            Check.NotNull(parameters, nameof(parameters));

            IOperationResource           resource            = ResourceFactory.GetResource(connectorName, OperationType.read, procedureName);
            IDictionary <string, object> parameterDictionary = (IDictionary <string, object>)parameters.JTokenToConventionalDotNetObject();

            return(resource.ExecuteProc(parameterDictionary));
        }
Ejemplo n.º 13
0
        /// <inheritdoc />
        public IDictionary <string, object> Execute <TViewModel>(string connectorName, string procedureName, TViewModel parameters, ILoggingService loggingService = null)
        {
            loggingService?.AddSprocToLogger(connectorName, procedureName, HttpMethodType.POST);
            IOperationResource           resource            = ResourceFactory.GetResource(connectorName, OperationType.read, procedureName);
            IDictionary <string, object> parameterDictionary = typeof(TViewModel)
                                                               .GetProperties(BindingFlags.Instance | BindingFlags.Public)
                                                               .ToDictionary(prop => prop.Name, prop => prop.GetValue(parameters, null));

            return(resource.ExecuteProc(parameterDictionary));
        }
Ejemplo n.º 14
0
        /// <inheritdoc />
        public virtual object CreateNewRow(string connectorName, string tableName, JToken value, ILoggingService loggingService = null)
        {
            loggingService?.AddTableToLogger(connectorName, tableName, HttpMethodType.POST);
            Check.NotNull(value, nameof(value));

            IOperationResource resource = ResourceFactory.GetResource(connectorName, OperationType.write, tableName);
            var data = resource.CreateNewResourceRecord(value);

            return(data);
        }
Ejemplo n.º 15
0
        /// <inheritdoc />
        public virtual (IQueryable <object> list, int connectorMax) GetAll(string connectorName, string tableName, ILoggingService loggingService = null)
        {
            Check.NotEmpty(connectorName, nameof(connectorName));
            Check.NotEmpty(tableName, nameof(tableName));

            loggingService?.AddTableToLogger(connectorName, tableName, HttpMethodType.GET);
            IOperationResource resource = ResourceFactory.GetResource(connectorName, OperationType.read, tableName);

            var queryString = _requestQuery.GetQueryStrings();

            return(resource.GetResourceRecords(queryString), resource.Connector.RecordLimit);
        }
Ejemplo n.º 16
0
        public virtual IServiceProvider GetOrAdd(IOperationResource resource, IServiceProvider rootProvider)
        {
            Check.NotNull(resource, nameof(resource));

            return(_configurations.GetOrAdd(
                       resource.ResourceType,
                       k =>
            {
                var service = new ServiceCollection();

                resource.ApplyServices(service, rootProvider);

                return service.BuildServiceProvider();
            }));
        }
Ejemplo n.º 17
0
        /// <inheritdoc />
        public virtual TViewModel UpdateRow <TViewModel>(string connectorName, string tableName, TViewModel value, ILoggingService loggingService = null) where TViewModel : class
        {
            IOperationResource resource = ResourceFactory.GetResource(connectorName, OperationType.write, tableName);

            object[] id = null;
            try
            {
                id = resource.GetPrimaryKeys(value);
            }
            catch (Exception)
            {
                throw;
            }
            finally
            {
                //Log even if values for PK not found
                loggingService?.AddTableToLogger(connectorName, tableName, HttpMethodType.PUT, id);
            }
            return(resource.UpdateResourceRecordById(value, id));
        }
Ejemplo n.º 18
0
        /// <inheritdoc />
        public virtual object UpdateRow(string connectorName, string tableName, JToken value, ILoggingService loggingService = null)
        {
            Check.NotNull(value, nameof(value));

            IOperationResource resource = ResourceFactory.GetResource(connectorName, OperationType.write, tableName);

            object[] id = null;
            try
            {
                id = resource.GetPrimaryKeys(value);
            }
            catch (Exception)
            {
                throw;
            }
            finally
            {
                //Log even if values for PK not found
                loggingService?.AddTableToLogger(connectorName, tableName, HttpMethodType.PUT, id);
            }
            return(resource.UpdateResourceRecordById(value, id));
        }
Ejemplo n.º 19
0
        /// <inheritdoc />
        public virtual TViewModel GetById <TViewModel>(string connectorName, string tableName, ILoggingService loggingService, params object[] id) where TViewModel : class
        {
            loggingService?.AddTableToLogger(connectorName, tableName, HttpMethodType.GET, id);

            //Manually $expand to prevent nulls on non pk joins
            var joinProperties = typeof(TViewModel).GetProperties()
                                 .Where(c => (c.PropertyType.IsClass && c.PropertyType != typeof(string)) ||
                                        (c.PropertyType.IsGenericType && c.PropertyType.GetGenericTypeDefinition() == typeof(IEnumerable <>)))
                                 .Select(c => c.Name);

            IOperationResource resource = ResourceFactory.GetResource(connectorName, OperationType.read, tableName);

            if (joinProperties.Any())
            {
                return(resource.GetResourceRecordById <TViewModel>(id, new Dictionary <string, string>()
                {
                    { "$expand", string.Join(",", joinProperties) }
                }));
            }
            else
            {
                return(resource.GetResourceRecordById <TViewModel>(id, new Dictionary <string, string>()));
            }
        }