Beispiel #1
0
        private TransferStatus TransferItems(string transferFile, List <PlayerItem> items)
        {
            var numReceived = items.Sum(item => Math.Max(1, item.StackCount));

            // Remove all items deposited (may or may not be less than the requested amount, if no inventory space is available)
            string error;
            int    numItemsReceived = (int)items.Sum(item => Math.Max(1, item.StackCount));

            _itemStatService.ApplyStatsToPlayerItems(items); // For item class? 'IsStackable' maybe?
            try {
                _transferStashService.Deposit(transferFile, items, out error);
                _dao.Update(items, true);

                var  numItemsAfterTransfer = items.Sum(item => item.StackCount);
                long numItemsTransferred   = numReceived - numItemsAfterTransfer;

                if (!string.IsNullOrEmpty(error))
                {
                    Logger.Warn(error);
                    _browser.ShowMessage(error, UserFeedbackLevel.Danger);
                }

                return(new TransferStatus {
                    NumItemsTransferred = (int)numItemsTransferred,
                });
            }
            catch (TransferStashService.DepositException) {
                _browser.ShowMessage(RuntimeSettings.Language.GetTag("iatag_feedback_unable_to_deposit"), UserFeedbackLevel.Danger);
                return(new TransferStatus {
                    NumItemsTransferred = 0,
                });
            }
        }
Beispiel #2
0
        public void Start()
        {
            // Queue any existing files
            foreach (var file in Directory.EnumerateFiles(GlobalPaths.CsvLocation))
            {
                _queue.Enqueue(new QueuedCsv {
                    Filename = file,
                    Cooldown = new ActionCooldown(0)
                });
            }


            // Process any newly added files. Threaded to ensure a proper delay between write and read.
            var t = new Thread(() => {
                ExceptionReporter.EnableLogUnhandledOnThread();

                while (!_isCancelled)
                {
                    Thread.Sleep(500);
                    if (!_queue.TryDequeue(out var entry))
                    {
                        continue;
                    }
                    try {
                        if (entry.Cooldown.IsReady)
                        {
                            PlayerItem item = Parse(File.ReadAllText(entry.Filename));
                            if (item == null)
                            {
                                continue;
                            }

                            // CSV probably wont have stackcount
                            item.StackCount   = Math.Max(item.StackCount, 1);
                            item.CreationDate = DateTime.UtcNow.ToTimestamp();

                            var classificationService = new ItemClassificationService(_cache, _playerItemDao);
                            classificationService.Add(item);

                            // Items to loot
                            if (classificationService.Remaining.Count > 0)
                            {
                                _playerItemDao.Save(item);
                                File.Delete(entry.Filename);

                                // Update replica reference
                                var hash = ItemReplicaService.GetHash(item);
                                _replicaItemDao.UpdatePlayerItemId(hash, item.Id);
                            }
                            else if (classificationService.Duplicates.Count > 0 && _settings.GetPersistent().DeleteDuplicates)
                            {
                                Logger.Info("Deleting duplicate item file");
                                File.Delete(entry.Filename);
                            }
                            else
                            {
                                // Transfer back in-game, should never have been looted.
                                // TODO: Separate transfer logic.. no delete-from-db etc..
                                if (RuntimeSettings.StashStatus == StashAvailability.CLOSED)
                                {
                                    string stashfile = _itemTransferController.GetTransferFile();
                                    _transferStashService.Deposit(stashfile, new List <PlayerItem> {
                                        item
                                    }, out string error);
                                    if (string.IsNullOrEmpty(error))
                                    {
                                        Logger.Info("Deposited item back in-game, did not pass item classification.");
                                        File.Delete(entry.Filename);
                                    }
                                    else
                                    {
                                        Logger.Warn("Failed re-depositing back into GD");
                                        _queue.Enqueue(entry);
                                    }
                                }
                                else
                                {
                                    _queue.Enqueue(entry);
                                }
                            }
                        }
                        else
                        {
                            _queue.Enqueue(entry);
                        }
                    }
                    catch (Exception ex) {
                        Logger.Warn("Error handling CSV item file", ex);
                    }
                }
            });

            t.Start();
        }