Ejemplo n.º 1
0
        public ICommandResult <TOutput> Execute <TInput, TOutput>(
            IServiceProvider locator,
            ISerialization <TInput> input,
            ISerialization <TOutput> output,
            IPrincipal principal,
            TInput data)
        {
            var either = CommandResult <TOutput> .Check <Argument <TInput>, TInput>(input, output, data, CreateExampleArgument);

            if (either.Error != null)
            {
                return(either.Error);
            }
            var argument = either.Argument;

            var documentType = DomainModel.FindNested(argument.CubeName, argument.TemplaterName);

            if (documentType == null)
            {
                return(CommandResult <TOutput> .Fail(
                           "Couldn't find Templater type {0} for {1}.".With(argument.TemplaterName, argument.CubeName),
                           @"Example argument: 
" + CommandResult <TOutput> .ConvertToString(CreateExampleArgument(output))));
            }

            if (!Permissions.CanAccess(documentType.FullName, principal))
            {
                return(CommandResult <TOutput> .Forbidden("{0} in {1}.".With(argument.TemplaterName, argument.CubeName)));
            }
            if (!typeof(IDocumentReport <DataTable>).IsAssignableFrom(documentType))
            {
                return
                    (CommandResult <TOutput> .Fail(
                         "Templater type {0} for {1} is not IDocumentReport<DataTable>. Check {0}.".With(
                             documentType.FullName,
                             argument.CubeName),
                         null));
            }

            IDocumentReport <DataTable> report;

            try
            {
                report = locator.Resolve <IDocumentReport <DataTable> >(documentType);
            }
            catch (Exception ex)
            {
                return(CommandResult <TOutput> .Fail(
                           @"Can't create document report. Is report {0} registered in system?".With(documentType.FullName),
                           ex.GetDetailedExplanation()));
            }
            try
            {
                var table  = AnalyzeOlapCube.PopulateTable(input, output, locator, DomainModel, argument, principal, Permissions);
                var result = report.Create(table);
                return(CommandResult <TOutput> .Return(HttpStatusCode.Created, Serialize(output, result), "Report created"));
            }
            catch (ArgumentException ex)
            {
                return(CommandResult <TOutput> .Fail(
                           ex.Message,
                           ex.GetDetailedExplanation() + @"
Example argument: 
" + CommandResult <TOutput> .ConvertToString(CreateExampleArgument(output))));
            }
        }
Ejemplo n.º 2
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));
        }
Ejemplo n.º 3
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));
            }
        }