예제 #1
0
        private async Task LoadDataAsync(EntityData data, bool lookupname)
        {
            if (lookupname)
            {
                await mClient.AddLookupAsync(data.Subject);
            }
            switch (data.Subject.Type)
            {
            case EntityType.Character:
                await LoadCharacterData((CharacterData)data);

                break;

            case EntityType.Corporation:
                await LoadCorporationData((CorporationData)data);

                break;

            case EntityType.Alliance:
                await LoadAllianceData((AllianceData)data);

                break;
            }

            await mClient.FinishLookupsAsync();
        }
예제 #2
0
        private async Task <List <ViewMailItem> > LoadMailsWorker(ILabelSource label, ISourceInfo source, int?from = null, long?to = null, bool fresh = false)
        {
            List <int?> labels = null;

            if (label != null && !label.IsVirtual)
            {
                labels = new List <int?>();
                labels.Add(label.Id);
            }

            MailApi api = new MailApi();

            int id = (int)DBAccount.CharacterId;

            List <GetCharactersCharacterIdMail200Ok> mails;

            mails = await api.GetCharactersCharacterIdMailAsync(
                characterId : id,
                datasource : ESIConfiguration.DataSource,
                labels : labels,
                lastMailId : from,
                token : DBAccount.AccessToken);

            List <ViewMailItem>  viewmails  = new List <ViewMailItem>();
            List <MailRecipient> recipients = new List <MailRecipient>();

            foreach (var i in mails)
            {
                if (!i.MailId.HasValue)
                {
                    continue;
                }

                if (to.HasValue && to.Value == i.MailId.Value)
                {
                    break;
                }

                if (label != null && label.Type == LabelType.MailingList)
                {
                    if (!HasRecipient(i, EntityType.Mailinglist, label.Id))
                    {
                        continue;
                    }
                }

                recipients.Clear();

                ViewMailItem item;

                if (!fresh && GetItemFromCache(i.MailId.Value, out item))
                {
                    viewmails.Add(item);
                    continue;
                }
                item        = new ViewMailItem(i.MailId.Value, i.IsRead.HasValue && i.IsRead.Value);
                item.Source = source;
                item.From   = new MailRecipient(EntityType.Character, i.From.HasValue ? i.From.Value : -1);
                await mClient.AddLookupAsync(item.From);

                item.MailSubject = i.Subject;
                item.Timestamp   = i.Timestamp.HasValue ? i.Timestamp.Value : DateTime.MinValue;

                foreach (var j in i.Recipients)
                {
                    MailRecipient recipient = new MailRecipient(ESIConvert.RecipientTypeToEntityType(j.RecipientType.GetValueOrDefault()), j.RecipientId.Value);
                    recipients.Add(recipient);
                }

                foreach (var j in mViewAccount.Labels)
                {
                    if (j.IsVirtual)
                    {
                        continue;
                    }

                    item.Labels.Add(new ViewMailLabelLink(item, j, i.Labels.Contains(j.Id), label != null && label.Id == j.Id));
                }

                item.Recipients = recipients.ToArray();

                viewmails.Add(item);
            }

            await mClient.FinishLookupsAsync();

            return(viewmails);
        }