public WorkflowContext(WorkflowContinuation <ContextWrapper> workflowContinuation, ContextWrapper context) { this.workflowContinuation = workflowContinuation; this.context = context; }
/// <summary> /// A workflow item implementing the ContextWrapper handler. /// </summary> public WorkflowState Process(WorkflowContinuation <ContextWrapper> workflowContinuation, ContextWrapper context) { // Create a workflow context and queue it. requests.Enqueue(new WorkflowContext(workflowContinuation, context)); semQueue.Release(); return(WorkflowState.Defer); }
/// <summary> /// Route the request. If no route exists, the workflow continues, otherwise, we return the route handler's continuation state. /// </summary> public WorkflowState Route(WorkflowContinuation <ContextWrapper> workflowContinuation, ContextWrapper wrapper) { WorkflowState ret = WorkflowState.Continue; RouteEntry entry = null; Session session = sessionManager != null ? sessionManager[wrapper.Context] : null; PathParams parms = null; // Makes debugging easier to declare these variable here. string verb = wrapper.Context.Verb(); string path = wrapper.Context.Path(); if (routeTable.TryGetRouteEntry(verb, path, wrapper.Context.Request.ContentType, out entry, out parms)) { if (entry.RouteHandler != null) { ret = entry.RouteHandler(workflowContinuation, wrapper, session, parms); } } return(ret); }
public WorkflowState GetContent(WorkflowContinuation <ContextWrapper> workflowContinuation, ContextWrapper wrapper) { // Only try to get the file if we DO NOT have a pending page response that some route handler or other workflow step created. if (wrapper.PendingResponse == null) { // Get the request. HttpListenerRequest request = wrapper.Context.Request; HttpListenerResponse response = wrapper.Context.Response; // Get the path, everything up to the first ? and excluding the leading "/" string path = wrapper.Context.Path(); string ext = wrapper.Context.Extension(); // Console.WriteLine(path); // Default to index.html if only the URL is provided with no additional page information. if (String.IsNullOrEmpty(path)) { path = "index.html"; ext = "html"; } if (String.IsNullOrEmpty(ext)) { path = path + ".html"; } path = websitePath + "\\" + path; FileExtensionHandler extHandler; if (extensionLoaderMap.TryGetValue(ext, out extHandler)) { extHandler.Loader(wrapper, path, ext); wrapper.PendingResponse.MimeType = extHandler.ContentType; } } return(WorkflowState.Continue); }
public WorkflowState Provider(WorkflowContinuation <ContextWrapper> workflowContinuation, ContextWrapper wrapper) { Session session; IPAddress endpointAddress = wrapper.Context.EndpointAddress(); if (!sessionMap.TryGetValue(endpointAddress, out session)) { session = new Session(endpointAddress); session[CsrfTokenName] = Guid.NewGuid().ToString(); sessionMap[endpointAddress] = session; } else { // If the session exists, set the expired flag before we update the last connection date/time. // Once set, stays set until explicitly cleared. session.Expired |= session.IsExpired(ExpireInSeconds); } wrapper.Session = session; session.UpdateLastConnectionTime(); WorkflowState ret = CheckExpirationAndAuthorization(workflowContinuation, wrapper, session); return(ret); }
protected WorkflowState CheckExpirationAndAuthorization(WorkflowContinuation <ContextWrapper> workflowContinuation, ContextWrapper wrapper, Session session) { // Inspect the route to see if we should do session expiration and/or session authorization checks. WorkflowState ret = WorkflowState.Continue; RouteEntry entry = null; PathParams parms = null; if (routeTable.TryGetRouteEntry(wrapper.Context.Verb(), wrapper.Context.Path(), out entry, out parms)) { if (entry.SessionExpirationHandler != null) { ret = entry.SessionExpirationHandler(workflowContinuation, wrapper, session, parms); } if (ret == WorkflowState.Continue) { if (entry.AuthorizationHandler != null) { ret = entry.AuthorizationHandler(workflowContinuation, wrapper, session, parms); } } } return(ret); }