private void RecordNodesAndSlots(IStorage storage, List <IVisualNode> nodeList, UserAction userAction)
        {
            DataHeader header = new DataHeader();
            long       initialPostionForData, currentPositionForData = 0;
            long       initialPosition = storage.GetPosition();

            //Retrieve all the slots Id in nodeList
            List <uint> allSlotsId = new List <uint>();

            foreach (IVisualNode node in nodeList)
            {
                if (node.GetInputSlots() != null)
                {
                    allSlotsId.AddRange(node.GetInputSlots());
                }
                if (node.GetOutputSlots() != null)
                {
                    allSlotsId.AddRange(node.GetOutputSlots());
                }
            }

            //Record the number of slots and the slot itself
            storage.WriteInteger(FieldCode.SlotCount, allSlotsId.Count());
            foreach (uint slotId in allSlotsId)
            {
                storage.Seek(header.HeaderSize, SeekOrigin.Current);
                initialPostionForData = storage.GetPosition();
                ISlot slot = this.graphController.GetSlot(slotId);
                slot.Serialize(storage);
                currentPositionForData = storage.GetPosition();
                header.DataSize        = currentPositionForData - initialPostionForData;
                storage.Seek(-(header.HeaderSize + header.DataSize), SeekOrigin.Current);
                header.Serialize(storage);
                storage.Seek(header.DataSize, SeekOrigin.Current);
            }

            //Record the number of nodes and the node itself
            storage.WriteInteger(FieldCode.NodeCount, nodeList.Count);
            foreach (IVisualNode node in nodeList)
            {
                storage.Seek(header.HeaderSize, SeekOrigin.Current);
                initialPostionForData = storage.GetPosition();
                node.Serialize(storage);
                currentPositionForData = storage.GetPosition();
                header.DataSize        = currentPositionForData - initialPostionForData;
                storage.Seek(-(header.HeaderSize + header.DataSize), SeekOrigin.Current);
                header.Serialize(storage);
                storage.Seek(header.DataSize, SeekOrigin.Current);
            }

            this.RecordFlag(storage, initialPosition, userAction);
        }
Example #2
0
        public void TestSerializeNullException()
        {
            IGraphController graphController = new GraphController(null);
            IStorage storage = null;
            DataHeader header = new DataHeader();

            Assert.Throws<ArgumentNullException>(() =>
            {
                header.Serialize(storage);
            });
        }
Example #3
0
        public void TestSerializeDeserialize()
        {
            IGraphController graphController = new GraphController(null);
            IStorage storage = new BinaryStorage();
            DataHeader header1 = new DataHeader();
            header1.DataSize = 21;
            DataHeader header2 = new DataHeader();
            header2.DataSize = 12;

            header1.Serialize(storage);
            storage.Seek(0, SeekOrigin.Begin);
            header2.Deserialize(storage);

            Assert.AreEqual(21, header2.DataSize);
        }
Example #4
0
        private void RecordNodeIds(IStorage storage, List<IVisualNode> nodeList, UserAction userAction)
        {
            DataHeader header = new DataHeader();
            header.DataSize = Configurations.UndoReDoDataHeaderSize;
            long initialPosition = storage.GetPosition();

            //Record the number of nodes and the nodeIds
            storage.WriteInteger(FieldCode.NodeCount, nodeList.Count);
            foreach (IVisualNode node in nodeList)
            {
                header.Serialize(storage);
                storage.WriteUnsignedInteger(FieldCode.NodeId, node.NodeId);
            }

            this.RecordFlag(storage, initialPosition, userAction);
        }
Example #5
0
        private void RecordEdgeIds(IStorage storage, List<IVisualEdge> edgeList, UserAction userAction)
        {
            DataHeader header = new DataHeader();
            header.DataSize = 12;
            long initialPosition = storage.GetPosition();

            //Record the number of edges and the edgeIds
            storage.WriteInteger(FieldCode.EdgeCount, edgeList.Count);
            foreach (IVisualEdge edge in edgeList)
            {
                header.Serialize(storage);
                storage.WriteUnsignedInteger(FieldCode.EdgeId, edge.EdgeId);
            }

            this.RecordFlag(storage, initialPosition, userAction);
        }
Example #6
0
        private void RecordRuntimeStates(IStorage storage, RuntimeStates runtimeStates, UserAction userAction)
        {
            DataHeader header = new DataHeader();
            long initialPosition = storage.GetPosition();

            //Record states
            storage.Seek(header.HeaderSize, SeekOrigin.Current);
            long initialPositionForData = storage.GetPosition();
            runtimeStates.Serialize(storage);
            long currentPositionforData = storage.GetPosition();
            header.DataSize = currentPositionforData - initialPositionForData;
            storage.Seek(-(header.HeaderSize + header.DataSize), SeekOrigin.Current);
            header.Serialize(storage);
            storage.Seek(header.DataSize, SeekOrigin.Current);

            this.RecordFlag(storage, initialPosition, userAction);
        }
Example #7
0
        private void RecordEdges(IStorage storage, List<IVisualEdge> edgeList, UserAction userAction)
        {
            DataHeader header = new DataHeader();
            long initialPostionForData, currentPositionForData = 0;
            long initialPosition = storage.GetPosition();

            //Record the number of edges and the edge itself
            storage.WriteInteger(FieldCode.EdgeCount, edgeList.Count);
            foreach (IVisualEdge edge in edgeList)
            {
                storage.Seek(header.HeaderSize, SeekOrigin.Current);
                initialPostionForData = storage.GetPosition();
                edge.Serialize(storage);
                currentPositionForData = storage.GetPosition();
                header.DataSize = currentPositionForData - initialPostionForData;
                storage.Seek(-(header.HeaderSize + header.DataSize), SeekOrigin.Current);
                header.Serialize(storage);
                storage.Seek(header.DataSize, SeekOrigin.Current);
            }

            this.RecordFlag(storage, initialPosition, userAction);
        }
Example #8
0
        private void RecordRuntimeStates(IStorage storage, RuntimeStates runtimeStates, UserAction userAction)
        {
            DataHeader header = new DataHeader();
            long initialPosition = storage.GetPosition();

            //Record states
            storage.Seek(header.HeaderSize, SeekOrigin.Current);
            long initialPositionForData = storage.GetPosition();
            runtimeStates.Serialize(storage);
            long currentPositionforData = storage.GetPosition();
            header.DataSize = currentPositionforData - initialPositionForData;
            storage.Seek(-(header.HeaderSize + header.DataSize), SeekOrigin.Current);
            header.Serialize(storage);
            storage.Seek(header.DataSize, SeekOrigin.Current);

            this.RecordFlag(storage, initialPosition, userAction);
        }
Example #9
0
        private void RecordNodesAndSlots(IStorage storage, List<IVisualNode> nodeList, UserAction userAction)
        {
            DataHeader header = new DataHeader();
            long initialPostionForData, currentPositionForData = 0;
            long initialPosition = storage.GetPosition();

            //Retrieve all the slots Id in nodeList
            List<uint> allSlotsId = new List<uint>();
            foreach (IVisualNode node in nodeList)
            {
                if (node.GetInputSlots() != null)
                    allSlotsId.AddRange(node.GetInputSlots());
                if (node.GetOutputSlots() != null)
                    allSlotsId.AddRange(node.GetOutputSlots());
            }

            //Record the number of slots and the slot itself
            storage.WriteInteger(FieldCode.SlotCount, allSlotsId.Count());
            foreach (uint slotId in allSlotsId)
            {
                storage.Seek(header.HeaderSize, SeekOrigin.Current);
                initialPostionForData = storage.GetPosition();
                ISlot slot = this.graphController.GetSlot(slotId);
                slot.Serialize(storage);
                currentPositionForData = storage.GetPosition();
                header.DataSize = currentPositionForData - initialPostionForData;
                storage.Seek(-(header.HeaderSize + header.DataSize), SeekOrigin.Current);
                header.Serialize(storage);
                storage.Seek(header.DataSize, SeekOrigin.Current);
            }

            //Record the number of nodes and the node itself
            storage.WriteInteger(FieldCode.NodeCount, nodeList.Count);
            foreach (IVisualNode node in nodeList)
            {
                storage.Seek(header.HeaderSize, SeekOrigin.Current);
                initialPostionForData = storage.GetPosition();
                node.Serialize(storage);
                currentPositionForData = storage.GetPosition();
                header.DataSize = currentPositionForData - initialPostionForData;
                storage.Seek(-(header.HeaderSize + header.DataSize), SeekOrigin.Current);
                header.Serialize(storage);
                storage.Seek(header.DataSize, SeekOrigin.Current);
            }

            this.RecordFlag(storage, initialPosition, userAction);
        }
Example #10
0
        private void RecordNodeIds(IStorage storage, List<IVisualNode> nodeList, UserAction userAction)
        {
            DataHeader header = new DataHeader();
            header.DataSize = Configurations.UndoReDoDataHeaderSize;
            long initialPosition = storage.GetPosition();

            //Record the number of nodes and the nodeIds
            storage.WriteInteger(FieldCode.NodeCount, nodeList.Count);
            foreach (IVisualNode node in nodeList)
            {
                header.Serialize(storage);
                storage.WriteUnsignedInteger(FieldCode.NodeId, node.NodeId);
            }

            this.RecordFlag(storage, initialPosition, userAction);
        }
Example #11
0
        private void RecordEdges(IStorage storage, List<IVisualEdge> edgeList, UserAction userAction)
        {
            DataHeader header = new DataHeader();
            long initialPostionForData, currentPositionForData = 0;
            long initialPosition = storage.GetPosition();

            //Record the number of edges and the edge itself
            storage.WriteInteger(FieldCode.EdgeCount, edgeList.Count);
            foreach (IVisualEdge edge in edgeList)
            {
                storage.Seek(header.HeaderSize, SeekOrigin.Current);
                initialPostionForData = storage.GetPosition();
                edge.Serialize(storage);
                currentPositionForData = storage.GetPosition();
                header.DataSize = currentPositionForData - initialPostionForData;
                storage.Seek(-(header.HeaderSize + header.DataSize), SeekOrigin.Current);
                header.Serialize(storage);
                storage.Seek(header.DataSize, SeekOrigin.Current);
            }

            this.RecordFlag(storage, initialPosition, userAction);
        }
Example #12
0
        private void RecordEdgeIds(IStorage storage, List<IVisualEdge> edgeList, UserAction userAction)
        {
            DataHeader header = new DataHeader();
            header.DataSize = 12;
            long initialPosition = storage.GetPosition();

            //Record the number of edges and the edgeIds
            storage.WriteInteger(FieldCode.EdgeCount, edgeList.Count);
            foreach (IVisualEdge edge in edgeList)
            {
                header.Serialize(storage);
                storage.WriteUnsignedInteger(FieldCode.EdgeId, edge.EdgeId);
            }

            this.RecordFlag(storage, initialPosition, userAction);
        }
        private void SaveFileInternal(string filePath)
        {
            IStorage storage = new FileStorage();
            DataHeader header = new DataHeader();
            long initialPosition, currentPosition = 0;

            //Serialize states
            storage.Seek(header.HeaderSize, SeekOrigin.Current);
            initialPosition = storage.GetPosition();
            this.graphProperties.Serialize(storage);
            currentPosition = storage.GetPosition();
            header.DataSize = currentPosition - initialPosition;
            storage.Seek(-(header.HeaderSize + header.DataSize), SeekOrigin.Current);
            header.Serialize(storage);
            storage.Seek(header.DataSize, SeekOrigin.Current);

            //Serialize slots
            List<ISlot> slotList = new List<ISlot>(this.slotCollection.Values);
            storage.WriteInteger(FieldCode.SlotCount, slotList.Count);
            foreach (ISlot slot in slotList)
            {
                storage.Seek(header.HeaderSize, SeekOrigin.Current);
                initialPosition = storage.GetPosition();
                slot.Serialize(storage);
                currentPosition = storage.GetPosition();
                header.DataSize = currentPosition - initialPosition;
                storage.Seek(-(header.HeaderSize + header.DataSize), SeekOrigin.Current);
                header.Serialize(storage);
                storage.Seek(header.DataSize, SeekOrigin.Current);
            }

            //Serialize nodes
            List<IVisualNode> nodeList = new List<IVisualNode>(this.nodeCollection.Values);
            storage.WriteInteger(FieldCode.NodeCount, nodeList.Count);
            foreach (IVisualNode node in nodeList)
            {
                storage.Seek(header.HeaderSize, SeekOrigin.Current);
                initialPosition = storage.GetPosition();
                node.Serialize(storage);
                currentPosition = storage.GetPosition();
                header.DataSize = currentPosition - initialPosition;
                storage.Seek(-(header.HeaderSize + header.DataSize), SeekOrigin.Current);
                header.Serialize(storage);
                storage.Seek(header.DataSize, SeekOrigin.Current);
            }

            //Serialize edges
            List<IVisualEdge> edgeList = this.edgeController.GetVisualEdges();
            storage.WriteInteger(FieldCode.EdgeCount, edgeList.Count);
            foreach (IVisualEdge edge in edgeList)
            {
                storage.Seek(header.HeaderSize, SeekOrigin.Current);
                initialPosition = storage.GetPosition();
                edge.Serialize(storage);
                currentPosition = storage.GetPosition();
                header.DataSize = currentPosition - initialPosition;
                storage.Seek(-(header.HeaderSize + header.DataSize), SeekOrigin.Current);
                header.Serialize(storage);
                storage.Seek(header.DataSize, SeekOrigin.Current);
            }

            ((FileStorage)storage).Save(filePath);
        }