/// <summary> /// Deserializes the translation table and the input file. Then it checks the input file for validity. /// After that it starts the conversion process. /// </summary> /// <param name="inputFile">The path to the input file.</param> /// <param name="outputFile">The path to the output file.</param> /// <param name="strictValidation">A flag which indicates if the GSDML should be checked for correctness.</param> private static void StartConversion(string inputFile, string outputFile, bool strictValidation) { if (strictValidation) { Util.CheckGsdFileForCorrectness(inputFile); } // Load the GSD and the translation table XML document. GsdDocument = Util.LoadXmlDocument(inputFile); var translationTable = Util.LoadTranslationTable(); if (translationTable.DocumentElement == null) { throw new XmlException("Could not load a XML file."); } // Add all conversion rules to a list. foreach (XmlNode node in translationTable.DocumentElement.ChildNodes) { TranslationRules.Add(node); } // Set FileName property of CAEX-element. AmlObject.GetType().GetProperties().FirstOrDefault(p => p.Name.Equals("FileName"))?.SetValue(AmlObject, new FileInfo(outputFile).Name); Logger?.Log(LogLevel.Debug, "Added the FileName attribute to the CAEXFile element."); Logger?.Log(LogLevel.Info, "Start the Handle function."); Handle(GsdDocument.DocumentElement, AmlObject); Logger?.Log(LogLevel.Info, "Successfully ended the Handle function."); }
public ActionResult DeleteConfirmed(int id) { TranslationRules translationRules = db.TranslationRules.Find(id); db.TranslationRules.Remove(translationRules); db.SaveChanges(); return(RedirectToAction("Index")); }
public ActionResult Edit(TranslationRules translationRules) { if (ModelState.IsValid) { db.Entry(translationRules).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(translationRules)); }
public ActionResult Create(TranslationRules translationRules) { if (ModelState.IsValid) { db.TranslationRules.Add(translationRules); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(translationRules)); }
// GET: TranslationRules/Delete/5 public ActionResult Delete(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } TranslationRules translationRules = db.TranslationRules.Find(id); if (translationRules == null) { return(HttpNotFound()); } return(View(translationRules)); }
/// <summary> /// Starts the real conversion process. /// It iterates over the GSDML properties and translates it to AML. /// Then it recursively starts a new Handle call with the translated property. /// </summary> /// <typeparam name="TA">The type of the current AML head object.</typeparam> /// <param name="currentAmlHead">The current AML head object.</param> /// <param name="currentGsdHead">The current GSD head object as a XmlElement.</param> private static void Handle <TA>(XmlNode currentGsdHead, TA currentAmlHead) { Logger?.Log(LogLevel.Debug, $"Started the Handle function with these heads. GSD: {currentGsdHead.Name} AML: {currentAmlHead.GetType().Name}"); // Iterate over the properties of the current GSD parent. foreach (XmlNode gsdChildNode in currentGsdHead.ChildNodes) { Logger?.Log(LogLevel.Debug, $"Current iterated GSD child node {gsdChildNode.Name}."); // Try to get a translation rule of the gsdTranslationElements list. var translationRule = TranslationRules.FirstOrDefault(node => node.Name.Equals(gsdChildNode.Name)); // If the rule does not exist, it cannot be translated. It continues with the next property. if (translationRule == null) { Logger?.Log(LogLevel.Debug, $"Translation rule for {gsdChildNode.Name} was not found. Skip the node."); continue; } Logger?.Log(LogLevel.Debug, $"Translation rule was found for {gsdChildNode.Name}. Now we are trying to translate it."); // Translate the gsdChildNode to AML. var newAmlHead = Translate(ref currentAmlHead, translationRule); Logger?.Log(LogLevel.Info, $"Translated successfully {gsdChildNode.Name} to {translationRule["Replacement"]?.FirstChild.Name}."); // If the new AML head is an array, it calls for every element in the array the Handle function. if (newAmlHead.GetType().IsArray) { Logger?.Log(LogLevel.Debug, "The translated AML head is an array. Therefore for every element it calls the Handle function."); foreach (var amlHeadElement in newAmlHead) { Handle(gsdChildNode, amlHeadElement); } } else { // Call the Handle function with the current gsdChildNode and the new AML head. Logger?.Log(LogLevel.Debug, "The translated AML is not an array. Therefore the Handle function will be directly called."); Handle(gsdChildNode, newAmlHead); } } Logger?.Log(LogLevel.Info, $"The Handle function ended for these heads. AML: {currentAmlHead.GetType().Name} GSD: {currentGsdHead.Name}"); }
/// <summary> /// This function handles a new Rule call in the translation table. /// It takes the inner text of the rule node and translate it with the corresponding rule. /// </summary> /// <param name="childNode">The rule node which contains the information which rule should be applied.</param> /// <param name="replacementInstance">The instance in which the rule instance will be set/added.</param> private static void HandleRuleCall(XmlNode childNode, dynamic replacementInstance) { // Get the translation rule var translationRule = TranslationRules.FirstOrDefault(node => node.Name.Equals(childNode.InnerText)); if (translationRule == null) { Logger?.Log(LogLevel.Debug, $"Translation rule for {childNode.Name} was not found. Skip the node."); return; } var lastNode = Util.IterateThroughGsdDocument(translationRule.Name); if (lastNode == null) { Logger?.Log(LogLevel.Warning, $"Failed to iterate thorugh a rule path. {translationRule.Name}"); // throw new InvalidDataException("Failed to handle a rule call in translation table."); } var preLastnode = (XmlElement)lastNode.ParentNode; var(ruleReplacement, _, refList) = Util.GetInformationFromRule(translationRule); var nodeList = preLastnode?.GetElementsByTagName(lastNode.Name); if (nodeList == null) { Logger?.Log(LogLevel.Error, $"Could not create a list out of {lastNode.Name}."); throw new InvalidDataException("Could not create a list out of a rule call in translation table."); } foreach (XmlNode node in nodeList) { var ruleReferences = Util.ParseReferences(refList, node); var(_, ruleReplacementPropertyType, isRuleReplacementPropertyArray) = Util.GetProperty(ruleReplacement.Name); var ruleReplacementInstance = Util.CreateInstance(ruleReplacementPropertyType, isRuleReplacementPropertyArray); SetAttributes(ruleReplacement, ruleReplacementInstance, ruleReferences); AddSubInstancesToInstance(ruleReplacement, ruleReplacementInstance, isRuleReplacementPropertyArray, ruleReferences); replacementInstance.Add(ruleReplacementInstance); } }
public static FieldStatus[,] GetMapByFieldStatus(char[,] entryMap) { int xMax = (entryMap != null)? entryMap.GetLength(0) : 0; // + 1; int yMax = (entryMap != null) ? entryMap.GetLength(1) : 0; FieldStatus[,] map = new FieldStatus[xMax, yMax]; TranslationResult[,] translationMap = new TranslationResult[xMax, yMax]; TranslationResult[] container; for (int y = 0; y < yMax /*- 1*/; y++) { for (int x = 0; x < xMax /*- 1*/; x++) { container = TranslationRules.TranslateCoordinate(entryMap[x, y], x, y); foreach (TranslationResult trans in container) { if (trans == null) { continue; } if (translationMap[trans.X, trans.Y] != null) { translationMap[trans.X, trans.Y] = TranslationRules.SolveConflicts(trans, translationMap[trans.X, trans.Y]); } else { translationMap[trans.X, trans.Y] = trans; } map[trans.X, trans.Y] = translationMap[trans.X, trans.Y].Status; } } } return(map); }