private void ClearSchemaIfCached(IApplicationResponse applicationResponse, HttpActionExecutedContext actionExecutedContext)
        {
            if (applicationResponse == null)
            {
                return;
            }
            var cachedSchemas = RequestUtil.GetValue(actionExecutedContext.Request, "cachedschemas");

            if (cachedSchemas == null)
            {
                return;
            }
            if (applicationResponse is SchemaChoosingDataResponse)
            {
                HandleSchemasToChoose(applicationResponse, cachedSchemas);
            }
            else if (applicationResponse.Schema != null && cachedSchemas.Contains(";" + applicationResponse.Schema.GetApplicationKey() + ";"))
            {
                //to reduce payload SWWEB-1317
                applicationResponse.CachedSchemaId = applicationResponse.Schema.SchemaId;
                var applicationName = applicationResponse.ApplicationName;
                applicationResponse.Schema = new ApplicationSchemaDefinition {
                    //to play safe since it might be a delegation method to the schema
                    ApplicationName = applicationName,
                    SchemaId        = applicationResponse.Schema.SchemaId,
                    Mode            = applicationResponse.Schema.Mode
                };
            }
        }
Beispiel #2
0
        public override void OnActionExecuting(HttpActionContext actionContext)
        {
            var currentModule = RequestUtil.GetValue(actionContext.Request, CurrentModuleKey);
            var currentUSer   = SecurityFacade.CurrentUser();

            if (currentModule != null && currentUSer != null)
            {
                FunctionalRole fr;
                Enum.TryParse(currentModule, true, out fr);
                if (!currentUSer.IsInRole(fr.ToString()))
                {
                    throw new InvalidOperationException(
                              "this user is not allowed for this role. Please contact your administrator");
                }
            }

            var currentMetadataId        = RequestUtil.GetValue(actionContext.Request, CurrentMetadataKey);
            var currentMetadataParameter = RequestUtil.GetValue(actionContext.Request, CurrentMetadataParameterKey);
            var printMode = "true".Equals(RequestUtil.GetValue(actionContext.Request, PrintMode));
            ApplicationLookupContext appCtx = null;

            if (currentMetadataId != null)
            {
                appCtx = new ApplicationLookupContext {
                    MetadataId = currentMetadataId
                };
            }
            ContextLookuper.AddContext(new ContextHolder()
            {
                Module = currentModule, ApplicationLookupContext = appCtx, PrintMode = printMode, MetadataParameters = PropertyUtil.ConvertToDictionary(currentMetadataParameter)
            }, true);
            base.OnActionExecuting(actionContext);
        }
        public override void OnActionExecuted(HttpActionExecutedContext actionExecutedContext)
        {
            base.OnActionExecuted(actionExecutedContext);
            if (actionExecutedContext.Exception != null)
            {
                //if has exception, will be handled by GenericExceptionFilter
                return;
            }

            if (!typeof(IGenericResponseResult).IsAssignableFrom(actionExecutedContext.ActionContext.ActionDescriptor.ReturnType))
            {
                //do nothing case it´s not returning a IGenericResponseResult instance
                return;
            }
            var redirectAttribute = LookupAttribute(actionExecutedContext.ActionContext);
            var controllerName    = actionExecutedContext.ActionContext.ControllerContext.ControllerDescriptor.ControllerName;
            var url           = FindRedirectURL(controllerName, redirectAttribute);
            var objectContent = actionExecutedContext.Response.Content as ObjectContent;

            if (objectContent == null)
            {
                //void method case
                return;
            }
            var value = objectContent.Value as IGenericResponseResult;
            var applicationResponse = objectContent.Value as IApplicationResponse;

            ClearSchemaIfCached(applicationResponse, actionExecutedContext);
            if (value == null)
            {
                return;
            }
            var requestTimeSt = RequestUtil.GetValue(actionExecutedContext.Request, "requesttime");

            if (requestTimeSt != null)
            {
                value.RequestTimeStamp = long.Parse(requestTimeSt);
            }
            if (value.RedirectURL == null)
            {
                value.RedirectURL = url;
            }
            if (value.CrudSubTemplate == null && redirectAttribute != null && redirectAttribute.CrudSubTemplate != null)
            {
                if (!redirectAttribute.CrudSubTemplate.StartsWith("/Content"))
                {
                    redirectAttribute.CrudSubTemplate = "/Content" + redirectAttribute.CrudSubTemplate;
                }
                value.CrudSubTemplate = redirectAttribute.CrudSubTemplate;
            }
            value.TimeStamp = DateTime.Now;

            var actionArguments = LookupArguments(actionExecutedContext.ActionContext);

            if (value is ApplicationDetailResult)
            {
                var detailResult = value as ApplicationDetailResult;
                var fixedTitle   = detailResult.Schema.GetProperty(ApplicationSchemaPropertiesCatalog.WindowPopupHeaderTitle);
                if (fixedTitle != null)
                {
                    value.Title = fixedTitle;
                }
                //to avoid any further evaluation
                return;
            }

            if (actionArguments != null && !String.IsNullOrWhiteSpace(actionArguments.Title))
            {
                value.Title = actionArguments.Title;
            }
            else if (value.Title == null && redirectAttribute != null)
            {
                value.Title = redirectAttribute.Title;
            }
        }