예제 #1
0
        /// <summary>
        /// Exports the plan under an XML format.
        /// </summary>
        /// <param name="plans">The plans.</param>
        /// <returns></returns>
        public static string ExportAsXML(IEnumerable <Plan> plans)
        {
            OutputPlans output = new OutputPlans {
                Revision = Settings.Revision
            };

            output.Plans.AddRange(plans.Select(plan => plan.Export()));

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

            return(Util.GetXmlStringRepresentation(doc));
        }
예제 #2
0
        /// <summary>
        /// Imports plans from the given filename.
        /// </summary>
        /// <param name="filename">The filename.</param>
        /// <returns></returns>
        /// <exception cref="System.ArgumentNullException">filename</exception>
        public static IEnumerable <SerializablePlan> ImportPlansFromXML(string filename)
        {
            filename.ThrowIfNull(nameof(filename));

            OutputPlans result = null;

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

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

                if (revision != 0)
                {
                    result = Util.DeserializeXmlFromFile <OutputPlans>(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)
            {
                return(result.Plans);
            }

            MessageBox.Show(@"There was a problem with the format of the document.");
            return(null);
        }