コード例 #1
0
        /// <summary>
        /// Saves an object to an XML file located in a specified isolated storage area, using a specified serialized format.
        /// </summary>
        /// <example>
        /// <code>
        ///
        /// SerializableObject serializableObject = new SerializableObject();
        ///
        /// ObjectXMLSerializer&lt;SerializableObject&gt;.Save(serializableObject, "XMLObjects.xml", IsolatedStorageFile.GetUserStoreForAssembly(), SerializedFormat.Binary);
        /// </code>
        /// </example>
        /// <param name="serializableObject">
        /// Serializable object to be saved to file.
        /// </param>
        /// <param name="fileName">
        /// Name of the file in the isolated storage area to save the object to.
        /// </param>
        /// <param name="isolatedStorageDirectory">
        /// Isolated storage area directory containing the XML file to save the object to.
        /// </param>
        /// <param name="serializedFormat">
        /// XML serialized format used to save the object.
        /// </param>
        public static void Save(
            T serializableObject,
            string fileName,
            IsolatedStorageFile isolatedStorageDirectory,
            SerializedFormat serializedFormat)
        {
            // Logger.Trace(
            // $"Started Save() - fileName: {fileName},  serializableObject: {serializableObject.ToString()}, isolatedStorageDirectory {isolatedStorageDirectory}, serializedFormat : {serializedFormat}");
            if (string.IsNullOrEmpty(fileName))
            {
                // Logger.Error("path may not be empty");
                throw new ArgumentException("path may not be empty");
            }

            switch (serializedFormat)
            {
            case SerializedFormat.Binary:
                SaveToBinaryFormat(serializableObject, fileName, isolatedStorageDirectory);
                break;

            case SerializedFormat.Document:
            default:
                SaveToDocumentFormat(serializableObject, null, fileName, isolatedStorageDirectory);
                break;
            }

            // Logger.Trace(
            // $"Completed Save() - fileName: {fileName},  serializableObject: {serializableObject.ToString()}, isolatedStorageDirectory {isolatedStorageDirectory}, serializedFormat : {serializedFormat}");
        }
コード例 #2
0
        /// <summary>
        /// Loads an object from an XML file using a specified serialized format.
        /// </summary>
        /// <example>
        /// <code>
        /// serializableObject = ObjectXMLSerializer&lt;SerializableObject&gt;.Load(@"C:\XMLObjects.xml", SerializedFormat.Binary);
        /// </code>
        /// </example>
        /// <param name="path">
        /// Path of the file to load the object from.
        /// </param>
        /// <param name="serializedFormat">
        /// XML serialized format used to load the object.
        /// </param>
        /// <returns>
        /// Object loaded from an XML file using the specified serialized format.
        /// </returns>
        public static T Load(string path, SerializedFormat serializedFormat)
        {
            // Logger.Trace($"Started Load() - path: {path}, serializedFormat: {serializedFormat}");
            if (string.IsNullOrEmpty(path))
            {
                // Logger.Error("Path may not be empty");
                throw new ArgumentException("Path may not be empty");
            }

            T serializableObject = null;

            switch (serializedFormat)
            {
            case SerializedFormat.Binary:
                serializableObject = LoadFromBinaryFormat(path, null);
                break;

            case SerializedFormat.Document:
            default:
                serializableObject = LoadFromDocumentFormat(null, path, null);
                break;
            }

            // Logger.Trace($"Completed Load() - path: {path}, serializedFormat: {serializedFormat}");
            return(serializableObject);
        }
コード例 #3
0
        /// <summary>
        /// Saves a collection
        /// </summary>
        /// <param name="format">
        /// The format.
        /// </param>
        /// <param name="path">
        /// The path.
        /// </param>
        private static void Save(SerializedFormat format, string path)
        {
//            List<CollectionOption> collection = new List<CollectionOption>();
//            collection.Add(new CollectionOption { Name = "NameA", NameSpace = "NameSpaceA" });
//            collection.Add(new CollectionOption { Name = "NameB", NameSpace = "NameSpaceB" });
//            ObjectXMLSerializer<List<CollectionOption>>.Save(collection, path, format);
        }
コード例 #4
0
        public virtual SerializedFormat ShouldSerializeProperty(XamlSerializerContext serializerContext, DocumentCompositeNode parentNode, IPropertyId propertyKey, DocumentNode valueNode)
        {
            bool             flag;
            SerializedFormat serializedFormat = this.ShouldSerializeProperty(serializerContext, parentNode, propertyKey, valueNode, out flag);

            if (flag && !parentNode.Type.IsExpression)
            {
                return(SerializedFormat.Element);
            }
            return(serializedFormat);
        }
コード例 #5
0
ファイル: Class2.cs プロジェクト: annv2601/SoLieuBaoCao
        public static void Save(T serializableObject, string path, SerializedFormat serializedFormat)
        {
            switch (serializedFormat)
            {
            case SerializedFormat.Binary:
                ObjectXMLSerializer <T> .SaveToBinaryFormat(serializableObject, path, null);

                return;
            }
            ObjectXMLSerializer <T> .SaveToDocumentFormat(serializableObject, null, path, null);
        }
コード例 #6
0
        /// <summary>
        /// Loads an object from an XML file using a specified serialized format.
        /// </summary>
        /// <example>
        /// <code>
        /// // Always create a new object prior to passing to ObjectXMLSerializer.Load method.
        /// SerializableObject serializableObject = new SerializableObject();
        ///
        /// serializableObject = (SerializableObject)ObjectXMLSerializer.Load(serializableObject, @"C:\XMLObjects.xml", SerializedFormat.Binary);
        /// </code>
        /// </example>
        /// <param name="serializableObject">Serializable object to be loaded from file.</param>
        /// <param name="path">Path of the file to load the object from.</param>
        /// <param name="serializedFormat">XML serialized format used to load the object.</param>
        /// <returns>Object loaded from an XML file using the specified serialized format.</returns>
        public static Object Load(Object serializableObject, string path, SerializedFormat serializedFormat)
        {
            switch (serializedFormat)
            {
            case SerializedFormat.Document:
            default:
                serializableObject = LoadFromDocumentFormat(serializableObject, null, path);
                break;
            }

            return(serializableObject);
        }
コード例 #7
0
        /// <summary>
        /// Saves an object to an XML file using a specified serialized format.
        /// </summary>
        /// <example>
        /// <code>
        /// SerializableObject serializableObject = new SerializableObject();
        ///
        /// ObjectXMLSerializer&lt;SerializableObject&gt;.Save(serializableObject, @"C:\XMLObjects.xml", SerializedFormat.Binary);
        /// </code>
        /// </example>
        /// <param name="serializableObject">Serializable object to be saved to file.</param>
        /// <param name="path">Path of the file to save the object to.</param>
        /// <param name="serializedFormat">XML serialized format used to save the object.</param>
        public static void Save(T serializableObject, string path, SerializedFormat serializedFormat)
        {
            switch (serializedFormat)
            {
            case SerializedFormat.Binary:
                SaveToBinaryFormat(serializableObject, path, null);
                break;

            default:
                SaveToDocumentFormat(serializableObject, null, path, null);
                break;
            }
        }
コード例 #8
0
        /// <summary>
        /// Saves an object to an XML file located in a specified isolated storage area, using a specified serialized format.
        /// </summary>
        /// <example>
        /// <code>
        /// SerializableObject serializableObject = new SerializableObject();
        ///
        /// ObjectXMLSerializer&lt;SerializableObject&gt;.Save(serializableObject, "XMLObjects.xml", IsolatedStorageFile.GetUserStoreForAssembly(), SerializedFormat.Binary);
        /// </code>
        /// </example>
        /// <param name="serializableObject">Serializable object to be saved to file.</param>
        /// <param name="fileName">Name of the file in the isolated storage area to save the object to.</param>
        /// <param name="isolatedStorageDirectory">Isolated storage area directory containing the XML file to save the object to.</param>
        /// <param name="serializedFormat">XML serialized format used to save the object.</param>
        public static void Save(T serializableObject, string fileName, IsolatedStorageFile isolatedStorageDirectory,
                                SerializedFormat serializedFormat)
        {
            switch (serializedFormat)
            {
            case SerializedFormat.Binary:
                SaveToBinaryFormat(serializableObject, fileName, isolatedStorageDirectory);
                break;

            case SerializedFormat.Document:
            default:
                SaveToDocumentFormat(serializableObject, null, fileName, isolatedStorageDirectory);
                break;
            }
        }
コード例 #9
0
ファイル: Class2.cs プロジェクト: annv2601/SoLieuBaoCao
        public static T Load(string path, SerializedFormat serializedFormat)
        {
            T result = default(T);

            switch (serializedFormat)
            {
            case SerializedFormat.Binary:
                result = ObjectXMLSerializer <T> .LoadFromBinaryFormat(path, null);

                return(result);
            }
            result = ObjectXMLSerializer <T> .LoadFromDocumentFormat(null, path, null);

            return(result);
        }
コード例 #10
0
        /// <summary>
        /// Loads an object from an XML file using a specified serialized format.
        /// </summary>
        /// <example>
        /// <code>
        /// serializableObject = ObjectXMLSerializer&lt;SerializableObject&gt;.Load(@"C:\XMLObjects.xml", SerializedFormat.Binary);
        /// </code>
        /// </example>
        /// <param name="path">Path of the file to load the object from.</param>
        /// <param name="serializedFormat">XML serialized format used to load the object.</param>
        /// <returns>Object loaded from an XML file using the specified serialized format.</returns>
        public static T Load(string path, SerializedFormat serializedFormat)
        {
            T serializableObject;

            switch (serializedFormat)
            {
            case SerializedFormat.Binary:
                serializableObject = LoadFromBinaryFormat(path, null);
                break;

            default:
                serializableObject = LoadFromDocumentFormat(null, path, null);
                break;
            }

            return(serializableObject);
        }
コード例 #11
0
        public ExtractorReport Run()
        {
            ExtractorReport report = new ExtractorReport();

            report.Templates = Database.Clone();

            int count = 0;
            SerializedFormat serializedFormat = new SerializedFormat();
            CompactFormat    compactFormat    = new CompactFormat();

            Stopwatch timer = new Stopwatch();

            timer.Start();

            foreach (TestDatabase database in report.Templates.Databases)
            {
                foreach (DatabaseIndex index in database.AllIndexes)
                {
#if !MONO
                    byte[,] grayscale = WpfIO.GetPixels(WpfIO.Load(database[index].FilePath));
#else
                    byte[,] grayscale = GdiIO.Load(database[index].FilePath);
#endif
                    TemplateBuilder builder  = Extractor.Extract(grayscale, database.Dpi);
                    Template        template = serializedFormat.Export(builder);
                    database[index].Template = template;

                    report.MinutiaCount += template.Minutiae.Length;
                    report.TemplateSize += compactFormat.Export(builder).Length;
                    ++count;

                    if (timer.Elapsed.TotalSeconds > Timeout)
                    {
                        throw new TimeoutException("Timeout in extractor");
                    }
                }
            }

            timer.Stop();
            report.Time = (float)(timer.Elapsed.TotalSeconds / count);

            report.MinutiaCount /= count;
            report.TemplateSize /= count;
            return(report);
        }
コード例 #12
0
        public static void Save(T serializableObject, string path, SerializedFormat serializedFormat, System.Type[] extraTypes)
        {
            switch (serializedFormat)
            {
            case SerializedFormat.Binary:
                SaveToBinaryFormat(serializableObject, path, null);
                break;

            case SerializedFormat.DocumentCompressed:
                SaveToDocumentCompressedFormat(serializableObject, extraTypes, path, null);
                break;

            case SerializedFormat.Document:
            default:
                SaveToDocumentFormat(serializableObject, extraTypes, path, null);
                break;
            }
        }
コード例 #13
0
        /// <summary>
        /// Tests a loaded collection.
        /// </summary>
        /// <param name="name">
        /// The name.
        /// </param>
        /// <param name="format">
        /// The format.
        /// </param>
        private static void TestLoadedCollection(string name, SerializedFormat format)
        {
            //List<CollectionOption> collection = ObjectXMLSerializer<List<CollectionOption>>.Load(name, format);

            //Assert.IsNotNull(collection, "The Collection may not be empty");
            //Assert.AreEqual(2, collection.Count, "There should be 2 items in the loaded collection");

            //Assert.AreEqual("NameA", collection[0].Name, "The first collection item name should be NameA");
            //Assert.AreEqual(
            //    "NameSpaceA",
            //    collection[0].NameSpace,
            //    "The first collection item Namespace should be NameSpaceA");

            //Assert.AreEqual("NameB", collection[1].Name, "The first collection item name should be NameB");
            //Assert.AreEqual(
            //    "NameSpaceB",
            //    collection[1].NameSpace,
            //    "The first collection item Namespace should be NameSpaceB");
        }
コード例 #14
0
        /// <summary>
        /// Loads an object from an XML file located in a specified isolated storage area, using a specified serialized format.
        /// </summary>
        /// <example>
        /// <code>
        /// serializableObject = ObjectXMLSerializer&lt;SerializableObject&gt;.Load("XMLObjects.xml", IsolatedStorageFile.GetUserStoreForAssembly(), SerializedFormat.Binary);
        /// </code>
        /// </example>
        /// <param name="fileName">Name of the file in the isolated storage area to load the object from.</param>
        /// <param name="isolatedStorageDirectory">Isolated storage area directory containing the XML file to load the object from.</param>
        /// <param name="serializedFormat">XML serialized format used to load the object.</param>
        /// <returns>Object loaded from an XML file located in a specified isolated storage area, using a specified serialized format.</returns>
        public static T Load(string fileName, IsolatedStorageFile isolatedStorageDirectory,
                             SerializedFormat serializedFormat)
        {
            T serializableObject = null;

            switch (serializedFormat)
            {
            case SerializedFormat.Binary:
                serializableObject = LoadFromBinaryFormat(fileName, isolatedStorageDirectory);
                break;

            case SerializedFormat.Document:
            default:
                serializableObject = LoadFromDocumentFormat(null, fileName, isolatedStorageDirectory);
                break;
            }

            return(serializableObject);
        }
コード例 #15
0
        public static T Load(string path, SerializedFormat serializedFormat, System.Type[] extraTypes)
        {
            T serializableObject = null;

            switch (serializedFormat)
            {
            case SerializedFormat.Binary:
                serializableObject = LoadFromBinaryFormat(path, null);
                break;

            case SerializedFormat.DocumentCompressed:
                serializableObject = LoadFromDocumentCompressedFormat(extraTypes, path, null);
                break;

            case SerializedFormat.Document:
            default:
                serializableObject = LoadFromDocumentFormat(extraTypes, path, null);
                break;
            }

            return(serializableObject);
        }
コード例 #16
0
        /// <summary>
        /// Loads an object from an XML file located in a specified isolated storage area, using a specified serialized format.
        /// </summary>
        /// <example>
        /// <code>
        /// serializableObject = ObjectXMLSerializer&lt;SerializableObject&gt;.Load("XMLObjects.xml", IsolatedStorageFile.GetUserStoreForAssembly(), SerializedFormat.Binary);
        /// </code>
        /// </example>
        /// <param name="fileName">
        /// Name of the file in the isolated storage area to load the object from.
        /// </param>
        /// <param name="isolatedStorageDirectory">
        /// Isolated storage area directory containing the XML file to load the object from.
        /// </param>
        /// <param name="serializedFormat">
        /// XML serialized format used to load the object.
        /// </param>
        /// <returns>
        /// Object loaded from an XML file located in a specified isolated storage area, using a specified serialized
        ///     format.
        /// </returns>
        public static T Load(
            string fileName,
            IsolatedStorageFile isolatedStorageDirectory,
            SerializedFormat serializedFormat)
        {
            Logger.Trace(
                $"Started Load() - fileName: {fileName}, isolatedStorageDirectory: {isolatedStorageDirectory}, serializedFormat: {serializedFormat.ToString()}");

            if (string.IsNullOrEmpty(fileName))
            {
                Logger.Error("fileName may not be empty");
                throw new ArgumentException("fileName may not be empty");
            }

            if (isolatedStorageDirectory == null)
            {
                Logger.Error("isolatedStorageDirectory may not be null");
                throw new ArgumentException("isolatedStorageDirectory may not be null");
            }

            T serializableObject = null;

            switch (serializedFormat)
            {
            case SerializedFormat.Binary:
                serializableObject = LoadFromBinaryFormat(fileName, isolatedStorageDirectory);
                break;

            case SerializedFormat.Document:
            default:
                serializableObject = LoadFromDocumentFormat(null, fileName, isolatedStorageDirectory);
                break;
            }

            Logger.Trace(
                $"Completed Load() - fileName: {fileName}, isolatedStorageDirectory: {isolatedStorageDirectory}, serializedFormat: {serializedFormat.ToString()}");
            return(serializableObject);
        }
コード例 #17
0
        /// <summary>
        /// Saves an object to an XML file using a specified serialized format.
        /// </summary>
        /// <example>
        /// <code>
        /// SerializableObject serializableObject = new SerializableObject();
        ///
        /// ObjectXMLSerializer&lt;SerializableObject&gt;.Save(serializableObject, @"C:\XMLObjects.xml", SerializedFormat.Binary);
        /// </code>
        /// </example>
        /// <param name="serializableObject">
        /// Serializable object to be saved to file.
        /// </param>
        /// <param name="path">
        /// Path of the file to save the object to.
        /// </param>
        /// <param name="serializedFormat">
        /// XML serialized format used to save the object.
        /// </param>
        public static void Save(T serializableObject, string path, SerializedFormat serializedFormat)
        {
            // Logger.Trace($"Started Save() - path: {path},  serializableObject: {serializableObject.ToString()}");
            if (string.IsNullOrEmpty(path))
            {
                // Logger.Error("path may not be empty");
                throw new ArgumentException("path may not be empty");
            }

            switch (serializedFormat)
            {
            case SerializedFormat.Binary:
                SaveToBinaryFormat(serializableObject, path, null);
                break;

            case SerializedFormat.Document:
            default:
                SaveToDocumentFormat(serializableObject, null, path, null);
                break;
            }

            // Logger.Trace($"Completed Save() - path: {path},  serializableObject: {serializableObject.ToString()}");
        }
コード例 #18
0
ファイル: Class2.cs プロジェクト: annv2601/SoLieuBaoCao
        public static void Save(T serializableObject, string fileName, IsolatedStorageFile isolatedStorageDirectory, SerializedFormat serializedFormat)
        {
            switch (serializedFormat)
            {
            case SerializedFormat.Binary:
                ObjectXMLSerializer <T> .SaveToBinaryFormat(serializableObject, fileName, isolatedStorageDirectory);

                return;
            }
            ObjectXMLSerializer <T> .SaveToDocumentFormat(serializableObject, null, fileName, isolatedStorageDirectory);
        }
コード例 #19
0
 /// <summary>
 /// Saves an object to an XML file using a specified serialized format.
 /// </summary>
 /// <example>
 /// <code>
 /// SerializableObject serializableObject = new SerializableObject();
 ///
 /// ObjectXMLSerializer.Save(serializableObject, @"C:\XMLObjects.xml", SerializedFormat.Binary);
 /// </code>
 /// </example>
 /// <param name="serializableObject">Serializable object to be saved to file.</param>
 /// <param name="nameSpace">Namespace to put in root node</param>
 /// <param name="path">Path of the file to save the object to.</param>
 /// <param name="serializedFormat">XML serialized format used to save the object.</param>
 public static void Save(Object serializableObject, string nameSpace, string path, SerializedFormat serializedFormat)
 {
     switch (serializedFormat)
     {
     case SerializedFormat.Document:
     default:
         SaveToDocumentFormat(serializableObject, nameSpace, null, path);
         break;
     }
 }
コード例 #20
0
 public static void Save(Object serializableObject, string path, SerializedFormat serializedFormat)
 {
     Save(serializableObject, null, path, serializedFormat);
 }
コード例 #21
0
 public static void Save(Object serializableObject, string path, SerializedFormat serializedFormat)
 {
     Save(serializableObject, null, path, serializedFormat);
 }
コード例 #22
0
        /// <summary>
        /// Saves an object to an XML file using a specified serialized format.
        /// </summary>
        /// <example>
        /// <code>
        /// SerializableObject serializableObject = new SerializableObject();
        /// 
        /// ObjectXMLSerializer.Save(serializableObject, @"C:\XMLObjects.xml", SerializedFormat.Binary);
        /// </code>
        /// </example>
        /// <param name="serializableObject">Serializable object to be saved to file.</param>
        /// <param name="nameSpace">Namespace to put in root node</param>
        /// <param name="path">Path of the file to save the object to.</param>
        /// <param name="serializedFormat">XML serialized format used to save the object.</param>
        public static void Save(Object serializableObject, string nameSpace, string path, SerializedFormat serializedFormat)
        {
            switch (serializedFormat)
            {

                case SerializedFormat.Document:
                default:
                    SaveToDocumentFormat(serializableObject, nameSpace, null, path);
                    break;
            }
        }
コード例 #23
0
        /// <summary>
        /// Loads an object from an XML file using a specified serialized format.
        /// </summary>
        /// <example>
        /// <code>
        /// // Always create a new object prior to passing to ObjectXMLSerializer.Load method.
        /// SerializableObject serializableObject = new SerializableObject();
        /// 
        /// serializableObject = (SerializableObject)ObjectXMLSerializer.Load(serializableObject, @"C:\XMLObjects.xml", SerializedFormat.Binary);
        /// </code>
        /// </example>		
        /// <param name="serializableObject">Serializable object to be loaded from file.</param>
        /// <param name="path">Path of the file to load the object from.</param>
        /// <param name="serializedFormat">XML serialized format used to load the object.</param>
        /// <returns>Object loaded from an XML file using the specified serialized format.</returns>
        public static Object Load(Object serializableObject, string path, SerializedFormat serializedFormat)
        {
            switch (serializedFormat)
            {


                case SerializedFormat.Document:
                default:
                    serializableObject = LoadFromDocumentFormat(serializableObject, null, path);
                    break;
            }

            return serializableObject;
        }
コード例 #24
0
ファイル: Class2.cs プロジェクト: annv2601/SoLieuBaoCao
        public static T Load(string fileName, IsolatedStorageFile isolatedStorageDirectory, SerializedFormat serializedFormat)
        {
            T result = default(T);

            switch (serializedFormat)
            {
            case SerializedFormat.Binary:
                result = ObjectXMLSerializer <T> .LoadFromBinaryFormat(fileName, isolatedStorageDirectory);

                return(result);
            }
            result = ObjectXMLSerializer <T> .LoadFromDocumentFormat(null, fileName, isolatedStorageDirectory);

            return(result);
        }