/// <summary> /// Common initialization for the service. /// Essentially writes down some logging string and getting the callback on which the service will respond /// </summary> /// <returns>The text writer object the service will write on</returns> private TextWriterAsync InitializeServiceInstance(string[] args, string encodingWebName) { Contract.Requires(args != null); // Update the request, and save some statistics this.myId = RequestId++; this.start = DateTime.Now; if (this.OnMain != null) { this.OnMain(args); } // here is the magic: the callback object is recovered in the line below var callbackLineWriter = OperationContext.Current.GetCallbackChannel<IVerySimpleLineWriter>(); // And now we create the output factory for Clousot var textWriter = new TextWriterAsync(callbackLineWriter.AsTextWriter(encodingWebName)); CloudotLogging.WriteLine("Starting processing request #" + myId); return textWriter; }
private int MainInternal(string name, string[] args, TextWriterAsync textWriter) { Contract.Requires(name != null); Contract.Requires(args != null); Contract.Requires(textWriter != null); try { CloudotLogging.LogAnalysiRequest(name, args); #if INTERNALCALL return CallClousotInternally(name, args, textWriter); #else return CallClousotViaProcess(name, args, textWriter); #endif } catch (ExitRequestedException e) { return e.ExitCode; } catch (Exception e) { CloudotLogging.WriteLine("Got an exception. Reporting it to the client and aborting the session."); // We need to catch all exception, otherwise the service is turned into an faulted state and remains unusable textWriter.WriteLine("Cloudot: caught exception: {0}".PrefixWithCurrentTime(), e); if (e.InnerException != null) { textWriter.WriteLine("Inner exception: {0}", e.InnerException); } return -4444; } finally { CloudotLogging.WriteLine("Analysis of request #{0} done in {1}", this.myId, DateTime.Now - this.start); textWriter.Close(); // make sure all pending output is flushed } }