private List<HttpApplication.IExecutionStep> GetStepArray(RequestNotification notification, bool isPostEvent) {

#if DBG
            Debug.Trace("PipelineRuntime",
                        "GetStepArray for " + DebugModuleName + " for " + notification.ToString() +
                        " and " + isPostEvent + "\r\n");
#endif            

            List<HttpApplication.IExecutionStep>[] steps = _moduleSteps;
            
            if (isPostEvent) { 
                steps = _modulePostSteps;
            }

            Debug.Assert(null != steps, "null != steps");

            int index = EventToIndex(notification);
            Debug.Assert(index != -1, "index != -1");

            Debug.Trace("PipelineRuntime",
                        "GetStepArray: " + notification.ToString() + " mapped to index " + index.ToString(CultureInfo.InvariantCulture) + "\r\n");

            List<HttpApplication.IExecutionStep> stepArray = steps[index];
            // we shouldn't be asking for events that aren't mapped to this
            // module at all
            Debug.Assert(null != stepArray, "null != stepArray");            
            
            return stepArray;                
        }
示例#2
0
 internal void RemoveEvent(RequestNotification notification, bool isPostEvent, Delegate handler)
 {
     List <HttpApplication.IExecutionStep>[] listArray = this._moduleSteps;
     if (isPostEvent)
     {
         listArray = this._modulePostSteps;
     }
     if (listArray != null)
     {
         int index = EventToIndex(notification);
         List <HttpApplication.IExecutionStep> list = listArray[index];
         if (list != null)
         {
             int num2 = -1;
             for (int i = 0; i < list.Count; i++)
             {
                 HttpApplication.SyncEventExecutionStep step = list[i] as HttpApplication.SyncEventExecutionStep;
                 if ((step != null) && (step.Handler == ((EventHandler)handler)))
                 {
                     num2 = i;
                     break;
                 }
             }
             if (num2 != -1)
             {
                 list.RemoveAt(num2);
             }
         }
     }
 }
 internal void AddEvent(RequestNotification notification, bool isPostEvent, HttpApplication.IExecutionStep step)
 {
     int index = EventToIndex(notification);
     List<HttpApplication.IExecutionStep>[] listArray = null;
     if (isPostEvent)
     {
         if (this._modulePostSteps == null)
         {
             this._modulePostSteps = new List<HttpApplication.IExecutionStep>[0x20];
         }
         listArray = this._modulePostSteps;
     }
     else
     {
         if (this._moduleSteps == null)
         {
             this._moduleSteps = new List<HttpApplication.IExecutionStep>[0x20];
         }
         listArray = this._moduleSteps;
     }
     List<HttpApplication.IExecutionStep> list = listArray[index];
     if (list == null)
     {
         list = new List<HttpApplication.IExecutionStep>();
         listArray[index] = list;
     }
     list.Add(step);
 }
示例#4
0
文件: World.cs 项目: Rixium/Repair
        public World(int currentLevel)
        {
            _currentLevel = currentLevel;

            Map = new Map(ContentChest.Maps[_currentLevel]);

            WorldObjects = Map.WorldObjects;
            WorldItems   = Map.WorldItems;

            InputManager.OnDownHeld        = () => Player.Move(0, 1);
            InputManager.OnUpHeld          = () => Player.Move(0, -1);
            InputManager.OnLeftHeld        = () => Player.Move(-1, 0);
            InputManager.OnRightHeld       = () => Player.Move(1, 0);
            InputManager.OnDownPressed     = () => Player.Look(0, 1);
            InputManager.OnUpPressed       = () => Player.Look(0, -1);
            InputManager.OnLeftPressed     = () => Player.Look(-1, 0);
            InputManager.OnRightPressed    = () => Player.Look(1, 0);
            InputManager.OnNextSlotPressed = () => UIManager.NextSlot();
            InputManager.OnLastSlotPressed = () => UIManager.LastSlot();
            InputManager.OnInteractPressed = UseItem;
            InputManager.OnPickupPressed   = PickupWorldObject;
            InputManager.OnBackPressed     = ResetWorld;

            Map.RequestNotification = s => RequestNotification?.Invoke(s);

            UIManager = new UIManager();

            SetupPlayer();
            SetupCamera();

            ProgressTimer          = new Timer();
            ProgressTimer.Elapsed += (e, b) => Progress();
            ProgressTimer.Start();
        }
        private List <HttpApplication.IExecutionStep> GetStepArray(RequestNotification notification, bool isPostEvent)
        {
#if DBG
            Debug.Trace("PipelineRuntime",
                        "GetStepArray for " + DebugModuleName + " for " + notification.ToString() +
                        " and " + isPostEvent + "\r\n");
#endif

            List <HttpApplication.IExecutionStep>[] steps = _moduleSteps;

            if (isPostEvent)
            {
                steps = _modulePostSteps;
            }

            Debug.Assert(null != steps, "null != steps");

            int index = EventToIndex(notification);
            Debug.Assert(index != -1, "index != -1");

            Debug.Trace("PipelineRuntime",
                        "GetStepArray: " + notification.ToString() + " mapped to index " + index.ToString(CultureInfo.InvariantCulture) + "\r\n");

            List <HttpApplication.IExecutionStep> stepArray = steps[index];
            // we shouldn't be asking for events that aren't mapped to this
            // module at all
            Debug.Assert(null != stepArray, "null != stepArray");

            return(stepArray);
        }
示例#6
0
        internal void AddEvent(RequestNotification notification, bool isPostEvent, HttpApplication.IExecutionStep step)
        {
            int index = EventToIndex(notification);

            List <HttpApplication.IExecutionStep>[] listArray = null;
            if (isPostEvent)
            {
                if (this._modulePostSteps == null)
                {
                    this._modulePostSteps = new List <HttpApplication.IExecutionStep> [0x20];
                }
                listArray = this._modulePostSteps;
            }
            else
            {
                if (this._moduleSteps == null)
                {
                    this._moduleSteps = new List <HttpApplication.IExecutionStep> [0x20];
                }
                listArray = this._moduleSteps;
            }
            List <HttpApplication.IExecutionStep> list = listArray[index];

            if (list == null)
            {
                list             = new List <HttpApplication.IExecutionStep>();
                listArray[index] = list;
            }
            list.Add(step);
        }
 private void validateStage(IOwinContext context, RequestNotification expectedStageName, int middlewareId)
 {
     var calledAtStage = context.Get<System.Web.HttpContextWrapper>("System.Web.HttpContextBase").CurrentNotification;
     if (calledAtStage != expectedStageName)
     {
         throw new Exception(string.Format(Error_UnexpectedMiddleware, expectedStageName, calledAtStage, middlewareId));
     }
 }
示例#8
0
        private void validateStage(IOwinContext context, RequestNotification expectedStageName, int middlewareId)
        {
            var calledAtStage = context.Get <System.Web.HttpContextWrapper>("System.Web.HttpContextBase").CurrentNotification;

            if (calledAtStage != expectedStageName)
            {
                throw new Exception(string.Format(Error_UnexpectedMiddleware, expectedStageName, calledAtStage, middlewareId));
            }
        }
        public static async Task RunOrchestrator(
            [OrchestrationTrigger] DurableOrchestrationContext ctx)
        {
            var data = ctx.GetInput <EnrollmentHttpRequest>();
            var notificationRequest = new RequestNotification(ctx.InstanceId, data.MobileNumber, data.Email, data.FirstName, data.LastName);
            var customerInfoRequest = new CustomerInfoRequest(data.MobileNumber, ctx.InstanceId, data.Id);

            await ctx.CallActivityAsync(Activities.StoreCustomerInformation, customerInfoRequest);

            if (data.Channel == ChannelType.Email)
            {
                await ctx.CallActivityAsync(Activities.Email.EnrollmentRequestNotification, notificationRequest);
            }
            else
            {
                await ctx.CallActivityAsync(Activities.Sms.EnrollmentRequestNotification, notificationRequest);
            }

            using (var timeoutCts = new CancellationTokenSource())
            {
                Task <EnrollmentStatusEnum> approvalEvent = ctx.WaitForExternalEvent <EnrollmentStatusEnum>(Events.ApprovalEvent);

                DateTime reminderDueTime = ctx.CurrentUtcDateTime.AddMinutes(3);
                Task     reminderTimeout = ctx.CreateTimer(reminderDueTime, timeoutCts.Token);

                if (approvalEvent == await Task.WhenAny(approvalEvent, reminderTimeout))
                {
                    var dataStatus = new UpdateStatus(data.Id, data.MobileNumber, approvalEvent.Result, data.Email);

                    await ctx.CallActivityAsync(Activities.UpdateEnrollmentStatus, dataStatus);

                    if (data.Channel == ChannelType.Email)
                    {
                        await ctx.CallActivityAsync(Activities.Email.SendEnrollmentFinishedNotification, dataStatus);
                    }
                    else
                    {
                        await ctx.CallActivityAsync(Activities.Sms.SendEnrollmentFinishedNotification, dataStatus);
                    }

                    timeoutCts.Cancel();
                }
                else
                {
                    if (data.Channel == ChannelType.Email)
                    {
                        await ctx.CallActivityAsync(Activities.Email.SendReminderEnrollmentNotification, data.Email);
                    }
                    else
                    {
                        await ctx.CallActivityAsync(Activities.Sms.SendReminderEnrollmentNotification, data.MobileNumber);
                    }
                }

                await ctx.CallActivityAsync(Activities.CleanCustomerInfoTable, data.MobileNumber);
            }
        }
        internal HttpApplication.IExecutionStep GetNextEvent(RequestNotification notification, bool isPostEvent, int eventIndex)
        {
            List <HttpApplication.IExecutionStep> stepArray = GetStepArray(notification, isPostEvent);

            Debug.Assert(eventIndex >= 0, "eventIndex >= 0");
            Debug.Assert(eventIndex < stepArray.Count, "eventIndex < stepArray.Count");

            return(stepArray[eventIndex]);
        }
示例#11
0
        internal int GetEventCount(RequestNotification notification, bool isPostEvent)
        {
            List <HttpApplication.IExecutionStep> stepArray = this.GetStepArray(notification, isPostEvent);

            if (stepArray == null)
            {
                return(0);
            }
            return(stepArray.Count);
        }
 private void AddEventMapping(string moduleName, RequestNotification requestNotification, bool isPostNotification, IExecutionStep step)
 {
     ThrowIfEventBindingDisallowed();
     //if (IsContainerInitalizationAllowed)
     //{
     //    var moduleContainer = GetModuleContainer(moduleName);
     //    if (moduleContainer != null)
     //        moduleContainer.AddEvent(requestNotification, isPostNotification, step);
     //}
 }
 internal void RemoveSyncEventHookup(object key, Delegate handler, RequestNotification notification, bool isPostNotification)
 {
     ThrowIfEventBindingDisallowed();
     Events.RemoveHandler(key, handler);
     //if (IsContainerInitalizationAllowed)
     //{
     //    var moduleContainer = GetModuleContainer(CurrentModuleCollectionKey);
     //    if (moduleContainer != null)
     //        moduleContainer.RemoveEvent(notification, isPostNotification, handler);
     //}
 }
示例#14
0
        private List <HttpApplication.IExecutionStep> GetStepArray(RequestNotification notification, bool isPostEvent)
        {
            List <HttpApplication.IExecutionStep>[] listArray = this._moduleSteps;
            if (isPostEvent)
            {
                listArray = this._modulePostSteps;
            }
            int index = EventToIndex(notification);

            return(listArray[index]);
        }
示例#15
0
 internal static extern int MgdRegisterEventSubscription(
     IntPtr pAppContext,
     string pszModuleName,
     [MarshalAs(UnmanagedType.U4)]
     RequestNotification requestNotifications,
     [MarshalAs(UnmanagedType.U4)]
     RequestNotification postRequestNotifications,
     string pszModuleType,
     string pszModulePrecondition,
     IntPtr moduleSpecificData,
     bool useHighPriority);
 private void AddSyncEventHookup(object key, Delegate handler, RequestNotification notification, bool isPostNotification)
 {
     ThrowIfEventBindingDisallowed();
     Events.AddHandler(key, handler);
     //if (IsContainerInitalizationAllowed)
     //{
     //    var moduleContainer = GetModuleContainer(CurrentModuleCollectionKey);
     //    if (moduleContainer != null)
     //    {
     //        var step = new SyncEventExecutionStep(this, (EventHandler)handler);
     //        moduleContainer.AddEvent(notification, isPostNotification, step);
     //    }
     //}
 }
示例#17
0
        public static void LevelUp(this ILevelUpEvent self)
        {
            var gameSystem        = GameSystem.Instance;
            var levelUpCostRecord = gameSystem.MasterData.LevelUpCost.Records.Get(self.Id, self.Level);

            levelUpCostRecord.Cost.Consume(gameSystem.User, gameSystem.MasterData.Item);
            self.Level++;
            var record = gameSystem.MasterData.CellEvent.Records.Get(self.Id);

            gameSystem.User.History.GenerateCellEvent.Add(self.Id, self.Level - 1);

            // FIXME: 不要になったら削除する
            Broker.Global.Publish(RequestNotification.Get($"レベルアップ! {self.Level - 1} -> {self.Level}", NotificationUIElement.MessageType.Information));
        }
示例#18
0
        public static PerformanceDataProvider GetStepData(RequestNotification notification)
        {
            if (AspPerformanceData.stepData == null)
            {
                AspPerformanceData.stepData = new Dictionary <RequestNotification, PerformanceDataProvider>(13);
            }
            PerformanceDataProvider performanceDataProvider;

            if (!AspPerformanceData.stepData.TryGetValue(notification, out performanceDataProvider))
            {
                performanceDataProvider = new PerformanceDataProvider(notification.ToString());
                AspPerformanceData.stepData[notification] = performanceDataProvider;
            }
            return(performanceDataProvider);
        }
        internal void RemoveEvent(RequestNotification notification, bool isPostEvent, Delegate handler)
        {
            // if module instances unregister multiple times, this can fail on subsequent attempts
            // so don't use GetStepArray which does extra checked verification
            List <HttpApplication.IExecutionStep>[] steps = _moduleSteps;

            if (isPostEvent)
            {
                steps = _modulePostSteps;
            }

            if (steps == null)
            {
                return;
            }

            int index = EventToIndex(notification);
            List <HttpApplication.IExecutionStep> stepArray = steps[index];

            if (null == stepArray)
            {
                return;
            }


            int toRemove = -1;

            HttpApplication.SyncEventExecutionStep syncStep;
            for (int i = 0; i < stepArray.Count; i++)
            {
                // we don't support removing async event handlers
                // but the event syntax forces us to handle sync events
                syncStep = stepArray[i] as HttpApplication.SyncEventExecutionStep;
                if (null != syncStep)
                {
                    if (syncStep.Handler == (EventHandler)handler)
                    {
                        toRemove = i;
                        break;
                    }
                }
            }

            if (toRemove != -1)
            {
                stepArray.RemoveAt(toRemove);
            }
        }
        internal void AddEvent(RequestNotification notification, bool isPostEvent, HttpApplication.IExecutionStep step)
        {
            int index = EventToIndex(notification);

#if DBG
            Debug.Trace("PipelineRuntime", "Adding event: " + DebugModuleName + " " + notification.ToString() + " " +
                        isPostEvent.ToString() + "@ index " + index.ToString(CultureInfo.InvariantCulture) + "\r\n");
#endif

            Debug.Assert(index != -1, "index != -1");

            List <HttpApplication.IExecutionStep>[] steps = null;

            if (isPostEvent)
            {
                if (null == _modulePostSteps)
                {
                    _modulePostSteps = new List <HttpApplication.IExecutionStep> [32];
                }
                steps = _modulePostSteps;
            }
            else
            {
                if (null == _moduleSteps)
                {
                    _moduleSteps = new List <HttpApplication.IExecutionStep> [32];
                }

                steps = _moduleSteps;
            }

            Debug.Assert(steps != null, "steps != null");

            // retrieve the steps for this event (typically none at this point)
            // allocate a new container as necessary and add this step
            // in the event that a single module has registered more than once
            // for a given event, we'll have multiple steps here
            List <HttpApplication.IExecutionStep> stepArray = steps[index];
            if (null == stepArray)
            {
                // first touch, instantiate and save it
                stepArray    = new List <HttpApplication.IExecutionStep>();
                steps[index] = stepArray;
            }

            stepArray.Add(step);
        }
        public static void RunSendNotificationEmail([ActivityTrigger] RequestNotification notificationRequest,
                                                    ILogger log,
                                                    [SendGrid(ApiKey = "SendGridApiKey")] out SendGridMessage message)
        {
            log.LogInformation($"Sending notification to mobile number {notificationRequest.Email}.");
            var enrollmentAFUrl = Environment.GetEnvironmentVariable("EnrollmentAFUrl");
            var subsKey         = Environment.GetEnvironmentVariable("APIM_SubsKey");
            var from            = Environment.GetEnvironmentVariable("SendGrid_From");

            message = new SendGridMessage();
            message.SetFrom(new EmailAddress(from));
            message.AddTo(notificationRequest.Email, notificationRequest.FullName);
            message.SetSubject("[no-reply] Welcome to Tailwind Traders Rewards Program");

            message.AddContent("text/plain", $"Welcome to the Tailwind Traders Rewards Program! " +
                               $"Please click one of the following links to ACCEPT or CANCEL your enrollment. " +
                               $"Click ACCEPT {enrollmentAFUrl}?action=accepted&id={notificationRequest.InstanceId}&Subscription-Key={subsKey}  Or  " +
                               $"Click CANCEL {enrollmentAFUrl}?action=rejected&id={notificationRequest.InstanceId}&Subscription-Key={subsKey}");
        }
示例#22
0
        public GameScreen(int level = 1)
        {
            if (!LevelExists(level))
            {
                RequestScreenChange?.Invoke(new GameScreen(level - 1));
                return;
            }

            _world = new World(level)
            {
                RequestNotification    = s => RequestNotification?.Invoke(s),
                RequestTransitionReset = ResetTransition,
                RequestScreenChange    = (screen) => RequestScreenChange?.Invoke(screen)
            };

            Transition.OnTransitionOutEnded = _world.Progress;

            UIManager = _world.UIManager;
        }
示例#23
0
        /// <summary>
        /// レベルアップ可能か返す
        /// </summary>
        public static bool CanLevelUp(this ILevelUpEvent self)
        {
            var gameSystem        = GameSystem.Instance;
            var levelUpCostRecord = gameSystem.MasterData.LevelUpCost.Records.Get(self.Id, self.Level);

            if (levelUpCostRecord == null)
            {
                // FIXME: 不要になったら削除する
                Broker.Global.Publish(RequestNotification.Get($"最大レベルです!", NotificationUIElement.MessageType.Error));
                return(false);
            }

            if (!levelUpCostRecord.Cost.IsEnough(gameSystem.User, gameSystem.MasterData.Item))
            {
                // FIXME: 不要になったら削除する
                Broker.Global.Publish(RequestNotification.Get($"素材が足りません!", NotificationUIElement.MessageType.Error));
                return(false);
            }

            return(true);
        }
示例#24
0
        private void HandleEvent(object sender, EventArgs e) // Явный, недекларативный вариант обработки событий
        {
            string eventName = "<Unknown>";
            RequestNotification requestNotification = Context.CurrentNotification;

            switch (requestNotification)
            {
            case RequestNotification.BeginRequest:
                EventCollection.Add(EventSource.Application, "BeginRequest");
                CreateTimeStamp();
                HttpRequest request = Context.Request;
                if (request.RawUrl == "/Time")
                {
                    Response.Write(Context.Timestamp.ToLongTimeString());
                    CompleteRequest(); // Завершение запроса с записью в журнал сервера
                }

                // Не отправляем содержимое клиенту, если браузер не Google Chrome
                string agent = request.UserAgent;
                if (agent != null && agent.ToLower().IndexOf("chrome", StringComparison.Ordinal) == -1)
                {
                    Response.SuppressContent = true;
                }
                break;

            default:
                eventName = Context.CurrentNotification.ToString();
                break;
                //case RequestNotification.EndRequest:
                //   eventName = requestNotification.ToString();
                //   break;
                //case RequestNotification.AcquireRequestState:
                //   eventName = Context.IsPostNotification ? "PostAcquireRequestState" : "AcquireRequestState";
                //   break;
            }

            EventCollection.Add(EventSource.Application, eventName);
        }
        public static void RunSendNotification([ActivityTrigger] RequestNotification notificationRequest,
                                               ILogger log,
                                               [TwilioSms(AccountSidSetting = "TwilioAccountSid", AuthTokenSetting = "TwilioAuthToken", From = "%TwilioPhoneNumber%")] out CreateMessageOptions message)
        {
            log.LogInformation($"Sending notification to mobile number {notificationRequest.MobileNumber}.");

            var useSMSReply     = Environment.GetEnvironmentVariable("UseSMSReply");
            var enrollmentAFUrl = Environment.GetEnvironmentVariable("EnrollmentAFUrl");
            var subsKey         = Environment.GetEnvironmentVariable("APIM_SubsKey");

            if (Convert.ToBoolean(useSMSReply))
            {
                message      = new CreateMessageOptions(new PhoneNumber(notificationRequest.MobileNumber));
                message.Body = $"Welcome to the Tailwind Traders Rewards Program! Please reply to the message with YES/ACCEPTED or NO/CANCELLED for customer enrollment";
            }
            else
            {
                message      = new CreateMessageOptions(new PhoneNumber(notificationRequest.MobileNumber));
                message.Body = $"Welcome to the Tailwind Traders Rewards Program! " +
                               $"Please click one of the following links to ACCEPT or CANCEL your enrollment. " +
                               $"Click ACCEPT {enrollmentAFUrl}?action=accepted&id={notificationRequest.InstanceId}&Subscription-Key={subsKey}  Or  " +
                               $"Click CANCEL {enrollmentAFUrl}?action=rejected&id={notificationRequest.InstanceId}&Subscription-Key={subsKey}";
            }
        }
            internal void AddHandler(Object eventId, BeginEventHandler beginHandler,
                                     EndEventHandler endHandler, Object state,
                                     RequestNotification requestNotification,
                                     bool isPost, HttpApplication app) {
                if (_table == null)
                    _table = new Hashtable();

                AsyncAppEventHandler asyncHandler = (AsyncAppEventHandler)_table[eventId];

                if (asyncHandler == null) {
                    asyncHandler = new AsyncAppEventHandler();
                    _table[eventId] = asyncHandler;
                }

                asyncHandler.Add(beginHandler, endHandler, state);

                if (HttpRuntime.UseIntegratedPipeline) {
                    AsyncEventExecutionStep step =
                        new AsyncEventExecutionStep(app,
                                                    beginHandler,
                                                    endHandler,
                                                    state);

                    app.AddEventMapping(app.CurrentModuleCollectionKey, requestNotification, isPost, step);
                }
            }
        private void ProcessEventSubscriptions(out RequestNotification requestNotifications,
                                               out RequestNotification postRequestNotifications) {
            requestNotifications = 0;
            postRequestNotifications = 0;

            // Begin
            if(HasEventSubscription(EventBeginRequest)) {
                requestNotifications |= RequestNotification.BeginRequest;
            }

            // Authenticate
            if(HasEventSubscription(EventAuthenticateRequest)) {
                requestNotifications |= RequestNotification.AuthenticateRequest;
            }

            if(HasEventSubscription(EventPostAuthenticateRequest)) {
                postRequestNotifications |= RequestNotification.AuthenticateRequest;
            }

            // Authorize
            if(HasEventSubscription(EventAuthorizeRequest)) {
                requestNotifications |= RequestNotification.AuthorizeRequest;
            }
            if(HasEventSubscription(EventPostAuthorizeRequest)) {
                postRequestNotifications |= RequestNotification.AuthorizeRequest;
            }

            // ResolveRequestCache
            if(HasEventSubscription(EventResolveRequestCache)) {
                requestNotifications |= RequestNotification.ResolveRequestCache;
            }
            if(HasEventSubscription(EventPostResolveRequestCache)) {
                postRequestNotifications |= RequestNotification.ResolveRequestCache;
            }

            // MapRequestHandler
            if(HasEventSubscription(EventMapRequestHandler)) {
                requestNotifications |= RequestNotification.MapRequestHandler;
            }
            if(HasEventSubscription(EventPostMapRequestHandler)) {
                postRequestNotifications |= RequestNotification.MapRequestHandler;
            }

            // AcquireRequestState
            if(HasEventSubscription(EventAcquireRequestState)) {
                requestNotifications |= RequestNotification.AcquireRequestState;
            }
            if(HasEventSubscription(EventPostAcquireRequestState)) {
                postRequestNotifications |= RequestNotification.AcquireRequestState;
            }

            // PreExecuteRequestHandler
            if(HasEventSubscription(EventPreRequestHandlerExecute)) {
                requestNotifications |= RequestNotification.PreExecuteRequestHandler;
            }

            // PostRequestHandlerExecute
            if (HasEventSubscription(EventPostRequestHandlerExecute)) {
                postRequestNotifications |= RequestNotification.ExecuteRequestHandler;
            }

            // ReleaseRequestState
            if(HasEventSubscription(EventReleaseRequestState)) {
                requestNotifications |= RequestNotification.ReleaseRequestState;
            }
            if(HasEventSubscription(EventPostReleaseRequestState)) {
                postRequestNotifications |= RequestNotification.ReleaseRequestState;
            }

            // UpdateRequestCache
            if(HasEventSubscription(EventUpdateRequestCache)) {
                requestNotifications |= RequestNotification.UpdateRequestCache;
            }
            if(HasEventSubscription(EventPostUpdateRequestCache)) {
                postRequestNotifications |= RequestNotification.UpdateRequestCache;
            }

            // LogRequest
            if(HasEventSubscription(EventLogRequest)) {
                requestNotifications |= RequestNotification.LogRequest;
            }
            if(HasEventSubscription(EventPostLogRequest)) {
                postRequestNotifications |= RequestNotification.LogRequest;
            }

            // EndRequest
            if(HasEventSubscription(EventEndRequest)) {
                requestNotifications |= RequestNotification.EndRequest;
            }

            // PreSendRequestHeaders
            if(HasEventSubscription(EventPreSendRequestHeaders)) {
                requestNotifications |= RequestNotification.SendResponse;
            }

            // PreSendRequestContent
            if(HasEventSubscription(EventPreSendRequestContent)) {
                requestNotifications |= RequestNotification.SendResponse;
            }
        }
        private void RegisterIntegratedEvent(IntPtr appContext,
                                             string moduleName,
                                             RequestNotification requestNotifications,
                                             RequestNotification postRequestNotifications,
                                             string moduleType,
                                             string modulePrecondition,
                                             bool useHighPriority) {

            // lookup the modules event index, if it already exists
            // use it, otherwise, bump the global count
            // the module is used for event dispatch

            int moduleIndex;
            if (_moduleIndexMap.ContainsKey(moduleName)) {
                moduleIndex = (int) _moduleIndexMap[moduleName];
            }
            else {
                moduleIndex = _moduleIndexMap.Count;
                _moduleIndexMap[moduleName] = moduleIndex;
            }

#if DBG
            Debug.Assert(moduleIndex >= 0, "moduleIndex >= 0");
            Debug.Trace("PipelineRuntime", "RegisterIntegratedEvent:"
                        + " module=" + moduleName
                        + ", index=" + moduleIndex.ToString(CultureInfo.InvariantCulture)
                        + ", rq_notify=" + requestNotifications
                        + ", post_rq_notify=" + postRequestNotifications
                        + ", preconditon=" + modulePrecondition + "\r\n");
#endif

            int result = UnsafeIISMethods.MgdRegisterEventSubscription(appContext,
                                                                       moduleName,
                                                                       requestNotifications,
                                                                       postRequestNotifications,
                                                                       moduleType,
                                                                       modulePrecondition,
                                                                       new IntPtr(moduleIndex),
                                                                       useHighPriority);

            if(result < 0) {
                throw new HttpException(SR.GetString(SR.Failed_Pipeline_Subscription, moduleName));
            }
        }
        internal HttpApplication.IExecutionStep GetNextEvent(RequestNotification notification, bool isPostEvent, int eventIndex) {
            List<HttpApplication.IExecutionStep> stepArray = GetStepArray(notification, isPostEvent);

            Debug.Assert(eventIndex >= 0, "eventIndex >= 0");
            Debug.Assert(eventIndex < stepArray.Count, "eventIndex < stepArray.Count");

            return stepArray[eventIndex];
        }
		public void SetCurrentNotification(RequestNotification val)
		{
		}
 internal void DisableNotifications(RequestNotification notifications, RequestNotification postNotifications)
 {
     IIS7WorkerRequest request = this._wr as IIS7WorkerRequest;
     if (request != null)
     {
         request.DisableNotifications(notifications, postNotifications);
     }
 }
示例#32
0
 public IntegratedPipelineMiddleware(OwinMiddleware next, RequestNotification expectedStageName, int middlewareId)
     : base(next)
 {
     this.expectedStageName = expectedStageName;
     this.middlewareId      = middlewareId;
 }
示例#33
0
        /// <summary>
        /// Initializes a new instance of the <see cref="FakeHttpContext"/> class.
        /// </summary>
        /// <param name="request">The request.</param>
        /// <param name="response">The response.</param>
        /// <param name="session">The session.</param>
        public FakeHttpContext(FakeHttpRequest request, FakeHttpResponse response, FakeHttpSessionState session)
        {
            if (request == null)
            {
                throw new ArgumentNullException(nameof(request));
            }

            if (response == null)
            {
                throw new ArgumentNullException(nameof(response));
            }

            if (session == null)
            {
                throw new ArgumentNullException(nameof(session));
            }

            this.request = request;
            this.response = response;
            this.session = session;

            this.request.Context = this;
            this.response.Context = this;

            this.applicationState = new FakeHttpApplicationState();
            this.currentNotification = RequestNotification.BeginRequest;
            this.errors = new List<Exception>();
            this.handlerStack = new Stack<IHttpHandler>();
            this.items = new Hashtable();
            this.pageInstrumentation = new PageInstrumentationService();
            this.server = new FakeHttpServerUtility(this);
            this.timestampUtc = DateTime.UtcNow;

            this.ThreadAbortOnTimeout = true;
        }
 internal void RemoveSyncEventHookup(object key, Delegate handler, RequestNotification notification) {
     RemoveSyncEventHookup(key, handler, notification, false);
 }
        internal void AddEvent(RequestNotification notification, bool isPostEvent, HttpApplication.IExecutionStep step) {
            int index = EventToIndex(notification);
#if DBG            
            Debug.Trace("PipelineRuntime", "Adding event: " + DebugModuleName + " " + notification.ToString() + " " +
                        isPostEvent.ToString() + "@ index " + index.ToString(CultureInfo.InvariantCulture) + "\r\n");
#endif            

            Debug.Assert(index != -1, "index != -1");

            List<HttpApplication.IExecutionStep>[] steps = null;
            
            if (isPostEvent) {
                if (null == _modulePostSteps) {
                    _modulePostSteps = new List<HttpApplication.IExecutionStep>[ 32 ];            
                }
                steps = _modulePostSteps;
            }
            else {
                if (null == _moduleSteps) {
                    _moduleSteps = new List<HttpApplication.IExecutionStep>[ 32 ];
                }

                steps = _moduleSteps;
            }

            Debug.Assert(steps != null, "steps != null");
            
            // retrieve the steps for this event (typically none at this point)
            // allocate a new container as necessary and add this step
            // in the event that a single module has registered more than once
            // for a given event, we'll have multiple steps here
            List<HttpApplication.IExecutionStep> stepArray = steps[index];                
            if (null == stepArray) {
                // first touch, instantiate and save it
                stepArray = new List<HttpApplication.IExecutionStep>();
                steps[index] = stepArray;
            }

            stepArray.Add(step);
       }
        // we have tried various techniques here for converting a request notification
        // into an index but a simple switch statement has so far performed the best
        // basically, the problem is converting a single on bit to its position
        // so 0x00000001 == 0, 0x00000002 == 1, etc.
        // Managed code doesn't support all the request flags so we only translate
        // the ones we deal with to keep the switch table as simple as possible
        private static int EventToIndex(RequestNotification notification) {
            int index = -1;

            switch (notification) {
                    // 0x00000001
                case RequestNotification.BeginRequest:
                    return 0;

                    // 0x00000002
                case RequestNotification.AuthenticateRequest:
                    return 1;

                    // 0x00000004
                case RequestNotification.AuthorizeRequest:
                    return 2;

                    // 0x00000008
                case RequestNotification.ResolveRequestCache:
                    return 3;

                    // 0x00000010
                case RequestNotification.MapRequestHandler:
                    return 4;

                    // 0x00000020
                case RequestNotification.AcquireRequestState:
                    return 5;

                    // 0x00000040
                case RequestNotification.PreExecuteRequestHandler:
                    return 6;

                    // 0x00000080
                case RequestNotification.ExecuteRequestHandler:
                    return 7;

                    // 0x00000100
                case RequestNotification.ReleaseRequestState:
                    return 8;

                    // 0x00000200
                case RequestNotification.UpdateRequestCache:
                    return 9;

                    // 0x00000400
                case RequestNotification.LogRequest:
                    return 10;

                    // 0x00000800
                case RequestNotification.EndRequest:
                    return 11;

                    // 0x20000000
                case RequestNotification.SendResponse :
                    return 12;

                default:
                    Debug.Assert(index != -1, "invalid request notification--need to update switch table?");
                    return index;
            }
        }
 internal void DisableNotifications(
         RequestNotification notifications,
         RequestNotification postNotifications) {
     IIS.MgdDisableNotifications(_context, notifications, postNotifications);
 }
 private void ProcessEventSubscriptions(out RequestNotification requestNotifications, out RequestNotification postRequestNotifications)
 {
     requestNotifications     = 0;
     postRequestNotifications = 0;
     if (HasEventSubscription(EventBeginRequest))
     {
         requestNotifications |= RequestNotification.BeginRequest;
     }
     if (HasEventSubscription(EventAuthenticateRequest))
     {
         requestNotifications |= RequestNotification.AuthenticateRequest;
     }
     if (HasEventSubscription(EventPostAuthenticateRequest))
     {
         postRequestNotifications |= RequestNotification.AuthenticateRequest;
     }
     if (HasEventSubscription(EventAuthorizeRequest))
     {
         requestNotifications |= RequestNotification.AuthorizeRequest;
     }
     if (HasEventSubscription(EventPostAuthorizeRequest))
     {
         postRequestNotifications |= RequestNotification.AuthorizeRequest;
     }
     if (HasEventSubscription(EventResolveRequestCache))
     {
         requestNotifications |= RequestNotification.ResolveRequestCache;
     }
     if (HasEventSubscription(EventPostResolveRequestCache))
     {
         postRequestNotifications |= RequestNotification.ResolveRequestCache;
     }
     if (HasEventSubscription(EventMapRequestHandler))
     {
         requestNotifications |= RequestNotification.MapRequestHandler;
     }
     if (HasEventSubscription(EventPostMapRequestHandler))
     {
         postRequestNotifications |= RequestNotification.MapRequestHandler;
     }
     if (HasEventSubscription(EventAcquireRequestState))
     {
         requestNotifications |= RequestNotification.AcquireRequestState;
     }
     if (HasEventSubscription(EventPostAcquireRequestState))
     {
         postRequestNotifications |= RequestNotification.AcquireRequestState;
     }
     if (HasEventSubscription(EventPreRequestHandlerExecute))
     {
         requestNotifications |= RequestNotification.PreExecuteRequestHandler;
     }
     if (HasEventSubscription(EventPostRequestHandlerExecute))
     {
         postRequestNotifications |= RequestNotification.ExecuteRequestHandler;
     }
     if (HasEventSubscription(EventReleaseRequestState))
     {
         requestNotifications |= RequestNotification.ReleaseRequestState;
     }
     if (HasEventSubscription(EventPostReleaseRequestState))
     {
         postRequestNotifications |= RequestNotification.ReleaseRequestState;
     }
     if (HasEventSubscription(EventUpdateRequestCache))
     {
         requestNotifications |= RequestNotification.UpdateRequestCache;
     }
     if (HasEventSubscription(EventPostUpdateRequestCache))
     {
         postRequestNotifications |= RequestNotification.UpdateRequestCache;
     }
     if (HasEventSubscription(EventLogRequest))
     {
         requestNotifications |= RequestNotification.LogRequest;
     }
     if (HasEventSubscription(EventPostLogRequest))
     {
         postRequestNotifications |= RequestNotification.LogRequest;
     }
     if (HasEventSubscription(EventEndRequest))
     {
         requestNotifications |= RequestNotification.EndRequest;
     }
     if (HasEventSubscription(EventPreSendRequestHeaders))
     {
         requestNotifications |= RequestNotification.SendResponse;
     }
     if (HasEventSubscription(EventPreSendRequestContent))
     {
         requestNotifications |= RequestNotification.SendResponse;
     }
 }
 internal void DisableNotifications(RequestNotification notifications, RequestNotification postNotifications)
 {
     UnsafeIISMethods.MgdDisableNotifications(this._context, notifications, postNotifications);
 }
 public IntegratedPipelineMiddleware(OwinMiddleware next, RequestNotification expectedStageName, int middlewareId)
     : base(next)
 {
     this.expectedStageName = expectedStageName;
     this.middlewareId = middlewareId;
 }
示例#41
0
 internal void DisableNotifications(RequestNotification notifications, RequestNotification postNotifications);
 internal int GetEventCount(RequestNotification notification, bool isPostEvent)
 {
     List<HttpApplication.IExecutionStep> stepArray = this.GetStepArray(notification, isPostEvent);
     if (stepArray == null)
     {
         return 0;
     }
     return stepArray.Count;
 }
示例#43
0
 internal static extern void MgdDisableNotifications(
     IntPtr pRequestContext,
     [MarshalAs(UnmanagedType.U4)]
     RequestNotification notifications,
     [MarshalAs(UnmanagedType.U4)]
     RequestNotification postNotifications);
 internal HttpApplication.IExecutionStep GetNextEvent(RequestNotification notification, bool isPostEvent, int eventIndex)
 {
     return this.GetStepArray(notification, isPostEvent)[eventIndex];
 }
示例#45
0
 internal void DisableNotifications(RequestNotification notifications, RequestNotification postNotifications) {
     IIS7WorkerRequest wr = _wr as IIS7WorkerRequest;
     if (null != wr) {
         wr.DisableNotifications(notifications, postNotifications);
     }
 }
 private List<HttpApplication.IExecutionStep> GetStepArray(RequestNotification notification, bool isPostEvent)
 {
     List<HttpApplication.IExecutionStep>[] listArray = this._moduleSteps;
     if (isPostEvent)
     {
         listArray = this._modulePostSteps;
     }
     int index = EventToIndex(notification);
     return listArray[index];
 }
 internal void RemoveEvent(RequestNotification notification, bool isPostEvent, Delegate handler)
 {
     List<HttpApplication.IExecutionStep>[] listArray = this._moduleSteps;
     if (isPostEvent)
     {
         listArray = this._modulePostSteps;
     }
     if (listArray != null)
     {
         int index = EventToIndex(notification);
         List<HttpApplication.IExecutionStep> list = listArray[index];
         if (list != null)
         {
             int num2 = -1;
             for (int i = 0; i < list.Count; i++)
             {
                 HttpApplication.SyncEventExecutionStep step = list[i] as HttpApplication.SyncEventExecutionStep;
                 if ((step != null) && (step.Handler == ((EventHandler) handler)))
                 {
                     num2 = i;
                     break;
                 }
             }
             if (num2 != -1)
             {
                 list.RemoveAt(num2);
             }
         }
     }
 }
        internal void RemoveEvent(RequestNotification notification, bool isPostEvent, Delegate handler) {

            // if module instances unregister multiple times, this can fail on subsequent attempts
            // so don't use GetStepArray which does extra checked verification
            List<HttpApplication.IExecutionStep>[] steps = _moduleSteps;
            
            if (isPostEvent) { 
                steps = _modulePostSteps;
            }

            if (steps == null) {
                return;
            }
            
            int index = EventToIndex(notification);
            List<HttpApplication.IExecutionStep> stepArray = steps[index];

            if (null == stepArray) {
                return;
            }
                                
            
            int toRemove = -1;
            
            HttpApplication.SyncEventExecutionStep syncStep;
            for (int i = 0; i < stepArray.Count; i++ ) {

                // we don't support removing async event handlers
                // but the event syntax forces us to handle [....] events
                syncStep = stepArray[i] as HttpApplication.SyncEventExecutionStep;
                if (null != syncStep) {
                    if (syncStep.Handler == (EventHandler)handler) {
                        toRemove = i;
                        break;
                    }
                }
            }

            if (toRemove != -1) {
                stepArray.RemoveAt(toRemove);
            }
        }
        private void HookupEventHandlersForApplicationAndModules(MethodInfo[] handlers) {
            _currentModuleCollectionKey = HttpApplicationFactory.applicationFileName;

            if(null == _pipelineEventMasks) {
                Dictionary<string, RequestNotification> dict = new Dictionary<string, RequestNotification>();
                BuildEventMaskDictionary(dict);
                if(null == _pipelineEventMasks) {
                    _pipelineEventMasks = dict;
                }
            }


            for (int i = 0; i < handlers.Length; i++) {
                MethodInfo appMethod = handlers[i];
                String appMethodName = appMethod.Name;
                int namePosIndex = appMethodName.IndexOf('_');
                String targetName = appMethodName.Substring(0, namePosIndex);

                // Find target for method
                Object target = null;

                if (StringUtil.EqualsIgnoreCase(targetName, "Application"))
                    target = this;
                else if (_moduleCollection != null)
                    target = _moduleCollection[targetName];

                if (target == null)
                    continue;

                // Find event on the module type
                Type targetType = target.GetType();
                EventDescriptorCollection events = TypeDescriptor.GetEvents(targetType);
                string eventName = appMethodName.Substring(namePosIndex+1);

                EventDescriptor foundEvent = events.Find(eventName, true);
                if (foundEvent == null
                    && StringUtil.EqualsIgnoreCase(eventName.Substring(0, 2), "on")) {

                    eventName = eventName.Substring(2);
                    foundEvent = events.Find(eventName, true);
                }

                MethodInfo addMethod = null;
                if (foundEvent != null) {
                    EventInfo reflectionEvent = targetType.GetEvent(foundEvent.Name);
                    Debug.Assert(reflectionEvent != null);
                    if (reflectionEvent != null) {
                        addMethod = reflectionEvent.GetAddMethod();
                    }
                }

                if (addMethod == null)
                    continue;

                ParameterInfo[] addMethodParams = addMethod.GetParameters();

                if (addMethodParams.Length != 1)
                    continue;

                // Create the delegate from app method to pass to AddXXX(handler) method

                Delegate handlerDelegate = null;

                ParameterInfo[] appMethodParams = appMethod.GetParameters();

                if (appMethodParams.Length == 0) {
                    // If the app method doesn't have arguments --
                    // -- hookup via intermidiate handler

                    // only can do it for EventHandler, not strongly typed
                    if (addMethodParams[0].ParameterType != typeof(System.EventHandler))
                        continue;

                    ArglessEventHandlerProxy proxy = new ArglessEventHandlerProxy(this, appMethod);
                    handlerDelegate = proxy.Handler;
                }
                else {
                    // Hookup directly to the app methods hoping all types match

                    try {
                        handlerDelegate = Delegate.CreateDelegate(addMethodParams[0].ParameterType, this, appMethodName);
                    }
                    catch {
                        // some type mismatch
                        continue;
                    }
                }

                // Call the AddXXX() to hook up the delegate

                try {
                    addMethod.Invoke(target, new Object[1]{handlerDelegate});
                }
                catch {
                    if (HttpRuntime.UseIntegratedPipeline) {
                        throw;
                    }
                }

                if (eventName != null) {
                    if (_pipelineEventMasks.ContainsKey(eventName)) {
                        if (!StringUtil.StringStartsWith(eventName, "Post")) {
                            _appRequestNotifications |= _pipelineEventMasks[eventName];
                        }
                        else {
                            _appPostNotifications |= _pipelineEventMasks[eventName];
                        }
                    }
                }
            }
        }
        private static int EventToIndex(RequestNotification notification)
        {
            int num = -1;
            RequestNotification notification2 = notification;
            if (notification2 <= RequestNotification.PreExecuteRequestHandler)
            {
                if (notification2 <= RequestNotification.ResolveRequestCache)
                {
                    switch (notification2)
                    {
                        case RequestNotification.BeginRequest:
                            return 0;

                        case RequestNotification.AuthenticateRequest:
                            return 1;

                        case (RequestNotification.AuthenticateRequest | RequestNotification.BeginRequest):
                            return num;

                        case RequestNotification.AuthorizeRequest:
                            return 2;

                        case RequestNotification.ResolveRequestCache:
                            return 3;
                    }
                    return num;
                }
                switch (notification2)
                {
                    case RequestNotification.MapRequestHandler:
                        return 4;

                    case RequestNotification.AcquireRequestState:
                        return 5;

                    case RequestNotification.PreExecuteRequestHandler:
                        return 6;
                }
                return num;
            }
            if (notification2 <= RequestNotification.UpdateRequestCache)
            {
                switch (notification2)
                {
                    case RequestNotification.ExecuteRequestHandler:
                        return 7;

                    case RequestNotification.ReleaseRequestState:
                        return 8;

                    case RequestNotification.UpdateRequestCache:
                        return 9;
                }
                return num;
            }
            switch (notification2)
            {
                case RequestNotification.LogRequest:
                    return 10;

                case RequestNotification.EndRequest:
                    return 11;

                case RequestNotification.SendResponse:
                    return 12;
            }
            return num;
        }
        private void RegisterEventSubscriptionsWithIIS(IntPtr appContext, HttpContext context, MethodInfo[] handlers) {
            RequestNotification requestNotifications;
            RequestNotification postRequestNotifications;

            // register an implicit filter module
            RegisterIntegratedEvent(appContext,
                                    IMPLICIT_FILTER_MODULE,
                                    RequestNotification.UpdateRequestCache| RequestNotification.LogRequest  /*requestNotifications*/,
                                    0 /*postRequestNotifications*/,
                                    String.Empty /*type*/,
                                    String.Empty /*precondition*/,
                                    true /*useHighPriority*/);

            // integrated pipeline will always use serverModules instead of <httpModules>
            _moduleCollection = GetModuleCollection(appContext);

            if (handlers != null) {
                HookupEventHandlersForApplicationAndModules(handlers);
            }

            // 1643363: Breaking Change: ASP.Net v2.0: Application_OnStart is called after Module.Init (Integarted mode)
            HttpApplicationFactory.EnsureAppStartCalledForIntegratedMode(context, this);

            // Call Init on HttpApplication derived class ("global.asax")
            // and process event subscriptions before processing other modules.
            // Doing this now prevents clearing any events that may
            // have been added to event handlers during instantiation of this instance.
            // NOTE:  If "global.asax" has a constructor which hooks up event handlers,
            // then they were added to the event handler lists but have not been registered with IIS yet,
            // so we MUST call ProcessEventSubscriptions on it first, before the other modules.
            _currentModuleCollectionKey = HttpApplicationFactory.applicationFileName;

            try {
                _hideRequestResponse = true;
                context.HideRequestResponse = true;
                _context = context;
                Init();
            }
            catch (Exception e) {
                RecordError(e);
                Exception error = context.Error;
                if (error != null) {
                    throw error;
                }
            }
            finally {
                _context = null;
                context.HideRequestResponse = false;
                _hideRequestResponse = false;
            }

            ProcessEventSubscriptions(out requestNotifications, out postRequestNotifications);

            // Save the notification subscriptions so we can register them with IIS later, after
            // we call HookupEventHandlersForApplicationAndModules and process global.asax event handlers.
            _appRequestNotifications |= requestNotifications;
            _appPostNotifications    |= postRequestNotifications;

            for (int i = 0; i < _moduleCollection.Count; i++) {
                _currentModuleCollectionKey = _moduleCollection.GetKey(i);
                IHttpModule httpModule = _moduleCollection.Get(i);
                ModuleConfigurationInfo moduleInfo = _moduleConfigInfo[i];

#if DBG
                Debug.Trace("PipelineRuntime", "RegisterEventSubscriptionsWithIIS: name=" + CurrentModuleCollectionKey
                            + ", type=" + httpModule.GetType().FullName + "\n");

                // make sure collections are in [....]
                Debug.Assert(moduleInfo.Name == _currentModuleCollectionKey, "moduleInfo.Name == _currentModuleCollectionKey");
#endif

                httpModule.Init(this);

                ProcessEventSubscriptions(out requestNotifications, out postRequestNotifications);

                // are any events wired up?
                if (requestNotifications != 0 || postRequestNotifications != 0) {

                    RegisterIntegratedEvent(appContext,
                                            moduleInfo.Name,
                                            requestNotifications,
                                            postRequestNotifications,
                                            moduleInfo.Type,
                                            moduleInfo.Precondition,
                                            false /*useHighPriority*/);
                }
            }

            // WOS 1728067: RewritePath does not remap the handler when rewriting from a non-ASP.NET request
            // register a default implicit handler
            RegisterIntegratedEvent(appContext,
                                    IMPLICIT_HANDLER,
                                    RequestNotification.ExecuteRequestHandler | RequestNotification.MapRequestHandler /*requestNotifications*/,
                                    RequestNotification.EndRequest /*postRequestNotifications*/,
                                    String.Empty /*type*/,
                                    String.Empty /*precondition*/,
                                    false /*useHighPriority*/);
        }
示例#52
0
            internal void AddHandler(object eventId, BeginEventHandler beginHandler, EndEventHandler endHandler, object state, RequestNotification requestNotification, bool isPost, NetHttpApplication app)
            {
                if (_table == null)
                {
                    _table = new Hashtable();
                }
                var handler = (AsyncAppEventHandler)_table[eventId];

                if (handler == null)
                {
                    handler         = new AsyncAppEventHandler();
                    _table[eventId] = handler;
                }
                handler.Add(beginHandler, endHandler, state);
                //if (HttpRuntime.UseIntegratedPipeline)
                //{
                //    var step = new AsyncEventExecutionStep(app, beginHandler, endHandler, state);
                //    app.AddEventMapping(app.CurrentModuleCollectionKey, requestNotification, isPost, step);
                //}
            }
        private void AddEventMapping(string moduleName,
                                      RequestNotification requestNotification,
                                      bool isPostNotification,
                                      IExecutionStep step) {

            ThrowIfEventBindingDisallowed();

            // Add events to the IExecutionStep containers only if
            // InitSpecial has completed and InitInternal has not completed.
            if (!IsContainerInitalizationAllowed) {
                return;
            }

            Debug.Assert(!String.IsNullOrEmpty(moduleName), "!String.IsNullOrEmpty(moduleName)");
            Debug.Trace("PipelineRuntime", "AddEventMapping: for " + moduleName +
                        " for " + requestNotification + "\r\n" );


            PipelineModuleStepContainer container = GetModuleContainer(moduleName);
            //WOS 1985878: HttpModule unsubscribing an event handler causes AV in Integrated Mode
            if (container != null) {
#if DBG
                container.DebugModuleName = moduleName;
#endif
                container.AddEvent(requestNotification, isPostNotification, step);
            }
        }
示例#54
0
 public void onRequest(object sender, RequestNotification req)
 {
 }
        private void AddSyncEventHookup(object key, Delegate handler, RequestNotification notification, bool isPostNotification) {
            ThrowIfEventBindingDisallowed();

            // add the event to the delegate invocation list
            // this keeps non-pipeline ASP.NET hosts working
            Events.AddHandler(key, handler);

            // For integrated pipeline mode, add events to the IExecutionStep containers only if
            // InitSpecial has completed and InitInternal has not completed.
            if (IsContainerInitalizationAllowed) {
                // lookup the module index and add this notification
                PipelineModuleStepContainer container = GetModuleContainer(CurrentModuleCollectionKey);
                //WOS 1985878: HttpModule unsubscribing an event handler causes AV in Integrated Mode
                if (container != null) {
#if DBG
                    container.DebugModuleName = CurrentModuleCollectionKey;
#endif
                    SyncEventExecutionStep step = new SyncEventExecutionStep(this, (EventHandler)handler);
                    container.AddEvent(notification, isPostNotification, step);
                }
            }
        }
 internal void RemoveSyncEventHookup(object key, Delegate handler, RequestNotification notification)
 {
     RemoveSyncEventHookup(key, handler, notification, false);
 }
        internal void RemoveSyncEventHookup(object key, Delegate handler, RequestNotification notification, bool isPostNotification) {
            ThrowIfEventBindingDisallowed();

            Events.RemoveHandler(key, handler);

            if (IsContainerInitalizationAllowed) {
                PipelineModuleStepContainer container = GetModuleContainer(CurrentModuleCollectionKey);
                //WOS 1985878: HttpModule unsubscribing an event handler causes AV in Integrated Mode
                if (container != null) {
                    container.RemoveEvent(notification, isPostNotification, handler);
                }
            }
        }
        // we have tried various techniques here for converting a request notification
        // into an index but a simple switch statement has so far performed the best
        // basically, the problem is converting a single on bit to its position
        // so 0x00000001 == 0, 0x00000002 == 1, etc.
        // Managed code doesn't support all the request flags so we only translate
        // the ones we deal with to keep the switch table as simple as possible
        private static int EventToIndex(RequestNotification notification)
        {
            int index = -1;

            switch (notification)
            {
            // 0x00000001
            case RequestNotification.BeginRequest:
                return(0);

            // 0x00000002
            case RequestNotification.AuthenticateRequest:
                return(1);

            // 0x00000004
            case RequestNotification.AuthorizeRequest:
                return(2);

            // 0x00000008
            case RequestNotification.ResolveRequestCache:
                return(3);

            // 0x00000010
            case RequestNotification.MapRequestHandler:
                return(4);

            // 0x00000020
            case RequestNotification.AcquireRequestState:
                return(5);

            // 0x00000040
            case RequestNotification.PreExecuteRequestHandler:
                return(6);

            // 0x00000080
            case RequestNotification.ExecuteRequestHandler:
                return(7);

            // 0x00000100
            case RequestNotification.ReleaseRequestState:
                return(8);

            // 0x00000200
            case RequestNotification.UpdateRequestCache:
                return(9);

            // 0x00000400
            case RequestNotification.LogRequest:
                return(10);

            // 0x00000800
            case RequestNotification.EndRequest:
                return(11);

            // 0x20000000
            case RequestNotification.SendResponse:
                return(12);

            default:
                Debug.Assert(index != -1, "invalid request notification--need to update switch table?");
                return(index);
            }
        }
示例#59
0
 /// <summary>
 /// Sets a <see cref="System.Web.RequestNotification" /> value that indicates 
 /// the <see cref="System.Web.HttpApplication" /> event that is currently processing.
 /// </summary>
 /// <param name="currentNotification">The current notification.</param>
 public void SetCurrentNotification(RequestNotification currentNotification)
 {
     this.currentNotification = currentNotification;
 }
 private void AddSyncEventHookup(object key, Delegate handler, RequestNotification notification, bool isPostNotification)
 {
     this.ThrowIfEventBindingDisallowed();
     this.Events.AddHandler(key, handler);
     if (this.IsContainerInitalizationAllowed)
     {
         PipelineModuleStepContainer moduleContainer = this.GetModuleContainer(this.CurrentModuleCollectionKey);
         if (moduleContainer != null)
         {
             SyncEventExecutionStep step = new SyncEventExecutionStep(this, (EventHandler) handler);
             moduleContainer.AddEvent(notification, isPostNotification, step);
         }
     }
 }