public AddSurrogate ( System type, System context, System surrogate ) : void | ||
type | System | |
context | System | |
surrogate | System | |
리턴 | void |
public BinaryMessageSerializer() { var surrogateSelector = new SurrogateSelector(); surrogateSelector.AddSurrogate(typeof(XDocument), new StreamingContext(StreamingContextStates.All), new XContainerSurrogate()); surrogateSelector.AddSurrogate(typeof(XElement), new StreamingContext(StreamingContextStates.All), new XElementSurrogate()); binaryFormatter.SurrogateSelector = surrogateSelector; }
/// <summary> /// Gets the surrogate selecteds for System.Drawing.Pen and System.Drawing.Brush /// </summary> /// <returns>SurrogateSelector</returns> public static SurrogateSelector GetSurrogateSelectors() { System.Runtime.Serialization.SurrogateSelector ss = new System.Runtime.Serialization.SurrogateSelector(); ss.AddSurrogate(typeof(Pen), new StreamingContext(StreamingContextStates.All), new SharpMap.Utilities.Surrogates.PenSurrogate()); ss.AddSurrogate(typeof(SolidBrush), new StreamingContext(StreamingContextStates.All), new SharpMap.Utilities.Surrogates.SolidBrushSurrogate()); ss.AddSurrogate(typeof(System.Drawing.TextureBrush), new StreamingContext(StreamingContextStates.All), new SharpMap.Utilities.Surrogates.TextureBrushSurrogate()); ss.AddSurrogate(typeof(Matrix), new StreamingContext(StreamingContextStates.All), new SharpMap.Utilities.Surrogates.MatrixSurrogate()); return ss; }
/// <summary> /// Gets the surrogate selecteds for System.Drawing.Pen and System.Drawing.Brush /// </summary> /// <returns>SurrogateSelector</returns> public static SurrogateSelector GetSurrogateSelectors() { System.Runtime.Serialization.SurrogateSelector ss = new System.Runtime.Serialization.SurrogateSelector(); ss.AddSurrogate(typeof(Pen), new StreamingContext(StreamingContextStates.All), new SharpMap.Utilities.Surrogates.PenSurrogate()); ss.AddSurrogate(typeof(SolidBrush), new StreamingContext(StreamingContextStates.All), new SharpMap.Utilities.Surrogates.SolidBrushSurrogate()); ss.AddSurrogate(typeof(System.Drawing.TextureBrush), new StreamingContext(StreamingContextStates.All), new SharpMap.Utilities.Surrogates.TextureBrushSurrogate()); ss.AddSurrogate(typeof(Matrix), new StreamingContext(StreamingContextStates.All), new SharpMap.Utilities.Surrogates.MatrixSurrogate()); return(ss); }
/// <summary> /// Gets the surrogate selecteds for System.Drawing.Pen and System.Drawing.Brush /// </summary> /// <returns>SurrogateSelector</returns> public static SurrogateSelector GetSurrogateSelectors() { SurrogateSelector ss = new SurrogateSelector(); ss.AddSurrogate(typeof (Pen), new StreamingContext(StreamingContextStates.All), new PenSurrogate()); ss.AddSurrogate(typeof (SolidBrush), new StreamingContext(StreamingContextStates.All), new SolidBrushSurrogate()); ss.AddSurrogate(typeof (TextureBrush), new StreamingContext(StreamingContextStates.All), new TextureBrushSurrogate()); ss.AddSurrogate(typeof (Matrix), new StreamingContext(StreamingContextStates.All), new MatrixSurrogate()); return ss; }
void ReadData() { StreamingContext context = new StreamingContext (StreamingContextStates.Other); SurrogateSelector sel = new SurrogateSelector(); sel.AddSurrogate (typeof (Point), context, new PointSurrogate()); sel.AddSurrogate (typeof (FalseISerializable), context, new FalseISerializableSurrogate()); BinaryFormatter f = new BinaryFormatter (sel, context); object list = f.Deserialize (ms); object[][] originalMsgData = null; IMessage[] calls = null; IMessage[] resps = null; originalMsgData = ProcessMessages (null, null); calls = new IMessage[originalMsgData.Length]; resps = new IMessage[originalMsgData.Length]; for (int n=0; n<originalMsgData.Length; n++) { calls[n] = (IMessage) f.Deserialize (ms); resps[n] = (IMessage) f.DeserializeMethodResponse (ms, null, (IMethodCallMessage)calls[n]); } f.Binder = new TestBinder (); object btbob = f.Deserialize (ms); ms.Close(); List expected = CreateTestData (); List actual = (List) list; expected.CheckEquals (actual, "List"); for (int i = 0; i < actual.children.Length - 1; ++i) if (actual.children [i].next != actual.children [i+1]) Assert.Fail ("Deserialization did not restore pointer graph"); BinderTester_A bta = CreateBinderTestData(); Assert.AreEqual (btbob.GetType(), typeof (BinderTester_B), "BinderTest.class"); BinderTester_B btb = btbob as BinderTester_B; if (btb != null) { Assert.AreEqual (btb.x, bta.x, "BinderTest.x"); Assert.AreEqual (btb.y, bta.y, "BinderTest.y"); } CheckMessages ("MethodCall", originalMsgData, ProcessMessages (null, calls)); CheckMessages ("MethodResponse", originalMsgData, ProcessMessages (null, resps)); }
protected override void OnDeserialize(System.Runtime.Serialization.IFormatter formatter, System.Runtime.Serialization.SurrogateSelector selector) { FlowchartSerialize surrogate = new FlowchartSerialize(); selector.AddSurrogate(typeof(Flowchart), new StreamingContext(StreamingContextStates.All), surrogate); base.OnDeserialize(formatter, selector); }
void ReadData() { StreamingContext context = new StreamingContext (StreamingContextStates.Other); SurrogateSelector sel = new SurrogateSelector(); sel.AddSurrogate (typeof (Point), context, new PointSurrogate()); sel.AddSurrogate (typeof (FalseISerializable), context, new FalseISerializableSurrogate()); BinaryFormatter f = new BinaryFormatter (sel, context); object list = f.Deserialize (ms); object[][] originalMsgData = null; IMessage[] calls = null; IMessage[] resps = null; originalMsgData = ProcessMessages (null, null); calls = new IMessage[originalMsgData.Length]; resps = new IMessage[originalMsgData.Length]; for (int n=0; n<originalMsgData.Length; n++) { calls[n] = (IMessage) f.Deserialize (ms); resps[n] = (IMessage) f.DeserializeMethodResponse (ms, null, (IMethodCallMessage)calls[n]); } f.Binder = new TestBinder (); object btbob = f.Deserialize (ms); ms.Close(); ((List)list).CheckEquals(CreateTestData()); BinderTester_A bta = CreateBinderTestData(); Assertion.AssertEquals ("BinderTest.class", btbob.GetType(), typeof (BinderTester_B)); BinderTester_B btb = btbob as BinderTester_B; if (btb != null) { Assertion.AssertEquals ("BinderTest.x", btb.x, bta.x); Assertion.AssertEquals ("BinderTest.y", btb.y, bta.y); } CheckMessages ("MethodCall", originalMsgData, ProcessMessages (null, calls)); CheckMessages ("MethodResponse", originalMsgData, ProcessMessages (null, resps)); }
void WriteData () { StreamingContext context = new StreamingContext (StreamingContextStates.Other); SurrogateSelector sel = new SurrogateSelector(); sel.AddSurrogate (typeof (Point), context, new PointSurrogate()); sel.AddSurrogate (typeof (FalseISerializable), context, new FalseISerializableSurrogate()); List list = CreateTestData(); BinderTester_A bta = CreateBinderTestData(); ms = new MemoryStream(); BinaryFormatter f = new BinaryFormatter (sel, new StreamingContext(StreamingContextStates.Other)); f.Serialize (ms, list); ProcessMessages (ms, null); f.Serialize (ms, bta); ms.Flush (); ms.Position = 0; }
private static void AddSurrogates(ref SurrogateSelector ss) { Vector2Surrogate Vector2_SS = new Vector2Surrogate(); ss.AddSurrogate(typeof(Vector2), new StreamingContext(StreamingContextStates.All), Vector2_SS); Vector3Surrogate Vector3_SS = new Vector3Surrogate(); ss.AddSurrogate(typeof(Vector3), new StreamingContext(StreamingContextStates.All), Vector3_SS); Vector4Surrogate Vector4_SS = new Vector4Surrogate(); ss.AddSurrogate(typeof(Vector4), new StreamingContext(StreamingContextStates.All), Vector4_SS); ColorSurrogate Color_SS = new ColorSurrogate(); ss.AddSurrogate(typeof(Color), new StreamingContext(StreamingContextStates.All), Color_SS); QuaternionSurrogate Quaternion_SS = new QuaternionSurrogate(); ss.AddSurrogate(typeof(Quaternion), new StreamingContext(StreamingContextStates.All), Quaternion_SS); //Reserved for future implementation //Texture2DSurrogate Texture2D_SS = new Texture2DSurrogate(); //ss.AddSurrogate(typeof(Texture2D), // new StreamingContext(StreamingContextStates.All), // Texture2D_SS); //GameObjectSurrogate GameObject_SS = new GameObjectSurrogate(); //ss.AddSurrogate(typeof(GameObject), // new StreamingContext(StreamingContextStates.All), // GameObject_SS); //TransformSurrogate Transform_SS = new TransformSurrogate(); //ss.AddSurrogate(typeof(Transform), // new StreamingContext(StreamingContextStates.All), // Transform_SS); }
/// <summary> /// Builds an ISurrugateSelector filled with all SerializationSurrogates /// valid for the given version. /// </summary> public ISurrogateSelector GetSurrogateSelectorFor(double version) { SurrogateSelector ss = new SurrogateSelector(); StreamingContext sc = new StreamingContext(StreamingContextStates.All); foreach (Registration reg in register) { if (reg.MatchesVersion(version)) { ss.AddSurrogate(reg.TargetType, sc, reg.Surrogate); } } return ss; }
public Scenario.Model.ScenarioModel Read() { using (Stream stream = File.Open(_path, FileMode.Open)) { var ss = new SurrogateSelector(); ss.AddSurrogate(typeof(System.Windows.Media.PathFigure), new StreamingContext(StreamingContextStates.All), new PathFigureSerializationSurrogate()); BinaryFormatter bformatter = new BinaryFormatter(); bformatter.SurrogateSelector = ss; Scenario.Model.ScenarioModel sc = (Scenario.Model.ScenarioModel)bformatter.Deserialize(stream); return sc; } }
public void Write(Scenario.Model.ScenarioModel scenario) { using (Stream stream = File.Open(_path, FileMode.Create)) { var ss = new SurrogateSelector(); ss.AddSurrogate(typeof(System.Windows.Media.PathFigure), new StreamingContext(StreamingContextStates.All), new PathFigureSerializationSurrogate()); BinaryFormatter bformatter = new BinaryFormatter(); bformatter.SurrogateSelector = ss; bformatter.Serialize(stream, scenario); } }
public static BinaryFormatter GetBinaryFormatter() { var ss = new SurrogateSelector(); ss.AddSurrogate(typeof (Vector3), new StreamingContext(StreamingContextStates.All), new NonSerializableSurrogate()); var bf = new BinaryFormatter { SurrogateSelector = ss, Binder = new ObjectEqualityComparerConverter() }; return bf; }
public void ISerializationSurrogate() { bool oldSetting = _dbContext.Configuration.ProxyCreationEnabled; _dbContext.Configuration.ProxyCreationEnabled = false; var surrogateSelector = new SurrogateSelector(); surrogateSelector.AddSurrogate(typeof(Order_Detail), new StreamingContext(StreamingContextStates.All), new OrderDetailSerializationSurrogate()); surrogateSelector.AddSurrogate(typeof(Order), new StreamingContext(StreamingContextStates.All), new OrderSerializationSurrogate()); var tester = new BinarySerializerTester<IEnumerable<Order_Detail>>( _testOutputHelper, new BinaryFormatter(surrogateSelector, new StreamingContext()), false); var orderDetails = _dbContext.Order_Details .Include(p => p.Product) .Include(p => p.Order) .Take(100) .ToList(); var deserializedOrderDetails = tester.SerializeAndDeserialize(orderDetails); _dbContext.Configuration.ProxyCreationEnabled = oldSetting; }
private static WorkflowCompilerResults DeserializeWrapperOutput(string fileName) { WorkflowCompilerResults results; using (Stream stream = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.Read)) { using (XmlReader reader = XmlReader.Create(stream)) { NetDataContractSerializer serializer = new NetDataContractSerializer(); SurrogateSelector selector = new SurrogateSelector(); selector.AddSurrogate(typeof(MemberAttributes), serializer.Context, new CompilerResultsSurrogate()); serializer.SurrogateSelector = selector; results = (WorkflowCompilerResults) serializer.ReadObject(reader); } } return results; }
public void ISerializationSurrogate() { var orderDetails = this.context.OrderDetails.Include(x => x.Product).ToList(); var selector = new SurrogateSelector(); selector.AddSurrogate( typeof(OrderDetail), new StreamingContext(StreamingContextStates.Persistence, null), new OrderDetailsSerializationSurrogate()); var binaryFormatter = new BinaryFormatter { SurrogateSelector = selector }; var tester = new BinaryDataContractSerializerTester<IEnumerable<OrderDetail>>(binaryFormatter, true); var orderDetailsBack = tester.SerializeAndDeserialize(orderDetails); }
public void ISerializationSurrogate() { var orderDetails = dbContext.Order_Details.Include(x => x.Product).ToArray(); var selector = new SurrogateSelector(); selector.AddSurrogate( typeof(Order_Detail), new StreamingContext(StreamingContextStates.Persistence, null), new SerializationSurrogate()); var tester = new SoapFormatterTester<IEnumerable<Order_Detail>>(new SoapFormatter(selector, new StreamingContext()), true); tester.SerializeAndDeserialize(orderDetails); }
private static void WriteCompilerOutput(string path, WorkflowCompilerResults results) { using (Stream stream = new FileStream(path, FileMode.Create, FileAccess.Write, FileShare.None)) { XmlWriterSettings settings = new XmlWriterSettings { Indent = true }; using (XmlWriter writer = XmlWriter.Create(stream, settings)) { NetDataContractSerializer serializer = new NetDataContractSerializer(); SurrogateSelector selector = new SurrogateSelector(); selector.AddSurrogate(typeof(MemberAttributes), serializer.Context, new CompilerResultsSurrogate()); serializer.SurrogateSelector = selector; serializer.WriteObject(writer, results); } } }
public void UsingISerializationSurrogates() { var surrogateSelector = new SurrogateSelector(); var streamingContext = new StreamingContext(StreamingContextStates.All); surrogateSelector.AddSurrogate(typeof(ClassWithSurrogate), streamingContext, new SurrogateClass()); var serializer = new FudgeSerializer(context); serializer.TypeMap.RegisterSurrogateSelector(surrogateSelector); // Check out the surrogate var surrogate = serializer.TypeMap.GetSurrogate(typeof(ClassWithSurrogate)); Assert.IsType<DotNetSerializationSurrogateSurrogate>(surrogate); Assert.IsType<SurrogateClass>(((DotNetSerializationSurrogateSurrogate)surrogate).SerializationSurrogate); var obj1 = new ClassWithSurrogate { A = 22 }; var msg = serializer.SerializeToMsg(obj1); var obj2 = (ClassWithSurrogate)serializer.Deserialize(msg); Assert.Equal(obj1.A, obj2.A); }
void WriteData () { StreamingContext context = new StreamingContext (StreamingContextStates.Other); SurrogateSelector sel = new SurrogateSelector(); sel.AddSurrogate (typeof (Point), context, new PointSurrogate()); List list = CreateTestData(); BinderTester_A bta = CreateBinderTestData(); ms = new MemoryStream(); SoapFormatter f = new SoapFormatter (sel, new StreamingContext(StreamingContextStates.Other)); f.Serialize (ms, list); // ProcessMessages (ms, null); // f.Serialize (ms, bta); ms.Flush (); ms.Position = 0; StreamReader reader = new StreamReader(ms); Console.WriteLine(reader.ReadToEnd()); ms.Position = 0; }
protected override void OnDeserialize(IFormatter formatter, SurrogateSelector selector) { SchemaModelSerialize surrogate = new SchemaModelSerialize(); selector.AddSurrogate(typeof(SchemaModel), new StreamingContext(StreamingContextStates.All), surrogate); base.OnDeserialize(formatter, selector); }
/// <summary> /// Gets the surrogate selecteds for System.Drawing.Pen and System.Drawing.Brush /// </summary> /// <returns>SurrogateSelector</returns> public static SurrogateSelector GetSurrogateSelectors() { var sc = new StreamingContext(StreamingContextStates.All); var ss = new SurrogateSelector(); ss.AddSurrogate(typeof (Pen), sc, new PenSurrogate()); ss.AddSurrogate(typeof (Brush), sc, new BrushSurrogate()); ss.AddSurrogate(typeof(SolidBrush), sc, new SolidBrushSurrogate()); ss.AddSurrogate(typeof(TextureBrush), sc, new TextureBrushSurrogate()); ss.AddSurrogate(typeof(HatchBrush), sc, new HatchBrushSurrogate()); ss.AddSurrogate(typeof(LinearGradientBrush), sc, new LinearGradientBrushSurrogate()); ss.AddSurrogate(typeof(AdjustableArrowCap), sc, new AdjustableArrowCapSurrogate()); #pragma warning disable 612,618 ss.AddSurrogate(typeof(CustomLineCap), sc, new CustomLineCapSurrogate()); #pragma warning restore 612,618 ss.AddSurrogate(typeof(GraphicsPath), sc, new GraphicsPathSurrogate()); ss.AddSurrogate(typeof(Blend), sc, new BlendSurrogate()); ss.AddSurrogate(typeof(ColorBlend), sc, new ColorBlendSurrogate()); ss.AddSurrogate(typeof(Matrix), sc, new MatrixSurrogate()); ss.AddSurrogate(typeof(StringFormat), sc, new StringFormatSurrogate()); ss.AddSurrogate(typeof(ImageFormat), sc, new ImageFormatSurrogate()); return ss; }
public void Save (Stream stream) { SurrogateSelector ss = new SurrogateSelector (); StreamingContext context = new StreamingContext ( StreamingContextStates.Persistence, this); ss.AddSurrogate (typeof (Foo), context, new Foo.SerializationSurrogate ()); BinaryFormatter formatter = new BinaryFormatter (ss, context); formatter.Serialize (stream, this); }
protected override void OnSerialize(IFormatter formatter, SurrogateSelector selector) { selector.AddSurrogate(typeof(Model),new StreamingContext(StreamingContextStates.All), new ModelSerialize()); base.OnSerialize (formatter, selector); }
protected override void OnDeserialize(System.Runtime.Serialization.IFormatter formatter, System.Runtime.Serialization.SurrogateSelector selector) { selector.AddSurrogate(typeof(CustomDiagram), new StreamingContext(StreamingContextStates.All), new CustomDiagramSerialize()); base.OnDeserialize(formatter, selector); }
public static Bar Load (Stream stream) { SurrogateSelector ss = new SurrogateSelector (); StreamingContext context = new StreamingContext ( StreamingContextStates.Persistence, null); ss.AddSurrogate (typeof (Foo), context, new Foo.SerializationSurrogate ()); BinaryFormatter formatter = new BinaryFormatter (ss, context); return (Bar) formatter.Deserialize (stream); }
public static ModelStencil Deserialize(String path) { ModelStencil modelStencil; Stream stream = null; //try //{ SoapFormatter sf = new SoapFormatter(); StreamReader streamReader = new StreamReader(path); stream = (streamReader).BaseStream; SurrogateSelector ss = new SurrogateSelector(); ss.AddSurrogate(typeof(ModelStencil), new StreamingContext(StreamingContextStates.All), new ModelStencilSerializationSurrogate()); sf.SurrogateSelector = ss; modelStencil = (ModelStencil)sf.Deserialize(stream); stream.Close(); //Serialize(path, modelStencil); //} //catch //{ // stream.Close(); // SoapFormatter sf = new SoapFormatter(); // StreamReader streamReader = new StreamReader(path); // stream = (streamReader).BaseStream; // modelStencil = (ModelStencil)sf.Deserialize(stream); // stream.Close(); // modelStencil.tag = Path.GetFileNameWithoutExtension(path); // Serialize(path, modelStencil); //} return modelStencil; }
/// <summary> /// TODO: Reusing the formatter will probably speed up the serializations allot, since it is /// complex creation procedure. /// </summary> /// <returns></returns> public static IFormatter GenerateFormatter() { // 1. Construct the desired formatter IFormatter formatter = new BinaryFormatter(); // 2. Construct a SurrogateSelector object SurrogateSelector surrogateSelector = new SurrogateSelector(); // 3. Tell the surrogate selector to use our object when a // object is serialized/deserialized //surrogateSelector.AddSurrogate(typeof(Color), // new StreamingContext(StreamingContextStates.All), // new ColorSurrogate()); //surrogateSelector.AddSurrogate(typeof(DragControl), // new StreamingContext(StreamingContextStates.All), // new MatrixSurrogate()); surrogateSelector.AddSurrogate(typeof(Matrix), new StreamingContext(StreamingContextStates.All), new MatrixSurrogate()); surrogateSelector.AddSurrogate(typeof(Pen), new StreamingContext(StreamingContextStates.All), new PenSurrogate()); surrogateSelector.AddSurrogate(typeof(SolidBrush), new StreamingContext(StreamingContextStates.All), new SolidBrushSurrogate()); surrogateSelector.AddSurrogate(typeof(LinearGradientBrush), new StreamingContext(StreamingContextStates.All), new LinearGradientBrushSurrogate()); surrogateSelector.AddSurrogate(typeof(Blend), new StreamingContext(StreamingContextStates.All), new BlendSurrogate()); surrogateSelector.AddSurrogate(typeof(ColorBlend), new StreamingContext(StreamingContextStates.All), new ColorBlendSurrogate()); formatter.SurrogateSelector = surrogateSelector; return formatter; }
public static void Serialize(string path, ModelStencil modelStencil) { SoapFormatter sf = new SoapFormatter(); StreamWriter streamWriter = new StreamWriter(path); Stream stream = streamWriter.BaseStream; SurrogateSelector ss = new SurrogateSelector(); ss.AddSurrogate(typeof(ModelStencil), new StreamingContext(StreamingContextStates.All), new ModelStencilSerializationSurrogate()); sf.SurrogateSelector = ss; sf.Serialize(stream, modelStencil); stream.Close(); }
/// <summary> /// Saves the Game into the folder. There will only be one such savegame at a time. /// </summary> public static void SaveGame() { //Create this file so we don't try to serialise a static class GameStateSaveFile saveFile = new GameStateSaveFile(); saveFile.GlobalMap = GameState.GlobalMap; saveFile.LocalMap = GameState.LocalMap; saveFile.PlayerCharacter = GameState.PlayerCharacter; saveFile.UniverseTime = GameState.UniverseTime; IFormatter formatter = new BinaryFormatter(); SurrogateSelector ss = new SurrogateSelector(); ss.AddSurrogate(typeof(Rectangle), new StreamingContext(StreamingContextStates.All), new RectSerializationSurrogate()); ss.AddSurrogate(typeof(Color), new StreamingContext(StreamingContextStates.All), new ColorSerializationSurrogate()); formatter.SurrogateSelector = ss; Stream stream = new FileStream(GameState.SAVEPATH + "GameState.dvg", FileMode.Create, FileAccess.Write, FileShare.None); formatter.Serialize(stream, saveFile); stream.Close(); }
/// <summary> /// Loads the game from the folder. There will only ever be one such savegame at a time. /// </summary> /// <returns></returns> public static void LoadGame() { IFormatter formatter = new BinaryFormatter(); SurrogateSelector ss = new SurrogateSelector(); ss.AddSurrogate(typeof(Rectangle), new StreamingContext(StreamingContextStates.All), new RectSerializationSurrogate()); ss.AddSurrogate(typeof(Color), new StreamingContext(StreamingContextStates.All), new ColorSerializationSurrogate()); formatter.SurrogateSelector = ss; Stream stream = new FileStream(GameState.SAVEPATH + "GameState.dvg", FileMode.Open, FileAccess.Read, FileShare.Read); GameStateSaveFile obj = (GameStateSaveFile)formatter.Deserialize(stream); stream.Close(); //Load it GameState.LocalMap = obj.LocalMap; GameState.LocalMap.Location = obj.LocalMap.Location; //This is to invoke the attachment of the minute check code GameState.GlobalMap = obj.GlobalMap; GameState.PlayerCharacter = obj.PlayerCharacter; GameState._universeTime = obj.UniverseTime; //Reattach handlers _universeTime.DayChanged += new System.EventHandler(DayChanged); _universeTime.MonthChanged += new System.EventHandler(MonthChanged); _universeTime.MinuteChanged += new EventHandler(MinuteChanged); }
private void SaveDiagram(Stream fs,IFormatter formatter) { SurrogateSelector selector = new SurrogateSelector(); try { selector.AddSurrogate(typeof(Diagram),new StreamingContext(StreamingContextStates.All), new DiagramSerialize()); //Raise the Serialize event and allow subclasses to add their own surrogates OnSerialize(formatter,selector); formatter.SurrogateSelector = selector; formatter.Serialize(fs, this); } catch (Exception ex) { if (ex.InnerException == null) { throw ex; } else { throw ex.InnerException; } } finally { } OnSerializeComplete(formatter,selector); }
private void LoadDiagram(Stream fs, IFormatter formatter) { Diagram diagram; SurrogateSelector selector = new SurrogateSelector(); DiagramSerialize surrogate = new DiagramSerialize(); try { selector.AddSurrogate(typeof(Diagram),new StreamingContext(StreamingContextStates.All), surrogate); //Raise the deserialize event and allow subclasses to add/change the surrogate to their own surrogate OnDeserialize(formatter,selector); formatter.SurrogateSelector = selector; formatter.Binder = Component.Instance.DefaultBinder; diagram = (Diagram) formatter.Deserialize(fs); } catch (Exception ex) { if (ex.InnerException == null) { throw ex; } else { throw ex.InnerException; } } finally { } surrogate = Serialization.Serialize.GetSurrogate(diagram,selector); if (surrogate == null) throw new Exception("A deserialization surrogate could not be found."); //Update this object using the surrogate and the diagram surrogate.UpdateObjectReferences(); SuspendEvents = true; Suspend(); //Copy settings from deserialized object DiagramSize = diagram.DiagramSize; Zoom = diagram.Zoom; ShowTooltips = diagram.ShowTooltips; CheckBounds = diagram.CheckBounds; Paged = diagram.Paged; WorkspaceColor = diagram.WorkspaceColor; //Copy all layers across Layers.Clear(); foreach (Layer layer in surrogate.Layers) { Layers.Add(layer); } Layers.CurrentLayer = surrogate.Layers.CurrentLayer; //Copy shapes and lines accross Shapes.Clear(); foreach (Shape shape in surrogate.Shapes.Values) { Shapes.Add(shape.Key,shape); } Lines.Clear(); foreach (Line line in surrogate.Lines.Values) { Lines.Add(line.Key,line); } mNavigate = new Navigation.Navigate(this); Route = new Route(); Route.Container = this; Margin = new Margin(); //##margin needs to be serialized/deserialized //Raise the deserialize complete event OnDeserializeComplete(diagram, formatter, selector); Resume(); SuspendEvents = false; Refresh(); }