Keine Cache-Version

Caching deaktiviert Standardeinstellung für diese Seite:aktiviert (code LNG204)
Wenn die Anzeige zu langsam ist, können Sie den Benutzermodus deaktivieren, um die zwischengespeicherte Version anzuzeigen.

AWSHelper.cs

Description du code

AWSHelper.cs est un fichier du projet BiblioBrol.
Ce fichier est situé dans /var/www/bin/sniplets/bibliobrol/src/.

Projet BiblioBrol :

Gestion de media en CSharp.

Pour plus d'infos, vous pouvez consulter la brève analyse.

Code source ou contenu du fichier

  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Text;
  5. using be.gaudry.bibliobrol.awsRef;
  6. using System.Text.RegularExpressions;
  7. using System.Net;
  8. using be.gaudry.bibliobrol.config;
  9.  
  10. namespace be.gaudry.bibliobrol.model.aws
  11. {
  12. public class AWSHelper
  13. {
  14. #region declarations and constructors
  15. private AWSECommerceService awsECService;
  16. public static string AmazonUrlFR = "http://soap.amazon.fr/onca/soap?Service=AWSECommerceService";
  17. private bool HTMLFilteringEnabled;
  18. public AWSHelper()
  19. {
  20. awsECService = new AWSECommerceService();
  21. HTMLFilteringEnabled = true;
  22. }
  23. #endregion
  24.  
  25. #region Film
  26. /// <summary>
  27. /// Search for films by keywords
  28. /// </summary>
  29. public void searchFilms(AWSSearchResult<AWSFilm> searchResults)
  30. {
  31. searchFilms(searchResults, "");
  32. }
  33. /// <summary>
  34. /// Search for films by keywords
  35. /// </summary>
  36. public void searchFilms(AWSSearchResult<AWSFilm> searchResults, string proxyAddress)
  37. {
  38. //objects needed to define search and search criteria
  39. ItemSearchRequest itemSearchRequest = new ItemSearchRequest();
  40. ItemSearch itemSearch = new ItemSearch();
  41.  
  42. itemSearchRequest.Keywords = searchResults.Keywords;
  43.  
  44. itemSearchRequest.ResponseGroup = new string[] { "Medium" };
  45.  
  46. itemSearchRequest.SearchIndex = searchResults.SearchIndice;
  47. itemSearchRequest.ItemPage = searchResults.PageToSearchNumber;
  48.  
  49. itemSearch.SubscriptionId = Config.AwsSubscription;
  50.  
  51. itemSearch.Request = new ItemSearchRequest[] { itemSearchRequest };
  52.  
  53. //objects to store the response of the Web service
  54. ItemSearchResponse amazonResponse = null;
  55. Item[] amazonItems = null;
  56.  
  57. //bind the Web service proxy to the appropriate service end-point URL for the current locale
  58. this.awsECService.Url = AmazonUrlFR;
  59.  
  60. if (proxyAddress!=null && !string.Empty.Equals(proxyAddress))
  61. {
  62. WebProxy proxy = new WebProxy(proxyAddress);
  63. proxy.Credentials = CredentialCache.DefaultCredentials;
  64. this.awsECService.Timeout = 10000;
  65. this.awsECService.Proxy = proxy;
  66. this.awsECService.Credentials = CredentialCache.DefaultCredentials;
  67. }
  68.  
  69. //call the Web service and assign the response
  70. amazonResponse = this.awsECService.ItemSearch(itemSearch);
  71.  
  72. //access the array of returned items is the response is not Nothing
  73. if (amazonResponse != null && amazonResponse.Items!=null)
  74. {
  75. amazonItems = amazonResponse.Items[0].Item;
  76. searchResults.setTotalResults(amazonResponse.Items[0].TotalResults);
  77. searchResults.setTotalPages(amazonResponse.Items[0].TotalPages);
  78. }
  79.  
  80. //convert Amazon Items to generic collection of DVDs
  81. addFilms(amazonItems, searchResults);
  82.  
  83. }
  84.  
  85. private void addFilms(Item[] amazonItems, AWSSearchResult<AWSFilm> searchResults)
  86. {
  87. AWSFilm film;
  88.  
  89. if (amazonItems != null)
  90. {
  91. foreach (Item amazonItem in amazonItems)
  92. {
  93.  
  94. {
  95. film = new AWSFilm(amazonItem.ItemAttributes.Title, this.AmazonASINToString(amazonItem), this.AmazonItemDescriptionToString(amazonItem), amazonItem.ItemAttributes.Actor, amazonItem.ItemAttributes.Director, amazonItem.ItemAttributes.AudienceRating, this.AmazonItemRunningTimeToString(amazonItem), this.AmazonDateFormatToString(amazonItem.ItemAttributes.TheatricalReleaseDate), amazonItem.DetailPageURL, this.AmazonItemLargeImageURLToString(amazonItem));
  96.  
  97.  
  98. }
  99. searchResults.Add(film);
  100. }
  101. }
  102. }
  103. #endregion
  104.  
  105. #region private misc utilities
  106. /// <summary>
  107. /// Utility function that returns ASIN string from an Item
  108. /// </summary>
  109. /// <remarks>Used to look up DVD objects by ASIN or UPC</remarks>
  110. private string AmazonASINToString(Item amazonItem)
  111. {
  112. string asinString = "";
  113.  
  114. if ((amazonItem != null) && (amazonItem.ASIN.Length > 0))
  115. {
  116. asinString = amazonItem.ASIN.ToString();
  117. }
  118.  
  119. return asinString;
  120. }
  121. /// <summary>
  122. /// Utility function that converts the Amazon editorial review field to a string
  123. /// </summary>
  124. /// <remarks>Used to provide a description for an item</remarks>
  125. private string AmazonItemDescriptionToString(Item amazonItem)
  126. {
  127. string description = "";
  128. EditorialReview[] editorialReviews = amazonItem.EditorialReviews;
  129. if ((editorialReviews != null) && (editorialReviews.Length > 0))
  130. {
  131. if (HTMLFilteringEnabled == true)
  132. {
  133. description = this.FilterHTMLText(editorialReviews[0].Content);
  134. }
  135. else
  136. {
  137. description = editorialReviews[0].Content;
  138. }
  139. }
  140. return description;
  141. }
  142. /// <summary>
  143. /// Utility function that converts the Amazon running time field to a string
  144. /// </summary>
  145. private string AmazonItemRunningTimeToString(Item amazonItem)
  146. {
  147. string runningTime = "";
  148. {
  149. {
  150. ItemAttributes itemAttributes = amazonItem.ItemAttributes;
  151. if ((itemAttributes != null) && (itemAttributes.RunningTime != null))
  152. {
  153. runningTime = itemAttributes.RunningTime.Value.ToString();
  154. }
  155.  
  156. }
  157. }
  158. return runningTime;
  159. }
  160. /// <summary>
  161. /// Utility function to return Amazon's custom date/timestamp formats into a .NET Date type
  162. /// </summary>
  163. /// <param name="amazonDate">Date string returned by Amazon.com's ProductInfo type</param>
  164. /// <returns>Date type converted from custom string, or empty string if parameter is _</returns>
  165. /// <remarks></remarks>
  166. private string AmazonDateFormatToString(string amazonDate)
  167. {
  168. // Format to handle Amazon's convention for date strings; 0 means not set
  169. string[] expectedFormats = { "d", "yyyy", "yyyy-mm", "yyyymmdd", "yyyy0000", "yyyymm00", "yyyy00dd", "yyyy-mm-dd" };
  170. System.DateTime myDate;
  171. if (amazonDate != null)
  172. {
  173. myDate = System.DateTime.ParseExact(amazonDate, expectedFormats, System.Windows.Forms.Application.CurrentCulture, System.Globalization.DateTimeStyles.AllowWhiteSpaces);
  174. }
  175. else
  176. {
  177. return "";
  178. }
  179.  
  180. return myDate.ToString("yyyy");
  181. }
  182. /// <summary>
  183. /// Utility function that strips HTML tags and whitespace from the input string.
  184. /// </summary>
  185. /// <param name="htmlText"></param>
  186. /// <remarks>Used by GetListOfDVDs method. </remarks>
  187. private string FilterHTMLText(string htmlText)
  188. {
  189. string filteredText = "";
  190.  
  191. if (htmlText != null)
  192. {
  193. filteredText = htmlText;
  194.  
  195. //remove HTML tags using a regular expression
  196. filteredText = Regex.Replace(filteredText, "(<[^>]+>)", "");
  197.  
  198. //remove whitespace characters using a regular expression
  199. filteredText = Regex.Replace(filteredText, "&(nbsp|#160);", "");
  200.  
  201. //optional: format out additional characters
  202. //...
  203. }
  204.  
  205. return filteredText;
  206. }
  207. /// <summary>
  208. /// Utility function that converts the Amazon ImageURL to a URL string
  209. /// </summary>
  210. /// <remarks>Used to load the item image</remarks>
  211. private string AmazonItemLargeImageURLToString(Item amazonItem)
  212. {
  213. string largeImageUrl = "";
  214. {
  215. if (amazonItem.LargeImage != null)
  216. {
  217. largeImageUrl = amazonItem.LargeImage.URL;
  218. //System.Console.WriteLine(String.Format("LargeImage : {0}", largeImageUrl));
  219. }
  220. else if (amazonItem.MediumImage != null)
  221. {
  222. largeImageUrl = amazonItem.MediumImage.URL;
  223. //System.Console.WriteLine(String.Format("MediumImage : {0}", largeImageUrl));
  224. }
  225. else if (amazonItem.SmallImage != null)
  226. {
  227. largeImageUrl = amazonItem.SmallImage.URL;
  228. //System.Console.WriteLine(String.Format("SmallImage : {0}", largeImageUrl));
  229. }
  230. //else System.Console.WriteLine("Aucune image");
  231. }
  232. return largeImageUrl;
  233. }
  234. #endregion
  235. }
  236. }

Structure et Fichiers du projet

Afficher/masquer...


Répertoires contenus dans /var/www/bin/sniplets/bibliobrol/src/model/aws/ 
IcôneNomTailleModification
Pas de sous-répertoires.
IcôneNomTailleModification
| _ Répertoire parent0 octets1717330019 02/06/2024 14:06:59
Fichiers contenus dans /var/www/bin/sniplets/bibliobrol/src/model/aws/ 
IcôneNomTailleModificationAction
IcôneNomTailleModificationAction
Afficher le fichier .cs|.csAWSSearchResult.cs2.26 Ko31/10/2018 18:32:53-refusé-
Afficher le fichier .cs|.csAWSSearchIndices.cs4.46 Ko31/10/2018 18:32:53-refusé-
Afficher le fichier .cs|.csAWSFilm.cs7.99 Ko31/10/2018 18:32:53-refusé-
Afficher le fichier .cs|.csAWSHelper.cs9.27 Ko31/10/2018 18:32:53-refusé-

Utilisation de l'explorateur de code

  • Navigation :
    • Un clic sur une icône de répertoire ouvre ce répertoire pour en afficher les fichiers.
    • Lorsque le répertoire en cours ne contient pas de sous-répertoires il est possible de remonter vers le répertoire parent.
    • La structure de répertoires en treetable (tableau en forme d'arborescence) n'est plus possibledans cette version.
    • Un clic sur une icône de fichier ouvre ce fichier pour en afficher le code avec la coloration syntaxique adaptée en fonction du langage principal utilisé dans le fichier.
  • Affichage :
    • Il est possible de trier les répertoires ou les fichiers selon certains critères (nom, taille, date).
  • Actions :
    • Les actions possible sur les fichiers dépendent de vos droits d'utilisateur sur le site. Veuillez activer le mode utilisateur pour activer les actions.

Deutsche Übersetzung

Sie haben gebeten, diese Seite auf Deutsch zu besuchen. Momentan ist nur die Oberfläche übersetzt, aber noch nicht der gesamte Inhalt.

Wenn Sie mir bei Übersetzungen helfen wollen, ist Ihr Beitrag willkommen. Alles, was Sie tun müssen, ist, sich auf der Website zu registrieren und mir eine Nachricht zu schicken, in der Sie gebeten werden, Sie der Gruppe der Übersetzer hinzuzufügen, die Ihnen die Möglichkeit gibt, die gewünschten Seiten zu übersetzen. Ein Link am Ende jeder übersetzten Seite zeigt an, dass Sie der Übersetzer sind und einen Link zu Ihrem Profil haben.

Vielen Dank im Voraus.

Dokument erstellt 16/10/2009, zuletzt geändert 26/10/2018
Quelle des gedruckten Dokuments:https://www.gaudry.be/de/cs-bibliobrol-source-rf-model/aws/AWSHelper.cs.html

Die Infobro ist eine persönliche Seite, deren Inhalt in meiner alleinigen Verantwortung liegt. Der Text ist unter der CreativeCommons-Lizenz (BY-NC-SA) verfügbar. Weitere Informationen auf die Nutzungsbedingungen und dem Autor.