Ejemplo n.º 1
0
 public IList<DTO.ItemsPerCountry> GetImportedCountries()
 {
     IList<Model.GoogleTaxonomy> allTaxonomy = null;
     using (var om = new OperationManager())
     {
         try
         {
             om.BeginOperation();
             allTaxonomy = Repository.GetAll<Model.GoogleTaxonomy>().ToList();
             om.CommitOperation();
         }
         catch (Exception ex)
         {
             om.RollbackOperation();
             logger.Error(ex);
             throw ex;
         }
     }
     IList<DTO.ItemsPerCountry> taxonomyPerCountry = new List<DTO.ItemsPerCountry>();
     taxonomyPerCountry.Add(new DTO.ItemsPerCountry { CountryCode = "IT", Value = allTaxonomy.Count(t => !string.IsNullOrEmpty(t.Name_IT)) });
     taxonomyPerCountry.Add(new DTO.ItemsPerCountry { CountryCode = "US", Value = allTaxonomy.Count(t => !string.IsNullOrEmpty(t.Name_US)) });
     return taxonomyPerCountry;            
 }
Ejemplo n.º 2
0
 public DTO.ImportResult Import(Stream originalFile, string countryCode)
 {
     var result = new DTO.ImportResult();
     var lineNumber = 0;
     logger.Trace("Start importing google taxonomy file for {0}", countryCode);
     using (var reader = new StreamReader(originalFile))
     {
         do
         {
             lineNumber++;
             try
             {
                 string textLine = reader.ReadLine();
                 logger.Trace("Processing line: {0}", lineNumber);
                 string idstr = string.Empty;
                 var taxonomy = ParseLine(textLine, out idstr);
                 int id;
                 if (!string.IsNullOrEmpty(idstr) && !string.IsNullOrEmpty(taxonomy) && int.TryParse(idstr, out id))
                 {
                     using (var om = new OperationManager())
                     {
                         try
                         {
                             var session = om.BeginOperation();
                             var gtItem = session.Get<Model.GoogleTaxonomy>(id);
                             if (gtItem == null)
                             {
                                 logger.Trace("Item {0} not found... creating", id);
                                 gtItem = new Model.GoogleTaxonomy() { Id = id };
                             }
                             else 
                             {
                                 logger.Trace("Item {0} found... updating", id);
                             }
                             switch (countryCode)
                             {
                                 case "IT":
                                     gtItem.Name_IT = taxonomy;
                                     break;
                                 case "US":
                                     gtItem.Name_US = taxonomy;
                                     break;
                                 default:
                                     break;
                             }
                             Repository.SaveUpdate(gtItem);
                             om.CommitOperation();
                             result.Success++;
                             logger.Trace("Line {0} successfully processed", lineNumber);
                         }
                         catch (Exception ex)
                         {
                             om.RollbackOperation();
                             throw ex;
                         }
                     }
                     
                 }
                 else
                 {
                     result.Failure++;
                     logger.Trace("Error occurred on line {0}", lineNumber);
                 }
             }
             catch (Exception ex)
             {
                 result.Failure++;
                 var msg = string.Format("Error occurred on line {0}", lineNumber);
                 result.FailureDetails.Add(string.Format("{0} : {1}", msg, ex.Message));
                 logger.Error(ex, msg);
             }
         } while (reader.Peek() != -1);
         reader.Close();
     }
     return result;
 }
Ejemplo n.º 3
0
        public string GetTaxonomy(int googleTaxonomyId, string countryCode)
        {
            logger.Trace("Requested taxonomy translation for CategoryId = {0} and country {1}", googleTaxonomyId, countryCode);

            using (var om = new OperationManager())
            {
                try
                {
                    var session = om.BeginOperation();
                    var taxonomy = Repository.GetAll<Model.GoogleTaxonomy>().FirstOrDefault(gt => gt.Id == googleTaxonomyId);
                    om.CommitOperation();
                    if (taxonomy == null)
                    {
                        logger.Warn("Taxonomy label not loaded for id={0} , country={1}", googleTaxonomyId, countryCode);
                        return string.Empty;
                    }
                    var taxonomyLabel = string.Empty;
                    switch (countryCode)
                    {
                        case "IT":
                            taxonomyLabel = taxonomy.Name_IT;
                            break;
                        case "US":
                            taxonomyLabel = taxonomy.Name_US;
                            break;
                        default:
                            break;
                    }
                    logger.Trace("Taxonomy translation found: {0}", taxonomyLabel);
                    return taxonomyLabel;
                }
                catch (Exception ex)
                {
                    om.RollbackOperation();
                    string msg = String.Format("Error retrieving Google taxonomy value for id = {0} and country =  {1}", googleTaxonomyId, countryCode);
                    logger.Error(ex, msg);
                    throw new Exception(msg, ex);
                }
            }
        }