Exemple #1
0
        public void Load(string FileName)
        {
            BinaryFormatter bf = new BinaryFormatter();

            // 1. Construct a SurrogateSelector object
            SurrogateSelector ss = new SurrogateSelector();

            RectSerializatoinSurrogate v3ss = new RectSerializatoinSurrogate();

            ss.AddSurrogate(typeof(Rect),
                            new StreamingContext(StreamingContextStates.All),
                            v3ss);

            // 2. Have the formatter use our surrogate selector
            bf.SurrogateSelector = ss;

            string fileLocation = FileManager.LoadFile(FileName);

            Stream stream = new FileStream(fileLocation, FileMode.Open);

            List <AbstractNode> _preNodeList = new List <AbstractNode>();

            _preNodeList = (List <AbstractNode>)bf.Deserialize(stream);

            foreach (AbstractNode _node in _preNodeList)
            {
                _node.SetDb(this);
            }

            stream.Close();

            Init();
            LoadNodeTypes();

            // Add Node to lists and dictionaries
            foreach (AbstractNode newNode in _preNodeList)
            {
                AddNodeToLists(newNode);
            }

            // Add connections
            foreach (AbstractNode node in NodeList)
            {
                Dictionary <int, string> activeConnections = node.GetActiveConnections();

                foreach (int key in activeConnections.Keys)
                {
                    AddConnection(node.UniqueID, key, activeConnections[key]);
                }
            }

            PropertiesNode propertiesNode = (PropertiesNode)GetNodeByType(typeof(PropertiesNode));

            propertiesNode.SelectedDialogIndex = FileManager.LoadFiles().FindIndex(a => a == FileName);

            propertiesNode.HasLoadedDialog = true;
            propertiesNode.LoadedFile      = FileName;
        }
Exemple #2
0
        public void Save(string FileName)
        {
            BinaryFormatter bf = new BinaryFormatter();

            // 1. Construct a SurrogateSelector object
            SurrogateSelector ss = new SurrogateSelector();

            RectSerializatoinSurrogate v3ss = new RectSerializatoinSurrogate();

            ss.AddSurrogate(typeof(Rect),
                            new StreamingContext(StreamingContextStates.All),
                            v3ss);

            // 2. Have the formatter use our surrogate selector
            bf.SurrogateSelector = ss;

            string fileLocation = FileManager.LoadFile(FileName);

            Stream stream = new FileStream(fileLocation, FileMode.Create, FileAccess.Write, FileShare.None);

            bf.Serialize(stream, NodeList);
            stream.Close();
        }