/// <summary> /// This is the entry point of the worker part of the process. It returns a first ExecuteResponse which /// will point to the stored Execute Response through it's statusLocation. /// </summary> /// <param name="args">Arguments</param> /// <param name="ret">Return value</param> /// <returns>The returnValue of the process.</returns> public override ProcessReturnValue Execute(ProcessInputParams args, ProcessReturnValue ret) { ///A simple check to make sure ret isn't null if (ret == null) { ret = new ProcessReturnValue(); } ///At this time, the process is accepted and will be executed. ret.status = ProcessState.Accepted; ///Provide advancement, obviously nothing has happened yet so it's 0% ret.percentageCompleted = 0; ///Make sure ret will be available to the async method, the easiest way is to copy it into ///the dedicated property of the class. If the thread is not parameterized, a Args property is also ///available. this.ExecuteResponseValue = ret; ///This check is performed to make sure this process is called asynchronously. Async processes ///are not compatible with synchronous calls at this time if (!ret.responseForm.responseDocument.storeExecuteResponse || !ret.responseForm.responseDocument.storeExecuteResponse) { throw new Exception("This process must be executed asynchronously, please make sure that 'status' and 'storeExecuteResponse' are set to 'true'"); } ///Initiate and start the worker thread. Thread workerThread = new Thread(new ParameterizedThreadStart(this.Work)); workerThread.IsBackground = false; workerThread.Start(args); ///Specify an empty output. this.ExecuteResponseValue.returnValues.Clear(); this.ExecuteResponseValue.returnValues.Add(new LiteralOutput("AsyncClockResult", "Async Clock Result", "A string containing the start datetime and the end datetime", "string")); ///Return the first response which will contain the statusLocation to the stored response ///(XML file stored on the server which will be updated with new values each time ///the ProgressChanged event is raised by this process. return(ExecuteResponseValue); }
// Opens source file and reads into one long string. // Then calls LexFromString. // // Throws : IOException // // Returns : ProcessReturnValue.PRV_OK, // ProcessReturnValue.PRV_WARNINGS, // ProcessReturnValue.PRV_ERRORS // ProcessReturnValue.PRV_NONE (On no tokens but EOF) public ProcessReturnValue LexFromFile(String sourceFilePath) { //Inits StreamReader sr = null; String file = null; ProcessReturnValue ret = ProcessReturnValue.PRV_OK; // Try code for IOException try { //Open FileStream and StreamReader FileStream fs = new FileStream(sourceFilePath, FileMode.Open); sr = new StreamReader(fs); //Read file to end into string file = sr.ReadToEnd(); //Lex from string ret = LexFromString(file); } // Throws up IOException catch (IOException e) { throw e; } //Close file reader and stream finally { if (sr != null) { sr.Close(); } } //Return value return(ret); }
public ProcessReturnValue Execute(ProcessInputParams args, ProcessReturnValue ret) { float fresult = 0; float fa = 0, fb = 0; ComplexInput a = args.GetData("a", 0).asComplexInput(); ComplexInput b = args.GetData("b", 0).asComplexInput(); XmlDocument doc = new XmlDocument(); try { doc.LoadXml(a.ToString()); fa = float.Parse(doc.InnerText); } catch { } try { doc.LoadXml(b.ToString()); fb = float.Parse(doc.InnerText); } catch { } LiteralInput oper = args.GetData("operator", 0).asLiteralInput(); string myOperator = oper.ToString(); if (ret.IsOutputIdentifierRequested("result")) { switch (myOperator) { case "sub": fresult = fa - fb; break; case "mult": fresult = fa * fb; break; case "div": if (fb != 0) { fresult = fa / fb; } else { fresult = fa; } break; case "add": default: fresult = fa + fb; break; } ComplexOutput result = null; List <OutputData> outputs = ret.GetOutputsForIdentifier("result"); if (ret.IsRawDataOutput()) { ret.fileName = "result.xml"; result = outputs[0].asComplexOutput(); result.SetValue(String.Format("<?xml version='1.0' encoding='{0}'?>\n<number>{1}</number>", result.Format.encoding, fresult)); ret.AddData(result); } else { foreach (OutputData output in outputs) { result = output.asComplexOutput(); result.SetValue("<number>" + fresult + "</number>"); ret.AddData(result); } } } ret.status = ProcessState.Succeeded; return(ret); }
public ProcessReturnValue Execute(ProcessInputParams args, ProcessReturnValue ret) { int sum = 0; int i = 0; while (true) { LiteralInput a = args.GetData("a", i++).asLiteralInput(); if (a == null) { break; } sum += Int32.Parse(a.ToString()); } LiteralInput b = args.GetData("b", 0).asLiteralInput(); int ib = Int32.Parse(b.ToString()); sum += ib; if (ret.IsOutputIdentifierRequested("sum")) { List <OutputData> outputs = ret.GetOutputsForIdentifier("sum"); // Output 1: a literal containing the raw sum LiteralOutput sumOutput = null; foreach (OutputData output in outputs) { sumOutput = output.asLiteralOutput(); sumOutput.Value = sum.ToString(); ret.AddData(sumOutput); } } if (ret.IsOutputIdentifierRequested("sumFile")) { List <OutputData> outputs = ret.GetOutputsForIdentifier("sumFile"); // Output 2: a complex data type - plain text by default if (ret.IsRawDataOutput()) { ComplexOutput sumOutput = outputs[0].asComplexOutput(); if (Utils.StrICmp(sumOutput.Format.mimeType, "text/xml")) { sumOutput.SetValue("<number>" + sum + "</number>"); ret.fileName = "result.xml"; } else if (Utils.StrICmp(sumOutput.Format.mimeType, "plain/text")) { sumOutput.SetValue("sum is " + sum); ret.fileName = "result.txt"; } ret.AddData(sumOutput); } else { ComplexOutput sumOutput = null; foreach (OutputData output in outputs) { sumOutput = output.asComplexOutput(); if (Utils.StrICmp(sumOutput.Format.mimeType, "text/xml")) { sumOutput.SetValue("<number>" + sum + "</number>"); } else { sumOutput.SetValue("sum is " + sum); } ret.AddData(sumOutput); } } } ret.status = ProcessState.Succeeded; return(ret); }
// Generates op codes from ast. public ProcessReturnValue GenerateOpCodes(ASTNode rootASTNode, DynamicBranchTreeNode <SymbolHashTable> rootSymbolTableNode) { // Inits ProcessReturnValue ret = ProcessReturnValue.PRV_NONE; OpCodeGenParam param; bool error = false; // Create temp tables tempTables = new OpCodeGenTempTables(); tempOpCodeData = new StringBuilder(250); // Create new byte array opCodeDataBytes = new byte[256]; // Reset error and warning count errorCount = 0; warningCount = 0; // Create op code gen param param = new OpCodeGenParam(tempOpCodeData, opCodeDataBytes, rootSymbolTableNode, tempTables); // Send message SendGeneralMessage("Starting code generation phase..."); // Send message SendGeneralMessage("Generating op codes..."); // Gen op codes try { rootASTNode.GenOpCodes(param); // Add final 00 param.AddBytes(0x00); } // Catch index out of range exption // on over 256 byte error catch (IndexOutOfRangeException ex) { SendError("Program ran over 256 bytes."); // Send message SendGeneralMessage("Op code generation complete."); error = true; } // Send message SendGeneralMessage("Op code generation complete."); // If not errors if (!error) { // Send message SendGeneralMessage("Inserting memory locations..."); // Fill in memory locations and jump sizes programData = FillInTempOpCodeValues(param); // Send message SendGeneralMessage("Completed inserting memory locations."); // Send message SendGeneralMessage("Code generation phase complete."); // Send message SendGeneralMessage("Compilation complete."); // Set op code total bytes opCodeBytes = programData.totalBytes; } // Else send error message else { // Send message SendGeneralMessage("Compilation completed with errors."); } //Determine return value if (ErrorCount > 0) { ret = ProcessReturnValue.PRV_ERRORS; } else if (WarningCount > 0) { ret = ProcessReturnValue.PRV_WARNINGS; } else { ret = ProcessReturnValue.PRV_OK; } //Return code return(ret); }