Example #1
0
        internal async Task <bool> DeleteLabel(Label label)
        {
            if (!await RefreshToken())
            {
                return(false);
            }

            MailApi api = new MailApi();

            int?charid  = (int?)mDBAccount.CharacterId;
            int?labelid = (int?)label.Id;

            try
            {
                await api.DeleteCharactersCharacterIdMailLabelsLabelIdAsync(
                    characterId : charid,
                    labelId : labelid,
                    datasource : ESIConfiguration.DataSource,
                    token : DBAccount.AccessToken);

                mLabels.Remove(label);
                ViewAccount.Sync(this);
                return(true);
            }
            catch (Eve.Api.Client.ApiException e)
            {
                ExceptionHandler.HandleApiException(null, e);
                return(false);
            }
        }
Example #2
0
        internal Account(EveMailClient client, DB.Account account)
        {
            mDBAccount = account;
            mClient    = client;

            mDraftLabel = new Label(mClient, this, -1, "Drafts", LabelType.Drafts);

            mEntityInfo.EntityType = EntityType.Character;
            mEntityInfo.EntityID   = account.CharacterId;
            mEntityInfo.Name       = account.CharacterName;
#if FAKE_NAMES
            GenerateFakeInfo();
#endif
            mLabels.Add(mDraftLabel);

            mViewAccount.RegisterHandler("IsExpanded", ViewAccount_IsExpandedChanged);

            mViewAccount.Sync(this);

            mClient.UpdateAccountOperationStarted += mClient_UpdateAccountOperationStarted;
            mClient.AccountRemoved += mClient_AccountRemoved;
        }
Example #3
0
        internal async Task <bool> AddLabel(string label_name)
        {
            if (!await RefreshToken())
            {
                return(false);
            }

            MailApi api = new MailApi();

            int?charid = (int?)mDBAccount.CharacterId;
            PostCharactersCharacterIdMailLabelsLabel label = new PostCharactersCharacterIdMailLabelsLabel(
                PostCharactersCharacterIdMailLabelsLabel.ColorEnum.Ffffff, label_name);

            try
            {
                int?labelid = await api.PostCharactersCharacterIdMailLabelsAsync(
                    characterId : charid,
                    label : label,
                    datasource : ESIConfiguration.DataSource,
                    token : DBAccount.AccessToken);

                if (!labelid.HasValue)
                {
                    return(false);
                }

                mLabels.Add(new Label(mClient, this, labelid ?? -1, label_name, LabelType.Label));
                ViewAccount.Sync(this);
                return(true);
            }
            catch (Eve.Api.Client.ApiException e)
            {
                ExceptionHandler.HandleApiException(null, e);
                return(false);
            }
        }
Example #4
0
        internal void UpdateAccountCounts(ViewMailItem item)
        {
            int[,] statetable = new int[, ]
            {
                //Label Added|Label Removed|No Change(True)|No Change(False)
                { 0, -1, -1, 0 }, /*Read Set*/
                { 1, 0, 1, 0 },   /*Read Unset*/
                { 1, -1, 0, 0 },  /*No Change(Unread)*/
                { 0, 0, 0, 0 }    /*No Change(Read)*/
            };

            int readstate = -1;

            if (item.MetaState.HasFlag(ViewMailMetaState.ReadFlagSet))
            {
                readstate = 0;
                UnreadCount--;
            }
            else if (item.MetaState.HasFlag(ViewMailMetaState.ReadFlagUnset))
            {
                readstate = 1;
                UnreadCount++;
            }
            else if (item.IsItemUnread)
            {
                readstate = 2;
            }
            else
            {
                readstate = 3;
            }

            if (UnreadCount < 0)
            {
                UnreadCount = 0;
            }

            for (int i = 0; i < item.Labels.Count; i++)
            {
                var vlabel = item.Labels[i];

                Label label      = ((ISourceInfo)vlabel.Label).LabelSource as Label;
                int   labelstate = -1;

                if (vlabel.MetaState.HasFlag(ViewMailMetaState.LabelAdded))
                {
                    labelstate = 0;
                }
                else if (vlabel.MetaState.HasFlag(ViewMailMetaState.LabelRemoved))
                {
                    labelstate = 1;
                }
                else if (vlabel.Subscribed)
                {
                    labelstate = 2;
                }
                else
                {
                    labelstate = 3;
                }



                label.UnreadCount += statetable[readstate, labelstate];

                MailCache cache = GetCache(label);

                if (cache != null && cache.IsValid)
                {
                    cache.MailItems.Remove(item);

                    if (vlabel.Subscribed)
                    {
                        cache.MailItems.Add(item);
                    }
                }
            }

            ViewAccount.Sync(this);
        }