Exemplo n.º 1
0
        public bool GetdownloadimagesFornewsletterin_Editors(List <string> IDs)
        {
            List <Image>        _liimg        = new List <Image>();
            List <ImageSize>    _liimgsize    = new List <ImageSize>();
            List <DownloadItem> lidwn         = new List <DownloadItem>();
            List <Imagedetails> _liimgdetails = new List <Imagedetails>();
            List <string>       _getIDs       = new List <string>();
            bool     _flag           = false;
            SiteInfo _objsite        = new SiteInfo();
            string   sitefolder      = string.Empty;
            string   monthyearfolder = DateTime.Now.ToString("yyyyMM");
            string   dayfolder       = DateTime.Now.ToString("MMMdd");
            string   imageName       = string.Empty;
            string   filename        = string.Empty;
            string   _returnfile     = string.Empty;

            try
            {
                GetLargestImageDownloadAuthorizationsSample _objdwnl  = new GetLargestImageDownloadAuthorizationsSample();
                GetImageDownloadAuthorizationsSample        _objsmall = new GetImageDownloadAuthorizationsSample();
                if (!string.IsNullOrEmpty(commonfn.getSession("token")))
                {
                    var token       = commonfn.getSession("token");
                    var securetoken = commonfn.getSession("securetoken");
                    //set imeges ID
                    if (IDs.Count > 0)
                    {
                        //new code to download images
                        GetImageDetailsSample _objgetalldetails            = new GetImageDetailsSample();
                        ImageSize             _objimgsize                  = new ImageSize();
                        Authorization         _objallauth                  = new Authorization();
                        DownloadItem          _objalldw                    = new DownloadItem();
                        GetImageDownloadAuthorizationsSample _objallimg    = new GetImageDownloadAuthorizationsSample();
                        CreateDownloadRequestSample          _objallcrtdwn = new CreateDownloadRequestSample();
                        //get all data for selected images.
                        var _getalldetails     = _objgetalldetails.GetImageDetails(token, IDs);
                        var _getmorealldetails = from images in _getalldetails.GetImageDetailsResult.Images
                                                 select new
                        {
                            Titel          = images.Title,
                            Collectname    = images.CollectionName,
                            UrlPreview     = images.UrlPreview,
                            UrlThumb       = images.UrlThumb,
                            ImageId        = images.ImageId,
                            LicensingModel = images.LicensingModel,
                            ImageFamily    = images.ImageFamily,
                            DateCreated    = images.DateCreated,
                            Artist         = images.Artist,
                            ShortCaption   = images.Caption.Substring(0, 100) + "..",
                            Caption        = images.Caption,
                            imagesize      = images.SizesDownloadableImages[0].SizeKey
                        };

                        foreach (var _objall in _getmorealldetails)
                        {
                            //assing imageID and sizes
                            _objimgsize.SizeKey = _objall.imagesize;
                            _objimgsize.ImageId = _objall.ImageId;
                            _liimgsize.Add(_objimgsize);
                            //authorize iamge
                            var _getauthtoken = _objallimg.AuthorizeDownload(token, _liimgsize);
                            var _getdatas     = from _firstauth in _getauthtoken.GetImageDownloadAuthorizationsResult.Images
                                                from _seondauth in _firstauth.Authorizations
                                                select new
                            {
                                //get download token
                                _newdwntoken = _seondauth.DownloadToken
                            };
                            foreach (var _val1 in _getdatas)
                            {
                                //assign token
                                _objalldw.DownloadToken = _val1._newdwntoken;
                                lidwn.Add(_objalldw);
                                var _getdwnurl2 = _objallcrtdwn.CreateRequest(securetoken, lidwn);
                                lidwn.Clear();
                                var _popupurl2 = from _popdwn2 in _getdwnurl2.CreateDownloadRequestResult.DownloadUrls
                                                 select new
                                {
                                    dwnlargeimage = _popdwn2.UrlAttachment
                                };
                                using (AddGettyImages _addimg = new AddGettyImages())
                                {
                                    //download image
                                    _addimg.SiteID    = _strsiteID;
                                    _addimg.NetworkId = _strnetworkID;
                                    _addimg.GetsitenameandserverID();
                                    filename = DateTime.Now.ToString("yyyyMMMddhhmmss") + "_" + _objall.ImageId + ".jpg";
                                    foreach (var goturl in _popupurl2)
                                    {
                                        _returnfile = GoWebshotwithpath(goturl.dwnlargeimage, _objall.ImageId, _addimg.Sitename, _addimg.serverId, _addimg.IsImageServer);
                                    }
                                    //download image and save it in database
                                    //_posturl = GoWebshot(_dr.Imgurl, _dr.ImgId, _addimg.Sitename, _addimg.serverId, _addimg.IsImageServer);
                                    _addimg.RandomId      = _strrandomecookie;
                                    _addimg.exturl        = _returnfile;
                                    _addimg.imagetxt      = _objall.Titel;
                                    _addimg.imagetxtbelow = _objall.Caption;
                                    _addimg.imagecredit   = _objall.Titel;
                                    _addimg.AddexternalimagesURL();
                                    //ScriptManager.RegisterStartupScript(this, this.GetType(), "close", "javascript:Singlegettyimage('" + _posturl +"');", true);
                                    _addimg.imagename     = "";
                                    _addimg.imagecredit   = "";
                                    _addimg.imagetxtbelow = "";
                                    _addimg.imagetxt      = "";
                                    imageName             = string.Empty;
                                    filename    = string.Empty;
                                    _returnfile = string.Empty;
                                    _flag       = true;
                                }
                            }
                        }
                        //end new code details
                    }
                }
            }
            catch (Exception ex)
            {
                CommonLib.ExceptionHandler.WriteLog(CommonLib.Sections.Client, "GetdownloadSelectedImage :", ex);
                ErrorLog.SaveErrorLog("0", "getimagedata", "GoWebshotwithpath", "GoWebshotwithpath", ex.Message, _strnetworkID.ToString());
            }
            return(_flag);
        }
Exemplo n.º 2
0
        public List <Imagedetails> getser()
        {
            List <string> li  = new List <string> {
            };
            List <Image> limg = new List <Image> {
            };
            List <Imagedetails> _liimgsetails = new List <Imagedetails>();
            List <DownloadItem> lidwn         = new List <DownloadItem> {
            };
            List <ImageSize> limgsize         = new List <ImageSize> {
            };
            DataTable _dt = new DataTable();
            DataRow   _dr = null;
            SearchForEditorialImagesSample s    = new SearchForEditorialImagesSample();
            CreateSessionRequestBody       serr = new CreateSessionRequestBody();
            CreateSessionSample            cs   = new CreateSessionSample();
            //create secure token

            //s.Search(token);
            //SearchForImages2RequestBody serbody = new SearchForImages2RequestBody();
            //SearchForImagesResult resu = new SearchForImagesResult();
            var searchQuery = new SearchForImages2RequestBody();

            searchQuery.Filter             = new Filter();
            searchQuery.Query              = new Query();
            searchQuery.Query.SearchPhrase = "football";
            var token       = cs.GetToken();
            var securetoken = cs.GetSecureToken();

            //searchQuery.Query.SpecificPersons = new List<string> {_strtext};
            //searchQuery.Query.SpecificPersons = new List<string> { "Jennifer Lopez" }; ;
            searchQuery.ResultOptions           = new ResultOptions();
            searchQuery.ResultOptions.ItemCount = 75;
            var searchResponse = s.Search(token, searchQuery.Query.SearchPhrase);
            var getimg         = from images in searchResponse.SearchForImagesResult.Images
                                 select new
            {
                Titel       = images.Title,
                Collectname = images.CollectionName,
                urlpre      = images.UrlPreview,
                urlthumb    = images.UrlThumb,
                ImagID      = images.ImageId,
                imglic      = images.LicensingModel,
                imgfamily   = images.ImageFamily,
                imgdate     = images.DateCreated,
                imgart      = images.Artist
            };

            _dt.Columns.Add("urlthumb", typeof(string));
            _dt.Columns.Add("urlpre", typeof(string));
            GetLargestImageDownloadAuthorizationsRequestBody b = new GetLargestImageDownloadAuthorizationsRequestBody();
            Image     i        = new Image();
            ImageSize _imgsize = new ImageSize();

            int  cnt  = 1;
            bool _got = false;

            foreach (var img in getimg)
            {
                if (cnt == 4)
                {
                    i.ImageId        = img.ImagID;
                    i.ImageFamily    = img.imgfamily;
                    i.LicensingModel = img.imglic;
                    i.UrlPreview     = img.urlpre;
                    i.UrlThumb       = img.urlthumb;
                    i.CollectionName = img.Collectname;
                    i.Title          = img.Titel;
                    _got             = true;
                }
                _dr             = _dt.NewRow();
                _dr["urlthumb"] = img.urlthumb;
                _dr["urlpre"]   = img.urlpre;
                _dt.Rows.Add(_dr);
                Imagedetails _objimgdetails = new Imagedetails();
                _objimgdetails.Artist         = img.imgart;
                _objimgdetails.CollectionName = img.Collectname;
                _objimgdetails.DateCreated    = img.imgdate;
                _objimgdetails.ImageFamily    = img.imgfamily;
                _objimgdetails.ImageId        = img.ImagID;
                _objimgdetails.LicensingModel = img.imglic;
                _objimgdetails.UrlPreview     = img.urlpre;
                _objimgdetails.UrlThumb       = img.urlthumb;
                _liimgsetails.Add(_objimgdetails);
                cnt++;
            }

            GetLargestImageDownloadAuthorizationsResponse bb  = new GetLargestImageDownloadAuthorizationsResponse();
            GetLargestImageDownloadAuthorizationsSample   bbb = new GetLargestImageDownloadAuthorizationsSample();

            if (_got)
            {
                limg.Add(i);
                var strjn = bbb.GetLargestDownloadForImages(token, limg);
                var _objr = from res in strjn.GetLargestImageDownloadAuthorizationsResult.Images
                            from auths in res.Authorizations
                            select new
                {
                    ImageIDs                  = res.ImageId,
                    DownloadIsFree            = auths.DownloadIsFree,
                    DownloadToken             = auths.DownloadToken,
                    ProductOfferingInstanceId = auths.ProductOfferingInstanceId,
                    ProductOfferingType       = auths.ProductOfferingType,
                    SizeKey = auths.SizeKey
                };

                foreach (var _testauth in _objr)
                {
                    //get image valu
                    GetImageDownloadAuthorizationsSample _objimg = new GetImageDownloadAuthorizationsSample();
                    Authorization _objaut = new Authorization();
                    DownloadItem  _objdw  = new DownloadItem();
                    CreateDownloadRequestSample _objcrtdwn = new CreateDownloadRequestSample();
                    _objaut.SizeKey                   = _testauth.SizeKey;
                    _objaut.DownloadIsFree            = _testauth.DownloadIsFree;
                    _objaut.DownloadToken             = _testauth.DownloadToken;
                    _objaut.ProductOfferingInstanceId = _testauth.ProductOfferingInstanceId;
                    _objaut.ProductOfferingType       = _testauth.ProductOfferingType;
                    _imgsize.SizeKey                  = _testauth.SizeKey;
                    _imgsize.ImageId                  = _testauth.ImageIDs;
                    _dnloadurlID = _testauth.ImageIDs;
                    limgsize.Add(_imgsize);
                    _objdw.DownloadToken = _objaut.DownloadToken;
                    lidwn.Add(_objdw);
                    var _getdownlod = _objimg.AuthorizeDownload(token, limgsize);
                    var _getdwnurl  = _objcrtdwn.CreateRequest(securetoken, lidwn);
                    var _popupurl   = from _popdwn in _getdwnurl.CreateDownloadRequestResult.DownloadUrls
                                      select new
                    {
                        dwnlargeimage = _popdwn.UrlAttachment
                    };
                    foreach (var getvalur in _popupurl)
                    {
                        _dnloadurl = getvalur.dwnlargeimage;
                    }
                }
                // JObject node = JObject.Parse(strjn);

                /*_n.DownloadIsFree=Convert.ToBoolean(node["DownloadIsFree"]);
                 * _n.DownloadToken = Convert.ToString(node["DownloadToken"]);
                 * _n.ProductOfferingInstanceId = Convert.ToString(node["ProductOfferingInstanceId"]);
                 * _n.ProductOfferingType = Convert.ToString(node["ProductOfferingType"]);
                 * _in.ImageId = Convert.ToString(node["ImageId"]);
                 * _in.SizeKey = Convert.ToString(node["SizeKey"]);*/
                /* var jArray = JArray.Parse(strjn.ToString());
                 * var countyNames = new List<string>();
                 * foreach (var element in jArray.SelectToken("[0]"))
                 * {
                 *   var value = element.SelectToken("Authorizations.DownloadToken").Value<string>();
                 *   countyNames.Add(value);
                 * }*/
            }

            return(_liimgsetails);
        }