コード例 #1
0
        /// <summary>
        /// Loads the specified files into a <see cref="PluginConfigurationData" /> object.
        /// </summary>
        /// <param name="fileName">The name of the file.</param>
        /// <returns>A <see cref="PluginConfigurationData" /> loaded from the file.</returns>
        public static PluginConfigurationData LoadFromFile(string fileName)
        {
            string[] lines               = File.ReadAllLines(fileName);
            XElement metadata            = XElement.Parse(lines[0]);
            string   metadataVersion     = lines[1];
            PluginConfigurationData data = new PluginConfigurationData(metadata, metadataVersion);

            if (lines.Length > 2)
            {
                data.Assets = Serializer.Deserialize <AssetSelectionData>(XElement.Parse(lines[2]));
            }

            if (lines.Length > 3)
            {
                data.Documents = Serializer.Deserialize <DocumentSelectionData>(XElement.Parse(lines[3]));
            }

            if (lines.Length > 4)
            {
                data.Servers = Serializer.Deserialize <ServerSelectionData>(XElement.Parse(lines[4]));
            }

            if (lines.Length > 5)
            {
                data.PrintQueues = Serializer.Deserialize <PrintQueueSelectionData>(XElement.Parse(lines[5]));
            }

            return(data);
        }
コード例 #2
0
        /// <summary>
        /// Writes the specified <see cref="PluginConfigurationData" /> to a file.
        /// </summary>
        /// <param name="configurationData">The <see cref="PluginConfigurationData" />.</param>
        /// <param name="fileName">The name of the file.</param>
        public static void WriteToFile(PluginConfigurationData configurationData, string fileName)
        {
            if (configurationData == null)
            {
                throw new ArgumentNullException(nameof(configurationData));
            }

            List <string> lines = new List <string>
            {
                configurationData.GetMetadata().ToString(SaveOptions.DisableFormatting),
                configurationData.MetadataVersion,
                Serializer.Serialize(configurationData.Assets).ToString(SaveOptions.DisableFormatting),
                Serializer.Serialize(configurationData.Documents).ToString(SaveOptions.DisableFormatting),
                Serializer.Serialize(configurationData.Servers).ToString(SaveOptions.DisableFormatting),
                Serializer.Serialize(configurationData.PrintQueues).ToString(SaveOptions.DisableFormatting)
            };

            File.WriteAllLines(fileName, lines);
        }