Example #1
0
        public void Resolve(DcSpace space)
        {
            if (!string.IsNullOrEmpty(SchemaName))
            {
                // 1. Resolve schema name
                TypeSchema = space.GetSchema(SchemaName);
                if (TypeSchema == null)
                {
                    return;                     // Cannot resolve
                }
                // 2. Resolve table name
                TypeTable = TypeSchema.GetSubTable(TypeName);
                if (TypeTable == null)
                {
                    return;                    // Cannot resolve
                }
            }
            else if (!string.IsNullOrEmpty(TypeName)) // No schema name (imcomplete info)
            {
                // 1. try to find the table in the mashup
                DcSchema mashup = space.GetSchemas().FirstOrDefault(x => x.GetSchemaKind() == DcSchemaKind.Dc);
                if (mashup != null)
                {
                    TypeTable = mashup.GetSubTable(TypeName);
                    if (TypeTable != null)
                    {
                        TypeSchema = mashup;
                        SchemaName = TypeSchema.Name; // We also reconstruct the name
                        return;
                    }
                }

                // 2. try to find the table in any other schema
                foreach (DcSchema schema in space.GetSchemas())
                {
                    TypeTable = schema.GetSubTable(TypeName);
                    if (TypeTable != null)
                    {
                        TypeSchema = schema;
                        SchemaName = TypeSchema.Name; // We also reconstruct the name
                        return;
                    }
                }
            }
        }
Example #2
0
        public static object ResolveJsonRef(JObject json, DcSpace ws) // Resolve a json reference to a real object
        {
            if (json == null)
            {
                return(null);
            }

            string element_type = (string)json["element_type"];

            if (element_type == null)
            {
                if (json["schema_name"] == null)
                {
                    return(null);
                }
                else if (json["table_name"] == null)
                {
                    element_type = "schema";
                }
                else if (json["column_name"] == null)
                {
                    element_type = "table";
                }
                else
                {
                    element_type = "column";
                }
            }

            if (element_type == "schema") // Find schema
            {
                return(ws.GetSchema((string)json["schema_name"]));
            }
            else if (element_type == "table") // Find table
            {
                DcSchema schema = ws.GetSchema((string)json["schema_name"]);
                if (schema == null)
                {
                    return(null);
                }
                return(schema.GetSubTable((string)json["table_name"]));
            }
            else if (element_type == "column") // Find column
            {
                DcSchema schema = ws.GetSchema((string)json["schema_name"]);
                if (schema == null)
                {
                    return(null);
                }
                DcTable table = schema.GetSubTable((string)json["table_name"]);
                if (table == null)
                {
                    return(null);
                }
                return(table.GetColumn((string)json["column_name"]));
            }
            else
            {
                throw new NotImplementedException("Unknown element type in the reference.");
            }
        }