/// <summary> /// Fonction qui retourne les films correspondant au critère de recherche /// </summary> /// <param name="critere"></param> public ListeFichesFilmsAllocine RechercherMedia(string critere, Constantes.EnumTypeMediaAllocine typeMedia) { Log.MonitoringLogger().Info(KS_NOM_MODULE + "Début RechercherFilm"); try { string filter = String.Empty; switch (typeMedia) { case Constantes.EnumTypeMediaAllocine.FILM: filter = "movie"; break; case Constantes.EnumTypeMediaAllocine.SERIE: filter = "tvseries"; break; default: break; } if (critere == null || String.Empty.Equals(critere)) { return null; } critere = critere.Replace('é', 'e').Replace('à', 'a').Replace('è', 'e').Replace('ê', 'e').Replace('ô', 'o').Replace('&', ' '); string responseValue = String.Empty; SHA1 sha1 = SHA1CryptoServiceProvider.Create(); // Construction de l'url de recherche string url = Properties.Settings.Default.UrlRechercheAllocine; string sed = String.Format("{0:yyyyMMdd}", DateTime.Now); string param = String.Format(Properties.Settings.Default.ParamsRechercheAllocine, critere.Replace(" ", "+"), sed, filter); string encode = Properties.Settings.Default.SecretKeyAllocine + param; string sig = HttpUtility.UrlEncode(System.Convert.ToBase64String(sha1.ComputeHash(Encoding.ASCII.GetBytes(encode)))); url = url + "?" + param + "&sig=" + sig; // Création de la requête HttpWebRequest request = CreateWebRequest(url); // Récupération de la réponse HttpWebResponse response = (HttpWebResponse)request.GetResponse(); if (response.StatusCode != HttpStatusCode.OK) { string message = String.Format("POST failed. Received HTTP {0}", response.StatusCode); throw new ApplicationException(message); } //13/03/2013 - prise en compte format JSON // Récupération du flux Stream responseStream = UtilsAllocine.ConvertToXML(response.GetResponseStream()); //responseStream.Position = 0; //StreamReader reader = new StreamReader(responseStream, Encoding.UTF8); //url = reader.ReadToEnd(); //responseStream.Position = 0; // Désérialisation return DeserialiserListeFilms(responseStream); } catch (Exception ex) { Log.MonitoringLogger().Info(KS_NOM_MODULE + "Erreur = " + ex.Message); throw; } finally { Log.MonitoringLogger().Info(KS_NOM_MODULE + "Fin RechercherFilm"); } }
/// <summary> /// Fonction qui retourne les films correspondant au critère de recherche /// </summary> /// <param name="critere"></param> public FicheFilmAllocine ObtenirFicheFilm(string codeFilm, Constantes.EnumTypeMediaAllocine typeMedia) { Log.MonitoringLogger().Info(KS_NOM_MODULE + "Début ObtenirFicheFilm"); try { string filter = String.Empty; switch (typeMedia) { case Constantes.EnumTypeMediaAllocine.FILM: filter = "movie"; break; case Constantes.EnumTypeMediaAllocine.SERIE: filter = "tvseries"; break; default: break; } string responseValue = String.Empty; SHA1 sha1 = SHA1CryptoServiceProvider.Create(); string sed = String.Format("{0:yyyyMMdd}", DateTime.Now); string param = String.Format(Properties.Settings.Default.ParamsInfosFilmAllocine, codeFilm, sed, filter); string encode = Properties.Settings.Default.SecretKeyAllocine + param; string sig = HttpUtility.UrlEncode(System.Convert.ToBase64String(sha1.ComputeHash(Encoding.ASCII.GetBytes(encode)))); // Construction de l'url de recherche string url = string.Format(Properties.Settings.Default.UrlInfosFilmAllocine, filter, param, sig); //url = url + "?" + param + "&sig=" + sig; // Création de la requête HttpWebRequest request = CreateWebRequest(url); // Récupération de la réponse HttpWebResponse response = (HttpWebResponse)request.GetResponse(); if (response.StatusCode != HttpStatusCode.OK) { string message = String.Format("POST failed. Received HTTP {0}", response.StatusCode); throw new ApplicationException(message); } //13/03/2013 - prise en compte format JSON // Récupération du flux Stream responseStream = UtilsAllocine.ConvertToXML(response.GetResponseStream()); // Désérialisation FicheFilmAllocine film = DeserialiserFilm(responseStream); ControlerDonnees(film); DownloadPhoto(film); return film; } catch (Exception ex) { Log.MonitoringLogger().Info(KS_NOM_MODULE + "Erreur = " + ex.Message); return null; } finally { Log.MonitoringLogger().Info(KS_NOM_MODULE + "Fin ObtenirFicheFilm"); } }