private static bool TryContributeMetadataValue(this IDictionary <string, object> dictionary, string name, object value, Type valueType, bool allowsMultiple)
        {
            object metadataValue;

            if (!dictionary.TryGetValue(name, out metadataValue))
            {
                if (allowsMultiple)
                {
                    var list = new MetadataList();
                    list.Add(value, valueType);
                    value = list;
                }

                dictionary.Add(name, value);
            }
            else
            {
                var list = metadataValue as MetadataList;
                if (!allowsMultiple || list == null)
                {
                    // Either single value already found when should be multiple
                    // or a duplicate name already exists
                    dictionary.Remove(name);
                    return(false);
                }

                list.Add(value, valueType);
            }
            return(true);
        }
        public override void LoadDatabases(MetadataList databases, MetadataLoadingOptions loadingOptions)
        {
            if (!Connected)
            {
                Connect();
            }

            // load from OLEDB catalogs
            try
            {
                DataTable schemaTable = _connection.GetSchema("Tables");

                string databaseFieldName = "TABLE_CATALOG";
                if (schemaTable.Columns[databaseFieldName] == null)
                {
                    databaseFieldName = "TABLE_CAT";
                }

                using (MetadataNamespacesFetcherFromDatatable mdf =
                           new MetadataNamespacesFetcherFromDatatable(databases, MetadataType.Database, loadingOptions))
                {
                    mdf.Datatable     = schemaTable;
                    mdf.NameFieldName = databaseFieldName;

                    mdf.LoadMetadata();
                }
            }
            catch
            {
                // loading from OLEDB catalog failed
            }

            // load default database
            string currentDatabase = Connection.Database;

            if (!string.IsNullOrEmpty(currentDatabase))
            {
                MetadataNamespace database = databases.FindItem <MetadataNamespace>(currentDatabase, MetadataType.Database);
                if (database == null)
                {
                    database      = new MetadataNamespace(databases, MetadataType.Database);
                    database.Name = currentDatabase;
                    databases.Add(database);
                }
                database.Default = true;
            }
        }
示例#3
0
        public override void LoadDatabases(MetadataList databases, MetadataLoadingOptions loadingOptions)
        {
            if (databases.Parent.Server == null)
            {
                if (!Connected)
                {
                    Connect();
                }

                string currentDatabase = Connection.Database;
                if (!String.IsNullOrEmpty(currentDatabase))
                {
                    MetadataNamespace database = databases.FindItem <MetadataNamespace>(currentDatabase, MetadataType.Database);
                    if (database == null)
                    {
                        database      = new MetadataNamespace(databases, MetadataType.Database);
                        database.Name = currentDatabase;
                        databases.Add(database);
                    }

                    database.Default = true;
                }
            }
        }
示例#4
0
        void parseAttribute(TokenStream gStream)
        {
            AttributeReader reader = new AttributeReader(gStream);

            var attr = reader.Read();

            switch (attr.Name)
            {
            case "AllowBuiltins":
                compilerConfig.AllowBuiltins = true;
                break;

            case "AddMeta":
            case "Info":
            case "Define":
            {
                if ((attr.Data.Count > 2 || attr.Data.Count < 1 || !(attr.Data[0].Value is string)) && !attr.Data[0].IsOptional)
                {
                    InfoProvider.AddError("@AddMeta: Incorrect data", ExceptionType.AttributeException, gStream.SourcePosition);
                    //throw new AttributeException("AddMeta", "Incorrect data");
                }

                Metadata md = new Metadata();
                if (attr.Data[0].IsOptional)
                {
                    md.Key   = attr.Data[0].Key;
                    md.Value = attr.Data[0].Value;
                    md.Type  = attr.Data[0].Type;
                }
                else
                {
                    md.Key = attr.Data[0].Value as string;
                    if (attr.Data.Count == 2)
                    {
                        md.Value = attr.Data[1].Value;
                        md.Type  = attr.Data[1].Type;
                    }
                    else
                    {
                        md.Type = DataTypes.Void;
                    }
                }
                var mlist = from m in metadataList
                            where m.Key == md.Key
                            select m;
                if (mlist.ToList().Count != 0)
                {
                    InfoProvider.AddError("Meta key " + md.Key + " exists", ExceptionType.MetaKeyExists, gStream.SourcePosition);
                }
                //throw new CompilerException(ExceptionType.MetaKeyExists, "Meta key " + md.key + " in module " + CommandArgs.source + " exists", tokens);

                metadataList.Add(md);
            }
            break;

            case "Module":
                if (attr.Data.Count != 1 && !(attr.Data[0].Value is string))
                {
                    InfoProvider.AddError("@Module: Incorrect name", ExceptionType.AttributeException, gStream.SourcePosition);
                }
                //throw new AttributeException("Module", "Incorrect module name");
                if (compilerConfig.OutBinaryFile == null)
                {
                    compilerConfig.OutBinaryFile = (attr.Data[0].Value as string) + ".vas";     // TODO: FIXME
                }
                break;

            case "RuntimeInternal":
                if (attr.Data.Count != 0)
                {
                    InfoProvider.AddError("@RuntimeInternal: Too many arguments", ExceptionType.AttributeException, gStream.SourcePosition);
                }
                //throw new AttributeException("RuntimeInternal", "Too many arguments");
                if (!attr.Binded)
                {
                    InfoProvider.AddError("@RuntimeInternal must be binded to method (check `;`)", ExceptionType.AttributeException, gStream.SourcePosition);
                }
                //throw new AttributeException("RuntimeInternal", "`@RuntimeInternal` must be binded to function (check `;`)");
                bindedAttributeList.Add(attr);
                break;

            case "Entry":
                if (attr.Data.Count != 0)
                {
                    InfoProvider.AddError("@Entry: Too many arguments", ExceptionType.AttributeException, gStream.SourcePosition);
                }
                //throw new AttributeException("Entry", "Too many arguments");
                if (!attr.Binded)
                {
                    InfoProvider.AddError("@Entry must be binded to method (check `;`)", ExceptionType.AttributeException, gStream.SourcePosition);
                }
                //throw new AttributeException("Entry", "`@Entry` must be binded to function (check `;`)");
                bindedAttributeList.Add(attr);
                break;

            case "Debug:Set":
            {
                if (!compilerConfig.DebugBuild)
                {
                    goto default;         // YAAAY ;D
                }
                if ((attr.Data.Count > 2 || attr.Data.Count < 1 || !(attr.Data[0].Value is string)) && !attr.Data[0].IsOptional)
                {
                    InfoProvider.AddError("@Debug:Set: Incorrect data", ExceptionType.AttributeException, gStream.SourcePosition);
                    //throw new AttributeException("Debug:Set", "Incorrect data");
                }
                RuntimeMetadata md = new RuntimeMetadata();
                md.Prefix = attr.Name;
                if (attr.Data[0].IsOptional)
                {
                    md.Key   = attr.Data[0].Key;
                    md.Value = attr.Data[0].Value;
                    md.Type  = attr.Data[0].Type;
                }
                else
                {
                    md.Key = attr.Data[0].Value as string;
                    if (attr.Data.Count == 2)
                    {
                        md.Value = attr.Data[1].Value;
                        md.Type  = attr.Data[1].Type;
                    }
                    else
                    {
                        md.Type = DataTypes.Void;
                    }
                }
                var mlist = from m in metadataList
                            where m.Key == md.Key
                            select m;
                if (mlist.ToList().Count != 0)
                {
                    foreach (var m in mlist)
                    {
                        metadataList.Remove(m);
                    }
                }

                metadataList.Add(md);
            }
            break;

            default:
                InfoProvider.AddWarning("Unknown attribute `@" + attr.Name + "`", ExceptionType.AttributeException, gStream.SourcePosition);
                //Console.WriteLine("Warning: unknown attribute `" + attr.Name + "`");
                break;
            }
        }