Пример #1
0
        public void AddConfig(ConfigVM config)
        {
            lock (LockThis)
            {
                using (SQLiteConnection connection = new SQLiteConnection("Data Source=" + DatabaseFile))
                {
                    using (SQLiteCommand command = new SQLiteCommand())
                    {
                        command.Connection = connection;
                        connection.Open();
                        SQLiteHelper helper = new SQLiteHelper(command);

                        Dictionary <string, object> dic = new Dictionary <string, object>
                        {
                            ["Name"]        = config.Name,
                            ["Keyword"]     = config.Keyword,
                            ["TeamId"]      = config.TeamId,
                            ["CategoryId"]  = config.CategoryId,
                            ["LastUpdate"]  = config.LastUpdate,
                            ["LastRefresh"] = config.LastRefresh,
                            ["Hash"]        = config.Hash,
                            ["Selected"]    = config.Selected ? "True" : "False"
                        };

                        helper.Insert("ConfigList", dic);

                        connection.Close();
                    }
                }
            }
        }
Пример #2
0
        private ObservableCollection <ConfigVM> GetConfigList()
        {
            using (SQLiteConnection connection = new SQLiteConnection("Data Source=" + DatabaseFile))
            {
                using (SQLiteCommand command = new SQLiteCommand())
                {
                    command.Connection = connection;
                    connection.Open();
                    SQLiteHelper helper = new SQLiteHelper(command);

                    string    cmd = "select * from ConfigList;";
                    DataTable dt  = helper.Select(cmd);
                    ObservableCollection <ConfigVM> configList = new ObservableCollection <ConfigVM>();
                    foreach (DataRow dr in dt.Rows)
                    {
                        ConfigVM config = new ConfigVM
                        {
                            Name        = dr["Name"] as string,
                            Keyword     = dr["Keyword"] as string,
                            TeamId      = dr["TeamId"] as string,
                            CategoryId  = dr["CategoryId"] as string,
                            LastUpdate  = dr["LastUpdate"] as string,
                            LastRefresh = dr["LastRefresh"] as string,
                            Selected    = (dr["Selected"] as string) == "True"
                        };
                        configList.Add(config);
                    }
                    connection.Close();
                    return(configList);
                }
            }
        }
Пример #3
0
 public ConfigMainGrid(ConfigVM ConfigVM, ConfiController ConfiController)
 {
     this.ConfiController = ConfiController;
     this.ConfigVM        = ConfigVM;
     ConfiController.LoadProfiles();
     InitializeLayout();
 }
Пример #4
0
 public ConfiController(ConfigVM ConfigVM)
 {
     AppDirectory          = System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), FastNPP.Launcher.Data.LocalConfiStore.AppDirectory);
     ConfigDirectory       = System.IO.Path.Combine(AppDirectory, FastNPP.Launcher.Data.LocalConfiStore.AppConfigDirectory);
     ConfigProfileFilePath = System.IO.Path.Combine(ConfigDirectory, FastNPP.Launcher.Data.LocalConfiStore.ConfigProfileFileName);
     this.ConfigVM         = ConfigVM;
 }
Пример #5
0
        public ConfigView()
        {
            var vm = new ConfigVM();

            this.BindingContext = vm;
            InitializeComponent();
        }
Пример #6
0
        public async Task <IActionResult> Add([FromBody] ConfigVM model)
        {
            if (model == null)
            {
                throw new ArgumentNullException("model");
            }

            var app = await _appService.GetAsync(model.AppId);

            if (app == null)
            {
                return(Json(new
                {
                    success = false,
                    message = $"应用({model.AppId})不存在。"
                }));
            }

            var oldConfig = await _configService.GetByAppIdKey(model.AppId, model.Group, model.Key);

            if (oldConfig != null)
            {
                return(Json(new
                {
                    success = false,
                    message = "配置已存在,请更改输入的信息。"
                }));
            }

            var config = new Config();

            config.Id           = string.IsNullOrEmpty(config.Id) ? Guid.NewGuid().ToString("N") : config.Id;
            config.Key          = model.Key;
            config.AppId        = model.AppId;
            config.Description  = model.Description;
            config.Value        = model.Value;
            config.Group        = model.Group;
            config.Status       = ConfigStatus.Enabled;
            config.CreateTime   = DateTime.Now;
            config.UpdateTime   = null;
            config.OnlineStatus = OnlineStatus.WaitPublish;

            var result = await _configService.AddAsync(config);

            if (result)
            {
                dynamic param = new ExpandoObject();
                param.config   = config;
                param.userName = this.GetCurrentUserName();
                TinyEventBus.Instance.Fire(EventKeys.ADD_CONFIG_SUCCESS, param);
            }

            return(Json(new
            {
                success = result,
                message = !result ? "新建配置失败,请查看错误日志" : "",
                data = config
            }));
        }
Пример #7
0
 public void AddConfigWithRemove(ConfigVM config)
 {
     if (ConfigExisted(config))
     {
         RemoveConfig(config);
     }
     AddConfig(config);
 }
Пример #8
0
        /// <summary>
        /// Updates the current config.
        /// </summary>
        public async Task SetAsync(ConfigVM config)
        {
            var wrapper = await _db.DynamicConfig.FirstOrDefaultAsync();

            wrapper.Value = JsonConvert.SerializeObject(_mapper.Map <DynamicConfig>(config));
            await _db.SaveChangesAsync();

            _cfg.ResetCache();
        }
Пример #9
0
        public ActionResult Config(ConfigVM configVM)
        {
            var userId = User.Identity.GetUserId();
            var user   = db.Users.Find(userId);

            //if (ModelState.IsValid)
            //{
            var bank = new BankAccount
            {
                HouseholdId     = configVM.HouseHoldId,
                Name            = configVM.Name,
                StartingBalance = configVM.StartingBalance,
                LowBalanceLevel = configVM.LowBalance,
                AccountType     = configVM.AccountType,

                Created        = DateTime.Now,
                CurrentBalance = configVM.StartingBalance,
                OwnerId        = userId
            };

            db.BankAccounts.Add(bank);
            db.SaveChanges();

            var budget = new Budget
            {
                Name         = configVM.BudgetName,
                Created      = DateTime.Now,
                OwnerId      = userId,
                HouseholdId  = configVM.HouseHoldId,
                TargetAmount = 0
            };

            db.Budgets.Add(budget);
            db.SaveChanges();

            var bItems = new BudgetItem
            {
                Name          = configVM.BIName,
                TargetAmount  = configVM.TargetAmount,
                BudgetId      = budget.Id,
                Created       = DateTime.Now,
                CurrentAmount = 0
            };


            db.BudgetItems.Add(bItems);
            user.Household.IsConfigured    = true;
            TempData["Complete_HH_config"] = "You have just configured your Household!";
            db.SaveChanges();

            return(RedirectToAction("Dashboard", "Home"));
            //}

            //return View(configVM);
        }
        public void Post_valid_data_returns_created_at_route()
        {
            // arrange
            var validConfig = new ConfigVM()
            {
                key = "fakeOrgName", value = "Machete"
            };
            // act
            var result = _controller.Post(validConfig);

            //assert
            Assert.IsInstanceOfType(result.Result, typeof(CreatedAtActionResult));
        }
Пример #11
0
        //get Households/config/5

        public ActionResult Config(int?Id)
        {
            var userId = User.Identity.GetUserId();
            var user   = db.Users.Find(userId);

            if (Id != null && Id != 0 && user.Household.IsConfigured == false)
            {
                var configVm = new ConfigVM();

                configVm.HouseHoldId = (int)Id;
                return(View(configVm));
            }
            return(RedirectToAction("Dashboard", "Home"));
        }
        public void Put_invalid_data_returns_bad_request()
        {
            // Arrange
            var invalidConfig = new ConfigVM()
            {
                id = 3, key = "fake key"
            };

            _controller.ModelState.AddModelError("value", "Required");
            // Act
            var result = _controller.Put(invalidConfig.id, invalidConfig);

            // Assert
            Assert.IsInstanceOfType(result.Result, typeof(BadRequestObjectResult));
        }
        public async Task <IActionResult> SaveConfiguration(ConfigVM vm)
        {
            // Get DB info
            var config = _context.ExactConfigurations
                         .FirstOrDefault(x => x.Id == vm.ConfigurationId);

            config.ItemGroupId        = new Guid(vm.ItemGroupId);
            config.DivsionId          = int.Parse(vm.DivisionId);
            config.BuyerId            = new Guid(vm.UserId);
            config.PaymentConditionId = vm.PaymentConditionId;
            config.Modified           = DateTime.Now;
            config.SupplierId         = vm.SupplierId;

            await _context.SaveChangesAsync();

            return(RedirectToAction(nameof(Index), new { sm = StateMessage.SuccessSave }));
        }
Пример #14
0
        private (bool, string) CheckRequired(ConfigVM model)
        {
            if (string.IsNullOrEmpty(model.Key))
            {
                return(false, "Key不能为空");
            }
            if (string.IsNullOrEmpty(model.Value))
            {
                return(false, "Value不能为空");
            }
            if (string.IsNullOrEmpty(model.AppId))
            {
                return(false, "AppId不能为空");
            }

            return(true, "");
        }
        public void Post_valid_data_returns_new_record_in_data_oject()
        {
            // arrange
            var validConfig = new ConfigVM()
            {
                key = "fakeOrgName", value = "Machete"
            };
            // act
            var result            = _controller.Post(validConfig);
            var typedResult       = (result.Result as ObjectResult).Value;
            var configVM          = UnitTestExtensions.ExtractFromDataObject <ConfigVM>(typedResult);
            var resultHasDataProp = typedResult.GetType().GetProperty("data") != null;

            //assert
            Assert.IsInstanceOfType(configVM, typeof(ConfigVM));
            Assert.IsTrue(resultHasDataProp);
            Assert.AreEqual("fakeOrgName", configVM.key);
        }
Пример #16
0
        public bool ConfigExisted(ConfigVM v)
        {
            lock (LockThis)
            {
                using (SQLiteConnection connection = new SQLiteConnection("Data Source=" + DatabaseFile))
                {
                    using (SQLiteCommand command = new SQLiteCommand())
                    {
                        command.Connection = connection;
                        connection.Open();
                        SQLiteHelper helper = new SQLiteHelper(command);

                        string    cmd = "select * from ConfigList where Hash='" + v.Hash + "';";
                        DataTable dt  = helper.Select(cmd);
                        connection.Close();
                        return(dt.Rows.Count > 0);
                    }
                }
            }
        }
Пример #17
0
        public void RemoveConfig(ConfigVM config)
        {
            lock (LockThis)
            {
                using (SQLiteConnection connection = new SQLiteConnection("Data Source=" + DatabaseFile))
                {
                    using (SQLiteCommand command = new SQLiteCommand())
                    {
                        command.Connection = connection;
                        connection.Open();
                        SQLiteHelper helper = new SQLiteHelper(command);

                        string cmd = "delete from ConfigList where Hash='" + config.Hash + "';";
                        helper.Execute(cmd);

                        connection.Close();
                    }
                }
            }
        }
Пример #18
0
        private async void ButtonSearch_Click(object sender, RoutedEventArgs e)
        {
            ConfigManageTabVM v = this.view.ConfigManageTab;

            v.SetStatus(ConfigManageTabVM.OpStatus.BUSY);
            ConfigVM       c    = v.CurrentConfig;
            List <VideoVM> list = await GetVideoList(c.Keyword, c.CategoryId, c.TeamId);

            if (list != null)
            {
                v.SearchResults = new ObservableCollection <VideoVM>(list);
                foreach (VideoVM item in v.SearchResults)
                {
                    if (this.db.VideoExisted(item))
                    {
                        item.Downloaded = true;
                    }
                }
            }
            v.SetStatus(ConfigManageTabVM.OpStatus.IDLE);
        }
Пример #19
0
        public PartialViewResult ConfigStep(int id)
        {
            var model                        = new ConfigVM();
            var WF_STEPBusiness              = Get <WF_STEPBusiness>();
            var CCTC_THANHPHANBusiness       = Get <CCTC_THANHPHANBusiness>();
            var DM_VAITROBusiness            = Get <DM_VAITROBusiness>();
            var DM_DANHMUC_DATABusiness      = Get <DM_DANHMUC_DATABusiness>();
            var DMLoaiDonViBusiness          = Get <DMLoaiDonViBusiness>();
            var WF_STEP_CONFIGBusiness       = Get <WF_STEP_CONFIGBusiness>();
            var WF_STEP_USER_PROCESSBusiness = Get <WF_STEP_USER_PROCESSBusiness>();

            model.Step        = WF_STEPBusiness.GetDaTaByID(id);
            model.ConfigStep  = WF_STEP_CONFIGBusiness.GetConfigStep(id);
            model.MainProcess = WF_STEP_USER_PROCESSBusiness.GetMainProcess(id);
            model.JoinProcess = WF_STEP_USER_PROCESSBusiness.GetJoinProcess(id);
            model.DSPhongBan  = CCTC_THANHPHANBusiness.GetDropDownList();
            model.DsVaiTro    = DM_VAITROBusiness.DsVaiTro(null);
            model.DSChucVu    = DM_DANHMUC_DATABusiness.DsByMaNhomNull(DMLOAI_CONSTANT.CHUCVU);
            model.DSCap       = DMLoaiDonViBusiness.DSLoaiDonVi();
            return(PartialView("_ConfigStepPartial", model));
        }
Пример #20
0
        public async Task <IActionResult> Edit(string id, [FromBody] ConfigVM model)
        {
            var requiredResult = CheckRequired(model);

            if (!requiredResult.Item1)
            {
                Response.StatusCode = 400;
                return(Json(new
                {
                    message = requiredResult.Item2
                }));
            }

            var ctrl = new Controllers.ConfigController(
                _configService,
                _modifyLogService,
                _remoteServerNodeProxy,
                _serverNodeService,
                _sysLogService,
                _appService
                );

            model.Id = id;
            var result = (await ctrl.Edit(model)) as JsonResult;

            dynamic obj = result.Value;

            if (obj.success == true)
            {
                return(Ok());
            }

            Response.StatusCode = 400;
            return(Json(new
            {
                obj.message
            }));
        }
Пример #21
0
        private void ButtonAddConfig_Click(object sender, RoutedEventArgs e)
        {
            ConfigManageTabVM v = this.view.ConfigManageTab;

            v.SetStatus(ConfigManageTabVM.OpStatus.BUSY);
            ConfigVM config = new ConfigVM(v.CurrentConfig);

            if (v.ConfigList.Contains(config))
            {
                if (MessageBox.Show("同名配置已存在,是否覆盖?", "警告", MessageBoxButton.YesNo, MessageBoxImage.Warning, MessageBoxResult.No) == MessageBoxResult.Yes)
                {
                    v.ConfigList.Remove(config);
                    v.ConfigList.Add(config);
                    this.db.AddConfigWithRemove(config);
                }
            }
            else
            {
                v.ConfigList.Add(config);
                this.db.AddConfigWithRemove(config);
            }
            v.SetStatus(ConfigManageTabVM.OpStatus.IDLE);
        }
Пример #22
0
        public async Task <IActionResult> Add([FromBody] ConfigVM model)
        {
            var requiredResult = CheckRequired(model);

            if (!requiredResult.Item1)
            {
                Response.StatusCode = 400;
                return(Json(new
                {
                    message = requiredResult.Item2
                }));
            }

            var ctrl = new Controllers.ConfigController(
                _configService,
                _modifyLogService,
                _remoteServerNodeProxy,
                _serverNodeService,
                _sysLogService,
                _appService
                );

            var result = (await ctrl.Add(model)) as JsonResult;

            dynamic obj = result.Value;

            if (obj.success == true)
            {
                return(Created("/api/config/" + obj.data.Id, ""));
            }

            Response.StatusCode = 400;
            return(Json(new
            {
                obj.message
            }));
        }
Пример #23
0
        public async Task <IActionResult> Edit([FromBody] ConfigVM model)
        {
            if (model == null)
            {
                throw new ArgumentNullException("model");
            }

            var config = await _configService.GetAsync(model.Id);

            if (config == null)
            {
                return(Json(new
                {
                    success = false,
                    message = "未找到对应的配置项。"
                }));
            }
            var oldConfig = new Config
            {
                Key   = config.Key,
                Group = config.Group,
                Value = config.Value
            };

            if (config.Group != model.Group || config.Key != model.Key)
            {
                var anotherConfig = await _configService.GetByAppIdKey(model.AppId, model.Group, model.Key);

                if (anotherConfig != null)
                {
                    return(Json(new
                    {
                        success = false,
                        message = "配置键已存在,请重新输入。"
                    }));
                }
            }

            config.AppId       = model.AppId;
            config.Description = model.Description;
            config.Key         = model.Key;
            config.Value       = model.Value;
            config.Group       = model.Group;
            config.Status      = model.Status;
            config.UpdateTime  = DateTime.Now;

            var result = await _configService.UpdateAsync(config);

            if (result && !IsOnlyUpdateDescription(config, oldConfig))
            {
                //add modify log
                await _modifyLogService.AddAsync(new ModifyLog
                {
                    Id         = Guid.NewGuid().ToString("N"),
                    ConfigId   = config.Id,
                    Key        = config.Key,
                    Group      = config.Group,
                    Value      = config.Value,
                    ModifyTime = config.UpdateTime.Value
                });

                //syslog
                await _sysLogService.AddSysLogSync(new SysLog
                {
                    LogTime = DateTime.Now,
                    LogType = SysLogType.Normal,
                    AppId   = config.AppId,
                    LogText = $"编辑配置【Key:{config.Key}】【Value:{config.Value}】【Group:{config.Group}】【AppId:{config.AppId}】"
                });

                //notice clients
                var action = new WebsocketAction
                {
                    Action = ActionConst.Update,
                    Item   = new ConfigItem {
                        group = config.Group, key = config.Key, value = config.Value
                    },
                    OldItem = new ConfigItem {
                        group = oldConfig.Group, key = oldConfig.Key, value = oldConfig.Value
                    }
                };
                var nodes = await _serverNodeService.GetAllNodesAsync();

                foreach (var node in nodes)
                {
                    if (node.Status == NodeStatus.Offline)
                    {
                        continue;
                    }
                    await _remoteServerNodeProxy.AppClientsDoActionAsync(node.Address, config.AppId, action);
                }
            }

            return(Json(new
            {
                success = result,
                message = !result ? "修改配置失败,请查看错误日志。" : ""
            }));
        }
Пример #24
0
 public ConfigView()
 {
     InitializeComponent();
     this.vm          = new ConfigVM();
     this.DataContext = vm;
 }
Пример #25
0
        public async Task <IActionResult> Edit([FromBody] ConfigVM model)
        {
            if (model == null)
            {
                throw new ArgumentNullException("model");
            }

            var config = await _configService.GetAsync(model.Id);

            if (config == null)
            {
                return(Json(new
                {
                    success = false,
                    message = "未找到对应的配置项。"
                }));
            }

            var app = await _configService.GetByAppIdAsync(model.AppId);

            if (!app.Any())
            {
                return(Json(new
                {
                    success = false,
                    message = $"应用({model.AppId})不存在。"
                }));
            }

            var oldConfig = new Config
            {
                Key   = config.Key,
                Group = config.Group,
                Value = config.Value
            };

            if (config.Group != model.Group || config.Key != model.Key)
            {
                var anotherConfig = await _configService.GetByAppIdKey(model.AppId, model.Group, model.Key);

                if (anotherConfig != null)
                {
                    return(Json(new
                    {
                        success = false,
                        message = "配置键已存在,请重新输入。"
                    }));
                }
            }

            config.AppId       = model.AppId;
            config.Description = model.Description;
            config.Key         = model.Key;
            config.Value       = model.Value;
            config.Group       = model.Group;
            config.UpdateTime  = DateTime.Now;

            var result = await _configService.UpdateAsync(config);

            if (result && !IsOnlyUpdateDescription(config, oldConfig))
            {
                dynamic param = new ExpandoObject();
                param.config    = config;
                param.oldConfig = oldConfig;

                TinyEventBus.Instance.Fire(EventKeys.EDIT_CONFIG_SUCCESS, param);
            }

            return(Json(new
            {
                success = result,
                message = !result ? "修改配置失败,请查看错误日志。" : ""
            }));
        }
Пример #26
0
        public async Task <IActionResult> Add([FromBody] ConfigVM model)
        {
            if (model == null)
            {
                throw new ArgumentNullException("model");
            }

            var oldConfig = await _configService.GetByAppIdKey(model.AppId, model.Group, model.Key);

            if (oldConfig != null)
            {
                return(Json(new
                {
                    success = false,
                    message = "配置已存在,请更改输入的信息。"
                }));
            }

            var config = new Config();

            config.Id           = Guid.NewGuid().ToString("N");
            config.Key          = model.Key;
            config.AppId        = model.AppId;
            config.Description  = model.Description;
            config.Value        = model.Value;
            config.Group        = model.Group;
            config.Status       = ConfigStatus.Enabled;
            config.CreateTime   = DateTime.Now;
            config.UpdateTime   = null;
            config.OnlineStatus = OnlineStatus.WaitPublish;

            var result = await _configService.AddAsync(config);

            if (result)
            {
                //add syslog
                await _sysLogService.AddSysLogSync(new SysLog
                {
                    LogTime = DateTime.Now,
                    LogType = SysLogType.Normal,
                    AppId   = config.AppId,
                    LogText = $"新增配置【Key:{config.Key}】【Value:{config.Value}】【Group:{config.Group}】【AppId:{config.AppId}】"
                });

                //add modify log
                await _modifyLogService.AddAsync(new ModifyLog
                {
                    Id         = Guid.NewGuid().ToString("N"),
                    ConfigId   = config.Id,
                    Key        = config.Key,
                    Group      = config.Group,
                    Value      = config.Value,
                    ModifyTime = config.CreateTime
                });
            }

            return(Json(new
            {
                success = result,
                message = !result ? "新建配置失败,请查看错误日志" : ""
            }));
        }
Пример #27
0
 public Task Set([FromBody] ConfigVM vm)
 {
     return(_cfgMgr.SetAsync(vm));
 }