Deserialize() public method

public Deserialize ( Stream serializationStream ) : object
serializationStream Stream
return object
        private void ReReadFiles()
        {
            FilesGrid.Items.Clear();
            try
            {
                Configuration config = (App.Current as App).config;
                using (TcpClient eClient = new TcpClient(config.IP.ToString(), config.Port))
                {
                    using (NetworkStream writerStream = eClient.GetStream())
                    {
                        MSG message = new MSG();
                        message.stat = STATUS.GET_FILES;
                        BinaryFormatter formatter = new BinaryFormatter();
                        formatter.Serialize(writerStream, message);
                        formatter.Serialize(writerStream, _eventId);
                        formatter.Serialize(writerStream, true);
                        _instrFiles = (Dictionary<string, string>)formatter.Deserialize(writerStream);
                        _studFiles = (Dictionary<string, string>)formatter.Deserialize(writerStream);
                        foreach (var file in _instrFiles)
                        {
                            FilesGrid.Items.Add(new FileRow(file.Key, "Викладач"));
                        }
                        foreach (var file in _studFiles)
                        {
                            FilesGrid.Items.Add(new FileRow(file.Key, "Студент"));
                        }
                    }
                }

            }
            catch (Exception)
            {
                MessageBox.Show("Помилка додавання файлу");
            }
        }
 private void UpdateSpecialities()
 {
     SpecialityGrid.Items.Clear();
     try
     {
         Configuration config = (App.Current as App).config;
         using (TcpClient eClient = new TcpClient(config.IP.ToString(), config.Port))
         {
             using (NetworkStream writerStream = eClient.GetStream())
             {
                 MSG message = new MSG();
                 message.stat = STATUS.GET_SPECIALITIES;
                 BinaryFormatter formatter = new BinaryFormatter();
                 formatter.Serialize(writerStream, message);
                 if ((bool)formatter.Deserialize(writerStream))
                 {
                     _specialityCollection = (List<Speciality>)formatter.Deserialize(writerStream);
                 }
             }
         }
     }
     catch (Exception)
     {
         throw;
     }
     foreach (var speciality in _specialityCollection)
     {
         SpecialityGrid.Items.Add(speciality);
     }
 }
Example #3
0
 public void Load(String filename)
 {
     FileStream fs = new FileStream(filename, FileMode.Open);
     BinaryFormatter f = new BinaryFormatter();
     simulation = (Common.Motion.Simulation)f.Deserialize(fs);
     zombieSimulation = (Common.Motion.Simulation)f.Deserialize(fs);
 }
		public Constants.LoginStatus logon(User user)
		{
			Constants.LoginStatus retval = Constants.LoginStatus.STATUS_SERVERNOTREACHED;
			byte[] message = new byte[Constants.WRITEBUFFSIZE];
			byte[] reply;
			MemoryStream stream = new MemoryStream(message);

			try
			{
				//Serialize data in memory so you can send them as a continuous stream
				BinaryFormatter serializer = new BinaryFormatter();
				
				NetLib.insertEntropyHeader(serializer, stream);

				serializer.Serialize(stream, Constants.MessageTypes.MSG_LOGIN);
				serializer.Serialize(stream, user.ringsInfo[0].ring.ringID);
				serializer.Serialize(stream, user.ringsInfo[0].userName);
				serializer.Serialize(stream, user.ringsInfo[0].password);
				serializer.Serialize(stream, user.node.syncCommunicationPoint);
				reply = NetLib.communicate(Constants.SERVER2,message, true);
				stream.Close();
				stream = new MemoryStream(reply);
				NetLib.bypassEntropyHeader(serializer, stream);
				Constants.MessageTypes replyMsg = (Constants.MessageTypes)serializer.Deserialize(stream);

				switch(replyMsg)
				{
					case Constants.MessageTypes.MSG_OK:
						ulong sessionID = (ulong)serializer.Deserialize(stream);
						uint numRings = (uint)serializer.Deserialize(stream);
						uint ringID;
						Ring ring;
						for(uint ringCounter = 0; ringCounter < numRings; ringCounter++)
						{
							LordInfo lordInfo = (LordInfo)serializer.Deserialize(stream);
							ring = RingInfo.findRingByID(user.ringsInfo, lordInfo.ringID);
							ring.lords = lordInfo.lords;
						}
						
						user.loggedIn = true;
						retval = Constants.LoginStatus.STATUS_LOGGEDIN;
						break;
					case Constants.MessageTypes.MSG_NOTAMEMBER:
						retval = Constants.LoginStatus.STATUS_NOTAMEMBER;
						break;
					case Constants.MessageTypes.MSG_ALREADYSIGNEDIN:
						retval = Constants.LoginStatus.STATUS_ALREADYSIGNEDIN;
						break;
					default:
						break;
				}
			}
			catch (Exception e)
			{
				
				int x = 2;
			}

			return retval;
		}
Example #5
0
 public void Setup()
 {
     IFormatter formatter = new BinaryFormatter();
     _scrapeOne = (Scrape)formatter.Deserialize(GetResourceStream("QualityBot.Test.Tests.TestData.FakeAncestryDevScrape.bin"));
     _scrapeTwo = (Scrape)formatter.Deserialize(GetResourceStream("QualityBot.Test.Tests.TestData.FakeAncestryStageScrape.bin"));
     _comparer = new Comparer();
 }
        public IEnumerable<Event> EventsFor(Guid aggregateRootId)
        {
            var idpair = new KeyValuePair<string, object>("@AggregateRootId", aggregateRootId);

            var snapshots = readRepository.All("SELECT * FROM [Snapshots] WHERE [AggregateRootId] = @AggregateRootId ORDER BY [DateTime] DESC", new[] { idpair });
            var snapshot = snapshots.FirstOrDefault();
            var date = epoch;
            if (snapshot != null)
                date = snapshot.DateTime;

            var events = readRepository.All("SELECT * FROM [Events] WHERE [AggregateRootId] = @AggregateRootId AND [DateTime] > @Date ORDER BY [DateTime]", new[] { idpair, new KeyValuePair<string, object>("@Date", date) });

            var formatter = new BinaryFormatter();

            if (date > epoch)
                yield return formatter.Deserialize(new MemoryStream((byte[])snapshot.Snapshot)) as Event;

            foreach (var @event in events)
            {
//Console.WriteLine("deserializing: " + @event.Id);
                var stream = new MemoryStream((byte[])@event.Event);

                yield return formatter.Deserialize(stream) as Event;
            }
        }
        public static void Main()
        {
            //Tworzenie Obiektów do serializacji
               Klasa ob = new Klasa ("ob1", 1);
               Klasa ob2 = new Klasa ("ob2", 5);

               Console.WriteLine ("Przed serializacją");
               ob.print ();
               ob2.print ();

               BinaryFormatter Formater = new BinaryFormatter();
               FileStream str = new FileStream ("Serial.bin", FileMode.Create, FileAccess.Write);

               //Serializowanie do strumienia
               Formater.Serialize (str, ob);
               Formater.Serialize (str, ob2);
               str.Close ();

               //Deserializacja
               str = new FileStream ("Serial.bin", FileMode.Open, FileAccess.Read);
               Klasa w = (Klasa)Formater.Deserialize (str);
               Klasa w2 = (Klasa)Formater.Deserialize (str);

               Console.WriteLine ("Po serializacji");
               w.print ();
               w2.print ();
               Console.ReadKey ();
        }
Example #8
0
        public FileCacheItem Deserialize(Stream stream)
        {
            var surrogateSelector = new AnonymousTypeSurrogateSelector();
            surrogateSelector.AddSurrogate(typeof(CacheItemPolicy), new StreamingContext(StreamingContextStates.All), new CacheItemPolicySurrogate());

            BinaryFormatter formatter = new BinaryFormatter();
            formatter.SurrogateSelector = surrogateSelector;
            formatter.Binder = _binder;

            FileCacheItem item = null;

            try
            {
                string key = (string)formatter.Deserialize(stream);
                CacheItemPolicy policy = (CacheItemPolicy)formatter.Deserialize(stream);
                object payload = formatter.Deserialize(stream);

                item = new FileCacheItem(key, policy, payload);
            }
            catch (SerializationException)
            {

            }

            return item;
        }
Example #9
0
      public void Load()
      {
         // Load preferencies
         FileStream fs;
         try
         {
            fs = new FileStream(GetUserDataPath(), FileMode.Open, FileAccess.Read);
            BinaryFormatter b = new BinaryFormatter();
            fs.Seek(0, SeekOrigin.Begin);

            Nick = (string)b.Deserialize(fs);
            Host = (string)b.Deserialize(fs);
            Port = (string)b.Deserialize(fs);
            TextColor = (Color)b.Deserialize(fs);

            AutoRun = (bool)b.Deserialize(fs);
            AutoConnect = (bool)b.Deserialize(fs);
            RunMinimized = (bool)b.Deserialize(fs);

            fs.Close();
         }
         catch (Exception)
         {
            // No preferencies, use default
            Nick = "Your nick";
            Host = "localhost";
            Port = "14242";
            TextColor = Color.Black;

            AutoRun = false;
            AutoConnect = false;
            RunMinimized = false;
         }
      }
Example #10
0
        static void Main(string[] args)
        {
            Insect i = new Insect("Meadow Brow", 12);
            Stream sw = File.Create("Insects.bin");
            BinaryFormatter bf = new BinaryFormatter();
            bf.Serialize(sw, i);
            sw.Close();

            ArrayList box = new ArrayList();
            box.Add(new Insect("Marsh Fritillarry", 34));
            box.Add(new Insect("Speckled Wood", 56));
            box.Add(new Insect("Milkweed", 78));

            sw = File.Open("Insects.bin", FileMode.Append);
            bf.Serialize(sw, box);
            sw.Close();

            Stream sr = File.OpenRead("Insects.bin");
            Insect j = (Insect)bf.Deserialize(sr);
            Console.WriteLine(j);

            ArrayList bag = (ArrayList)bf.Deserialize(sr);
            sr.Close();

            foreach (Insect k in bag)
            {
                Console.WriteLine(k);
            }

            Console.ReadLine();
        }
 public async Task<Stream> Get(string endpoint, object args, string expectedContentType)
 {
     var cacheFileName = Path.Combine(_cacheDir, string.Concat((endpoint + "_" + args).Replace(" ", "").Split(Path.GetInvalidFileNameChars())));
     if (endpoint == "accounts/login")
     {
         if (File.Exists(cacheFileName))
         {
             using (var stream = File.OpenRead(cacheFileName))
             {
                 var formatter = new BinaryFormatter();
                 Cookies = (CookieContainer) formatter.Deserialize(stream);
                 _headers = (NameValueCollection) formatter.Deserialize(stream);
             }
             return Stream.Null;
         }
         return await _decorated.Get(endpoint, args, expectedContentType);
     }
     if (!File.Exists(cacheFileName))
     {
         using (var source = await _decorated.Get(endpoint, args, expectedContentType))
         using (var destination = File.OpenWrite(cacheFileName))
         {
             source.CopyTo(destination);
         }
     }
     return File.OpenRead(Path.Combine(_cacheDir, cacheFileName));
 }
Example #12
0
        public void Resume()
        {
            string fileName = "";
            if (sign == '$')
                fileName = "food.ser";
            if (sign == 'o')
                fileName = "snake.ser";
            if (sign == '#')
                fileName = "wall.ser";
            FileStream fs = new FileStream(fileName, FileMode.OpenOrCreate, FileAccess.ReadWrite);
            BinaryFormatter bf = new BinaryFormatter();
            try
            {
                if (sign == '$')
                    Game.food = bf.Deserialize(fs) as Food;
                if (sign == '#')
                    Game.wall = bf.Deserialize(fs) as Wall;

                if (sign == 'o')
                    Game.snake = bf.Deserialize(fs) as Snake;
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
            finally
            {
                fs.Close();
            }
        }
 public Dictionary<string, int> InitSubjectsTable()
 {
     try
     {
         Configuration config = (App.Current as App).config;
         using (TcpClient eClient = new TcpClient(config.IP.ToString(), config.Port))
         {
             using (NetworkStream writerStream = eClient.GetStream())
             {
                 MSG message = new MSG();
                 message.stat = STATUS.GET_SUBJECTS;
                 BinaryFormatter formatter = new BinaryFormatter();
                 formatter.Serialize(writerStream, message);
                 bool fl = (bool)formatter.Deserialize(writerStream);
                 if (fl)
                 {
                     _subjectsCollection = (Dictionary<string, int>)formatter.Deserialize(writerStream);
                 }
             }
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message, "Помилка", MessageBoxButton.OK, MessageBoxImage.Error);
     }
     return _subjectsCollection;
 }
Example #14
0
        static void Main(string[] args)
        {
            Ohjelma ohj1 = new Ohjelma { nimi = "muumit", kanava = "TV2", alkuaika = 8, loppuaika = 9, info = "muumit seikkailee" };
            Ohjelma ohj2 = new Ohjelma { nimi = "jattipotti", kanava = "MTV3", alkuaika = 8, loppuaika = 23, info = "voita tsiljoona euroa soita nyt heti" };
            List<Ohjelma> ohjelmat = new List<Ohjelma>();
            ohjelmat.Add(ohj1);
            ohjelmat.Add(ohj2);
            IFormatter formatter = new BinaryFormatter();
            foreach (Ohjelma o in ohjelmat)
            {
                Stream writeStream = new FileStream(o.nimi+".bin", FileMode.Create, FileAccess.Write, FileShare.None);
                
                formatter.Serialize(writeStream, o);
                writeStream.Close();
            }


            Stream readStream = new FileStream("jattipotti.bin", FileMode.Open, FileAccess.Read, FileShare.None);
            Ohjelma jattipotti = (Ohjelma) formatter.Deserialize(readStream);

            Console.WriteLine("nimi: {0}, kanava: {1}, alkuaika: {2}, loppuaika: {3}, info: {4}", jattipotti.nimi, jattipotti.kanava, 
                jattipotti.alkuaika, jattipotti.loppuaika, jattipotti.info);

            readStream = new FileStream("muumit.bin", FileMode.Open, FileAccess.Read, FileShare.None);
            Ohjelma muumit = (Ohjelma)formatter.Deserialize(readStream);

            Console.WriteLine("nimi: {0}, kanava: {1}, alkuaika: {2}, loppuaika: {3}, info: {4}", muumit.nimi, muumit.kanava,
                muumit.alkuaika, muumit.loppuaika, muumit.info);

        }
Example #15
0
        public void TestTeardDown()
        {
            foreach (Process oldProcess in processes) {
                while (!oldProcess.HasExited)
                    oldProcess.CloseMainWindow ();

                //System.Threading.Thread.Sleep (5000);

                // Print values to make sure if something changed
                Console.WriteLine ("ProcessId: {0}", oldProcess.Id);

                BinaryFormatter bf = new BinaryFormatter ();
                FileStream retrieveStream = new FileStream (string.Format("{0}.0.bin", oldProcess.Id), FileMode.Open);
                ArrayList oldArraylist = (ArrayList) bf.Deserialize(retrieveStream);              
                retrieveStream.Close ();
                retrieveStream.Dispose ();
                File.Delete(string.Format ("{0}.0.bin", oldProcess.Id));
                //
                retrieveStream = new FileStream (string.Format ("{0}.1.bin", oldProcess.Id), FileMode.Open);
                ArrayList newArrayList = (ArrayList) bf.Deserialize (retrieveStream);
                retrieveStream.Close ();
                retrieveStream.Dispose ();
                File.Delete (string.Format ("{0}.1.bin", oldProcess.Id));

                // If we fail here is because we *did* change something
                for (int index = 0; index < oldArraylist.Count; index++)
                    Assert.IsTrue (object.Equals(oldArraylist[index], newArrayList[index]),
                        string.Format("elements at index {0} are not equal", index));
            }
        }
Example #16
0
        public void Resume()
            // чтобы вернуться в предыдущее место делаем десериализатор
        {
            string fileName = "";
            if (sign == '*')
                fileName = "food.dat";
            if (sign == '#')

                fileName = "wall.dat";
            if (sign == 'o')
                fileName = "snake.dat";
            FileStream fs = new FileStream(fileName, FileMode.OpenOrCreate, FileAccess.ReadWrite);
            BinaryFormatter bf = new BinaryFormatter();

            if (sign == '*')
                Game.food = bf.Deserialize(fs) as Food;
            if (sign == '#')
                Game.wall = bf.Deserialize(fs) as Wall;

            if (sign == 'o')
                Game.snake = bf.Deserialize(fs) as Snake;

            fs.Close();

        }
 public Dictionary<GroupRow, int> InitGroupTable()
 {
     _groupsCollection.Clear();
     foreach (var faculty in EnumDecoder.StringToFaculties)
     {
         try
         {
             Configuration config = (App.Current as App).config;
             using (TcpClient eClient = new TcpClient(config.IP.ToString(), config.Port))
             {
                 using (NetworkStream writerStream = eClient.GetStream())
                 {
                     MSG message = new MSG();
                     message.stat = STATUS.GET_GROUP_BY_FACULTY;
                     BinaryFormatter formatter = new BinaryFormatter();
                     formatter.Serialize(writerStream, message); 
                     formatter.Serialize(writerStream, faculty.Value);
                     bool fl = (bool)formatter.Deserialize(writerStream);
                     if (fl)
                     {
                         foreach (var group in (Dictionary<string, int>)formatter.Deserialize(writerStream))
                         {
                             _groupsCollection.Add(new GroupRow(group.Key, faculty.Key), group.Value);
                         }
                     }
                 }
             }
         }
         catch (Exception ex)
         {
             MessageBox.Show(ex.Message, "Помилка", MessageBoxButton.OK, MessageBoxImage.Error);
         }
     }
     return _groupsCollection;
 }
Example #18
0
        public void Resume()
        {
            string fname = "snake.ser";
            if (sign == '@')
                fname = "food.ser";
            if (sign == '#')
                fname = "wall.ser";
            string path = @"C:\Users\Zhandos\Documents\Visual Studio 2012\Projects\mySnake\Snake\Snake\ser\" + fname;
            BinaryFormatter bf = new BinaryFormatter();
            FileStream fs = new FileStream(path, FileMode.Open, FileAccess.Read);

            if (sign == 'O')
            {
                updateConsole(color, ' ', ref Game.snake.body);
                Game.snake.body.Clear();
                Game.snake = bf.Deserialize(fs) as Snake;
                updateConsole(color, sign, ref Game.snake.body);
            }
            if (sign == '#')
            {
                updateConsole(color, ' ', ref Game.wall.body);
                Game.wall.body.Clear();
                Game.wall = bf.Deserialize(fs) as Wall;
                updateConsole(color, sign, ref Game.wall.body);
            }
            if (sign == '@')
            {
                updateConsole(color,' ', ref Game.food.body);
                Game.food.body.Clear();
                Game.food = bf.Deserialize(fs) as Food;
                updateConsole(color, sign, ref Game.food.body);
            }
            fs.Close();
        }
Example #19
0
File: Program.cs Project: sbst/code
        public static void DoAcceptTcpClientCallback(IAsyncResult ar)
        {
            Thread.Sleep(0);
            Byte[] bytes = new Byte[1024];
            String data = null;
            TcpListener listener = (TcpListener)ar.AsyncState;
            TcpClient client = listener.EndAcceptTcpClient(ar);
            Console.WriteLine("Client connect completed");

            data = null;
            NetworkStream stream = client.GetStream();

            BinaryFormatter outformat = new BinaryFormatter();

            string name;
            name = outformat.Deserialize(stream).ToString();
            FileStream fs = new FileStream("D:\\" + name, FileMode.OpenOrCreate);
            BinaryWriter bw = new BinaryWriter(fs);
            int count;
            count = int.Parse(outformat.Deserialize(stream).ToString());
            int i = 0;
            for (; i < count; i += 1024)
            {

                byte[] buf = (byte[])(outformat.Deserialize(stream));
                bw.Write(buf);
            }
            Console.WriteLine("Successfully read in D:\\" + name);
            bw.Close();
            fs.Close();
            tcpClientConnected.Set();
        }
Example #20
0
        static void LoadConsts(Stream fs) {
            var bf = new BinaryFormatter();

            GTA5Constants.PC_AES_KEY = (byte[]) bf.Deserialize(fs);
            GTA5Constants.PC_NG_KEYS = (byte[][]) bf.Deserialize(fs);
            GTA5Constants.PC_NG_DECRYPT_TABLES = (byte[][]) bf.Deserialize(fs);
            GTA5Constants.PC_LUT = (byte[]) bf.Deserialize(fs);
        }
Example #21
0
 public static void Deserialize(byte[] buffer, 
     out int messageKind, out MessageBase msg)
 {
     MemoryStream ms = new MemoryStream(buffer);
     BinaryFormatter formatter = new BinaryFormatter();
     messageKind = (int)formatter.Deserialize(ms);
     msg = (MessageBase)formatter.Deserialize(ms);
 }
Example #22
0
 public void GetMove(NetworkStream ns, View view, Game game )
 {
     BinaryFormatter formatter = new BinaryFormatter();
     Position from = (Position)formatter.Deserialize(ns);
     Position to = (Position)formatter.Deserialize(ns);
     // view
     view.Invoke(new Action(
         () => { game.Cell_Click(from); Thread.Sleep(100); game.Cell_Click(to); }));
 }
Example #23
0
        static void Main(string[] args)
        {
            BinaryFormatter bFormatter = new BinaryFormatter();

            FileStream inPut = new FileStream("C:\\Users\\DEVELOPER4\\Desktop\\savefile\\lolblackjagged.yup", FileMode.Open, FileAccess.Read);
            States state = new States();

            state.gridSize = (Size)bFormatter.Deserialize(inPut);

            state.innerRectColor = (Color[][])bFormatter.Deserialize(inPut);
            state.innerShapeColor = (Color[][])bFormatter.Deserialize(inPut);
            state.rectColor = (Color[][])bFormatter.Deserialize(inPut);
            state.shapeColor = (Color[][])bFormatter.Deserialize(inPut);
            state.types = (int[][])bFormatter.Deserialize(inPut);
            state.rotation = (int[][])bFormatter.Deserialize(inPut);
            state.values = (int[][])bFormatter.Deserialize(inPut);
            state.circleGrid = (Rectangle[][])bFormatter.Deserialize(inPut);
            state.rectangleGrid = (Rectangle[][])bFormatter.Deserialize(inPut);
            state.lvls = Converter.ToJagged(new int[state.gridSize.Height,state.gridSize.Width]);
            state.owned = new List<Location>[4];

            for (int i = 0; i < state.owned.Length; i++) {
                state.owned[i] = new List<Location>();
            }

            inPut.Close();

            Console.WriteLine("Number of Players?");
            state.numOfPlayers = Convert.ToInt32(Console.ReadLine());

            Console.WriteLine("Total Value?");
            state.totalValue = Convert.ToInt32(Console.ReadLine());

            //ICommandBoardService proxy;
            using (ServiceHost host = new ServiceHost(typeof(CommandBoardServiceLibrary.CommandBoardService)))
            {
                NetTcpBinding ntb = new NetTcpBinding();
                NetTcpSecurity nts = new NetTcpSecurity();
                nts.Mode = SecurityMode.None;
                ntb.Security = nts;

                host.AddServiceEndpoint(typeof(
                    CommandBoardServiceLibrary.ICommandBoardService),
                    new NetTcpBinding(),"net.tcp://localhost:9000/commandboard");
                host.Open();

                ICommandBoardService proxy = ChannelFactory<ICommandBoardService>.CreateChannel(
                             new NetTcpBinding(),
                            new EndpointAddress("net.tcp://localhost:9000/commandboard"));

                proxy.setState(state);

                Console.WriteLine("Good to go");
                Console.ReadLine();

            }
        }
Example #24
0
 private static void Load(string path, Script script)
 {
     var formatter = new BinaryFormatter();
     using (var stream = File.OpenRead(path))
     {
         script.RootBranches.AddRange((List<ScriptedRootBranch>)formatter.Deserialize(stream));
         script.Changesets.AddRange((List<ScriptedChangeset>)formatter.Deserialize(stream));
     }
 }
Example #25
0
        private LegacyDataLibrary(Stream file)
        {
            var formatter = new BinaryFormatter();

            trainingLibrary = (List<Tuple<string, List<int>>>)formatter.Deserialize(file);
            listOfIndicies = (List<List<int>>)formatter.Deserialize(file);
            listOfIndexLabels = (List<string>)formatter.Deserialize(file);

            ReferenceSet = new InMemoryReferenceSet(trainingLibrary.Select(t => new ReferenceItem(t.Item1, t.Item2)));
        }
Example #26
0
 public void Resume()
 {
     Type t = GetType();
     FileStream fs = new FileStream(string.Format("{0}.dat", t.Name), FileMode.Open, FileAccess.Read);
     BinaryFormatter bf = new BinaryFormatter();
     if (t == typeof(Wall)) Game.wall = bf.Deserialize(fs) as Wall;
     if (t == typeof(Snake)) Game.snake = bf.Deserialize(fs) as Snake;
     if (t == typeof(Food)) Game.food = bf.Deserialize(fs) as Food;
     fs.Close();
 }
Example #27
0
 public void Load()
 {
     var bf = new BinaryFormatter();
     var file = File.Open(Application.persistentDataPath + "\\" + gameObject.name + "statdata.bin", FileMode.Open);
     var file2 = File.Open(Application.persistentDataPath + "\\" + gameObject.name + "chardata.bin", FileMode.Open);
     Stats = (ModifiableStatistic[])bf.Deserialize(file);
     Characteristics = (Characteristic[])bf.Deserialize(file);
     file.Close();
     file2.Close();
 }
Example #28
0
        public void Resume2()
        {
            Type t = GetType();
            BinaryFormatter bf = new BinaryFormatter();
            FileStream fs = new FileStream(string.Format(@"C:\Users\Home\Source\Repos\labwork1\lab3_zmeika\lab3_zmeika\bin\Debug\{0}.dat", t.Name), FileMode.Open, FileAccess.Read);
            //BinaryFormatter bf = new BinaryFormatter();

            if (t == typeof(Wall)) Game.wall = bf.Deserialize(fs) as Wall;
            if (t == typeof(Snake)) Game.snake = bf.Deserialize(fs) as Snake;
            if (t == typeof(Food)) Game.food = bf.Deserialize(fs) as Food;
            fs.Close();
         }
 private void Login_Click(object sender, RoutedEventArgs e)
 {
     Configuration config = (App.Current as App).config;
     TcpClient eClient = new TcpClient();
     try
     {
         eClient = new TcpClient(config.IP.ToString(), config.Port);
         using (NetworkStream writerStream = eClient.GetStream())
         {
             MSG message = new MSG();
             message.stat = STATUS.LOGIN;
             BinaryFormatter formatter = new BinaryFormatter();
             formatter.Serialize(writerStream, message);
             formatter.Serialize(writerStream, LoginBox.Text);
             formatter.Serialize(writerStream, PasswordBox.Password);
             bool fl = (bool)formatter.Deserialize(writerStream);
             if (fl)
             {
                 Account ac = (Account)formatter.Deserialize(writerStream);
                 if (ac != null)
                 {
                     Instructor st;
                     if (ac is Instructor)
                     {
                         st = (Instructor)ac;
                         config.Login = LoginBox.Text;
                         config.Password = PasswordBox.Password;
                         (App.Current as App).SaveConfig();
                         (App.Current as App).instr = st;
                         NavigationService nav = NavigationService.GetNavigationService(this);
                         nav.Navigate(new System.Uri("MainWindow.xaml", UriKind.RelativeOrAbsolute));
                     }
                     else
                     {
                         MessageBox.Show("Невірний тип облікового запису");
                     }
                 }
             }
             else
             {
                 MessageBox.Show("Невірна комбінація");
             }
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
     }
     finally
     {
         eClient.Close();
     }
 }
Example #30
0
 protected override void Show(IDialogVisualizerService windowService, IVisualizerObjectProvider objectProvider)
 {
     Stream incomingData = objectProvider.GetData();
     BinaryFormatter formatter = new BinaryFormatter();
     string name = (string)formatter.Deserialize(incomingData);
     Bitmap pixeldata = (Bitmap)formatter.Deserialize(incomingData);
     using (BitmapForm form = new BitmapForm()) {
         form.Text = name;
         form.Bitmap = pixeldata;
         windowService.ShowDialog(form);
     }
 }