private void worker_DoWork_XML(object sender, DoWorkEventArgs e) { try { Total = _selectedItems.Length; foreach (XElement node in _selectedItems) { //exit if the user cancels if (_isCancelationPending == true) { return; } Movie movie = new Movie(); movie.Title = Util.GetElementValue(node, "Title"); movie.OriginalTitle = Util.GetElementValue(node, "OriginalTitle"); movie.BarCode = Util.GetElementValue(node, "BarCode"); movie.Comments = Util.GetElementValue(node, "Comments"); movie.Description = Util.GetElementValue(node, "Description"); movie.FileName = Util.GetElementValue(node, "FileName"); movie.FilePath = Util.GetElementValue(node, "FilePath"); movie.Country = Util.GetElementValue(node, "Country"); movie.AlloCine = Util.GetElementValue(node, "AlloCine"); movie.Imdb = Util.GetElementValue(node, "Imdb"); movie.Tagline = Util.GetElementValue(node, "Tagline"); DateTime dateValue; if (DateTime.TryParse(Util.GetElementValue(node, "AddedDate"), out dateValue) == true) { movie.AddedDate = dateValue; } if (DateTime.TryParse(Util.GetElementValue(node, "ReleaseDate"), out dateValue) == true) { movie.ReleaseDate = dateValue; } #region Bool bool boolValue; if (bool.TryParse(Util.GetElementValue(node, "IsComplete"), out boolValue) == true) { movie.IsComplete = boolValue; } if (bool.TryParse(Util.GetElementValue(node, "IsDeleted"), out boolValue) == true) { movie.IsDeleted = boolValue; } if (bool.TryParse(Util.GetElementValue(node, "Seen"), out boolValue) == true) { movie.Watched = boolValue; } if (bool.TryParse(Util.GetElementValue(node, "IsWhish"), out boolValue) == true) { movie.IsWhish = boolValue; } if (bool.TryParse(Util.GetElementValue(node, "ToBeDeleted"), out boolValue) == true) { movie.ToBeDeleted = boolValue; } #endregion #region Int int intValue; if (int.TryParse(Util.GetElementValue(node, "Rated"), out intValue) == true) { movie.Rated = intValue.ToString(CultureInfo.InvariantCulture); } if (int.TryParse(Util.GetElementValue(node, "Rating"), out intValue) == true) { movie.MyRating = intValue; } if (int.TryParse(Util.GetElementValue(node, "Runtime"), out intValue) == true) { movie.Runtime = intValue; } #endregion #region Media var query = from item in node.Descendants("Media") select item; XElement[] movieNode = query.ToArray(); foreach (XElement media in movieNode) { Media newMedia = MediaServices.Get(Util.GetElementValue(media, "Name"), true); newMedia.Path = Util.GetElementValue(media, "Path"); movie.Media = newMedia; } #endregion #region AspectRatio query = from item in node.Descendants("AspectRatio") select item; movieNode = query.ToArray(); foreach (XElement aspectRatio in movieNode) { movie.AspectRatio = MovieServices.GetAspectRatio(Util.GetElementValue(aspectRatio, "Name")); } #endregion #region FileFormat query = from item in node.Descendants("FileFormat") select item; movieNode = query.ToArray(); foreach (XElement format in movieNode) { movie.FileFormat = MovieServices.GetFormat(Util.GetElementValue(format, "Name")); } #endregion #region Studio query = from item in node.Descendants("Studio") select item; movieNode = query.ToArray(); foreach (XElement studio in movieNode) { bool isNew; movie.Publisher = PublisherServices.GetPublisher(Util.GetElementValue(studio, "Name"), out isNew, "Movie_Studio"); if (isNew == true) { Dal.GetInstance.AddPublisher("Movie_Studio", movie.Publisher); } } #endregion #region Links query = from item in node.Descendants("Link") select item; movieNode = query.ToArray(); foreach (XElement link in movieNode) { LinksServices.AddLinks(Util.GetElementValue(link, "Path"), movie, true); } #endregion #region Types query = from item in node.Descendants("Type") select item; movieNode = query.ToArray(); foreach (XElement type in movieNode) { MovieServices.AddTypes(Util.GetElementValue(type, "RealName"), movie); } #endregion #region Image query = from item in node.Descendants("Ressource") select item; movieNode = query.ToArray(); foreach (XElement images in movieNode) { if (Util.GetElementValue(images, "ResourcesType") == "Image") { bool isDefault = bool.Parse(Util.GetElementValue(images, "IsDefault")); byte[] cover = Convert.FromBase64String(Util.GetElementValue(images, "Value")); if (cover.Length > 0) { RessourcesServices.AddImage(cover, movie, isDefault); } } if (Util.GetElementValue(images, "ResourcesType") == "Background") { byte[] cover = Convert.FromBase64String(Util.GetElementValue(images, "Value")); if (cover.Length > 0) { RessourcesServices.AddBackground(cover, movie); } } } #endregion #region Artist query = from item in node.Descendants("Artist") select item; XElement[] artistNode = query.ToArray(); foreach (XElement artist in artistNode) { bool isNew; string fullname = Util.GetElementValue(artist, "FulleName"); Artist newArtist = ArtistServices.Get(fullname, out isNew); if (string.IsNullOrWhiteSpace(newArtist.Aka)) { newArtist.Aka = Util.GetElementValue(artist, "Aka"); } if (string.IsNullOrWhiteSpace(newArtist.Bio)) { newArtist.Bio = Util.GetElementValue(artist, "Bio"); } if (newArtist.BirthDay == null && DateTime.TryParse(Util.GetElementValue(artist, "BirthDay"), out dateValue) == true) { newArtist.BirthDay = dateValue; } if (string.IsNullOrWhiteSpace(newArtist.Breast)) { newArtist.Breast = Util.GetElementValue(artist, "Breast"); } if (string.IsNullOrWhiteSpace(newArtist.Ethnicity)) { newArtist.Ethnicity = Util.GetElementValue(artist, "Ethnicity"); } if (string.IsNullOrWhiteSpace(newArtist.FirstName)) { newArtist.FirstName = Util.GetElementValue(artist, "FirstName"); } if (string.IsNullOrWhiteSpace(newArtist.LastName)) { newArtist.LastName = Util.GetElementValue(artist, "LastName"); } if (newArtist.Picture == null) { newArtist.Picture = Convert.FromBase64String(Util.GetElementValue(artist, "Picture")); } if (string.IsNullOrWhiteSpace(newArtist.PlaceBirth)) { newArtist.PlaceBirth = Util.GetElementValue(artist, "PlaceBirth"); } if (string.IsNullOrWhiteSpace(newArtist.WebSite)) { newArtist.WebSite = Util.GetElementValue(artist, "WebSite"); } if (string.IsNullOrWhiteSpace(newArtist.YearsActive)) { newArtist.YearsActive = Util.GetElementValue(artist, "YearsActive"); } query = from item in artist.Descendants("Credit") select item; XElement[] creditsNode = query.ToArray(); foreach (XElement artistCredit in creditsNode) { ArtistCredits artistCredits = new ArtistCredits(); artistCredits.Title = Util.GetElementValue(artistCredit, "Title"); artistCredits.BuyLink = Util.GetElementValue(artistCredit, "BuyLink"); artistCredits.EntityType = EntityType.Movie; artistCredits.Notes = Util.GetElementValue(artistCredit, "Notes"); DateTime releaseDate; if (DateTime.TryParse(Util.GetElementValue(artistCredit, "ReleaseDate"), out releaseDate) == true) { artistCredits.ReleaseDate = releaseDate; } if (string.IsNullOrWhiteSpace(artistCredits.Title) == false && string.IsNullOrWhiteSpace(newArtist.FulleName) == false) { if (Dal.GetInstance.GetArtistCredit(artistCredits.Title, newArtist.FulleName) == null) { newArtist.ArtistCredits.Add(artistCredits); } } } ArtistServices.AddArtist(new[] { newArtist }, movie); } #endregion Dal.GetInstance.AddMovie(movie); _intAddedItem++; Current++; } } catch (Exception ex) { Util.LogException(ex); } }
public static Hashtable Parse(string asin, AmazonCountry country, bool isBarcode, AmazonIndex index, string barcodeType) { Hashtable objResults = new Hashtable(); try { ItemLookupRequest request = new ItemLookupRequest(); if (isBarcode) { switch (barcodeType) { case "EAN_8": case "EAN_13": request.IdType = ItemLookupRequestIdType.EAN; break; case "UPC_A": case "UPC_E": case "UPC_EAN_EXTENSION": request.IdType = ItemLookupRequestIdType.UPC; break; default: request.IdType = ItemLookupRequestIdType.EAN; break; } request.SearchIndex = index.ToString(); } else { request.IdType = ItemLookupRequestIdType.ASIN; } request.IdTypeSpecified = true; request.ItemId = new [] { asin }; request.ResponseGroup = new [] { "EditorialReview", "Images", "ItemAttributes", "Large", "Tracks" }; ItemLookup itemLookup = new ItemLookup(); itemLookup.AWSAccessKeyId = Aws1; itemLookup.AssociateTag = AssociateTag; itemLookup.Request = new [] { request }; AWSECommerceServicePortTypeClient client = new AWSECommerceServicePortTypeClient( new BasicHttpBinding("AWSECommerceServiceBinding"), new EndpointAddress(string.Format("https://webservices.amazon.{0}/onca/soap?Service=AWSECommerceService", country.ToString()))); // add authentication to the ECS client client.ChannelFactory.Endpoint.Behaviors.Add(new AmazonSigningEndpointBehavior(Aws1, Aws2)); ItemLookupResponse response = client.ItemLookup(itemLookup); if (response.Items.GetLength(0) > 0) { if (response.Items[0].Item != null) { if (response.Items[0].Item.GetLength(0) > 0) { Item item = response.Items[0].Item[0]; #region Actor bool isNew; if (item.ItemAttributes.Actor != null) { List <Artist> actors = item.ItemAttributes.Actor.Select(actor => ArtistServices.Get(actor, out isNew)).ToList(); objResults.Add("Actors", actors); } #endregion #region Album if (string.IsNullOrWhiteSpace(item.ItemAttributes.Title) == false) { objResults.Add("Album", item.ItemAttributes.Title); } #endregion #region AlternateVersions if (item.AlternateVersions != null) { if (item.AlternateVersions.GetLength(0) > 0) { objResults.Add("OriginalTitle", item.AlternateVersions[0].Title); } } #endregion #region Artist if (item.ItemAttributes.Artist != null) { if (item.ItemAttributes.Artist.GetLength(0) > 0) { if (MySettings.FastSearch == false && index == AmazonIndex.Music) { Artist artist = ArtistServices.Get(item.ItemAttributes.Artist[0], out isNew); GetArtistCredits(artist, index, country, 1); objResults.Add("Artist", artist); } else { objResults.Add("Artist", ArtistServices.Get(item.ItemAttributes.Artist[0], out isNew)); } } } #endregion #region AspectRatio if (string.IsNullOrWhiteSpace(item.ItemAttributes.AspectRatio) == false) { objResults.Add("DisplayAspectRatio", MovieServices.GetAspectRatio(item.ItemAttributes.AspectRatio)); } #endregion #region Author if (item.ItemAttributes.Author != null) { if (item.ItemAttributes.Author.GetLength(0) > 0) { if (MySettings.FastSearch == false && index == AmazonIndex.Books) { //Fix since 2.6.7.0 Artist artist = ArtistServices.Get(item.ItemAttributes.Author[0], out isNew); GetArtistCredits(artist, index, country, 1); objResults.Add("Author", artist); } else { objResults.Add("Author", ArtistServices.Get(item.ItemAttributes.Author[0], out isNew)); } } } #endregion #region Background if (item.ImageSets != null && item.LargeImage != null) { if (item.ImageSets.GetLength(0) > 0 && item.ImageSets[0].LargeImage.URL != item.LargeImage.URL) { objResults.Add("Background", item.ImageSets[0].LargeImage.URL); } else if (item.ImageSets.GetLength(0) > 1 && item.ImageSets[1].LargeImage.URL != item.LargeImage.URL) { objResults.Add("Background", item.ImageSets[1].LargeImage.URL); } } #endregion #region BarCode if (string.IsNullOrWhiteSpace(item.ItemAttributes.EAN) == false) { objResults.Add("BarCode", item.ItemAttributes.EAN); } else if (string.IsNullOrWhiteSpace(item.ItemAttributes.UPC) == false) { objResults.Add("BarCode", item.ItemAttributes.UPC); } else if (string.IsNullOrWhiteSpace(item.ASIN) == false) { objResults.Add("BarCode", item.ASIN); } #endregion #region Comments if (item.CustomerReviews != null) { if (item.CustomerReviews.HasReviews == true) { objResults.Add("Comments", Util.PurgeHtml(GetReview(item.CustomerReviews.IFrameURL, country))); } } #endregion #region Description if (item.EditorialReviews != null) { string description = string.Empty; foreach (EditorialReview edito in item.EditorialReviews) { if (edito.Content.Length > description.Length && edito.IsLinkSuppressed == false) { description = edito.Content; break; } } objResults.Add("Description", Util.PurgeHtml(description)); } #endregion #region Director if (item.ItemAttributes.Director != null) { List <Artist> directors = item.ItemAttributes.Director.Select(director => ArtistServices.Get(director, out isNew)).ToList(); objResults.Add("Director", directors); } #endregion #region Editor if (string.IsNullOrEmpty(item.ItemAttributes.Publisher) == false) { objResults.Add("Editor", item.ItemAttributes.Publisher); } if (objResults.ContainsKey("Editor") == false) { if (string.IsNullOrEmpty(item.ItemAttributes.Label) == false) { objResults.Add("Editor", item.ItemAttributes.Label); } } if (objResults.ContainsKey("Editor") == false) { if (string.IsNullOrEmpty(item.ItemAttributes.Manufacturer) == false) { objResults.Add("Editor", item.ItemAttributes.Manufacturer); } } if (objResults.ContainsKey("Editor") == false) { if (string.IsNullOrEmpty(item.ItemAttributes.Studio) == false) { objResults.Add("Editor", item.ItemAttributes.Studio); } } #endregion #region Format if (item.ItemAttributes.Format != null) { if (item.ItemAttributes.Format.GetLength(0) > 0) { objResults.Add("Format", item.ItemAttributes.Format[0]); } } #endregion #region Feature if (item.ItemAttributes.Feature != null) { if (item.ItemAttributes.Feature.GetLength(0) > 0) { if (objResults.ContainsKey("Description") == false) { objResults.Add("Description", item.ItemAttributes.Feature[0]); } else if (objResults.ContainsKey("Comments") == false) { objResults.Add("Comments", item.ItemAttributes.Feature[0]); } } } #endregion #region Image if (item.LargeImage != null) { objResults.Add("Image", item.LargeImage.URL); } #endregion #region ISBN if (string.IsNullOrWhiteSpace(item.ItemAttributes.ISBN) == false) { objResults.Add("ISBN", item.ItemAttributes.ISBN); } #endregion #region Language if (item.ItemAttributes.Languages != null) { if (item.ItemAttributes.Languages.GetLength(0) > 0) { objResults.Add("Language", item.ItemAttributes.Languages[0].Name); } } #endregion #region Links if (string.IsNullOrEmpty(item.DetailPageURL) == false) { objResults.Add("Links", item.DetailPageURL); } #endregion #region Pages if (string.IsNullOrEmpty(item.ItemAttributes.NumberOfPages) == false) { objResults.Add("Pages", item.ItemAttributes.NumberOfPages); } #endregion #region Platform if (item.ItemAttributes.Platform != null) { if (item.ItemAttributes.Platform.GetLength(0) > 0) { objResults.Add("Platform", item.ItemAttributes.Platform[0]); } } #endregion #region ProductGroup if (string.IsNullOrEmpty(item.ItemAttributes.ProductGroup) == false) { objResults.Add("ProductGroup", item.ItemAttributes.ProductGroup); } #endregion #region ProductTypeName if (string.IsNullOrEmpty(item.ItemAttributes.ProductTypeName) == false) { objResults.Add("ProductTypeName", item.ItemAttributes.ProductTypeName); } #endregion #region Price if (item.ItemAttributes.ListPrice != null) { objResults.Add("Price", item.ItemAttributes.ListPrice.Amount); } #endregion #region Rated if (string.IsNullOrEmpty(item.ItemAttributes.AudienceRating) == false) { if (item.ItemAttributes.AudienceRating.Contains("PG-13")) { objResults.Add("Rated", "PG-13"); } else if (item.ItemAttributes.AudienceRating.Contains("NC-17")) { objResults.Add("Rated", "NC-17"); } else if (item.ItemAttributes.AudienceRating.Contains("PG")) { objResults.Add("Rated", "PG"); } else if (item.ItemAttributes.AudienceRating.Contains("R")) { objResults.Add("Rated", "R"); } else if (item.ItemAttributes.AudienceRating.Contains("G") || item.ItemAttributes.AudienceRating.Contains("Tous publics")) { objResults.Add("Rated", "G"); } } #endregion #region Rating if (objResults.ContainsKey("Rating") == false) { if (item.CustomerReviews != null) { if (item.CustomerReviews.HasReviews == true) { objResults.Add("Rating", GetRating(item.CustomerReviews.IFrameURL)); } } } #endregion #region Released if (string.IsNullOrWhiteSpace(item.ItemAttributes.ReleaseDate) == false) { DateTime date; if (DateTime.TryParse(item.ItemAttributes.ReleaseDate, out date) == true) { objResults.Add("Released", date); } } else if (string.IsNullOrWhiteSpace(item.ItemAttributes.PublicationDate) == false) { DateTime date; if (DateTime.TryParse(item.ItemAttributes.PublicationDate, out date) == true) { objResults.Add("Released", date); } } #endregion #region RunTime if (item.ItemAttributes.RunningTime != null) { objResults.Add("Runtime", (int?)item.ItemAttributes.RunningTime.Value); } #endregion #region Studio if (string.IsNullOrWhiteSpace(item.ItemAttributes.Studio) == false) { objResults.Add("Studio", item.ItemAttributes.Studio); } #endregion #region Title if (string.IsNullOrWhiteSpace(item.ItemAttributes.Title) == false) { objResults.Add("Title", item.ItemAttributes.Title); } #endregion #region Tracks if (item.Tracks != null) { if (item.Tracks[0].Track.GetLength(0) > 0) { List <string> tracks = item.Tracks[0].Track.Select(node => node.Value).ToList(); objResults.Add("Tracks", tracks); } } #endregion #region Types if (item.BrowseNodes != null) { if (item.BrowseNodes.BrowseNode.GetLength(0) > 0) { List <string> types = new List <string>(); foreach (BrowseNode node in item.BrowseNodes.BrowseNode) { if (node.Ancestors.GetLength(0) > 0) { if (node.Ancestors[0].Name == "Genres" || node.Ancestors[0].Name == "Styles" || node.Ancestors[0].Name == "Nintendo DS" || node.Ancestors[0].Name == "Categories" || node.Ancestors[0].Name == "Categorías" || node.Ancestors[0].Name == "Thèmes" || node.Ancestors[0].Name == "Juegos" || node.Ancestors[0].Name == "Genre (theme_browse-bin)" || node.Ancestors[0].Name == "Les collections" || node.Ancestors[0].Name == "Literature & Fiction" || node.Ancestors[0].BrowseNodeId == "301138" || node.Ancestors[0].BrowseNodeId == "301134" || (node.Ancestors[0].BrowseNodeId == "425527031" && node.BrowseNodeId != "2486268031") || node.Ancestors[0].BrowseNodeId == "466276" || node.Ancestors[0].BrowseNodeId == "302068" || node.Ancestors[0].BrowseNodeId == "924340031" || node.Ancestors[0].BrowseNodeId == "301132" || node.Ancestors[0].BrowseNodeId == "2" || node.Ancestors[0].BrowseNodeId == "2396" || node.Ancestors[0].Name == "Literatura y ficción") { types.Add(node.Name); } else if (node.Ancestors[0].IsCategoryRoot == false && node.Ancestors[0].Ancestors != null) { if (node.Ancestors[0].Ancestors.GetLength(0) > 0) { if (node.Ancestors[0].Ancestors[0].Name == "Genres" || node.Ancestors[0].Name == "Nintendo DS" || node.Ancestors[0].Name == "Styles" || node.Ancestors[0].Name == "Categories" || node.Ancestors[0].Name == "Categorías" || node.Ancestors[0].Name == "Les collections" || node.Ancestors[0].Name == "Juegos" || node.Ancestors[0].Name == "Genre (theme_browse-bin)" || node.Ancestors[0].Name == "Literature & Fiction" || node.Ancestors[0].Name == "Literatura y ficción") { types.Add(node.Name); } } } } } objResults.Add("Types", types); } } #endregion } } } return(objResults); } catch (Exception ex) { Util.LogException(ex, asin); return(null); } }