public void PackConstValue(string type, object value, string expected) { var converter = new RulesConverter(); var dictionary = new Dictionary <string, string> { ["manifests/some/const.json"] = JsonConvert.SerializeObject(new { key_path = "some/const", dependencies = new string[] { }, valueType = type, meta = new { name = "test", }, implementation = new { type = "const", value, }, }), }; var results = converter.Convert("id", dictionary.Keys, name => dictionary[name]); var packedKey = JsonConvert.DeserializeObject <Dictionary <string, KeyDef> >(results.Item2)["some/const"]; Assert.Equal(expected, packedKey.Payload); Assert.Equal("const", packedKey.Format); Assert.Empty(packedKey.Dependencies); }
public RulesController( RulesConverter ruleConverter, IBeginConversionHelper beginConversionHelper) { this.ruleConverter = ruleConverter; this.beginConversionHelper = beginConversionHelper; }
public RulesController( RulesConverter ruleConverter, IKeyGenerator keyGenerator, ILogger <RulesController> logger) { this.ruleConverter = ruleConverter; this.keyGenerator = keyGenerator; this.logger = logger; }
private void ProcessRules(OutputFormat language, string ruleInput) { try { var outputCode = Program.Settings.Find <CodeSettings>(); outputCode.SetInstance(FileUtils.GetFileNameOnly(ruleInput), Environment.CurrentDirectory, language); var outputDocument = Program.Settings.Find <DocumentSettings>(); outputDocument.SetInstance(FileUtils.GetFileNameOnly(ruleInput), Environment.CurrentDirectory, OutputFormat.Docx); if (_processAssembly != null) { RulesExtractor rulesExtractor; if (_processAssembly.Value) // assembly loading { rulesExtractor = RulesExtractor.Create(_assemblyResolver.GetResourceData(ruleInput)); rulesExtractor.OnMessageReceived += RulesExtractorOnMessageReceived; } else // rule file loading { rulesExtractor = RulesExtractor.CreateFromFile(ruleInput); rulesExtractor.OnMessageReceived += RulesExtractorOnMessageReceived; } using (var rulesConverter = new RulesConverter(rulesExtractor, _runAsync)) { rulesConverter.AddOutput <RulesCodeGenerator>(outputCode); if (_generateWordDocumentAutomatically) { rulesConverter.AddOutput <RulesDocGenerator>(outputDocument); } rulesConverter.OnMessageReceived += RulesConverterOnMessageReceived; rulesConverter.OnProcessingComplete += RulesConverterOnProcessingComplete; rulesConverter.Generate(); } } } catch (WorkflowMarkupSerializationException workflowException) { UpdateError(this, new MessageEventArgs(String.Format("There is error in retrieving XOML at Line: {0} Position: {1}.", workflowException.LineNumber, workflowException.LinePosition), Base.EventType.Error)); UpdateOutput(this, new MessageEventArgs("[ERROR]: Recommended fix- Copy the rules and edit XOML based on error and retry with new rules file", Base.EventType.Error)); UpdateOutput(this, new MessageEventArgs("Generation Failed!", Base.EventType.Error)); } catch (Exception ex) { UpdateError(this, new MessageEventArgs(ex.Message, Base.EventType.Error)); UpdateOutput(this, new MessageEventArgs("Generation Failed!", Base.EventType.Error)); } }
public RulesConverterTest() { this.mockBlobStorageClient = new Mock <IBlobStorageClient>(); this.mockStorageAdapterClient = new Mock <IStorageAdapterClient>(); this.mockLog = new Mock <ILogger <RulesConverter> >(); this.rand = new Random(); this.entityHelper = new CreateEntityHelper(this.rand); this.converter = new RulesConverter( this.mockBlobStorageClient.Object, this.mockStorageAdapterClient.Object, this.mockLog.Object); }
private static void TransformExcelFiltersToThunderbirdFilters(string[] args) { // read and validate arguments if (args.Length != 2) { Logger.Log("You have not provided input arguments"); Console.ReadLine(); return; } var excelRulesFileName = args[0]; var thunderbirdRulesFileName = args[1]; if (!File.Exists(excelRulesFileName)) { Logger.Log("Excel file does not exist"); Console.ReadLine(); return; } if (!File.Exists(thunderbirdRulesFileName)) { Logger.Log("Thunderbird file does not exist"); Console.ReadLine(); return; } // make sure that thunderbird has not upgraded the format of the config file (from version 9) var msgFilterRulesFile = new FileParser().Parse(thunderbirdRulesFileName); var version = msgFilterRulesFile.Version; if (version != "9") { Logger.Log($"Thunderbird seems to have upgraded its config file version from 9 to `{version}`"); Console.ReadLine(); return; } // read my current filtering rules from excel ExcelRulesReader reader = new(); var rules = reader.Read(excelRulesFileName); // convert to Thunderbird's model var tbRules = new RulesConverter().Convert(rules); Dictionary <string, string>?metadata = new() { { "version", "9" }, { "logging", "yes" } };
private void ProcessWorkflow() { //TODO: Find a better way of doing this... if (treeLoaded == null) { return; } var inputFile = (BindItem)treeLoaded.Nodes[0].Tag; var outputDocument = Program.Settings.Find <DocumentSettings>(); outputDocument.SetInstance(FileUtils.GetFileNameOnly(inputFile.Name), Environment.CurrentDirectory, OutputFormat.Docx); if (_assemblyResolver == null) { return; } var workflowExtractor = new WorkflowExtractor(_assemblyResolver); workflowExtractor.OnMessageReceived += WorkflowExtractorOnMessageReceived; workflowExtractor.GetActivityTree(); RulesExtractor rulesExtractor = RulesExtractor.Create(_assemblyResolver); rulesExtractor.OnMessageReceived += RulesExtractorOnMessageReceived; using (var rulesConverter = new RulesConverter(rulesExtractor, _runAsync)) { rulesConverter.OnMessageReceived += RulesConverterOnMessageReceived; rulesConverter.OnProcessingComplete += RulesConverterOnProcessingComplete; } using (var converter = new WorkflowConverter(workflowExtractor, rulesExtractor)) { converter.OnMessageReceived += ConverterOnMessageReceived; converter.OnProcessingComplete += ConverterOnProcessingComplete; converter.AddOutput <Generators.Workflow.WfDocGenerator>(outputDocument); converter.Generate(); } }
public void PackAlias() { var converter = new RulesConverter(); var dictionary = new Dictionary <string, string> { ["manifests/some/alias.json"] = JsonConvert.SerializeObject(new { key_path = "some/alias", dependencies = new string[] { }, implementation = new { type = "alias", key = "some/other_key", }, }), }; var results = converter.Convert("id", dictionary.Keys, x => dictionary[x]); var packedKey = JsonConvert.DeserializeObject <Dictionary <string, KeyDef> >(results.Item2)["some/alias"]; Assert.Equal("some/other_key", packedKey.Payload); Assert.Equal("alias", packedKey.Format); Assert.Contains(packedKey.Dependencies, x => x == "some/other_key"); }
public void PackJPad() { var converter = new RulesConverter(); var jpad = JsonConvert.SerializeObject(new { partitions = new string[] { }, rules = new object[] { }, valueType = "number", defaultValue = 5, }); var dictionary = new Dictionary <string, string> { ["manifests/some/jpad_example.json"] = JsonConvert.SerializeObject(new { key_path = "some/jpad_example", dependencies = new string[] { }, valueType = "number", meta = new { name = "test", }, implementation = new { type = "file", format = "jpad", }, }), ["implementations/jpad/some/jpad_example.jpad"] = jpad, }; var results = converter.Convert("id", dictionary.Keys, name => dictionary[name]); var packedKey = JsonConvert.DeserializeObject <Dictionary <string, KeyDef> >(results.Item2)["some/jpad_example"]; Assert.Equal(jpad, packedKey.Payload); Assert.Equal("jpad", packedKey.Format); Assert.Empty(packedKey.Dependencies); }
private void ProcessWorkflow() { //TODO: Find a better way of doing this... if (treeLoaded == null) return; var inputFile = (BindItem)treeLoaded.Nodes[0].Tag; var outputDocument = Program.Settings.Find<DocumentSettings>(); outputDocument.SetInstance(FileUtils.GetFileNameOnly(inputFile.Name), Environment.CurrentDirectory, OutputFormat.Docx); if (_assemblyResolver == null) return; var workflowExtractor = new WorkflowExtractor(_assemblyResolver); workflowExtractor.OnMessageReceived += WorkflowExtractorOnMessageReceived; workflowExtractor.GetActivityTree(); RulesExtractor rulesExtractor = RulesExtractor.Create(_assemblyResolver); rulesExtractor.OnMessageReceived += RulesExtractorOnMessageReceived; using (var rulesConverter = new RulesConverter(rulesExtractor, _runAsync)) { rulesConverter.OnMessageReceived += RulesConverterOnMessageReceived; rulesConverter.OnProcessingComplete += RulesConverterOnProcessingComplete; } using (var converter = new WorkflowConverter(workflowExtractor, rulesExtractor)) { converter.OnMessageReceived += ConverterOnMessageReceived; converter.OnProcessingComplete += ConverterOnProcessingComplete; converter.AddOutput<Generators.Workflow.WfDocGenerator>(outputDocument); converter.Generate(); } }
private void ProcessRules(OutputFormat language, string ruleInput) { try { var outputCode = Program.Settings.Find<CodeSettings>(); outputCode.SetInstance(FileUtils.GetFileNameOnly(ruleInput), Environment.CurrentDirectory, language); var outputDocument = Program.Settings.Find<DocumentSettings>(); outputDocument.SetInstance(FileUtils.GetFileNameOnly(ruleInput), Environment.CurrentDirectory, OutputFormat.Docx); if (_processAssembly != null) { RulesExtractor rulesExtractor; if (_processAssembly.Value) // assembly loading { rulesExtractor = RulesExtractor.Create(_assemblyResolver.GetResourceData(ruleInput)); rulesExtractor.OnMessageReceived += RulesExtractorOnMessageReceived; } else // rule file loading { rulesExtractor = RulesExtractor.CreateFromFile(ruleInput); rulesExtractor.OnMessageReceived += RulesExtractorOnMessageReceived; } using (var rulesConverter = new RulesConverter(rulesExtractor, _runAsync)) { rulesConverter.AddOutput<RulesCodeGenerator>(outputCode); if (_generateWordDocumentAutomatically) rulesConverter.AddOutput<RulesDocGenerator>(outputDocument); rulesConverter.OnMessageReceived += RulesConverterOnMessageReceived; rulesConverter.OnProcessingComplete += RulesConverterOnProcessingComplete; rulesConverter.Generate(); } } } catch (WorkflowMarkupSerializationException workflowException) { UpdateError(this, new MessageEventArgs(String.Format("There is error in retrieving XOML at Line: {0} Position: {1}.", workflowException.LineNumber, workflowException.LinePosition), Base.EventType.Error)); UpdateOutput(this, new MessageEventArgs("[ERROR]: Recommended fix- Copy the rules and edit XOML based on error and retry with new rules file", Base.EventType.Error)); UpdateOutput(this, new MessageEventArgs("Generation Failed!", Base.EventType.Error)); } catch (Exception ex) { UpdateError(this, new MessageEventArgs(ex.Message, Base.EventType.Error)); UpdateOutput(this, new MessageEventArgs("Generation Failed!", Base.EventType.Error)); } }