Exemplo n.º 1
0
        public bool Import(string DGPath, out string msg, bool needShapeData = true, bool needControlData = false)
        {
            if (!SignXmlHelper.VerifyXml(DGPath))
            {
                msg = "文件已被更改!";
                return(false);
            }

            msg = "";
            XmlSerializer xs = new XmlSerializer(typeof(SaveDataInfo));

            using (Stream stream = new FileStream(DGPath, FileMode.Open, FileAccess.Read, FileShare.Read))
            {
                SaveDataInfo dataInfo = (xs.Deserialize(stream) as SaveDataInfo);
                if (needShapeData)
                {
                    this.CopyShapes(dataInfo);
                }

                if (needControlData)
                {
                    this.CopyControlParams(dataInfo);
                }
            }
            return(true);
        }
Exemplo n.º 2
0
        public void CopyShapes(SaveDataInfo dataInfo)
        {
            dataInfo.Shapes.ForEach(shape =>
            {
                Assembly[] assemblies    = AppDomain.CurrentDomain.GetAssemblies();
                Assembly selectAssemblie = assemblies.FirstOrDefault((Func <Assembly, bool>)(assemblie => assemblie.FullName == shape.AssemblyInfo));
                Type shapeType           = selectAssemblie.GetType(shape.Type);
                Object[] constructParms  = new object[] { }; //构造器参数
                ShapeBase createShape    = (ShapeBase)Activator.CreateInstance(shapeType, constructParms);
                this.AddShape(createShape);
                createShape.ObjectID                    = shape.ObjectID;
                createShape.X                           = shape.X;
                createShape.Y                           = shape.Y;
                createShape.Text                        = shape.Text;
                createShape.BackGroundColor             = shape.BackGroundColor;
                createShape.BoderColor                  = shape.BoderColor;
                createShape.BoderSelectedColor          = shape.BoderSelectedColor;
                createShape.EnableBottomSourceConnector = shape.EnableBottomSourceConnector;
                createShape.EnableLeftSourceConnector   = shape.EnableLeftSourceConnector;
                createShape.EnableRightSourceConnector  = shape.EnableRightSourceConnector;
                createShape.EnableTopSourceConnector    = shape.EnableTopSourceConnector;
                createShape.EnableBottomTargetConnector = shape.EnableBottomTargetConnector;
                createShape.EnableLeftTargetConnector   = shape.EnableLeftTargetConnector;
                createShape.EnableRightTargetConnector  = shape.EnableRightTargetConnector;
                createShape.EnableTopTargetConnector    = shape.EnableTopTargetConnector;
                createShape.ShowBorder                  = shape.ShowBorder;
            });

            dataInfo.Connections.ForEach(connection =>
            {
                ShapeBase shapeFrom = null;
                ShapeBase shapeTo   = null;
                foreach (ShapeBase shape in shapes)
                {
                    if (connection.FromContainEntityObjectID == shape.ObjectID)
                    {
                        shapeFrom = shape;
                    }

                    if (connection.ToContainEntityObjectID == shape.ObjectID)
                    {
                        shapeTo = shape;
                    }

                    if (shapeFrom != null && shapeTo != null)
                    {
                        break;
                    }
                }

                if (shapeFrom == null || shapeTo == null)
                {
                    return;
                }

                this.AddConnection(shapeFrom.Connectors[connection.FromContainEntityIndex], shapeTo.Connectors[connection.ToContainEntityIndex]);
            });
        }
Exemplo n.º 3
0
 public void CopyControlParams(SaveDataInfo dataInfo)
 {
     this.ViewOriginPoint   = dataInfo.ViewOriginPoint;
     this.LineHoveredColor  = dataInfo.LineHoveredColor;
     this.LineSelectedColor = dataInfo.LineSelectedColor;
     this.LineColor         = dataInfo.LineColor;
     this.BackColor         = dataInfo.BackColor;
     this.ShowGrid          = dataInfo.ShowGrid;
 }
Exemplo n.º 4
0
        public void Save(string savePath)
        {
            SaveDataInfo  data = this;
            XmlSerializer xs   = new XmlSerializer(data.GetType());

            using (Stream stream = new FileStream(savePath, FileMode.Create, FileAccess.Write, FileShare.Read))
            {
                xs.Serialize(stream, data);
            }
            SignXmlHelper.SignXml(savePath);
        }