Exemplo n.º 1
0
        public void XmlSerializerTestMethod()
        {
            // Create a new instance of the Person class and serialize it to an XML file.
            CSharpSelectedTypesEncoding _p1 = new CSharpSelectedTypesEncoding();
            string _fileName = "DataContractExample.xml";

            XmlDataContractSerializers.Save <CSharpSelectedTypesEncoding>(new FileInfo(_fileName), _p1, (x, y, z) => Assert.AreEqual(System.Diagnostics.TraceEventType.Verbose, x));
            FileInfo _newFile = new FileInfo(_fileName);

            Assert.IsTrue(_newFile.Exists);
            CSharpSelectedTypesEncoding _p2 = XmlDataContractSerializers.Load <CSharpSelectedTypesEncoding>(new FileInfo(_fileName), (x, y, z) => Assert.AreEqual <System.Diagnostics.TraceEventType>(System.Diagnostics.TraceEventType.Verbose, x));

            Assert.IsNotNull(_p2);
            _p1.AreEqual(_p2);
        }
        internal static void Save <ConfigurationDataType>(ConfigurationDataType configuration, SerializerType serializer, FileInfo configurationFile, Action <TraceEventType, int, string> trace)
            where ConfigurationDataType : class, IConfigurationDataFactory, new()
        {
            configuration?.OnSaving();
            Action <FileInfo, ConfigurationDataType, Action <TraceEventType, int, string> > _saver = null;

            if (serializer == SerializerType.Xml)
            {
                _saver = (conf, file, tracer) => XmlDataContractSerializers.Save <ConfigurationDataType>(conf, file, tracer);
            }
            else
            {
                _saver = (conf, file, tracer) => JSONDataContractSerializers.Save <ConfigurationDataType>(conf, file, tracer);
            }
            _saver(configurationFile, configuration, (x, y, z) => trace?.Invoke(x, y, z));
        }
        private void NewMethod(string inFileName, string outFileName)
        {
            TraceSourceBase _trace       = new TraceSourceBase();
            FileInfo        _file2Covert = new FileInfo(inFileName);

            Assert.IsTrue(_file2Covert.Exists);
            ConfigurationData _oldConfiguration = XmlDataContractSerializers.Load <ConfigurationData>(_file2Covert, _trace.TraceData);

            Assert.IsNotNull(_oldConfiguration);
            NewConfigurationData _newConfiguration = Import(_oldConfiguration);

            Assert.IsNotNull(_newConfiguration);
            FileInfo _file2Save = new FileInfo(outFileName);

            XmlDataContractSerializers.Save <NewConfigurationData>(_file2Save, _newConfiguration, _trace.TraceData);
        }
        /// <summary>
        /// Loads the <typeparamref name="ConfigurationDataType" /> instance using specified loader.
        /// </summary>
        /// <typeparam name="ConfigurationDataType">The type of the configuration data type.</typeparam>
        /// <param name="serializer">The serializer.</param>
        /// <param name="configurationFile">The configuration file.</param>
        /// <param name="trace">The trace.</param>
        /// <param name="onChanged">The on changed.</param>
        /// <returns>ConfigurationDataType.</returns>
        public static ConfigurationDataType Load <ConfigurationDataType>(SerializerType serializer, FileInfo configurationFile, Action <TraceEventType, int, string> trace, Action onChanged)
            where ConfigurationDataType : class, IConfigurationDataFactory, new()
        {
            Func <FileInfo, Action <TraceEventType, int, string>, ConfigurationDataType> _loader = null;

            if (serializer == SerializerType.Xml)
            {
                _loader = (file, tracer) => XmlDataContractSerializers.Load <ConfigurationDataType>(file, tracer);
            }
            else
            {
                _loader = (conf, tracer) => JSONDataContractSerializers.Load <ConfigurationDataType>(conf, tracer);
            }
            ConfigurationDataType _configuration = _loader(configurationFile, (x, y, z) => trace?.Invoke(x, y, z));

            _configuration.OnChanged = onChanged;
            _configuration.OnLoaded();
            return(_configuration);
        }
        private void LoadUsingSerializer(Role role, SerializerType serializer)
        {
            FileInfo _fileInfo = GetFileName(role, serializer, @"TestData\ConfigurationData{0}.{1}");

            Assert.IsTrue(_fileInfo.Exists, _fileInfo.ToString());
            ConfigurationData _mirror = null;
            ConfigurationData _source = null;

            switch (role)
            {
            case Role.Producer:
                _source = ReferenceConfiguration.LoadProducer();
                break;

            case Role.Consumer:
                _source = ReferenceConfiguration.LoadConsumer();
                break;
            }
            string _message = null;

            switch (serializer)
            {
            case SerializerType.Json:
                _mirror = ConfigurationDataFactoryIO.Load <ConfigurationData>
                              (() => JSONDataContractSerializers.Load <ConfigurationData>(_fileInfo, (x, y, z) => { _message = z; Assert.AreEqual <TraceEventType>(TraceEventType.Verbose, x); }), () => { });
                break;

            case SerializerType.Xml:
                _mirror = ConfigurationDataFactoryIO.Load <ConfigurationData>
                              (() => XmlDataContractSerializers.Load <ConfigurationData>(_fileInfo, (x, y, z) => { _message = z; Assert.AreEqual <TraceEventType>(TraceEventType.Verbose, x); }), () => { });
                break;
            }
            Console.WriteLine(_message);
            Assert.IsNotNull(_mirror);
            Assert.IsFalse(String.IsNullOrEmpty(_message));
            Assert.IsTrue(_message.Contains(_fileInfo.FullName));
            ReferenceConfiguration.Compare(_source, _mirror);
        }
        private ConfigurationData LoadConfig()
        {
            FileInfo _configurationFile = new FileInfo(Properties.Settings.Default.ProducerConfigurationFileName);

            return(ConfigurationDataFactoryIO.Load <ConfigurationData>(() => XmlDataContractSerializers.Load <ConfigurationData>(_configurationFile, (x, y, z) => { }), () => RaiseEvents()));
        }
Exemplo n.º 7
0
        private ConfigurationData LoadConfig()
        {
            FileInfo _configurationFile = new FileInfo(m_ConfigurationFileName);

            return(ConfigurationDataFactoryIO.Load <ConfigurationData>(() => XmlDataContractSerializers.Load <ConfigurationData>(_configurationFile, (x, y, z) => { }), () => RaiseEvents()));
        }
 private ConfigurationType LoadConfig()
 {
     return(ConfigurationDataFactoryIO.Load <ConfigurationType>(() => XmlDataContractSerializers.Load <ConfigurationType>(m_ConfigurationFileInformation, TraceData), () => RaiseEvents()));
 }
Exemplo n.º 9
0
        private ConfigurationData LoadConfig()
        {
            FileInfo _configurationFile = new FileInfo(m_ProducerConfigurationFileName);

            return(ConfigurationDataFactoryIO.Load <ConfigurationData>(() => XmlDataContractSerializers.Load <ConfigurationData>(_configurationFile, m_TraceSource.TraceData), () => RaiseEvents()));
        }