Example #1
0
        public DefinitionBase UnpackDefinition(FieldList source)
        {
            int appID = source[MessageOutFieldID.ApplicationID].AsInteger() ?? 0;
            int defID = source[MessageOutFieldID.DefinitionID].AsInteger() ?? 0;

            DefinitionBase liveEntity = CreateDefinition(source);

            if (liveEntity != null)
            {
                // find cache item ID and cache hint
                CacheItemID?ciid      = null;
                byte        cacheHint = 0;

                byte[] ciidData = source[MessageOutFieldID.CacheItemID].AsByteArray();

                if (ciidData != null)
                {
                    ciid = new CacheItemID(ciidData);

                    cacheHint = source[MessageOutFieldID.CacheHint].AsByte() ?? 0;
                }

                // add to cache (global or local)
                if (ciid.HasValue)
                {
                    Core.Cache.Server.Add(
                        liveEntity, ciid,
                        EntityID.Create(CacheEntityType.Definition, appID, defID),
                        CacheEntityType.Definition, cacheHint, true);
                }
            }

            return(liveEntity);
        }
Example #2
0
        public void UnpackDefinitions(List <FieldList> sources)
        {
            if ((sources != null) && (sources.Count > 0))
            {
                List <CacheDataTemplate> templates = new List <CacheDataTemplate>(sources.Count);

                foreach (FieldList source in sources)
                {
                    int appID = source[MessageOutFieldID.ApplicationID].AsInteger() ?? 0;
                    int defID = source[MessageOutFieldID.DefinitionID].AsInteger() ?? 0;

                    DefinitionBase liveEntity = CreateDefinition(source);

                    if (liveEntity != null)
                    {
                        // find cache item ID and cache hint
                        CacheItemID?ciid      = null;
                        byte        cacheHint = 0;

                        byte[] ciidData = source[MessageOutFieldID.CacheItemID].AsByteArray();

                        if (ciidData != null)
                        {
                            ciid = new CacheItemID(ciidData);

                            cacheHint = source[MessageOutFieldID.CacheHint].AsByte() ?? 0;
                        }

                        if (ciid.HasValue)
                        {
                            templates.Add(new CacheDataTemplate(liveEntity, ciid, EntityID.Create(CacheEntityType.Definition, appID, defID), CacheEntityType.Definition, cacheHint));
                        }
                    }
                }

                Core.Cache.Server.AddRange(templates, true);
            }
        }
Example #3
0
        public DefinitionBase Find(int applicationID, int definitionID, bool createIfNeeded = false)
        {
            byte[] entityID = EntityID.Create(CacheEntityType.Definition, applicationID, definitionID);
            object data     = Core.Cache.Server.FindLiveEntity(null, entityID);

            if (data == null)
            {
                data = Core.Cache.Server[entityID];
            }

            if (data != null)
            {
                if (data is DefinitionBase)
                {
                    return(data as DefinitionBase);
                }
                else if (createIfNeeded && (data is FieldList))
                {
                    return(UnpackDefinition((FieldList)data)); //TODO: cache this?
                }
            }

            return(null);
        }