示例#1
0
        public void Listen(string domainObject)
        {
            if (!IsRunning)
            {
                Clients.Caller.Error("In shutdown. Try again later");
                return;
            }
            var found = Model.Find(domainObject);

            if (found == null ||
                !typeof(IAggregateRoot).IsAssignableFrom(found) && !typeof(IDomainEvent).IsAssignableFrom(found))
            {
                Clients.Caller.Error("Unknown object " + domainObject);
                return;
            }
            var rl  = (IListener)Activator.CreateInstance(typeof(DomainObjectListen <>).MakeGenericType(found));
            var cid = Context.ConnectionId;

            if (rl.Register(cid, ids => NotifyDomainObjectChanges(cid, domainObject, ids)))
            {
                Clients.Caller.Success("Registered for " + domainObject);
            }
            else
            {
                Clients.Caller.Error("Error registering for " + domainObject);
            }
        }
示例#2
0
        public Stream Read(string domainObject, string uri)
        {
            var type = DomainModel.Find(domainObject);

            if (type != null && typeof(IAggregateRoot).IsAssignableFrom(type))
            {
                return(CachingService.ReadFromCache(type, uri, Locator));
            }
            return(CrudComands.Read(domainObject, uri));
        }
示例#3
0
        public Stream Find(string domainObject, string uris)
        {
            var type = DomainModel.Find(domainObject);

            if (type != null && typeof(IAggregateRoot).IsAssignableFrom(type))
            {
                return(CachingService.ReadFromCache(type, (uris ?? string.Empty).Split(','), false, Locator));
            }
            return(DomainCommands.Find(domainObject, uris));
        }
示例#4
0
        public static Type FindDataSourceAndCheckPermissions(
            this IDomainModel DomainModel,
            IPermissionManager Permissions,
            IPrincipal principal,
            string domainName)
        {
            if (string.IsNullOrEmpty(domainName))
            {
                throw new ArgumentException("Domain object name not provided.");
            }
            var domainObjectType = DomainModel.Find(domainName);

            if (domainObjectType == null)
            {
                throw new ArgumentException("Couldn't find domain object: {0}".With(domainName));
            }
            if (!typeof(IDataSource).IsAssignableFrom(domainObjectType))
            {
                throw new ArgumentException(@"Specified type ({0}) is not a data source. 
Please check your arguments.".With(domainName));
            }
            if (!Permissions.CanAccess(domainObjectType.FullName, principal))
            {
                throw new SecurityException("You don't have permission to access: {0}.".With(domainName));
            }
            return(domainObjectType);
        }
示例#5
0
        public static Either <Type> CheckDomainObject(IDomainModel domainModel, Either <Type> parentType, string name)
        {
            if (parentType.IsFailure)
            {
                return(parentType);
            }
            if (name == null)
            {
                return(Either <Type> .Empty);
            }
            var type = name.Contains("+") ? domainModel.Find(name) : domainModel.Find(parentType.Result.FullName + "+" + name);

            if (type == null)
            {
                return("Can't find domain object: " + name);
            }
            return(type);
        }
示例#6
0
        public static Try <Type> CheckDomainObject(IDomainModel domainModel, Try <Type> parentType, string name, HttpResponse response)
        {
            if (parentType.IsFailure)
            {
                return(Try <Type> .Error);
            }
            if (name == null)
            {
                return(Try <Type> .Empty);
            }
            var type = name.Contains("+") ? domainModel.Find(name) : domainModel.Find(parentType.Result.FullName + "+" + name);

            if (type == null)
            {
                return(Try.Fail <Type>("Can't find domain object: " + name, response));
            }
            return(type);
        }
示例#7
0
        public static Either <Type> CheckDomainObject(IDomainModel domainModel, string name)
        {
            var type = domainModel.Find(name);

            if (type == null)
            {
                return("Can't find domain object: " + name);
            }
            return(type);
        }
示例#8
0
        public static Try <Type> CheckDomainObject(IDomainModel domainModel, string name, HttpResponse response)
        {
            var type = domainModel.Find(name);

            if (type == null)
            {
                return(Try.Fail <Type>("Can't find domain object: " + name, response));
            }
            return(type);
        }
示例#9
0
        public static Type CheckDomainObject(IDomainModel domainModel, string name)
        {
            var type = domainModel.Find(name);

            if (type == null)
            {
                Utility.ThrowError("Can't find domain object: {0}".With(name), HttpStatusCode.BadRequest);
            }
            return(type);
        }
示例#10
0
        public static Either <KeyValuePair <Type, Type> > CheckCube(IDomainModel domainModel, string name)
        {
            var type = domainModel.Find(name);

            if (type == null)
            {
                return("Can't find olap cube: " + name);
            }
            var findImpl = type.GetInterfaces().FirstOrDefault(it => it.IsGenericType && it.GetGenericTypeDefinition() == typeof(IOlapCubeQuery <>));

            if (findImpl == null)
            {
                return(name + " is not an olap cube.");
            }
            return(new KeyValuePair <Type, Type>(type, findImpl.GetGenericArguments()[0]));
        }
示例#11
0
        public static KeyValuePair <Type, Type> CheckCube(IDomainModel domainModel, string name)
        {
            var type = domainModel.Find(name);

            if (type == null)
            {
                Utility.ThrowError("Can't find olap cube: {0}".With(name), HttpStatusCode.BadRequest);
            }
            if (!typeof(IOlapCubeQuery).IsAssignableFrom(type))
            {
                Utility.ThrowError("{0} is not an olap cube.".With(name), HttpStatusCode.BadRequest);
            }
            //TODO ugly hack. fix later
            var prop   = type.GetProperty("DataSource");
            var source = prop != null ? (Type)prop.GetValue(null, null) : null;

            return(new KeyValuePair <Type, Type>(type, source));
        }
示例#12
0
        public static Either <KeyValuePair <Type, Type> > CheckCube(IDomainModel domainModel, string name)
        {
            var type = domainModel.Find(name);

            if (type == null)
            {
                return("Can't find olap cube: " + name);
            }
            if (!typeof(IOlapCubeQuery).IsAssignableFrom(type))
            {
                return(name + " is not an olap cube.");
            }
            //TODO ugly hack. fix later
            var prop   = type.GetProperty("DataSource");
            var source = prop != null ? (Type)prop.GetValue(null, null) : null;

            if (source == null)
            {
                return(Either <KeyValuePair <Type, Type> > .Fail("Cube data source not found. Static DataSource property not found.", HttpStatusCode.NotImplemented));
            }
            return(new KeyValuePair <Type, Type>(type, source));
        }
示例#13
0
        public Task Handle(HttpContext context, int prefixLength)
        {
            var path = context.Request.Path.Value;

            if (path.Length == prefixLength)
            {
                return(context.Response.WriteError("Domain object not specified", HttpStatusCode.BadRequest));
            }
            var name = path.Substring(prefixLength + 1);
            var type = DomainModel.Find(name);

            if (type == null)
            {
                return(Utility.WriteError(context.Response, $"Can't find domain object: {name}", HttpStatusCode.BadRequest));
            }
            if (!typeof(IIdentifiable).IsAssignableFrom(type))
            {
                return(Utility.WriteError(context.Response, $"Invalid domain object: {name}", HttpStatusCode.BadRequest));
            }
            switch (context.Request.Method)
            {
            case "POST":
                return(Create(type, context));

            case "GET":
                return(Read(name, context));

            case "PUT":
                return(Update(type, context));

            case "DELETE":
                return(Delete(type, context));

            default:
                return(Utility.WriteError(context.Response, "Unsuported method type", HttpStatusCode.MethodNotAllowed));
            }
        }
示例#14
0
        public static DataTable PopulateTable <TInput, TOutput>(
            ISerialization <TInput> input,
            ISerialization <TOutput> output,
            IServiceProvider Locator,
            IDomainModel DomainModel,
            Argument <TInput> argument,
            IPrincipal principal,
            IPermissionManager permissions)
        {
            var cubeType = DomainModel.Find(argument.CubeName);

            if (cubeType == null)
            {
                throw new ArgumentException(
                          "Couldn't find cube type {0}.".With(argument.CubeName),
                          new FrameworkException(@"Example argument: 
" + CommandResult <TOutput> .ConvertToString(CreateExampleArgument(output))));
            }

            if (!permissions.CanAccess(cubeType.FullName, principal))
            {
                throw new SecurityException("You don't have permission to access: {0}.".With(argument.CubeName));
            }

            var findImpl = cubeType.GetInterfaces().FirstOrDefault(it => it.IsGenericType && it.GetGenericTypeDefinition() == typeof(IOlapCubeQuery <>));

            if (findImpl == null)
            {
                throw new ArgumentException("Cube type {0} is not IOlapCubeQuery<>.".With(cubeType.FullName));
            }

            var sourceType = findImpl.GetGenericArguments()[0];

            IAnalyzeData command;

            if (string.IsNullOrEmpty(argument.SpecificationName))
            {
                var commandType = typeof(AnalyzeSpecification <,>).MakeGenericType(cubeType, sourceType);
                command = (IAnalyzeData)Activator.CreateInstance(commandType);
            }
            else
            {
                var specificationType =
                    DomainModel.FindNested(argument.CubeName, argument.SpecificationName)
                    ?? DomainModel.Find(argument.SpecificationName);
                if (specificationType == null)
                {
                    throw new ArgumentException("Couldn't find specification: {0}".With(argument.SpecificationName));
                }
                var commandType = typeof(AnalyzeWithSpecification <, ,>).MakeGenericType(cubeType, sourceType, specificationType);
                command = (IAnalyzeData)Activator.CreateInstance(commandType);
            }
            return
                (command.Analyze(
                     input,
                     Locator,
                     argument.Dimensions,
                     argument.Facts,
                     argument.Order,
                     argument.Limit,
                     argument.Offset,
                     argument.Specification));
        }
示例#15
0
 public static Type FindNested(this IDomainModel dom, string type, string name)
 {
     return(dom.Find(string.Format(CultureInfo.InvariantCulture, "{0}+{1}", type, name)));
 }
示例#16
0
        public static DataTable PopulateTable <TInput, TOutput>(
            ISerialization <TInput> input,
            ISerialization <TOutput> output,
            IServiceLocator Locator,
            IDomainModel DomainModel,
            Argument <TInput> argument,
            IPermissionManager Permissions)
        {
            var cubeType = DomainModel.Find(argument.CubeName);

            if (cubeType == null)
            {
                throw new ArgumentException(
                          "Couldn't find cube type {0}.".With(argument.CubeName),
                          new FrameworkException(@"Example argument: 
" + CommandResult <TOutput> .ConvertToString(CreateExampleArgument(output))));
            }

            if (!Permissions.CanAccess(cubeType))
            {
                throw new SecurityException("You don't have permission to access: {0}.".With(argument.CubeName));
            }

            if (!typeof(IOlapCubeQuery).IsAssignableFrom(cubeType))
            {
                throw new ArgumentException("Cube type {0} is not IOlapCubeQuery.".With(cubeType.FullName));
            }

            IOlapCubeQuery query;

            try
            {
                query = Locator.Resolve <IOlapCubeQuery>(cubeType);
            }
            catch (Exception ex)
            {
                throw new ArgumentException(
                          "Can't create cube query. Is query {0} registered in system?".With(cubeType.FullName),
                          ex);
            }

            if (string.IsNullOrEmpty(argument.SpecificationName) && argument.Specification == null)
            {
                return(query.Analyze(argument.Dimensions, argument.Facts, argument.Order, argument.Limit, argument.Offset));
            }
            else if (string.IsNullOrEmpty(argument.SpecificationName))
            {
                dynamic specification;
                try
                {
                    specification = input.Deserialize <TInput, dynamic>(argument.Specification, Locator);
                }
                catch (Exception ex)
                {
                    throw new ArgumentException(
                              "Specification could not be deserialized.",
                              new FrameworkException(@"Please provide specification name. Error: {0}.".With(ex.Message), ex));
                }
                if (specification == null)
                {
                    throw new ArgumentException(
                              "Specification could not be deserialized.",
                              new FrameworkException("Please provide specification name."));
                }
                return(query.Analyze(argument.Dimensions, argument.Facts, argument.Order, specification, argument.Limit, argument.Offset));
            }
            else
            {
                var specificationType =
                    DomainModel.FindNested(argument.CubeName, argument.SpecificationName)
                    ?? DomainModel.Find(argument.SpecificationName);
                if (specificationType == null)
                {
                    throw new ArgumentException("Couldn't find specification: {0}".With(argument.SpecificationName));
                }
                var commandType = typeof(AnalyzeWithSpecification <>).MakeGenericType(specificationType);
                var command     = (IAnalyzeData)Activator.CreateInstance(commandType);
                return
                    (command.Analyze(
                         input,
                         Locator,
                         query,
                         argument.Dimensions,
                         argument.Facts,
                         argument.Order,
                         argument.Limit,
                         argument.Offset,
                         argument.Specification));
            }
        }