Exemplo n.º 1
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);
        }