Пример #1
0
        public static async Task<SchemaBuilder> FromTableInfosAsync(BigQueryContext context, DriverProperty property)
        {
            string[] datasets;
            if (property.ContextIsOnlyDataSet)
            {
                datasets = new[] { property.ContextDataSet };
            }
            else
            {
                datasets = await context.GetAllDatasetsAsync();
            }

            var list = new List<Schema>();
            foreach (var dataset in datasets)
            {
                var tables = await context.GetFastTableSchemasAsync(dataset);

                var schema = new Schema()
                {
                    DatasetName = dataset,
                    GroupedMetaTableSchemas = tables,
                };

                list.Add(schema);
            }

            return new SchemaBuilder(context, property, list.ToArray());
        }
        public override object[] GetContextConstructorArguments(IConnectionInfo cxInfo)
        {
            var property = new DriverProperty(cxInfo);

            return(new object[]
            {
                property.ContextJsonAuthenticationKey,
                property.ContextUser,
                property.ContextProjectId
            });
        }
Пример #3
0
        public ConnectionDialog(IConnectionInfo connectionInfo)
        {
            InitializeComponent();
            this.connectionInfo = connectionInfo;
            this.property = new DriverProperty(connectionInfo);

            JsonTextBox.Text = property.ContextJsonAuthenticationKey;
            UserTextBox.Text = property.ContextUser;
            ProjectIdBox.Text = property.ContextProjectId;
            UseDataSetCheckBox.IsChecked = property.ContextIsOnlyDataSet;
            DataSetBox.Text = property.ContextDataSet;
        }
        // 3. explore item and generate assembly
        public override List <ExplorerItem> GetSchemaAndBuildAssembly(IConnectionInfo cxInfo, AssemblyName assemblyToBuild, ref string nameSpace, ref string typeName)
        {
            var property = new DriverProperty(cxInfo);

            var context = ContextHelper.GetContext(property.ContextJsonAuthenticationKey, property.ContextUser, property.ContextProjectId);

            SchemaBuilder schemaBuilder = null;

            var useCache = false; // for debugging shortcut

            if (useCache)
            {
                var schemaCache = property.GetTempCache();
                if (schemaCache != null)
                {
                    try
                    {
                        var deserialized = JsonConvert.DeserializeObject <Schema[]>(schemaCache);
                        schemaBuilder = new SchemaBuilder(context, property, deserialized);
                    }
                    catch
                    {
                    }
                }
            }

            if (schemaBuilder == null)
            {
                schemaBuilder = SchemaBuilder.FromTableInfosAsync(context, property).GetAwaiter().GetResult();
                var cacheString = JsonConvert.SerializeObject(schemaBuilder.Schemas, Formatting.None);
                property.SetTempCache(cacheString);
            }

            BuildCodeResult[] generatedCodes;
            var namespacesToAdd = schemaBuilder.CompileTo(assemblyToBuild, nameSpace, out generatedCodes);
            var list            = schemaBuilder.BuildExplorerItems(generatedCodes);

            property.NamespacesToAdd = namespacesToAdd;
            typeName = "CustomBigQueryContext";

            return(list);
        }
        // 3. explore item and generate assembly
        public override List<ExplorerItem> GetSchemaAndBuildAssembly(IConnectionInfo cxInfo, AssemblyName assemblyToBuild, ref string nameSpace, ref string typeName)
        {
            var property = new DriverProperty(cxInfo);

            var context = ContextHelper.GetContext(property.ContextJsonAuthenticationKey, property.ContextUser, property.ContextProjectId);

            SchemaBuilder schemaBuilder = null;

            var useCache = false; // for debugging shortcut
            if (useCache)
            {
                var schemaCache = property.GetTempCache();
                if (schemaCache != null)
                {
                    try
                    {
                        var deserialized = JsonConvert.DeserializeObject<Schema[]>(schemaCache);
                        schemaBuilder = new SchemaBuilder(context, property, deserialized);
                    }
                    catch
                    {

                    }
                }
            }

            if (schemaBuilder == null)
            {
                schemaBuilder = SchemaBuilder.FromTableInfosAsync(context, property).GetAwaiter().GetResult();
                var cacheString = JsonConvert.SerializeObject(schemaBuilder.Schemas, Formatting.None);
                property.SetTempCache(cacheString);
            }

            BuildCodeResult[] generatedCodes;
            var namespacesToAdd = schemaBuilder.CompileTo(assemblyToBuild, nameSpace, out generatedCodes);
            var list = schemaBuilder.BuildExplorerItems(generatedCodes);

            property.NamespacesToAdd = namespacesToAdd;
            typeName = "CustomBigQueryContext";

            return list;
        }
        public override IEnumerable <string> GetNamespacesToAdd(IConnectionInfo cxInfo)
        {
            var     asm = typeof(DynamicDataContextDriver).Assembly; // LINQPad.exe
            Version version;

            if (!Version.TryParse(asm.GetCustomAttribute <AssemblyFileVersionAttribute>()?.Version ?? "", out version))
            {
                version = new Version(1, 0, 0, 0);
            }

            var prop = new DriverProperty(cxInfo);

            return(base.GetNamespacesToAdd(cxInfo)
                   .Concat(prop.NamespacesToAdd)
                   .Concat(new[]
            {
                "System.Linq",
                "BigQuery.Linq",
                "System.Windows.Forms.DataVisualization.Charting"
            })
                   .Concat(new Version(5, 0, 0, 0) <= version ? new[] { "static BigQuery.Linq.BqFunc" } : new string[0])
                   .Distinct());
        }
Пример #7
0
 public SchemaBuilder(BigQueryContext context, DriverProperty property, Schema[] schemas)
 {
     this.context = context;
     this.Schemas = schemas;
     this.property = property;
 }
Пример #8
0
        public static async Task <SchemaBuilder> FromTableInfosAsync(BigQueryContext context, DriverProperty property)
        {
            string[] datasets;
            if (property.ContextIsOnlyDataSet)
            {
                datasets = new[] { property.ContextDataSet };
            }
            else
            {
                datasets = await context.GetAllDatasetsAsync();
            }

            var list = new List <Schema>();

            foreach (var dataset in datasets)
            {
                var tables = await context.GetFastTableSchemasAsync(dataset);

                var schema = new Schema()
                {
                    DatasetName             = dataset,
                    GroupedMetaTableSchemas = tables,
                };

                list.Add(schema);
            }

            return(new SchemaBuilder(context, property, list.ToArray()));
        }
Пример #9
0
 public SchemaBuilder(BigQueryContext context, DriverProperty property, Schema[] schemas)
 {
     this.context  = context;
     this.Schemas  = schemas;
     this.property = property;
 }
        public override IEnumerable<string> GetNamespacesToAdd(IConnectionInfo cxInfo)
        {
            var asm = typeof(DynamicDataContextDriver).Assembly; // LINQPad.exe
            Version version;
            if (!Version.TryParse(asm.GetCustomAttribute<AssemblyFileVersionAttribute>()?.Version ?? "", out version))
            {
                version = new Version(1, 0, 0, 0);
            }

            var prop = new DriverProperty(cxInfo);

            return base.GetNamespacesToAdd(cxInfo)
                .Concat(prop.NamespacesToAdd)
                .Concat(new[]
                {
                    "System.Linq",
                    "BigQuery.Linq",
                    "System.Windows.Forms.DataVisualization.Charting"
                })
                .Concat(new Version(5, 0, 0, 0) <= version ? new[] { "static BigQuery.Linq.BqFunc" } : new string[0])
                .Distinct();
        }
        public override object[] GetContextConstructorArguments(IConnectionInfo cxInfo)
        {
            var property = new DriverProperty(cxInfo);

            return new object[]
            {
                property.ContextJsonAuthenticationKey,
                property.ContextUser,
                property.ContextProjectId
            };
        }