Esempio n. 1
0
        //[Benchmark]
        public SimpleStruct OrleansStructRoundTrip()
        {
            var writer = new BinaryTokenStreamWriter();

            _orleansSerializer.Serialize(_structValue, writer);
            return((SimpleStruct)_orleansSerializer.Deserialize(new BinaryTokenStreamReader(writer.ToBytes())));
        }
Esempio n. 2
0
        internal SerializedDataStorage()
        {
            try
            {
                Transform(SerializationManager.Deserialize <List <PersonData> >(FileHelper.StorageFilePath));
            }
            catch (FileNotFoundException)
            {
                _personsList = new List <Person>();
                for (int i = 1; i < 10; i++)
                {
                    _personsList.Add(new Person("Volodymyr", "Osadchuk", "*****@*****.**",
                                                new System.DateTime(2000, 8, 4)));
                    _personsList.Add(new Person("Andrey", "Olekseev", "*****@*****.**",
                                                new System.DateTime(2004, 2, 13)));
                    _personsList.Add(new Person("Vasya", "Kobelev", "*****@*****.**",
                                                new System.DateTime(1989, 8, 18)));
                    _personsList.Add(new Person("Misha", "Stasuk", "*****@*****.**",
                                                new System.DateTime(2012, 1, 21)));
                    _personsList.Add(new Person("Kyrylo", "Andonik", "*****@*****.**",
                                                new System.DateTime(2001, 7, 9)));
                }


                SaveChanges();
            }
        }
Esempio n. 3
0
        public MainWindow()
        {
            InitializeComponent();
            var navigationModel = new NavigationModel(this);

            NavigationManager.Instance.Initialize(navigationModel);

            try
            {
                String guid = SerializationManager.Deserialize <String>(FileFolderHelper.StorageFilePath);
                StationManager.CurrentUser = ConnectionManager.GetUserByGuid(guid);
                if (StationManager.CurrentUser != null)
                {
                    StationManager.CurrentUser.LastSingInDate = DateTime.Now;
                    ConnectionManager.SaveUser(StationManager.CurrentUser);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }

            MainWindowViewModel mainWindowViewModel = new MainWindowViewModel();

            DataContext = mainWindowViewModel;
            mainWindowViewModel.StartApplication();
        }
Esempio n. 4
0
        public static ISerializable Deserialize(string text)
        {
            var jsonObject   = JObject.Parse(text);
            var deserializer = new JsonDeserializer(jsonObject);

            return(SerializationManager.Deserialize(deserializer));
        }
Esempio n. 5
0
        private void Form1_DragDrop(object sender, DragEventArgs e)
        {
            try {
                string[] files = (string[])e.Data.GetData(DataFormats.FileDrop);
                foreach (string filename in files)
                {
                    if (filename.EndsWith(".sms") == false)
                    {
                        new AlertForm("Dropping files", "Only \".sms\" files allowed!").ShowDialog();
                    }

                    // get the script-model by de-serializing
                    ScriptModel scriptModel = SerializationManager.Deserialize <ScriptModel>(filename);

                    // open the designated script-model,
                    // if the script is already in the opened script list
                    if (ModelManager.openScript(scriptModel) == false)
                    {
                        new AlertForm("Alert", "The designated script \"" + filename + "\" is already in the opened script list.").ShowDialog();
                    }
                    // add new tab-page for this script
                    else
                    {
                        addNewTabPage(scriptModel, false);
                    }
                }
            } catch (Exception) {}
        }
        public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
        {
            var info = new GrainReferenceInfo();

            serializer.Populate(reader, info);
            return(SerializationManager.Deserialize(objectType, new BinaryTokenStreamReader(info.Data)));
        }
Esempio n. 7
0
        internal SerializedDataStorage()
        {
            try
            {
                _users = SerializationManager.Deserialize <List <Person> >(FileFolderHelper.StorageFilePath);
            }
            catch (FileNotFoundException)
            {
                _users = new List <Person>();
                Random random = new Random();

                string[] names    = Enum.GetNames(typeof(Names));
                string[] surnames = Enum.GetNames(typeof(Surnames));

                for (int i = 0; i < 50; ++i)
                {
                    int      currName    = random.Next(0, 10);
                    int      currSurname = random.Next(0, 10);
                    DateTime birthday    = new DateTime(random.Next(1885, 2019), random.Next(1, 12), random.Next(1, 28));
                    string   email       = surnames[currSurname] + "@test.com";

                    Person tmp = new Person(names[currName], surnames[currSurname], email, birthday);

                    _users.Add(tmp);
                }

                SaveChanges();
            }
        }
        public void AzureQueueBatchContainerV2_Serialize_IfNotNull()
        {
            var container = CreateAzureQueueBatchContainer();
            var writer    = new SerializationContext
            {
                StreamWriter = new BinaryTokenStreamWriter()
            };

            AzureQueueBatchContainerV2.Serialize(container, writer, null);
            var reader = new DeserializationContext
            {
                StreamReader = new BinaryTokenStreamReader(writer.StreamWriter.ToByteArray())
            };

            var deserialized = AzureQueueBatchContainerV2.Deserialize(typeof(AzureQueueBatchContainer), reader) as AzureQueueBatchContainerV2;

            ValidateIdenticalQueueBatchContainerButNotSame(container, deserialized);

            var streamWriter = new BinaryTokenStreamWriter();

            SerializationManager.Serialize(container, streamWriter);
            var streamReader = new BinaryTokenStreamReader(streamWriter.ToByteArray());

            deserialized = SerializationManager.Deserialize <AzureQueueBatchContainerV2>(streamReader);
            ValidateIdenticalQueueBatchContainerButNotSame(container, deserialized);
        }
Esempio n. 9
0
        internal SerializedDataStorage()
        {
            try
            {
                _users = SerializationManager.Deserialize <List <Person> >(FileFolderHelper.StorageFilePath);
            }
            catch (FileNotFoundException)
            {
                _users = new List <Person>();

                Random   rnd        = new Random();
                string[] lastNames  = { "Rubka", "Kraevoy", "Volkov", "Sobolevsky", "Kreyman", "Maliukova", "Bondar", "Black", "Bond", "Bing" };
                string[] firstNames = { "Mary", "Ann", "Katy", "Danya", "Hlib", "Vova", "Alla", "Denys", "Sasha", "Maryna" };
                string   fn;
                string   ln;
                for (int i = 0; i < 50; i++)
                {
                    AddUser(new Person(fn = firstNames[rnd.Next(0, 10)], ln = lastNames[rnd.Next(0, 10)],
                                       $"{fn}{ln}@ukma.edu.ua", new DateTime(
                                           rnd.Next(DateTime.Today.Year - 100, DateTime.Today.Year - 1),
                                           rnd.Next(1, 13), rnd.Next(1, 30))));
                }

                SaveChanges();
            }
        }
Esempio n. 10
0
        public static Project OpenProject(string projectFile)
        {
            CloseProject();
            var project = Project.Load(projectFile);

            CurrentProject = project;

            var shell = App.Current.Shell;
            var scene = new SceneViewModel();

            using (
                var stream = File.Open(Path.Combine(CurrentProject.ProjectPath, ".datamodel"),
                                       FileMode.Open))
            {
                var game = InstanceManager.DataModel;

                SerializationManager.Deserialize(stream, game);

                if (File.Exists(game.StartupPlace))
                {
                    InstanceManager.Workspace.LoadPlace(game.StartupPlace);
                }
            }

            shell.OpenDocument(scene);
            shell.Scene = scene;

            return(project);
        }
        public void ExceptionSerializer_SimpleException()
        {
            // Throw an exception so that is has a stack trace.
            var expected = GetNewException();

            var writer = new SerializationContext
            {
                StreamWriter = new BinaryTokenStreamWriter()
            };

            // Deep copies should be reference-equal.
            Assert.Equal(expected, SerializationManager.DeepCopyInner(expected, new SerializationContext()), ReferenceEqualsComparer.Instance);

            SerializationManager.Serialize(expected, writer.StreamWriter);
            var reader = new DeserializationContext
            {
                StreamReader = new BinaryTokenStreamReader(writer.StreamWriter.ToByteArray())
            };

            var actual = (ILExceptionSerializerTestException)SerializationManager.Deserialize(null, reader.StreamReader);

            Assert.Equal(expected.BaseField.Value, actual.BaseField.Value, StringComparer.Ordinal);
            Assert.Equal(expected.SubClassField, actual.SubClassField, StringComparer.Ordinal);
            Assert.Equal(expected.OtherField.Value, actual.OtherField.Value, StringComparer.Ordinal);

            // Check for referential equality in the two fields which happened to be reference-equals.
            Assert.Equal(actual.BaseField, actual.OtherField, ReferenceEqualsComparer.Instance);
        }
            public IBatchContainer GetBatchContainer(ref CachedMessage cachedMessage)
            {
                //Deserialize payload
                var             stream    = new BinaryTokenStreamReader(cachedMessage.Payload);
                MemoryEventData eventData = (MemoryEventData)SerializationManager.Deserialize(stream);

                return(new MemoryBatchContainer(eventData, cachedMessage.SequenceNumber));
            }
Esempio n. 13
0
 public IBatchContainer GetBatchContainer(ref CachedMessage cachedMessage)
 {
     //Deserialize payload
     var stream = new BinaryTokenStreamReader(cachedMessage.Payload);
     object payloadObject = SerializationManager.Deserialize(stream);
     return new GeneratedBatchContainer(cachedMessage.StreamGuid, cachedMessage.StreamNamespace,
         payloadObject, new EventSequenceToken(cachedMessage.SequenceNumber));
 }
        public T RoundTripSerialization <T>(T source)
        {
            BinaryTokenStreamWriter writer = new BinaryTokenStreamWriter();

            SerializationManager.Serialize(source, writer);
            T output = (T)SerializationManager.Deserialize(new BinaryTokenStreamReader(writer.ToByteArray()));

            return(output);
        }
Esempio n. 15
0
        public void TestBasicSerializationAndDeserializationUsage()
        {
            int    i    = 12;
            string data = SerializationManager.Serialize(i);

            Assert.AreEqual(data, "12");
            i = (int)SerializationManager.Deserialize(typeof(int), data);
            Assert.AreEqual(i, 12);
        }
            public IBatchContainer GetBatchContainer(ref CachedMessage cachedMessage)
            {
                //Deserialize payload
                var stream = new BinaryTokenStreamReader(cachedMessage.Payload.ToArray());
                //object payloadObject = SerializationManager.Deserialize(stream);
                var payloadObject = SerializationManager.Deserialize <List <object> >(stream);

                return(new PlainBatchContainer(cachedMessage.StreamGuid, cachedMessage.StreamNamespace,
                                               payloadObject, new SimpleSequenceToken(cachedMessage.SequenceNumber)));
            }
Esempio n. 17
0
 internal SerializedDataStorage()
 {
     try
     {
         _indexedDirs = SerializationManager.Deserialize <Dictionary <String, int> >(FileFolderHelper.StorageFilePath);
     }
     catch (FileNotFoundException)
     {
         _indexedDirs = new Dictionary <String, int>();
     }
 }
        public void PrivatePropertiesWithSettersSerialized()
        {
            var de  = new MockDomainEvent("Tom", "Green");
            var mgr = new SerializationManager();

            var json = mgr.Serialize(de, ContentTypes.Json);
            var de2  = mgr.Deserialize <MockDomainEvent>(ContentTypes.Json, json);

            de2.FirstName.Should().Be(de.FirstName);
            de2.LastName.Should().Be(de.LastName);
        }
Esempio n. 19
0
 /// <summary>
 /// Get logged in user (that was saved after previous app runs).
 /// </summary>
 /// <returns>Logged in user</returns>
 public CustomerDTO GetCurrentUser()
 {
     try
     {
         return(SerializationManager.Deserialize <CustomerDTO>(FileFolderHelper.StorageFilePath));
     }
     catch (FileNotFoundException)
     {
         return(null);
     }
 }
Esempio n. 20
0
        private static object DeserializeBody(SerializationManager serializationManager, List <ArraySegment <byte> > bytes)
        {
            if (bytes == null)
            {
                return(null);
            }

            var stream = new BinaryTokenStreamReader(bytes);

            return(serializationManager.Deserialize(stream));
        }
Esempio n. 21
0
 internal SerializedDataStorage()
 {
     try
     {
         _users = SerializationManager.Deserialize <List <User> >(FileFolderHelper.StorageFilePath);
     }
     catch (FileNotFoundException)
     {
         _users = new List <User>();
     }
 }
Esempio n. 22
0
 internal SerializedDataStorage()
 {
     try
     {
         _users = SerializationManager.Deserialize <List <User> >(FileFolderHelper.StorageFilePath);
     }
     catch (FileNotFoundException ex)
     {
         Logger.SaveIntoFile(ex, FileFolderHelper.ExceptionLogFilePath);
         _users = new List <User>();
     }
 }
Esempio n. 23
0
        private List <Data> DeserializeTestIOff()
        {
            ErrInfLogger.LockInstance.InfoLog("Start of the DeserializeTestIOff");

            SerializationManager <ObjectToUse> SM = new SerializationManager <ObjectToUse>(SingletonStorage.Instance.s_Path);
            ObjectToUse OTU = new ObjectToUse();

            OTU = SM.Deserialize();

            ErrInfLogger.LockInstance.InfoLog("End of the DeserializeTestIOff");
            return(OTU.s_DataList);
        }
Esempio n. 24
0
 internal SerializedDataStorage()
 {
     try
     {
         _persons = SerializationManager.Deserialize <List <Person> >(FileFolderHelper.StorageFilePath);
     }
     catch (FileNotFoundException)
     {
         _persons = new List <Person>();
         AddPersonsToInitialize();
     }
 }
Esempio n. 25
0
 internal SerializedDataStorage()
 {
     try
     {
         _user = SerializationManager.Deserialize <UserLocal>(FileFolderHelper.StorageFilePath);
     }
     catch (FileNotFoundException)
     {
         _user = new UserLocal();
         //_user = null;
     }
 }
 internal SerializedDataStorage()
 {
     try
     {
         _persons = SerializationManager.Deserialize <ObservableCollection <Person> >(FileFolderHelper.StorageFilePath);
     }
     catch (FileNotFoundException)
     {
         _persons = new ObservableCollection <Person>();
         FillPersons();
     }
 }
Esempio n. 27
0
 internal SerializedDataStorage()
 {
     try
     {
         _persons = SerializationManager.Deserialize <List <Person> >(FileFolderHelper.StorageFilePath);
     }
     catch (FileNotFoundException)
     {
         _persons = new List <Person>();
         FillWithInitialPersons();
         SaveChanges();
     }
 }
Esempio n. 28
0
        public GameWindow()
        {
            _game = SerializationManager.Deserialize();

            InitializeComponent();

            WindowState     = FormWindowState.Maximized;
            FormBorderStyle = FormBorderStyle.None;
            Bounds          = Screen.PrimaryScreen.Bounds;

            ShowPanel(panelMenu);
            pictureBoxGameBoard.Image = _game.GetDrawnBoard();
        }
Esempio n. 29
0
        private void shapes_Click(object sender, EventArgs e)
        {
            ToolStripItem toolStripItem = (sender as ToolStripItem);
            string        name          = toolStripItem.Text;

            string filePath = SampleShapes.BuildFilePath(name);
            SerializationManager manager   = new SerializationManager();
            List <Triangle>      triangles = manager.Deserialize(filePath);

            shapes.AddRange(triangles);

            picBox.Invalidate();
        }
 internal SerializedDataStorage()
 {
     try
     {
         UsersList = SerializationManager.Deserialize <ObservableCollection <Person> >(FileFolderHelper.StorageFilePath);
     }
     catch (FileNotFoundException)
     {
         UsersList = new ObservableCollection <Person>();
         InitFill();
         SaveChanges();
     }
 }