Exemplo n.º 1
0
        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="esiKey">The ESI key.</param>
        /// <exception cref="System.ArgumentNullException">esiKey</exception>
        public EsiKeyDeletionWindow(ESIKey esiKey)
            : this()
        {
            esiKey.ThrowIfNull(nameof(esiKey), "ESI key can't be null");

            m_apiKey = esiKey;
        }
Exemplo n.º 2
0
        /// <summary>
        /// Updates the content.
        /// </summary>
        private void UpdateContent()
        {
            if (!Visible)
            {
                m_pendingUpdate = true;
                return;
            }
            m_pendingUpdate = false;

            int    scrollBarPosition = TopIndex;
            ESIKey oldSelection      = SelectedItem as ESIKey;

            BeginUpdate();
            try
            {
                Items.Clear();
                foreach (ESIKey apiKey in ESIKeys)
                {
                    Items.Add(apiKey);
                    if (apiKey == oldSelection)
                    {
                        SelectedIndex = Items.Count - 1;
                    }
                }
            }
            finally
            {
                EndUpdate();
                TopIndex = scrollBarPosition;
            }
        }
        /// <summary>
        /// Goes to the results page once the key has been received from the server.
        /// </summary>
        private void GoToResults(AccessResponse response)
        {
            // Fail if an empty response is received
            bool failed = string.IsNullOrEmpty(response?.AccessToken) || string.IsNullOrEmpty(
                response?.RefreshToken);

            // If the arguments have not been invalidated since the last time...
            if (m_creationArgs != null)
            {
                MultiPanel.SelectedPage = ResultPage;
            }
            else if (failed)
            {
                // Error when fetching the key
                KeyPicture.Image               = Resources.KeyWrong32;
                KeyLabel.Text                  = Properties.Resources.ErrorNoToken;
                CharactersGroupBox.Text        = @"Error report";
                ResultsMultiPanel.SelectedPage = ESITokenFailedErrorPage;
                MultiPanel.SelectedPage        = ResultPage;
                m_keyValid = false;
            }
            else
            {
                long newID = DateTime.UtcNow.ToFileTime();
                // Are we updating existing API key?
                if (m_updateMode)
                {
                    m_esiKey.TryUpdateAsync(response, OnUpdated);
                }
                else
                {
                    ESIKey.TryAddOrUpdateAsync(newID, response, OnUpdated);
                }
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// Creates a CHR format file for character exportation.
        /// </summary>
        /// <param name="character"></param>
        /// <param name="plan"></param>
        private static string ExportAsEFTCHR(Character character, Plan plan)
        {
            StringBuilder builder = new StringBuilder();

            foreach (SerializableCharacterSkill skill in character.Skills
                     .Where(x => x.IsPublic &&
                            x.Group.ID != DBConstants.CorporationManagementSkillsGroupID &&
                            x.Group.ID != DBConstants.SocialSkillsGroupID &&
                            x.Group.ID != DBConstants.TradeSkillsGroupID)
                     .Select(x => GetMergedSkill(plan, x)))
            {
                builder.AppendLine($"{skill.Name}={skill.Level}");
            }

            ESIKey apiKey = character.Identity.FindAPIKeyWithAccess(ESIAPICharacterMethods.CharacterSheet);

            if (apiKey == null)
            {
                return(builder.ToString());
            }

            builder
            .AppendLine($"KeyID={apiKey.ID}")
            .AppendLine($"VCode={apiKey.AccessToken}")
            .Append($"CharID={character.CharacterID}");

            return(builder.ToString());
        }
Exemplo n.º 5
0
        /// <summary>
        /// Queries the character's data. Used generically across multiple methods.
        /// </summary>
        /// <param name="targetMethod">The ESI method to use.</param>
        /// <param name="onError">The callback if an error occurs.</param>
        /// <param name="onSuccess">The callback if the request is successful.</param>
        private void QueryCharacterData <T>(ESIAPICharacterMethods targetMethod,
                                            CharacterQueryMonitor <T> .NotifyErrorCallback onError, Action <T> onSuccess)
            where T : class
        {
            ESIKey apiKey = m_ccpCharacter.Identity.FindAPIKeyWithAccess(targetMethod);

            // Network available, has access
            if (NetworkMonitor.IsNetworkAvailable && apiKey != null)
            {
                EveMonClient.APIProviders.CurrentProvider.QueryEsiAsync <T>(targetMethod,
                                                                            apiKey.AccessToken, m_ccpCharacter.CharacterID, (result, ignore) =>
                {
                    var target = m_ccpCharacter;

                    // Character may have been deleted or set to not be monitored
                    if (target != null && target.Monitored)
                    {
                        // Notify if an error occured
                        if (target.ShouldNotifyError(result, targetMethod))
                        {
                            onError.Invoke(target, result);
                        }
                        if (!result.HasError)
                        {
                            onSuccess.Invoke(result.Result);
                        }
                    }
                });
            }
        }
Exemplo n.º 6
0
        /// <summary>
        /// API key toolbar > Edit.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void editAPIKeyMenu_Click(object sender, EventArgs e)
        {
            ESIKey esiKey = esiKeysListBox.ESIKeys.ElementAt(esiKeysListBox.SelectedIndex);

            using (EsiKeyUpdateOrAdditionWindow window = new EsiKeyUpdateOrAdditionWindow(esiKey))
            {
                window.ShowDialog(this);
            }
        }
Exemplo n.º 7
0
        /// <summary>
        /// Called when the character list updated.
        /// </summary>
        /// <param name="esiKey">The ESI key.</param>
        internal static void OnCharacterListUpdated(ESIKey esiKey)
        {
            if (Closed)
            {
                return;
            }

            Trace(esiKey.ToString());
            Settings.Save();
            CharacterListUpdated?.ThreadSafeInvoke(null, new ESIKeyInfoChangedEventArgs(esiKey));
        }
Exemplo n.º 8
0
        /// <summary>
        /// Called when the ESI key info is updated.
        /// </summary>
        /// <param name="esiKey">The ESI key.</param>
        internal static void OnESIKeyInfoUpdated(ESIKey esiKey)
        {
            if (Closed)
            {
                return;
            }

            Trace(esiKey.ToString());
            Settings.Save();
            ESIKeyInfoUpdated?.ThreadSafeInvoke(null, EventArgs.Empty);
        }
Exemplo n.º 9
0
        /// <summary>
        /// Validates the operation and closes the window.
        /// </summary>
        private void Complete()
        {
            if (m_creationArgs == null)
            {
                return;
            }

            m_esiKey = m_creationArgs.CreateOrUpdate();

            // Closes the window
            Close();
        }
Exemplo n.º 10
0
        /// <summary>
        /// Called when an account status has been updated.
        /// </summary>
        /// <param name="esiKey">The ESI key.</param>
        internal static void OnAccountStatusUpdated(ESIKey esiKey)
        {
            if (Closed)
            {
                return;
            }

            Trace(esiKey.ToString());
            Characters.UpdateAccountStatuses();
            Settings.Save();
            AccountStatusUpdated?.ThreadSafeInvoke(null, EventArgs.Empty);
        }
Exemplo n.º 11
0
        /// <summary>
        /// Queries the character's attributes. Called on success or failure of implant
        /// import as attributes must be done second.
        /// </summary>
        private void QueryAttributesAsync(CCPCharacter target)
        {
            // This is only invoked where the character has already been checked against null
            ESIKey esiKey = target.Identity.FindAPIKeyWithAccess(ESIAPICharacterMethods.
                                                                 Attributes);

            if (esiKey != null)
            {
                EveMonClient.APIProviders.CurrentProvider.QueryEsiAsync <EsiAPIAttributes>(
                    ESIAPICharacterMethods.Attributes, esiKey.AccessToken, target.CharacterID,
                    OnCharacterAttributesUpdated);
            }
        }
Exemplo n.º 12
0
 /// <summary>
 /// Wraps citadel request info in a single state object.
 /// </summary>
 /// <param name="id">The citadel ID</param>
 /// <param name="key">The ESI key used to request</param>
 public CitadelRequestInfo(long id, ESIKey key)
 {
     if (id == 0L)
     {
         throw new ArgumentException("id");
     }
     if (key == null)
     {
         throw new ArgumentNullException("key");
     }
     ID  = id;
     Key = key;
 }
Exemplo n.º 13
0
        /// <summary>
        /// Goes to the results page once the key has been received from the server.
        /// </summary>
        private void GoToResults(JsonResult <AccessResponse> result)
        {
            bool           failed   = result.HasError;
            AccessResponse response = null;

            // Fail if an empty response is received
            if (!failed)
            {
                response = result.Result;
                if (string.IsNullOrEmpty(response?.AccessToken) || string.IsNullOrEmpty(
                        response?.RefreshToken))
                {
                    failed = true;
                }
            }

            // If the args have not been invalidated since the last time...
            if (m_creationArgs != null)
            {
                MultiPanel.SelectedPage = ResultPage;
                return;
            }

            if (failed)
            {
                Exception e = result.Exception;
                if (e != null)
                {
                    ExceptionHandler.LogException(e, true);
                }

                // Error when fetching the key
                KeyPicture.Image               = Resources.KeyWrong32;
                KeyLabel.Text                  = @"ESI token could not be obtained.";
                CharactersGroupBox.Text        = @"Error report";
                ResultsMultiPanel.SelectedPage = ESITokenFailedErrorPage;
                MultiPanel.SelectedPage        = ResultPage;
                return;
            }

            // Are we updating existing API key?
            if (m_updateMode)
            {
                m_esiKey.TryUpdateAsync(response, OnUpdated);
            }
            else
            {
                ESIKey.TryAddOrUpdateAsync(DateTime.UtcNow.ToFileTime(), response, OnUpdated);
            }
        }
Exemplo n.º 14
0
        /// <summary>
        /// Gets the icon.
        /// </summary>
        /// <param name="apiKey">The API key.</param>
        /// <returns></returns>
        private static Image GetIcon(ESIKey apiKey)
        {
            Image icon;

            if (apiKey.HasError)
            {
                icon = Resources.KeyWrong32;
            }
            else
            {
                icon = Resources.DefaultCharacterImage32;
            }
            return(icon);
        }
Exemplo n.º 15
0
        /// <summary>
        /// Queries the character's attributes. Called on success or failure of implant
        /// import as attributes must be done second.
        /// </summary>
        private void QueryAttributesAsync(CCPCharacter target)
        {
            // This is only invoked where the character has already been checked against null
            ESIKey esiKey = target.Identity.FindAPIKeyWithAccess(ESIAPICharacterMethods.
                                                                 Attributes);

            if (esiKey != null && !EsiErrors.IsErrorCountExceeded)
            {
                EveMonClient.APIProviders.CurrentProvider.QueryEsi <EsiAPIAttributes>(
                    ESIAPICharacterMethods.Attributes, OnCharacterAttributesUpdated,
                    new ESIParams(m_attrResponse, esiKey.AccessToken)
                {
                    ParamOne = target.CharacterID
                });
            }
        }
Exemplo n.º 16
0
        /// <summary>
        /// Accounts toolbar > Delete
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void deleteESIKeyMenu_Click(object sender, EventArgs e)
        {
            if (esiKeysListBox.SelectedIndex == -1)
            {
                return;
            }

            ESIKey apiKey = esiKeysListBox.ESIKeys.ElementAt(esiKeysListBox.SelectedIndex);

            using (EsiKeyDeletionWindow window = new EsiKeyDeletionWindow(apiKey))
            {
                window.ShowDialog(this);
            }

            deleteESIKeyMenu.Enabled = esiKeysListBox.SelectedIndex != -1;
            editESIKeyMenu.Enabled   = esiKeysListBox.SelectedIndex != -1;
        }
Exemplo n.º 17
0
        /// <summary>
        /// Queries the character's data.
        /// </summary>
        private void QueryCharacterData <T>(ESIAPICharacterMethods targetMethod,
                                            APIProvider.ESIRequestCallback <T> onUpdated) where T : class
        {
            // Quits if no network
            if (!NetworkMonitor.IsNetworkAvailable)
            {
                return;
            }

            // Quits if access denied
            ESIKey apiKey = m_ccpCharacter.Identity.FindAPIKeyWithAccess(targetMethod);

            if (apiKey == null)
            {
                return;
            }

            EveMonClient.APIProviders.CurrentProvider.QueryEsiAsync <T>(
                targetMethod, apiKey.AccessToken, m_ccpCharacter.CharacterID, onUpdated);
        }
Exemplo n.º 18
0
        /// <summary>
        /// Queries the character's contract bids.
        /// </summary>
        private void QueryCorporationContractBids()
        {
            // Quits if no network
            if (!NetworkMonitor.IsNetworkAvailable)
            {
                return;
            }

            // Quits if access denied
            ESIKey apiKey = m_ccpCharacter.Identity.FindAPIKeyWithAccess(CCPAPICorporationMethods.CorporationContracts);

            if (apiKey == null)
            {
                return;
            }

            EveMonClient.APIProviders.CurrentProvider.QueryEsiAsync <EsiAPIContractBids>(
                CCPAPICorporationMethods.CorporationContractBids, apiKey.AccessToken,
                m_ccpCharacter.CharacterID, OnCorporationContractBidsUpdated);
        }
Exemplo n.º 19
0
        /// <summary>
        /// Creates or updates the ESI key.
        /// </summary>
        /// <returns></returns>
        public ESIKey CreateOrUpdate()
        {
            // Checks whether this ESI key already exists to update it
            ESIKey esiKey = EveMonClient.ESIKeys[ID];

            if (esiKey != null)
            {
                esiKey.Update(this);

                // Fires the event regarding the ESI key info update
                EveMonClient.OnESIKeyInfoUpdated(esiKey);
            }
            else
            {
                esiKey = new ESIKey(ID);
                esiKey.Update(this);
                EveMonClient.ESIKeys.Add(esiKey);
            }

            return(esiKey);
        }
Exemplo n.º 20
0
        /// <summary>
        /// Performs the supplemental controls layout.
        /// </summary>
        private void PerformSupplementalControlsLayout()
        {
            // Skip if the user do not want to be warned about accounts not in training
            // No longer possible to determine since ESI keys are for only one character
#if false
            string warningMessage;
            if (Settings.UI.SystemTrayPopup.ShowWarning && ESIKey.HasCharactersNotTraining(out warningMessage))
            {
                FlowLayoutPanel warningPanel = CreateAccountsNotTrainingPanel(warningMessage);
                if (!MainFlowLayoutPanel.IsDisposed)
                {
                    MainFlowLayoutPanel.Controls.Add(warningPanel);
                }
            }
#endif

            // Server Status
            if (Settings.UI.SystemTrayPopup.ShowServerStatus)
            {
                m_serverStatusLabel.AutoSize = true;
                if (!MainFlowLayoutPanel.IsDisposed)
                {
                    MainFlowLayoutPanel.Controls.Add(m_serverStatusLabel);
                    UpdateServerStatusLabel();
                }
            }

            // EVE Time
            if (Settings.UI.SystemTrayPopup.ShowEveTime)
            {
                m_eveTimeLabel.AutoSize = true;
                if (!MainFlowLayoutPanel.IsDisposed)
                {
                    MainFlowLayoutPanel.Controls.Add(m_eveTimeLabel);
                    UpdateEveTimeLabel();
                }
            }
        }
Exemplo n.º 21
0
        /// <summary>
        /// Handles the MouseClick event of the apiKeysListBox control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.Windows.Forms.MouseEventArgs"/> instance containing the event data.</param>
        private void apiKeysListBox_MouseClick(object sender, MouseEventArgs e)
        {
            bool itemClicked = false;

            // Search for the clicked item
            for (int index = 0; index < esiKeysListBox.ESIKeys.Count(); index++)
            {
                Rectangle rect = esiKeysListBox.GetItemRectangle(index);

                // Did click occured generally on the item ?
                if (!rect.Contains(e.Location))
                {
                    continue;
                }

                itemClicked = true;

                int       yOffset = (rect.Height - EsiKeysListBox.CheckBoxSize.Height) / 2;
                Rectangle cbRect  = new Rectangle(rect.Left + esiKeysListBox.Margin.Left, rect.Top + yOffset,
                                                  EsiKeysListBox.CheckBoxSize.Width, EsiKeysListBox.CheckBoxSize.Height);
                cbRect.Inflate(2, 2);

                // Did click occured on the checkbox ?
                if (e.Button == MouseButtons.Middle || !cbRect.Contains(e.Location))
                {
                    continue;
                }

                ESIKey esiKey = esiKeysListBox.ESIKeys.ElementAt(index);
                esiKey.Monitored = !esiKey.Monitored;
                esiKeysListBox.Invalidate();
            }

            if (!itemClicked)
            {
                esiKeysListBox.SelectedIndex = -1;
            }
        }
Exemplo n.º 22
0
        /// <summary>
        /// Draws the ESI key info.
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The <see cref="System.Windows.Forms.DrawItemEventArgs"/> instance containing the event data.</param>
        private void OnDrawItem(object sender, DrawItemEventArgs e)
        {
            ItemHeight = m_boldFont.Height + m_middleFont.Height + m_smallBoldFont.Height * 2;

            // Background
            Graphics g          = e.Graphics;
            bool     isSelected = (e.State & DrawItemState.Selected) == DrawItemState.Selected;
            Brush    fontBrush  = isSelected ? SystemBrushes.HighlightText : SystemBrushes.ControlText;

            e.DrawBackground();

            if (e.Index < 0 || e.Index >= Items.Count)
            {
                return;
            }

            ESIKey esiKey = (ESIKey)Items[e.Index];
            Image  icon   = GetIcon(esiKey);

            Margin = new Padding((ItemHeight - icon.Height) / 2);
            int left = e.Bounds.Left + Margin.Left;
            int top  = e.Bounds.Top + Margin.Top / 4;

            // Draws the checbox
            CheckBoxRenderer.DrawCheckBox(g, new Point(left, (ItemHeight - CheckBoxSize.Height) / 2),
                                          esiKey.Monitored ? CheckBoxState.CheckedNormal : CheckBoxState.UncheckedNormal);
            left += CheckBoxSize.Width + Margin.Left * 2;

            // Draws the picture of the API key type
            g.DrawImage(icon, new Rectangle(left, top + Margin.Top, icon.Width, icon.Height));

            // Texts drawing
            DrawTexts(g, esiKey, left, top, fontBrush, icon);

            e.DrawFocusRectangle();
        }
Exemplo n.º 23
0
 /// <summary>
 /// Constructor for editing existing ESI credentials.
 /// </summary>
 /// <param name="esiKey"></param>
 public EsiKeyUpdateOrAdditionWindow(ESIKey esiKey)
     : this()
 {
     m_esiKey     = esiKey;
     m_updateMode = m_esiKey != null;
 }
 /// <summary>
 /// Constructor.
 /// </summary>
 /// <param name="apiKey"></param>
 internal CharacterIdentityIgnoreList(ESIKey apiKey)
 {
     m_owner = apiKey;
 }
Exemplo n.º 25
0
        /// <summary>
        /// Draws the texts.
        /// </summary>
        /// <param name="top">The top.</param>
        /// <param name="g">The g.</param>
        /// <param name="esiKey">The ESI key.</param>
        /// <param name="left">The left.</param>
        /// <param name="fontBrush">The font brush.</param>
        /// <param name="icon">The icon.</param>
        private void DrawTexts(Graphics g, ESIKey esiKey, int left, int top, Brush fontBrush, Image icon)
        {
            // Draws the texts on the upper third
            left += icon.Width + Margin.Left;

            // Api key ID
            string apiKeyId = esiKey.ID.ToString(CultureConstants.InvariantCulture);

            g.DrawString(apiKeyId, m_boldFont, fontBrush, new Point(left, top + 2));
            int indentedLeft = left + g.MeasureString(apiKeyId, m_boldFont).ToSize().Width + Margin.Left * 2;

            // Api key verification code
            string tokenText = string.IsNullOrEmpty(esiKey.AccessToken) ? "No access token" : "Access token present";

            g.DrawString(tokenText, Font, fontBrush, new Point(indentedLeft, top));
            indentedLeft += g.MeasureString(esiKey.AccessToken, Font).ToSize().Width + Margin.Left * 2;

            // Draw the texts on the middle third
            top += g.MeasureString(apiKeyId, Font).ToSize().Height;

#if false
            // Account header
            string accountHeader = "Account";
            g.DrawString(accountHeader, m_boldFont, fontBrush, new Point(left, top));
            indentedLeft = left + g.MeasureString(accountHeader, m_boldFont).ToSize().Width + Margin.Left * 2;

            // Account created
            string accountCreatedText = esiKey.AccountCreated != DateTime.MinValue
                ? esiKey.AccountCreated.ToLocalTime().ToString(CultureConstants.DefaultCulture)
                : "-";
            string accountCreated = $"Created: {accountCreatedText}";

            g.DrawString(accountCreated, m_middleFont, fontBrush, new Point(indentedLeft, top));
            indentedLeft += g.MeasureString(accountCreated, m_middleFont).ToSize().Width + Margin.Left * 2;

            // Account paid until
            string accountPaidUntilText = esiKey.AccountExpires != DateTime.MinValue
                ? esiKey.AccountExpires.ToLocalTime().ToString(CultureConstants.DefaultCulture)
                : "-";
            string accountPaidUntil = $"Paid Until: {accountPaidUntilText}";
            g.DrawString(accountPaidUntil, m_middleFont, fontBrush, new Point(indentedLeft, top));
            indentedLeft += g.MeasureString(accountPaidUntil, m_middleFont).ToSize().Width + Margin.Left * 2;

            // Account status header
            string accountStatusHeader = "Status: ";
            g.DrawString(accountStatusHeader, m_middleFont, fontBrush, new Point(indentedLeft, top));
            indentedLeft += g.MeasureString(accountStatusHeader, m_middleFont).ToSize().Width;

            // Account status body
            string accountStatusBody = esiKey.AccountExpires != DateTime.MinValue
                ? esiKey.AccountExpires > DateTime.UtcNow
                    ? "Active"
                    : "Expired"
                : "-";
            Brush accountStatusBrush = esiKey.AccountExpires != DateTime.MinValue
                ? new SolidBrush(esiKey.AccountExpires > DateTime.UtcNow ? Color.DarkGreen : Color.Red)
                : fontBrush;
            g.DrawString(accountStatusBody, m_middleFont, accountStatusBrush, new Point(indentedLeft, top));

            // Draws the texts on the lower third
            top += g.MeasureString(accountCreated, m_middleFont).ToSize().Height;
#endif
            bool isFirst = true;

            foreach (CharacterIdentity identity in esiKey.CharacterIdentities)
            {
                // Draws "; " between ids
                if (!isFirst)
                {
                    g.DrawString("; ", m_smallFont, fontBrush, new Point(left, top));
                    left += g.MeasureString("; ", Font).ToSize().Width;
                }
                isFirst = false;

                // Selects font
                Font         font         = m_smallFont;
                CCPCharacter ccpCharacter = identity.CCPCharacter;
                if (ccpCharacter != null && ccpCharacter.Monitored)
                {
                    font = m_smallBoldFont;
                }

                // Draws character's name
                g.DrawString(identity.CharacterName, font, fontBrush, new Point(left, top));
                left += g.MeasureString(identity.CharacterName, font).ToSize().Width;
            }
        }
Exemplo n.º 26
0
 /// <summary>
 /// Constructor.
 /// </summary>
 /// <param name="apiKey"></param>
 /// <param name="method"></param>
 /// <param name="onUpdated"></param>
 internal ESIKeyQueryMonitor(ESIKey apiKey, Enum method, Action <EsiResult <T> > onUpdated)
     : base(method, onUpdated)
 {
     m_esiKey = apiKey;
 }
Exemplo n.º 27
0
 /// <summary>
 /// Constructor.
 /// </summary>
 /// <param name="esiKey"></param>
 public ESIKeyInfoChangedEventArgs(ESIKey esiKey)
 {
     ESIKey = esiKey;
 }