Ejemplo n.º 1
0
 public Printer(string dbPath)
 {
     if (File.Exists(dbPath) && dbPath.EndsWith(".db"))
     {
         string newConnectionString = ConnectionTools.ModifyDatabaseConnectionString(connectionStringName, dataSource: dbPath);
         string oldConnectionString = ConfigurationManager.ConnectionStrings[connectionStringName].ConnectionString;
         if (oldConnectionString == newConnectionString)
         {
             return;
         }
         ConnectionTools.ChangeConnectionString(newConnectionString, connectionStringName);
         using (IADbContext dbContext = new IADbContext())
         {
             if (!dbContext.Database.Exists())
             {
                 ConnectionTools.ChangeConnectionString(oldConnectionString, connectionStringName);
                 throw new FileNotFoundException();
             }
         }
     }
     else
     {
         throw new FileNotFoundException();
     }
 }
Ejemplo n.º 2
0
 public string Print(PrinterConfig config = null)
 {
     if (config == null)
     {
         config = new PrinterConfig();
     }
     using (IADbContext dbContext = new IADbContext())
     {
         if (!dbContext.Database.Exists())
         {
             log.Warn("Db not found.");
             return("");
         }
         List <PlayerItem> itemResult = new List <PlayerItem>();
         try
         {
             IQueryable <PlayerItem> items = dbContext.PlayerItem;
             items      = FilterItems(items, config, dbContext);
             itemResult = items.ToList();
             log.Info("LoadedPlayerItems");
         }
         catch (Exception ex)
         {
             log.Error("Error fetching playeritems. Most likely path to db is incorrect.", ex);
             return("");
         }
         log.Info("Formatting");
         ItemContainer container    = new ItemContainer(itemResult);
         string        stringResult = ResultFormatter.FormatResult(container, config);
         log.Info("Writing output");
         CreateOutputFile(stringResult, config);
         log.Info("Printer Finished");
         return(stringResult);
     }
 }
Ejemplo n.º 3
0
        private IQueryable <PlayerItem> FilterItems(IQueryable <PlayerItem> items, PrinterConfig config, IADbContext dbContext)
        {
            items = items.Where(e => e.LevelRequirement >= config.ItemLevel);
            List <string> rarityFilter = config.RarityToFilterList();

            if (rarityFilter != null)
            {
                items = items.Where(e => rarityFilter.Contains(e.Rarity) && e.Rarity != "Unknown");
            }
            if (config.Rarity != RarityEnum.Purple && config.ExcludedGreens != null && config.ExcludedGreens.Count > 0)
            {
                var excludedItemIds = dbContext.PlayerItem.Where(e => config.ExcludedGreens.Any(x => e.namelowercase.Contains(x)) && e.Rarity == "Green").Select(e => e.Id);
                items = items.Where(e => !excludedItemIds.Contains(e.Id));
            }
            return(items);
        }