Ejemplo n.º 1
0
        public byte[] GetBinaryByUrl(string url)
        {
            string encodedUrl = HttpUtility.UrlPathEncode(url); // ?? why here? why now?

            Query findBinary = new Query();
            PublicationURLCriteria urlCriteria = new PublicationURLCriteria(url);
            //MultimediaCriteria isBinary = new MultimediaCriteria(true);

            //Criteria allCriteria = CriteriaFactory.And(isBinary, urlCriteria);
            Criteria allCriteria = urlCriteria;

            findBinary.Criteria = allCriteria;
            if (this.PublicationId != 0)
            {
                PublicationCriteria correctSite = new PublicationCriteria(this.PublicationId);
                allCriteria.AddCriteria(correctSite);
            }

            string[] binaryUri = findBinary.ExecuteQuery();

            if (binaryUri.Length == 0)
            {
                // TODO: find out how to retrieve binary data
            }

            throw new NotImplementedException();
        }
        public byte[] GetBinaryByUrl(string url)
        {
            string encodedUrl = HttpUtility.UrlPathEncode(url); // ?? why here? why now?
            
            Query findBinary = new Query();
            PublicationURLCriteria urlCriteria = new PublicationURLCriteria(url);
            //MultimediaCriteria isBinary = new MultimediaCriteria(true);

            //Criteria allCriteria = CriteriaFactory.And(isBinary, urlCriteria);
            Criteria allCriteria = urlCriteria;
            findBinary.Criteria = allCriteria;
            if (this.PublicationId != 0)
            {
                PublicationCriteria correctSite = new PublicationCriteria(this.PublicationId);
                allCriteria.AddCriteria(correctSite);
            }

            string[] binaryUri = findBinary.ExecuteQuery();

            if (binaryUri.Length == 0)
            {
                
                // TODO: find out how to retrieve binary data
            }

            throw new NotImplementedException();
        }
        public bool TryFindBinary(string url, out IBinary binary)
        {
            //string encodedUrl = HttpUtility.UrlPathEncode(url);
            binary = null;
            return(false);

            Query findBinary = new Query();
            PublicationURLCriteria urlCriteria = new PublicationURLCriteria(url);

            MultimediaCriteria isBinary = new MultimediaCriteria(true);

            Com.Tridion.Broker.Querying.Criteria.Criteria allCriteria = Com.Tridion.Broker.Querying.CriteriaFactory.And(isBinary, isBinary);
            //Criteria allCriteria = CriteriaFactory.And(isBinary, urlCriteria);
            //Criteria allCriteria = urlCriteria;
            //findBinary.Criteria = allCriteria;

            string[] binaryUri = findBinary.ExecuteQuery();

            if (binaryUri.Length == 0)
            {
                return(false);
            }
            else
            {
                ComponentPresentation binaryComponent;



                return(true);
            }

            /*
             * using (var sqlBinMetaHome = new Com.Tridion.Broker.Binaries.Meta.SQLBinaryMetaHome())
             * {
             *  Com.Tridion.Meta.BinaryMeta binaryMeta = sqlBinMetaHome.FindByURL(PublicationId, encodedUrl); // "/Images/anubis_pecunia160_tcm70-520973.jpg"
             *  if (binaryMeta != null)
             *  {
             *      using (var sqlBinaryHome = new Com.Tridion.Broker.Binaries.SQLBinaryHome())
             *      {
             *          Com.Tridion.Data.BinaryData binData = sqlBinaryHome.FindByPrimaryKey(PublicationId, (int)binaryMeta.GetId());
             *          if (binData != null)
             *          {
             *              binary = new Binary(this)
             *              {
             *                  Url = url,
             *                  LastPublishedDate = DateTime.Now,
             *                  Multimedia = null,
             *                  VariantId = binData.GetVariantId()
             *              };
             *              return true;
             *          }
             *      }
             *  }
             *  return false;
             * }
             */
        }
        public bool TryFindBinary(string url, out IBinary binary)
        {
            //string encodedUrl = HttpUtility.UrlPathEncode(url);
            binary = null;
            return false;

            Query findBinary = new Query();
            PublicationURLCriteria urlCriteria = new PublicationURLCriteria(url);

            MultimediaCriteria isBinary = new MultimediaCriteria(true);
            Com.Tridion.Broker.Querying.Criteria.Criteria allCriteria = Com.Tridion.Broker.Querying.CriteriaFactory.And(isBinary, isBinary);
            //Criteria allCriteria = CriteriaFactory.And(isBinary, urlCriteria);
            //Criteria allCriteria = urlCriteria;
            //findBinary.Criteria = allCriteria;

            string[] binaryUri = findBinary.ExecuteQuery();

            if (binaryUri.Length == 0)
            {
                return false;
            }
            else
            {
                ComponentPresentation binaryComponent ;

                return true;
            }

            /*
            using (var sqlBinMetaHome = new Com.Tridion.Broker.Binaries.Meta.SQLBinaryMetaHome())
            {
                Com.Tridion.Meta.BinaryMeta binaryMeta = sqlBinMetaHome.FindByURL(PublicationId, encodedUrl); // "/Images/anubis_pecunia160_tcm70-520973.jpg"
                if (binaryMeta != null)
                {
                    using (var sqlBinaryHome = new Com.Tridion.Broker.Binaries.SQLBinaryHome())
                    {
                        Com.Tridion.Data.BinaryData binData = sqlBinaryHome.FindByPrimaryKey(PublicationId, (int)binaryMeta.GetId());
                        if (binData != null)
                        {
                            binary = new Binary(this)
                            {
                                Url = url,
                                LastPublishedDate = DateTime.Now,
                                Multimedia = null,
                                VariantId = binData.GetVariantId()
                            };
                            return true;
                        }
                    }
                }
                return false;
            }
            */
        }