Esempio n. 1
0
        public static ConfigModel ConfigEntityToModel(ConfigEntity entity)
        {
            if (entity == null)
            {
                return(null);
            }
            ConfigModel model = new ConfigModel()
            {
                ID = entity.ID, Code = entity.Code, ParentID = entity.ParentID, Data = entity.Data, DataStatus = entity.DataStatus
            };

            return(model);
        }
        public async Task QuerySingleHappyPath()
        {
            string name   = "config-name";
            var    entity = new ConfigEntity();

            model.GetEntityByNameAsync(name).Returns(entity);

            var context = new QueryContext(name, QueryTypes.ValueRequest, model);
            var result  = await AllQueries.QueryConfigEntityAsync(context);

            Assert.Same(entity, result.Result);
            Assert.True(result.IsSuccess);
        }
        public Task ConfigAsync([Summary("config's name")] string configName, [Summary("config's value")] int value)
        {
            ConfigEntity config = configDb.GetConfigByName(configName);

            if (config == null)
            {
                return(ReplyAsync($"there are no config named {configName}"));
            }

            config.ConfigValue = value;
            configDb.Save(config);

            return(ReplyAsync($"modified config {configName}"));
        }
Esempio n. 4
0
 async void InitSocket()
 {
     client            = new CommonSocketClient();
     client.Error     += Client_Error;
     client.Closed    += Client_Closed;
     client.Connected += Client_Connected;
     // Initialize the client with the receive filter and request handler
     client.Initialize(new MyReceiveFilter(), (request) =>
     {
         ucLogMessageBox1.PrintShowLogMessage(Encoding.UTF8.GetString(request.Body));
     });
     Conf = new ConfigEntity();
     await client.ConnectAsync(new IPEndPoint(IPAddress.Parse(Conf.SocketServerIp), Conf.SocketServerPort));
 }
Esempio n. 5
0
        public bool EditConfig(ConfigModel config)
        {
            DBFactory.GetModel <IDBConfigDal>("IDBConfigDal").EditConfig(config);
            ConfigEntity  entity = ConvertData.ConfigModelToEntity(config);
            ICacheService cache  = CacheFactory.GetInstace();

            if (cache != null)
            {
                string key = CacheFactory.MadePrefix(config.Code, config.ParentID);
                cache.SetConfig(key, entity);
            }
            ClientMonitor.SetConfig(entity);
            return(true);
        }
 public static Config Map(ConfigEntity configEntity)
 {
     return(configEntity == null
         ? null
         : new Config
     {
         Id = configEntity._id.ToString(),
         Name = configEntity.Name,
         Value = configEntity.Value,
         IsActive = configEntity.IsActive,
         ApplicationName = configEntity.ApplicationName,
         Type = configEntity?.Type
     });
 }
        public void TestInitialize()
        {
            Debug.WriteLine("Test Initialize");

            MailEntity = new MailEntity();
            MailEntity.To.Add(new MailAddress("*****@*****.**"));
            MailEntity.From     = new MailAddress("*****@*****.**");
            MailEntity.Subject  = "1 письмо";
            MailEntity.Body     = new StringBuilder("вап ваппррр");
            MailEntity.DateSent = DateTime.Now;

            ConfigEntity = new ConfigEntity
            {
                MailActions = new[]
                {
                    new Config.MailAction {
                        ActType = ActionType.Notify, ActTypeValue = "yes"
                    },
                    new Config.MailAction {
                        ActType = ActionType.Print, ActTypeValue = "yes"
                    },
                    new Config.MailAction {
                        ActType = ActionType.CopyTo, ActTypeValue = "folder"
                    },
                    new Config.MailAction {
                        ActType = ActionType.Forward, ActTypeValue = "*****@*****.**"
                    },
                },
                IdentityMessages = new[]
                {
                    new IdentityMessage {
                        IdType = IdentityType.To, IdTypeValue = "*****@*****.**"
                    },
                    new IdentityMessage {
                        IdType = IdentityType.From, IdTypeValue = "*****@*****.**"
                    },
                    new IdentityMessage {
                        IdType = IdentityType.Title, IdTypeValue = "пис"
                    },
                    new IdentityMessage {
                        IdType = IdentityType.Body, IdTypeValue = "вап"
                    }
                },
                Mail     = "pop.yandex.ru",
                Port     = 995,
                Login    = "******",
                Password = "******"
            };
        }
        public void GetTax_ShouldReturnValue_WhenInTaxLimit(double value, double expectedTax)
        {
            // Arrange
            var config = new ConfigEntity()
            {
                MinTaxAmount = 100, SocialPercentage = 0.1, MaxSocialAmount = 3000
            };
            var sut = new SocialRule(config);

            // Act
            var tax = sut.GetTax(value);

            // Assert
            Assert.AreEqual(expectedTax, tax);
        }
        public void GetTax_ShouldReturnValue_WhenAboveLimit(double value, double expectedTax)
        {
            // Arrange
            var config = new ConfigEntity()
            {
                MinTaxAmount = 100, TaxPercentage = 0.1
            };
            var sut = new TaxRule(config);

            // Act
            var tax = sut.GetTax(value);

            // Assert
            Assert.AreEqual(expectedTax, tax);
        }
Esempio n. 10
0
        public EntityFilterControl(IBaseRepository Service, Dictionary <string, object> ValeursFiltre, ConfigEntity ConfigEntity = null)
        {
            InitializeComponent();
            this.MainContainer = this.flowLayoutPanel1;
            this.Service       = Service;
            this.ValeursFiltre = ValeursFiltre;
            this.ConfigEntity  = ConfigEntity;

            if (this.ConfigEntity == null)
            {
                this.ConfigEntity = new ConfigEntity(this.Service.TypeEntity);
            }

            initFiltre();
        }
Esempio n. 11
0
        private List <string> FirstAccessToMail(ConfigEntity configEntity)
        {
            try
            {
                var mailTransfer = _mailProvider.GetAllMessages(configEntity);
                ProcessingMail(mailTransfer.MailEntities, configEntity);

                return(mailTransfer.Uids);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                throw;
            }
        }
Esempio n. 12
0
        public MainForm()
        {
            LoadVersionInfo();
            //AllocConsole();
            InitializeComponent();
            CurrentConfig = new ConfigEntity();
            InitSocket();
            dataGridView1.AutoGenerateColumns = false;

            OnlineUsers = new BindingList <UserDto>(new List <UserDto>());
            flag        = DateTime.Now.Date.AddDays(1).ToString("MM-dd");
            //InitOMCSServer();
            //RefreashGrid();
            UpdateDataTimer.Start();
        }
Esempio n. 13
0
    public static ConfigEntity Get()
    {
        if (_config != null)
        {
            return(_config);
        }

        var c = new ConfigurationBuilder()
                .AddJsonFile("appsettings.json", optional: false, reloadOnChange: true)
                .Build();

        _config = new ConfigEntity();
        c.Bind(_config);
        return(_config);
    }
Esempio n. 14
0
        public void GetTax_ShouldReturn0_WhenUnderLimit(double value)
        {
            // Arrange
            var config = new ConfigEntity()
            {
                MinTaxAmount = 100
            };
            var sut = new TaxRule(config);

            // Act
            var tax = sut.GetTax(value);

            // Assert
            Assert.AreEqual(0, tax);
        }
        /// <summary>
        /// Create Entry form instance
        /// </summary>
        /// <param name="EtityBLO"></param>
        /// <param name="entity"></param>
        /// <param name="critereRechercheFiltre"></param>
        /// <param name="AutoGenerateField"></param>
        public BaseEntryForm(
            IGwinBaseBLO EtityBLO,
            BaseEntity entity,
            Dictionary <string, object> critereRechercheFiltre,
            bool AutoGenerateField)
        {
            InitializeComponent();
            errorProvider.RightToLeft = GwinApp.isRightToLeft;

            if (System.ComponentModel.LicenseManager.UsageMode != System.ComponentModel.LicenseUsageMode.Designtime)
            {
                CheckPramIsNull.CheckParam_is_NotNull(EtityBLO, this, nameof(EtityBLO));

                // Init Variables
                this.EntityBLO         = EtityBLO;
                this.Entity            = entity;
                this.FilterValues      = critereRechercheFiltre;
                this.AutoGenerateField = AutoGenerateField;
                this.ConfigEntity      = ConfigEntity.CreateConfigEntity(this.EntityBLO.TypeEntity);

                // Default values
                this.ConteneurFormulaire      = FlowLayoutContainer;
                this.isStepInitializingValues = false;
                this.MessageValidation        = new MessageValidation(errorProvider);
                this.Fields      = new Dictionary <string, BaseField>();
                this.GroupsBoxes = new Dictionary <string, GroupBox>();

                // Create PLO Instance if PLO exist
                if (this.EntityPLO == null && this.ConfigEntity.PresentationLogic != null)
                {
                    this.EntityPLO = (IGwinPLO)Activator.CreateInstance(this.ConfigEntity.PresentationLogic.TypePLO);
                }


                // Create or Config Entity Instance
                if (this.EntityBLO != null && this.Entity == null)
                {
                    this.Entity = (BaseEntity)EtityBLO.CreateEntityInstance();
                }
                if ((this.Entity == null || this.Entity.Id == 0) && this.FilterValues != null)
                {
                    this.InitialisationEntityParCritereRechercheFiltre();
                }

                // Create Field in Form
                this.CreateFieldIfNotGenerated();
            }
        }
Esempio n. 16
0
 public Task <bool> StoreEntityAsync(ConfigEntity entity)
 {
     if (entity.CrudOperationName == CommandTypes.Create)
     {
         _entity = entity;
     }
     else if (entity.CrudOperationName == CommandTypes.Delete)
     {
         _entity = null;
     }
     else if (entity.CrudOperationName == CommandTypes.UpdateValue)
     {
         _entity.Value = entity.Value;
     }
     return(Task.FromResult(true));
 }
Esempio n. 17
0
        public List <string> Read(ConfigEntity configEntity)
        {
            string        path     = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"Files", configEntity.Mail + "_" + configEntity.Login + "_SeenUids" + ".txt");
            List <string> seenUids = new List <string>();

            using (StreamReader sr = new StreamReader(path, Encoding.Default))
            {
                string line;
                while ((line = sr.ReadLine()) != null)
                {
                    seenUids.Add(line);
                }
            }

            return(seenUids);
        }
Esempio n. 18
0
        public string SqlFormatter(string inputSql, ConfigEntity entity)
        {
            SqlAstParser         sqlAstParser = new SqlAstParser();
            SqlCompilationUnit   unit         = sqlAstParser.Parse(inputSql);
            SqlAstVisitor        visitor      = new SqlFormatVisitor(entity);
            IList <ITransformer> transformers = new List <ITransformer>();

            transformers.Add(new CaseTransform(entity));
            transformers.Add(new CommentTransform(entity.IsDeleteComment));
            if (entity.IsReservedWordAsComplement)
            {
                transformers.Add(new AsWordCompletionTransform(entity));
            }
            unit.Accept(visitor, transformers);
            return(visitor.ResultSql);
        }
Esempio n. 19
0
 private static void UpdateInternalValue(ConfigEntity entity)
 {
     if (entity != null)
     {
         if (Values.Any(q => q.Key == entity.Key))
         {
             var get = Values.Single(q => q.Key == entity.Key);
             get.ProductionValue = entity.ProductionValue;
             get.DevelopmentValue = entity.DevelopmentValue;
         }
         else
         {
             Values.Add(entity);
         }
     }
 }
Esempio n. 20
0
        public void BindParam()
        {
            ConfigEntity entity = (ConfigEntity)objectListView1.SelectedObject;

            if (entity != null)
            {
                CurrentConfigEntity = entity;
                ListViewHelper.BindData(objectListView2, entity.ParamCollection);
            }
            else
            {
                CurrentConfigEntity = null;
                ListViewHelper.BindData(objectListView2, null);
            }
            btnParamEdit.Enabled = btnParamDelete.Enabled = objectListView2.SelectedIndex > -1;
        }
Esempio n. 21
0
 public JsonResult Edit(string id, ConfigEntity config)
 {
     var configbll = new MessageConfigBLL();
     var success = true;
     var message = "保存成功!";
     try
     {
         configbll.ModifyConfig(config);
     }
     catch (Exception e)
     {
         success = false;
         message = e.Message;
     }
     return Json(new AjaxResult() { type = success ? ResultType.success : ResultType.error, message = message });
 }
Esempio n. 22
0
        private static async Task <ConfigEntityResult> TryExtractConfigEntityAsync(string initiatingMethod, CommandContext context, CommandTypes storeType, Func <ConfigEntity, ConfigEntity> adjustEntity)
        {
            // get config entity if exists
            var config = await context.StorageEngine.GetEntityByNameAsync(context.ConfigurationEntryKey);

            if (config == null)
            {
                return(new ConfigEntityResult
                {
                    Success = false,
                    ThrowError = () => SanityChecks.NotFound(context.ConfigurationEntryKey, initiatingMethod)
                });
            }
            // for diff checking
            var before = new ConfigEntity
            {
                Id    = config.Id,
                Name  = new string(config.Name.ToCharArray()),
                Value = new string(config.Value.ToCharArray())
            };

            // callback for entity
            config = adjustEntity(config);

            config.CrudOperationName = storeType;
            bool isSuccess = await context.StorageEngine.StoreEntityAsync(config);

            if (!isSuccess)
            {
                return(new ConfigEntityResult
                {
                    ThrowError = () => SanityChecks.StorageFailed <ConfigEntity>
                                 (
                        context.CommandType.ToString(),
                        initiatingMethod
                                 ),
                    Success = false
                });
            }

            return(new ConfigEntityResult
            {
                Before = before,
                Entity = config,
                Success = true
            });
        }
        public async Task <bool> UpsertAsync(Config configuration)
        {
            /*
             * Check if allready exist
             */
            var config = string.IsNullOrEmpty(configuration.Id)
                ? await _repository.FindOneAsync(c => c.ApplicationName == configuration.ApplicationName && c.Name == configuration.Name)
                : await _repository.GetAsync(configuration.Id);

            /*
             * Map request to entity
             * A better solution is creating a mapper class
             * because of limited time I choosed this way
             */
            var mappedConfig = new ConfigEntity
            {
                Name            = configuration.Name,
                Value           = configuration.Value,
                ApplicationName = configuration.ApplicationName,
                Type            = configuration.Type,
                IsActive        = configuration.IsActive
            };

            //Create new record
            if (config == null)
            {
                mappedConfig._id = ObjectId.GenerateNewId();
                return(await _repository.InsertAsync(mappedConfig));
            }

            //Update existing record
            var isUpdated = await _repository.UpdateAsync(config._id.ToString(), mappedConfig);

            if (isUpdated && _isSubscribing)
            {
                //Always check subscriber if still alive
                if (_subscriber.Multiplexer.IsConnected == false)
                {
                    EnsureRedisConnection(_settings);
                }

                //Publish the change
                await _subscriber.PublishAsync(Constants.RedisPubSubChannel, mappedConfig.Name);
            }

            return(isUpdated);
        }
        ///<summary>
        /// load simple json file
        /// save to in Memory store
        /// and load all and print to console
        ///</summary>
        public static async Task Run(Action <object> printCallback)
        {
            var store = new InMemoryStore();
            // upload file from the current directory
            string     json      = JsonFromConfigFile();
            ITransform transform = new JsonTransform();

            OperationResult result = transform.Parse(json);

            if (result.Result is ConfigCollection collection)
            {
                foreach (var item in collection.WrappedConfigEntities)
                {
                    var request = new ConfigChangeRequest {
                        Name = item.Name, Value = item.Value
                    };
                    var context = new CommandContext(CommandTypes.Create, request, store);

                    await Factory.RunOperationAsync(context);
                }
            }
            else
            {
                throw new InvalidCastException("should have been ConfigCollection yet is " + result.Result.GetType().Name);
            }
            foreach (var item in await store.AllEntitesAsync())
            {
                printCallback($"next one is [{item.Name}] - [{item.Value}]");
            }

            printCallback("also find RabbitMQ:Port and change it to 5674");
            ConfigEntity port = await QueryRabbitPortAsync(store);

            printCallback(port.Name + " - " + port.Value);

            var updateRq = new ConfigChangeRequest {
                Name = port.Name, Value = "5674"
            };
            var update = new CommandContext(CommandTypes.UpdateValue, updateRq, store);

            OperationResult rs = await Factory.RunOperationAsync(update);

            printCallback("after the update:");
            port = await QueryRabbitPortAsync(store);

            printCallback(port.Name + " - " + port.Value);
        }
        public async Task QueryAllHappyPath()
        {
            string name     = "config-name";
            var    entity   = new ConfigEntity();
            var    entities = new List <ConfigEntity> {
                entity
            };

            model.AllEntitesAsync().Returns((IEnumerable <ConfigEntity>)entities);

            var context = new QueryContext(name, QueryTypes.AllValues, model);
            var result  = await AllQueries.QueryAllConfigEntityValuesAsync(context);

            Assert.IsType <ConfigCollection>(result.Result);
            Assert.Same(entity, ((ConfigCollection)(result.Result)).WrappedConfigEntities.First());
            Assert.True(result.IsSuccess);
        }
Esempio n. 26
0
        public async Task TryUpdateWithExistingReturnsTrue()
        {
            var entity = new ConfigEntity {
                Name = FOUND, Value = "updated"
            };

            entity.CrudOperationName = CommandTypes.UpdateValue;

            bool result = await _store.StoreEntityAsync(entity);

            Assert.True(result);
            Assert.Equal(2, _store.Entities.Count);

            var updated = _store.Entities[FOUND];

            Assert.Equal(updated.Value, "updated");
        }
Esempio n. 27
0
        public async Task StoreDeleteRemoves()
        {
            var entity = new ConfigEntity {
                Name = FOUND, Value = null
            };

            entity.CrudOperationName = CommandTypes.Delete;

            bool result = await _store.StoreEntityAsync(entity);

            Assert.True(result);
            Assert.Equal(1, _store.Entities.Count);

            bool exists = _store.Entities.ContainsKey(FOUND);

            Assert.False(exists);
        }
Esempio n. 28
0
        private void CreateMenu()
        {
            // Create Parent Menu from ManuItemApplication Table
            foreach (MenuItemApplication menuItemApplication in this.Service.GetAll())
            {
                // ToolStripMenu
                ToolStripMenuItem toolStripMenuItem = new ToolStripMenuItem();
                toolStripMenuItem.Name = "toolStripMenuItem" + menuItemApplication.Name;
                toolStripMenuItem.Size = new System.Drawing.Size(82, 20);
                toolStripMenuItem.Text = menuItemApplication.TitrleCulture(ApplicationInstance.Session.CultureInfo);
                this.menuStrip.Items.Add(toolStripMenuItem);
            }



            Dictionary <Type, MenuAttribute> MenuAttributes_And_Types = new EntitiesModel().Get_All_Type_And_MenuAttributes();


            foreach (var menuAttributes_And_Types in MenuAttributes_And_Types)
            {
                ConfigEntity attributesOfEntity = new ConfigEntity(menuAttributes_And_Types.Key);

                // ToolStripMenu
                ToolStripMenuItem toolStripMenuItem = new ToolStripMenuItem();
                toolStripMenuItem.Name   = "toolStripMenuItem" + attributesOfEntity.Menu.Title;
                toolStripMenuItem.Size   = new System.Drawing.Size(82, 20);
                toolStripMenuItem.Text   = attributesOfEntity.Menu.Title;
                toolStripMenuItem.Click += ToolStripMenuItem_Click;
                MenuItems.Add(toolStripMenuItem.Name, menuAttributes_And_Types.Key);

                // Find groupe
                if (attributesOfEntity.Menu.Group != null)
                {
                    ToolStripItem     GroupeToolStripItem     = this.menuStrip.Items.Find("toolStripMenuItem" + attributesOfEntity.Menu.Group, true).SingleOrDefault();
                    ToolStripMenuItem GroupeToolStripMenuItem = GroupeToolStripItem as ToolStripMenuItem;
                    if (GroupeToolStripMenuItem != null)
                    {
                        GroupeToolStripMenuItem.DropDownItems.Add(toolStripMenuItem);
                    }
                }
                else
                {
                    this.menuStrip.Items.Add(toolStripMenuItem);
                }
            }
        }
Esempio n. 29
0
        /// <summary>
        /// Créer du formuliare
        /// </summary>
        /// <param name="service"></param>
        public BaseEntryForm(
            IBaseRepository service,
            BaseEntity entity,
            Dictionary <string, object> critereRechercheFiltre,
            bool AutoGenerateField,
            ConfigEntity configEntity)
        {
            InitializeComponent();
            if (!DesignMode)
            {
                // Params
                this.Service = service;
                this.Entity  = entity;
                this.CritereRechercheFiltre = critereRechercheFiltre;
                this.AutoGenerateField      = AutoGenerateField;
                this.ConfigEntity           = configEntity;

                // Les valeus par défaux
                this.isStepInitializingValues = false;
                this.MessageValidation        = new MessageValidation(errorProvider);


                // Préparation de l'objet Entity
                if (this.Service != null && this.Entity == null)
                {
                    this.Entity = (BaseEntity)service.CreateInstanceObjet();
                }
                if ((this.Entity == null || this.Entity.Id == 0) && this.CritereRechercheFiltre != null)
                {
                    this.InitialisationEntityParCritereRechercheFiltre();
                }

                // Conteneurs du formulaire
                this.ConteneurFormulaire = this.flowLayoutPanelForm;

                // Génération du Formulaire
                if (this.AutoGenerateField)
                {
                    if (this.ConfigEntity == null)
                    {
                        this.ConfigEntity = new ConfigEntity(this.Service.TypeEntity);
                    }
                }
            }
        }
        public async Task DeleteAsyncConfigEntityNotFound()
        {
            var request = new ConfigChangeRequest {
                Name = "name", Value = "value"
            };
            var context  = new CommandContext(CommandTypes.Delete, request, model);
            var expected = new ConfigEntity {
                Name = "name", Value = "old"
            };

            model.GetEntityByNameAsync("name").Returns((ConfigEntity)null);

            var result = await AllCommands.DeleteAsync(context);

            Assert.False(result.IsSuccess);
            Assert.Null(result.Result);
            Assert.Equal(ResultType.NotFound, result.ResultType);
        }
Esempio n. 31
0
        public async Task <IResultModel> Add(ConfigAddModel model)
        {
            if (await _repository.Exists(model.Key))
            {
                return(ResultModel.HasExists);
            }

            var entity = new ConfigEntity
            {
                Key     = model.Key,
                Value   = model.Value,
                Remarks = model.Remarks
            };

            var result = await _repository.AddAsync(entity);

            return(ResultModel.Result(result));
        }
Esempio n. 32
0
 public static string Replace(System.Collections.Specialized.NameValueCollection pageRequest,ConfigEntity.WebSiteZWCE webSite)
 {
     return "";
 }
Esempio n. 33
0
        private static string GetValueByEnvironment(ConfigEntity entity)
        {
            if (entity == null) return null;

            if (Definition.IsDevelopmentEnvironment)
            {
                return entity.DevelopmentValue;
            }
            else
            {
                return entity.ProductionValue;
            }
        }