Ejemplo n.º 1
0
		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();
		}
Ejemplo n.º 2
0
		private void ClearDiagram()
		{
			SuspendEvents = true;

			//Set default layers collection, need for shapes and lines
			Layers = new Layers();
			mRenderList = new RenderList();

			//Set up shapes and lines, needed for navigation
			Shapes = new Elements(typeof(Shape),"Shape");
			Lines = new Elements(typeof(Line),"Line");
			
			mNavigate = new Navigation.Navigate(this);
			Route = new Route();
			Route.Container = this;
			
			SuspendEvents = false;
		}