Exemplo n.º 1
0
        /// <summary>
        /// Creates the character.
        /// </summary>
        public UriCharacter CreateCharacter()
        {
            CharacterIdentity identity = GetIdentity(m_result);

            // Instantiates characters, adds, notify
            UriCharacter uriCharacter = m_apiResult != null
                                            ? new UriCharacter(identity, Uri, m_apiResult)
                                            : new UriCharacter(identity, Uri, m_result as SerializableSettingsCharacter);

            EveMonClient.Characters.Add(uriCharacter);

            return(uriCharacter);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Adds the blank character.
        /// </summary>
        public static async Task AddBlankCharacterAsync(Action callback)
        {
            // Add blank character
            var result = await GlobalCharacterCollection.TryAddOrUpdateFromUriAsync(new Uri(s_filename));

            if (result == null || result.HasError)
            {
                return;
            }

            UriCharacter character = result.CreateCharacter();

            character.Monitored = true;

            callback.Invoke();
        }
Exemplo n.º 3
0
        /// <summary>
        /// Updates the given character.
        /// </summary>
        /// <param name="character"></param>
        /// <exception cref="System.ArgumentNullException">character</exception>
        public void UpdateCharacter(UriCharacter character)
        {
            character.ThrowIfNull(nameof(character));

            CharacterIdentity identity = GetIdentity(m_result);

            // Updates
            if (m_apiResult != null)
            {
                character.Update(identity, Uri, m_apiResult);
            }
            else
            {
                SerializableCCPCharacter ccpCharacter = m_result as SerializableCCPCharacter;
                character.Update(identity, Uri, ccpCharacter);
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// Constructor to update a character.
        /// </summary>
        public CharacterImportationWindow(UriCharacter character)
        {
            InitializeComponent();
            errorPanel.Visible = false;
            namePanel.Visible  = false;
            okButton.Enabled   = false;

            m_character = character;
            if (m_character.Uri.IsFile)
            {
                fileTextBox.Text  = m_character.Uri.ToString();
                fileRadio.Checked = true;
            }
            else
            {
                urlTextBox.Text  = m_character.Uri.ToString();
                urlRadio.Checked = true;
            }
        }
Exemplo n.º 5
0
        /// <summary>
        /// When the user clicks the OK button, we may have to generate the character
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void okButton_Click(object sender, System.EventArgs e)
        {
            // Shouldn't occur but, well...
            if (m_args == null || m_args.HasError)
            {
                this.DialogResult = DialogResult.Cancel;
                return;
            }

            // Generates or updates the character
            if (m_character == null)
            {
                m_character = m_args.CreateCharacter();
            }
            else
            {
                m_args.UpdateCharacter(m_character);
            }
            m_character.Name = nameTextBox.Text;

            this.DialogResult = DialogResult.OK;
        }
Exemplo n.º 6
0
        /// <summary>
        /// Characters toolbar > Edit Uri...
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void editUriButton_Click(object sender, EventArgs e)
        {
            // Retrieve the selected URI character
            if (charactersListView.SelectedItems.Count == 0)
            {
                return;
            }

            ListViewItem item         = charactersListView.SelectedItems[0];
            UriCharacter uriCharacter = item.Tag as UriCharacter;

            // Returns if the selected item is not an Uri character
            if (uriCharacter == null)
            {
                return;
            }

            // Opens the importation form
            using (CharacterImportationWindow form = new CharacterImportationWindow(uriCharacter))
            {
                form.ShowDialog(this);
            }
        }
Exemplo n.º 7
0
        /// <summary>
        /// Arranges the by group.
        /// </summary>
        /// <param name="fileGroup">The file group.</param>
        /// <param name="esiKeyGroups">The ESI key groups.</param>
        /// <param name="noESIKeyGroup">The no ESI key group.</param>
        /// <param name="urlGroup">The URL group.</param>
        private void ArrangeByGroup(ListViewGroup fileGroup, Dictionary <ESIKey, ListViewGroup> esiKeyGroups,
                                    ListViewGroup noESIKeyGroup, ListViewGroup urlGroup)
        {
            bool hasNoESIKey  = false;
            bool hasFileChars = false;
            bool hasUrlChars  = false;

            // Scroll through listview items to gather the groups
            foreach (Character character in EveMonClient.Characters)
            {
                UriCharacter uriCharacter = character as UriCharacter;

                // Uri character ?
                if (uriCharacter != null)
                {
                    if (uriCharacter.Uri.IsFile)
                    {
                        hasFileChars = true;
                    }
                    else
                    {
                        hasUrlChars = true;
                    }
                }
                // CCP character ?
                else
                {
                    if (!character.Identity.ESIKeys.Any())
                    {
                        hasNoESIKey = true;
                    }
                    else
                    {
                        foreach (ESIKey apiKey in character.Identity.ESIKeys.Where(
                                     esiKey => !esiKeyGroups.ContainsKey(esiKey)))
                        {
                            esiKeyGroups.Add(apiKey, new ListViewGroup($"Key ID #{apiKey.ID}"));
                        }
                    }
                }
            }

            // Add the groups
            if (hasNoESIKey)
            {
                charactersListView.Groups.Add(noESIKeyGroup);
            }

            foreach (ListViewGroup group in esiKeyGroups.Values)
            {
                charactersListView.Groups.Add(group);
            }

            if (hasFileChars)
            {
                charactersListView.Groups.Add(fileGroup);
            }

            if (hasUrlChars)
            {
                charactersListView.Groups.Add(urlGroup);
            }
        }
Exemplo n.º 8
0
        /// <summary>
        /// Recreate the items in the characters listview
        /// </summary>
        private void UpdateCharactersListContent()
        {
            int position = charactersListView.GetVerticalScrollBarPosition();

            charactersListView.BeginUpdate();
            try
            {
                // Retrieve current selection and grouping option
                List <Character> oldSelection = new List <Character>(charactersListView.SelectedItems.Cast <ListViewItem>()
                                                                     .Select(x => x.Tag).OfType <Character>());

                charactersListView.Groups.Clear();
                charactersListView.Items.Clear();

                // Grouping (no ESI key, ESI key #1, ESI key #2, character files, character urls)
                bool          isGrouping    = groupingMenu.Checked;
                ListViewGroup noESIKeyGroup = new ListViewGroup("No ESI key");
                ListViewGroup fileGroup     = new ListViewGroup("Character files");
                ListViewGroup urlGroup      = new ListViewGroup("Character urls");
                Dictionary <ESIKey, ListViewGroup> apiKeyGroups = new Dictionary <ESIKey, ListViewGroup>();

                if (isGrouping)
                {
                    ArrangeByGroup(fileGroup, apiKeyGroups, noESIKeyGroup, urlGroup);
                }

                // Add items
                foreach (Character character in EveMonClient.Characters.OrderBy(x => x.Name))
                {
                    ListViewItem item = new ListViewItem {
                        Checked = character.Monitored, Tag = character
                    };

                    // Retrieve the texts for the different columns
                    IEnumerable <ESIKey> esiKeys = character.Identity.ESIKeys.OrderBy(esiKey => esiKey.ID);
                    string apiKeyIDText          = esiKeys.Any()
                                              ? string.Join(", ", esiKeys.Select(esiKey => esiKey.ID))
                                              : string.Empty;
                    string typeText = "CCP";
                    string uriText  = "-";

                    UriCharacter uriCharacter = character as UriCharacter;
                    if (uriCharacter != null)
                    {
                        typeText = uriCharacter.Uri.IsFile ? "File" : "Url";
                        uriText  = uriCharacter.Uri.ToString();

                        if (isGrouping)
                        {
                            item.Group = uriCharacter.Uri.IsFile ? fileGroup : urlGroup;
                        }
                    }
                    // Grouping CCP characters
                    else if (isGrouping)
                    {
                        if (!esiKeys.Any())
                        {
                            item.Group = noESIKeyGroup;
                        }
                        else
                        {
                            item.Group = apiKeyGroups[esiKeys.First()];
                        }
                    }

                    // Add the item and its subitems
                    item.SubItems.Add(new ListViewItem.ListViewSubItem(item, typeText));
                    item.SubItems.Add(new ListViewItem.ListViewSubItem(item, character.CharacterID.ToString(
                                                                           CultureConstants.DefaultCulture)));
                    item.SubItems.Add(new ListViewItem.ListViewSubItem(item, character.Name));
                    item.SubItems.Add(new ListViewItem.ListViewSubItem(item, apiKeyIDText));
                    item.SubItems.Add(new ListViewItem.ListViewSubItem(item, character.
                                                                       EffectiveCharacterStatus.ToString()));
                    item.SubItems.Add(new ListViewItem.ListViewSubItem(item, uriText));

                    charactersListView.Items.Add(item);

                    if (oldSelection.Contains(character))
                    {
                        item.Selected = true;
                    }
                }

                // Auto-resize the columns
                charactersListView.Columns.Cast <ColumnHeader>().Where(
                    column => column.Index != charactersListView.Columns.Count - 1).ToList().ForEach(column => column.Width = -2);

                AdjustLastColumn();
            }
            finally
            {
                charactersListView.EndUpdate();
                charactersListView.SetVerticalScrollBarPosition(position);
            }

            // Forces a refresh of the enabled/disabled items
            UpdateControlsUsability();
        }
Exemplo n.º 9
0
 /// <summary>
 /// Constructor to update a character.
 /// </summary>
 public CharacterImportationWindow(UriCharacter uriCharacter)
     : this()
 {
     m_uriCharacter = uriCharacter;
 }