public static async Task <bool> ImportWithHearthmirror(PluginSettings theSettings)
        {
            var importObject = new HearthstoneImporter();

            try
            {
                var collection     = importObject.Import();
                var setChangesList = new List <BasicSetCollectionInfo>();
                foreach (var set in collection)
                {
                    var existingSet = theSettings.ActiveAccountSetsInfo.FirstOrDefault(s => s.CardSet == set.CardSet);
                    if (existingSet == null)
                    {
                        theSettings.ActiveAccountSetsInfo.Add(set);
                    }
                    else
                    {
                        var setChanges = setChangesList.FirstOrDefault(s => s.CardSet == set.CardSet) ?? new BasicSetCollectionInfo {
                            CardSet = set.CardSet, Cards = new List <CardInCollection>(),
                        };
                        // keep desired amount
                        foreach (var card in set.Cards)
                        {
                            var existingCardInfo = existingSet.Cards.FirstOrDefault(c => c.CardId == card.CardId);
                            if (existingCardInfo != null)
                            {
                                card.DesiredAmount = existingCardInfo.DesiredAmount;
                                if (card.AmountNonGolden != existingCardInfo.AmountNonGolden || card.AmountGolden != existingCardInfo.AmountGolden)
                                {
                                    setChanges?.Cards.Add(new CardInCollection(card.Card, card.AmountNonGolden - existingCardInfo.AmountNonGolden, card.AmountGolden - existingCardInfo.AmountGolden));
                                }
                            }
                        }
                        existingSet.Cards = set.Cards;
                        if (setChanges.Cards.Count > 0)
                        {
                            setChangesList.Add(setChanges);
                        }
                    }
                }
                if (theSettings.EnableImportHistory)
                {
                    ImportHistory.SaveChange(theSettings.Accounts.FirstOrDefault(a => a.AccountName == theSettings.ActiveAccount), setChangesList);
                }
            }
            catch (ImportingException)
            {
                return(false);
            }


            // save imported collection
            HearthstoneCollectionTrackerPlugin.Settings.SaveCurrentAccount();
            return(true);
        }
Beispiel #2
0
        private void buttonImport_Click(object sender, EventArgs e)
        {
            var itm = (from EDCommander c in EDCommander.GetList() where c.Name.Equals(comboBoxCommander.Text) select c).ToList();

            if (itm == null || itm.Count == 0)
            {
                ExtendedControls.MessageBoxTheme.Show("Code failure - cannot find selected commander", "EDD Import", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }

            long cmdrID = itm[0].Nr;

            if (string.IsNullOrEmpty(importFile) || !File.Exists(importFile))
            {
                ExtendedControls.MessageBoxTheme.Show("An import file must be specified.", "EDD Import", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }

            string delim = radioButtonTab.Checked ? "\t" : textBoxDelimiter.Text;

            if (string.IsNullOrEmpty(delim))
            {
                ExtendedControls.MessageBoxTheme.Show("A delimiter must be defined.", "EDD Import", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }
            int?datecol = string.IsNullOrEmpty(textBoxArrivalDate.Text) ? null : (int?)int.Parse(textBoxArrivalDate.Text);
            int?timecol = string.IsNullOrEmpty(textBoxArrivalTime.Text) ? null : (int?)int.Parse(textBoxArrivalTime.Text);
            int?namecol = string.IsNullOrEmpty(textBoxSysName.Text) ? null : (int?)int.Parse(textBoxSysName.Text);
            int?notecol = string.IsNullOrEmpty(textBoxSysNotes.Text) ? null : (int?)int.Parse(textBoxSysNotes.Text);

            if (!namecol.HasValue)
            {
                ExtendedControls.MessageBoxTheme.Show("System Name column must be defined.", "EDD Import", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }
            if (!datecol.HasValue && !notecol.HasValue)
            {
                ExtendedControls.MessageBoxTheme.Show("At least one of arrival date and system note columns must be defined.", "EDD Import", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }
            ImportHistory ih = new ImportHistory(importFile, delim, datecol, timecol, namecol, notecol, checkBoxImpHeader.Checked, cmdrID);
            string        result;

            if (ih.Import(out result))
            {
                ExtendedControls.MessageBoxTheme.Show("Import successful.", "EDD Import", MessageBoxButtons.OK, MessageBoxIcon.None);
                _discoveryForm.RefreshHistoryAsync();
            }
            else
            {
                ExtendedControls.MessageBoxTheme.Show("Import failed: " + result, "EDD Import", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            ih = null;
        }
Beispiel #3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="importHistory"></param>
        /// <returns></returns>
        public TaskResult Add(ImportHistory importHistory)
        {
            Logger.Info($"adding new import history: {importHistory}");
            var response = this.Entities.PutAsync(importHistory.Id, importHistory);
            var result   = new TaskResult {
                IsSuccessful = true
            };

            Logger.Info($"add completed. reason {response.Result.Reason}");
            return(result);
        }
Beispiel #4
0
        protected override void ExecuteWorkImplementation()
        {
            var externalRepository = m_externalRepositoryRepository.FindById <ExternalRepository>(m_externalRepositoryId);

            if (externalRepository == null)
            {
                throw new MainServiceException(MainServiceErrorCode.EntityNotFound, "The entity was not found.");
            }

            TotalImportStatistics      = m_externalRepositoryRepository.GetExternalRepositoryStatistics(m_externalRepositoryId);
            LastImportStatisticsResult = m_externalRepositoryRepository.GetLastUpdateExternalRepositoryStatistics(m_externalRepositoryId);
            LastImportHistory          = m_importHistoryRepository.GetLastImportHistory(m_externalRepositoryId);
        }
Beispiel #5
0
        private void buttonImport_Click(object sender, EventArgs e)
        {
            long cmdrID = long.Parse(comboBoxCommander.SelectedValue.ToString());

            if (string.IsNullOrEmpty(importFile) || !File.Exists(importFile))
            {
                EDDiscovery.Forms.MessageBoxTheme.Show("An import file must be specified.", "EDD Import", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }
            string delim = radioButtonTab.Checked ? "\t" : textBoxDelimiter.Text;

            if (string.IsNullOrEmpty(delim))
            {
                EDDiscovery.Forms.MessageBoxTheme.Show("A delimiter must be defined.", "EDD Import", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }
            int?datecol = string.IsNullOrEmpty(textBoxArrivalDate.Text) ? null : (int?)int.Parse(textBoxArrivalDate.Text);
            int?timecol = string.IsNullOrEmpty(textBoxArrivalTime.Text) ? null : (int?)int.Parse(textBoxArrivalTime.Text);
            int?namecol = string.IsNullOrEmpty(textBoxSysName.Text) ? null : (int?)int.Parse(textBoxSysName.Text);
            int?notecol = string.IsNullOrEmpty(textBoxSysNotes.Text) ? null : (int?)int.Parse(textBoxSysNotes.Text);

            if (!namecol.HasValue)
            {
                EDDiscovery.Forms.MessageBoxTheme.Show("System Name column must be defined.", "EDD Import", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }
            if (!datecol.HasValue && !notecol.HasValue)
            {
                EDDiscovery.Forms.MessageBoxTheme.Show("At least one of arrival date and system note columns must be defined.", "EDD Import", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }
            ImportHistory ih = new ImportHistory(importFile, delim, datecol, timecol, namecol, notecol, checkBoxImpHeader.Checked, cmdrID);

            _discoveryForm.ShowInfoPanel("Importing, please wait...", true, Color.Gold);
            string result;

            if (ih.Import(out result))
            {
                EDDiscovery.Forms.MessageBoxTheme.Show("Import successful.", "EDD Import", MessageBoxButtons.OK, MessageBoxIcon.None);
                _discoveryForm.RefreshHistoryAsync();
            }
            else
            {
                EDDiscovery.Forms.MessageBoxTheme.Show("Import failed: " + result, "EDD Import", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            _discoveryForm.ShowInfoPanel("", false);
            ih = null;
        }
        protected override int ExecuteWorkImplementation()
        {
            var now  = DateTime.UtcNow;
            var user = m_importHistoryRepository.Load <User>(m_userId);
            var externalRepository = m_importHistoryRepository.Load <ExternalRepository>(m_externalRepositoryId);

            var importHistory = new ImportHistory
            {
                Date = now,
                ExternalRepository = externalRepository,
                Status             = ImportStatusEnum.Running,
                CreatedByUser      = user
            };

            return((int)m_importHistoryRepository.Create(importHistory));
        }
Beispiel #7
0
        public ImportHistory RunImport(string folderName)
        {
            var import = new ImportHistory
            {
                PerformedDate = DateTime.Now,
                FolderName    = folderName
            };
            var dailyInputs = InputDataReader.ReadFromFolder(folderName);

            import.DateFrom = dailyInputs.Min(di => di.Day);
            import.DateTo   = dailyInputs.Max(di => di.Day);

            ImportDays(dailyInputs);
            ImportCompanies(dailyInputs);
            ImportPrices(dailyInputs);

            Repository.Insert(import);
            return(import);
        }
        public virtual LastImportStatisticsResult GetLastUpdateExternalRepositoryStatistics(int repositoryId)
        {
            ExternalRepository     externalRepository     = null;
            ImportHistory          importHistory1         = null;
            ImportHistory          importHistory2         = null;
            ImportedRecordMetadata importedRecordMetadata = null;
            Snapshot snapshot = null;
            LastImportStatisticsResult lastImportStatisticsResult = null;

            var subQuery = QueryOver.Of(() => importHistory2).Where(x => x.ExternalRepository.Id == repositoryId)
                           .OrderBy(x => x.Date).Desc
                           .Select(x => x.Id)
                           .Take(1);

            var result = GetSession().QueryOver(() => importHistory1)
                         .JoinAlias(() => importHistory1.ExternalRepository, () => externalRepository)
                         .JoinAlias(() => importHistory1.ImportedRecordMetadata, () => importedRecordMetadata, JoinType.LeftOuterJoin)
                         .JoinAlias(() => importedRecordMetadata.Snapshot, () => snapshot, JoinType.LeftOuterJoin)
                         .WithSubquery
                         .WhereProperty(() => importHistory1.Id).Eq(subQuery)
                         .SelectList(list => list
                                     .SelectCount(() => importedRecordMetadata.Id)
                                     .WithAlias(() => lastImportStatisticsResult.TotalItems)
                                     .Select(
                                         Projections.Sum(Projections.Conditional(
                                                             Restrictions.Eq(
                                                                 Projections.Property(() => snapshot.VersionNumber), 1),
                                                             Projections.Constant(1, NHibernateUtil.Int32),
                                                             Projections.Constant(0, NHibernateUtil.Int32))))
                                     .WithAlias(() => lastImportStatisticsResult.NewItems)
                                     .Select(
                                         Projections.Sum(Projections.Conditional(
                                                             Restrictions.Gt(
                                                                 Projections.Property(() => snapshot.VersionNumber), 1),
                                                             Projections.Constant(1, NHibernateUtil.Int32),
                                                             Projections.Constant(0, NHibernateUtil.Int32)))
                                         .WithAlias(() => lastImportStatisticsResult.UpdatedItems)))
                         .TransformUsing(Transformers.AliasToBean <LastImportStatisticsResult>())
                         .SingleOrDefault <LastImportStatisticsResult>();

            return(result);
        }
Beispiel #9
0
 public void Update(ImportHistory item)
 {
     _importHistoryRep.Update(item);
 }
Beispiel #10
0
 public ImportHistory Add(ImportHistory item)
 {
     _importHistoryRep.Add(item);
     return(item);
 }
Beispiel #11
0
 public void UpdateImportHistory(ImportHistory importHistory)
 {
     m_importHistoryRepository.InvokeUnitOfWork(x => x.Update(importHistory));
 }