public string ParseCode(Translator translator, TreeReader reader) { var data = new List <string>(); foreach (var arg in Args) { data.Add(translator.Emulate(arg, false)); } if ( Value.Args.Count == 1 && Value.Args[0].IsDotUsed && (Value.Args[0].Body[0] is VariableLexeme variableLexeme && variableLexeme.Value == "init") ) { return($"new TENGRI_{Value.Value}(new dynamic[] {{{string.Join(",", data)}}})" + (translator.InBlock ? ";" : "")); } if (Value.Value == "throw" && Args.Count == 1) { var variable = translator.Emulate(Args[0], false); return($"throw {variable};"); } var main = Value.BuildVar(translator); return($"{main}(new dynamic[] {{{string.Join(",", data)}}})" + (translator.InBlock ? ";" : "")); }
static void Main() { Tree <int> tree = TreeReader.ReadIntegerTreeValues(); int deepestNodeValue = GetDeepestNode(tree); Console.WriteLine($"Deepest node: {deepestNodeValue}"); }
// Add object with no attribute list defined private static void addObject(Dictionary <string, List <string> > objectList, HlaObject obj, HlaObjectNode hlaObjectTree) { // If the object is not in the list, add it if (!objectList.ContainsKey(obj.ObjectClassName)) { // Get the complete attribute list objectList.Add(obj.ObjectClassName, TreeReader.FindAttributes(hlaObjectTree, obj.ObjectClassName)); } }
public string ParseCode(Translator translator, TreeReader reader) { var variable = Variable == null ? "ex" : Variable.Value; return($"try {{ {translator.Emulate(TryBlock)} }} " + $"catch (Exception SYS_TENGRI_{variable})" + $"{{ var TENGRI_{variable} = new TENGRI_exceptionData(SYS_TENGRI_{variable}.Message, SYS_TENGRI_{variable}.Source); {translator.Emulate(CatchBlock)} }}" + (FinallyBlock.Count != 0 ? $"finally {{{translator.Emulate(FinallyBlock)}}}" : "")); }
static void Main() { Tree <int> tree = TreeReader.ReadIntegerTreeValues(); List <int> result = new List <int>(); GetLeaves(tree, result); result.Sort(); Console.WriteLine($"Leaf nodes: {string.Join(" ", result)}"); }
static void Main() { Tree <int> tree = TreeReader.ReadIntegerTreeValues(); List <int> longestPath = new List <int>(); List <int> currentPath = new List <int>(); FindLongestPath(tree, longestPath, currentPath); Console.WriteLine($"Longest path: {string.Join(" ", longestPath)}"); }
public string ParseCode(Translator translator, TreeReader reader) { var code = "new TengriArray(new Dictionary<dynamic, dynamic> {"; var elements = new List <string>(); foreach (var arrItem in Array) { elements.Add($"{{ \"{arrItem.Key.Replace("\"", "\\\"")}\", {translator.Emulate(arrItem.Value, false)} }}"); } return(code + $"{string.Join(",", elements)}}})"); }
private TreeElement ParseLoop(TreeBuilder builder, TreeReader reader) { if (Value == "while" || Value == "do") { var cond = ParseToBracket(reader); reader.Next(); var block = builder.ParseInBrackets('{', '}')[0]; if (Value == "while") { return(new WhileElement(this, cond, block)); } return(new DoWhileElement(this, cond, block)); } else if (Value == "for") { var cond = ParseToBracket(reader); reader.Next(); VariableLexeme variable = null; List <TreeElement> startValue = new List <TreeElement>(); List <TreeElement> endValue = new List <TreeElement>(); var block = builder.ParseInBrackets('{', '}')[0]; var dotCount = 0; var toStartValue = true; for (int i = 0; i < cond.Count; i++) { if (cond[i] is VariableLexeme variableLexeme && toStartValue) { variable = variableLexeme; if (variableLexeme.Args.Count > 0) { Exception("Wrong for construction!"); } } else if (i == 0) { Exception("Wrong for construction!"); } else if (cond[i] is SpecialLexeme specialLexeme && toStartValue && specialLexeme.Value == ".") { dotCount++; if (dotCount == 3) { toStartValue = false; } }
static void Main() { Tree <int> inputTree = TreeReader.ReadIntegerTreeValues(); int requestedSum = int.Parse(Console.ReadLine()); List <Tree <int> > subTrees = GetSubtreesWithGivenSum(inputTree, requestedSum); Console.WriteLine($"Subtrees of sum {requestedSum}:"); subTrees.ForEach(st => { st.Each(node => Console.Write($"{node} ")); Console.WriteLine(); } ); }
public string ParseCode(Translator translator, TreeReader reader) { var variable = Left.BuildVar(translator); if (translator.ClassName != null) { return($"{variable} {Operator} {translator.Emulate(Right, false)}" + (translator.InBlock ? ";" : "")); } else if (translator.ClassName == null && Operator == "=") { return($"class SYS_TENGRI_GLOBAL_{Left.Value} {{ public static dynamic {variable} = {translator.Emulate(Right, false)};}}"); } return(null); }
static void Main() { Tree <int> inputTree = TreeReader.ReadIntegerTreeValues(); int requestedSum = int.Parse(Console.ReadLine()); List <List <int> > allPaths = new List <List <int> >(); List <int> path = new List <int>(); GetAllPathsWithAGivenSum(inputTree, allPaths, path, 0, requestedSum); Console.WriteLine($"Paths of sum {requestedSum}:"); foreach (var currentPath in allPaths) { Console.WriteLine(string.Join(" ", currentPath)); } }
public TreeElement ParseElement(TreeBuilder builder, TreeReader reader) { if (reader.Read(1) is SpecialLexeme specialLexeme && specialLexeme.Value == "{" && IsFuncBrackets) { reader.Next(2); var args = new List <List <TreeElement> >() { new List <TreeElement>() }; foreach (var treeElement in Block) { if (treeElement is SpecialLexeme special && special.Value == ",") { args.Add(new List <TreeElement>()); }
public TreeElement ParseElement(TreeBuilder builder, TreeReader reader) { if (Right.Count == 1 && Right[0] is BlockElement block && !block.IsFuncBrackets) { var data = block.Block.Where(e => e is DeclareFieldElement); foreach (var obj in data) { var declareField = obj as DeclareFieldElement; declareField.ClassName = Left.Value; } var declareClass = new DeclareClassElement(Left, block.Block, FuncType.Public); return(declareClass.ParseElement(builder, reader) ?? declareClass); } return(null); }
public string ParseCode(Translator translator, TreeReader reader) { string code = $"if ({translator.Emulate(Condition, false)})"; code += "{" + translator.Emulate(ThenBlock, true, translator.IsStaticBlock) + "}"; foreach (var elifBlock in ElifBlocks) { code += $"else if ({translator.Emulate(elifBlock.Key)})"; code += "{" + translator.Emulate(elifBlock.Value, true, translator.IsStaticBlock) + "}"; } if (ElseBlock != null) { code += "else {" + translator.Emulate(ElseBlock, true, translator.IsStaticBlock) + "}"; } return(code); }
public string ParseCode(Translator translator, TreeReader reader) { if (translator.IsStaticBlock && FieldName == "init") { Exception("Creating a constructor in static block!"); } string code = (translator.IsStaticBlock ? "static " : "") + $"{translator.TypeToString(Type)} dynamic TENGRI_{FieldName} = {translator.Emulate(Body, false)};"; if (Body.Count == 1 && Body[0] is DeclareFunctionElement functionElement) { if (FieldName == "main" && translator.IsStaticBlock) { code += "static void Main(string[] args) {{TENGRI_main(args); TENGRI_console.TENGRI_input(null); }}"; } else if (FieldName == "init") { code += $"{translator.TypeToString(Type)} TENGRI_{ClassName}(dynamic[] args) {{ TENGRI_init(args); }}"; } } return(code); }
public TreeElement ParseElement(TreeBuilder builder, TreeReader reader) { switch (Value) { case "@": if (reader.Read() is VariableLexeme variableLexeme) { if (!builder.AvailableAttributes.Split(' ').Contains(variableLexeme.Value)) { variableLexeme.Exception($"Unknown attribute \"{variableLexeme.Value}\""); } reader.Next(); return(new AttributeElement(variableLexeme)); } return(null); case "{": var blockClass = new BlockElement(this, builder.ParseInBrackets('{', '}')[0]); return(blockClass.ParseElement(builder, reader)); case "[": return(ParseArray(builder, reader)); case ",": return(this); case "(": var block = new BlockElement(this, builder.ParseInBrackets('(', ')')[0]) { IsFuncBrackets = true }; return(block.ParseElement(builder, reader)); default: return(null); } }
public string ParseCode(Translator translator, TreeReader reader) { string code = Name == null ? $"(TengriData.TengriMethod)({ArgsName} => {{" : $"class SYS_TENGRI_GLOBAL_{Name} {{ public static dynamic TENGRI_{Name}(dynamic[] {ArgsName}) {{"; var i = 0; foreach (var arg in Args) { if (arg.Count == 0) { continue; } if (!(arg[0] is VariableLexeme || arg[0] is AssignElement)) { Exception("Wrong args!"); } if (arg[0] is AssignElement assign) { var val = translator.Emulate(assign.Right, false); code += $"dynamic TENGRI_{assign.Left.Value};if ({ArgsName}.Length - 1 < {i})" + "{TENGRI_" + assign.Left.Value + " = " + val + ";}else{TENGRI_" + assign.Left.Value + $" = {ArgsName}[" + (i) + "];}"; } else { var variable = arg[0] as VariableLexeme; code += $"dynamic TENGRI_{variable.Value} = {ArgsName}[{i}];"; } i++; } code += translator.Emulate(Body); code += "return null;"; return(Name == null ? (code + "})") : code + "}}"); }
private DeclareArrayElement ParseArray(TreeBuilder builder, TreeReader reader) { var block = builder.ParseInBrackets('[', ']')[0]; var data = new Dictionary <string, List <TreeElement> >(); var index = 0; foreach (var treeElement in block) { if (treeElement is DeclareFieldElement fieldElement) { data.Add(fieldElement.FieldName, fieldElement.Body); } else { if (treeElement is SpecialLexeme specialLexeme && specialLexeme.Value == ",") { index++; continue; } if (data.ContainsKey(index.ToString())) { data[index.ToString()].Add(treeElement); } else { data.Add(index.ToString(), new List <TreeElement> { treeElement }); } } } return(new DeclareArrayElement(this, data)); }
public TreeBuilder(string file, List <TreeElement> elements) { _reader = new TreeReader(elements); _file = file; }
public string ParseCode(Translator translator, TreeReader reader) => Value ? "true" : "false";
public string ParseCode(Translator translator, TreeReader reader) => Value.ToString().Replace(',', '.');
public static TreeReader[] createEncodedTreeReader(int numCols, List<OrcProto.Type> types, List<OrcProto.ColumnEncoding> encodings, EncodedColumnBatch<OrcBatchKey> batch, CompressionCodec codec, bool skipCorrupt) { long file = batch.getBatchKey().file; TreeReader[] treeReaders = new TreeReader[numCols]; for (int i = 0; i < numCols; i++) { int columnIndex = batch.getColumnIxs()[i]; ColumnStreamData[] streamBuffers = batch.getColumnData()[i]; OrcProto.Type columnType = types[columnIndex]; // EncodedColumnBatch is already decompressed, we don't really need to pass codec. // But we need to know if the original data is compressed or not. This is used to skip // positions in row index properly. If the file is originally compressed, // then 1st position (compressed offset) in row index should be skipped to get // uncompressed offset, else 1st position should not be skipped. // TODO: there should be a better way to do this, code just needs to be modified OrcProto.ColumnEncoding columnEncoding = encodings[columnIndex]; // stream buffers are arranged in enum order of stream kind ColumnStreamData present = streamBuffers[Kind.PRESENT_VALUE], data = streamBuffers[Kind.DATA_VALUE], dictionary = streamBuffers[Kind.DICTIONARY_DATA_VALUE], lengths = streamBuffers[Kind.LENGTH_VALUE], secondary = streamBuffers[Kind.SECONDARY_VALUE]; switch (columnType.Kind) { case OrcProto.Type.Types.Kind.BINARY: treeReaders[i] = BinaryStreamReader.builder() .setFileId(file) .setColumnIndex(columnIndex) .setPresentStream(present) .setDataStream(data) .setLengthStream(lengths) .setCompressionCodec(codec) .setColumnEncoding(columnEncoding) .build(); break; case OrcProto.Type.Types.Kind.BOOLEAN: treeReaders[i] = BooleanStreamReader.builder() .setFileId(file) .setColumnIndex(columnIndex) .setPresentStream(present) .setDataStream(data) .setCompressionCodec(codec) .build(); break; case OrcProto.Type.Types.Kind.BYTE: treeReaders[i] = ByteStreamReader.builder() .setFileId(file) .setColumnIndex(columnIndex) .setPresentStream(present) .setDataStream(data) .setCompressionCodec(codec) .build(); break; case OrcProto.Type.Types.Kind.SHORT: treeReaders[i] = ShortStreamReader.builder() .setFileId(file) .setColumnIndex(columnIndex) .setPresentStream(present) .setDataStream(data) .setCompressionCodec(codec) .setColumnEncoding(columnEncoding) .build(); break; case OrcProto.Type.Types.Kind.INT: treeReaders[i] = IntStreamReader.builder() .setFileId(file) .setColumnIndex(columnIndex) .setPresentStream(present) .setDataStream(data) .setCompressionCodec(codec) .setColumnEncoding(columnEncoding) .build(); break; case OrcProto.Type.Types.Kind.LONG: treeReaders[i] = LongStreamReader.builder() .setFileId(file) .setColumnIndex(columnIndex) .setPresentStream(present) .setDataStream(data) .setCompressionCodec(codec) .setColumnEncoding(columnEncoding) .skipCorrupt(skipCorrupt) .build(); break; case OrcProto.Type.Types.Kind.FLOAT: treeReaders[i] = FloatStreamReader.builder() .setFileId(file) .setColumnIndex(columnIndex) .setPresentStream(present) .setDataStream(data) .setCompressionCodec(codec) .build(); break; case OrcProto.Type.Types.Kind.DOUBLE: treeReaders[i] = DoubleStreamReader.builder() .setFileId(file) .setColumnIndex(columnIndex) .setPresentStream(present) .setDataStream(data) .setCompressionCodec(codec) .build(); break; case OrcProto.Type.Types.Kind.CHAR: treeReaders[i] = CharStreamReader.builder() .setFileId(file) .setColumnIndex(columnIndex) .setMaxLength((int)columnType.MaximumLength) .setPresentStream(present) .setDataStream(data) .setLengthStream(lengths) .setDictionaryStream(dictionary) .setCompressionCodec(codec) .setColumnEncoding(columnEncoding) .build(); break; case OrcProto.Type.Types.Kind.VARCHAR: treeReaders[i] = VarcharStreamReader.builder() .setFileId(file) .setColumnIndex(columnIndex) .setMaxLength((int)columnType.MaximumLength) .setPresentStream(present) .setDataStream(data) .setLengthStream(lengths) .setDictionaryStream(dictionary) .setCompressionCodec(codec) .setColumnEncoding(columnEncoding) .build(); break; case OrcProto.Type.Types.Kind.STRING: treeReaders[i] = StringStreamReader.builder() .setFileId(file) .setColumnIndex(columnIndex) .setPresentStream(present) .setDataStream(data) .setLengthStream(lengths) .setDictionaryStream(dictionary) .setCompressionCodec(codec) .setColumnEncoding(columnEncoding) .build(); break; case OrcProto.Type.Types.Kind.DECIMAL: treeReaders[i] = DecimalStreamReader.builder() .setFileId(file) .setColumnIndex(columnIndex) .setPrecision((int)columnType.Precision) .setScale((int)columnType.Scale) .setPresentStream(present) .setValueStream(data) .setScaleStream(secondary) .setCompressionCodec(codec) .setColumnEncoding(columnEncoding) .build(); break; case OrcProto.Type.Types.Kind.TIMESTAMP: treeReaders[i] = TimestampStreamReader.builder() .setFileId(file) .setColumnIndex(columnIndex) .setPresentStream(present) .setSecondsStream(data) .setNanosStream(secondary) .setCompressionCodec(codec) .setColumnEncoding(columnEncoding) .skipCorrupt(skipCorrupt) .build(); break; case OrcProto.Type.Types.Kind.DATE: treeReaders[i] = DateStreamReader.builder() .setFileId(file) .setColumnIndex(columnIndex) .setPresentStream(present) .setDataStream(data) .setCompressionCodec(codec) .setColumnEncoding(columnEncoding) .build(); break; default: throw new NotSupportedException("Data type not supported yet! " + columnType); } } return treeReaders; }
public static string Create(DeployObject deploy, Component component) { // Find the modules we need ModuleFederation federation = (ModuleFederation)findModule(component.Modules, Enums.ModuleType.federation); ModuleImport import = (ModuleImport)findModule(component.Modules, Enums.ModuleType.import); ModuleExport export = (ModuleExport)findModule(component.Modules, Enums.ModuleType.export); ModuleExtension extension = (ModuleExtension)findModule(component.Modules, Enums.ModuleType.extension); ModuleOsp[] osp = findModules(component.Modules); // Create an HlaObject tree to use when defining attribute lists StringReader ms = new StringReader(Properties.Resources.HLAfeatures); HlaObjectNode hlaObjectTree = TreeReader.CreateTree(ms); StringBuilder sb = new StringBuilder(); // Side A - always the side connected to a federation sb.AppendLine("# A side settings (Federation Side)"); sb.AppendLine("A.side_name=" + federation.FederationName); sb.AppendLine("A.description=Federate " + federation.FederateName + " on " + federation.FederationName + " federation"); switch (federation.RTI.HlaSpec) { case "Pitch pRTI 1516": sb.AppendLine("A.profile=A"); break; case "HLA Evolved": sb.AppendLine("A.profile=B"); break; case "Pitch pRTI 1.3": sb.AppendLine("A.profile=C"); break; case "RTI NG": sb.AppendLine("A.profile=D"); break; case "MAK 1.3 RTI": sb.AppendLine("A.profile=E"); break; case "MAK 1516 RTI": sb.AppendLine("A.profile=F"); break; case "RTI NG C++": sb.AppendLine("A.profile=G"); break; case "RTI DLC C++": sb.AppendLine("A.profile=H"); break; case "Evolved C++": sb.AppendLine("A.profile=I"); break; default: sb.AppendLine("A.profile=B"); break; } sb.AppendLine("A.configurationType=" + extension.Parameters["configurationType"]); sb.AppendLine("A.host=" + federation.RTI.CrcAddress); sb.AppendLine("A.port=" + federation.RTI.CrcPortNumber); sb.AppendLine("A.designator="); sb.AppendLine("A.federation=" + federation.FederationName); sb.AppendLine("A.type=" + deploy.Systems[0].SystemType.ToString()); sb.AppendLine("A.name=" + federation.FederateName); sb.AppendLine("A.create=" + extension.Parameters["create"]); sb.Append("A.evolvedFomModules="); for (int i = 0; i < federation.RTI.FomFile.Count; i++) { if (i == federation.RTI.FomFile.Count - 1) { sb.AppendFormat("{0}\n", federation.RTI.FomFile[i]); } else { sb.AppendFormat("{0};", federation.RTI.FomFile[i]); } } sb.AppendLine("A.destroy=false"); sb.AppendLine("A.disableRequest=false"); sb.AppendLine("A.logicalTimeFactoryClassName="); sb.AppendLine("A.conveyProducingFederate=true"); // If this is a High proxy then this is the Export Policy list, otherwise the Import Policy string result = (component.ComponentName.ToUpper().Contains("HIGH")) ? string.Join("; ", ListBuilder.ObjectList(export, hlaObjectTree)) : string.Join("; ", ListBuilder.ObjectList(import, hlaObjectTree)); sb.AppendLine("A.objects=" + result); // same idea for interactions result = (component.ComponentName.ToUpper().Contains("HIGH")) ? string.Join("; ", ListBuilder.InteractionList(export, hlaObjectTree)) : string.Join("; ", ListBuilder.InteractionList(import, hlaObjectTree)); sb.AppendLine("A.interactions=" + result); sb.AppendLine("A.filter=se.pitch.ral.extender.hpsd.Hpsd"); sb.AppendLine("A.filter.policy=" + component.ComponentName + ".xml"); sb.AppendLine(); // B Side -- Always connected to OSP sb.AppendLine("# B side settings (HPSD side)"); sb.AppendLine("B.side_name=" + component.ComponentName); sb.AppendLine("B.description=Federate " + federation.FederateName + " HPSD interface"); sb.AppendLine("B.profile=M"); // HPSD designator sb.AppendLine("B.configurationType=LocalSettingsDesignator"); sb.AppendLine("B.host=0.0.0.0"); sb.AppendLine("B.port=0"); sb.AppendFormat("B.designator={0};DEBUG;CONNECT_TIMEOUT\\=10;HEARTBEAT\\=5\n", getDesignator(osp, component)); sb.AppendLine("B.federation=" + component.ComponentName); sb.AppendLine("B.type=" + deploy.Systems[0].SystemType.ToString()); sb.AppendLine("B.name=" + federation.FederateName); sb.AppendLine("B.create=" + extension.Parameters["create"]); sb.Append("B.evolvedFomModules="); for (int i = 0; i < federation.RTI.FomFile.Count; i++) { if (i == federation.RTI.FomFile.Count - 1) { sb.AppendFormat("{0}\n", federation.RTI.FomFile[i]); } else { sb.AppendFormat("{0};", federation.RTI.FomFile[i]); } } sb.AppendLine("B.destroy=false"); sb.AppendLine("B.disableRequest=false"); sb.AppendLine("B.logicalTimeFactoryClassName="); sb.AppendLine("B.conveyProducingFederate=true"); // If this is a High proxy then this is the Import Policy list, otherwise the Export Policy result = (component.ComponentName.ToUpper().Contains("HIGH")) ? string.Join("; ", ListBuilder.ObjectList(import, hlaObjectTree)) : string.Join("; ", ListBuilder.ObjectList(export, hlaObjectTree)); sb.AppendLine("B.objects=" + result); // same idea for interactions result = (component.ComponentName.ToUpper().Contains("HIGH")) ? string.Join("; ", ListBuilder.InteractionList(import, hlaObjectTree)) : string.Join("; ", ListBuilder.InteractionList(export, hlaObjectTree)); sb.AppendLine("B.interactions=" + result); return(sb.ToString()); }
public string ParseCode(Translator translator, TreeReader reader) => Value.ToString();
public static XElement Create(DeployObject deploy, Component component) { HpsdPolicy hpsdPolicy = new HpsdPolicy(); // We can assume that there is only one System in the deploy doc DeploySystem system = deploy.Systems[0]; // PolicyIdentification <--> ConfigMgmt PolicyIdentification polID = new PolicyIdentification { PolicyName = system.FederateName, PolicyVersion = ConfigMgmt.VersionToString(deploy.ConfigMgmt.CurrentVersion), CreatedDate = deploy.ConfigMgmt.Created.date, ModifiedDate = deploy.ConfigMgmt.Changed[deploy.ConfigMgmt.Changed.Count - 1].date, Status = deploy.ConfigMgmt.DocReference.ToString(), Description = deploy.ConfigMgmt.Description }; // No POC information hpsdPolicy.PolicyIdentification = polID; // ======================================= // FomInformation <--> Federation, Extensions FomInformation fominfo = new FomInformation(); // List of fomModule in Federation module ModuleFederation fedModule = (ModuleFederation)findModule(component.Modules, Enums.ModuleType.federation); foreach (string file in fedModule.RTI.FomFile) { fominfo.FomModule.Add(file); } // InstanceIdAttributes are a Vendor extension ModuleExtension extModule = (ModuleExtension)findModule(component.Modules, Enums.ModuleType.extension); if (extModule.VendorName != "Pitch Technologies") { throw new ApplicationException("Pitch Technologies vendor extensions not found"); } foreach (KeyValuePair <string, string> p in extModule.Parameters) { // General format key = <identifier>:<parameterName> // we expect: key = instanceIdAttribute:<fully qualified attribute> string[] sa1 = p.Key.Split(':'); if (sa1[0] == "instanceIdAttribute") { string attribName = sa1[1].Split('.').Last(); string objclass = sa1[1].Substring(0, sa1[1].Length - (attribName.Length + 1)); // trailing '.' string encoding = p.Value; InstanceId instId = new InstanceId { ObjectClass = objclass, Attribute_Name = attribName, Attribute_Encoding = encoding }; fominfo.InstanceID.Add(instId); } } hpsdPolicy.FomInformation = fominfo; // ===================================================================================== // Federates <---> Export module Federates feds = new Federates(); // List of federates in Export module ModuleExport expModule = (ModuleExport)findModule(component.Modules, Enums.ModuleType.export); foreach (Source source in expModule.Sources) { feds.Federate.Add(source.FederateName); } hpsdPolicy.Federates = feds; // ===================================================================================== // PolicyRules <----> Export/Import module // Hack // Create an HlaObject tree to use when defining attribute lists StringReader ms = new StringReader(Properties.Resources.HLAfeatures); HlaObjectNode hlaObjectTree = TreeReader.CreateTree(ms); PolicyRules rules = new PolicyRules(); int ruleNumber = 0; if (component.ComponentName.ToUpper().Contains("HIGH")) { // Status message - session name = federateName SessionStatusReleaseRule sess = new SessionStatusReleaseRule { Condition_SessionName = system.FederateName, RuleName = ruleNumber++.ToString() }; rules.SessionStatus.Add(sess); // Object update/create foreach (Source source in expModule.Sources) { string federateName = source.FederateName; string entityID = ""; if (source.SourceType == Source.Type.Federate) { entityID = "*"; } else { entityID = source.EntityId; } foreach (HlaObject hlaObj in source.Objects) { ObjectReleaseReplaceRule obj = new ObjectReleaseReplaceRule() { Condition_ProducingFederate = federateName, Condition_InstanceID = entityID, RuleName = ruleNumber++.ToString(), Condition_ObjectClass = hlaObj.ObjectClassName.NoHlaRoot() }; // Hack if no attribs listed add all attribs from the TreeReader if (hlaObj.Attributes.Count == 0) { List <string> theworks = TreeReader.FindAttributes(hlaObjectTree, hlaObj.ObjectClassName); foreach (string attrib in theworks) { obj.Release_Attribute.Add(attrib); } rules.ObjectRelease.Add(obj); } else // Hack - read attributes from the object and add them; de-duplicate { List <string> temp = new List <string>(); foreach (HlaAttribute attrib in hlaObj.Attributes) { temp.Add(attrib.AttributeName); } obj.Release_Attribute = temp.Distinct().ToList(); rules.ObjectRelease.Add(obj); } } foreach (HlaInteraction hlaInt in source.Interactions) { InteractionReleaseReplaceRule intr = new InteractionReleaseReplaceRule() { Condition_ProducingFederate = federateName, RuleName = ruleNumber++.ToString(), Condition_InteractionClass = hlaInt.InteractionClassName.NoHlaRoot() }; List <string> temp = new List <string>(); foreach (HlaParameter para in hlaInt.Parameters) { temp.Add(para.ParameterName); } intr.Release_Parameter = temp.Distinct().ToList(); rules.InteractionRelease.Add(intr); } } } else { ModuleImport impModule = (ModuleImport)findModule(component.Modules, Enums.ModuleType.import); foreach (HlaObject hlaObj in impModule.Objects) { ObjectReleaseReplaceRule obj = new ObjectReleaseReplaceRule() { Condition_ProducingFederate = "*", Condition_InstanceID = "*", RuleName = ruleNumber++.ToString(), Condition_ObjectClass = hlaObj.ObjectClassName.NoHlaRoot() }; List <string> temp = new List <string>(); foreach (HlaAttribute attrib in hlaObj.Attributes) { temp.Add(attrib.AttributeName); } obj.Release_Attribute = temp.Distinct().ToList(); rules.ObjectRelease.Add(obj); } foreach (HlaInteraction hlaInt in impModule.Interactions) { InteractionReleaseReplaceRule intr = new InteractionReleaseReplaceRule() { Condition_ProducingFederate = "*", RuleName = ruleNumber++.ToString(), Condition_InteractionClass = hlaInt.InteractionClassName.NoHlaRoot() }; List <string> temp = new List <string>(); foreach (HlaParameter para in hlaInt.Parameters) { temp.Add(para.ParameterName); } intr.Release_Parameter = temp.Distinct().ToList(); rules.InteractionRelease.Add(intr); } } hpsdPolicy.PolicyRules = rules; return(hpsdPolicy.ToHPSD()); }
public string ParseCode(Translator translator, TreeReader reader) { return($"foreach (dynamic TENGRI_{VarName} in {Array.BuildVar(translator)}.TENGRI_invoke()) {{{translator.Emulate(Block, true, translator.IsStaticBlock)}}}"); }
public string ParseCode(Translator translator, TreeReader reader) => "null";
public string ParseCode(Translator translator, TreeReader reader) => $"\"{Value}\"";
public TreeElement ParseElement(TreeBuilder builder, TreeReader reader) => null;
public string ParseCode(Translator translator, TreeReader reader) { return($"for (dynamic TENGRI_{VarName} = {translator.Emulate(StartValue, false)}; TENGRI_{VarName} < {translator.Emulate(ToValue, false)}; TENGRI_{VarName}++) {{{translator.Emulate(Block, true, translator.IsStaticBlock)}}}"); }
public TreeElement ParseElement(TreeBuilder builder, TreeReader reader) { return(null); }