private IExpressionData getVariable(IObject Data) { IExpressionData expressionData = null; if (Data is VariableData) { VariableData data = (VariableData)Data; if (typeof(Double) == data.type) { expressionData = new DoubleType((double)data.value); } else if (data.type == typeof(String)) { expressionData = new StringType((string)data.value); } else if (data.type == typeof(Boolean)) { expressionData = new BoolType((bool)data.value); } else { throw new Exception("Unknown data type, Expression evaluate"); } } else if (Data is ArrayIndex || Data is ArrayObject) { expressionData = new ObjectType(Data); } return(expressionData); }
public ExpressionElement(IExpressionData value) { this._type = ParameterType.Expression; this._value = string.Empty; this._expression = value; this._parent = null; }
public bool ReceiveComponentVariable(IComponentVariableSource component) { this.Focus(); AbstractComponentData receivedData = component.GetData(); if (receivedData == null) { return(false); } if (receivedData is IExpressionData) { if (textTarget.IsFocused) { targetData = receivedData as IExpressionData; textTarget.Text = receivedData.autoLabel; } else if (textVariable.IsFocused) { variableData = receivedData as IExpressionData; textVariable.Text = receivedData.autoLabel; } return(true); } else { // only receive IExpressionData, other type of data cannot have value return(false); } }
public ExpressionElement() { this._type = ParameterType.NotAvailable; this._value = string.Empty; this._expression = null; this._parent = null; }
private static IObject getData(IExpressionData data) { IObject Value = null; if (data is DoubleType) { Value = new VariableData(typeof(Double), (double)data.GetData()); } else if (data is StringType) { Value = new VariableData(typeof(String), (string)data.GetData()); } else if (data is BoolType) { Value = new VariableData(typeof(Boolean), (bool)data.GetData()); } else if (data is ObjectType) { Value = (IObject)data.GetData(); } else { throw new Exception("Unknown data type in Variable Dictionary"); } return(Value); }
public ExpressionElement(ParameterType type, string value) { this._type = type; this._value = value; this._expression = null; this._parent = null; }
private void ExpressionPostProcess(IExpressionData expressionData, Dictionary <string, string> argumentCache) { ExpressionElementPostProcess(expressionData.Source, argumentCache); foreach (IExpressionElement expressionElement in expressionData.Arguments) { ExpressionElementPostProcess(expressionElement, argumentCache); } }
public IExpressionData ParseExpression(string expression, ISequence parent) { // 参数别名到参数值的映射 Dictionary <string, string> argumentCache = new Dictionary <string, string>(10); StringBuilder expressionCache = new StringBuilder(expression); // 预处理,删除冗余的空格,替换参数为固定模式的字符串 ParsingPreProcess(expressionCache, parent, argumentCache); // 分割表达式元素 IExpressionData expressionData = ParseExpressionData(expressionCache); ParsingPostProcess(expressionData, argumentCache); return(expressionData); }
public IExpressionData Evaluate() { IExpressionData leftData = leftExpression.Evaluate(); IExpressionData rightData = rightExpression.Evaluate(); if (leftData.GetType() != rightData.GetType()) { throw new Exception("Operation on different types"); } if (leftData is DoubleType) { double left, right; left = (double)leftData.GetData(); right = (double)rightData.GetData(); switch (Operation) { case '+': return(new DoubleType(left + right)); case '-': return(new DoubleType(left - right)); case '*': return(new DoubleType(left * right)); case '/': return(new DoubleType(left / right)); default: throw new Exception("Unknown operation"); } } else if (leftData is StringType) { if (Operation != '+') { throw new Exception("Unknown operation on string"); } string left = (string)leftData.GetData(); string right = (string)rightData.GetData(); return(new StringType(left + right)); } else if (leftData is BoolType) { throw new Exception("Cant use operator on boolen type"); } else { throw new Exception("Not initialized data"); } }
//Methods public IExpressionData Evaluate() { if (!IsObject) { return(DefaultEvaluate()); } IExpressionData container = (new VariableExpression(name)).Evaluate(); IObject array = null; if (container is ObjectType) { array = (IObject)container.GetData(); } else { throw new Exception("Brackets to a variable"); } GetIndexes(); for (int i = 0; i < Indexes.Count; ++i) { if (Indexes[i] is string && array is ArrayObject) { array = ((ArrayObject)array)[(string)Indexes[i]]; } else if (Indexes[i] is int && array is ArrayIndex) { array = ((ArrayIndex)array)[(int)Indexes[i]]; } else { throw new Exception("Inappropriate index in brackets"); } } if (array is VariableData) { return(getVariable(array)); } else { throw new Exception("Inappropriate count of indexes"); } }
public void GetObjectData(SerializationInfo info, StreamingContext context) { this.Type = (ParameterType)info.GetValue("Type", typeof(ParameterType)); switch (Type) { case ParameterType.NotAvailable: break; case ParameterType.Value: case ParameterType.Variable: this.Value = info.GetString("Value"); break; case ParameterType.Expression: this.Expression = (ExpressionData)info.GetValue("Expression", typeof(ExpressionData)); break; default: break; } }
override public void Execute(Args commandArgs) { var filter = new MapFilter(commandArgs.StringEnumArgs[Arguments.MapFileName]); filter.OutputFile = commandArgs.StringEnumArgs[Arguments.OutputFile]; switch ((FilterType)Enum.Parse(typeof(FilterType), commandArgs.StringEnumArgs[Arguments.FilterType])) { case FilterType.BestWorst: { string[] p = commandArgs.StringEnumArgs[Arguments.FilterParams].Split(','); filter.ExpressionData = IExpressionData.LoadExpressionData( p[1], "LongPap", "gtf", null); filter.HistoneName = p[2]; filter.BestWorst(double.Parse(p[0])); break; } case FilterType.Link: { string[] p = commandArgs.StringEnumArgs[Arguments.FilterParams].Split(','); filter.ExpressionData = IExpressionData.LoadExpressionData( p[1], "LongPap", "gtf", null); filter.HistoneName = "None"; filter.Link((MapLinkFilter.LinkType)Enum.Parse(typeof(MapLinkFilter.LinkType), p[0])); break; } } }
private IObject getObject() { IExpressionData data = expression.Evaluate(); IObject result = null; if (data is StringType) { result = new VariableData(typeof(string), data.GetData()); } else if (data is DoubleType) { result = new VariableData(typeof(double), data.GetData()); } else if (data is BoolType) { result = new VariableData(typeof(bool), data.GetData()); } else if (data is ObjectType) { result = (IObject)data.GetData(); } return(result); }
//File private static IExpressionData LoadText(List <IExpression> parameters) { if (parameters.Count == 0) { throw new Exception("Empty"); } IExpressionData data = parameters[0].Evaluate(); string path = ""; if (data is StringType) { path = (string)data.GetData(); } else { throw new Exception("Not string"); } string text = ""; using (StreamReader sr = new StreamReader(path)) text = sr.ReadToEnd(); return(new StringType(text)); }
public IExpressionData Evaluate() { IExpressionData data = expression.Evaluate(); if (data is DoubleType) { switch (Operator) { case '-': return(new DoubleType(-(double)data.GetData())); case '+': return(data); default: return(data); } } else if (data is BoolType && Operator == '!') { return(new BoolType(!(bool)data.GetData())); } else { throw new Exception("Cant create unary expression. Evaluate"); } }
public static void PutVariable(string name, IExpressionData data) { dictionary.Add(name, getData(data)); }
private void buttonClearTarget_Click(object sender, RoutedEventArgs e) { targetData = null; textTarget.Text = ""; }
public IExpressionData Evaluate() { IExpressionData leftData = leftExpression.Evaluate(); IExpressionData rightData = rightExpression.Evaluate(); if (leftData.GetType() != rightData.GetType()) { throw new Exception("Operation on different types"); } if (Operation == "&" || Operation == "|") { if (leftData.GetType() != typeof(BoolType)) { throw new Exception("Boolen operation on none boolen variable"); } bool left = (bool)leftData.GetData(); bool right = (bool)rightData.GetData(); if (Operation == "&" && (left && right)) { return(new BoolType(true)); } else if (Operation == "|" && (left || right)) { return(new BoolType(true)); } else { return(new BoolType(false)); } } else if (Operation == ">" || Operation == "<" || Operation == "==" || Operation == "<=" || Operation == ">=" || Operation == "!=") { if (leftData.GetType() == typeof(BoolType)) { throw new Exception("Not boolen operation on boolen type"); } if (leftData.GetType() == typeof(StringType)) { if (Operation == "==") { if ((string)leftData.GetData() == (string)rightData.GetData()) { return(new BoolType(true)); } else { return(new BoolType(false)); } } else if (Operation == "!=") { if ((string)leftData.GetData() != (string)rightData.GetData()) { return(new BoolType(true)); } else { return(new BoolType(false)); } } else { throw new Exception("Cant use this operation on string"); } } else if (leftData.GetType() == typeof(DoubleType)) { double left = (double)leftData.GetData(); double right = (double)rightData.GetData(); bool result = false; switch (Operation) { case ">": if (left > right) { result = true; } break; case "<": if (left < right) { result = true; } break; case ">=": if (left >= right) { result = true; } break; case "<=": if (left <= right) { result = true; } break; case "==": if (left == right) { result = true; } break; case "!=": if (left != right) { result = true; } break; } return(new BoolType(result)); } else { throw new Exception("Unknown data type"); } } else { throw new Exception("Unknown operation in Condition expression"); } }
bool ValidateInput() { if (rowData != null || columnData != null) { // must check that the row & column data is not part of rangeData. Otherwise cyclic dependency // exception: it's ok when only 1 of row/column data is set and it refers to the top left cell in rangeData, // because the top left cell is free (not linked) unless both row&column data is set if (rowData == null || columnData == null) { // only 1 data is set, the top left cell on rangeData can be used IExpressionData data = (rowData != null) ? rowData : columnData; if (data is SpreadsheetCellData) { PointInt?position = rangeData.GetPositionOfCell(data as SpreadsheetCellData); if (position.HasValue && !(position.Value.X == 0 && position.Value.Y == 0)) { if (rowData != null) { textRow.Focus(); } else { textColumn.Focus(); } MessageBox.Show("Invalid input. Cannot use a cell inside the selected range!"); return(false); } } } else { // row data and column data cannot refer to the same thing if ((rowData as AbstractComponentData).id == (columnData as AbstractComponentData).id) { textColumn.Focus(); MessageBox.Show("Row input and column input must be different!"); return(false); } // both data are set, cannot use entire rangeData IExpressionData[] array = { rowData, columnData }; foreach (IExpressionData data in array) { if (data is SpreadsheetCellData) { PointInt?position = rangeData.GetPositionOfCell(data as SpreadsheetCellData); if (position.HasValue) { if (data == rowData) { textRow.Focus(); } else { textColumn.Focus(); } MessageBox.Show("Invalid input. Cannot use a cell inside the selected range!"); return(false); } } } } return(true); } else { textRow.Focus(); MessageBox.Show("Please input the row or column expression"); return(false); } }
private void buttonClearRow_Click(object sender, RoutedEventArgs e) { rowData = null; textRow.Text = ""; }
private void ParsingPostProcess(IExpressionData expressionData, Dictionary <string, string> argumentCache) { ExpressionPostProcess(expressionData, argumentCache); }
public static void SetVariable(string name, IExpressionData data) { dictionary[name] = getData(data); }