private static void DoUpdate(Table table, TypedDataSource source, SchemaNode tableSchema, RowLimitClause rowLimitClause) { table.Partitions[0].Name = tableSchema.Name; table.Partitions[0].Query = tableSchema.GetSql(true, source.UseThreePartName); table.Partitions[0].SetAnnotation("TabularEditor_TableSchema", tableSchema.ToJson()); var schemaTable = source.GetSchemaTable(tableSchema); var updatedColumns = new HashSet <TOMWrapper.DataColumn>(); foreach (DataRow row in schemaTable.Rows) { var sourceColumn = row["ColumnName"].ToString(); var dataTypeName = schemaTable.Columns.Contains("DataTypeName") ? row["DataTypeName"].ToString() : (row["DataType"] as Type).Name; var column = table.DataColumns.FirstOrDefault(c => c.SourceColumn.EqualsI(sourceColumn)); if (column == null) { column = table.AddDataColumn(sourceColumn, sourceColumn); } column.DataType = TableMetadata.DataTypeMap(dataTypeName); column.SourceProviderType = dataTypeName; updatedColumns.Add(column); } foreach (var col in table.DataColumns.Except(updatedColumns).ToList()) { col.Delete(); } }
protected override void DrawCustomCaptionInfo(RenderInfo info, int x, int y, int width) { if (InheritsTypeName != null) { info.Graphics.DrawImage(Resources.InheritanceArrow, x + Margins.TypeBoxSideMargin, y + 35); var typeInheritsBounds = new Rectangle(x + 24, y + 33, width - 26, 10); info.Graphics.DrawString(InheritsTypeName, Fonts.InheritsTypeName, Brushes.Black, typeInheritsBounds, StringFormat.GenericTypographic); } IList <string> implementedInterfaces = TypedDataSource.GetImplementedInterfaces(); if (implementedInterfaces.Count > 0) { int offsetX = 20; int offsetY = 20 + (16 * (implementedInterfaces.Count - 1)); info.Graphics.DrawEllipse(Pens.Lolipop, x + offsetX, y - offsetY, 12, 12); info.Graphics.DrawLine(Pens.Lolipop, x + offsetX + 6, y - offsetY + 12, x + offsetX + 6, y); int yy = y - offsetY; foreach (string interfaceName in implementedInterfaces) { info.Graphics.DrawString(interfaceName, Fonts.ImplementedInterfaces, Brushes.Black, x + offsetX + 16, yy); yy += 16; } } }
public bool Init(TypedDataSource source) { if (source.NeedsPassword) { if (PasswordPromptForm.Show(source.TabularDsName, source.Username, out string password) == DialogResult.OK) { source.SetPassword(password); } else { return(false); } } Source = source; SchemaModel = new SchemaModel(Source, InitialSelection); switch (source) { case OdbcDataSource odbc: case OracleDataSource oracle: case OleDbDataSource oledb: case OtherDataSource other: pnlODBC.Visible = true; break; case SqlDataSource sql: pnlODBC.Visible = false; break; } return(true); }
public static DialogResult ShowWizard(Model model, ProviderDataSource source) { var dialog = new ImportTablesWizard(); //dialog.page1.Init(model); dialog.btnBack.Visible = false; dialog.btnNext.Visible = false; dialog.btnCancel.Left = 654; dialog.page2.RowLimitClause = source.GetRowLimitClause(); dialog.page2.IdentifierQuoting = source.GetIdentifierQuoting(); var tds = TypedDataSource.GetFromTabularDs(source); if (!dialog.page2.Init(tds)) { return(DialogResult.Cancel); } dialog.CurrentPage = 2; var res = dialog.ShowDialog(); if (res == DialogResult.OK) { DoImport(dialog.page1.Mode, model, dialog.page2.Source, dialog.page2.SelectedSchemas, dialog.page2.RowLimitClause, dialog.page2.IdentifierQuoting); } return(res); }
/// <summary> /// Creates the data source. /// </summary> /// <returns></returns> protected sealed override TypedDataSource CreateDataSource() { var server = CreateMongoServer(); var dataContext = CreateDataContext(server); var dataSource = new TypedDataSource(server, dataContext); InitializeDataContext(dataSource); return(dataSource); }
private void InitializeDataContext(TypedDataSource dataSource) { var metadata = GetMetadata(); foreach (var resourceSet in metadata.ResourceSets) { var annotation = (TypedResourceSetAnnotation)resourceSet.CustomState; annotation.SetDataContext(dataSource); } }
private void btnNext_Click(object sender, EventArgs e) { if (CurrentPage == 1) { switch (page1.Mode) { case Pages.ImportMode.UseExistingDs: if (page1.CurrentDataSource != null) { if (!page2.Init(TypedDataSource.GetFromTabularDs(page1.CurrentDataSource))) { return; } CurrentPage = 2; return; } break; case Pages.ImportMode.UseNewDs: var connectionDialog = ShowConnectionDialog(); if (connectionDialog == null) { return; } var source = TypedDataSource.GetFromConnectionUi(connectionDialog); var tabularDs = Model.AddDataSource(source.SuggestSourceName()); ConnectionUIHelper.ApplyToTabularDs(connectionDialog, tabularDs); source = TypedDataSource.GetFromTabularDs(tabularDs); page2.Init(source); CurrentPage = 2; return; case Pages.ImportMode.UseTempDs: connectionDialog = ShowConnectionDialog(); if (connectionDialog == null) { return; } source = TypedDataSource.GetFromConnectionUi(connectionDialog); source.TabularDsName = "(Temporary connection)"; page2.Init(source); CurrentPage = 2; return; case Pages.ImportMode.UseClipboard: page3.Visible = true; page3.BringToFront(); CurrentPage = 3; break; } } }
public void New() { var dcd = new DataConnectionDialog(); DataSource.AddStandardDataSources(dcd); dcd.SelectedDataSource = DataSource.SqlDataSource; dcd.SelectedDataProvider = DataProvider.SqlDataProvider; var res = DataConnectionDialog.Show(dcd); if (res == DialogResult.OK) { var ds = TypedDataSource.GetFromConnectionUi(dcd); } }
public object Edit(object instance, string property, object value, out bool cancel) { if (!(instance is TOMWrapper.ProviderDataSource)) { throw new NotSupportedException("This data source is not supported by Tabular Editor."); } cancel = true; var tabularDs = instance as TOMWrapper.ProviderDataSource; if (tabularDs is null) { return(value); } var ds = TypedDataSource.GetFromTabularDs(tabularDs); var dcd = new DataConnectionDialog(); DataSource.AddStandardDataSources(dcd); if (!string.IsNullOrEmpty(value as string)) { if (ds.ProviderType != ProviderType.Unknown) { dcd.SelectedDataSource = ds.DataSource; dcd.SelectedDataProvider = ds.DataProvider; dcd.ConnectionString = ds.ProviderString; } else { var mbResult = MessageBox.Show("The provider and/or connection string used by this data source, is not supported by Tabular Editor.", "Unknown provider", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning); if (mbResult == DialogResult.Cancel) { return(value); } } } var res = DataConnectionDialog.Show(dcd); if (res == DialogResult.OK) { cancel = false; return(dcd.ApplyToTabularDs(tabularDs)); } return(value); }
private static void DoImport(Pages.ImportMode importMode, Model model, TypedDataSource source, IEnumerable <SchemaNode> schemaNodes, RowLimitClause rowLimitClause, IdentifierQuoting identifierQuoting) { foreach (var tableSchema in schemaNodes) { var newTable = model.AddTable(tableSchema.Name); if (newTable.Partitions[0] is MPartition) { Partition.CreateNew(newTable); newTable.Partitions[0].Delete(); } newTable.Partitions[0].Name = tableSchema.Name; newTable.Partitions[0].Query = tableSchema.GetSql(identifierQuoting, true, source.UseThreePartName); if (source?.TabularDsName != null && model.DataSources.Contains(source.TabularDsName)) { newTable.Partitions[0].DataSource = model.DataSources[source.TabularDsName]; } if (importMode != Pages.ImportMode.UseTempDs && !(source is SqlDataSource)) { newTable.SetRowLimitClause(rowLimitClause); newTable.SetIdentifierQuoting(identifierQuoting); } var schemaTable = source.GetSchemaTable(tableSchema, identifierQuoting); foreach (DataRow row in schemaTable.Rows) { var sourceColumn = row["ColumnName"].ToString(); var dataType = schemaTable.Columns.Contains("DataTypeName") ? row["DataTypeName"].ToString() : (row["DataType"] as Type).Name; var col = newTable.AddDataColumn( sourceColumn, sourceColumn, null, TableMetadata.DataTypeMap(dataType) ); col.SourceProviderType = dataType; } newTable.SetTableSchema(tableSchema); newTable.Select(); if (UIController.Current.TreeModel.Perspective != null) { newTable.InPerspective[UIController.Current.TreeModel.Perspective] = true; } } }
public void Init(TypedDataSource source) { Source = source; SchemaModel = new SchemaModel(Source, InitialSelection); switch (source) { case OdbcDataSource odbc: case OracleDataSource oracle: case OleDbDataSource oledb: case OtherDataSource other: chkEnablePreview.Left = panel1.ClientSize.Width - 345; break; case SqlDataSource sql: lblRowReduction.Visible = false; cmbRowReduction.Visible = false; chkEnablePreview.Left = panel1.ClientSize.Width - 101; break; } }
public static DialogResult ShowWizard(Model model, ProviderDataSource source) { var dialog = new ImportTablesWizard(); dialog.page1.Init(model); var tds = TypedDataSource.GetFromTabularDs(source); if (!(tds is SqlDataSource) && int.TryParse(source.GetAnnotation("TabularEditor_RowLimitClause"), out int rlc)) { dialog.page2.RowLimitClause = (RowLimitClause)rlc; } dialog.page2.Init(tds); dialog.CurrentPage = 2; var res = dialog.ShowDialog(); if (res == DialogResult.OK) { DoImport(dialog.page1.Mode, model, dialog.page2.Source, dialog.page2.SelectedSchemas, dialog.page2.RowLimitClause); } return(res); }
public static DialogResult ShowWizard(Table table) { if (!(table.Partitions[0].DataSource is ProviderDataSource)) { MessageBox.Show("This feature currently only supports tables using Legacy Data Sources.", "Unsupported Data Source", MessageBoxButtons.OK, MessageBoxIcon.Information); return(DialogResult.Cancel); } var dialog = new ImportTablesWizard(); dialog.Model = table.Model; dialog._currentPage = 2; dialog.btnBack.Visible = false; dialog.btnNext.Visible = false; dialog.btnCancel.Left = 654; dialog.page2.lblHeader.Text = "Choose the table/view you want to use as a source for " + table.DaxObjectFullName + ":"; dialog.btnImport.Text = "OK"; dialog.page2.SingleSelection = true; dialog.page2.InitialSelection = table.GetTableSchema(); dialog.page2.RowLimitClause = table.GetRowLimitClause(); dialog.page2.IdentifierQuoting = table.GetIdentifierQuoting(); if (!dialog.page2.Init(TypedDataSource.GetFromTabularDs(table.Partitions[0].DataSource as ProviderDataSource))) { return(DialogResult.Cancel); } dialog.page2.Visible = true; // TODO: var res = dialog.ShowDialog(); if (res == DialogResult.OK) { DoUpdate(table, dialog.page2.Source, dialog.page2.SelectedSchemas.First(), dialog.page2.RowLimitClause, dialog.page2.IdentifierQuoting); } return(res); }
private static void DoImport(Pages.ImportMode importMode, Model model, TypedDataSource source, IEnumerable <SchemaNode> schemaNodes, RowLimitClause rowLimitClause) { foreach (var tableSchema in schemaNodes) { var newTable = model.AddTable(tableSchema.Name); if (newTable.Partitions[0] is MPartition) { Partition.CreateNew(newTable); newTable.Partitions[0].Delete(); } newTable.Partitions[0].Name = tableSchema.Name; newTable.Partitions[0].Query = tableSchema.GetSql(true, source.UseThreePartName); if (importMode != Pages.ImportMode.UseTempDs) { newTable.Partitions[0].DataSource = model.DataSources[source.TabularDsName]; model.DataSources[source.TabularDsName].SetAnnotation("TabularEditor_RowLimitClause", ((int)rowLimitClause).ToString()); } var schemaTable = source.GetSchemaTable(tableSchema); foreach (DataRow row in schemaTable.Rows) { var sourceColumn = row["ColumnName"].ToString(); var dataType = schemaTable.Columns.Contains("DataTypeName") ? row["DataTypeName"].ToString() : (row["DataType"] as Type).Name; var col = newTable.AddDataColumn( sourceColumn, sourceColumn, null, TableMetadata.DataTypeMap(dataType) ); col.SourceProviderType = dataType; } newTable.Partitions[0].SetAnnotation("TabularEditor_TableSchema", tableSchema.ToJson()); newTable.Select(); } }
public SchemaModel(TypedDataSource dataSource, SchemaNode initialSelection) { InitialSelection = initialSelection; TypedDataSource = dataSource; }