示例#1
0
文件: Plan.cs 项目: Darkfoe703/evemon
        /// <summary>
        /// Generates a serialization object.
        /// </summary>
        /// <returns></returns>
        public SerializablePlan Export()
        {
            // Create serialization object
            SerializablePlan serial = new SerializablePlan
            {
                Name               = Name,
                Description        = Description,
                SortingPreferences = SortingPreferences
            };

            Character character = Character as Character;

            if (character != null)
            {
                serial.Owner = character.Guid;
            }

            // Add entries
            foreach (PlanEntry entry in Items)
            {
                SerializablePlanEntry serialEntry = new SerializablePlanEntry
                {
                    ID        = entry.Skill.ID,
                    SkillName = entry.Skill.Name,
                    Level     = entry.Level,
                    Type      = entry.Type,
                    Notes     = entry.Notes,
                    Priority  = entry.Priority
                };

                // Add groups
                foreach (string group in entry.PlanGroups)
                {
                    serialEntry.PlanGroups.Add(group);
                }

                // Remapping point
                if (entry.Remapping != null)
                {
                    serialEntry.Remapping = entry.Remapping.Export();
                }

                serial.Entries.Add(serialEntry);
            }

            foreach (SerializableInvalidPlanEntry serialEntry in m_invalidEntries.Select(
                         entry => new SerializableInvalidPlanEntry
            {
                SkillName = entry.SkillName,
                PlannedLevel = entry.PlannedLevel,
                Acknowledged = entry.Acknowledged
            }))
            {
                serial.InvalidEntries.Add(serialEntry);
            }

            return(serial);
        }
示例#2
0
        /// <summary>
        /// Imports data from a serialization object
        /// </summary>
        /// <param name="serial"></param>
        public void Import(SerializablePlan serial)
        {
            // Update name
            m_name = serial.Name;
            m_sortingPreferences = serial.SortingPreferences.Clone();

            // Update entries
            List <PlanEntry>        entries        = new List <PlanEntry>();
            List <InvalidPlanEntry> invalidEntries = new List <InvalidPlanEntry>();

            foreach (var serialEntry in serial.Entries)
            {
                PlanEntry entry = new PlanEntry(this, serialEntry);

                if (entry.Skill != null)
                {
                    entries.Add(entry);
                }
                // There are buggy entries in the plan
                else
                {
                    var invalidEntry = new InvalidPlanEntry()
                    {
                        SkillName    = serialEntry.SkillName,
                        PlannedLevel = serialEntry.Level
                    };

                    invalidEntries.Add(invalidEntry);
                }
            }

            RebuildPlanFrom(entries);
            FixPrerequisites();

            foreach (var serialInvalidEntry in serial.InvalidEntries)
            {
                var invalidEntry = new InvalidPlanEntry()
                {
                    SkillName    = serialInvalidEntry.SkillName,
                    PlannedLevel = serialInvalidEntry.PlannedLevel,
                    Acknowledged = serialInvalidEntry.Acknowledged
                };

                invalidEntries.Add(invalidEntry);
            }

            m_invalidEntries = invalidEntries.ToArray();

            // Notify name change
            if (m_isConnected)
            {
                EveClient.OnPlanNameChanged(this);
            }
        }
示例#3
0
        /// <summary>
        /// Imports a <see cref="SerializablePlan"/> from the given filename. Works with old and new formats.
        /// </summary>
        /// <param name="filename"></param>
        /// <returns></returns>
        public static SerializablePlan ImportFromXML(String filename)
        {
            SerializablePlan result = null;

            try
            {
                // Is the format compressed ?
                if (filename.EndsWith(".emp"))
                {
                    string tempFile = Util.UncompressToTempFile(filename);
                    try
                    {
                        return(ImportFromXML(tempFile));
                    }
                    finally
                    {
                        File.Delete(tempFile);
                    }
                }

                // Reads the revision number from the file
                int revision = Util.GetRevisionNumber(filename);

                // Old format
                if (revision == 0)
                {
                    result = Util.DeserializeXML <SerializablePlan>(filename, Util.LoadXSLT(Properties.Resources.SettingsAndPlanImport));
                }
                // New format
                else
                {
                    result = Util.DeserializeXML <OutputPlan>(filename);
                }
            }
            catch (UnauthorizedAccessException exc)
            {
                MessageBox.Show("Couldn't read the given file, access was denied. Maybe the directory was under synchronization.");
                ExceptionHandler.LogException(exc, true);
            }
            catch (InvalidDataException exc)
            {
                MessageBox.Show("The file seems to be corrupted, wrong gzip format.");
                ExceptionHandler.LogException(exc, true);
            }

            if (result == null)
            {
                MessageBox.Show("There was a problem with the format of the document.");
            }

            return(result);
        }
示例#4
0
文件: Plan.cs 项目: Darkfoe703/evemon
        /// <summary>
        /// Imports data from a serialization object.
        /// </summary>
        /// <param name="serial">The serial.</param>
        /// <exception cref="System.ArgumentNullException">serial</exception>
        public void Import(SerializablePlan serial)
        {
            serial.ThrowIfNull(nameof(serial));

            // Update name
            Name               = serial.Name;
            Description        = serial.Description ?? string.Empty;
            SortingPreferences = serial.SortingPreferences;

            // Update entries
            List <PlanEntry>        entries        = new List <PlanEntry>();
            List <InvalidPlanEntry> invalidEntries = new List <InvalidPlanEntry>();

            foreach (SerializablePlanEntry serialEntry in serial.Entries)
            {
                PlanEntry entry = new PlanEntry(this, serialEntry);

                // There are buggy entries in the plan
                if (entry.Skill == null)
                {
                    InvalidPlanEntry invalidEntry = new InvalidPlanEntry
                    {
                        SkillName    = serialEntry.SkillName,
                        PlannedLevel = serialEntry.Level
                    };

                    invalidEntries.Add(invalidEntry);
                    continue;
                }

                entries.Add(entry);
            }

            RebuildPlanFrom(entries);
            FixPrerequisites();

            invalidEntries.AddRange(serial.InvalidEntries.Select(
                                        serialInvalidEntry => new InvalidPlanEntry
            {
                SkillName    = serialInvalidEntry.SkillName,
                PlannedLevel = serialInvalidEntry.PlannedLevel,
                Acknowledged = serialInvalidEntry.Acknowledged
            }));

            m_invalidEntries = invalidEntries.ToArray();

            // Notify name or decription change
            if (IsConnected)
            {
                EveMonClient.OnPlanNameChanged(this);
            }
        }
示例#5
0
        /// <summary>
        /// Generates a serialization object
        /// </summary>
        /// <returns></returns>
        public SerializablePlan Export()
        {
            // Create serialization object
            var character = (Character)m_character;
            var serial    = new SerializablePlan {
                Name = m_name, Owner = character.Guid, SortingPreferences = m_sortingPreferences.Clone()
            };

            // Add entries
            foreach (var entry in m_items)
            {
                var serialEntry = new SerializablePlanEntry
                {
                    ID        = entry.Skill.ID,
                    SkillName = entry.Skill.Name,
                    Level     = entry.Level,
                    Type      = entry.Type,
                    Notes     = entry.Notes,
                    Priority  = entry.Priority
                };

                // Add groups
                foreach (var group in entry.PlanGroups)
                {
                    serialEntry.PlanGroups.Add(group);
                }

                // Remapping point
                if (entry.Remapping != null)
                {
                    serialEntry.Remapping = entry.Remapping.Export();
                }

                serial.Entries.Add(serialEntry);
            }

            foreach (var entry in m_invalidEntries)
            {
                var serialEntry = new SerializableInvalidPlanEntry
                {
                    SkillName    = entry.SkillName,
                    PlannedLevel = entry.PlannedLevel,
                    Acknowledged = entry.Acknowledged
                };

                serial.InvalidEntries.Add(serialEntry);
            }

            return(serial);
        }
示例#6
0
        /// <summary>
        /// Imports a <see cref="SerializablePlan" /> from the given filename. Works with old and new formats.
        /// </summary>
        /// <param name="filename">The filename.</param>
        /// <returns></returns>
        /// <exception cref="System.ArgumentNullException">filename</exception>
        public static SerializablePlan ImportFromXML(string filename)
        {
            filename.ThrowIfNull(nameof(filename));

            int revision            = -1;
            SerializablePlan result = null;

            try
            {
                // Is the format compressed ?
                if (filename.EndsWith(".emp", StringComparison.OrdinalIgnoreCase))
                {
                    string tempFile = Util.UncompressToTempFile(filename);
                    try
                    {
                        return(ImportFromXML(tempFile));
                    }
                    finally
                    {
                        FileHelper.DeleteFile(tempFile);
                    }
                }

                // Reads the revision number from the file
                revision = Util.GetRevisionNumber(filename);

                // Old format
                result = revision == 0
                             ? (SerializablePlan)UIHelper.ShowNoSupportMessage()
                             : Util.DeserializeXmlFromFile <OutputPlan>(filename);
            }
            catch (UnauthorizedAccessException exc)
            {
                MessageBox.Show(@"Couldn't read the given file, access was denied. Maybe the directory was under synchronization.");
                ExceptionHandler.LogException(exc, true);
            }
            catch (InvalidDataException exc)
            {
                MessageBox.Show(@"The file seems to be corrupted, wrong gzip format.");
                ExceptionHandler.LogException(exc, true);
            }

            if (result == null && revision > 0)
            {
                MessageBox.Show(@"There was a problem with the format of the document.");
            }

            return(result);
        }
示例#7
0
        /// <summary>
        /// Exports the plan under an XML format.
        /// </summary>
        /// <param name="plan">The plan.</param>
        /// <returns></returns>
        /// <exception cref="System.ArgumentNullException">plan</exception>
        public static string ExportAsXML(Plan plan)
        {
            plan.ThrowIfNull(nameof(plan));

            // Generates a settings plan and transforms it to an output plan
            SerializablePlan serial = plan.Export();
            OutputPlan       output = new OutputPlan {
                Name = serial.Name, Owner = serial.Owner, Revision = Settings.Revision
            };

            output.Entries.AddRange(serial.Entries);

            // Serializes to XML document and gets a string representation
            XmlDocument doc = (XmlDocument)Util.SerializeToXmlDocument(output);

            return(Util.GetXmlStringRepresentation(doc));
        }
示例#8
0
        /// <summary>
        /// Deserializes a settings file from an old format.
        /// </summary>
        /// <param name="filename"></param>
        /// <returns></returns>
        private static SerializableSettings DeserializeOldFormat(string filename)
        {
            var oldSerial = Util.DeserializeXML <OldSettings>(filename, Util.LoadXSLT(Properties.Resources.SettingsAndPlanImport));
            var serial    = new SerializableSettings();

            // Accounts
            serial.Accounts.AddRange(oldSerial.Accounts);

            // Characters
            foreach (var oldCharacter in oldSerial.Characters)
            {
                // Adds the char both to the characters list and the monitored characters list.
                var character = new SerializableCCPCharacter {
                    ID   = oldCharacter.ID,
                    Name = oldCharacter.Name,
                    Guid = Guid.NewGuid()
                };
                serial.MonitoredCharacters.Add(new MonitoredCharacterSettings {
                    CharacterGuid = character.Guid
                });
                serial.Characters.Add(character);
            }

            // Plans
            foreach (var oldPlan in oldSerial.Plans)
            {
                // Look for the owner by his name
                var owner = serial.Characters.SingleOrDefault(x => x.Name == oldPlan.Owner);
                if (owner == null)
                {
                    continue;
                }

                // Imports the plan
                var plan = new SerializablePlan {
                    Owner = owner.Guid, Name = oldPlan.Name
                };
                plan.Entries.AddRange(oldPlan.Entries);
                serial.Plans.Add(plan);
            }

            return(serial);
        }
示例#9
0
        /// <summary>
        /// Imports data from a serialization object
        /// </summary>
        /// <param name="serial"></param>
        public void Import(SerializablePlan serial)
        {
            // Update name
            m_name = serial.Name;
            m_sortingPreferences = serial.SortingPreferences.Clone();

            // Update entries
            List <PlanEntry> entries = new List <PlanEntry>();

            foreach (var serialEntry in serial.Entries)
            {
                entries.Add(new PlanEntry(this, serialEntry));
            }
            RebuildPlanFrom(entries);

            // Notify name change
            if (m_isConnected)
            {
                EveClient.OnPlanNameChanged(this);
            }
        }
示例#10
0
        public static void Store(IPlan plan, string fileName)
        {
            var serializablePlan = new SerializablePlan
            {
                TimeToGoal             = plan.TimeToGoal,
                SerializableTrajectory = plan.Trajectory.Select(segment =>
                                                                new SerializableTrajectory
                {
                    SerializableAction = segment.Action != null ? new SerializableAction {
                        Steering = segment.Action.Steering, Throttle = segment.Action.Throttle
                    } : null,
                    State          = segment.State,
                    TargetWayPoint = segment.TargetWayPoint,
                    Time           = segment.Time
                }).ToList().AsReadOnly()
            };

            var json = JsonConvert.SerializeObject(serializablePlan, CustomJsonSerializationSettings.Default);

            File.WriteAllText(fileName, json);
        }
示例#11
0
        /// <summary>
        /// File > Import Plan from File...
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void miImportPlanFromFile_Click(object sender, EventArgs e)
        {
            // Prompt the user to select a file
            DialogResult dr = ofdOpenDialog.ShowDialog();

            if (dr == DialogResult.Cancel)
            {
                return;
            }

            // Load from file and returns if an error occurred (user has already been warned)
            SerializablePlan serial = PlanIOHelper.ImportFromXML(ofdOpenDialog.FileName);

            if (serial == null)
            {
                return;
            }

            // Imports the plan
            Plan loadedPlan = new Plan(m_character, serial);

            // Prompt the user for the plan name
            using (NewPlanWindow npw = new NewPlanWindow())
            {
                npw.PlanName = Path.GetFileNameWithoutExtension(ofdOpenDialog.FileName);
                DialogResult xdr = npw.ShowDialog();
                if (xdr == DialogResult.Cancel)
                {
                    return;
                }

                loadedPlan.Name        = npw.PlanName;
                loadedPlan.Description = npw.PlanDescription;
                m_character.Plans.Add(loadedPlan);
            }
        }
示例#12
0
 /// <summary>
 /// Deserialization constructor
 /// </summary>
 /// <param name="character"></param>
 /// <param name="serial"></param>
 internal Plan(BaseCharacter character, SerializablePlan serial)
     : this(character)
 {
     Import(serial);
 }