private long GetId(ref long stored, string ns, string alias)
 {
     if (stored == 0)
     {
         // (Unfortunately) presently the fastest way to get an ID.
         EntityAlias ea = new EntityAlias(ns, alias, true);
         stored = EntityIdentificationCache.GetId(ea);
     }
     return(stored);
 }
Example #2
0
        /// <summary>
        ///     Converts the current entity alias to its corresponding entity id.
        /// </summary>
        /// <param name="alias">The alias.</param>
        /// <returns>
        ///     Entity id of the current entity alias.
        /// </returns>
        public static long ToEntityId(EntityAlias alias)
        {
            if (alias == null || alias.Alias == null)
            {
                throw new ArgumentNullException("alias");
            }

            if (alias.Alias.Length == 0)
            {
                throw new ArgumentException(@"alias was empty", "alias");
            }

            return(EntityIdentificationCache.GetId(alias));
        }
Example #3
0
        /// <summary>
        /// Resolves the identifier.
        /// </summary>
        public long ResolveId( )
        {
            if (_id == 0 && !_serializing)
            {
                if (_entity != null)
                {
                    _id = _entity.Id;
                }
                else if (Alias != null)
                {
                    EntityAlias ea = new EntityAlias(Namespace ?? "core", Alias, true);
                    _id = EntityIdentificationCache.GetId(ea);
                }
                else
                {
                    return(0);
                }
            }

            return(_id);
        }
        /// <summary>
        ///     Gets the ID of the type represented by a C# class.
        /// </summary>
        /// <param name="type"></param>
        /// <returns></returns>
        public long GetTypeId(Type type)
        {
            long id;

            if (!_strongTypeIdCache.TryGetValue(type, out id))
            {
                id = -1;

                if (type != typeof(Entity))
                {
                    ModelClassAttribute modelClass = GetModelClassAttribute(type);
                    if (modelClass != null)
                    {
                        id = EntityIdentificationCache.GetId(modelClass.TypeAlias);
                    }
                }

                _strongTypeIdCache[type] = id;
            }
            return(id);
        }
Example #5
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;
                        }
                    }
        }
        /// <summary>
        ///     Determine if one type is equal to or derived from another.
        /// </summary>
        /// <returns>True if the child type is equal to, or derived from, the parent type.</returns>
        public bool IsDerivedFrom(long possibleChildTypeId, string possibleParentTypeAlias)
        {
            long possibleParentTypeId = EntityIdentificationCache.GetId(possibleParentTypeAlias);

            return(IsDerivedFrom(possibleChildTypeId, possibleParentTypeId));
        }