public void Process(ISemanticProcessor proc, IMembrane membrane, DataResponse resp) { string data64 = resp.Data.ToBase64(); resp.Context.Response.ContentLength64 = data64.Length; resp.Context.Response.Write(data64, "text/text", resp.StatusCode); }
public override void FinishedInitialization() { base.FinishedInitialization(); logger = ServiceManager.Get<ILoggerService>(); semProc = ServiceManager.Get<ISemanticProcessor>(); Assert.SilentTry(() => httpOnly = ServiceManager.Get<IAppConfigService>().GetValue("httpOnly").to_b()); }
public void Process(ISemanticProcessor proc, IMembrane membrane, ForgotPassword forgotPassword) { IDbContextService db = proc.ServiceManager.Get <IDbContextService>(); List <UserAccount> uas = db.Context.Query <UserAccount>(r => r.Email == forgotPassword.Email); if (uas.Count == 1) { uas[0].PasswordRecoveryToken = Guid.NewGuid().ToString(); db.Context.Update(uas[0]); string website = proc.ServiceManager.Get <IConfigService>().GetValue("website"); // Email the registrant. proc.ServiceManager.Get <ISemanticProcessor>().ProcessInstance <EmailClientMembrane, Email>(email => { email.AddTo(forgotPassword.Email); email.Subject = "ByteStruck Password Recovery"; email.Body = File.ReadAllText("passwordRecoveryEmail.html").Replace("{link}", website + "/account/recoverPassword?token=" + uas[0].PasswordRecoveryToken); }); JsonResponse(proc, forgotPassword, "{'state': 'OK'}"); } else { JsonResponse(proc, forgotPassword, "{'state': 'NotFound'}"); } }
// Ex: http://localhost/dictionary // Ex: http://localhost/dictionary?showInstanceIds=true public void Process(ISemanticProcessor proc, IMembrane membrane, GetDictionary msg) { StringBuilder sb = new StringBuilder(); sb.StartHtml(); sb.StartHead(). Script("/js/wireUpValueChangeNotifier.js"). Stylesheet("/css/styles.css"). EndHead(); sb.StartBody(); sb.StartParagraph().Append("<b>Dictionary:</b>").EndParagraph(); sb.StartParagraph().StartDiv().ID("dictionary").EndDiv().EndParagraph(); sb.StartParagraph().Append("<b>Type Nodes:</b>").EndParagraph(); sb.StartParagraph().StartDiv().ID("nodes").EndDiv().EndParagraph(); sb.StartScript().Javascript("(function() {getDictionaryHtml(" + msg.ShowInstanceIDs.ToString().ToLower() + ");})();").EndScript(); sb.EndBody().EndHtml(); proc.ProcessInstance <WebServerMembrane, HtmlResponse>(r => { r.Context = msg.Context; r.Html = sb.ToString(); }); }
public void Process(ISemanticProcessor proc, IMembrane membrane, Login login) { IDbContextService db = proc.ServiceManager.Get <IDbContextService>(); List <UserAccount> uas = db.Context.Query <UserAccount>(r => r.Email == login.Email); if (uas.Count == 1) { if (PasswordHash.ValidatePassword(login.Password, uas[0].PasswordHash)) { if (uas[0].Registered) { proc.ServiceManager.Get <IWebSessionService>().Authenticate(login.Context); JsonResponse(proc, login, "{'state': 'OK'}"); IWebSessionService session = proc.ServiceManager.Get <IWebSessionService>(); session.SetSessionObject(login.Context, "OneTimeAlert", "Welcome Back " + uas[0].FirstName + "!"); session.SetSessionObject(login.Context, "UserName", uas[0].FullName); session.SetSessionObject(login.Context, "UserAccount", uas[0]); session.SetSessionObject(login.Context, "RoleMask", uas[0].RoleMask); } else { JsonResponse(proc, login, "{'state': 'RegisterFirst'}"); } } else { JsonResponse(proc, login, "{'state': 'BadAccount'}"); } } else { JsonResponse(proc, login, "{'state': 'NotFound'}"); } }
public TemplateEngine(ISemanticProcessor proc = null) { Usings = new List<string>(); References = new List<string>(); cachedAssemblies = new Dictionary<Guid, IRuntimeAssembly>(); AddCoreUsings(); }
// Ex: localhost:8001/flowsharp?cmd=CmdDropShape&ShapeName=Box&X=50&Y=100 // Ex: localhost:8001/flowsharp?cmd=CmdDropShape&ShapeName=Box&X=50&Y=100&Text=Foobar&FillColor=!FF00ff&Width=300 public void Process(ISemanticProcessor proc, IMembrane membrane, CmdDropShape cmd) { List <Type> shapes = proc.ServiceManager.Get <IFlowSharpToolboxService>().ShapeList; var controller = proc.ServiceManager.Get <IFlowSharpCanvasService>().ActiveController; Type t = shapes.Where(s => s.Name == cmd.ShapeName).SingleOrDefault(); if (t != null) { controller.Canvas.FindForm().BeginInvoke(() => { GraphicElement el = (GraphicElement)Activator.CreateInstance(t, new object[] { controller.Canvas }); el.DisplayRectangle = new Rectangle(cmd.X, cmd.Y, cmd.Width ?? el.DefaultRectangle().Width, cmd.Height ?? el.DefaultRectangle().Height); el.Name = cmd.Name; el.Text = cmd.Text; cmd.FillColor.IfNotNull(c => el.FillColor = GetColor(c)); cmd.BorderColor.IfNotNull(c => el.BorderPenColor = GetColor(c)); cmd.TextColor.IfNotNull(c => el.TextColor = GetColor(c)); el.UpdateProperties(); el.UpdatePath(); controller.Insert(el); }); } }
public override void FinishedInitialization() { ISemanticProcessor semProc = ServiceManager.Get <ISemanticProcessor>(); semProc.Register <LoggerMembrane, GenericTypeLogger>(); semProc.Register <LoggerMembrane, LoggerService>(); }
public void Process(ISemanticProcessor proc, IMembrane membrane, ST_Log log) { this.BeginInvoke(() => { tbLog.AppendText(log.Message+"\r\n"); }); }
private static void RegisterRouteReceptors() { ISemanticProcessor semProc = serviceManager.Get <ISemanticProcessor>(); semProc.Register <WebServerMembrane, PostReceptor>(); semProc.Register <WebServerMembrane, GetReceptor>(); }
public void Process(ISemanticProcessor proc, IMembrane membrane, ExceptionResponse resp) { // proc.ServiceManager.Get<ILoggerService>().Log(LogMessage.Create(resp.Exception.Message)); proc.ServiceManager.Get <ISemanticProcessor>().ProcessInstance <LoggerMembrane, ST_Exception>(ex => ex.Exception = resp.Exception); resp.Context.Response.ContentLength64 = resp.Exception.Message.Length; resp.Context.Response.Write(resp.Exception.Message, "text/text", 500); }
public void Process(ISemanticProcessor semProc, IMembrane membrane, ISemanticType t) { if ((!(t is ST_Log)) && (!(t is ST_Exception))) { Console.WriteLine("Publishing type: " + t.GetType().Name); } }
public TemplateEngine(ISemanticProcessor proc = null) { Usings = new List <string>(); References = new List <string>(); cachedAssemblies = new Dictionary <Guid, IRuntimeAssembly>(); AddCoreUsings(); }
public void Process(ISemanticProcessor semProc, IMembrane membrane, ISemanticType t) { if ( (!(t is ST_Log)) && (!(t is ST_Exception)) ) { Console.WriteLine("Publishing type: " + t.GetType().Name); } }
public void Process(ISemanticProcessor proc, IMembrane membrane, ST_Log log) { this.BeginInvoke(() => { tbLog.AppendText(log.Message + "\r\n"); }); }
public override void FinishedInitialization() { base.FinishedInitialization(); logger = ServiceManager.Get <ILoggerService>(); semProc = ServiceManager.Get <ISemanticProcessor>(); Assert.SilentTry(() => httpOnly = ServiceManager.Get <IAppConfigService>().GetValue("httpOnly").to_b()); }
public override void FinishedInitialization() { base.FinishedInitialization(); ISemanticProcessor semProc = ServiceManager.Get <ISemanticProcessor>(); semProc.Register <EmailClientMembrane, DbContextReceptor>(); }
public override void FinishedInitialization() { base.FinishedInitialization(); ISemanticProcessor semProc = ServiceManager.Get <ISemanticProcessor>(); semProc.Register <WebServerMembrane, ResponderReceptor>(); }
// Ex: localhost:8001/flowsharp?cmd=CmdDropConnector&ConnectorName=DiagonalConnector&X1=50&Y1=100&X2=150&Y2=150 public void Process(ISemanticProcessor proc, IMembrane membrane, CmdDropConnector cmd) { List <Type> shapes = proc.ServiceManager.Get <IFlowSharpToolboxService>().ShapeList; var controller = proc.ServiceManager.Get <IFlowSharpCanvasService>().ActiveController; Type t = shapes.Where(s => s.Name == cmd.ConnectorName).SingleOrDefault(); if (t != null) { controller.Canvas.FindForm().BeginInvoke(() => { DynamicConnector el = (DynamicConnector)Activator.CreateInstance(t, new object[] { controller.Canvas }); // el = (DynamicConnector)el.CloneDefault(controller.Canvas, new Point(cmd.X1, cmd.Y1)); // el = (DynamicConnector)el.CloneDefault(controller.Canvas); el.Name = cmd.Name; el.StartPoint = new Point(cmd.X1, cmd.Y1); el.EndPoint = new Point(cmd.X2, cmd.Y2); cmd.BorderColor.IfNotNull(c => el.BorderPenColor = GetColor(c)); int x1 = cmd.X1.Min(cmd.X2); int y1 = cmd.Y1.Min(cmd.Y2); int x2 = cmd.X1.Max(cmd.X2); int y2 = cmd.Y1.Max(cmd.Y2); el.DisplayRectangle = new Rectangle(x1, y1, x2 - x1, y2 - y1); el.UpdatePath(); controller.Insert(el); }); } }
public void Process(ISemanticProcessor proc, IMembrane membrane, Logout logout) { proc.ServiceManager.Get <IWebSessionService>().Logout(logout.Context); proc.ServiceManager.Get <IWebSessionService>().SetSessionObject(logout.Context, "OneTimeAlert", "You are now logged out."); proc.ServiceManager.Get <IWebSessionService>().SetSessionObject(logout.Context, "UserName", ""); logout.Context.Redirect("/"); }
public void Process(ISemanticProcessor proc, IMembrane membrane, ST_RssFeedItem feedItem) { lbl.BeginInvoke(() => { lbl.Text = labelText; tb.Text = feedItem.Text; }); }
public override void FinishedInitialization() { base.FinishedInitialization(); websitePath = ServiceManager.Get <IAppConfigService>().GetValue("WebsitePath"); ISemanticProcessor semProc = ServiceManager.Get <ISemanticProcessor>(); semProc.Register <WebServerMembrane, WebFileResponseReceptor>(); }
public void Process(ISemanticProcessor proc, IMembrane membrane, FontResponse resp) { resp.Context.Response.ContentType = resp.ContentType; resp.Context.Response.ContentEncoding = Encoding.UTF8; resp.Context.Response.ContentLength64 = resp.BinaryData.Length; resp.Context.Response.OutputStream.Write(resp.BinaryData, 0, resp.BinaryData.Length); resp.Context.Response.Close(); }
public void Process(ISemanticProcessor proc, IMembrane membrane, ST_AddNewSubtype data) { TreeNode sttn = selectedNode; Schema parentSchema = (Schema)sttn.Parent.Tag; Schema schema = new Schema() { Name = data.Name, Alias = data.Alias, Parent = parentSchema }; parentSchema.Subtypes.Add(schema); AddSchemaNode(sttn, schema); }
protected void Process(ISemanticProcessor proc, IMembrane membrane, ST_NoData nothing) { dgView.FindForm().BeginInvoke(() => { dgView.DataSource = null; label.Text = "Collection: "; }); }
protected void ProcessFileRequest(ISemanticProcessor semProc, HttpListenerContext context) { bool handled = false; string path = context.Request.RawUrl.LeftOf("?").RightOf("/").LeftOfRightmostOf('.'); string ext = context.Request.RawUrl.RightOfRightmostOf('.'); if (String.IsNullOrEmpty(path)) { path = "index"; } if (String.IsNullOrEmpty(ext)) { ext = "html"; } path = path + "." + ext; // Hardcoded folder path for the website! path = Path.Combine("Website", path); if (File.Exists(path)) { switch (ext) { case "html": semProc.ProcessInstance <WebServerMembrane, ST_HtmlResponse>(r => { r.Context = context; r.Html = ReadTextFile(path); }); break; case "js": semProc.ProcessInstance <WebServerMembrane, ST_JavascriptResponse>(r => { r.Context = context; r.Javascript = ReadTextFile(path); }); break; case "css": semProc.ProcessInstance <WebServerMembrane, ST_CssResponse>(r => { r.Context = context; r.Css = ReadTextFile(path); }); break; } handled = true; } if (!handled) { semProc.ServiceManager.Get <ILoggerService>().Log("Route not found."); semProc.ProcessInstance <WebServerMembrane, ST_RouteNotFound>(r => r.Context = context); } }
protected void ProcessFileRequest(ISemanticProcessor semProc, HttpListenerContext context) { bool handled = false; string path = context.Request.RawUrl.LeftOf("?").RightOf("/").LeftOfRightmostOf('.'); string ext = context.Request.RawUrl.RightOfRightmostOf('.'); if (String.IsNullOrEmpty(path)) { path = "index"; } if (String.IsNullOrEmpty(ext)) { ext = "html"; } path = path + "." + ext; // Hardcoded folder path for the website! path = Path.Combine("Website", path); if (File.Exists(path)) { switch (ext) { case "html": semProc.ProcessInstance<WebServerMembrane, ST_HtmlResponse>(r => { r.Context = context; r.Html = ReadTextFile(path); }); break; case "js": semProc.ProcessInstance<WebServerMembrane, ST_JavascriptResponse>(r => { r.Context = context; r.Javascript = ReadTextFile(path); }); break; case "css": semProc.ProcessInstance<WebServerMembrane, ST_CssResponse>(r => { r.Context = context; r.Css = ReadTextFile(path); }); break; } handled = true; } if (!handled) { semProc.ServiceManager.Get<ILoggerService>().Log("Route not found."); semProc.ProcessInstance<WebServerMembrane, ST_RouteNotFound>(r => r.Context = context); } }
protected void JsonResponse(ISemanticProcessor proc, SemanticRoute packet) { proc.ProcessInstance <WebServerMembrane, JsonResponse>(r => { r.Context = packet.Context; r.Json = ""; r.StatusCode = 200; }); }
public void Process(ISemanticProcessor proc, IMembrane membrane, CssResponse resp) { byte[] utf8data = resp.Script.to_Utf8(); resp.Context.Response.ContentType = "text/css"; resp.Context.Response.ContentEncoding = Encoding.UTF8; resp.Context.Response.ContentLength64 = utf8data.Length; resp.Context.Response.OutputStream.Write(utf8data, 0, utf8data.Length); resp.Context.Response.Close(); }
public void Process(ISemanticProcessor proc, IMembrane membrane, ST_JavascriptResponse resp) { byte[] utf8data = resp.Javascript.to_Utf8(); resp.Context.Response.ContentType = "text/javascript"; resp.Context.Response.ContentEncoding = Encoding.UTF8; resp.Context.Response.ContentLength64 = utf8data.Length; resp.Context.Response.OutputStream.Write(utf8data, 0, utf8data.Length); resp.Context.Response.Close(); }
public void Process(ISemanticProcessor proc, IMembrane membrane, JsonResponse resp) { resp.Context.Response.StatusCode = resp.StatusCode; resp.Context.Response.ContentType = "text/json"; resp.Context.Response.ContentEncoding = Encoding.UTF8; resp.Context.Response.ContentLength64 = resp.Json.Length; resp.Context.Response.OutputStream.Write(resp.Json.to_Utf8(), 0, resp.Json.Length); resp.Context.Response.Close(); }
public void Process(ISemanticProcessor proc, IMembrane membrane, ST_Associations assoc) { this.BeginInvoke(() => { RemoveAssociationButtons(); int n = CreateForwardAssociationButtons(assoc.ForwardSchemaNames); CreateReverseAssociationButtons(assoc.ReverseSchemaNames, n); }); }
public void Process(ISemanticProcessor proc, IMembrane membrane, ST_Data data) { DataView dv = new DataView(data.Table); view.FindForm().BeginInvoke(() => { view.DataSource = dv; label.Text = "Collection: " + data.Table.TableName; }); }
public void Process(ISemanticProcessor proc, IMembrane membrane, ST_Url url) { SyndicationFeed sf = GetFeed(url.Url); sf.Items.ForEach(si => proc.ProcessInstance(membrane, new ST_RssFeedItem() { Text = si.Summary.Text })); }
public void Process(ISemanticProcessor proc, IMembrane membrane, HtmlPageRoute context) { bool handled = proc.ServiceManager.Get<IWebFileResponse>().ProcessFileRequest(context.Context); if (!handled) { RouteNotFoundResponse(proc, context.Context); } }
public void Process(ISemanticProcessor proc, IMembrane membrane, ST_AddConcreteType data) { TreeNode cttn = selectedNode; Schema schema = (Schema)cttn.Parent.Tag; // TODO: Get actual type at some point. ConcreteType ct = new ConcreteType() { Name = data.Name, Alias = data.Alias, Type = typeof(string) }; schema.ConcreteTypes.Add(ct); AddConcreteTypeToNode(cttn, ct); }
protected virtual void RouteNotFoundResponse(ISemanticProcessor proc, HttpListenerContext context) { proc.ProcessInstance<WebServerMembrane, StringResponse>(r => { r.Context = context; r.Message = "Route not found"; r.StatusCode = 500; }); }
protected virtual void RouteNotFoundResponse(ISemanticProcessor proc, HttpListenerContext context) { proc.ProcessInstance <WebServerMembrane, StringResponse>(r => { r.Context = context; r.Message = "Route not found"; r.StatusCode = 500; }); }
public void Process(ISemanticProcessor proc, IMembrane membrane, HtmlPageRoute context) { bool handled = proc.ServiceManager.Get <IWebFileResponse>().ProcessFileRequest(context.Context); if (!handled) { RouteNotFoundResponse(proc, context.Context); } }
public void Process(ISemanticProcessor proc, IMembrane membrane, DataResponse resp) { byte[] utf8data = resp.Data.ToBase64().to_Utf8(); resp.Context.Response.StatusCode = resp.StatusCode; resp.Context.Response.ContentEncoding = Encoding.UTF8; resp.Context.Response.ContentLength64 = utf8data.Length; resp.Context.Response.OutputStream.Write(utf8data, 0, utf8data.Length); resp.Context.Response.Close(); }
// FlowSharpCodeOutputWindowService required for this behavior. // Ex: localhost:8001/flowsharp?cmd=CmdOutputMessage&Text=foobar public void Process(ISemanticProcessor proc, IMembrane membrane, CmdOutputMessage cmd) { BaseController controller = proc.ServiceManager.Get <IFlowSharpCanvasService>().ActiveController; var w = proc.ServiceManager.Get <IFlowSharpCodeOutputWindowService>(); controller.Canvas.FindForm().BeginInvoke(() => { cmd.Text.Split('\n').Where(s => !String.IsNullOrEmpty(s.Trim())).ForEach(s => w.WriteLine(s.Trim())); }); }
public void Process(ISemanticProcessor proc, IMembrane membrane, StringResponse resp) { resp.Context.Response.StatusCode = resp.StatusCode; resp.Context.Response.ContentType = "text/text"; resp.Context.Response.ContentEncoding = Encoding.UTF8; byte[] byteData = resp.Message.to_Utf8(); resp.Context.Response.ContentLength64 = byteData.Length; resp.Context.Response.OutputStream.Write(byteData, 0, byteData.Length); resp.Context.Response.Close(); }
/// <summary> /// Returns HTML rendering the current state of the dictionary tree. /// </summary> public void Process(ISemanticProcessor proc, IMembrane membrane, GetDictionaryTreeHtml msg) { ContextValueDictionary cvd = CreateOrGetContextValueDictionary(proc, msg.Context); StringBuilder sb = new StringBuilder(); List <Guid> path = new List <Guid>(); NavigateChildren(sb, cvd.Root.Children, 0, path, msg.ShowInstanceIDs); JsonResponse(proc, msg, new { Status = "OK", html = sb.ToBase64String() }); }
/// <summary> /// The HtmlResponse process is the only process that invokes the workflow post router for final /// processing of the HTML. /// </summary> public void Process(ISemanticProcessor proc, IMembrane membrane, HtmlResponse resp) { proc.ServiceManager.IfExists <IWebWorkflowService>(wws => wws.PostRouter(resp.Context, resp)); byte[] utf8data = resp.Html.to_Utf8(); resp.Context.Response.ContentType = "text/html"; resp.Context.Response.ContentEncoding = Encoding.UTF8; resp.Context.Response.ContentLength64 = utf8data.Length; resp.Context.Response.OutputStream.Write(utf8data, 0, utf8data.Length); resp.Context.Response.Close(); }
public void Process(ISemanticProcessor proc, IMembrane membrane, ST_AddExistingSubtype data) { TreeNode sttn = selectedNode; Schema parentSchema = (Schema)sttn.Parent.Tag; Schema schema = data.Schema.DeepClone(); schema.Parent = parentSchema; parentSchema.Subtypes.Add(schema); TreeNode tn = AddSchemaNode(sttn, schema); AddConcreteTypes(tn.Nodes[0], schema); schema.Subtypes.ForEach(st => AddSubTypesToNode(tn.Nodes[1], st)); }
public void Process(ISemanticProcessor proc, IMembrane membrane, ExceptionResponse resp) { // proc.ServiceManager.Get<ILoggerService>().Log(LogMessage.Create(resp.Exception.Message)); proc.ServiceManager.Get<ISemanticProcessor>().ProcessInstance<LoggerMembrane, ST_Exception>(ex => ex.Exception = resp.Exception); resp.Context.Response.StatusCode = 500; resp.Context.Response.ContentType = "text/text"; resp.Context.Response.ContentEncoding = Encoding.UTF8; resp.Context.Response.ContentLength64 = resp.Exception.Message.Length; resp.Context.Response.OutputStream.Write(resp.Exception.Message.to_Utf8(), 0, resp.Exception.Message.Length); resp.Context.Response.Close(); }
public void Process(ISemanticProcessor proc, IMembrane membrane, ST_Data data) { schema = data.Schema; DataView dv = new DataView(data.Table); dgView.FindForm().BeginInvoke(() => { dgView.DataSource = dv; dgView.Columns[0].Visible = false; // Hide the ID field. label.Text = "Semantic Type: " + data.Table.TableName; }); }
private static void RunProcessor(ConnectionStringSettings tycheDBCN, ISemanticProcessor processor) { if (processor != null) { var tycheRepo = new Repository(tycheDBCN.ConnectionString); processor.TycheRepository = tycheRepo; processor.Start(); processor.Stop(); } }
public virtual void Start(string ip, int port) { logger = ServiceManager.Get<ILoggerService>(); semProc = ServiceManager.Get<ISemanticProcessor>(); listener = new HttpListener(); string url = IpWithPort(ip, port); logger.Log("Listening on " + ip + ":" + port); listener.Prefixes.Add(url); listener.Start(); Task.Run(() => WaitForConnection(listener)); }
public void Process(ISemanticProcessor proc, IMembrane membrane, ISemanticType type) { // Don't log our log message, otherwise we get an infinite loop! if (!(type is ST_Log)) { // One way, with instances: // proc.ProcessInstance(proc.Logger, new ST_Log() { Message = type.GetType().ToString() }); // Another way, strictly with types: proc.ProcessInstance<LoggerMembrane, ST_Log>(log => log.Message = type.GetType().ToString()); } }
public void Process(ISemanticProcessor proc, IMembrane membrane, ST_AddSchema data) { Schema schema = new Schema() { Name = data.Name, Alias = data.Alias }; model.Schemata.Add(schema); TreeNode tn = new TreeNode(Helpers.GetSchemaNodeText(schema)); tn.Tag = schema; tn.Nodes.Add("Concrete Types"); tn.Nodes.Add("Subtypes"); tv.FindForm().BeginInvoke(() => { tv.Nodes[0].Nodes.Add(tn); }); }
public override void FinishedInitialization() { base.FinishedInitialization(); logger = ServiceManager.Get<ILoggerService>(); semProc = ServiceManager.Get<ISemanticProcessor>(); }
public void Process(ISemanticProcessor proc, IMembrane membrane, ST_CompilerError error) { proc.ServiceManager.Get<IConsoleLoggerService>().Log(error.Error); }
public void Process(ISemanticProcessor semProc, IMembrane membrane, ST_Exception msg) { Log(msg.Exception.Message); Log(msg.Exception.StackTrace); }
public void Process(ISemanticProcessor semProc, IMembrane membrane, ST_Log msg) { Log(msg.Message); }
public void Process(ISemanticProcessor proc, IMembrane membrane, ST_Log msg) { proc.ServiceManager.Get<IPaperTrailAppLoggerService>().Log(msg.Tid, msg.Message); }
public void Process(ISemanticProcessor proc, IMembrane membrane, ST_Exception exception) { proc.ServiceManager.Get<IPaperTrailAppLoggerService>().Log(exception.Tid, exception.Exception); }
public void Process(ISemanticProcessor proc, IMembrane membrane, Route route) { IPublicRouterService routerService = proc.ServiceManager.Get<IPublicRouterService>(); HttpListenerContext context = route.Context; HttpVerb verb = context.Verb(); UriPath path = context.Path(); string searchRoute = GetSearchRoute(verb, path); RouteInfo routeInfo; // Semantic routes can be either public or authenticated. if (routerService.Routes.TryGetValue(searchRoute, out routeInfo)) { string data = new StreamReader(context.Request.InputStream, context.Request.ContentEncoding).ReadToEnd(); Type receptorSemanticType = routeInfo.ReceptorSemanticType; SemanticRoute semanticRoute = (SemanticRoute)Activator.CreateInstance(receptorSemanticType); semanticRoute.PostData = data; if (!String.IsNullOrEmpty(data)) { // Is it JSON? if (data[0] == '{') { JsonConvert.PopulateObject(data, semanticRoute); } else { // Example: "username=sdfsf&password=sdfsdf&LoginButton=Login" string[] parms = data.Split('&'); foreach (string parm in parms) { string[] keyVal = parm.Split('='); PropertyInfo pi = receptorSemanticType.GetProperty(keyVal[0], BindingFlags.Public | BindingFlags.Instance | BindingFlags.IgnoreCase); if (pi != null) { // TODO: Convert to property type. // TODO: value needs to be re-encoded to handle special characters. pi.SetValue(semanticRoute, keyVal[1]); } } } } else if (verb.Value == "GET") { // Parse parameters NameValueCollection nvc = context.Request.QueryString; foreach(string key in nvc.AllKeys) { PropertyInfo pi = receptorSemanticType.GetProperty(key, BindingFlags.Public | BindingFlags.Instance); if (pi != null) { // TODO: Convert to property type. // TODO: value needs to be re-encoded to handle special characters. pi.SetValue(semanticRoute, nvc[key]); } } } // Must be done AFTER populating the object -- sometimes the json converter nulls the base class! semanticRoute.Context = context; proc.ProcessInstance<WebServerMembrane>(semanticRoute, true); // TODO: Why execute on this thread? } else if (verb.Value == "GET") { // Only issue the UnhandledContext if this is not an authenticated route. if (!proc.ServiceManager.Get<IAuthenticatingRouterService>().IsAuthenticatedRoute(searchRoute)) { // Put the context on the bus for some service to pick up. // All unhandled context are assumed to be public routes. proc.ProcessInstance<WebServerMembrane, UnhandledContext>(c => c.Context = context); } } else { proc.ProcessInstance<WebServerMembrane, ExceptionResponse>(e => { e.Context = context; e.Exception = new Exception("Route " + searchRoute + " not defined."); }); } }