Ejemplo n.º 1
0
        public async Task <IActionResult> PostFileData([FromBody] ModuleData value)
        {
            _logger.LogInformation("File Posted1 Before Save " + value.ModuleName);

            try
            {
                dynamic existing = await _rulesRepository.QueryAsync <RulesModuleModel, RulesModule, object, object>
                                   (
                    q => q.Select(r => new { r.RulesModuleId, r.Application, r.Name })
                    .SingleOrDefault(r => r.Application == value.Application && r.Name == value.ModuleName)
                                   );

                RulesModuleModel model = new RulesModuleModel
                {
                    Application     = value.Application,
                    Name            = value.ModuleName,
                    RuleSetFile     = value.RulesStream,
                    ResourceSetFile = value.ResourcesStream,
                    LastUpdated     = DateTime.UtcNow,
                    RulesModuleId   = existing == null ? 0 : existing.RulesModuleId,
                    EntityState     = existing == null ? LogicBuilder.Domain.EntityStateType.Added : LogicBuilder.Domain.EntityStateType.Modified
                };

                if (await this._rulesRepository.SaveAsync <RulesModuleModel, RulesModule>(model))
                {
                    _logger.LogInformation("Saved " + value.ModuleName);
                    await this._rulesManager.LoadSelectedModules(new List <string> {
                        model.Name
                    });

                    return(Created($"/api/[controller]/{model.RulesModuleId}", model));
                }
                else
                {
                    _logger.LogInformation("Not Saved " + value.ModuleName);
                    return(BadRequest("Not Saved"));
                }
            }
            catch (Exception ex)
            {
                this._logger.LogError(ex, ex.Message);
                _logger.LogInformation("Exception on Save " + value.ModuleName);
                return(BadRequest(ex.Message));
            }
        }
Ejemplo n.º 2
0
        public void LoadRules(RulesModuleModel module, RulesCache cache)
        {
            string  moduleName = module.Name.ToLowerInvariant();
            RuleSet ruleSet    = module.DeserializeRuleSetFile();

            if (ruleSet == null)
            {
                throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, Properties.Resources.invalidRulesetFormat, moduleName));
            }

            cache.RuleEngines.Add(moduleName, new RuleEngine(ruleSet, RulesSerializer.GetValidation(ruleSet)));

            using (IResourceReader reader = new ResourceReader(new MemoryStream(module.ResourceSetFile)))
            {
                reader.OfType <DictionaryEntry>()
                .ToList()
                .ForEach(entry => cache.ResourceStrings.Add((string)entry.Key, (string)entry.Value));
            }
        }
 /// <summary>
 /// Returns a rule set given a RulesModuleModel record
 /// </summary>
 /// <param name="module"></param>
 /// <returns></returns>
 public static RuleSet DeserializeRuleSetFile(this RulesModuleModel module)
 {
     using (StreamReader inStream = new StreamReader(new MemoryStream(module.RuleSetFile)))
         return(DeserializeRuleSet(inStream.ReadToEnd()));
 }