protected override string DoImpl() { var elementId = this.ExecutedCommand.Parameters["ID"].ToString(); var imageFormatStr = this.ExecutedCommand.Parameters["format"].ToString(); var foreground = Boolean.Parse(this.ExecutedCommand.Parameters["foreground"].ToString()); var element = this.Automator.ElementsRegistry.GetRegisteredElement(elementId); ImageFormat imageFormat = ImFormat.GetImageFormat(imageFormatStr); MemoryStream memoryStream = new MemoryStream(); CaptureImage captureImage; if (foreground) { captureImage = Capture.Element(element.FlaUIElement); } else { captureImage = ElementCapture.CaptureImageOfElement(element.FlaUIElement); } captureImage.Bitmap.Save((Stream)memoryStream, imageFormat); return(this.JsonResponse(ResponseStatus.Success, (object)Convert.ToBase64String(memoryStream.ToArray()))); }
private string EvaluateOperator(string exp, string op) { var ops = GetOperatorPositions(exp, op); for (var i = 0; i < ops.Length; i++) { var cOp = ops[i]; var needRight = !(op == "++" || op == "--"); var captureLeft = CaptureLeft(exp, cOp - 1); var elementLeft = captureLeft.Identifier.Trim(); if (!(op == "-" && elementLeft.Length == 0)) { var result = ""; if (string.IsNullOrWhiteSpace(elementLeft)) ErrorHandler.ThrowError(ErrorType.SyntaxError, ErrorHandler.MESSAGE_SYNTAX_EXPECTED_EXPRESSION, op); var objectLeft = ToScriptObject(elementLeft); ElementCapture captureRight; string elementRight; SObject objectRight = null; if (needRight) { captureRight = CaptureRight(exp, cOp + op.Length); elementRight = captureRight.Identifier.Trim(); if (string.IsNullOrWhiteSpace(elementRight)) ErrorHandler.ThrowError(ErrorType.SyntaxError, ErrorHandler.MESSAGE_SYNTAX_EXPECTED_EXPRESSION, "end of script"); if (op != ".") objectRight = ToScriptObject(elementRight); } else { elementRight = ""; captureRight = new ElementCapture() { Length = 0 }; } if (op != "." || !IsDotOperatorDecimalSeparator(elementLeft, elementRight)) { switch (op) { case ".": result = InvokeMemberOrMethod(objectLeft, elementRight).ToScriptObject(); break; case "+": result = ObjectOperators.AddOperator(this, objectLeft, objectRight); break; case "-": result = ObjectOperators.SubtractOperator(this, objectLeft, objectRight); break; case "*": result = ObjectOperators.MultiplyOperator(this, objectLeft, objectRight); break; case "/": result = ObjectOperators.DivideOperator(this, objectLeft, objectRight); break; case "%": result = ObjectOperators.ModulusOperator(this, objectLeft, objectRight); break; case "**": result = ObjectOperators.ExponentOperator(this, objectLeft, objectRight); break; case "==": result = ObjectOperators.EqualsOperator(this, objectLeft, objectRight); break; case "===": result = ObjectOperators.TypeEqualsOperator(this, objectLeft, objectRight); break; case "!=": result = ObjectOperators.NotEqualsOperator(this, objectLeft, objectRight); break; case "!==": result = ObjectOperators.TypeNotEqualsOperator(this, objectLeft, objectRight); break; case "<=": result = ObjectOperators.SmallerOrEqualsOperator(this, objectLeft, objectRight); break; case "<": result = ObjectOperators.SmallerOperator(this, objectLeft, objectRight); break; case ">=": result = ObjectOperators.LargerOrEqualsOperator(this, objectLeft, objectRight); break; case ">": result = ObjectOperators.LargerOperator(this, objectLeft, objectRight); break; case "&&": result = ObjectOperators.AndOperator(this, objectLeft, objectRight); break; case "||": result = ObjectOperators.OrOperator(this, objectLeft, objectRight); break; case "++": result = ObjectOperators.IncrementOperator(this, objectLeft); break; case "--": result = ObjectOperators.DecrementOperator(this, objectLeft); break; } exp = exp.Remove(captureLeft.StartIndex, op.Length + captureLeft.Length + captureRight.Length); exp = exp.Insert(captureLeft.StartIndex, result); var offset = result.Length - (op.Length + captureLeft.Length + captureRight.Length); for (var j = i + 1; j < ops.Length; j++) { ops[j] += offset; } } } } return exp; }
private string EvaluateOperator(string exp, string op) { var ops = GetOperatorPositions(exp, op); for (var i = 0; i < ops.Length; i++) { var cOp = ops[i]; var needRight = !(op == "++" || op == "--"); var captureLeft = CaptureLeft(exp, cOp - 1); var elementLeft = captureLeft.Identifier.Trim(); if (!(op == "-" && elementLeft.Length == 0)) { var result = ""; if (string.IsNullOrWhiteSpace(elementLeft)) { ErrorHandler.ThrowError(ErrorType.SyntaxError, ErrorHandler.MESSAGE_SYNTAX_EXPECTED_EXPRESSION, op); } var objectLeft = ToScriptObject(elementLeft); ElementCapture captureRight; string elementRight; SObject objectRight = null; if (needRight) { captureRight = CaptureRight(exp, cOp + op.Length); elementRight = captureRight.Identifier.Trim(); if (string.IsNullOrWhiteSpace(elementRight)) { ErrorHandler.ThrowError(ErrorType.SyntaxError, ErrorHandler.MESSAGE_SYNTAX_EXPECTED_EXPRESSION, "end of script"); } if (op != ".") { objectRight = ToScriptObject(elementRight); } } else { elementRight = ""; captureRight = new ElementCapture() { Length = 0 }; } if (op != "." || !IsDotOperatorDecimalSeparator(elementLeft, elementRight)) { switch (op) { case ".": result = InvokeMemberOrMethod(objectLeft, elementRight).ToScriptObject(); break; case "+": result = ObjectOperators.AddOperator(this, objectLeft, objectRight); break; case "-": result = ObjectOperators.SubtractOperator(this, objectLeft, objectRight); break; case "*": result = ObjectOperators.MultiplyOperator(this, objectLeft, objectRight); break; case "/": result = ObjectOperators.DivideOperator(this, objectLeft, objectRight); break; case "%": result = ObjectOperators.ModulusOperator(this, objectLeft, objectRight); break; case "**": result = ObjectOperators.ExponentOperator(this, objectLeft, objectRight); break; case "==": result = ObjectOperators.EqualsOperator(this, objectLeft, objectRight); break; case "===": result = ObjectOperators.TypeEqualsOperator(this, objectLeft, objectRight); break; case "!=": result = ObjectOperators.NotEqualsOperator(this, objectLeft, objectRight); break; case "!==": result = ObjectOperators.TypeNotEqualsOperator(this, objectLeft, objectRight); break; case "<=": result = ObjectOperators.SmallerOrEqualsOperator(this, objectLeft, objectRight); break; case "<": result = ObjectOperators.SmallerOperator(this, objectLeft, objectRight); break; case ">=": result = ObjectOperators.LargerOrEqualsOperator(this, objectLeft, objectRight); break; case ">": result = ObjectOperators.LargerOperator(this, objectLeft, objectRight); break; case "&&": result = ObjectOperators.AndOperator(this, objectLeft, objectRight); break; case "||": result = ObjectOperators.OrOperator(this, objectLeft, objectRight); break; case "++": result = ObjectOperators.IncrementOperator(this, objectLeft); break; case "--": result = ObjectOperators.DecrementOperator(this, objectLeft); break; } exp = exp.Remove(captureLeft.StartIndex, op.Length + captureLeft.Length + captureRight.Length); exp = exp.Insert(captureLeft.StartIndex, result); var offset = result.Length - (op.Length + captureLeft.Length + captureRight.Length); for (var j = i + 1; j < ops.Length; j++) { ops[j] += offset; } } } } return(exp); }
private string EvaluateOperatorLeftToRight(string exp, string op) { int[] ops = GetOperatorPositions(exp, op); for (int i = 0; i < ops.Length; i++) { var cOp = ops[i]; bool needRight = true; if (op == "++" || op == "--") { needRight = false; } ElementCapture captureLeft = CaptureLeft(exp, cOp - 1); string elementLeft = captureLeft.Identifier; if (!(op == "-" && elementLeft.Length == 0)) { string result = ""; SObject objectLeft = ToScriptObject(elementLeft); ElementCapture captureRight; string elementRight; SObject objectRight = null; if (needRight) { captureRight = CaptureRight(exp, cOp + op.Length); elementRight = captureRight.Identifier; if (op != ".") objectRight = ToScriptObject(elementRight); } else { elementRight = ""; captureRight = new ElementCapture() { Length = 0 }; } if (op != "." || IsDotOperatorDecimalSeperator(elementLeft, elementRight)) { switch (op) { case ".": //TODO: call member invoke. break; case "+": result = ObjectOperators.AddOperator(this, objectLeft, objectRight); break; case "-": result = ObjectOperators.SubtractOperator(this, objectLeft, objectRight); break; case "*": result = ObjectOperators.MultiplyOperator(this, objectLeft, objectRight); break; case "/": result = ObjectOperators.DivideOperator(this, objectLeft, objectRight); break; case "%": result = ObjectOperators.ModulusOperator(this, objectLeft, objectRight); break; case "**": result = ObjectOperators.ExponentOperator(this, objectLeft, objectRight); break; case "==": result = ObjectOperators.EqualsOperator(this, objectLeft, objectRight); break; case "===": result = ObjectOperators.TypeEqualsOperator(this, objectLeft, objectRight); break; case "!=": result = ObjectOperators.NotEqualsOperator(this, objectLeft, objectRight); break; case "!==": result = ObjectOperators.TypeNotEqualsOperator(this, objectLeft, objectRight); break; case "<=": result = ObjectOperators.SmallerOrEqualsOperator(this, objectLeft, objectRight); break; case "<": result = ObjectOperators.SmallerOperator(this, objectLeft, objectRight); break; case ">=": result = ObjectOperators.LargerOrEqualsOperator(this, objectLeft, objectRight); break; case ">": result = ObjectOperators.LargerOperator(this, objectLeft, objectRight); break; case "&&": result = ObjectOperators.AndOperator(this, objectLeft, objectRight); break; case "||": result = ObjectOperators.OrOperator(this, objectLeft, objectRight); break; case "++": result = ObjectOperators.IncrementOperator(this, objectLeft); break; case "--": result = ObjectOperators.DecrementOperator(this, objectLeft); break; } exp = exp.Remove(captureLeft.StartIndex, op.Length + captureLeft.Length + captureRight.Length); exp = exp.Insert(captureLeft.StartIndex, result); var offset = result.Length - (op.Length + captureLeft.Length + captureRight.Length); for (int j = i + 1; j < ops.Length; j++) { ops[j] += offset; } } } } return exp; }