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
Code c# (AWSHelper.cs) (236 lignes)
using System; using System.Collections.Generic; using System.ComponentModel; using System.Text; using be.gaudry.bibliobrol.awsRef; using System.Text.RegularExpressions; using System.Net; using be.gaudry.bibliobrol.config; namespace be.gaudry.bibliobrol.model.aws { public class AWSHelper { #region declarations and constructors private AWSECommerceService awsECService; public static string AmazonUrlFR = "http://soap.amazon.fr/onca/soap?Service=AWSECommerceService"; private bool HTMLFilteringEnabled; public AWSHelper() { HTMLFilteringEnabled = true; } #endregion #region Film /// <summary> /// Search for films by keywords /// </summary> public void searchFilms(AWSSearchResult<AWSFilm> searchResults) { searchFilms(searchResults, ""); } /// <summary> /// Search for films by keywords /// </summary> public void searchFilms(AWSSearchResult<AWSFilm> searchResults, string proxyAddress) { //objects needed to define search and search criteria itemSearchRequest.Keywords = searchResults.Keywords; itemSearchRequest.SearchIndex = searchResults.SearchIndice; itemSearchRequest.ItemPage = searchResults.PageToSearchNumber; itemSearch.SubscriptionId = Config.AwsSubscription; //objects to store the response of the Web service ItemSearchResponse amazonResponse = null; Item[] amazonItems = null; //bind the Web service proxy to the appropriate service end-point URL for the current locale this.awsECService.Url = AmazonUrlFR; if (proxyAddress!=null && !string.Empty.Equals(proxyAddress)) { proxy.Credentials = CredentialCache.DefaultCredentials; this.awsECService.Timeout = 10000; this.awsECService.Proxy = proxy; this.awsECService.Credentials = CredentialCache.DefaultCredentials; } //call the Web service and assign the response amazonResponse = this.awsECService.ItemSearch(itemSearch); //access the array of returned items is the response is not Nothing if (amazonResponse != null && amazonResponse.Items!=null) { amazonItems = amazonResponse.Items[0].Item; searchResults.setTotalResults(amazonResponse.Items[0].TotalResults); searchResults.setTotalPages(amazonResponse.Items[0].TotalPages); } //convert Amazon Items to generic collection of DVDs addFilms(amazonItems, searchResults); } private void addFilms(Item[] amazonItems, AWSSearchResult<AWSFilm> searchResults) { AWSFilm film; if (amazonItems != null) { foreach (Item amazonItem in amazonItems) { { 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)); } searchResults.Add(film); } } } #endregion #region private misc utilities /// <summary> /// Utility function that returns ASIN string from an Item /// </summary> /// <remarks>Used to look up DVD objects by ASIN or UPC</remarks> private string AmazonASINToString(Item amazonItem) { string asinString = ""; if ((amazonItem != null) && (amazonItem.ASIN.Length > 0)) { asinString = amazonItem.ASIN.ToString(); } return asinString; } /// <summary> /// Utility function that converts the Amazon editorial review field to a string /// </summary> /// <remarks>Used to provide a description for an item</remarks> private string AmazonItemDescriptionToString(Item amazonItem) { string description = ""; EditorialReview[] editorialReviews = amazonItem.EditorialReviews; if ((editorialReviews != null) && (editorialReviews.Length > 0)) { if (HTMLFilteringEnabled == true) { description = this.FilterHTMLText(editorialReviews[0].Content); } else { description = editorialReviews[0].Content; } } return description; } /// <summary> /// Utility function that converts the Amazon running time field to a string /// </summary> private string AmazonItemRunningTimeToString(Item amazonItem) { string runningTime = ""; { { ItemAttributes itemAttributes = amazonItem.ItemAttributes; if ((itemAttributes != null) && (itemAttributes.RunningTime != null)) { runningTime = itemAttributes.RunningTime.Value.ToString(); } } } return runningTime; } /// <summary> /// Utility function to return Amazon's custom date/timestamp formats into a .NET Date type /// </summary> /// <param name="amazonDate">Date string returned by Amazon.com's ProductInfo type</param> /// <returns>Date type converted from custom string, or empty string if parameter is _</returns> /// <remarks></remarks> private string AmazonDateFormatToString(string amazonDate) { // Format to handle Amazon's convention for date strings; 0 means not set string[] expectedFormats = { "d", "yyyy", "yyyy-mm", "yyyymmdd", "yyyy0000", "yyyymm00", "yyyy00dd", "yyyy-mm-dd" }; System.DateTime myDate; if (amazonDate != null) { myDate = System.DateTime.ParseExact(amazonDate, expectedFormats, System.Windows.Forms.Application.CurrentCulture, System.Globalization.DateTimeStyles.AllowWhiteSpaces); } else { return ""; } return myDate.ToString("yyyy"); } /// <summary> /// Utility function that strips HTML tags and whitespace from the input string. /// </summary> /// <param name="htmlText"></param> /// <remarks>Used by GetListOfDVDs method. </remarks> private string FilterHTMLText(string htmlText) { string filteredText = ""; if (htmlText != null) { filteredText = htmlText; //remove HTML tags using a regular expression filteredText = Regex.Replace(filteredText, "(<[^>]+>)", ""); //remove whitespace characters using a regular expression filteredText = Regex.Replace(filteredText, "&(nbsp|#160);", ""); //optional: format out additional characters //... } return filteredText; } /// <summary> /// Utility function that converts the Amazon ImageURL to a URL string /// </summary> /// <remarks>Used to load the item image</remarks> private string AmazonItemLargeImageURLToString(Item amazonItem) { string largeImageUrl = ""; { if (amazonItem.LargeImage != null) { largeImageUrl = amazonItem.LargeImage.URL; //System.Console.WriteLine(String.Format("LargeImage : {0}", largeImageUrl)); } else if (amazonItem.MediumImage != null) { largeImageUrl = amazonItem.MediumImage.URL; //System.Console.WriteLine(String.Format("MediumImage : {0}", largeImageUrl)); } else if (amazonItem.SmallImage != null) { largeImageUrl = amazonItem.SmallImage.URL; //System.Console.WriteLine(String.Format("SmallImage : {0}", largeImageUrl)); } //else System.Console.WriteLine("Aucune image"); } return largeImageUrl; } #endregion } }
Structure et Fichiers du projet
Afficher/masquer...Icône | Nom | Taille | Modification |
Pas de sous-répertoires. | |||
Icône | Nom | Taille | Modification |
| _ | Répertoire parent | 0 octets | 1736383330 09/01/2025 01:42:10 |
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.
English translation
You have asked to visit this site in English. For now, only the interface is translated, but not all the content yet.If you want to help me in translations, your contribution is welcome. All you need to do is register on the site, and send me a message asking me to add you to the group of translators, which will give you the opportunity to translate the pages you want. A link at the bottom of each translated page indicates that you are the translator, and has a link to your profile.
Thank you in advance.
Document created the 16/10/2009, last modified the 26/10/2018
Source of the printed document:https://www.gaudry.be/en/cs-bibliobrol-source-rf-model/aws//AWSHelper.cs.html
The infobrol is a personal site whose content is my sole responsibility. The text is available under CreativeCommons license (BY-NC-SA). More info on the terms of use and the author.