Exemple #1
0
        /// <summary>
        /// 图运行时节点信息
        /// </summary>
        /// <returns></returns>
        private static byte[] ConvertToRuntimeInfo(List <NodeEditorView> nodeViewList,
                                                   List <GraphVariableInfo> graphVariableInfoList, int graphId)
        {
            FlatBufferBuilder fbb = new FlatBufferBuilder(1024);

            Offset <NodeInfo>[] nodeInfoOffsets    = new Offset <NodeInfo> [nodeViewList.Count];
            List <int>          commonNodeIdList   = new List <int>();
            List <int>          entranceNodeIdList = new List <int>();

            for (int i = 0; i < nodeViewList.Count; i++)
            {
                NodeEditorView    nodeView       = nodeViewList[i];
                Offset <NodeInfo> nodeInfoOffset = ConvertToRuntimeNodeInfo(fbb, nodeView);
                nodeInfoOffsets[i] = nodeInfoOffset;

                if (nodeView.CheckNodeIsCommonNode())
                {
                    commonNodeIdList.Add(nodeView.NodeId);
                }

                if (nodeView.ReflectionInfo.IsEntranceNode)
                {
                    entranceNodeIdList.Add(nodeView.NodeId);
                }
            }

            VectorOffset nodeVectorOffset = GraphInfo.CreateNodesVector(fbb, nodeInfoOffsets);

            //common node ids
            GraphInfo.StartCommonNodeIdsVector(fbb, commonNodeIdList.Count);
            for (int i = commonNodeIdList.Count - 1; i >= 0; i--)
            {
                fbb.AddInt(commonNodeIdList[i]);
            }

            VectorOffset commonNodeVectorOffset = fbb.EndVector();

            //entrance node ids
            GraphInfo.StartEntranceNodeIdsVector(fbb, entranceNodeIdList.Count);
            for (int i = entranceNodeIdList.Count - 1; i >= 0; i--)
            {
                fbb.AddInt(entranceNodeIdList[i]);
            }

            VectorOffset entranceNodeVectorOffset = fbb.EndVector();

            //graph variable infos
            int graphVariableCount = graphVariableInfoList.Count;

            Offset <FlatNode.Runtime.Flat.GraphVariableInfo>[] graphVariableInfoOffsets =
                new Offset <FlatNode.Runtime.Flat.GraphVariableInfo> [graphVariableCount];
            for (int i = 0; i < graphVariableCount; i++)
            {
                graphVariableInfoOffsets[i] = ConvertToRuntimeGraphVariableInfo(fbb, graphVariableInfoList[i]);
            }

            VectorOffset graphVariableInfoVectorOffset = GraphInfo.CreateGraphVariableInfosVector(fbb, graphVariableInfoOffsets);

            GraphInfo.StartGraphInfo(fbb);
            GraphInfo.AddGraphId(fbb, graphId);
            GraphInfo.AddCommonNodeIds(fbb, commonNodeVectorOffset);
            GraphInfo.AddEntranceNodeIds(fbb, entranceNodeVectorOffset);
            GraphInfo.AddNodes(fbb, nodeVectorOffset);
            GraphInfo.AddGraphVariableInfos(fbb, graphVariableInfoVectorOffset);
            Offset <GraphInfo> offset = GraphInfo.EndGraphInfo(fbb);

            fbb.Finish(offset.Value);
            return(fbb.SizedByteArray());
        }