private void ProcessXML()
        {
            log.Info("Start import of expert product reviews");
            AssortmentServiceSoapClient client = new AssortmentServiceSoapClient();

            var message = client.GetExpertProductReviews();

            XDocument reviews = XDocument.Parse(message);

            var productReviews = (from p in reviews.Element("ExpertReviews").Element("Products").Elements("Product")
                                  select new
            {
                ConcentratorID = int.Parse(p.Attribute("ID").Value),
                Reviews = from r in p.Element("Reviews").Elements("Review")
                          let sourceID = int.Parse(r.Attribute("SourceID").Value)
                                         select new
                {
                    CustomID = r.Attribute("ConcentratorID").Value,
                    SourceID = sourceID,
                    isSummary = bool.Parse(r.Attribute("isSummary").Value),
                    Author = r.Element("Author").Value,
                    Date = r.Element("Date").Value,
                    Title = r.Element("Title").Value,
                    Summary = r.Element("Summary").Value,
                    Verdict = r.Element("Verdict").Value,
                    ReviewURL = r.Element("ReviewURL").Value,
                    RatingImageURL = r.Element("RatingImageURL").Value,
                    Rating = r.Element("Rating").Try <XElement, int?>(c => int.Parse(c.Value), null),
                    Source = (from s in reviews.Element("ExpertReviews").Element("Sources").Elements("Source")
                              where int.Parse(s.Attribute("ID").Value) == sourceID
                              select new
                    {
                        Name = s.Element("Name").Value,
                        LanguageCode = s.Element("LanguageCode").Value,
                        CountryCode = s.Element("CountryCode").Value,
                        SourceURL = s.Element("SourceURL").Value,
                        SourceLogoURL = s.Element("SourceLogoURL").Value,
                        SourceRank = s.Element("SourceRank").Try <XElement, int?>(c => int.Parse(c.Value), null)
                    }).FirstOrDefault()
                }
            }
                                  );

            foreach (Connector connector in base.Connectors.Where(x => ((ConnectorType)x.ConnectorType).Has(ConnectorType.Reviews)))
            {
                log.InfoFormat("Start expert product review import for connector {0}", connector.Name);
                DateTime start = DateTime.Now;

                using (WebsiteDataContext context = new WebsiteDataContext(ConfigurationManager.ConnectionStrings[connector.Connection].ConnectionString))
                {
                    var productIDs = (from p in context.Products select p.ConcentratorProductID).ToList();
                    var sources    = (from s in context.ReviewSources select s).ToList();
                    productIDs.Sort();

                    foreach (var product in productReviews)
                    {
                        if (!productIDs.Contains(product.ConcentratorID))
                        {
                            continue;
                        }

                        var productItem = (from p in context.Products where p.ConcentratorProductID == product.ConcentratorID select p).FirstOrDefault();

                        foreach (var review in product.Reviews)
                        {
                            #region Source
                            var src = sources.FirstOrDefault(c => c.CustomSourceID == review.SourceID);
                            if (src == null)
                            {
                                src = new ReviewSource
                                {
                                    CustomSourceID = review.SourceID
                                };
                                context.ReviewSources.InsertOnSubmit(src);
                                sources.Add(src);
                            }
                            src.CountryCode   = review.Source.CountryCode;
                            src.LanguageCode  = review.Source.LanguageCode;
                            src.Name          = review.Source.Name;
                            src.SourceLogoUrl = review.Source.SourceLogoURL;
                            src.SourceRank    = review.Source.SourceRank;
                            src.SourceUrl     = review.Source.SourceURL;
                            #endregion

                            var reviewItem =
                                (from s in context.AlatestExpertReviews where s.CustomID == review.CustomID select s).FirstOrDefault();

                            if (reviewItem == null)
                            {
                                reviewItem = new AlatestExpertReview()
                                {
                                    Product      = productItem,
                                    ReviewSource = src,
                                    CustomID     = review.CustomID
                                };
                                context.AlatestExpertReviews.InsertOnSubmit(reviewItem);
                            }

                            reviewItem.Author = review.Author;

                            DateTime date;
                            DateTime.TryParse(review.Date, out date);
                            reviewItem.Date           = review.Date.Try <string, DateTime?>(c => DateTime.Parse(c), null);
                            reviewItem.isSummary      = review.isSummary;
                            reviewItem.Rating         = review.Rating;
                            reviewItem.RatingImageURL = review.RatingImageURL;
                            reviewItem.ReviewURL      = review.ReviewURL;
                            reviewItem.Summary        = review.Summary;
                            reviewItem.Title          = review.Title;
                            reviewItem.Verdict        = review.Verdict;
                        }
                    }
                    try
                    {
                        using (TransactionScope ts = new TransactionScope(TransactionScopeOption.Suppress, TimeSpan.FromMinutes(5)))
                        {
                            context.SubmitChanges();
                        }
                    }
                    catch (Exception e)
                    {
                        log.AuditError("Import of alatest expert reviews failed for connector: " + connector.Name, e,
                                       "Import Expert Reviews");
                    }
                }
            }
        }
        private void ImportFeed(IUnitOfWork unit, XDocument reviewsDoc)
        {
            var assortmentRepo = unit.Scope.Repository <VendorAssortment>();

            var products = assortmentRepo.GetAllAsQueryable().Select(c => c.CustomItemNumber).Distinct().ToList();

            var reviewSources = unit.Scope.Repository <ReviewSource>().GetAll().ToList();

            products.Sort();

            var rev = (from pr in reviewsDoc.Element("reviewsfeed").Element("products").Elements("product")
                       let root = reviewsDoc.Element("reviewsfeed")
                                  let alid = pr.Element("alid").Value
                                             let reviews = reviewsDoc.Element("reviewsfeed").Element("reviews").Elements("review").Where(c => c.Element("alid").Value == alid)
                                                           select new
            {
                CustomItemNumber = (from r in root.Element("productids").Elements("productid").Where(c => c.Element("alid").Value == alid)
                                    select r.Element("idvalue").Value).FirstOrDefault(),
                ReviewsCollection = (from m in reviews
                                     select new
                {
                    masterLineID = m.Element("masterlineid").Try(c => c.Value, string.Empty),
                    title = m.Try(c => c.Element("testtitle").Value, string.Empty),
                    sourceTestRating = m.Try <XElement, int?>(c => int.Parse(c.Element("sourcetestrating").Value), null),
                    language = m.Try(c => c.Element("language").Value, string.Empty),
                    author = m.Try(c => c.Element("author").Value, string.Empty),
                    date = m.Try <XElement, DateTime?>(c => DateTime.Parse(c.Element("testdate").Value), null),
                    source = (from s in reviewsDoc.Element("reviewsfeed").Element("sources").Elements("source")
                              where s.Element("sourceid").Value == m.Element("sourceid").Value
                              select new
                    {
                        sourceID = s.Element("sourceid").Try <XElement, int>(c => int.Parse(c.Value, 0)),
                        name = s.Element("name").Value,
                        countryCode = s.Try(c => c.Element("countrycode").Value, string.Empty),
                        languageCode = s.Try(c => c.Element("languagecode").Value, string.Empty),
                        sourceURL = s.Try(c => c.Element("sourcewww").Value, string.Empty),
                        sourceLogo = s.Try(c => c.Element("sourcelogo").Value, string.Empty),
                        sourceRank = s.Try <XElement, int?>(c => int.Parse(c.Element("sourcerank").Value), null)
                    }).FirstOrDefault(),
                    advanced = (m.Attribute("issummary") != null && m.Attribute("issummary").Try(c => bool.Parse(c.Value), false)) ?
                               new
                    {
                        ratingImageURL = m.Try(c => c.Element("ratingimage").Value, string.Empty),
                        summary = m.Try(c => c.Element("testsummary").Value, string.Empty),
                        verdict = m.Try(c => c.Element("testverdict").Value, string.Empty),
                        reviewUrl = m.Try(c => c.Element("reviewurl").Value, string.Empty)
                    } : null
                })
            });

            foreach (var productReview in rev)
            {
                string customItemNumber = productReview.CustomItemNumber;
                if (!products.Contains(customItemNumber))
                {
                    continue;
                }

                var product = assortmentRepo.GetSingle(v => v.CustomItemNumber == customItemNumber).Product;

                foreach (var review in productReview.ReviewsCollection)
                {
                    ReviewSource src = null;
                    if (review.source != null)
                    {
                        #region source

                        src = reviewSources.FirstOrDefault(c => c.CustomSourceID == review.source.sourceID);

                        if (src == null)
                        {
                            src = new ReviewSource()
                            {
                                CustomSourceID = review.source.sourceID
                            };
                            unit.Scope.Repository <ReviewSource>().Add(src);

                            reviewSources.Add(src);
                        }
                        src.Name          = review.source.name;
                        src.LanguageCode  = review.source.languageCode;
                        src.SourceLogoUrl = review.source.sourceLogo;
                        src.SourceUrl     = review.source.sourceURL;
                        src.SourceRank    = review.source.sourceRank;
                        src.CountryCode   = review.source.countryCode;

                        #endregion
                    }
                    #region review
                    var repoReview = unit.Scope.Repository <ProductReview>();
                    var rv         = repoReview.GetSingle(r => r.CustomID == review.masterLineID);

                    if (rv == null)
                    {
                        rv = new ProductReview()
                        {
                            ReviewSource = src,
                            Product      = product,
                            CustomID     = review.masterLineID
                        };
                        repoReview.Add(rv);
                    }

                    rv.Author = review.author;
                    rv.Date   = review.date;
                    if (review.advanced != null)
                    {
                        rv.IsSummary      = true;
                        rv.Summary        = review.advanced.summary;
                        rv.Verdict        = review.advanced.verdict;
                        rv.RatingImageURL = review.advanced.ratingImageURL;
                        rv.ReviewURL      = review.advanced.reviewUrl;
                    }
                    rv.Rating       = review.sourceTestRating;
                    rv.SourceRating = review.sourceTestRating;
                    #endregion
                }
            }
        }