Пример #1
0
        /// <summary>
        /// Displays the character exportation window and then exports it.
        /// </summary>
        /// <param name="character"></param>
        public static void ExportCharacter(Character character)
        {
            // Open the dialog box
            using (var characterSaveDialog = new SaveFileDialog())
            {
                characterSaveDialog.Title       = "Save Character Info";
                characterSaveDialog.Filter      = "Text Format|*.txt|CHR Format (EFT)|*.chr|HTML Format|*.html|XML Format (EVEMon)|*.xml|XML Format (CCP API)|*.xml|PNG Image|*.png";
                characterSaveDialog.FileName    = character.Name;
                characterSaveDialog.FilterIndex = (int)CharacterSaveFormat.CCPXML;

                var result = characterSaveDialog.ShowDialog();
                if (result == DialogResult.Cancel)
                {
                    return;
                }

                // Serialize
                try
                {
                    CharacterSaveFormat format = (CharacterSaveFormat)characterSaveDialog.FilterIndex;
                    // Save character with the chosen format to our file
                    FileHelper.OverwriteOrWarnTheUser(characterSaveDialog.FileName, fs =>
                    {
                        if (format == CharacterSaveFormat.PNG)
                        {
                            var monitor = Program.MainWindow.GetCurrentMonitor();
                            var bmp     = monitor.GetCharacterScreenshot();
                            bmp.Save(fs, ImageFormat.Png);
                            return(true);
                        }

                        var content = CharacterExporter.Export(format, character, null);
                        if ((format == CharacterSaveFormat.CCPXML) && string.IsNullOrEmpty(content))
                        {
                            MessageBox.Show("This character has never been downloaded from CCP, cannot find it in the XML cache.", "Cannot export the character", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                            return(false);
                        }

                        using (var sw = new StreamWriter(fs, Encoding.UTF8))
                        {
                            sw.Write(content);
                            sw.Flush();
                            sw.Close();
                        }
                        return(true);
                    });
                }
                // Handle exception
                catch (IOException exc)
                {
                    ExceptionHandler.LogException(exc, true);
                    MessageBox.Show("A problem occurred during exportation. The operation has not been completed.");
                }
            }
        }
Пример #2
0
 /// <summary>
 /// Creates formatted string for character exportation.
 /// </summary>
 /// <param name="format"></param>
 /// <param name="character"></param>
 /// <param name="plan"></param>
 /// <exception cref="NotImplementedException"></exception>
 /// <returns></returns>
 public static string Export(CharacterSaveFormat format, Character character, Plan plan = null)
 {
     switch (format)
     {
         case CharacterSaveFormat.Text:
             return ExportAsText(character, plan);
         case CharacterSaveFormat.EFTCHR:
             return ExportAsEFTCHR(character, plan);
         case CharacterSaveFormat.EVEMonXML:
             return ExportAsEVEMonXML(character, plan);
         case CharacterSaveFormat.HTML:
             return ExportAsHTML(character, plan);
         case CharacterSaveFormat.CCPXML:
             return ExportAsCCPXML(character);
         default:
             throw new NotImplementedException();
     }
 }
Пример #3
0
        /// <summary>
        /// Displays the character exportation window and then exports it as it would be after the plan finish.
        /// </summary>
        /// <param name="character"></param>
        public static void ExportAfterPlanCharacter(Character character, Plan plan)
        {
            // Open the dialog box
            using (var characterSaveDialog = new SaveFileDialog())
            {
                characterSaveDialog.Title       = "Save After Plan Character Info";
                characterSaveDialog.Filter      = "Text Format|*.txt|CHR Format (EFT)|*.chr|HTML Format|*.html|XML Format (EVEMon)|*.xml";
                characterSaveDialog.FileName    = String.Format(CultureConstants.DefaultCulture, " {0} (after plan {1})", character.Name, plan.Name);
                characterSaveDialog.FilterIndex = (int)CharacterSaveFormat.EVEMonXML;

                var result = characterSaveDialog.ShowDialog();
                if (result == DialogResult.Cancel)
                {
                    return;
                }

                // Serialize
                try
                {
                    // Save character to string with the chosen format
                    CharacterSaveFormat format = (CharacterSaveFormat)characterSaveDialog.FilterIndex;
                    var content = CharacterExporter.Export(format, character, plan);
                    // Save character with the chosen format to our file
                    FileHelper.OverwriteOrWarnTheUser(characterSaveDialog.FileName, fs =>
                    {
                        using (var sw = new StreamWriter(fs, Encoding.UTF8))
                        {
                            sw.Write(content);
                            sw.Flush();
                            sw.Close();
                        }
                        return(true);
                    });
                }
                // Handle exception
                catch (IOException ex)
                {
                    ExceptionHandler.LogException(ex, true);
                    MessageBox.Show("A problem occurred during exportation. The operation has not been completed.");
                }
            }
        }
Пример #4
0
        /// <summary>
        /// Creates formatted string for character exportation.
        /// </summary>
        /// <param name="format"></param>
        /// <param name="character"></param>
        /// <param name="plan"></param>
        /// <returns></returns>
        public static string Export(CharacterSaveFormat format, Character character, Plan plan)
        {
            switch (format)
            {
            case CharacterSaveFormat.Text:
                return(ExportAsText(character, plan));

            case CharacterSaveFormat.EFTCHR:
                return(ExportAsEFTCHR(character, plan));

            case CharacterSaveFormat.EVEMonXML:
                return(ExportAsEVEMonXML(character, plan));

            case CharacterSaveFormat.HTML:
                return(ExportAsHTML(character, plan));

            case CharacterSaveFormat.CCPXML:
                return(ExportAsCCPXML(character));

            default:
                throw new NotImplementedException();
            }
        }
Пример #5
0
        /// <summary>
        /// Displays the character exportation window and then exports it.
        /// Optionally it exports it as it would be after the plan finish.
        /// </summary>
        /// <param name="character">The character.</param>
        /// <param name="plan">The plan.</param>
        /// <returns></returns>
        /// <exception cref="System.ArgumentNullException">character</exception>
        public static async Task ExportCharacterAsync(Character character, Plan plan = null)
        {
            character.ThrowIfNull(nameof(character));

            bool isAfterPlanExport = plan != null;

            // Open the dialog box
            using (SaveFileDialog characterSaveDialog = new SaveFileDialog())
            {
                characterSaveDialog.Title  = $"Save {(isAfterPlanExport ? "After Plan " : string.Empty)}Character Info";
                characterSaveDialog.Filter =
                    @"Text Format|*.txt|CHR Format (EFT)|*.chr|HTML Format|*.html|XML Format (EVEMon)|*.xml";

                if (!isAfterPlanExport)
                {
                    characterSaveDialog.Filter += @"|XML Format (CCP API)|*.xml|PNG Image|*.png";
                }

                characterSaveDialog.FileName =
                    $"{character.Name}{(isAfterPlanExport ? $" (after plan {plan.Name})" : string.Empty)}";

                characterSaveDialog.FilterIndex = isAfterPlanExport
                                                      ? (int)CharacterSaveFormat.EVEMonXML
                                                      : (int)CharacterSaveFormat.CCPXML;

                if (characterSaveDialog.ShowDialog() == DialogResult.Cancel)
                {
                    return;
                }

                // Serialize
                try
                {
                    CharacterSaveFormat format = (CharacterSaveFormat)characterSaveDialog.FilterIndex;

                    // Save character with the chosen format to our file
                    await FileHelper.OverwriteOrWarnTheUserAsync(
                        characterSaveDialog.FileName,
                        async fs =>
                    {
                        if (format == CharacterSaveFormat.PNG)
                        {
                            Image image = CharacterMonitorScreenshot;
                            image.Save(fs, ImageFormat.Png);
                            await fs.FlushAsync();
                            return(true);
                        }

                        string content = CharacterExporter.Export(format, character, plan);
                        if ((format == CharacterSaveFormat.CCPXML) && string.IsNullOrEmpty(content))
                        {
                            MessageBox.Show(
                                @"This character has never been downloaded from CCP, cannot find it in the XML cache.",
                                @"Cannot export the character", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                            return(false);
                        }

                        using (StreamWriter sw = new StreamWriter(fs))
                        {
                            await sw.WriteAsync(content);
                            await sw.FlushAsync();
                            await fs.FlushAsync();
                        }
                        return(true);
                    });
                }
                // Handle exception
                catch (IOException exc)
                {
                    ExceptionHandler.LogException(exc, true);
                    MessageBox.Show(@"A problem occurred during exportation. The operation has not been completed.");
                }
            }
        }
Пример #6
0
        /// <summary>
        /// Displays the character exportation window and then exports it.
        /// </summary>
        /// <param name="character"></param>
        public static void ExportCharacter(Character character)
        {
            // Open the dialog box
            using (var characterSaveDialog = new System.Windows.Forms.SaveFileDialog())
            {
                characterSaveDialog.Title       = "Save Character Info";
                characterSaveDialog.Filter      = "Text Format|*.txt|HTML Format|*.html|XML Format (CCP API)|*.xml|XML Format (EVEMon)|*.xml|PNG Image|*.png";
                characterSaveDialog.FileName    = character.Name;
                characterSaveDialog.FilterIndex = (int)CharacterSaveFormat.CCPXML;

                var result = characterSaveDialog.ShowDialog();
                if (result == DialogResult.Cancel)
                {
                    return;
                }

                // Serialize
                try
                {
                    // Save file to the chosen format and to a temp file
                    string tempFileName        = Path.GetTempFileName();
                    CharacterSaveFormat format = (CharacterSaveFormat)characterSaveDialog.FilterIndex;
                    switch (format)
                    {
                    case CharacterSaveFormat.HTML:
                        File.WriteAllText(tempFileName, CharacterExporter.ExportAsHTML(character), Encoding.UTF8);
                        break;

                    case CharacterSaveFormat.CCPXML:
                        var content = CharacterExporter.ExportAsCCPXML(character);
                        if (content == null)
                        {
                            MessageBox.Show("This character has never been downloaded from CCP, cannot find it in the XML cache.", "Cannot export the character", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                            return;
                        }
                        File.WriteAllText(tempFileName, content, Encoding.UTF8);
                        break;

                    case CharacterSaveFormat.EVEMonXML:
                        File.WriteAllText(tempFileName, CharacterExporter.ExportAsEVEMonXML(character), Encoding.UTF8);
                        break;

                    case CharacterSaveFormat.Text:
                        File.WriteAllText(tempFileName, CharacterExporter.ExportAsText(character), Encoding.UTF8);
                        break;

                    case CharacterSaveFormat.PNG:
                        var monitor = Program.MainWindow.GetCurrentMonitor();
                        var bmp     = monitor.GetCharacterScreenshot();
                        bmp.Save(tempFileName, System.Drawing.Imaging.ImageFormat.Png);
                        break;

                    default:
                        throw new NotImplementedException();
                    }

                    // Writes to our file
                    FileHelper.OverwriteOrWarnTheUser(tempFileName, characterSaveDialog.FileName, OverwriteOperation.Move);
                }
                // Handle exception
                catch (IOException exc)
                {
                    ExceptionHandler.LogException(exc, true);
                    MessageBox.Show("A problem occured during exportation. The operation has not been completed.");
                }
            }
        }