Example #1
1
        public static void SaveGameData(GameData gameData)
        {
            using (IsolatedStorageFile isf = IsolatedStorageFile.GetUserStoreForApplication())
            {
                if (isf.FileExists(GAME_DATA_FILENAME))
                    isf.DeleteFile(GAME_DATA_FILENAME);

                    using (var stream = isf.OpenFile(GAME_DATA_FILENAME, System.IO.FileMode.Create))
                    {
                        SharpSerializer serializer = new SharpSerializer(true);
                        serializer.Serialize(gameData, stream);
                    }

                using (var stream = isf.OpenFile(LEVEL_DATA_FILENAME, System.IO.FileMode.Create))
                {
                    SharpSerializer serializer = new SharpSerializer(true);
                    serializer.Serialize(gameData.Levels, stream);
                }
            }
        }
Example #2
0
 public override string Serialize(object serializable)
 {
     using (var ms = new MemoryStream())
     {
         _serializer.Serialize(serializable, ms);
         ms.Flush();
         ms.Position = 0;
         return(Convert.ToBase64String(ms.ToArray()));
     }
 }
        public void BinSerial_TwoIdenticalChildsShouldBeSameInstance()
        {
            var parent = new ParentChildTestClass()
            {
                Name = "parent",
            };

            var child = new ParentChildTestClass()
            {
                Name = "child",
                Father = parent,
                Mother = parent,
            };

            Assert.AreSame(child.Father, child.Mother, "Precondition: Saved Father and Mother are same instance");

            var stream = new MemoryStream();
            var settings = new SharpSerializerBinarySettings(BinarySerializationMode.SizeOptimized);
            var serializer = new SharpSerializer(settings);

            serializer.Serialize(child, stream);

            serializer = new SharpSerializer(settings);
            stream.Position = 0;
            ParentChildTestClass loaded = serializer.Deserialize(stream) as ParentChildTestClass;

            Assert.AreSame(loaded.Father, loaded.Mother, "Loaded Father and Mother are same instance");
        }
Example #4
0
        private static void serialize(object source, SharpSerializer serializer, Func <byte[], byte[]> dataCallback)
        {
            byte[] data;

            // Serializing
            using (var stream = new MemoryStream())
            {
                // serialize
                serializer.Serialize(source, stream);

                data = stream.ToArray();
            }


            // Modifying data
            if (dataCallback != null)
            {
                data = dataCallback(data);
            }

            // Deserializing
            using (var stream = new MemoryStream(data))
            {
                // deserialize
                var result = serializer.Deserialize(stream);

                // it comes never here
            }
        }
Example #5
0
        public void XmlSerial_ShouldSerializeGuid()
        {
            var parent = new ClassWithGuid()
            {
                Guid = Guid.NewGuid(),
            };

            var stream     = new MemoryStream();
            var settings   = new SharpSerializerXmlSettings();
            var serializer = new SharpSerializer(settings);

            serializer.Serialize(parent, stream);

            stream.Position = 0;
            XmlDocument doc = new XmlDocument();

            doc.Load(stream);
            System.Console.WriteLine(doc.InnerXml);

            serializer      = new SharpSerializer(settings);
            stream.Position = 0;
            ClassWithGuid loaded = serializer.Deserialize(stream) as ClassWithGuid;

            Assert.AreEqual(parent.Guid, loaded.Guid, "same guid");
        }
Example #6
0
        private static XmlDocument Save(object data)
        {
            var stream   = new MemoryStream();
            var settings = new SharpSerializerXmlSettings();

            settings.AdvancedSettings.PropertiesToIgnore.Add(typeof(Class2BeSerialized), "NameRule");
            settings.AdvancedSettings.PropertiesToIgnore.Add(typeof(Class2BeSerialized), "ComplexRule");

            settings.AdvancedSettings.PropertyTypesToIgnore.Add(typeof(Class2BeIgnored));

            settings.AdvancedSettings.AttributesToIgnore.Add(typeof(MyExcludeAttribute));
            // this does not work
            //settings.AdvancedSettings.PropertiesToIgnore.Add(null, "NameRule");
            //settings.AdvancedSettings.PropertiesToIgnore.Add(null, "ComplexRule");
            var serializer = new SharpSerializer(settings);

            serializer.Serialize(data, stream);

            stream.Position = 0;

            XmlDocument doc = new XmlDocument();

            doc.Load(stream);

            return(doc);
        }
Example #7
0
        public void BinSerial_ShouldSerializeDateTimeOffset()
        {
            var parent = new ClassWithDateTimeOffset
            {
                Date          = DateTimeOffset.Now,
                DateTimeLocal = new DateTime(2021, 12, 11, 10, 9, 8, DateTimeKind.Local),
                DateTimeUtc   = new DateTime(2021, 12, 11, 10, 9, 8, DateTimeKind.Utc)
            };

            var stream     = new MemoryStream();
            var settings   = new SharpSerializerBinarySettings(BinarySerializationMode.SizeOptimized);
            var serializer = new SharpSerializer(settings);

            serializer.Serialize(parent, stream);


            serializer      = new SharpSerializer(settings);
            stream.Position = 0;
            ClassWithDateTimeOffset loaded = serializer.Deserialize(stream) as ClassWithDateTimeOffset;

            Assert.AreEqual(parent.Date, loaded.Date, "same date");
            // Additional tests concerning
            // https://github.com/polenter/SharpSerializer/issues/17#issuecomment-994484009
            // DateTimeKind is not deserialized as expected.
            // A suggested workaround is using DateTimeOffset or a complex object instead of DateTime.
            Assert.AreEqual(parent.DateTimeLocal, loaded.DateTimeLocal);
            Assert.AreEqual(DateTimeKind.Unspecified, loaded.DateTimeLocal.Kind);
            Assert.AreEqual(parent.DateTimeUtc, loaded.DateTimeUtc);
            Assert.AreEqual(DateTimeKind.Unspecified, loaded.DateTimeUtc.Kind);
        }
Example #8
0
        public void XmlSerial_ShouldSerializeDateTimeOffset()
        {
            var parent = new ClassWithDateTimeOffset
            {
                Date          = DateTimeOffset.Now,
                DateTimeLocal = new DateTime(2021, 12, 11, 10, 9, 8, DateTimeKind.Local),
                DateTimeUtc   = new DateTime(2021, 12, 11, 10, 9, 8, DateTimeKind.Utc)
            };

            var stream     = new MemoryStream();
            var settings   = new SharpSerializerXmlSettings();
            var serializer = new SharpSerializer(settings);

            serializer.Serialize(parent, stream);

            stream.Position = 0;
            XmlDocument doc = new XmlDocument();

            doc.Load(stream);
            System.Console.WriteLine(doc.InnerXml);

            serializer      = new SharpSerializer(settings);
            stream.Position = 0;
            ClassWithDateTimeOffset loaded = serializer.Deserialize(stream) as ClassWithDateTimeOffset;

            Assert.AreEqual(parent.Date, loaded.Date);

            // Additional tests concerning
            // https://github.com/polenter/SharpSerializer/issues/17#issuecomment-994484009
            Assert.AreEqual(parent.DateTimeLocal, loaded.DateTimeLocal);
            Assert.AreEqual(parent.DateTimeLocal.Kind, loaded.DateTimeLocal.Kind);
            Assert.AreEqual(parent.DateTimeUtc, loaded.DateTimeUtc);
            Assert.AreEqual(parent.DateTimeUtc.Kind, loaded.DateTimeUtc.Kind);
        }
Example #9
0
        public void CanDeserializeClassWithPrivateConstructor()
        {
            var child = new ClassWithPrivateConstructor("child");

            var data = new ClassWithPrivateConstructor("MyName")
            {
                Complex = child
            };

            var settings   = new SharpSerializerXmlSettings();
            var serializer = new SharpSerializer(settings);

            using (var stream = new MemoryStream())
            {
                serializer.Serialize(data, stream);

                stream.Position = 0;

                var deserialized = serializer.Deserialize(stream) as ClassWithPrivateConstructor;

                Assert.IsNotNull(deserialized);
                Assert.AreEqual(data.Name, deserialized.Name);
                Assert.AreEqual(data.Complex.Name, deserialized.Complex.Name);
            }
        }
Example #10
0
        public void BinSerial_TwoIdenticalChildsShouldBeSameInstance()
        {
            var parent = new ParentChildTestClass()
            {
                Name = "parent",
            };

            var child = new ParentChildTestClass()
            {
                Name   = "child",
                Father = parent,
                Mother = parent,
            };

            Assert.AreSame(child.Father, child.Mother, "Precondition: Saved Father and Mother are same instance");

            var stream     = new MemoryStream();
            var settings   = new SharpSerializerBinarySettings(BinarySerializationMode.SizeOptimized);
            var serializer = new SharpSerializer(settings);

            serializer.Serialize(child, stream);

            serializer      = new SharpSerializer(settings);
            stream.Position = 0;
            ParentChildTestClass loaded = serializer.Deserialize(stream) as ParentChildTestClass;

            Assert.AreSame(loaded.Father, loaded.Mother, "Loaded Father and Mother are same instance");
        }
Example #11
0
        static public void Closing(object sender, FormClosingEventArgs e)
        {
            Form form       = (Form)sender;
            var  serializer = new Polenter.Serialization.SharpSerializer();

            serializer.Serialize(form, fileName(form));
        }
Example #12
0
        public static void SaveToCache(TwitterResource resource, IEnumerable<TwitterStatus> list)
        {
            string fileName = GetCacheName(resource);

            var serializer = new SharpSerializer(SerializerSettings);
            Mutex mutex = new Mutex(false, "OCELL_FILE_MUTEX" + fileName);

            if (mutex.WaitOne(1000))
            {
                try
                {
                    using (var stream = FileAbstractor.GetFileStream(fileName))
                    {
                        serializer.Serialize(list.Distinct().OfType<TwitterStatus>().ToList(), stream);
                    }
                }
                catch (Exception ex)
                {
                    Debug.WriteLine(ex);
                }
                finally
                {
                    mutex.ReleaseMutex();
                }
            }

            mutex.Dispose();
        }
Example #13
0
 public static void Serialize(SyncHistory history, string path)
 {
     SharpSerializerXmlSettings settings = new SharpSerializerXmlSettings();
     settings.IncludeAssemblyVersionInTypeName = false;
     settings.IncludePublicKeyTokenInTypeName = false;
     SharpSerializer serializer = new SharpSerializer(settings);
     serializer.Serialize(history, path);
 }
Example #14
0
 public void Save(IEnumerable<Datensatz> datensätze) {
     using (var appStorage = IsolatedStorageFile.GetUserStoreForApplication()) {
         using (var file = appStorage.OpenFile(Filename, FileMode.OpenOrCreate)) {
             using (var writer = new StreamWriter(file)) {
                 var serializer = new SharpSerializer();
                 serializer.Serialize(datensätze, writer.BaseStream);
             }
         }
     }
 }
Example #15
0
 /// <summary>
 ///   Writes a string value to the Octgn registry
 /// </summary>
 /// <param name="valName"> Name of the value </param>
 /// <param name="value"> String to write for value </param>
 public static void WriteValue(string valName, string value)
 {
     var serializer = new SharpSerializer();
     var config = new Hashtable();
     if (File.Exists(GetPath()))
     {
         config = (Hashtable) serializer.Deserialize(GetPath());
     }
     config[valName] = value;
     serializer.Serialize(config, GetPath());
 }
Example #16
0
        public void GenerateTestConfig()
        {
            List<TrackItem> items = new List<TrackItem>();
            items.Add(new TrackItem() { Path = @"$/Sandbox/litvinov/XPF/DevExpress.Xpf.Core", ProjectPath = "DevExpress.Xpf.Core" });
            TrackBranch branch = new TrackBranch("2015.2", "$/Sandbox/litvinov/XPF/track2015.2.config", "$/Sandbox/litvinov/XPF", items);

            SharpSerializerXmlSettings settings = new SharpSerializerXmlSettings();
            settings.IncludeAssemblyVersionInTypeName = false;
            settings.IncludePublicKeyTokenInTypeName = false;
            SharpSerializer serializer = new SharpSerializer(settings);
            serializer.Serialize(new List<TrackBranch>() { branch }, @"c:\1\trackconfig_testxpf.config");
        }
Example #17
0
        public void XmlSerial_TwoIdenticalChildsShouldBeSameInstance()
        {
            var parent = new ParentChildTestClass()
            {
                Name = "parent",
            };

            var child = new ParentChildTestClass()
            {
                Name   = "child",
                Father = parent,
                Mother = parent,
            };

            Assert.AreSame(child.Father, child.Mother, "Precondition: Saved Father and Mother are same instance");

            var stream     = new MemoryStream();
            var settings   = new SharpSerializerXmlSettings();
            var serializer = new SharpSerializer(settings);

            serializer.Serialize(child, stream);

            /*
             *  <Complex name="Root" type="Polenter.Serialization.XmlSerialisationTests+ParentChildTestClass, SharpSerializer.Tests">
             *          <Properties>
             *                  <Simple name="Name" value="child" />
             *                  <Complex name="Mother" id="1">
             *                          <Properties>
             *                                  <Simple name="Name" value="parent" />
             *                                  <Null name="Mother" />
             *                                  <Null name="Father" />
             *                          </Properties>
             *                  </Complex>
             *                  <ComplexReference name="Father" id="1" />
             *          </Properties>
             *  </Complex>
             */
            stream.Position = 0;
            XmlDocument doc = new XmlDocument();

            doc.Load(stream);
            System.Console.WriteLine(doc.InnerXml);

            serializer      = new SharpSerializer(settings);
            stream.Position = 0;
            ParentChildTestClass loaded = serializer.Deserialize(stream) as ParentChildTestClass;

            Assert.AreSame(loaded.Father, loaded.Mother, "Loaded Father and Mother are same instance");
        }
Example #18
0
 void GenerateRepoConfig(string branch, string taskName, string watchTaskName, string defaultService, bool allowTesting = false,  string[] testConfigs = null)
 {
     RepoConfig config = new RepoConfig() {
         Name = branch,
         FarmTaskName = watchTaskName,
         FarmSyncTaskName = taskName,
         DefaultServiceName = defaultService,
         SupportsTesting = allowTesting,
     };
     SharpSerializerXmlSettings settings = new SharpSerializerXmlSettings();
     settings.IncludeAssemblyVersionInTypeName = false;
     settings.IncludePublicKeyTokenInTypeName = false;
     SharpSerializer serializer = new SharpSerializer(settings);
     serializer.Serialize(config, @"z:\gitconfig.config");
 }
Example #19
0
 public static void Save(object sender = null, object args = null)
 {
     if(OrusTheGame.Instance.GameInformation.Character != null)
     {
         SharpSerializer serializer = new SharpSerializer();
         //Decide which properties to ignore
         serializer.PropertyProvider.PropertiesToIgnore.Add(typeof(OrusTheGame), "Content");
         serializer.PropertyProvider.PropertiesToIgnore.Add(typeof(OrusTheGame), "Components");
         serializer.PropertyProvider.PropertiesToIgnore.Add(typeof(OrusTheGame), "LaunchParameters");
         serializer.PropertyProvider.PropertiesToIgnore.Add(typeof(OrusTheGame), "Services");
         serializer.PropertyProvider.PropertiesToIgnore.Add(typeof(OrusTheGame), "TargetElapsedTime");
         serializer.PropertyProvider.PropertiesToIgnore.Add(typeof(OrusTheGame), "QuestFont");
         serializer.PropertyProvider.PropertiesToIgnore.Add(typeof(OrusTheGame), "NameFont");
         serializer.PropertyProvider.PropertiesToIgnore.Add(typeof(OrusTheGame), "AllCharacters");
         serializer.Serialize(OrusTheGame.Instance, "save.xml");
     }
 }
Example #20
0
 /// <summary>
 ///   Writes a string value to the Octgn registry
 /// </summary>
 /// <param name="valName"> Name of the value </param>
 /// <param name="value"> String to write for value </param>
 public static void WriteValue(string valName, string value)
 {
     try
     {
         var serializer = new SharpSerializer();
         var config = new Hashtable();
         if (File.Exists(GetPath()))
         {
             config = (Hashtable) serializer.Deserialize(GetPath());
         }
         config[valName] = value;
         serializer.Serialize(config, GetPath());
     }
     catch(Exception e)
     {
         Trace.WriteLine("[SimpleConfig]WriteValue Error: " + e.Message);
     }
 }
        public void BinSerial_ShouldSerializeGuid()
        {
            var parent = new ClassWithGuid()
            {
                Guid = Guid.NewGuid(),
            };

            var stream = new MemoryStream();
            var settings = new SharpSerializerBinarySettings(BinarySerializationMode.SizeOptimized);
            var serializer = new SharpSerializer(settings);

            serializer.Serialize(parent, stream);

            serializer = new SharpSerializer(settings);
            stream.Position = 0;
            ClassWithGuid loaded = serializer.Deserialize(stream) as ClassWithGuid;

            Assert.AreEqual(parent.Guid, loaded.Guid, "same guid");
        }
Example #22
0
        public static void SaveToCache(TwitterResource resource, IEnumerable<TwitterStatus> list)
        {
            string fileName = GetCacheName(resource);

            var serializer = new SharpSerializer(SerializerSettings);
            MutexUtil.DoWork("OCELL_FILE_MUTEX" + fileName, () =>
            {
                try
                {
                    using (var stream = FileAbstractor.GetFileStream(fileName))
                    {
                        serializer.Serialize(list.Distinct().OfType<TwitterStatus>().ToList(), stream);
                    }
                }
                catch (Exception ex)
                {
                    Debug.WriteLine(ex);
                }
            });
        }
Example #23
0
        public void BinSerial_ShouldSerializeGuid()
        {
            var parent = new ClassWithGuid()
            {
                Guid = Guid.NewGuid(),
            };

            var stream     = new MemoryStream();
            var settings   = new SharpSerializerBinarySettings(BinarySerializationMode.SizeOptimized);
            var serializer = new SharpSerializer(settings);

            serializer.Serialize(parent, stream);


            serializer      = new SharpSerializer(settings);
            stream.Position = 0;
            ClassWithGuid loaded = serializer.Deserialize(stream) as ClassWithGuid;

            Assert.AreEqual(parent.Guid, loaded.Guid, "same guid");
        }
Example #24
0
        public void CannotDeserializeClassWithoutParameterlessConstructor()
        {
            var child = new ClassWithoutParameterlessConstructor("child");

            var data = new ClassWithoutParameterlessConstructor("MyName")
            {
                Complex = child
            };

            var settings   = new SharpSerializerXmlSettings();
            var serializer = new SharpSerializer(settings);

            using (var stream = new MemoryStream())
            {
                serializer.Serialize(data, stream);

                stream.Position = 0;

                serializer.Deserialize(stream);
            }
        }
Example #25
0
        public void SaveData(string filename, DataXML saveData)
        {
            var documentsPath = System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal);
            var filePath = Path.Combine(documentsPath, filename);
            var serializer = new SharpSerializer();
            Stream fileStream = new FileStream(filePath, FileMode.Create, FileAccess.Write, FileShare.None);
            BinaryFormatter formatter = new BinaryFormatter();
            try
            {
                serializer.Serialize(saveData, fileStream);
            }
			catch (Exception e)
            {
                Console.WriteLine("Failed to serialize. Reason: " + e.Message);
                throw;
            }
            finally
            {
                fileStream.Close();
            }
        }
Example #26
0
        private static void serialize(HelloWorldTestCase testCase, SharpSerializer serializer)
        {
            using (var stream = new MemoryStream())
            {
                // serialize
                serializer.Serialize(testCase.Source, stream);

                // reset stream
                stream.Position = 0;

                // deserialize
                var result = serializer.Deserialize(stream);

                // reset stream to test if it is not closed
                // the stream will be closed by the user
                stream.Position = 0;

                // Fix assertions
                Assert.AreEqual(testCase.Source.GetType(), result.GetType());

                // Custom assertions
                testCase.MakeAssertion(result);
            }
        }
Example #27
0
        /// <summary>
        /// Returns the byte array representation of the object.
        /// </summary>
        /// <param name="entity">The object to serialize.</param>
        /// <returns>Byte array representation of the object.</returns>
        public static byte[] SerializeToBinary(object entity)
        {
            byte[] result;

            var settings = new SharpSerializerBinarySettings
            {
                IncludeAssemblyVersionInTypeName = true,
                IncludeCultureInTypeName = true,
                IncludePublicKeyTokenInTypeName = true
            };
            SharpSerializer ser = new SharpSerializer(settings);
            using (MemoryStream memStream = new MemoryStream())
            {
                var sw = new BinaryWriter(memStream);
                ser.Serialize(entity, memStream);
                sw.Flush();

                memStream.Position = 0;
                var sr = new BinaryReader(memStream);
                result = sr.ReadBytes((int)memStream.Length);
            }

            return result;
        }
        private static void serialize(object source, SharpSerializer serializer, Func<byte[], byte[]> dataCallback)
        {
            byte[] data;

            // Serializing
            using (var stream = new MemoryStream())
            {
                // serialize
                serializer.Serialize(source, stream);

                data = stream.ToArray();
            }

            // Modifying data
            if (dataCallback!=null)
            {
                data = dataCallback(data);
            }

            // Deserializing
            using (var stream = new MemoryStream(data))
            {
                // deserialize
                var result = serializer.Deserialize(stream);

                // it comes never here
            }
        }
Example #29
0
        void GenerateDataAccessConfig(string branchName)
        {
            List<TrackItem> items = new List<TrackItem>();
            items.Add(new TrackItem() { Path = $@"$/{branchName}/Win/DevExpress.DataAccess", ProjectPath = "DevExpress.DataAccess", AdditionalOffset = "Win" });
            items.Add(new TrackItem() { Path = $@"$/{branchName}/Tests.DataAccess/BigQueryTests", ProjectPath = "BigQueryTests", AdditionalOffset = "Tests.DataAccess" });
            items.Add(new TrackItem() { Path = $@"$/{branchName}/Tests.DataAccess/DataAccessTests", ProjectPath = "DataAccessTests", AdditionalOffset = "Tests.DataAccess" });
            items.Add(new TrackItem() { Path = $@"$/{branchName}/Tests.DataAccess/EntityFramework7Tests", ProjectPath = "EntityFramework7Tests", AdditionalOffset = "Tests.DataAccess" });
            items.Add(new TrackItem() { Path = $@"$/{branchName}/Tests.DataAccess/MsSqlCEEF7Tests", ProjectPath = "MsSqlCEEF7Tests", AdditionalOffset = "Tests.DataAccess" });
            items.Add(new TrackItem() { Path = $@"$/{branchName}/Tests.DataAccess/MsSqlEF5Tests", ProjectPath = "MsSqlEF5Tests", AdditionalOffset = "Tests.DataAccess" });
            items.Add(new TrackItem() { Path = $@"$/{branchName}/Tests.DataAccess/MsSqlEF6Tests", ProjectPath = "MsSqlEF6Tests", AdditionalOffset = "Tests.DataAccess" });
            items.Add(new TrackItem() { Path = $@"$/{branchName}/Tests.DataAccess/MsSqlEF7Tests", ProjectPath = "MsSqlEF7Tests", AdditionalOffset = "Tests.DataAccess" });
            items.Add(new TrackItem() { Path = $@"$/{branchName}/Tests.DataAccess/MySqlEF6Tests", ProjectPath = "MySqlEF6Tests", AdditionalOffset = "Tests.DataAccess" });
            items.Add(new TrackItem() { Path = $@"$/{branchName}/Tests.DataAccess/PostgreSqlEF7Tests", ProjectPath = "PostgreSqlEF7Tests", AdditionalOffset = "Tests.DataAccess" });
            items.Add(new TrackItem() { Path = $@"$/{branchName}/Tests.DataAccess/PostgreSqlEF7Tests", ProjectPath = "PostgreSqlEF7Tests", AdditionalOffset = "Tests.DataAccess" });
            items.Add(new TrackItem() { Path = $@"$/{branchName}/Tests.DataAccess/SqliteEF7Tests", ProjectPath = "SqliteEF7Tests", AdditionalOffset = "Tests.DataAccess" });
            items.Add(new TrackItem() { Path = $@"$/{branchName}/Tests.DataAccess/WizardTests", ProjectPath = "WizardTests", AdditionalOffset = "Tests.DataAccess" });
            TrackBranch branch = new TrackBranch($"{branchName}", $@"$/{branchName}/DataAccess/sync.config", $@"$/{branchName}", items);

            SharpSerializerXmlSettings settings = new SharpSerializerXmlSettings();
            settings.IncludeAssemblyVersionInTypeName = false;
            settings.IncludePublicKeyTokenInTypeName = false;
            SharpSerializer serializer = new SharpSerializer(settings);
            serializer.Serialize(new List<TrackBranch>() { branch }, $@"z:\trackconfig_dataaccess_{branchName}.config");
        }
        public void XmlSerial_TwoIdenticalChildsShouldBeSameInstance()
        {
            var parent = new ParentChildTestClass()
            {
                Name = "parent",
            };

            var child = new ParentChildTestClass()
            {
                Name = "child",
                Father = parent,
                Mother = parent,
            };

            Assert.AreSame(child.Father, child.Mother, "Precondition: Saved Father and Mother are same instance");

            var stream = new MemoryStream();
            var settings = new SharpSerializerXmlSettings();
            var serializer = new SharpSerializer(settings);

            serializer.Serialize(child, stream);

            /*
                <Complex name="Root" type="Polenter.Serialization.XmlSerialisationTests+ParentChildTestClass, SharpSerializer.Tests">
                    <Properties>
                        <Simple name="Name" value="child" />
                        <Complex name="Mother" id="1">
                            <Properties>
                                <Simple name="Name" value="parent" />
                                <Null name="Mother" />
                                <Null name="Father" />
                            </Properties>
                        </Complex>
                        <ComplexReference name="Father" id="1" />
                    </Properties>
                </Complex>
             */
            stream.Position = 0;
            XmlDocument doc = new XmlDocument();
            doc.Load(stream);
            System.Console.WriteLine(doc.InnerXml);

            serializer = new SharpSerializer(settings);
            stream.Position = 0;
            ParentChildTestClass loaded = serializer.Deserialize(stream) as ParentChildTestClass;

            Assert.AreSame(loaded.Father, loaded.Mother, "Loaded Father and Mother are same instance");
        }
        private static XmlDocument Save(object data)
        {
            var stream = new MemoryStream();
            var settings = new SharpSerializerXmlSettings();

            settings.AdvancedSettings.PropertiesToIgnore.Add(typeof(Class2BeSerialized), "NameRule");
            settings.AdvancedSettings.PropertiesToIgnore.Add(typeof(Class2BeSerialized), "ComplexRule");

            settings.AdvancedSettings.AttributesToIgnore.Add(typeof(MyExcludeAttribute));
            // this does not work
            //settings.AdvancedSettings.PropertiesToIgnore.Add(null, "NameRule");
            //settings.AdvancedSettings.PropertiesToIgnore.Add(null, "ComplexRule");
            var serializer = new SharpSerializer(settings);

            serializer.Serialize(data, stream);

            stream.Position = 0;

            XmlDocument doc = new XmlDocument();
            doc.Load(stream);

            return doc;
        }
Example #32
0
 private void CopyUrlAddress_Click(object sender, RoutedEventArgs e)
 {
     var tableName = (ListGridTab.SelectedItem as TabItem).Tag.ToString();
     this.SearchCondition.SelectedTableName = tableName;
     var ud = new UrlData
     {
         Condition = this.SearchCondition,
         Type = "List",
     };
     MemoryStream ms = new MemoryStream();
     var serializer = new SharpSerializer(true);
     serializer.Serialize(ud, ms);
     byte[] array = ms.ToArray();
     ms.Close();
     string data = Convert.ToBase64String(array);
     var url = HtmlPage.Document.DocumentUri;
     var urlstring = url.ToString();
     if (url.Query.Length > 0)
         urlstring = urlstring.Replace(url.Query, "");
     Clipboard.SetText(string.Format("{0}?url={1}", urlstring, data));
 }
        public void XmlSerial_ShouldSerializeGuid()
        {
            var parent = new ClassWithGuid()
            {
                Guid = Guid.NewGuid(),
            };

            var stream = new MemoryStream();
            var settings = new SharpSerializerXmlSettings();
            var serializer = new SharpSerializer(settings);

            serializer.Serialize(parent, stream);

            stream.Position = 0;
            XmlDocument doc = new XmlDocument();
            doc.Load(stream);
            System.Console.WriteLine(doc.InnerXml);

            serializer = new SharpSerializer(settings);
            stream.Position = 0;
            ClassWithGuid loaded = serializer.Deserialize(stream) as ClassWithGuid;

            Assert.AreEqual(parent.Guid, loaded.Guid, "same guid");
        }
Example #34
0
        void GenerateXpfDiagramConfig(string branchName)
        {
            List<TrackItem> items = new List<TrackItem>();
            items.Add(new TrackItem() { Path = $@"$/{branchName}/Win/DevExpress.XtraDiagram", ProjectPath = "DevExpress.XtraDiagram", AdditionalOffset = "Win" });
            items.Add(new TrackItem() { Path = $@"$/{branchName}/XPF/DevExpress.Xpf.Diagram", ProjectPath = "DevExpress.Xpf.Diagram", AdditionalOffset = "XPF" });
            items.Add(new TrackItem() { Path = $@"$/{branchName}/XPF/DevExpress.Xpf.ReportDesigner", ProjectPath = "DevExpress.Xpf.ReportDesigner", AdditionalOffset = "XPF" });
            items.Add(new TrackItem() { Path = $@"$/{branchName}/XPF/DevExpress.Xpf.PdfViewer", ProjectPath = "DevExpress.Xpf.PdfViewer", AdditionalOffset = "XPF" });
            items.Add(new TrackItem() { Path = $@"$/{branchName}/XPF/DevExpress.Xpf.Printing", ProjectPath = "DevExpress.Xpf.Printing", AdditionalOffset = "XPF" });
            TrackBranch branch = new TrackBranch($"{branchName}", $@"$/{branchName}/Diagram/xpf_common_sync.config", $@"$/{branchName}", items);

            SharpSerializerXmlSettings settings = new SharpSerializerXmlSettings();
            settings.IncludeAssemblyVersionInTypeName = false;
            settings.IncludePublicKeyTokenInTypeName = false;
            SharpSerializer serializer = new SharpSerializer(settings);
            serializer.Serialize(new List<TrackBranch>() { branch }, $@"z:\trackconfig_diagram_{branchName}.config");
        }
Example #35
0
        public void writeVariables()
        {
            string path = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\FastMove";

            try
            {
                // If the directory doesn't exist, create it.
                if (!Directory.Exists(path))
                {
                    Directory.CreateDirectory(path);
                }
            }
            catch (System.Exception e)
            {
                // Fail silently
                // Let the user know what went wrong.
                MessageBox.Show("Error: " + e.Message);
            }

            path += "\\FastMove.xml";

            try
            {
                purgeCountedMails();

                FastMoveVariables up = new FastMoveVariables();

                up._FoldersLevel1 = _FoldersLevel1;
                up._ignoreList = _ignoreList;
                up._recentItems = _recentItems;
                up._folderItems = _items;
                up._InboxAvg = _InboxAvg;
                up._avgTimeBeforeMove = _avgTimeBeforeMove;
                up.MailsPerDay = _MailsPerDay;
                up.LastMailReceived = _LastMailReceived;
                up.LastOnlineCheck = _LastOnlineCheck;
                up.OnlineCheckInterval = _OnlineCheckInterval;
                up._CountedNewMails = _CountedNewMails;
                up.MailsFromWho = _MailsFromWho;

                up.DeferEmailActive = _deferEmails;
                up.DeferEmailsAlwaysSendHighPriority = _deferEmailsAlwaysSendHighPriority;
                up.DeferEmailsAllowedTime = _deferEmailsAllowedTime;

                var serializer = new SharpSerializer();
                serializer.Serialize(up, path);
            }
            catch (System.Exception e)
            {
                // Let the user know what went wrong.
                MessageBox.Show("The file could not be written: " + e.Message);
            }

            //StoreVariables();
        }
        private string serialize(object obj, SharpSerializer serializer, string shortFilename)
        {
            // Serializing the first object
            var file1 = getFullFilename(shortFilename, "1");
            serializer.Serialize(obj, file1);

            // Deserializing to a second object
            var obj2 = serializer.Deserialize(file1);

            // Serializing the second object
            var file2 = getFullFilename(shortFilename, "2");
            serializer.Serialize(obj2, file2);

            // Comparing two files
            string retval = compareTwoFiles(file1, file2);

            // Show files in explorer
            showInExplorer(file1);

            return retval;
        }
Example #37
0
 public void Serialize(string path = "../../")
 {
     var serializer = new SharpSerializer();
     serializer.Serialize(this, path + "test.xml");
 }
Example #38
0
        void GenerateUWPDemoConfig(string branchName)
        {
            List<TrackItem> items = new List<TrackItem>();
            items.Add(new TrackItem() { Path = $@"$/{branchName}/Demos.UWP/DemoLauncher", ProjectPath = "DemoLauncher" });
            items.Add(new TrackItem() { Path = $@"$/{branchName}/Demos.UWP/DevExpress.PackageRegistrator", ProjectPath = "DevExpress.PackageRegistrator" });
            items.Add(new TrackItem() { Path = $@"$/{branchName}/Demos.UWP/DXCRM", ProjectPath = "DXCRM" });
            items.Add(new TrackItem() { Path = $@"$/{branchName}/Demos.UWP/FeatureDemo", ProjectPath = "FeatureDemo" });
            items.Add(new TrackItem() { Path = $@"$/{branchName}/Demos.UWP/FinanceTracker", ProjectPath = "FinanceTracker" });
            items.Add(new TrackItem() { Path = $@"$/{branchName}/Demos.UWP/HybridDemo", ProjectPath = "HybridDemo" });
            TrackBranch branch = new TrackBranch($"{branchName}", $@"$/{branchName}/Demos.UWP.GIT/sync.config", $@"$/{branchName}", items);

            SharpSerializerXmlSettings settings = new SharpSerializerXmlSettings();
            settings.IncludeAssemblyVersionInTypeName = false;
            settings.IncludePublicKeyTokenInTypeName = false;
            SharpSerializer serializer = new SharpSerializer(settings);
            serializer.Serialize(new List<TrackBranch>() { branch }, $@"z:\trackconfig_uwp_demos_{branchName}.config");
        }
Example #39
0
        private static void Serialize(Stream streamObject, object obj)
        {
            if (obj == null || streamObject == null)
                return;

            // true - binary serialization, default - xml ser.
            var serializer = new SharpSerializer(true);
            serializer.Serialize(obj, streamObject);
        }
Example #40
0
 public override void Serialize(object root, Stream stream)
 {
     m_Serializer.Serialize(root, stream);
 }
Example #41
0
        void GenerateWinRTConfig(string branchName)
        {
            List<TrackItem> items = new List<TrackItem>();
            items.Add(new TrackItem() { Path = $@"$/{branchName}/WinRT/DevExpress.Core", ProjectPath = "DevExpress.Core" });
            items.Add(new TrackItem() { Path = $@"$/{branchName}/WinRT/DevExpress.Drawing", ProjectPath = "DevExpress.Drawing" });
            items.Add(new TrackItem() { Path = $@"$/{branchName}/WinRT/DevExpress.Pdf.Core", ProjectPath = "DevExpress.Pdf.Core" });
            items.Add(new TrackItem() { Path = $@"$/{branchName}/WinRT/DevExpress.TestFramework", ProjectPath = "DevExpress.TestFramework" });
            items.Add(new TrackItem() { Path = $@"$/{branchName}/WinRT/DevExpress.TestRunner", ProjectPath = "DevExpress.TestRunner" });
            items.Add(new TrackItem() { Path = $@"$/{branchName}/WinRT/DevExpress.TestsKey", ProjectPath = "DevExpress.TestsKey" });
            items.Add(new TrackItem() { Path = $@"$/{branchName}/WinRT/DevExpress.TestUtils", ProjectPath = "DevExpress.TestUtils" });
            items.Add(new TrackItem() { Path = $@"$/{branchName}/WinRT/DevExpress.UI.Xaml", ProjectPath = "DevExpress.UI.Xaml" });
            items.Add(new TrackItem() { Path = $@"$/{branchName}/WinRT/DevExpress.UI.Xaml.Charts", ProjectPath = "DevExpress.UI.Xaml.Charts" });
            items.Add(new TrackItem() { Path = $@"$/{branchName}/WinRT/DevExpress.UI.Xaml.Controls", ProjectPath = "DevExpress.UI.Xaml.Controls" });
            items.Add(new TrackItem() { Path = $@"$/{branchName}/WinRT/DevExpress.UI.Xaml.Editors", ProjectPath = "DevExpress.UI.Xaml.Editors" });
            items.Add(new TrackItem() { Path = $@"$/{branchName}/WinRT/DevExpress.UI.Xaml.Gauges", ProjectPath = "DevExpress.UI.Xaml.Gauges" });
            items.Add(new TrackItem() { Path = $@"$/{branchName}/WinRT/DevExpress.UI.Xaml.Grid", ProjectPath = "DevExpress.UI.Xaml.Grid" });
            items.Add(new TrackItem() { Path = $@"$/{branchName}/WinRT/DevExpress.UI.Xaml.Layout", ProjectPath = "DevExpress.UI.Xaml.Layout" });
            items.Add(new TrackItem() { Path = $@"$/{branchName}/WinRT/DevExpress.UI.Xaml.Map", ProjectPath = "DevExpress.UI.Xaml.Map" });
            items.Add(new TrackItem() { Path = $@"$/{branchName}/WinRT/DevExpress.WinRT.Projects.Installers", ProjectPath = "DevExpress.WinRT.Projects.Installers" });
            items.Add(new TrackItem() { Path = $@"$/{branchName}/WinRT/DevExpress.WinRT.Projects.Wizards", ProjectPath = "DevExpress.WinRT.Projects.Wizards" });
            items.Add(new TrackItem() { Path = $@"$/{branchName}/WinRT/Shared", ProjectPath = "Shared" });
            items.Add(new TrackItem() { Path = $@"$/{branchName}/WinRT/Tools", ProjectPath = "Tools" });
            TrackBranch branch = new TrackBranch($"{branchName}", $@"$/{branchName}/UWP.GIT/sync.config", $@"$/{branchName}", items);

            SharpSerializerXmlSettings settings = new SharpSerializerXmlSettings();
            settings.IncludeAssemblyVersionInTypeName = false;
            settings.IncludePublicKeyTokenInTypeName = false;
            SharpSerializer serializer = new SharpSerializer(settings);
            serializer.Serialize(new List<TrackBranch>() { branch }, $@"z:\trackconfig_uwp_{branchName}.config");
        }
Example #42
0
        void GenerateXpfCommonConfig(string branchName)
        {
            List<TrackItem> items = new List<TrackItem>();
            items.Add(new TrackItem() { Path = $@"$/{branchName}/XPF/DevExpress.Mvvm", ProjectPath = "DevExpress.Mvvm" });
            items.Add(new TrackItem() { Path = $@"$/{branchName}/XPF/DevExpress.Xpf.Core", ProjectPath = "DevExpress.Xpf.Core" });
            items.Add(new TrackItem() { Path = $@"$/{branchName}/XPF/DevExpress.Xpf.Controls", ProjectPath = "DevExpress.Xpf.Controls" });
            items.Add(new TrackItem() { Path = $@"$/{branchName}/XPF/DevExpress.Xpf.Grid", ProjectPath = "DevExpress.Xpf.Grid" });
            items.Add(new TrackItem() { Path = $@"$/{branchName}/XPF/DevExpress.Xpf.NavBar", ProjectPath = "DevExpress.Xpf.NavBar" });
            items.Add(new TrackItem() { Path = $@"$/{branchName}/XPF/DevExpress.Xpf.PropertyGrid", ProjectPath = "DevExpress.Xpf.PropertyGrid" });
            items.Add(new TrackItem() { Path = $@"$/{branchName}/XPF/DevExpress.Xpf.Ribbon", ProjectPath = "DevExpress.Xpf.Ribbon" });
            items.Add(new TrackItem() { Path = $@"$/{branchName}/XPF/DevExpress.Xpf.Layout", ProjectPath = "DevExpress.Xpf.Layout" });
            items.Add(new TrackItem() { Path = $@"$/{branchName}/XPF/DevExpress.Xpf.LayoutControl", ProjectPath = "DevExpress.Xpf.LayoutControl" });
            TrackBranch branch = new TrackBranch($"{branchName}", $@"$/{branchName}/Common/xpf_common_sync.config", $@"$/{branchName}/XPF", items);

            SharpSerializerXmlSettings settings = new SharpSerializerXmlSettings();
            settings.IncludeAssemblyVersionInTypeName = false;
            settings.IncludePublicKeyTokenInTypeName = false;
            SharpSerializer serializer = new SharpSerializer(settings);
            serializer.Serialize(new List<TrackBranch>() { branch }, $@"z:\trackconfig_common_{branchName}.config");
        }
 void IProfileMapper.Save(List<SyncProfile> profiles)
 {
     SharpSerializer s = new SharpSerializer();
     s.Serialize(profiles, Filename);
 }
Example #44
0
        void GenerateAspConfig(string branchName)
        {
            List<TrackItem> items = new List<TrackItem>();
            items.Add(new TrackItem() { Path = $@"$/{branchName}/ASP/ASPxThemeBuilder", ProjectPath = "ASPxThemeBuilder" });
            items.Add(new TrackItem() { Path = $@"$/{branchName}/ASP/ASPxThemeDeployer", ProjectPath = "ASPxThemeDeployer" });
            items.Add(new TrackItem() { Path = $@"$/{branchName}/ASP/DevExpress.Web", ProjectPath = "DevExpress.Web" });
            items.Add(new TrackItem() { Path = $@"$/{branchName}/ASP/DevExpress.Web.ASPxHtmlEditor", ProjectPath = "DevExpress.Web.ASPxHtmlEditor" });
            items.Add(new TrackItem() { Path = $@"$/{branchName}/ASP/DevExpress.Web.ASPxRichEdit", ProjectPath = "DevExpress.Web.ASPxRichEdit" });
            items.Add(new TrackItem() { Path = $@"$/{branchName}/ASP/DevExpress.Web.ASPxRichEdit.Tests", ProjectPath = "DevExpress.Web.ASPxRichEdit.Tests" });
            items.Add(new TrackItem() { Path = $@"$/{branchName}/ASP/DevExpress.Web.ASPxScheduler", ProjectPath = "DevExpress.Web.ASPxScheduler" });
            items.Add(new TrackItem() { Path = $@"$/{branchName}/ASP/DevExpress.Web.ASPxSpellChecker", ProjectPath = "DevExpress.Web.ASPxSpellChecker" });
            items.Add(new TrackItem() { Path = $@"$/{branchName}/ASP/DevExpress.Web.ASPxSpreadsheet", ProjectPath = "DevExpress.Web.ASPxSpreadsheet" });
            items.Add(new TrackItem() { Path = $@"$/{branchName}/ASP/DevExpress.Web.ASPxThemes", ProjectPath = "DevExpress.Web.ASPxThemes" });
            items.Add(new TrackItem() { Path = $@"$/{branchName}/ASP/DevExpress.Web.ASPxTreeList", ProjectPath = "DevExpress.Web.ASPxTreeList" });
            items.Add(new TrackItem() { Path = $@"$/{branchName}/ASP/DevExpress.Web.Design", ProjectPath = "DevExpress.Web.Design" });
            items.Add(new TrackItem() { Path = $@"$/{branchName}/ASP/DevExpress.Web.Mvc", ProjectPath = "DevExpress.Web.Mvc" });
            items.Add(new TrackItem() { Path = $@"$/{branchName}/ASP/DevExpress.Web.Projects", ProjectPath = "DevExpress.Web.Projects" });

            TrackBranch branch = new TrackBranch($"{branchName}", $@"$/{branchName}/Diagram/xpf_common_sync.config", $@"$/{branchName}", items);

            SharpSerializerXmlSettings settings = new SharpSerializerXmlSettings();
            settings.IncludeAssemblyVersionInTypeName = false;
            settings.IncludePublicKeyTokenInTypeName = false;
            SharpSerializer serializer = new SharpSerializer(settings);
            serializer.Serialize(new List<TrackBranch>() { branch }, $@"z:\trackconfig_asp_{branchName}.config");
        }