コード例 #1
0
ファイル: DataType.cs プロジェクト: zhaoweigg/GraphEngine
        public static StructType ConvertFromCellDescriptor(ICellDescriptor cd)
        {
            if (cd == null)
            {
                return(null);
            }

            var fields = new List <StructField>();

            fields.Add(new StructField
            {
                Name = "CellID",
                Type = new DataType {
                    TypeName = typeof(long).FullName
                },
                Nullable = false
            });

            fields.AddRange(cd.GetFieldDescriptors().Select(fd => StructField.ConvertFromFieldDescriptor(fd)));

            return(new StructType
            {
                TypeName = typeof(StructType).Name,
                Fields = fields
            });
        }
コード例 #2
0
        public ICell ImportEntity(string type, string line, long?parent_id)
        {
            ICell           cell      = Global.LocalStorage.NewGenericCell(type);
            JObject         jobj      = JObject.Parse(line);
            ICellDescriptor cell_desc = Importer.s_cellTypes[type];
            long?           cellid    = null;

            List <Action> tree_imports = new List <Action>();

            foreach (var fd in cell_desc.GetFieldDescriptors())
            {
                string field_name    = fd.Name;
                JToken field_content = null;
                bool   field_exist   = jobj.TryGetValue(field_name, out field_content);
                string treeimport    = fd.GetAttributeValue(Consts.c_KW_TreeImport);
                bool   optional      = fd.Optional;
                bool   is_parent     = fd.GetAttributeValue(Consts.c_KW_TreeParent) != null;
                bool   is_rev_import = fd.GetAttributeValue(Consts.c_KW_ReverseEdgeImport) != null;

                if (!field_exist && !is_parent)
                {
                    if (optional || is_rev_import)
                    {
                        continue;
                    }
                    else
                    {
                        throw new ImporterException("Non-optional field {0}.{1} not found on entity: {2}", type, field_name, line);
                    }
                }

                if (fd.GetAttributeValue(Consts.c_KW_HashImport) != null)
                {
                    ProcessCellIdOrCellIdListField(type, cell, fd, field_name, optional, field_content, Hash);
                }
                else if (fd.GetAttributeValue(Consts.c_KW_CellIdKey) != null)
                {
                    cell.SetField(field_name, field_content.ToString());
                    cellid = Hash(field_content, fd);
                }
                else if (treeimport != null)
                {
                    // process this later so we're confident about cell id
                    tree_imports.Add(() =>
                    {
                        ProcessCellIdOrCellIdListField(type, cell, fd, field_name, optional, field_content, (c, _) =>
                        {
                            var sub_cell = ImportEntity(treeimport, c.ToString(), cellid);
                            return(sub_cell.CellId);
                        });
                    });
                }
                else if (is_parent)
                {
                    cell.SetField(field_name, parent_id.Value);
                }
                else
                {
                    cell.SetField(field_name, field_content.ToString());
                }
            }

            tree_imports.ForEach(_ => _());

            if (cellid == null)
            {
                cellid = CellIdFactory.NewCellId();
            }
            cell.CellId = cellid.Value;
            if (parent_id != null)
            {
                var parent_fd = cell_desc.GetFieldDescriptors().Where(fd => fd.GetAttributeValue(Consts.c_KW_TreeParent) != null).First();
            }
            // TODO check for duplicate records.
            // TODO in a distributed setting we cannot save to local storage like this.
            Global.LocalStorage.SaveGenericCell(cell);

            return(cell);
        }
コード例 #3
0
        private static Dictionary <string, IFieldDescriptor> GetFieldDescriptors(string type)
        {
            ICellDescriptor cellDesc = Importer.s_cellTypes[type];

            return(cellDesc.GetFieldDescriptors().ToDictionary(_ => _.Name));
        }