Beispiel #1
0
        /// <summary>
        ///     Executes the filter action asynchronously.
        /// </summary>
        /// <param name="actionContext">The action context.</param>
        /// <param name="cancellationToken">The cancellation token assigned for this task.</param>
        /// <param name="continuation">The delegate function to continue after the action method is invoked.</param>
        /// <returns>
        ///     The newly created task for this operation.
        /// </returns>
        public Task <HttpResponseMessage> ExecuteActionFilterAsync(HttpActionContext actionContext, CancellationToken cancellationToken, Func <Task <HttpResponseMessage> > continuation)
        {
            // Get web context
            string entryPoint = "Failed";

            try
            {
                entryPoint = actionContext.ControllerContext.Controller.GetType( ).Name + "." + actionContext.ActionDescriptor.ActionName;
            }
            catch { }

            using (DatabaseContextInfo.SetContextInfo($"WebApi - {actionContext.ControllerContext.ControllerDescriptor.ControllerName}.{actionContext.ActionDescriptor.ActionName}"))
                using (EntryPointContext.SetEntryPoint(entryPoint))
                {
                    ProcessMonitorWriter.Instance.Write(entryPoint);

                    RequestContext requestContext = RequestContext.GetContext( );
                    if (requestContext != null && requestContext.IsValid)
                    {
                        // Attach timezone
                        string tz = HttpContext.Current.Request.Headers.Get("Tz");
                        if (!string.IsNullOrEmpty(tz))
                        {
                            // Set the timezone in the logical context
                            var contextData = new RequestContextData(requestContext.Identity, requestContext.Tenant, requestContext.Culture, tz);
                            RequestContext.SetContext(contextData);
                        }
                    }

                    // Do the actual API call work
                    return(continuation( ));
                }
        }
        /// <summary>
        /// Entry point to the thread running background workflows. Used by monitoring software.
        /// </summary>
        /// <param name="o">
        /// The <see cref="Action"/> to run. This cannot be null.
        /// </param>
        /// <exception cref="ArgumentException">
        /// <paramref name="o"/> cannot be null and must be an <see cref="Action"/>.
        /// </exception>
        private static void StartThread(object o)
        {
            using (EntryPointContext.SetEntryPoint("WorkflowThread"))
            {
                ProcessMonitorWriter.Instance.Write("WorkflowThread");

                try
                {
                    Action action;

                    action = o as Action;
                    if (action == null)
                    {
                        throw new ArgumentException("Null or not an Action", "o");
                    }

                    using (DeferredChannelMessageContext deferredMsgContext = new DeferredChannelMessageContext())
                        using (DatabaseContext.GetContext())
                        {
                            action();
                        }
                }
                catch (Exception ex)
                {
                    EventLog.Application.WriteError("WorkflowRunContext.StartThread: Unexpected exception thrown: {0}", ex);
                }
            }
        }
Beispiel #3
0
 private void ProcessTask(BackgroundTask task)
 {
     HandleTask(task, handler =>
     {
         using (EntryPointContext.SetEntryPoint("BackgroundTask"))
         {
             ProcessMonitorWriter.Instance.Write("BackgroundTask");
             using (DeferredChannelMessageContext deferredMsgContext = new DeferredChannelMessageContext())
             {
                 var contextData = task.Context;
                 using (CustomContext.SetContext(contextData))
                 {
                     handler.HandleTask(task);
                 }
             }
         }
     });
 }
Beispiel #4
0
        /// <summary>
        ///     Run various queries to pre-fill the entity cache for the current tenant.
        /// </summary>
        public static void TenantWarmup( )
        {
            using (new DeferredChannelMessageContext())
                using (EntryPointContext.SetEntryPoint("Warmup TenantId=" + RequestContext.TenantId))
                    using (Profiler.Measure("BulkPreloader.TenantWarmup TenantId=" + RequestContext.TenantId))
                    {
                        ProcessMonitorWriter.Instance.Write("Warmup TenantId=" + RequestContext.TenantId);

                        _tenantWarmupRunning = true;
                        try
                        {
                            CacheRelationships( );

                            // Fetch all aliases in the tenant
                            EntityIdentificationCache.PreloadAliases( );

                            // Prewarm type hierarchy
                            PerTenantEntityTypeCache.Instance.Prewarm( );

                            // Includes relationships, as they inherit type.
                            const string typePreloaderQuery = "alias, name, isOfType.{id, isMetadata}, inherits.id, {k:defaultEditForm, defaultPickerReport, defaultDisplayReport}.isOfType.id, allowEveryoneRead, isAbstract, relationships.{id, isOfType.id}, reverseRelationships.{id, isOfType.id}, instanceFlags.id";
                            Preload(new EntityRequest("type", typePreloaderQuery, QueryType.Instances, "Preload types"));

                            const string derivedTypePreloaderQuery = "derivedTypes.id";
                            Preload(new EntityRequest("type", derivedTypePreloaderQuery, QueryType.Instances, "Preload types"));

                            // Includes enum definitions
                            const string relationshipPreloaderQuery = "reverseAlias, cardinality.id, fromType.id, toType.id, fromName, toName, securesTo, securesFrom, securesToReadOnly, securesFromReadOnly, flags.id, relationshipInKey.id";
                            Preload(new EntityRequest("relationship", relationshipPreloaderQuery, QueryType.Instances, "Preload relationships"));

                            const string resourceKeyPreloaderQuery = "resourceKeyRelationships.id, keyFields.id";
                            Preload(new EntityRequest("resourceKey", resourceKeyPreloaderQuery, QueryType.ExactInstances, "Preload resourcekeys"));

                            const string fieldTypesPreloaderQuery = "alias, isOfType.id, dbFieldTable, dbType, dbTypeFull, readiNowType, { k:renderingControl, k:defaultRenderingControls }.{ isOfType.id, k:context.isOfType.id }";
                            Preload(new EntityRequest("fieldType", fieldTypesPreloaderQuery, QueryType.ExactInstances, "Preload field types"));

                            const string fieldPreloaderQuery = @"alias, name, isOfType.id, description, isFieldReadOnly, defaultValue, isRequired, isFieldWriteOnly, allowMultiLines,
                    pattern.{isOfType.id, regex, regexDescription},{flags, fieldRepresents}.{ isOfType.id, alias }, 
                    minLength, maxLength, minInt, maxInt, minDecimal, maxDecimal, minDate, maxDate, minTime, maxTime, minDateTime, maxDateTime, decimalPlaces, autoNumberDisplayPattern, isCalculatedField, fieldCalculation";
                            Preload(new EntityRequest("field", fieldPreloaderQuery, QueryType.Instances, "Preload field definitions"));

                            const string tenantSettingsPreloaderQuery = "alias, isOfType.id, finYearStartMonth.isOfType.id";
                            Preload(new EntityRequest("tenantGeneralSettings", tenantSettingsPreloaderQuery, QueryType.ExactInstances, "Preload tenant settings"));

                            const string enumValuesPreloaderQuery = "alias, name, enumOrder, isOfType.instancesOfType.id";
                            Preload(new EntityRequest("enumValue", enumValuesPreloaderQuery, QueryType.Instances, "Preload enum values"));

                            const string accessRulesPreloaderQuery = "alias, isOfType.id, allowAccess.{ isOfType.id, accessRuleReport.isOfType.id, controlAccess.isOfType.id, permissionAccess.isOfType.id, accessRuleEnabled, accessRuleHidden, accessRuleIgnoreForReports }";
                            Preload(new EntityRequest("subject", accessRulesPreloaderQuery, QueryType.Instances, "Preload access rules"));

                            const string userPreloaderQuery = "alias, name, isOfType.id, userHasRole.{id, isOfType.id}";
                            Preload(new EntityRequest("userAccount", userPreloaderQuery, QueryType.Instances, "Preload users"));

                            const string rolesPreloaderQuery = "alias, name, isOfType.id, includesRoles.{id, isOfType.id}, includedByRoles.{id, isOfType.id}, roleMembers.{id, isOfType.id}";
                            Preload(new EntityRequest("role", rolesPreloaderQuery, QueryType.Instances, "Preload roles"));

                            // edit form controls
                            const string controlsTypePreloaderQueryCommon = @"
                    name, alias, isOfType.id, 
                    instancesOfType.{
                        name, 
                        k:requiresContext, k:isHiddenFromFormDesigner, k:designControl, k:control, k:viewControl, 
                        k:context.{alias, isOfType.id}
                    }";

                            const string controlsTypePreloaderQuery = controlsTypePreloaderQueryCommon + @",
                    instancesOfType.{
                        k:wbcHideSuccessConfirmation, 
                        {
                            k:wbcWorkflowToRun, k:wbcResourceInputParameter, 
                            k:wbcDisableControlBasedOnRelationshipControl, k:wbcDisableControlBasedOnResources, 
                            k:reportToRender, k:chartToRender, k:formToRender
                        }.{alias, isOfType.id}
                    }";

                            Preload(new EntityRequest("k:renderControlType", controlsTypePreloaderQuery, QueryType.Instances, "Preload editForm controls"));

                            const string fieldControlsTypePreloaderQuery = controlsTypePreloaderQueryCommon + @",
                    instancesOfType.{ 
                        {k:fieldTypeToRender, k:defaultFieldTypesToRender, k:fieldInstanceToRender}.{alias, isOfType.id},
                        k:textControlWidth, k:textControlHeight
                    }";

                            Preload(new EntityRequest("k:fieldRenderControlType", fieldControlsTypePreloaderQuery, QueryType.Instances, "Preload editForm field controls"));

                            const string relControlsTypePreloaderQuery = controlsTypePreloaderQueryCommon + @",
                    instancesOfType.{ 
                        {k:thumbnailScalingSetting, k:thumbnailSizeSetting}.{alias, id}
                    }";
                            Preload(new EntityRequest("k:relationshipRenderControlType", relControlsTypePreloaderQuery, QueryType.Instances, "Preload editForm rel controls"));
                            Preload(new EntityRequest("k:structureRenderControlType", controlsTypePreloaderQuery, QueryType.Instances, "Preload editForm struct controls"));


                            PrecompileEntityQuery(ReportHelpers.ReportPreloaderQuery, "Precompile report query");
                            PrecompileEntityQuery(ReportHelpers.QueryPreloaderQuery, "Precompile report-query query");
                            PrecompileEntityQuery(ActionServiceHelpers.ReportRequest, "Precompile report actions query");
                            PrecompileEntityQuery(ActionServiceHelpers.ResourceRequest, "Precompile resource actions query");
                            PrecompileEntityQuery(ActionServiceHelpers.ResourceViewerRequest, "Precompile resource viewer actions query");
                            PrecompileEntityQuery(ActionServiceHelpers.WorkflowRequest, "Precompile workflow actions query");

                            PrecompileEntityQuery(CustomEditFormHelper.GetHtmlFormQuery( ), "Precompile form view query");
                            PrecompileEntityQuery(CustomEditFormHelper.GetHtmlFormQuery(true), "Precompile form design query");
                            PrecompileEntityQuery(DefaultLayoutGenerator.FormGenerationPreloaderQuery, "Precompile default form generator query");

                            Factory.ExpressionCompiler.Prewarm( );
                            TimeZoneHelper.Prewarm( );

                            PreloadAccessRuleReports( );

                            _tenantWarmupDone = true;
                        }
                        finally
                        {
                            _tenantWarmupRunning = false;
                        }
                    }
        }