Пример #1
0
        private void UnreadFutureReadMail()
        {
            var localMail = Repository.Instance.Fetch <Mail>(x =>
                                                             x.Status == MailStatus.Read &&
                                                             x.ToFarmerId == _farmerService.CurrentFarmer.Id
                                                             );

            if (!localMail.Any())
            {
                return;
            }
            var currentGameDateTime = ModHelper.GetGameDayTime();
            var futureMail          = localMail.Where(x => x.ReadInGameDate == null || x.ReadInGameDate > currentGameDateTime.GetNightBefore()).ToList();

            foreach (var mail in futureMail)
            {
                mail.Status         = MailStatus.Delivered;
                mail.ReadInGameDate = null;
            }

            if (!futureMail.Any())
            {
                return;
            }
            Repository.Instance.Upsert(futureMail.AsEnumerable());
        }
Пример #2
0
        private void MailComposed(object sender, MailComposedEventArgs e)
        {
            var toFarmerId = e.ToFarmerId;
            var fromFarmer = _farmerService.CurrentFarmer;
            var item       = e.Item;

            if (item == null)
            {
                return;
            }

            var messageText = string.Format(_messageFormat, fromFarmer.Name, item.ParentSheetIndex, item.Stack);

            // Consider: Moving this to own service
            var mail = new Mail()
            {
                Id                = Guid.NewGuid(),
                ToFarmerId        = toFarmerId,
                FromFarmerId      = fromFarmer.Id,
                Text              = messageText,
                CreatedDate       = DateTime.Now.ToUniversalTime(),
                Status            = MailStatus.Composed,
                CreatedInGameDate = ModHelper.GetGameDayTime()
            };

            Repository.Instance.Insert(mail);
            ModHelper.ShowInfoMessage(_letterPostedNotification);
        }
Пример #3
0
        private void MailRead(object sender, MailReadEventArgs e)
        {
            var currentFarmerId = _farmerService.CurrentFarmer.Id;
            var mail            = Repository.Instance.FirstOrDefault <Mail>(x => x.Id == e.Id);

            if (mail != null)
            {
                mail.Status         = MailStatus.Read;
                mail.ReadInGameDate = ModHelper.GetGameDayTime();
                Repository.Instance.Update(mail);
            }
        }
Пример #4
0
        private void DeleteFutureComposedMail()
        {
            var localMail = Repository.Instance.Fetch <Mail>(x =>
                                                             x.Status == MailStatus.Composed &&
                                                             x.ToFarmerId == _farmerService.CurrentFarmer.Id
                                                             );

            if (!localMail.Any())
            {
                return;
            }
            var currentGameDateTime = ModHelper.GetGameDayTime();
            var futureMail          = localMail.Where(x => x.CreatedInGameDate > currentGameDateTime.GetNightBefore()).ToList();

            foreach (var mail in futureMail)
            {
                Repository.Instance.Delete <Mail>(x => x.Id == mail.Id);
            }
        }
Пример #5
0
        private async Task DeleteReadMail()
        {
            var localMail = Repository.Instance.Fetch <Mail>(x =>
                                                             x.Status == MailStatus.Read &&
                                                             x.ToFarmerId == _farmerService.CurrentFarmer.Id
                                                             );

            if (!localMail.Any())
            {
                return;
            }

            var logPrefix = "[CleanRead] ";

            _mod.Monitor.Log($"{logPrefix}Clean up read cloud mail...", LogLevel.Debug);
            var currentGameDateTime = ModHelper.GetGameDayTime();
            var readMail            = localMail.Where(x => x.ReadInGameDate != null && x.ReadInGameDate <= currentGameDateTime.GetNightBefore()).ToList();

            if (readMail.Any())
            {
                _mod.Monitor.Log($"{logPrefix}.clearing {readMail.Count} read mail...", LogLevel.Debug);
                foreach (var mail in readMail)
                {
                    var deleted = await DeleteRemoteMail(mail, logPrefix);

                    if (deleted)
                    {
                        try
                        {
                            var i = Repository.Instance.Delete <Mail>(x => x.Id == mail.Id);
                        }
                        catch
                        {
                        }
                    }
                }
            }
            _mod.Monitor.Log($"{logPrefix}.done", LogLevel.Debug);
        }