コード例 #1
0
        public Task <string> SerializeAsync(configurationTemplate template)
        {
            if (template == null)
            {
                return(null);
            }

            var serializer = new XmlSerializer(typeof(configurationTemplate));

            string xml;

            using (var memorySteam = new MemoryStream())
                using (var writer = new XmlTextWriter(memorySteam, Encoding.UTF8))
                {
                    serializer.Serialize(writer, template); // memoryStream contains the xml
                    memorySteam.Position = 0;
                    using (var reader = new StreamReader(memorySteam))
                    {
                        xml = reader.ReadToEnd();
                        reader.Close();
                    }
                    writer.Close();
                }

            return(System.Threading.Tasks.Task.FromResult(xml));
        }
コード例 #2
0
        public bool TryDeserialize(string xml, out configurationTemplate template)
        {
            template = null;

            bool result = true;

            try
            {
                template = DeserializeAsync(xml).Result;
            }
            catch
            {
                result = false;
            }

            return(result);
        }
コード例 #3
0
        public bool TrySerialize(configurationTemplate template, out string xml)
        {
            xml = null;

            bool result = true;

            try
            {
                xml = SerializeAsync(template).Result;
            }
            catch
            {
                result = false;
            }

            return(result);
        }
コード例 #4
0
        public Configuration(string libraryPath, string templatePath, configurationTemplate template)
        {
            if (string.IsNullOrWhiteSpace(libraryPath))
            {
                throw new ArgumentNullException(nameof(libraryPath));
            }

            if (string.IsNullOrWhiteSpace(templatePath))
            {
                throw new ArgumentNullException(nameof(templatePath));
            }

            if (template == null)
            {
                throw new ArgumentNullException(nameof(template));
            }

            TemplatePath = templatePath;
            LibraryPath  = libraryPath;

            if (string.IsNullOrWhiteSpace(LibraryPath))
            {
                throw new ArgumentException(templatePath, nameof(templatePath));
            }

            Product = new Product(template.product);

            if (template.pages != null)
            {
                _pages.AddRange(template.pages.Select(page => new Page(page)));
            }

            if (template.build != null)
            {
                _build.AddRange(template.build.Select(Task.CreateTask));
            }

            if (template.import != null)
            {
                _import.AddRange(template.import.Select(Task.CreateTask));
            }
        }