Ejemplo n.º 1
0
        public DataBaseType(ICremaHost cremaHost)
        {
            this.cremaHost = cremaHost;

            Field(_ => _.Id, type: typeof(IdGraphType)).Name("ID");
            Field(_ => _.Name);
            Field(_ => _.Comment);
            Field(_ => _.CreatedDateTime, type: typeof(DateTimeGraphType));
            Field(_ => _.Creator);
            Field(_ => _.ModifiedDateTime, type: typeof(DateTimeGraphType));
            Field(_ => _.Modifier);
            Field(_ => _.Paths);
            Field(_ => _.Revision);
            Field(_ => _.TablesHashValue, nullable: true);
            Field(_ => _.TypesHashValue, nullable: true);
            Field(_ => _.Tags);

            Field <BooleanGraphType>()
            .Name("IsLoaded")
            .Resolve(context =>
            {
                return(this.cremaHost.Dispatcher.Invoke(() => this.cremaHost.DataBases[context.Source.Name].IsLoaded));
            });

            Field <BooleanGraphType>()
            .Name("IsEntered")
            .Resolve(context =>
            {
                return(this.cremaHost.Dispatcher.Invoke(() =>
                {
                    var authentication = context.UserContext as Authentication;
                    var database = this.cremaHost.DataBases[context.Source.Name];
                    return database.Contains(authentication);
                }));
            });

            Field <TableType>()
            .Name("Table")
            .Argument <StringGraphType>("name", "")
            .Resolve(context =>
            {
                var tableName = context.GetArgument <string>("name");
                var table     = this.GetTable(context.Source.Name, tableName);

                return(table.Dispatcher.Invoke(() =>
                {
                    var tableInfo = table.TableInfo;
                    return TableModel.ConvertFrom(context.Source.DataBase, table, tableInfo);
                }));
            });

            Field <ListGraphType <TableType> >()
            .Name("Tables")
            .Argument <StringGraphType, string>("name", "", "*")
            .Argument <StringGraphType>("tags", "")
            .Resolve(context =>
            {
                var tableName = context.GetArgument <string>("name");
                var tags      = context.GetArgument <string>("tags");
                var tables    = this.GetTables(context.Source.Name, tableName, tags);

                return(tables?.Select(table =>
                {
                    return table.Dispatcher.Invoke(() =>
                    {
                        var tableInfo = table.TableInfo;
                        return TableModel.ConvertFrom(context.Source.DataBase, table, tableInfo);
                    });
                }).ToArray());
            });

            Field <TypeType>()
            .Name("Type")
            .Argument <StringGraphType>("name", "")
            .Resolve(context =>
            {
                var typeName = context.GetArgument <string>("name");
                var type     = this.GetType(context.Source.Name, typeName);

                return(type?.Dispatcher.Invoke(() =>
                {
                    var typeInfo = type.TypeInfo;
                    return TypeModel.ConvertFrom(context.Source.DataBase, type, typeInfo);
                }));
            });

            Field <ListGraphType <TypeType> >()
            .Name("Types")
            .Argument <StringGraphType, string>("name", "", "*")
            .Resolve(context =>
            {
                var typeName = context.GetArgument <string>("name");
                var types    = this.GetTypes(context.Source.Name, typeName);

                return(types?.Select(type =>
                {
                    return type.Dispatcher.Invoke(() =>
                    {
                        var typeInfo = type.TypeInfo;
                        return TypeModel.ConvertFrom(context.Source.DataBase, type, typeInfo);
                    });
                }).ToArray());
            });

            Field <ListGraphType <LogInfoType> >()
            .Name("Logs")
            .Resolve(context =>
            {
                var authentication = context.UserContext as Authentication;
                var database       = context.Source.DataBase;
                var logs           = database.Dispatcher.Invoke(() => database.GetLog(authentication));

                return(LogInfoModel.ConvertFrom(logs));
            });
        }