public Result <List <Method> > CreateMethods(CreateMethods createMethods)
        {
            List <Method> methods = createMethods.Methods.Select(m =>
                                                                 new Method(m.Creator, m.Name, m.ApplicationRate)).ToList();

            MethodValidator methodValidator = new MethodValidator();
            List <string>   errors          = new List <string>();

            foreach (var method in methods)
            {
                var validationResult = methodValidator.Validate(method);

                if (!validationResult.IsValid)
                {
                    errors.AddRange(validationResult.Errors.Select(e => e.ToString()));
                }
            }

            if (errors.Count() > 0)
            {
                return(Result.Fail <List <Method> >(string.Join(" ", errors)));
            }

            foreach (var method in methods)
            {
                method.SetId(++lastIdValue);
                methodsMemoryDatabase.Add(method);
            }

            return(Result.Ok <List <Method> >(methods));
        }
        public IActionResult CreateExperimentWithMethods(ExperimentWithMethodsDTO experimentWithMethodsDTO)
        {
            long loggedInUserId = GetLoggedInUserIdMockUp();

            if (loggedInUserId == -1)
            {
                return(Unauthorized());
            }

            CreateExperiment createExperiment =
                new CreateExperiment(experimentWithMethodsDTO.Experiment.Creator, experimentWithMethodsDTO.Experiment.Name, loggedInUserId);

            List <CreateMethod> createMethods = new List <CreateMethod>();

            foreach (var methodDTO in experimentWithMethodsDTO.Methods)
            {
                CreateMethod createMethod = new CreateMethod(methodDTO.Creator, methodDTO.Name, methodDTO.ApplicationRate, loggedInUserId);
                createMethods.Add(createMethod);
            }

            CreateMethods createMethodsCommand = new CreateMethods(createMethods, loggedInUserId);

            Guid sagaId = Guid.NewGuid();

            StartCreatingExperimentWithMethods startCreatingExperimentWithMethods =
                new StartCreatingExperimentWithMethods(createExperiment, createMethodsCommand, loggedInUserId, sagaId);

            _kafkaProducer.Produce(startCreatingExperimentWithMethods, EXPERIMENTS_TOPIC);

            _logger.LogInformation("In Controller about to return");

            return(Ok("Currently processing your request..."));
        }
Exemplo n.º 3
0
 public void SetPersistenceCreateMethod <T>(Action <T> saveMethod)
 {
     if (CreateMethods.ContainsKey(typeof(T)))
     {
         CreateMethods[typeof(T)] = saveMethod;
     }
     else
     {
         CreateMethods.Add(typeof(T), saveMethod);
     }
 }
Exemplo n.º 4
0
        public void Create <T>(IList <T> list)
        {
            if (!CreateMethods.ContainsKey(typeof(IList <T>)))
            {
                throw new PersistenceMethodNotFoundException("No persistence create method set up for " + typeof(IList <T>).Name + ". Add one using BuilderSetup.SetPersistenceCreateMethod()");
            }

            var creator = CreateMethods[typeof(IList <T>)];

            creator.DynamicInvoke(list);
        }
        public IActionResult CreateMethods([FromBody] List <MethodDTO> methodsDTO)
        {
            long loggedInUserId = GetLoggedInUserIdMockUp();

            if (loggedInUserId == -1)
            {
                return(Unauthorized());
            }

            List <CreateMethod> createMethodsList =
                methodsDTO.Select(m => new CreateMethod(m.Creator, m.Name, m.ApplicationRate, loggedInUserId)).ToList();

            CreateMethods createMethods =
                new CreateMethods(createMethodsList, loggedInUserId);

            _kafkaProducer.Produce(createMethods, METHODS_TOPIC);

            return(Ok("Currently processing your request..."));
        }
        private void HandleCreateMethods(CreateMethods createMethods)
        {
            Result <List <Method> > methodsCreationResult = _repository.CreateMethods(createMethods);

            if (methodsCreationResult.IsFailure)
            {
                MethodsCreationFailed failedMethod =
                    new MethodsCreationFailed(
                        methodsCreationResult.Error,
                        createMethods.LoggedInUserId,
                        createMethods.SagaId
                        );
                _kafkaProducer.Produce(failedMethod, METHODS_TOPIC);
                return;
            }

            List <MethodCreated> createdMethods = new List <MethodCreated>();

            foreach (var methodCreationResult in methodsCreationResult.Value)
            {
                MethodCreated createdMethod = new MethodCreated(
                    methodCreationResult.Id,
                    methodCreationResult.Creator,
                    methodCreationResult.Name,
                    methodCreationResult.ApplicationRate,
                    methodCreationResult.CreationDate,
                    createMethods.LoggedInUserId,
                    createMethods.SagaId
                    );
                createdMethods.Add(createdMethod);
            }

            MethodsCreated createdMethodsEvent = new MethodsCreated(createdMethods, createMethods.LoggedInUserId, createMethods.SagaId);

            _kafkaProducer.Produce(createdMethodsEvent, METHODS_TOPIC);
        }
Exemplo n.º 7
0
        public static async Task SeedAsync(MyContext myContext, string WebRootPath)
        {
            try
            {
                if (string.IsNullOrEmpty(WebRootPath))
                {
                    //到时候数据文件在接口项目的网站文件中
                    throw new Exception("获取wwwroot路径时,异常!");
                }
                SeedDataFolder = Path.Combine(WebRootPath, SeedDataFolder);

                //创建一个数据库
                myContext.Db.DbMaintenance.CreateDatabase(Appsettings.app(new string[] { "BaseConfig", "DataBaseName" }), null);


                var modelTypes = from t in Assembly.GetExecutingAssembly().GetTypes()
                                 where t.IsClass && t.Namespace == "Strong.Entities.DBModel"
                                 select t;
                modelTypes.ToList().ForEach(t =>
                {
                    string msg = string.Empty;

                    //生成数据库表
                    if (!myContext.Db.DbMaintenance.IsAnyTable(t.Name))
                    {
                        myContext.Db.CodeFirst.InitTables(t);
                        //生成对应层类文件
                        msg += CreateMethods.GenerationLogic(t.Name, bllusing, "Bussiness", "Bussiness", "Bussiness");
                        msg += CreateMethods.GenerationLogic(t.Name, ibllusing, "IBussiness", "IBussiness", "Bussiness");
                        //msg += CreateMethods.GenerationLogic(t.Name, repositoryusing, "Repository", "Repository", "Repository");
                        msg += CreateMethods.GenerationLogic(t.Name, irepositoryusing, "IRepository", "IRepository", "Repository");
                        Console.WriteLine(msg);
                    }
                });

                //生成种子数据,数据库没有的表,创建的时候,同时创建数据
                #region TB_User
                if (!await myContext.Db.Queryable <TB_User>().AnyAsync())
                {
                    myContext.GetEntityDB <TB_User>().InsertRange(JsonHelper.ParseFormByJson <List <TB_User> >(FileHelper.ReadFile(string.Format(SeedDataFolder, "TB_User"), Encoding.UTF8)));
                    Console.WriteLine("Table:TB_User Data created success!");
                }
                else
                {
                    Console.WriteLine("Table:TB_User already exists...");
                }
                #endregion

                #region TB_Role
                if (!await myContext.Db.Queryable <TB_Role>().AnyAsync())
                {
                    myContext.GetEntityDB <TB_Role>().InsertRange(JsonHelper.ParseFormByJson <List <TB_Role> >(FileHelper.ReadFile(string.Format(SeedDataFolder, "TB_Role"), Encoding.UTF8)));
                    Console.WriteLine("Table:TB_Role Data created success!");
                }
                else
                {
                    Console.WriteLine("Table:TB_Role already exists...");
                }
                #endregion

                #region TB_Menu
                if (!await myContext.Db.Queryable <TB_Menu>().AnyAsync())
                {
                    myContext.GetEntityDB <TB_Menu>().InsertRange(JsonHelper.ParseFormByJson <List <TB_Menu> >(FileHelper.ReadFile(string.Format(SeedDataFolder, "TB_Menu"), Encoding.UTF8)));
                    Console.WriteLine("Table:TB_Menu Data created success!");
                }
                else
                {
                    Console.WriteLine("Table:TB_Menu already exists...");
                }
                #endregion

                #region TB_Role_Menu
                if (!await myContext.Db.Queryable <TB_Role_Menu>().AnyAsync())
                {
                    myContext.GetEntityDB <TB_Role_Menu>().InsertRange(JsonHelper.ParseFormByJson <List <TB_Role_Menu> >(FileHelper.ReadFile(string.Format(SeedDataFolder, "TB_Role_Menu"), Encoding.UTF8)));
                    Console.WriteLine("Table:TB_Role_Menu Data created success!");
                }
                else
                {
                    Console.WriteLine("Table:TB_Role_Menu already exists...");
                }
                #endregion

                #region TB_User_Role
                if (!await myContext.Db.Queryable <TB_User_Role>().AnyAsync())
                {
                    myContext.GetEntityDB <TB_User_Role>().InsertRange(JsonHelper.ParseFormByJson <List <TB_User_Role> >(FileHelper.ReadFile(string.Format(SeedDataFolder, "TB_User_Role"), Encoding.UTF8)));
                    Console.WriteLine("Table:TB_User_Role Data created success!");
                }
                else
                {
                    Console.WriteLine("Table:TB_User_Role already exists...");
                }
                #endregion

                #region TaskJob


                var s = JsonHelper.GetJSON <TasksQz>(new TasksQz {
                    BeginTime = DateTime.Now, EndTime = DateTime.Now.AddYears(5)
                });
                if (!await myContext.Db.Queryable <TasksQz>().AnyAsync())
                {
                    myContext.GetEntityDB <TasksQz>().InsertRange(JsonHelper.ParseFormByJson <List <TasksQz> >(FileHelper.ReadFile(string.Format(SeedDataFolder, "TasksQz"), Encoding.UTF8)));
                    Console.WriteLine("Table:TasksQz Data created success!");
                }
                else
                {
                    Console.WriteLine("Table:TasksQz already exists...");
                }
                #endregion
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Exemplo n.º 8
0
        //
        /// <summary>
        /// create database |dbName|
        /// create table |tableName|
        /// create table |tableName| (ColName,ColType,IsAllowNull(true/false),DefaultValue;...)
        /// </summary>
        /// <param name="query"></param>
        private static void Create(string query)
        {
            string _command = query.Substring(6);

            CreateMethods.Execute(_command);
        }