Inheritance: ISurrogateSelector
Example #1
0
        public static SaveGame Load(string gameToLoad)
        {
            if (File.Exists(saveGamePath + gameToLoad + ".sav"))
            {

                BinaryFormatter bf = new BinaryFormatter();
                // 1. Construct a SurrogateSelector object
                SurrogateSelector ss = new SurrogateSelector();
                // 2. Add the ISerializationSurrogates to our new SurrogateSelector
                AddSurrogates(ref ss);
                // 3. Have the formatter use our surrogate selector
                bf.SurrogateSelector = ss;

                FileStream file = File.Open(saveGamePath + gameToLoad + ".sav", FileMode.Open);
                SaveGame loadedGame = (SaveGame)bf.Deserialize(file);
                file.Close();
                Debug.Log("Loaded Game: " + loadedGame.savegameName);
                return loadedGame;
            }
            else
            {
                Debug.Log(gameToLoad + " does not exist!");
                return null;
            }
        }
Example #2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="BinarySerializer"/> class.
 /// </summary>
 public BinarySerializer()
 {
     this.TypeLookupMode = TypeLookupModeEnum.AllowExactVersions;
     this.Context = new StreamingContext();
     SurrogateSelector ss = new SurrogateSelector();
     this.Selector = ss;
 }
        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;
        }
Example #4
0
 /// <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;
 }
Example #5
0
 /// <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>
		/// Construct a new VersionSupportingBinaryFormatter instance.
		/// </summary>
		public VersionSupportingBinaryFormatter()
		{
			formatter = new BinaryFormatter();
			SurrogateSelector surrogateSelector = new SurrogateSelector();
			formatter.SurrogateSelector = surrogateSelector;
			VersionSupportingSurrogateConnectingBinder  deserializationSurrogateConnectingBinder
				= new VersionSupportingSurrogateConnectingBinder(surrogateSelector);
			formatter.Binder = deserializationSurrogateConnectingBinder;
		}
 public void ConstructorArgChecking()
 {
     var typeData = new TypeData(context, new TypeDataCache(context), GetType(), FudgeFieldNameConvention.Identity);
     var surrogate = new SurrogateClass();
     var selector = new SurrogateSelector();
     Assert.Throws<ArgumentNullException>(() => new DotNetSerializationSurrogateSurrogate(null, typeData, surrogate, selector));
     Assert.Throws<ArgumentNullException>(() => new DotNetSerializationSurrogateSurrogate(context, null, surrogate, selector));
     Assert.Throws<ArgumentNullException>(() => new DotNetSerializationSurrogateSurrogate(context, typeData, null, selector));
 }
Example #8
0
 /// <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));
		}
		/// <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 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 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;
            }
        }
Example #13
0
        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;
        }
 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;
 }
 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 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);
        }
		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));
		}
        public static void AddSurrogate(Type type,ISerializationSurrogate surrogate)
        {
            if(__surrogateSelector==null){

                __surrogateSelector=new SurrogateSelector();

                __streamingContext=new StreamingContext();

            }

            ISurrogateSelector surrogateExist=null;

            __surrogateSelector.GetSurrogate (type, __streamingContext,out surrogateExist);

            if(surrogateExist==null)

                __surrogateSelector.AddSurrogate(type,__streamingContext, surrogate);
        }
Example #20
0
		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;
		}
        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);
        }
Example #22
0
		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;
		}
Example #23
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);
        }
Example #24
0
 /// <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;
 }
Example #25
0
        public static void Save(SaveGame saveGame)
        {

            BinaryFormatter bf = new BinaryFormatter();

            // 1. Construct a SurrogateSelector object
            SurrogateSelector ss = new SurrogateSelector();
            // 2. Add the ISerializationSurrogates to our new SurrogateSelector
            AddSurrogates(ref ss);
            // 3. Have the formatter use our surrogate selector
            bf.SurrogateSelector = ss;

            //Application.persistentDataPath is a string, so if you wanted you can put that into debug.log if you want to know where save games are located
            //You can also use any path you like
            CheckPath(saveGamePath);

            FileStream file = File.Create(saveGamePath + saveGame.savegameName + ".sav"); //you can call it anything you want including the file extension
            bf.Serialize(file, saveGame);
            file.Close();
            Debug.Log("Saved Game: " + saveGame.savegameName);

        }
        public static object Deserialize(byte[] data)
        {
            object result;

            if (__binaryFormater == null)
                __binaryFormater = new BinaryFormatter ();

            using (var stream = new System.IO.MemoryStream())
            {
                stream.Write(data,0,data.Length);
                stream.Seek(0, SeekOrigin.Begin);

                if(__surrogateSelector==null)
                    __surrogateSelector=new SurrogateSelector();

                __binaryFormater.SurrogateSelector=__surrogateSelector;

                result=__binaryFormater.Deserialize(stream);

            }

            return result;
        }
        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;
        }
Example #28
0
		public static DiagramSerialize GetSurrogate(object graph, SurrogateSelector selector)
		{
			//Retrieve the surrogate reference
			//Sub classes may have added other surrogates
			//Start with the type of the deserialized data
			Type type = graph.GetType().UnderlyingSystemType;
			ISurrogateSelector iselector = (ISurrogateSelector) selector;
			DiagramSerialize surrogate = null;
			
			//Walk through the types until we find a surrogate
			while (type != typeof(System.Windows.Forms.UserControl))
			{
				surrogate = (DiagramSerialize) selector.GetSurrogate(type,new StreamingContext(StreamingContextStates.All),out iselector);
				if (surrogate != null) break;
				type = type.BaseType; //return the base type and try again
			}
			return surrogate;
		}
        protected override void OnDeserializeComplete(object graph, IFormatter formatter, SurrogateSelector selector) {
            SchemaModelSerialize surrogate = (SchemaModelSerialize)Crainiate.ERM4.Serialization.Serialize.GetSurrogate(graph, selector);
            SchemaModel schemaModel = (SchemaModel)graph;

            // Apply Surrogate Settings
            this.SuspendEvents = true;
            this.Suspend();

            // Do Stuff
            this._workspaceType = schemaModel.WorkspaceType;
            this._version = schemaModel.Version;
            this._document = schemaModel.Document;
            this._metadata = schemaModel.Metadata;

            this.Resume();
            this.SuspendEvents = false;

            // Call Base Method
            base.OnDeserializeComplete(graph, formatter, selector);
        }
 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);
 }
Example #31
0
		protected override void OnDeserializeComplete(object graph, IFormatter formatter, SurrogateSelector selector)
		{
			ModelSerialize surrogate = (ModelSerialize) Serialization.Serialize.GetSurrogate(graph,selector);
			Model model = (Model) graph;

			//Apply surrogate settings
			SuspendEvents = true;
			Suspend();

			Runtime = surrogate.Runtime;
			Runtime.ActiveContainer = this;

			AlignGrid= model.AlignGrid;
			DragScroll = model.DragScroll;
			DrawGrid = model.DrawGrid;
			DrawPageLines = model.DrawPageLines;
			DrawSelections = model.DrawSelections;
			GridColor = model.GridColor;
			GridSize = model.GridSize;
			GridStyle = model.GridStyle;
			PageLineSize = model.PageLineSize;
			Margin = model.Margin;

			Resume();
			SuspendEvents = false;

			base.OnDeserializeComplete (graph, formatter, selector);
		}
Example #32
0
        public virtual void ChainSelector(ISurrogateSelector selector)
        {
            if (selector == null)
            {
                throw new ArgumentNullException("selector");
            }
            if (selector == this)
            {
                throw new SerializationException(Environment.GetResourceString("Serialization_DuplicateSelector"));
            }
            if (!SurrogateSelector.HasCycle(selector))
            {
                throw new ArgumentException(Environment.GetResourceString("Serialization_SurrogateCycleInArgument"), "selector");
            }
            ISurrogateSelector nextSelector       = selector.GetNextSelector();
            ISurrogateSelector surrogateSelector1 = selector;

            for (; nextSelector != null && nextSelector != this; nextSelector = nextSelector.GetNextSelector())
            {
                surrogateSelector1 = nextSelector;
            }
            if (nextSelector == this)
            {
                throw new ArgumentException(Environment.GetResourceString("Serialization_SurrogateCycle"), "selector");
            }
            ISurrogateSelector surrogateSelector2 = selector;
            ISurrogateSelector surrogateSelector3 = selector;

            while (surrogateSelector2 != null)
            {
                ISurrogateSelector surrogateSelector4 = surrogateSelector2 != surrogateSelector1?surrogateSelector2.GetNextSelector() : this.GetNextSelector();

                if (surrogateSelector4 != null)
                {
                    if (surrogateSelector4 == surrogateSelector3)
                    {
                        throw new ArgumentException(Environment.GetResourceString("Serialization_SurrogateCycle"), "selector");
                    }
                    surrogateSelector2 = surrogateSelector4 != surrogateSelector1?surrogateSelector4.GetNextSelector() : this.GetNextSelector();

                    surrogateSelector3 = surrogateSelector3 != surrogateSelector1?surrogateSelector3.GetNextSelector() : this.GetNextSelector();

                    if (surrogateSelector2 == surrogateSelector3)
                    {
                        throw new ArgumentException(Environment.GetResourceString("Serialization_SurrogateCycle"), "selector");
                    }
                }
                else
                {
                    break;
                }
            }
            ISurrogateSelector selector1 = this.m_nextSelector;

            this.m_nextSelector = selector;
            if (selector1 == null)
            {
                return;
            }
            surrogateSelector1.ChainSelector(selector1);
        }
        public virtual void ChainSelector(ISurrogateSelector selector)
        {
            if (selector == null)
            {
                throw new ArgumentNullException("selector");
            }
            if (selector == this)
            {
                throw new SerializationException(Environment.GetResourceString("Serialization_DuplicateSelector"));
            }
            if (!SurrogateSelector.HasCycle(selector))
            {
                throw new ArgumentException(Environment.GetResourceString("Serialization_SurrogateCycleInArgument"), "selector");
            }
            ISurrogateSelector surrogateSelector  = selector.GetNextSelector();
            ISurrogateSelector surrogateSelector2 = selector;

            while (surrogateSelector != null && surrogateSelector != this)
            {
                surrogateSelector2 = surrogateSelector;
                surrogateSelector  = surrogateSelector.GetNextSelector();
            }
            if (surrogateSelector == this)
            {
                throw new ArgumentException(Environment.GetResourceString("Serialization_SurrogateCycle"), "selector");
            }
            surrogateSelector = selector;
            ISurrogateSelector surrogateSelector3 = selector;

            while (surrogateSelector != null)
            {
                if (surrogateSelector == surrogateSelector2)
                {
                    surrogateSelector = this.GetNextSelector();
                }
                else
                {
                    surrogateSelector = surrogateSelector.GetNextSelector();
                }
                if (surrogateSelector == null)
                {
                    break;
                }
                if (surrogateSelector == surrogateSelector3)
                {
                    throw new ArgumentException(Environment.GetResourceString("Serialization_SurrogateCycle"), "selector");
                }
                if (surrogateSelector == surrogateSelector2)
                {
                    surrogateSelector = this.GetNextSelector();
                }
                else
                {
                    surrogateSelector = surrogateSelector.GetNextSelector();
                }
                if (surrogateSelector3 == surrogateSelector2)
                {
                    surrogateSelector3 = this.GetNextSelector();
                }
                else
                {
                    surrogateSelector3 = surrogateSelector3.GetNextSelector();
                }
                if (surrogateSelector == surrogateSelector3)
                {
                    throw new ArgumentException(Environment.GetResourceString("Serialization_SurrogateCycle"), "selector");
                }
            }
            ISurrogateSelector nextSelector = this.m_nextSelector;

            this.m_nextSelector = selector;
            if (nextSelector != null)
            {
                surrogateSelector2.ChainSelector(nextSelector);
            }
        }
Example #34
0
 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);
 }
Example #35
0
        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);
        }