Example #1
0
        public string SerializeToString()
        {
            InitializeOptionsList();

            var result = string.Empty;

            using (var stream = new MemoryStream())
            {
                using (var xmlBuilder = new XmlDescriptionBuilder(stream))
                {
                    var service = new OptionsSerializationService(xmlBuilder)
                    {
                        SerializeDefaultValues = true
                    };
                    XmlSerializerExtensions.Builder = xmlBuilder;
                    using (var root = xmlBuilder.BeginObject("Options"))
                    {
                        foreach (var option in _options)
                        {
                            using (var optionHandle = xmlBuilder.BeginObjectProperty(root, option.GetType().Name))
                            {
                                service.EncodeObject(optionHandle, option);
                            }
                        }
                    }
                }

                stream.Position = 0;
                using (var reader = new StreamReader(stream))
                {
                    result = reader.ReadToEnd();
                }
            }

            return(result);
        }
Example #2
0
 public static void SerializeOptions(string path, DatabaseSchemaView dbView, ISupportOptions withOptions)
 {
     using (var fileStream = new FileStream(path, FileMode.Create, FileAccess.ReadWrite))
         using (var xmlBuilder = new XmlDescriptionBuilder(fileStream))
         {
             var service = new OptionsSerializationService(xmlBuilder)
             {
                 SerializeDefaultValues = true
             };
             var metadataService = new MetadataSerializationService(xmlBuilder);
             XmlSerializerExtensions.Builder = xmlBuilder;
             using (var root = xmlBuilder.BeginObject("Options"))
             {
                 // Behavior options
                 using (var behaviorHandle = xmlBuilder.BeginObjectProperty(root, Constants.BehaviorOptionsTag))
                 {
                     service.EncodeObject(behaviorHandle, withOptions.BehaviorOptions);
                 }
                 // Database view options
                 using (var dbViewOptionsHandle = xmlBuilder.BeginObjectProperty(root, Constants.DatabaseSchemaViewOptionsTag))
                 {
                     service.EncodeObject(dbViewOptionsHandle, dbView.Options);
                 }
                 // DesignPaneOptions
                 using (var designPaneOptionsHandle = xmlBuilder.BeginObjectProperty(root, Constants.DesignPaneOptionsTag))
                 {
                     service.EncodeObject(designPaneOptionsHandle, withOptions.DesignPaneOptions);
                 }
                 // VisualOptions
                 using (var visualOptionsHandle = xmlBuilder.BeginObjectProperty(root, Constants.VisualOptionsTag))
                 {
                     service.EncodeObject(visualOptionsHandle, withOptions.VisualOptions);
                 }
                 // AddObjectDialogOptions
                 using (var addObjectDialogHandle = xmlBuilder.BeginObjectProperty(root, Constants.AddObjectDialogOptionsTag))
                 {
                     service.EncodeObject(addObjectDialogHandle, withOptions.AddObjectDialogOptions);
                 }
                 // DataSourceOptions
                 using (var dataSourceOptionsHandle = xmlBuilder.BeginObjectProperty(root, "DataSourceOptions"))
                 {
                     service.EncodeObject(dataSourceOptionsHandle, withOptions.DataSourceOptions);
                 }
                 // MetadataLoadingOptions
                 using (var metadataLoadingOptionsHandle = xmlBuilder.BeginObjectProperty(root, "MetadataLoadingOptions"))
                 {
                     metadataService.Encode(metadataLoadingOptionsHandle, withOptions.MetadataLoadingOptions);
                 }
                 // MetadataStructureOptions
                 using (var metadataStructureOptionsHandle = xmlBuilder.BeginObjectProperty(root, "MetadataStructureOptions"))
                 {
                     service.EncodeObject(metadataStructureOptionsHandle, withOptions.MetadataStructureOptions);
                 }
                 // QueryColumnListOptions
                 using (var queryColumnListOptionsHandle = xmlBuilder.BeginObjectProperty(root, "QueryColumnListOptions"))
                 {
                     service.EncodeObject(queryColumnListOptionsHandle, withOptions.QueryColumnListOptions);
                 }
                 // QueryNavBarOptions
                 using (var queryNavBarOptionsHandle = xmlBuilder.BeginObjectProperty(root, "QueryNavBarOptions"))
                 {
                     service.EncodeObject(queryNavBarOptionsHandle, withOptions.QueryNavBarOptions);
                 }
                 // UserInterfaceOptions
                 using (var userInterfaceOptionsHandle = xmlBuilder.BeginObjectProperty(root, "UserInterfaceOptions"))
                 {
                     service.EncodeObject(userInterfaceOptionsHandle, withOptions.UserInterfaceOptions);
                 }
                 // SqlFormattingOptions
                 using (var sqlFormattingOptionsHandle = xmlBuilder.BeginObjectProperty(root, "SqlFormattingOptions"))
                 {
                     service.EncodeObject(sqlFormattingOptionsHandle, withOptions.SqlFormattingOptions);
                 }
                 // SqlGenerationOptions
                 using (var sqlGenerationOptionsHandle = xmlBuilder.BeginObjectProperty(root, "SqlGenerationOptions"))
                 {
                     service.EncodeObject(sqlGenerationOptionsHandle, withOptions.SqlGenerationOptions);
                 }
             }
         }
 }