Пример #1
0
 public IBinaryMeta GetBinaryMetaByUri(string uri)
 {
     Tridion.ContentDelivery.Meta.BinaryMeta binaryMeta = null;
     binaryMeta = BinaryMetaFactory.GetMeta(uri);
     if (binaryMeta == null)
     {
         LoggerService.Debug($"cannot find binary with uri {uri}");
         return(null);
     }
     DD4T.ContentModel.BinaryMeta bm = new ContentModel.BinaryMeta()
     {
         Id        = uri,
         VariantId = binaryMeta.VariantId,
     };
     Tridion.ContentDelivery.Meta.IComponentMeta componentMeta = GetTridionComponentMetaFactory(binaryMeta.PublicationId).GetMeta(binaryMeta.Id);
     if (componentMeta == null)
     {
         LoggerService.Debug($"no component metadata found for binary with uri {uri}");
         bm.HasLastPublishedDate = false;
         return(bm);
     }
     bm.HasLastPublishedDate = true;
     bm.LastPublishedDate    = componentMeta.LastPublicationDate;
     LoggerService.Debug(string.Format("returning binary for uri {0} with the following metadata: Id = {1}, VariantId = {2}, HasLastPublishDate = {3}, lastPublishDate = {4}", uri, bm.Id, bm.VariantId, bm.HasLastPublishedDate, bm.LastPublishedDate));
     return(bm);
 }
Пример #2
0
        public byte[] GetBinaryByUrl(string url)
        {
            string encodedUrl = HttpUtility.UrlPathEncode(url); // ?? why here? why now?


            IList metas = null;

            Tridion.ContentDelivery.Meta.BinaryMeta binaryMeta = null;

            if (this.PublicationId == 0)
            {
                metas = BinaryMetaFactory.GetMetaByUrl(encodedUrl);
                if (metas.Count == 0)
                {
                    throw new BinaryNotFoundException();
                }
                binaryMeta = metas[0] as Tridion.ContentDelivery.Meta.BinaryMeta;
            }
            else
            {
                binaryMeta = BinaryMetaFactory.GetMetaByUrl(this.PublicationId, encodedUrl);
                if (binaryMeta == null)
                {
                    throw new BinaryNotFoundException();
                }
            }
            TcmUri uri = new TcmUri(binaryMeta.PublicationId, binaryMeta.Id, 16, 0);

            Tridion.ContentDelivery.DynamicContent.BinaryFactory factory = new BinaryFactory();

            BinaryData binaryData = string.IsNullOrEmpty(binaryMeta.VariantId) ? factory.GetBinary(uri.ToString()) : factory.GetBinary(uri.ToString(), binaryMeta.VariantId);

            return(binaryData == null ? null : binaryData.Bytes);
        }
Пример #3
0
        public IBinaryMeta GetBinaryMetaByUrl(string url)
        {
            LoggerService.Debug($"started GetBinaryMetaByUrl for url {url} with publication id {PublicationId}");
            string encodedUrl = HttpUtility.UrlPathEncode(url); // ?? why here? why now?

            LoggerService.Debug($"using encodedUrl: {encodedUrl}");
            Tridion.ContentDelivery.Meta.BinaryMeta binaryMeta = null;
            if (this.PublicationId == 0)
            {
                IList metas = BinaryMetaFactory.GetMetaByUrl(encodedUrl);
                if (metas.Count == 0)
                {
                    return(null);
                }

                binaryMeta = metas[0] as Tridion.ContentDelivery.Meta.BinaryMeta;
            }
            else
            {
                binaryMeta = BinaryMetaFactory.GetMetaByUrl(this.PublicationId, encodedUrl);
            }
            if (binaryMeta == null)
            {
                LoggerService.Debug($"cannot find binary with URL {url}");
                return(null);
            }
            LoggerService.Debug($"found binarymeta with ID {binaryMeta.Id}");

            string uri = string.Format("tcm:{0}-{1}", binaryMeta.PublicationId, binaryMeta.Id);

            DD4T.ContentModel.BinaryMeta bm = new ContentModel.BinaryMeta()
            {
                Id        = uri,
                VariantId = binaryMeta.VariantId,
            };
            LoggerService.Debug("about to call ComponentMetaFactory.GetMeta");
            Tridion.ContentDelivery.Meta.IComponentMeta componentMeta = GetTridionComponentMetaFactory(binaryMeta.PublicationId).GetMeta(binaryMeta.Id);
            if (componentMeta == null)
            {
                LoggerService.Debug($"no component metadata found for binary with url {url}");
                bm.HasLastPublishedDate = false;
                return(bm);
            }
            LoggerService.Debug($"found component meta with LastPublishDate {componentMeta.LastPublicationDate}");
            bm.HasLastPublishedDate = true;
            bm.LastPublishedDate    = componentMeta.LastPublicationDate;
            LoggerService.Debug(string.Format("returning binary for url {0} with the following metadata: Id = {1}, VariantId = {2}, HasLastPublishDate = {3}, lastPublishDate = {4}", url, bm.Id, bm.VariantId, bm.HasLastPublishedDate, bm.LastPublishedDate));
            return(bm);
        }
Пример #4
0
        public DateTime GetLastPublishedDateByUrl(string url)
        {
            string encodedUrl = HttpUtility.UrlPathEncode(url); // ?? why here? why now?

            Tridion.ContentDelivery.Meta.BinaryMeta binaryMeta = null;
            if (this.PublicationId == 0)
            {
                IList metas = BinaryMetaFactory.GetMetaByUrl(encodedUrl);
                if (metas.Count == 0)
                {
                    return(DateTime.MinValue.AddSeconds(1)); // TODO: use nullable type
                }
                binaryMeta = metas[0] as Tridion.ContentDelivery.Meta.BinaryMeta;
            }
            else
            {
                binaryMeta = BinaryMetaFactory.GetMetaByUrl(this.PublicationId, encodedUrl);
            }

            Tridion.ContentDelivery.Meta.IComponentMeta componentMeta = GetTridionComponentMetaFactory(binaryMeta.PublicationId).GetMeta(binaryMeta.Id);
            return(componentMeta == null ? DateTime.MinValue : componentMeta.LastPublicationDate);
        }