Exemplo n.º 1
0
        /// <summary>
        /// Tries to dull an item data from cache trying to load it if it has not been already loaded
        /// </summary>
        /// <param name="oItemId"></param>
        /// <returns></returns>
        private PrefetchData GetPrefetchData(ID oItemId)
        {
            PrefetchData oData;

            this.EnsureInitialPrefetch();

            oData = this.PrefetchCache[oItemId] as PrefetchData;
            if (oData == null)
            {
                oData = this.PrefetchItem(oItemId);
                if (oData == null)
                {
                    oData = new PrefetchData(ItemDefinition.Empty, ID.Null);
                    lock (this.PrefetchCache.SyncRoot)
                    {
                        if (!this.PrefetchCache.ContainsKey(oItemId))
                        {
                            this.PrefetchCache.Add(oItemId, oData, oData.GetDataLength());
                        }
                    }
                    oData = this.GetPrefetchDataFromCache(oItemId);
                }
            }
            else
            {
                if (oData.ItemDefinition.IsEmpty)
                {
                    oData = null;
                }
            }

            return(oData);
        }
Exemplo n.º 2
0
        private PrefetchData GetPrefetchData(ID itemId)
        {
            var data = PrefetchCache[itemId] as PrefetchData;

            if (data != null)
            {
                if (!data.ItemDefinition.IsEmpty)
                {
                    return(data);
                }

                return(null);
            }

            var itemDto = Provider.GetItem(itemId.ToGuid());

            if (itemDto != null)
            {
                data = new PrefetchData(new ItemDefinition(itemId, itemDto.Name, new ID(itemDto.TemplateId), new ID(itemDto.BranchId)), new ID(itemDto.ParentId));

                PrefetchCache.Add(itemId, data, data.GetDataLength());

                return(data);
            }

            return(null);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Returns a definition containing the id, name, template id, branch id and parent id of the Item that corresponds with the itemId parameter.
        /// </summary>
        /// <param name="itemId">The item id to search for</param>
        /// <param name="context"></param>
        /// <returns></returns>
        public override ItemDefinition GetItemDefinition(ID itemId, CallContext context)
        {
            PrefetchData prefetchData = GetPrefetchData(itemId);

            if (prefetchData == null)
            {
                return(null);
            }
            return(prefetchData.ItemDefinition);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Loads the fields for the collection of items passed as parameters
        /// </summary>
        /// <param name="parameters"></param>
        /// <param name="prefetchData"></param>
        protected virtual void LoadItemFields(object[] parameters, SafeDictionary <ID, PrefetchData> prefetchData)
        {
            LanguageCollection languages = this.GetLanguages();
            List <string>      oItemIds;
            PrefetchData       data = null;
            ID oCurrentItemId;
            List <FieldContract> oGenFieldsForItem;
            ID @null = ID.Null;
            Dictionary <string, List <FieldContract> > oItemsWithFields;

            oItemIds = ParseIDsFromParameters(parameters);

            Sitecore.Diagnostics.Log.Debug("LoadItemFields - Begins", this);

            if (oItemIds != null)
            {
                using (var oContentService = new GenContentServiceProxy())
                {
                    oItemsWithFields = oContentService.GetItemsFields(oItemIds, this.CurrentDatabase);
                }

                foreach (string sItemId in oItemIds)
                {
                    if (ID.TryParse(sItemId, out oCurrentItemId))
                    {
                        if (oCurrentItemId != @null)
                        {
                            data = prefetchData[oCurrentItemId];
                            if (data != null)
                            {
                                data.InitializeFieldLists(languages);
                            }
                            @null = oCurrentItemId;
                        }

                        oGenFieldsForItem = oItemsWithFields[sItemId];

                        if ((data != null) && oGenFieldsForItem != null && oGenFieldsForItem.Count > 0)
                        {
                            foreach (FieldContract oGenField in oGenFieldsForItem)
                            {
                                data.AddField(oGenField.Language, oGenField.Version, ID.Parse(oGenField.Id), oGenField.Value);
                                Sitecore.Diagnostics.Log.Debug(string.Format("Field:{0}   Value:{1}  Language:{2} Version:{3}", oGenField.Id, oGenField.Value, oGenField.Language, oGenField.Version), this);
                            }
                        }
                    }
                }
            }
        }
 /// <summary>
 ///     Returns a definition containing the id, name, template id, branch id and parent id of the Item that corresponds
 ///     with the itemId parameter.
 /// </summary>
 /// <param name="itemId">The item id to search for</param>
 /// <param name="context"></param>
 /// <returns></returns>
 public override ItemDefinition GetItemDefinition(ID itemId, CallContext context)
 {
     if (ItemsById.ContainsKey(itemId))
     {
         var data = new PrefetchData(
             new ItemDefinition(
                 itemId,
                 ItemsById[itemId].Name,
                 ParseId(ItemsById[itemId].TemplateID) ?? ID.Null,
                 ParseId(ItemsById[itemId].BranchId) ?? ID.Null),
             ParseId(ItemsById[itemId].ParentID) ?? ID.Null);
         if (data != null)
         {
             return(data.ItemDefinition);
         }
     }
     return(null);
 }
Exemplo n.º 6
0
        /// <summary>
        /// Sitecore request and item children IDs
        /// </summary>
        /// <param name="oItemDefinition">Sitecore item definition</param>
        /// <param name="oContext">Sitecore call context</param>
        /// <returns>IDList with the IDs for the children items of the given item </returns>
        public override IDList GetChildIDs(ItemDefinition oItemDefinition, CallContext oContext)
        {
            #region VARIABLES

            IDList    oIDsList;
            object[]  oPrefetchParameters;
            ArrayList oIdsToPrefetch;

            #endregion

            Sitecore.Diagnostics.Log.Debug(string.Format("GetChildIDs {0}", oItemDefinition.ID), this);

            oIDsList = null;


            PrefetchData prefetchData = this.GetPrefetchData(oItemDefinition.ID);
            if (prefetchData != null)
            {
                oIDsList = prefetchData.GetChildIds();
                if (oIDsList != null && oIDsList.Count > 1)
                {
                    oIdsToPrefetch = new ArrayList();
                    foreach (ID oItemId in oIDsList)
                    {
                        if (!this.PrefetchCache.ContainsKey(oItemId))
                        {
                            oIdsToPrefetch.Add("ItemId");
                            oIdsToPrefetch.Add(oItemDefinition.ID);
                        }
                    }

                    if (oIdsToPrefetch.Count > 0)
                    {
                        oPrefetchParameters = oIdsToPrefetch.ToArray(typeof(object)) as object[];
                        PrefetchItems(oPrefetchParameters);
                    }
                }
            }


            return(oIDsList);
        }
Exemplo n.º 7
0
        /// <summary>
        /// Saves and item data to the cache
        /// </summary>
        /// <param name="oItemId"></param>
        /// <param name="oData"></param>
        private void AddPrefetchDataToCache(ID oItemId, PrefetchData oData)
        {
            #region VARIABLES
            ItemDefinition oItemDefinition;
            ID             oTemplateID;

            #endregion
            this.PrefetchCache.Add(oItemId, oData, oData.GetDataLength());
            if (this.bLogPrefetchStatistics && this.bInitialDataPrefetched)
            {
                oItemDefinition = oData.ItemDefinition;
                if (!oItemDefinition.IsEmpty)
                {
                    oTemplateID = oItemDefinition.TemplateID;
                    lock (this.oPrefetchStatistics.SyncRoot)
                    {
                        this.oPrefetchStatistics[oTemplateID] += 1;
                    }
                }
            }
        }
Exemplo n.º 8
0
        /// <summary>
        /// Load the childs for the items passed through the parameters
        /// </summary>
        /// <param name="condition"></param>
        /// <param name="parameters"></param>
        /// <param name="prefetchData"></param>
        protected virtual void LoadChildIds(object[] parameters, SafeDictionary <ID, PrefetchData> prefetchData)
        {
            List <string> oItemIds;
            PrefetchData  data = null;
            ID            @null;
            ID            oCurrentItemId;
            List <Guid>   oChildIds;
            Dictionary <Guid, List <Guid> > oItemsWithChilds;

            @null = ID.Null;

            oItemIds = ParseIDsFromParameters(parameters);

            if (oItemIds != null)
            {
                using (var oContentService = new GenContentServiceProxy())
                {
                    oItemsWithChilds = oContentService.GetItemsChildIDs(oItemIds, this.CurrentDatabase);
                }

                foreach (var oItemChild in oItemsWithChilds)
                {
                    oCurrentItemId = ID.Parse(oItemChild.Key);

                    if (oCurrentItemId != @null)
                    {
                        data  = prefetchData[oCurrentItemId];
                        @null = oCurrentItemId;
                    }
                    if (data != null)
                    {
                        oChildIds = oItemChild.Value;
                        foreach (Guid oChild in oChildIds)
                        {
                            data.AddChildId(ID.Parse(oChild));
                        }
                    }
                }
            }
        }
Exemplo n.º 9
0
        private PrefetchData GetPrefetchData(ID itemId)
        {
            PrefetchData data = this.PrefetchCache[itemId] as PrefetchData;

            if (data != null)
            {
                if (!data.ItemDefinition.IsEmpty)
                {
                    return(data);
                }
                return(null);
            }
            ItemInfo result = Items.FindOneByIdAs <ItemInfo>(itemId.ToGuid());

            if (result != null)
            {
                data = new PrefetchData(new ItemDefinition(itemId, result.Name, new ID(result.TemplateID), new ID(result.BranchID)), new ID(result.ParentID));
                this.PrefetchCache.Add(itemId, data, data.GetDataLength());
                return(data);
            }

            return(null);
        }
Exemplo n.º 10
0
        public static IAudioFormat ToAudioStream(BxstmStructure structure)
        {
            if (structure.PrefetchData != null)
            {
                // Read only the first prefetch region for now
                PrefetchData pdat = structure.PrefetchData[0];
                structure.StreamInfo.Looping     = false;
                structure.StreamInfo.SampleCount = pdat.SampleCount;
            }
            switch (structure.StreamInfo.Codec)
            {
            case NwCodec.GcAdpcm:
                return(ToAdpcmStream(structure));

            case NwCodec.Pcm16Bit:
                return(ToPcm16Stream(structure));

            case NwCodec.Pcm8Bit:
                return(ToPcm8Stream(structure));

            default:
                return(null);
            }
        }
Exemplo n.º 11
0
        private static void ReadDataBlock(BinaryReader reader, BxstmStructure structure, bool readAudioData)
        {
            SizedReference reference =
                structure.Blocks.FirstOrDefault(x => x.Type == ReferenceType.StreamDataBlock ||
                                                x.Type == ReferenceType.StreamPrefetchDataBlock ||
                                                x.Type == ReferenceType.WaveDataBlock) ??
                throw new InvalidDataException("File has no DATA block");

            StreamInfo info = structure.StreamInfo;

            reader.BaseStream.Position = reference.AbsoluteOffset;

            string blockId = reader.ReadUTF8(4);

            if (blockId != "DATA" && blockId != "PDAT")
            {
                throw new InvalidDataException("Unknown or invalid DATA block");
            }

            if (reader.ReadInt32() != reference.Size)
            {
                throw new InvalidDataException("DATA block size in main header doesn't match size in DATA header");
            }

            if (!readAudioData)
            {
                return;
            }

            if (reference.IsType(ReferenceType.WaveDataBlock))
            {
                int audioDataLength = Common.SamplesToBytes(info.SampleCount, info.Codec);
                structure.AudioData = CreateJaggedArray <byte[][]>(info.ChannelCount, audioDataLength);
                int baseOffset = (int)reader.BaseStream.Position;

                for (int i = 0; i < info.ChannelCount; i++)
                {
                    reader.BaseStream.Position = baseOffset + structure.ChannelInfo.WaveAudioOffsets[i];
                    structure.AudioData[i]     = reader.ReadBytes(audioDataLength);
                }
            }
            else if (reference.IsType(ReferenceType.StreamDataBlock))
            {
                int audioOffset = reference.AbsoluteOffset + info.AudioReference.Offset + 8;
                reader.BaseStream.Position = audioOffset;
                int audioDataLength = reference.Size - (audioOffset - reference.AbsoluteOffset);
                int outputSize      = Common.SamplesToBytes(info.SampleCount, info.Codec);

                structure.AudioData = reader.BaseStream.DeInterleave(audioDataLength, info.InterleaveSize,
                                                                     info.ChannelCount, outputSize);
            }
            else if (reference.IsType(ReferenceType.StreamPrefetchDataBlock))
            {
                structure.PrefetchData = new List <PrefetchData>();
                int count = reader.ReadInt32();

                for (int i = 0; i < count; i++)
                {
                    structure.PrefetchData.Add(PrefetchData.ReadPrefetchData(reader, info));
                }

                reader.BaseStream.Position = structure.PrefetchData[0].AudioData.AbsoluteOffset;
                structure.AudioData        = reader.BaseStream.DeInterleave(structure.PrefetchData[0].Size, info.InterleaveSize,
                                                                            info.ChannelCount, structure.PrefetchData[0].Size);
            }
        }
 /// <summary>
 /// Returns a definition containing the id, name, template id, branch id and parent id of the Item that corresponds with the itemId parameter.
 /// </summary>
 /// <param name="itemId">The item id to search for</param>
 /// <param name="context"></param>
 /// <returns></returns>
 public override ItemDefinition GetItemDefinition(ID itemId, CallContext context)
 {
     if (ItemsById.ContainsKey(itemId))
     {
         PrefetchData data = new PrefetchData(
             new ItemDefinition(
                 itemId,
                 ItemsById[itemId].Name,
                 ParseId(ItemsById[itemId].TemplateID) ?? ID.Null,
                 ParseId(ItemsById[itemId].BranchId) ?? ID.Null),
                 ParseId(ItemsById[itemId].ParentID) ?? ID.Null);
         if (data != null)
         {
             return data.ItemDefinition;
         }
     }
     return null;
 }
        private PrefetchData GetPrefetchData(ID itemId)
        {
            PrefetchData data = this.PrefetchCache[itemId] as PrefetchData;
            if (data != null)
            {
                if (!data.ItemDefinition.IsEmpty)
                {
                    return data;
                }
                return null;
            }
            ItemInfo result = Items.FindOneByIdAs<ItemInfo>(itemId.ToGuid());

            if (result != null)
            {
                data = new PrefetchData(new ItemDefinition(itemId, result.Name, new ID(result.TemplateID), new ID(result.BranchID)), new ID(result.ParentID));
                this.PrefetchCache.Add(itemId, data, data.GetDataLength());
                return data;
            }

            return null;
        }
Exemplo n.º 14
0
        private PrefetchData GetPrefetchData(ID itemId)
        {
            var data = PrefetchCache[itemId] as PrefetchData;

            if (data != null)
            {
                if (!data.ItemDefinition.IsEmpty)
                {
                    return data;
                }

                return null;
            }

            var itemDto = Provider.GetItem(itemId.ToGuid());

            if (itemDto != null)
            {
                data = new PrefetchData(new ItemDefinition(itemId, itemDto.Name, new ID(itemDto.TemplateId), new ID(itemDto.BranchId)), new ID(itemDto.ParentId));

                PrefetchCache.Add(itemId, data, data.GetDataLength());

                return data;
            }

            return null;
        }
Exemplo n.º 15
0
        /// <summary>
        /// Loads a set item definitions into the cache by using the parameters array passed as parameter. Parameters are in the form of {"ItemId", "{Sitecore Id}"}
        /// </summary>
        /// <param name="parameters"></param>
        /// <param name="prefetchData"></param>
        protected virtual void LoadItemDefinitions(object[] parameters, SafeDictionary <ID, PrefetchData> prefetchData)
        {
            #region VARIABLES

            ItemDefinition oItemDefinition;
            string         sItemId;
            int            iParameterIndex;
            List <string>  oItemIds;
            List <ItemDefinitionContract> oItemDefinitions;
            PrefetchData oData;

            //Add variables here...

            #endregion

            if (parameters != null && parameters.Length > 1)
            {
                oItemIds = new List <string>();
                for (iParameterIndex = 0; iParameterIndex < parameters.Length; iParameterIndex += 2)
                {
                    if (ID.IsID(parameters[iParameterIndex + 1].ToString()))
                    {
                        sItemId = parameters[iParameterIndex + 1].ToString();

                        oItemIds.Add(sItemId);
                    }
                }

                if (oItemIds.Count > 0)
                {
                    using (var oContentService = new GenContentServiceProxy())
                    {
                        oItemDefinitions = oContentService.GetItemDefinitions(oItemIds, this.CurrentDatabase);
                    }

                    if (oItemDefinitions != null && oItemDefinitions.Count > 0)
                    {
                        try
                        {
                            foreach (ItemDefinitionContract oItemDefinitionContract in oItemDefinitions)
                            {
                                oItemDefinition = new Sitecore.Data.ItemDefinition(
                                    new Sitecore.Data.ID(oItemDefinitionContract.Id),
                                    !string.IsNullOrEmpty(oItemDefinitionContract.Name) ? oItemDefinitionContract.Name : string.Empty,
                                    !string.IsNullOrEmpty(oItemDefinitionContract.TemplateId) ? new Sitecore.Data.ID(oItemDefinitionContract.TemplateId) : null,
                                    !string.IsNullOrEmpty(oItemDefinitionContract.BranchId) ? new Sitecore.Data.ID(oItemDefinitionContract.BranchId) : null
                                    );

                                oData = new PrefetchData(oItemDefinition, !string.IsNullOrEmpty(oItemDefinitionContract.ParentId) ? new Sitecore.Data.ID(oItemDefinitionContract.ParentId) : ID.Null);

                                prefetchData[oItemDefinition.ID] = oData;

                                Sitecore.Diagnostics.Log.Debug(string.Format("GetItemDefinition, Item Cached:{0}", oItemDefinition.ID.ToString()), this);
                            }
                        }
                        catch
                        {
                            Sitecore.Diagnostics.Log.Error("GetItemDefinition, Unable to get item definitions", this);
                            throw;
                        }
                    }
                }
            }
        }