本文整理汇总了C#中System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Deserialize方法的典型用法代码示例。如果您正苦于以下问题:C# BinaryFormatter.Deserialize方法的具体用法?C# BinaryFormatter.Deserialize怎么用?C# BinaryFormatter.Deserialize使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
的用法示例。
在下文中一共展示了BinaryFormatter.Deserialize方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ReReadFiles
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("Помилка додавання файлу");
}
}
示例2: UpdateSpecialities
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);
}
}
示例3: Load
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);
}
示例4: logon
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;
}
示例5: Setup
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();
}
示例6: EventsFor
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;
}
}
示例7: Main
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 ();
}
示例8: Deserialize
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;
}
示例9: Load
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;
}
}
示例10: Main
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();
}
示例11: Get
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));
}
示例12: Resume
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();
}
}
示例13: InitSubjectsTable
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;
}
示例14: Main
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);
}
示例15: TestTeardDown
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));
}
}