Update Reference Sources to .NET Framework 4.6.1
[mono.git] / mcs / class / referencesource / System.Workflow.Runtime / Hosting / WorkflowWebHostingModule.cs
1 /*******************************************************************************
2 // Copyright (C) 2000-2001 Microsoft Corporation.  All rights reserved.
3 //
4 // CONTENTS
5 //     Workflow Web Hosting Module.
6  
7 // DESCRIPTION
8 //      Implementation of Workflow Web Host Module.
9  
10 // REVISIONS
11 // Date          Ver     By           Remarks
12 // ~~~~~~~~~~    ~~~     ~~~~~~~~     ~~~~~~~~~~~~~~
13 // 02/22/05      1.0     [....]       Implementation.
14  * ****************************************************************************/
15
16 #region Using directives
17
18 using System;
19 using System.Collections;
20 using System.Collections.Generic;
21 using System.Text;
22 using System.Diagnostics;
23 using System.Web;
24 using System.Collections.Specialized;
25 using System.Threading;
26
27 #endregion
28
29 namespace System.Workflow.Runtime.Hosting
30 {
31     /// <summary>
32     /// Cookie based rotuing module implementation
33     /// </summary>
34     [Obsolete("The System.Workflow.* types are deprecated.  Instead, please use the new types from System.Activities.*")]
35     public sealed class WorkflowWebHostingModule : IHttpModule
36     {
37         HttpApplication currentApplication;
38
39         public WorkflowWebHostingModule()
40         {
41             WorkflowTrace.Host.TraceEvent(TraceEventType.Information, 0, "Workflow Web Hosting Module Created");            
42         }
43
44         /// <summary>
45         /// IHttpModule.Init()
46         /// </summary>
47         /// <param name="application"></param>
48         void IHttpModule.Init(HttpApplication application)
49         {
50             WorkflowTrace.Host.TraceEvent(TraceEventType.Information, 0, "Workflow Web Hosting Module Initialized");
51
52             this.currentApplication = application;
53
54             //Listen for Acquire and ReleaseRequestState event
55             application.ReleaseRequestState += this.OnReleaseRequestState;
56             application.AcquireRequestState += this.OnAcquireRequestState;
57         }
58
59         void IHttpModule.Dispose()
60         {
61
62         }
63
64         void OnAcquireRequestState(Object sender, EventArgs e)
65         {
66             //Performs Cookie based routing.
67             WorkflowTrace.Host.TraceEvent(TraceEventType.Information, 0, "WebHost Module Routing Begin");
68
69             HttpCookie routingCookie = HttpContext.Current.Request.Cookies.Get("WF_WorkflowInstanceId");
70
71             if (routingCookie != null)
72             {
73                 HttpContext.Current.Items.Add("__WorkflowInstanceId__", new Guid(routingCookie.Value));
74             }
75             //else no routing information found, it could be activation request or non workflow based request.
76         }
77
78         void OnReleaseRequestState(Object sender, EventArgs e)
79         {
80             //Saves cookie back to client.
81             HttpCookie cookie = HttpContext.Current.Request.Cookies.Get("WF_WorkflowInstanceId");
82
83             if (cookie == null)
84             {
85                 cookie = new HttpCookie("WF_WorkflowInstanceId");
86                 Object workflowInstanceId = HttpContext.Current.Items["__WorkflowInstanceId__"];
87
88                 if (workflowInstanceId != null)
89                 {
90                     cookie.Value = workflowInstanceId.ToString();
91                     HttpContext.Current.Response.Cookies.Add(cookie);
92                 }
93             }            
94         }        
95     }   
96 }