Ejemplo n.º 1
0
        private void buttonImport_Click(object sender, EventArgs e)
        {
            if (buttonImport.Enabled)
            {
                FileExporter io;

                if (radioIAStash.Checked)
                {
                    io = new IAFileExporter(_filename);
                }
                else if (radioGDStash.Checked)
                {
                    GDTransferFile settings = cbItemSelection.SelectedItem as GDTransferFile;
                    io = new GDFileExporter(_filename, settings?.Mod ?? string.Empty);
                }
                else
                {
                    _playerItemDao.Save(_sm.EmptyStash(_filename));

                    MessageBox.Show(
                        RuntimeSettings.Language.GetTag("iatag_ui_importexport_import_success"),
                        RuntimeSettings.Language.GetTag("iatag_ui_importexport_import_success"),
                        MessageBoxButtons.OK,
                        MessageBoxIcon.Information
                        );
                    return;
                }

                var items = io.Read(Read(_filename));
                Logger.Debug($"Storing {items.Count} items to db");
                progressBar1.Maximum = items.Count;
                buttonImport.Enabled = false;
                Thread t = new Thread(() => {
                    ExceptionReporter.EnableLogUnhandledOnThread();
                    isLocked = true;

                    var batches = BatchUtil.ToBatches <PlayerItem>(items);
                    foreach (var batch in batches)
                    {
                        _playerItemDao.Import(batch);
                        Invoke((MethodInvoker) delegate { progressBar1.Value += batch.Count; });
                    }

                    isLocked = false;
                    MessageBox.Show(
                        RuntimeSettings.Language.GetTag("iatag_ui_importexport_import_success_body"),
                        RuntimeSettings.Language.GetTag("iatag_ui_importexport_import_success"),
                        MessageBoxButtons.OK,
                        MessageBoxIcon.Information
                        );
                });

                t.Start();
            }
        }
Ejemplo n.º 2
0
        private void SyncDown(BuddySubscription subscription)
        {
            try {
                Logger.Debug("Checking buddy cloud for new items..");
                // Fetching the known IDs will allow us to skip the items we just uploaded. A massive issue if you just logged on and have 10,000 items for download.
                var knownItems = _buddyItemDao.GetOnlineIds(subscription);
                var sync       = Get(subscription);

                // Skip items we've already have
                var items = sync.Items
                            .Where(item => !knownItems.Contains(item.Id))
                            .Select(item => ToBuddyItem(subscription, item))
                            .ToList();


                // Store items in batches, to prevent IA just freezing up if we happen to get 10-20,000 items.
                var batches = BatchUtil.ToBatches <BuddyItem>(items);
                foreach (var batch in batches)
                {
                    Logger.Debug($"Storing batch of {batch.Count} items");
                    _buddyItemDao.Save(subscription, batch);
                }
                _buddyItemDao.UpdateNames(items);

                // Delete items that no longer exist
                _buddyItemDao.Delete(subscription, sync.Removed);

                // Store timestamp to db
                subscription.LastSyncTimestamp = sync.Timestamp;
                _subscriptionRepo.Update(subscription);


                Logger.Debug($"Fetched {items.Count} items, new timestamp is {sync.Timestamp}");
            }
            catch (AggregateException ex) {
                Logger.Warn(ex.Message, ex);
                return;
            }
            catch (WebException ex) {
                Logger.Warn(ex.Message, ex);
                return;
            }
            catch (Exception ex) {
                ExceptionReporter.ReportException(ex, "SyncDown");
                Logger.Warn(ex);
                return;
            }
        }