示例#1
0
        public static IServiceCollection AddBusinessLogic(this IServiceCollection services)
        {
            var operatorBuilder = new OperatorBuilder();

            // Set the default operator implementations. This should be done first.
            operatorBuilder.SetDefaultAsyncGetOperatorTypes(typeof(AsyncGetOperator <>), typeof(AsyncGetOperator <,>));
            operatorBuilder.SetDefaultAsyncQueryOperatorTypes(typeof(AsyncQueryOperator <>), typeof(AsyncQueryOperator <,>));
            operatorBuilder.SetDefaultAsyncAddOperatorTypes(typeof(AsyncAddOperator <>), typeof(AsyncAddOperator <,>));
            operatorBuilder.SetDefaultAsyncUpdateOperatorTypes(typeof(AsyncUpdateOperator <>), typeof(AsyncUpdateOperator <,>));
            operatorBuilder.SetDefaultAsyncDeleteOperatorTypes(typeof(AsyncDeleteOperator <>), typeof(AsyncDeleteOperator <,>));

            // Configure operators in one time for the Home entity
            operatorBuilder.ConfigureAsyncCrudOperators <Home>()
            .WithValidation <HomeValidator>()
            .WithPostprocessing <HomePostprocessor>();

            // Configure operators and their decorators separately for Person entity
            operatorBuilder.ConfigureAsyncGetOperator <Person, GetPersonInput>()
            .WithPreprocessing <PersonPreprocessor>();
            operatorBuilder.ConfigureAsyncQueryOperator <Person>()
            .WithPreprocessing <PersonPreprocessor>();
            operatorBuilder.ConfigureAsyncAddOperator <Person>()
            .WithValidation <PersonValidator>();
            operatorBuilder.ConfigureAsyncUpdateOperator <Person>()
            .WithValidation <PersonValidator>();
            operatorBuilder.ConfigureAsyncDeleteOperator <Person, int?, object>(serviceProvider => new AsyncPersonDeleteOperator(serviceProvider.GetRequiredService <IUnitOfWorkScope>()))
            .WithValidation <PersonValidator>();

            // Add all configured operators to the servicecollection
            operatorBuilder.AddOperators(services);

            return(services);
        }
示例#2
0
        public void closeAllReplicas()
        {
            List <string> replicasNames = operatorsInfo.OperatorNames;
            List <Task>   TaskList      = new List <Task>();

            // To prevent the execution of the remaining commands
            Monitor.Enter(commandsToRun.SyncRoot);
            commandsToRun.Clear();
            Monitor.PulseAll(commandsToRun.SyncRoot);
            Monitor.Exit(commandsToRun.SyncRoot);

            foreach (string name in replicasNames)
            {
                OperatorBuilder ob        = operatorsInfo.getOpInfo(name);
                int             repFactor = ob.RepFactor;

                for (int i = 0; i < repFactor; i++)
                {
                    string crashLine = "crash " + name + " " + i;
                    AddMsgToLog(crashLine);

                    var LastTask = new Task(() => shell.run(crashLine));
                    LastTask.Start();
                    TaskList.Add(LastTask);
                }
            }
            Task.WaitAll(TaskList.ToArray());

            consumer.Abort();
        }
    public void BuildsStructExpressionFromBuilderTree()
    {
        var paramInput   = Expression.Parameter(typeof(float), "testP");
        var operatorData = OperatorBuilder.Binary(OperatorType.MULTIPLY,
                                                  OperatorBuilder.ConstantValue(1.5f),
                                                  OperatorBuilder.ParameterReference(paramInput));

        var builder = new DynamicExpressionData(operatorData, new ParameterExpression[] { paramInput });

        using var nativeOpData = new NativeArray <OperatorDefinition>(builder.OperatorSpaceNeeded, Allocator.Persistent);
        using var inputParams  = new NativeArray <float>(new float[] { 2f }, Allocator.Persistent);
        var opDataSpace = new JaggedIndexing
        {
            index  = 0,
            length = builder.OperatorSpaceNeeded
        };
        var expression = builder.WriteIntoOpDataArray(
            nativeOpData,
            opDataSpace);

        var result = expression.EvaluateExpression(
            inputParams,
            new JaggedIndexing
        {
            index  = 0,
            length = 1
        },
            nativeOpData);

        Assert.AreEqual(3f, result);
    }
示例#4
0
        private void callAllOperators()
        {
            List <Task> taskList = new List <Task>();

            foreach (string name in operatorsInfo.OperatorNames)
            {
                OperatorBuilder opb      = operatorsInfo.getOpInfo(name);
                Task            lastTask = new Task(() => callAllReplicas(opb));
                lastTask.Start();
                taskList.Add(lastTask);
            }
            Task.WaitAll(taskList.ToArray());
        }
示例#5
0
        private void callAllReplicas(OperatorBuilder opb)
        {
            List <Task> taskList = new List <Task>();

            for (int i = 0; i < opb.Addresses.Count; i++)
            {
                string address  = opb.Addresses[i];
                Task   lastTask = new Task(() => callSpecificReplica(address));
                lastTask.Start();
                taskList.Add(lastTask);
            }
            Task.WaitAll(taskList.ToArray());
        }
        public void LoanApplication_WithoutScore_CannotBeAccepted()
        {
            var application = new LoanApplicationBuilder()
                              .WithCustomer(customer => customer.WithAge(25).WithIncome(15_000M))
                              .WithLoan(loan => loan.WithAmount(200_000).WithNumberOfYears(25).WithInterestRate(1.1M))
                              .WithProperty(prop => prop.WithValue(250_000M))
                              .NotEvaluated()
                              .Build();

            var user = new OperatorBuilder().WithLogin("admin").Build();
            var ex   = Assert.Throws <ApplicationException>(() => application.Accept(user));

            Assert.Equal("Cannot accept application before scoring", ex.Message);
        }
示例#7
0
        private void contactReplicas()
        {
            foreach (string opName in operatorsInfo.OperatorNames)
            {
                OperatorBuilder opb             = operatorsInfo.getOpInfo(opName);
                string          routing         = null;
                string          incomingRouting = null;
                List <string>   output          = null;
                List <string>   input           = null;
                List <string>   operation       = new List <string>();

                // Setting the common parameters between replicas
                try {
                    routing         = operatorsInfo.getMyRouting(opb.Name);
                    incomingRouting = operatorsInfo.getMyIncomingRouting(opb.Name);
                    output          = operatorsInfo.getOuputAddressesListOfOP(opb.Name);
                    input           = operatorsInfo.getInputAddressesListOfOP(opb.Name);
                } catch (LastOperatorException) {
                    routing         = "primary";
                    incomingRouting = "primary";
                    output          = new List <string>();
                    input           = new List <string>();
                }

                operation.Add(opb.OperatorType);
                operation.Add(string.Join(",", opb.SpecificParameters));

                // Contacting all the operator's PCS
                for (int i = 0; i < opb.RepFactor; i++)
                {
                    Console.WriteLine("- Replica number " + i);
                    Console.WriteLine("Machine Address: {0}\t port: {1}", urlsplitter.getAddress(opb.Addresses[i]), urlsplitter.getPort(opb.Addresses[i]));

                    string address = urlsplitter.getAddress(opb.Addresses[i]);
                    Console.WriteLine("Calling PCS on address " + address);

                    try {
                        CommonClasses.IProcessCreator obj = (CommonClasses.IProcessCreator)Activator.GetObject(typeof(CommonClasses.IProcessCreator),
                                                                                                               "tcp://" + address + ":" + PCS_RESERVED_PORT + "/ProcessCreator");

                        obj.createReplica("tcp://" + puppetMasterIPAddress.ToString() + ":" + LOGGING_PORT.ToString(),
                                          routing, incomingRouting, semantics, loggingLevel, i, operation, opb.Addresses, output, input);
                    }
                    catch (System.Net.Sockets.SocketException e) {
                        Console.WriteLine("Error with host " + address);
                        Console.WriteLine("Exception " + e);
                    }
                }
            }
        }
        public void LoanApplication_Accepted_CannotBeRejected()
        {
            var application = new LoanApplicationBuilder()
                              .WithCustomer(customer => customer.WithAge(25).WithIncome(15_000M))
                              .WithLoan(loan => loan.WithAmount(200_000).WithNumberOfYears(25).WithInterestRate(1.1M))
                              .WithProperty(prop => prop.WithValue(250_000M))
                              .Evaluated()
                              .Accepted()
                              .Build();

            var user = new OperatorBuilder().WithLogin("admin").Build();
            var ex   = Assert.Throws <ApplicationException>(() => application.Reject(user));

            Assert.Equal("Cannot reject application that is already accepted or rejected", ex.Message);
        }
    public void BuildsLinqExpressionFromBuilderTree()
    {
        var paramInput   = Expression.Parameter(typeof(float), "testP");
        var operatorData = OperatorBuilder.Binary(OperatorType.MULTIPLY,
                                                  OperatorBuilder.ConstantValue(1.5f),
                                                  OperatorBuilder.ParameterReference(paramInput));

        var expression = operatorData.CompileToLinqExpression();
        var lambdaExpr = Expression.Lambda(expression, paramInput);
        var fun        = lambdaExpr.Compile();

        var result = fun.DynamicInvoke(2f);

        Assert.AreEqual(3f, result);
    }
        public void LoanApplication_WithoutScore_CanBeRejected()
        {
            var application = new LoanApplicationBuilder()
                              .WithCustomer(customer => customer.WithAge(25).WithIncome(15_000M))
                              .WithLoan(loan => loan.WithAmount(200_000).WithNumberOfYears(25).WithInterestRate(1.1M))
                              .WithProperty(prop => prop.WithValue(250_000M))
                              .NotEvaluated()
                              .Build();

            var user = new OperatorBuilder().WithLogin("admin").Build();

            application.Reject(user);

            LoanApplicationAssert.That(application)
            .IsInStatus(LoanApplicationStatus.Rejected)
            .ScoreIsNull();
        }
        public void LoanApplication_InStatusNew_EvaluatedGreen_OperatorDoesNotHaveCompetenceLevel_CannotBeAccepted()
        {
            var application = new LoanApplicationBuilder()
                              .WithCustomer(customer => customer.WithAge(25).WithIncome(15_000M))
                              .WithLoan(loan => loan.WithAmount(200_000).WithNumberOfYears(25).WithInterestRate(1.1M))
                              .WithProperty(prop => prop.WithValue(250_000M))
                              .Evaluated()
                              .Build();

            var user = new OperatorBuilder()
                       .WithLogin("admin")
                       .WithCompetenceLevel(100_000M)
                       .Build();

            var ex = Assert.Throws <ApplicationException>(() => application.Accept(user));

            Assert.Equal("Operator does not have required competence level to accept application", ex.Message);
        }
        public void LoanApplication_InStatusNew_EvaluatedGreen_OperatorHasCompetenceLevel_CanBeAccepted()
        {
            var application = new LoanApplicationBuilder()
                              .WithCustomer(customer => customer.WithAge(25).WithIncome(15_000M))
                              .WithLoan(loan => loan.WithAmount(200_000).WithNumberOfYears(25).WithInterestRate(1.1M))
                              .WithProperty(prop => prop.WithValue(250_000M))
                              .Evaluated()
                              .Build();

            var user = new OperatorBuilder()
                       .WithLogin("admin")
                       .WithCompetenceLevel(1_000_000M)
                       .Build();

            application.Accept(user);

            LoanApplicationAssert.That(application)
            .IsInStatus(LoanApplicationStatus.Accepted)
            .ScoreIs(ApplicationScore.Green);
        }
示例#13
0
        private void runConfigCommands(List <string> lines)
        {
            if (alreadyRunConfigCommands)
            {
                return;
            }

            alreadyRunConfigCommands = true;
            foreach (var line in lines)
            {
                AddMsgToLog(line);
                //ConsoleBox.AppendText(line + "\r\n");

                LineParser ln = new LineParser(line);
                Debug.WriteLine(ln.Words[0]);
                switch (ln.Words[0])
                {
                case "Semantics":
                    semantics = ln.Words[1];
                    break;

                case "LoggingLevel":
                    loggingLevel = ln.Words[1];
                    break;

                default:
                    OperatorBuilder opb = new OperatorBuilder(ln.Words.ToList());

                    //Use Name and Input to create a graph/map to know the next node  **step 1
                    operatorsInfo.addNewOP(opb);
                    Debug.WriteLine("created fields association " + opb.Name);
                    break;
                }
            }

            shell = new Shell(operatorsInfo);

            firstOPName = operatorsInfo.getFirstOperator();

            contactReplicas();
        }