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);
        }