/// <summary> /// Creates new object /// </summary> /// <created> /// <author>DIVI Group</author> /// <created>2018.10.23</created> /// </created> /// <param name="pClass">class name</param> /// <param name="pName">objects name</param> /// <param name="pParameters">list of construction parameters</param> public static void NewObject(string pClass, string pName, string pParameters) { if (!Interpreter.IsBreakpoint) { // error validation if (Graphics.Variables.ContainsKey(pName)) { Interpreter.AddError(string.Format("Object with name [{0}] already exists.", pName)); } else { switch (pClass) { case CLASS_POINT: { Graphics.NewPoint(pName, pParameters); break; } case CLASS_LINE: { Graphics.NewLine(pName, pParameters); break; } default: { Interpreter.AddError(string.Format("Object of type [{0}] cannot be created.", pClass)); break; } } } } }
public override void Translate() { var value = GetValue(); var parts = value.Split(' '); var roman = String.Empty; var thingValue = 1m; var lastRoman = parts.Length; for (var p = 0; p < parts.Length; p++) { var part = parts[p]; if (Interpreter.ConversionDictionary.ContainsKey(part)) { roman += Interpreter.ConversionDictionary[part]; } else { lastRoman = p; break; } } parts = parts.Skip(lastRoman).ToArray(); if (parts.Any()) { var thingName = String.Join(" ", parts); if (Interpreter.ThingValueDictionary.ContainsKey(thingName)) { thingValue *= Interpreter.ThingValueDictionary[thingName]; } else { var message = String.Format(Messages.UnknownAlienNumberOrThing, thingName); Interpreter.AddError(message, Order); return; } } var arabic = RomanConversor.Convert(roman); var thingToBeValued = GetThing(); var finalValue = getFinalValue(arabic, thingValue, thingToBeValued); if (finalValue.HasValue) { var message = String.Format(rightAnswer, value, finalValue, thingToBeValued); Interpreter.AddInfo(message, Order); } else { var message = String.Format(Messages.UnknownRomanNumber, roman); Interpreter.AddError(message, Order); } }
/// <summary> /// Añade un error /// </summary> protected override void AddError(string error, Exception exception = null, [CallerFilePath] string fileName = null, [CallerMemberName] string methodName = null, [CallerLineNumber] int lineNumber = 0) { // Añade el error al log Interpreter.Logger.Default.LogItems.Error(error, exception, fileName, methodName, lineNumber); // Detiene el procesamiento Stopped = true; // Añade el error al intérprete Interpreter.AddError(error, exception); }
/// <summary> /// Get object property value /// </summary> /// <created> /// <author>DIVI Group</author> /// <date>2018.10.05</date> /// </created> /// <param name="pName"></param> /// <param name="pAttribute"></param> /// <returns></returns> public static string GetProperty(string pName, string pAttribute) { if (Interpreter.IsBreakpoint) { return(""); } string error = ""; // Console.WriteLine(string.Format("Get Value: {0}.{1}", pName, pAttribute)); // set value Variable curVar = Graphics.GetVariable(pName); if (curVar.type == Variable.VarType.VAR_TYPE_OBJECT) { switch (curVar.value) { case CLASS_POINT: { switch (pAttribute.ToUpper()) { case "X": return(Graphics.GetPoint(pName).x.ToString()); break; case "Y": return(Graphics.GetPoint(pName).y.ToString()); break; default: Interpreter.AddError(string.Format("Object [{0}] of calss [{1}] has no attribute [{2}]", pName, CLASS_POINT, pAttribute)); break; } break; } case CLASS_LINE: { Interpreter.AddError(string.Format("Object [{0}] of calss [{1}] has no attribute [{2}]", pName, CLASS_POINT, pAttribute)); break; } } } return(error); }
/// <summary> /// Adds new line to Graphics /// </summary> /// <created> /// <author>DIVI Group</author> /// <date>2018.10.05</date> /// </created> /// <param name="pName">line name</param> /// <param name="pParameters">line parameters: point names separated by comma</param> /// <returns></returns> private static void NewLine(string pName, string pParameters) { Console.WriteLine(string.Format("Add Line: {0}, [{1}]", pName, pParameters)); // gets point string[] xy_param = pParameters.Split(','); // validates number of parameters if (xy_param.Length < 2 || xy_param.Length > 3) { Interpreter.AddError(string.Format("Straight line definition should have two or three parameters!")); } // validates color type (3rd parameter) if (xy_param.Length == 3) { if (!Graphics.LineTypes.ContainsKey(xy_param[2])) { Interpreter.AddError(string.Format("Line type [{0}] is not defined!", xy_param[2])); } } // builds coordinates // TODO: error validation for Add Lines and get Point Graphics.NewVariable(pName, Variable.VarType.VAR_TYPE_OBJECT, CLASS_LINE); if (xy_param.Length == 2) { Elements.Graphics.Lines.Add( pName, new Line( pName, Graphics.GetPoint(xy_param[0]), Graphics.GetPoint(xy_param[1]) ) ); } else { Elements.Graphics.Lines.Add( pName, new Line( pName, Graphics.GetPoint(xy_param[0]), Graphics.GetPoint(xy_param[1]), xy_param[2] ) ); } }
/// <summary> /// gets line by name /// </summary> /// <created> /// <author>DIVI Group</author> /// <date>2018.10.31</date> /// </created> /// <param name="pName"></param> /// <returns></returns> public static Line GetLine(string pName) { if (Interpreter.IsBreakpoint) { return(null); } // rise error if variable does not exists if (!Graphics.Lines.ContainsKey(pName)) { Interpreter.AddError(string.Format("Line with name [{0}] does not exists", pName)); return(null); } else { return(Graphics.Lines[pName]); } }
/// <summary> /// gets point by name /// </summary> /// <created> /// <author>DIVI Group</author> /// <date>2018.10.23</date> /// </created> /// <param name="pName"></param> /// <returns></returns> public static Point GetPoint(string pName) { if (Interpreter.IsBreakpoint) { return(null); } // rise error if variable allready exists if (!Graphics.Points.ContainsKey(pName)) { Interpreter.AddError(string.Format("Point with name [{0}] does not exists", pName)); return(null); } else { return(Graphics.Points[pName]); } }
/// <summary> /// MEthod to access variables with error checking /// </summary> /// <created> /// <atuhor>DIVI Group</atuhor> /// <date>2018.10.23</date> /// </created> /// <param name="pName"></param> /// <returns></returns> public static Variable GetVariable(string pName) { if (Interpreter.IsBreakpoint) { return(null); } string name = pName.Trim(); if (!Graphics.Variables.ContainsKey(name)) { Interpreter.AddError(string.Format("Variable [{0}] does not exists", pName)); return(null); } else { return(Graphics.Variables[name]); } }
/// <summary> /// Creates new variable /// </summary> /// <created> /// <author>DIVI Group</author> /// <date>2018.10.23</date> /// </created> /// <param name="pName"></param> /// <param name=""></param> /// <param name="pValue"></param> public static Variable NewVariable(string pName, Variable.VarType pType, string pValue) { if (Interpreter.IsBreakpoint) { return(null); } // rise error if variable allready exists if (Graphics.Variables.ContainsKey(pName)) { Interpreter.AddError(string.Format("Variable [{0}] already exists", pName)); return(null); } else { Variable v = new Variable(pName, pType, pValue); Graphics.Variables.Add(pName, v); return(v); } }
/// <summary> /// Set variable value /// </summary> /// <created> /// <author>DIVI Group</author> /// <date>2018.10.23</date> /// </created> /// <param name="pName"></param> /// <param name="pType"></param> /// <param name="pValue"></param> public static void SetVariable(string pName, Variable.VarType pType, string pValue) { if (!Interpreter.IsBreakpoint) { if (Graphics.Variables.ContainsKey(pName)) { if (Graphics.Variables[pName].type == pType) { Graphics.Variables[pName].value = pValue; } else { Interpreter.AddError(string.Format("You cannot change data type of variable [{0}]. Actual type is [{1}].", pName, pType)); } } else { Graphics.NewVariable(pName, pType, pValue); } } }
public override void Translate() { var key = Match.Groups[1].Value.Trim(); var value = (Decimal?)Decimal.Parse(Match.Groups[2].Value); String name; if (!key.Contains(" ")) { name = key; } else { var numbers = key.Split(' '); var names = new List <String>(); for (var n = 0; n < numbers.Length; n++) { if (numbers[n][0].ToString() == numbers[n][0].ToString().ToUpper()) { names.Add(numbers[n]); numbers[n] = String.Empty; } } name = String.Join(" ", names); var romanDivisor = String.Empty; foreach (var number in numbers) { if (String.IsNullOrEmpty(number)) { continue; } if (!Interpreter.ConversionDictionary.ContainsKey(number)) { var message = String.Format(Messages.UnknownAlienToRomanConversion, number); Interpreter.AddError(message, Order); return; } romanDivisor += Interpreter.ConversionDictionary[number]; } var divisor = RomanConversor.Convert(romanDivisor); if (divisor == null) { value = null; var message = String.Format(Messages.UnknownRomanNumber, romanDivisor); Interpreter.AddError(message, Order); } else if (divisor.Value != 0) { value /= divisor.Value; } } if (value.HasValue) { var message = Interpreter.ThingValueDictionary.HandleKeyValue(name, value.Value); if (!String.IsNullOrEmpty(message)) { Interpreter.AddWarning(message, Order); } } }
public override void Translate() { Interpreter.AddError(FileTranslation.AnswerNoIdea, Order); }
/// <summary> /// Sets property to object /// </summary> /// <created> /// <author>DIVI Group</author> /// <date>2018.10.05</date> /// </created> /// <param name="pName"></param> /// <param name="pAttribute"></param> /// <param name="pValue"></param> /// <returns></returns> public static string SetProperty(string pName, string pAttribute, string pValue) { if (Interpreter.IsBreakpoint) { return(""); } string error = ""; // todo: error validation Console.WriteLine(string.Format("Set Value: {0}.{1} [{2}]", pName, pAttribute, pValue)); // set value Variable curVar = Graphics.GetVariable(pName); if (curVar.type == Variable.VarType.VAR_TYPE_OBJECT) { switch (curVar.value) { case CLASS_POINT: { switch (pAttribute.ToUpper()) { case "X": Graphics.GetPoint(pName).x = Int32.Parse(pValue); break; case "Y": Graphics.GetPoint(pName).y = Int32.Parse(pValue); break; case "TYPE": Graphics.GetPoint(pName).type = pValue; break; case "VISIBLE": Graphics.GetPoint(pName).visible = (pValue.ToUpper() == "FALSE" ? false : true); break; default: Interpreter.AddError(string.Format("Object [{0}] of calss [{1}] has no attribute [{2}]", pName, CLASS_POINT, pAttribute)); break; } break; } case CLASS_LINE: { switch (pAttribute.ToUpper()) { case "TYPE": Graphics.GetLine(pName).type = pValue; break; case "VISIBLE": Graphics.GetLine(pName).visible = (pValue.ToUpper() == "FALSE" ? false : true); break; default: Interpreter.AddError(string.Format("Object [{0}] of calss [{1}] has no attribute [{2}]", pName, CLASS_LINE, pAttribute)); break; } break; } } } return(error); }
/// <summary> /// Adds new point to Graphics /// </summary> /// <created> /// <author>DIVI Group</author> /// <date>2018.10.05</date> /// </created> /// <param name="parameters"></param> /// <returns></returns> public static void NewPoint(string pName, string pParameters) { Console.WriteLine(string.Format("Add Point: {0}, [{1}]", pName, pParameters)); // gets point string[] xy_param = pParameters.Split(','); // check if point exists if (Graphics.Variables.ContainsKey(pName)) { Interpreter.AddError(string.Format("Variable [{0}] alreadey exists", pName)); } // validates number of parameters if (xy_param.Length < 2 || xy_param.Length > 3) { Interpreter.AddError(string.Format("Point definition should have two or three parameters!")); } // validates color type (3rd parameter) if (xy_param.Length == 3) { if (!Graphics.PointTypes.ContainsKey(xy_param[2])) { Interpreter.AddError(string.Format("Point type [{0}] is not defined!", xy_param[2])); } } // builds coordinates Variable x; Variable y; String name = ""; if (xy_param[0].EndsWith("(d)")) { name = pName + "__X__"; x = Graphics.NewVariable( pName + "__X__", Variable.VarType.VAR_TYPE_SIMPLE, xy_param[0].Substring(0, xy_param[0].Length - 3) ); } else { x = Graphics.GetVariable(xy_param[0]); }; if (xy_param[1].EndsWith("(d)")) { name = pName + "__Y__"; y = Graphics.NewVariable( pName + "__Y__", Variable.VarType.VAR_TYPE_SIMPLE, xy_param[1].Substring(0, xy_param[1].Length - 3) ); } else { y = Graphics.GetVariable(xy_param[1]); }; Graphics.NewVariable(pName, Variable.VarType.VAR_TYPE_OBJECT, CLASS_POINT); if (xy_param.Length == 2) // invisible point { Graphics.Points.Add( pName, new Point(pName, x, y) ); } else // visible point with type { Graphics.Points.Add( pName, new Point(pName, x, y, xy_param[2]) ); } }