public static byte[] ToBytes(this PVCFrame frame) { IFormatter formatter = new BinaryFormatter(); //IFormatter formatter = new JsonNetFormatter(); formatter.SurrogateSelector = PUtil.FrameworkSurrogateSelector; MemoryStream stream = new MemoryStream(); PStream pStream = new PStream(stream); pStream.WriteObjectTree(formatter, frame); return(stream.ToArray()); }
public static PVCFrame ToFrame(this byte[] byteArray) { PVCFrame frame = null; IFormatter formatter = new BinaryFormatter(); //IFormatter formatter = new JsonNetFormatter(); formatter.SurrogateSelector = PUtil.FrameworkSurrogateSelector; MemoryStream stream = new MemoryStream(byteArray); PStream pStream = new PStream(stream); frame = (PVCFrame)pStream.ReadObjectTree(formatter); stream.Close(); return(frame); }
private void InitFrame() { if (ViewModel.Frame == null) { ProfileType p = Storage.GetAll <ProfileType>().Find(i => i.Shape == ProfileShape.L); if (p == null) { MessageBox.Show("There is no profile type defined.", "Error", MessageBoxButton.OK, MessageBoxImage.Error); return; } Frame = new PVCFrame(ViewModel.Width, ViewModel.Height, Storage.GetAll <ProfileType>()[0]); ViewModel.Modified = true; Frame.FontSize = (float)FrameFontSize.SelectedItem; } else { Frame = (PVCFrame)ViewModel.Frame.ToFrame(); FrameFontSize.SelectedValue = Frame.FontSize; } Frame.Click += Frame_Click; Frame.Model.Code = ViewModel.Code; ShowCodesCheckBox.IsChecked = Frame.ShowCodes; Canvas.Layer.AddChild(Frame); SelectionEventHandler = new SelectionEventHandler(Frame); DivisionEventHandler = new DivisionEventHandler(Frame.Surface); SashCreationEventHandler = new SashCreationEventHandler(Frame.Surface); FillingCreationEventHandler = new FillingCreationEventHandler(Frame.Surface); DragEventHandler = new MullionDragEventHandler(Canvas, Frame); PanEventHandler = new PPanEventHandler(); Decorator = new FrameDecorator(Frame, Canvas.Layer); Decorator.EnableFrameDecorator(); SelectionEventHandler.SelectionChanged += SelectionEventHandler_SelectionChanged; LProfileComboBox.SelectedItem = Frame.Model.ProfileType; UProfileComboBox.SelectedItem = Frame.Model.UProfileType; OnPropertyChanged("UnitWidth"); OnPropertyChanged("UnitHeight"); Frame.DimensionChanged += Frame_DimensionChanged; }