Example #1
0
        public static bool SearchCoverOK(string zserverUrl, Book book, string fullName)
        {
            if (book == null) throw new ArgumentNullException("book");
            if (String.IsNullOrEmpty(fullName)) throw new ArgumentNullException("Nebyla zadána cesta k souboru", "fullName");

            bool result = false;

            ObalkyKnihRequest request = new ObalkyKnihRequest();
            request.zserverUrl = zserverUrl;

            ObalkyKnihBibInfo bibinfo = new ObalkyKnihBibInfo();
            bibinfo.sysno = book.SysNo;
            bibinfo.authors = new List<string>() { book.Author };
            bibinfo.title = book.Title;
            bibinfo.year = book.Year;
            bibinfo.isbn = book.ISBN;
            bibinfo.nbn = book.NBN;
            bibinfo.oclc = book.OCLC;
            request.bibinfo = bibinfo;

            ObalkyKnihResponse response = AuthController.GetProxy().Execute(client => client.SearchObalkyKnihCZ(request));

            if (response != null && response.cover_image != null && response.cover_image.Length > 0)
            {
                result = (ImageFunctions.WriteFile(fullName, response.cover_image, true) > 0);
            }

            return result;
        }
Example #2
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="catalogueID"></param>
        /// <param name="sysno"></param>
        /// <param name="isbn"></param>
        /// <returns></returns>
        public static string SearchCoverUrl(string zserverUrl, Book book)
        {
            if (book == null) throw new ArgumentNullException("book");

            string frontCoverUrl = null;

            ObalkyKnihRequest request = new ObalkyKnihRequest();
            request.zserverUrl = zserverUrl;

            ObalkyKnihBibInfo bibinfo = new ObalkyKnihBibInfo();
            bibinfo.sysno = book.SysNo;
            bibinfo.authors = new List<string>() { book.Author };
            bibinfo.title = book.Title;
            bibinfo.year = book.Year;
            bibinfo.isbn = book.ISBN;
            bibinfo.nbn = book.NBN;
            bibinfo.oclc = book.OCLC;
            request.bibinfo = bibinfo;

            ObalkyKnihResponse response = AuthController.GetProxy().Execute(client => client.SearchObalkyKnihCZ(request));

            if (response != null)
            {
                frontCoverUrl = response.cover_medium_url;
            }

            return frontCoverUrl;
        }
Example #3
0
        public ObalkyKnihResponse SearchObalkyKnihCZ(ObalkyKnihRequest request)
        {
            if (request == null) throw new ArgumentException("Request parameter is null.");
            if (request.bibinfo == null) throw new ArgumentException("Request parameter 'bibinfo' is null.");

            ObalkyKnihResponse response = null;

            try
            {
                if (String.IsNullOrEmpty(request.permalink) && !String.IsNullOrEmpty(request.zserverUrl))
                {
                    request.permalink = String.Format(@"http://{0}/F?func=find-c&ccl_term=sys={1}", request.zserverUrl, request.bibinfo.sysno);
                }

                JsonSerializerSettings jsonSettings = new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore };
                string jsonData = JsonConvert.SerializeObject(request, Formatting.None, jsonSettings);
                string jsonUrl = String.Format(@"https://{0}/api/book?book={1}", OBALKY_KNIH_URL, Uri.EscapeDataString(jsonData));

                using (WebClient webClient = new WebClient())
                {
                    webClient.Headers.Add(HttpRequestHeader.Referer, request.zserverUrl);
                    Stream stream = webClient.OpenRead(jsonUrl);
                    StreamReader reader = new StreamReader(stream);
                    string responseJson = reader.ReadToEnd();
                    char[] endTrimChars = { ')', ']', ';', '\n' };
                    responseJson = responseJson.Replace("obalky.callback([", "").TrimEnd(endTrimChars);
                    response = JsonConvert.DeserializeObject<ObalkyKnihResponse>(responseJson);

                    if (!String.IsNullOrEmpty(response.cover_medium_url))
                    {
                        //response.cover_cache_url = response.cover_medium_url.Replace("www", "cache");
                        response.cover_image = webClient.DownloadData(response.cover_medium_url);
                    }
                }
            }
            catch (Exception ex)
            {
                string message = String.Format("Chyba při vyhledaní publikace (SysNo={0}) na serveru ObalkyKnih.cz", request.bibinfo.sysno);
                throw new FaultException<DozpServiceFault>(new DozpServiceFault(message), ex.Message);
            }

            return response;
        }