internal static AVPage GetAVPageFromBytes(byte[] BytesToConvert) { using (MemoryStream StreamConverter = new MemoryStream(BytesToConvert)) { BinaryFormatter ClassFormatter = new BinaryFormatter(); StreamConverter.Position = 0; object ReceivedObject = ClassFormatter.Deserialize(StreamConverter); AVPage PageToReturn = (AVPage)ReceivedObject; return(PageToReturn); } }
internal static void AssignCurrentUserPage(byte[] Data) { try { Console.WriteLine("Creating new page class for " + CurrentUser); AVPage UserPage = GetAVPageFromBytes(Data); Console.WriteLine("Created new page class for " + CurrentUser); try { WindowController.MainPage.Dispatcher.Invoke(() => { WindowController.MainPage.AssignCurrentUserCover(UserPage.Banner); }); Task.Run(() => Console.WriteLine("Updated " + CurrentUser + "'s cover picture successfully")); } catch (Exception exc) { Task.Run(() => Console.WriteLine("Couldn't update cover picture due to " + exc)); } try { WindowController.MainPage.Dispatcher.Invoke(() => { using (MemoryStream CurrentClientContentMemoryStream = new MemoryStream(UserPage.Content)) { TextRange TextRangeToAppend = new TextRange(WindowController.MainPage.ProfilePageRichTextBox.Document.ContentStart, WindowController.MainPage.ProfilePageRichTextBox.Document.ContentEnd); TextRangeToAppend.Load(CurrentClientContentMemoryStream, DataFormats.Rtf); } }); Console.WriteLine("Loaded content successfully"); } catch (Exception exc) { Console.WriteLine("Couldn't load content due to " + exc); } } catch (Exception exc) { Console.WriteLine("Couldn't deserialize the data due to " + exc); } }