Esempio n. 1
0
        public static void ProcessedRequestHandler(object source, DataServiceProcessingPipelineEventArgs args)
        {
            TraceHelper.Current.DebugMessage("QuotaSystem.ProcessedRequestHandler entered");
            if (args != null)
            {
                args.OperationContext.Trace();
            }
            UserContext userContext = new UserContext(CurrentRequestHelper.Identity, CurrentRequestHelper.Certificate);

            if (DataServiceController.Current.IsRequestProcessingStarted(userContext))
            {
                try
                {
                    DataServiceController.Current.SetRequestProcessingState(userContext, false);
                    UserDataCache.UserDataEnvelope userDataEnvelope = DataServiceController.Current.UserDataCache.Get(userContext);
                    using (userDataEnvelope)
                    {
                        userDataEnvelope.Data.Usage.RequestProcessed();
                    }
                    TraceHelper.Current.RequestProcessingEnd();
                }
                finally
                {
                    DataServiceController.Current.UserDataCache.TryUnlockKey(userContext);
                    TraceHelper.Current.DebugMessage("QuotaSystem.ProcessedRequestHandler exited");
                }
                return;
            }
            else
            {
                TraceHelper.Current.DebugMessage("QuotaSystem.ProcessedRequestHandler IsRequestProcessingStarted returned false");
                return;
            }
        }
Esempio n. 2
0
        public static void ProcessingRequestHandler(object source, DataServiceProcessingPipelineEventArgs args)
        {
            UserData userDatum = null;

            TraceHelper.Current.DebugMessage("QuotaSystem.ProcessingRequestHandler entered");
            if (args != null && args.OperationContext != null)
            {
                TraceHelper.CorrelateWithClientRequestId(args.OperationContext);
            }
            UserContext userContext = new UserContext(CurrentRequestHelper.Identity, CurrentRequestHelper.Certificate);

            if (!DataServiceController.Current.IsRequestProcessingStarted(userContext))
            {
                UserDataCache.UserDataEnvelope userDataEnvelope = DataServiceController.Current.UserDataCache.Get(userContext);
                using (userDataEnvelope)
                {
                    UserQuota userQuota = DataServiceController.Current.GetUserQuota(userContext);
                    if (args != null)
                    {
                        Guid activityId = EtwActivity.GetActivityId();
                        args.OperationContext.ResponseHeaders.Add("request-id", activityId.ToString());
                    }
                    if (userDataEnvelope.Data.Usage.QuotaCheckAndUpdate(userContext, userQuota))
                    {
                        DataServiceController.Current.UserDataCache.TryLockKey(userContext, out userDatum);
                    }
                    else
                    {
                        throw new DataServiceException(0x193, ExceptionHelpers.GetDataServiceExceptionMessage(HttpStatusCode.Forbidden, Resources.UserQuotaExceeded, new object[0]));
                    }
                }
                DataServiceController.Current.SetRequestProcessingState(userContext, true);
                TraceHelper.Current.RequestProcessingStart();
                DataServiceController.Current.UserDataCache.Trace();
                TraceHelper.Current.DebugMessage("QuotaSystem.ProcessingRequestHandler exited");
                return;
            }
            else
            {
                TraceHelper.Current.DebugMessage("QuotaSystem.ProcessingRequestHandler IsRequestProcessingStarted returned true");
                return;
            }
        }