protected override void LoadLinks() { Links = new List <BlobChildLink>(); SlotCount = (Data.Length - 12) / 12; for (var i = 0; i < SlotCount; i++) { Mark("LinksArray", "Child " + i + " - ", i); var length = BitConverter.ToInt32(Data, ChildOffset + (i * 12)); var rowIdData = new byte[8]; Array.Copy(Data, ChildOffset + (i * 12) + 4, rowIdData, 0, 8); var rowId = new RowIdentifier(rowIdData); var link = new BlobChildLink(rowId, 0, length); link.Mark("Length", Offset + ChildOffset + (i * 12), sizeof(int)); link.Mark("RowIdentifier", Offset + ChildOffset + (i * 12) + sizeof(int), 8); Links.Add(link); } }
private void MarkersDataGridView_CellContentClick(object sender, DataGridViewCellEventArgs e) { if (e.RowIndex >= 0) { if ((MarkerType)markersDataGridView.Rows[e.RowIndex].Cells["DataTypeColumn"].Value == MarkerType.PageAddress) { var temp = PageNavigated; if (temp != null) { var pageEvent = new PageEventArgs( RowIdentifier.Parse( markersDataGridView.Rows[e.RowIndex].Cells["valueDataGridViewTextBoxColumn"].Value. ToString()), false); temp(this, pageEvent); } } else { if (SelectionClicked != null) { SelectionClicked(sender, e); } } } }
private object[] GetDataRow(RowIdentifier riNewFk) { if (riNewFk == null) { throw new ArgumentNullException(nameof(riNewFk)); } if (!riNewFk.Columns.Any()) { throw new Exception("Failed to return a foreign key value."); } //La FK (ou unique constraint) n'est pas necessairement la PK donc on réobtient la ligne car //BuildExecutionPlan retourne toujours la PK. var sqlVar = riNewFk.Columns.Values.First() as SqlVariable; if (sqlVar == null) { throw new Exception(); } var varId = sqlVar.Id; foreach (var plan in _executionPlanByServer) { var dr = plan.Value.InsertSteps.FirstOrDefault(r => r.Variables.Any(v => v.Id == varId)); if (dr != null) { return(dr.Datarow); } } throw new Exception(); }
public void Cloning_With_StaticTable(Connection conn) { //Arrange var config = Utils.MakeDefaultSettings(conn); var tablesConfig = config.GetDefaultSchema(); tablesConfig.AddRange(new List <TableModifier> { new TableModifier { Name = "Artist", IsStatic = true } }); var executionPlanBuilder = new ExecutionPlanBuilder(config); var source = new RowIdentifier { ServerId = conn.Id, Database = Utils.TestDatabase(conn), Schema = Utils.TestSchema(conn), Table = "Album", Columns = new ColumnsWithValue { { "AlbumId", 1 } } }; var clonedData = new List <RowIdentifier>(); executionPlanBuilder.StatusChanged += (s, e) => { if (e.Status == Status.Cloning) { clonedData.Add(e.SourceRow); } }; //Act var query = executionPlanBuilder.Append(source, false).Compile(); query.Commiting += (s, e) => e.Cancel = true; query.Execute(); //Assert var expectedData = new List <RowIdentifier> { new RowIdentifier { ServerId = conn.Id, Database = Utils.TestDatabase(conn), Schema = Utils.TestSchema(conn), Table = "Album", Columns = new ColumnsWithValue { { "AlbumId", 1 } } } }; Assert.True(Utils.ScrambledEquals(clonedData, expectedData, RowIdentifierComparer.OrdinalIgnoreCase)); }
private static BlobChildLink LoadRootBlobChild(BlobRecord record, int index) { var blobChildLink = new BlobChildLink(); var offsetPosition = record.SlotOffset + BlobRecord.RootChildOffset + (index * 12); blobChildLink.Mark("Offset", offsetPosition, sizeof(int)); var offset = BitConverter.ToInt32(record.Page.PageData, offsetPosition); var rowData = new byte[8]; var rowIdPosition = record.SlotOffset + BlobRecord.RootChildOffset + (index * 12) + 4; blobChildLink.Mark("RowIdentifier", rowIdPosition, 8); Array.Copy(record.Page.PageData, rowIdPosition, rowData, 0, 8); var rowId = new RowIdentifier(rowData); blobChildLink.RowIdentifier = rowId; blobChildLink.Offset = offset; return(blobChildLink); }
private static List <RowIdentifier> ParseClonedRows(Dictionary <string, ExecutionPlan> exucutionPlanByServer) { var clonedRows = new List <RowIdentifier>(); foreach (var server in exucutionPlanByServer) { foreach (var row in server.Value.InsertSteps.Where(s => s.Depth == 0)) { var pkTemp = row.TableMetadata.BuildPkFromDataRow(row.Datarow); //Clone for new reference var clonedPk = new ColumnsWithValue(); foreach (var col in pkTemp) { var sqlVar = col.Value as SqlVariable; clonedPk.Add(col.Key, sqlVar != null ? sqlVar.Value : col.Value); } var riReturn = new RowIdentifier { ServerId = row.DestinationTable.ServerId, Database = row.DestinationTable.Database, Schema = row.DestinationTable.Schema, Table = row.DestinationTable.Table, Columns = clonedPk }; //Construit la pk de retour clonedRows.Add(riReturn); } } return(clonedRows); }
void _superList_DragDropEx(object sender, SuperlistDragEventArgs ea) { bool changed = false; GroupSection gs = ea.SectionOver as GroupSection; if (gs != null) { IDataObject dataObject = ea.DragEventArgs.Data; string[] formats = dataObject.GetFormats(); foreach (string format in formats) { object[] items = dataObject.GetData(format) as object[]; foreach (object item in items) { RowIdentifier ri = item as RowIdentifier; if (ri != null) { foreach (Person p in ri.Items) { ApplyDragDropChanges(gs.RowIdentifier.GroupColumns, (Person)gs.RowIdentifier.Items[0], p); changed = true; } } } } } if (changed) { _superList.Items.Sort(); } }
public override RowSection CreateRowSection( ListControl listControl, RowIdentifier rowIdentifier, HeaderSection headerSection, int position) { return(new MyRowSection(listControl, rowIdentifier, headerSection, position, _style)); }
public RowSection(ListControl listControl, RowIdentifier rowIdentifier, HeaderSection headerSection, int position) : base(listControl) { _headerSection = headerSection; _rowIdentifier = rowIdentifier; _position = position; _seperatorColor = listControl.SeparatorColor; _indentColor = listControl.IndentColor; }
public MyRowSection( ListControl listControl, RowIdentifier rowIdentifier, HeaderSection headerSection, int position) : base(listControl, rowIdentifier, headerSection, position) { _position = position; }
public RowSection( ListControl listControl, RowIdentifier rowIdentifier, HeaderSection headerSection, int position ) : base(listControl) { _headerSection = headerSection; _rowIdentifier = rowIdentifier; _position = position; _seperatorColor = listControl.SeparatorColor; _indentColor = listControl.IndentColor; }
private void LogStatusChanged(RowIdentifier riSource, int level) { var clientCopy = riSource.Clone(); if (StatusChanged != null) { var args = new StatusChangedEventArgs(Status.Cloning, 0, 0, clientCopy, level); StatusChanged(this, args); } }
public MyRowSection( ListControl listControl, RowIdentifier rowIdentifier, HeaderSection headerSection, int position, Style style) : base(listControl, rowIdentifier, headerSection, position) { _style = style; }
public static UpdateStep Deserialize(BinaryReader input) { return(new UpdateStep { StepId = input.ReadInt32(), DestinationTable = TableIdentifier.Deserialize(input), DestinationRow = RowIdentifier.Deserialize(input), ForeignKey = ColumnsWithValue.Deserialize(input) }); }
public static UpdateStep Deserialize(BinaryReader input) { var step = new UpdateStep(); step.StepId = input.ReadInt32(); step.DestinationTable = TableIdentifier.Deserialize(input); step.DestinationRow = RowIdentifier.Deserialize(input); step.ForeignKey = ColumnsWithValue.Deserialize(input); return(step); }
public object[] GetKey(RowIdentifier sourceKey) { var rawKey = new object[sourceKey.Columns.Count]; for (var i = 0; i < sourceKey.Columns.Count; i++) { rawKey[i] = sourceKey.Columns.ElementAt(i).Value; } return(GetKey(sourceKey.ServerId, sourceKey.Database, sourceKey.Schema, sourceKey.Table, rawKey)); }
public ISelectWriter AppendColumns(RowIdentifier row, List <ColumnDefinition> columns) { _sb.Append("SELECT "); //Nom des colonnes for (var i = 0; i < columns.Count(); i++) { _sb.Append(IdentifierDelemiterStart).Append(columns[i].Name).Append(IdentifierDelemiterEnd).Append(","); } _sb.Remove(_sb.Length - 1, 1) .Append(" FROM ") .Append(row.Schema).Append("."); _sb.Append(IdentifierDelemiterStart).Append(row.Table).Append(IdentifierDelemiterEnd); return(this); }
/// <summary> /// Append a blueprint of the desired object to the execution plan. /// </summary> /// <param name="sourceData">Source data representing 0 to N rows.</param> /// <param name="getDerivatives">If set to 1 the Sql data referencing the <see cref="sourceData"/> will be collected.</param> /// <returns>A reference to this <see cref="ExecutionPlanBuilder"/>.</returns> public ExecutionPlanBuilder Append(RowIdentifier sourceData, bool getDerivatives = true) { if (sourceData == null) { throw new ArgumentNullException(nameof(sourceData)); } _steps.Add(sourceData); var rowsGenerating = new Stack <RowIdentifier>(); rowsGenerating.Push(sourceData); BuildExecutionPlan(sourceData, getDerivatives, false, 0, rowsGenerating); BuildCircularReferencesPlan(); return(this); }
private static BlobChildLink LoadInternalBlobChild(BlobRecord blobRecord, int index) { var offset = BitConverter.ToInt32(blobRecord.Page.PageData, blobRecord.SlotOffset + BlobRecord.InternalChildOffset + (index * 16)); var rowData = new byte[8]; Array.Copy(blobRecord.Page.PageData, blobRecord.SlotOffset + BlobRecord.InternalChildOffset + (index * 16) + 8, rowData, 0, 8); var rowId = new RowIdentifier(rowData); return(new BlobChildLink(rowId, offset, offset)); }
protected override void LoadLinks() { Links = new List <BlobChildLink>(); var rowIdData = new byte[8]; Array.Copy(Data, RowIdOffset, rowIdData, 0, 8); Mark("LinksArray", string.Empty, 0); var rowId = new RowIdentifier(rowIdData); var link = new BlobChildLink(rowId, 0, 0); link.Mark("RowIdentifier", Offset + RowIdOffset, 8); Links.Add(link); }
public ISelectWriter AppendColumns(RowIdentifier row, List <ColumnDefinition> columns) { _sb.Append("SELECT "); //Nom des colonnes foreach (var column in columns) { _sb.Append(IdentifierDelemiterStart).Append(column.Name).Append(IdentifierDelemiterEnd).Append(","); } _sb.Remove(_sb.Length - 1, 1) .Append(" FROM ") .Append(IdentifierDelemiterStart).Append(row.Database).Append(IdentifierDelemiterEnd).Append("."); if (!string.IsNullOrWhiteSpace(row.Schema)) { _sb.Append(IdentifierDelemiterStart).Append(row.Schema).Append(IdentifierDelemiterEnd).Append("."); } _sb.Append(IdentifierDelemiterStart).Append(row.Table).Append(IdentifierDelemiterEnd); return(this); }
private void GetDerivatives(TableMetadata sourceTable, object[] sourceRow, bool getDerivatives, int level, Stack <RowIdentifier> rowsGenerating) { LogDerivativeStep(level + 1); var derivativeTable = getDerivatives ? sourceTable.DerivativeTables : sourceTable.DerivativeTables.Where(t => t.Access == DerivativeTableAccess.Forced); foreach (var dt in derivativeTable) { var tableDt = Metadatas.GetTable(dt); if (dt.Access == DerivativeTableAccess.Forced && dt.Cascade) { getDerivatives = true; } else if (dt.Access == DerivativeTableAccess.Denied) { continue; } var riDt = new RowIdentifier { ServerId = dt.ServerId, Database = dt.Database, Schema = dt.Schema, Table = dt.Table, Columns = sourceTable.BuildDerivativePk(tableDt, sourceRow) }; var rows = ConnectionsContext.Select(riDt); //Pour chaque ligne dérivée de la table source foreach (var row in rows) { riDt.Columns = tableDt.BuildPkFromDataRow(row); rowsGenerating.Push(riDt); BuildExecutionPlan(riDt, getDerivatives, false, level + 1, rowsGenerating); rowsGenerating.Pop(); } } }
public object[][] Select(IDbConnection connection, Metadatas metadata, RowIdentifier row) { var rows = new List <object[]>(); var tableMetadata = metadata.GetTable(row); var nbParams = row.Columns.Count; var selectWriter = SqlWriter.GetSelectWriter() .AppendColumns(row, tableMetadata.ColumnsDefinition); using (var cmd = connection.CreateCommand()) { //Build query / params for (var i = 0; i < nbParams; i++) { var colName = row.Columns.ElementAt(i).Key; var paramName = SqlWriter.NamedParamPrefix + colName; var p = cmd.CreateParameter(); p.ParameterName = paramName; p.Value = row.Columns.ElementAt(i).Value; cmd.Parameters.Add(p); selectWriter.AppendToWhere(colName, paramName); } cmd.CommandText = selectWriter.ToStringBuilder().ToString(); //Exec query connection.Open(); using (var r = cmd.ExecuteReader()) { while (r.Read()) { var values = new object[r.FieldCount]; r.GetValues(values); rows.Add(values); } } connection.Close(); } return(rows.ToArray()); }
protected override void LoadLinks() { Links = new List <BlobChildLink>(); RowIdentifier rowId; byte[] rowIdData; Length = BitConverter.ToInt32(Data, ChildOffset); rowIdData = new byte[8]; Array.Copy(Data, ChildOffset + 4, rowIdData, 0, 8); Mark("LinksArray", string.Empty, 0); rowId = new RowIdentifier(rowIdData); var link = new BlobChildLink(rowId, Length, 0); link.Mark("RowIdentifier", Offset + ChildOffset + 4, 8); Links.Add(link); }
/// <summary> /// Creates a page viewer window with a given connection string and page address /// </summary> /// <param name="connectionString">The connection string.</param> /// <param name="pageAddress">The page address.</param> /// <returns></returns> public PageViewerContainer CreatePageViewerWindow(string connectionString, RowIdentifier rowIdentifier) { Guid id = Guid.NewGuid(); Windows2 windows2 = applicationObject.Windows as Windows2; if (windows2 != null) { object controlObject = null; Assembly asm = Assembly.GetExecutingAssembly(); Window toolWindow = windows2.CreateToolWindow2(this.addInInstance, asm.Location, "InternalsViewer.SSMSAddIn.PageViewerContainer", "Page Viewer " + rowIdentifier.PageAddress.ToString(), "{" + id.ToString() + "}", ref controlObject); // Make the window a tabbed document toolWindow.Linkable = false; toolWindow.IsFloating = false; PageViewerContainer pageViewerContainer = (controlObject as PageViewerContainer); pageViewerContainer.Window = toolWindow; pageViewerContainer.WindowManager = this; pageViewerContainer.PageViewerWindow.LoadPage(connectionString, rowIdentifier); toolWindow.Visible = true; pageViewerContainer.PageViewerWindow.SetSlot(rowIdentifier.SlotId); return(pageViewerContainer); } else { return(null); } }
Person[] PersonsFromDataObject(IDataObject dataObject) { List <Person> persons = new List <Person>(); string[] formats = dataObject.GetFormats(); foreach (string format in formats) { object[] items = dataObject.GetData(format) as object[]; foreach (object item in items) { RowIdentifier ri = item as RowIdentifier; if (ri != null) { foreach (Person p in ri.Items) { persons.Add(p); } } } } return(persons.ToArray()); }
private PositionedRowIdentifier SelectedItemFromRowIdentifer( RowIdentifier ri ) { return new PositionedRowIdentifier( ri, PositionFromRowIdentifier( ri ) ); }
public virtual RowSection CreateRowSection( ListControl listControl, RowIdentifier rowIdentifier, HeaderSection headerSection, int position ) { return new RowSection( listControl, rowIdentifier, headerSection, position ); }
/// <summary> /// Creates a page viewer window with the application level connection string /// </summary> /// <param name="pageAddress">The page address.</param> /// <returns></returns> public PageViewerContainer CreatePageViewerWindow(RowIdentifier rowIdentifier) { return(CreatePageViewerWindow(InternalsViewerConnection.CurrentConnection().ConnectionString, rowIdentifier)); }
public PositionedRowIdentifier( RowIdentifier rowIdentifier, int position ) { RowIdentifier = rowIdentifier; Position = position; }
private void BuildCircularReferencesPlan() { foreach (var job in _circularKeyJobs) { var baseTable = Metadatas.GetTable(job.SourceBaseRowStartPoint); var fkTable = Metadatas.GetTable(job.SourceFkRowStartPoint); var pkDestinationRow = _keyRelationships.GetKey(job.SourceBaseRowStartPoint); var keyDestinationFkRow = _keyRelationships.GetKey(job.SourceFkRowStartPoint); var serverDstBaseTable = ExecutionContext.Map[new SehemaIdentifier { ServerId = job.SourceBaseRowStartPoint.ServerId, Database = job.SourceBaseRowStartPoint.Database, Schema = job.SourceBaseRowStartPoint.Schema }]; var serverDstFkTable = ExecutionContext.Map[new SehemaIdentifier { ServerId = job.SourceFkRowStartPoint.ServerId, Database = job.SourceFkRowStartPoint.Database, Schema = job.SourceFkRowStartPoint.Schema }]; if (job.ForeignKey.Columns.Count != keyDestinationFkRow.Length) { throw new Exception("The foreign key defenition is not matching with the values."); } var fk = new ColumnsWithValue(); for (var i = 0; i < job.ForeignKey.Columns.Count; i++) { var colName = job.ForeignKey.Columns[i].NameTo; var value = keyDestinationFkRow[i]; fk.Add(colName, value); } var riBaseDestination = new RowIdentifier { ServerId = serverDstBaseTable.ServerId, Database = serverDstBaseTable.Database, Schema = serverDstBaseTable.Schema, Table = job.SourceBaseRowStartPoint.Table, Columns = baseTable.BuildPkFromRawKey(pkDestinationRow) }; var riFkDestination = new RowIdentifier { ServerId = serverDstFkTable.ServerId, Database = serverDstFkTable.Database, Schema = serverDstFkTable.Schema, Table = job.SourceFkRowStartPoint.Table, Columns = fk }; var fkDestinationDataRow = GetDataRow(riFkDestination); var modifiedFk = fkTable.BuildKeyFromFkDataRow(job.ForeignKey, fkDestinationDataRow); var step = new UpdateStep() { StepId = _nextStepId++, DestinationRow = riBaseDestination, ForeignKey = modifiedFk, DestinationTable = riFkDestination }; AddUpdateStep(step); } _circularKeyJobs.Clear(); }
/// <summary> /// Returns the number of items in the list adjusted for the group items. /// This method will also create a bit array of types <seealso cref="_positionTypes"/> /// </summary> /// <returns></returns> private int CalculateListItems() { using( new EnforceLazyLayout( this ) ) { if( _rowInformation == null ) { PositionedRowIdentifier[] trackableItems = new PositionedRowIdentifier[3]; trackableItems[0] = _focusedItem; if( _lastCalculatedRowInformation != null ) { if( FocusedItem != null ) { if( LineStart < _lastCalculatedRowInformation.Count ) { trackableItems[1] = new PositionedRowIdentifier( _lastCalculatedRowInformation[LineStart], LineStart ); } RowIdentifier nextValidRow = locateNearestRowThatsStillValid( FocusedItem, ItemList, _lastCalculatedRowInformation ); if( nextValidRow != null ) { trackableItems[2] = new PositionedRowIdentifier( nextValidRow, 0 ); } } } Column[] groupColumns = ListControl.Columns.GroupedItems.ToArray(); object lastItem = null; _lastCalculatedRowInformation = _rowInformation = new List<RowIdentifier>( ItemList.Count ); int hideRowGroupIndex = -1; List<PositionedRowIdentifier> newSelection = new List<PositionedRowIdentifier>(); GroupIdentifier[] activeGroups = new GroupIdentifier[groupColumns.Length]; object[] listItems = ItemList.ToArray(); for( int i = 0; i < ItemList.Count; i++ ) { object item = ItemList[i]; int groupIndex = ItemInNewGroup( groupColumns, item, lastItem ); if( groupIndex != -1 ) { for( int iGroup = groupIndex; iGroup < groupColumns.Length; iGroup++ ) { GroupIdentifier gi = new GroupIdentifier( i, listItems, Columns, iGroup, item ); int hideGroupIndex = hideRowGroupIndex; if( hideRowGroupIndex == -1 || iGroup <= hideRowGroupIndex ) { if( GetGroupState( gi ) == GroupState.Collapsed ) { hideGroupIndex = iGroup; if( groupIndex <= hideRowGroupIndex ) { hideRowGroupIndex = -1; } } else { hideRowGroupIndex = hideGroupIndex = -1; } } if( hideRowGroupIndex == -1 ) { HandleSyncing( gi, _rowInformation.Count, trackableItems, newSelection ); _rowInformation.Add( gi ); } if( activeGroups[iGroup] != null ) { activeGroups[iGroup].End = i; } activeGroups[iGroup] = gi; hideRowGroupIndex = hideGroupIndex; } } if( hideRowGroupIndex == -1 ) { RowIdentifier ri = new NonGroupRow( item ); HandleSyncing( ri, _rowInformation.Count, trackableItems, newSelection ); _rowInformation.Add( ri ); } lastItem = item; } foreach( GroupIdentifier gi in activeGroups ) { if( gi != null ) { gi.End = ItemList.Count; } } if( VerticalScrollbarVisible ) { int newMax = _rowInformation.Count == 0 ? 0 : _rowInformation.Count - 1; if( VScrollbar.Value >= newMax ) { VScrollbar.Value = newMax; } VScrollbar.Maximum = newMax; } if( trackableItems[1] != null ) { LineStart = trackableItems[1].Position; } if( _focusedItem != null && !IsSelectedItemValid( _focusedItem ) ) { if( trackableItems[2] != null && IsSelectedItemValid( trackableItems[2] ) ) { PositionedRowIdentifier oldFocusedItem = _focusedItem; if( _focusedItem != trackableItems[2] ) { _focusedItem = trackableItems[2]; ListControl.FireFocusChanged( oldFocusedItem == null ? null : oldFocusedItem.RowIdentifier, _focusedItem == null ? null : _focusedItem.RowIdentifier ); } newSelection.Add( _focusedItem ); } else { int newPosition; if( _focusedItem.Position >= _rowInformation.Count ) { newPosition = _rowInformation.Count - 1; } else { newPosition = _focusedItem.Position; } if( newPosition >= 0 ) { PositionedRowIdentifier si = new PositionedRowIdentifier( _rowInformation[newPosition], newPosition ); FocusedItem = si; newSelection.Add( _focusedItem ); } else { FocusedItem = null; } } } RowIdentifier[] rowItemsToSelect = new RowIdentifier[newSelection.Count]; int j = 0; foreach( PositionedRowIdentifier pri in newSelection ) { rowItemsToSelect[j++] = pri.RowIdentifier; } SelectedItems.ClearAndAdd( rowItemsToSelect ); if( SelectedItems.Count == 0 && FocusedItem == null && VScrollbar != null && VScrollbar.Visible ) { VScrollbar.Value = 0; } } _mapOfPositions = null; } ListControl.OnCalculatedGroupRows( EventArgs.Empty ); return _rowInformation.Count; }
public virtual GroupSection CreateGroupSection( ListControl listControl, RowIdentifier ri, HeaderSection headerSection, int position, int groupIndentWidth ) { return new GroupSection( listControl, ri, headerSection, position, groupIndentWidth ); }
public void Cloning_With_DataBuilder(Connection conn) { //Arrange var project = Utils.MakeDefaultProject(conn); project.ExtractionTemplates[0].Tables.AddRange(new List <Table> { new Table { Name = "Employee", DataBuilders = new List <DataBuilder> { new DataBuilder { Name = "FirstName", BuilderName = "StringDataBuilder" }, new DataBuilder { Name = "LastName", BuilderName = "StringDataBuilder" }, new DataBuilder { Name = "ReportsTo", BuilderName = "AutoIncrementDataBuilder" } } } }); var executionPlanBuilder = new ExecutionPlanBuilder(project, Utils.MakeDefaultContext()); var source = new RowIdentifier { ServerId = conn.Id, Database = Utils.TestDatabase(conn), Schema = Utils.TestSchema(conn), Table = "Employee", Columns = new ColumnsWithValue { { "EmployeeId", 1 } } }; //Act var query = executionPlanBuilder.Append(source, false).Compile(); IDbCommand command = null; query.Commiting += (s, e) => { e.Cancel = true; command = e.Command; }; query.Execute(); //Assert var paramFirstName = command?.Parameters["@FirstName0"] as IDataParameter; Assert.Matches("(.+){20}", paramFirstName.Value.ToString()); var paramLastName = command?.Parameters["@LastName0"] as IDataParameter; Assert.Matches("(.+){20}", paramLastName.Value.ToString()); var paramReportsTo = command?.Parameters["@ReportsTo0"] as IDataParameter; Assert.True(paramReportsTo.Value.IsNumericType()); }
private int PositionFromRowIdentifier( RowIdentifier ri ) { int position; if( GetRowPosMap().TryGetValue( ri, out position ) ) { return position; } return -1; }
public void SetGroupState( RowIdentifier ri, GroupState groupState, bool layoutNow ) { System.Diagnostics.Debug.Assert( ri.GroupColumns != null ); if( FocusedItem != null && FocusedItem.RowIdentifier.GroupColumns.Length == 0 && Array.IndexOf( ri.Items, FocusedItem.RowIdentifier.Items[0] ) != -1 ) { bool isSelected = SelectedItems.Contains( FocusedItem.RowIdentifier ); PositionedRowIdentifier pri = GetPositionedIdentifierFromObject( ri ); if( pri != null ) { if( !SelectedItems.Contains( pri.RowIdentifier ) ) { SelectedItems.Add( pri.RowIdentifier ); } FocusedItem = pri; } } if( GetGroupState( ri ) != groupState ) { if( _globalGroupState == groupState ) { _groupExpansionState.Remove( ri ); } else { _groupExpansionState.Add( ri ); } ClearRowInformation(); if( layoutNow ) { Layout(); } else { Host.LazyLayout( this ); } } }
internal PositionedRowIdentifier GetPositionedIdentifierFromObject( RowIdentifier identifier ) { int position; if( GetRowPosMap().TryGetValue( identifier, out position ) ) { return new PositionedRowIdentifier( identifier, position ); } return null; }
private static bool IsValidNextRow( RowIdentifier ri, RowIdentifier riCompare, ItemLists.ItemList itemList ) { // // Only settle on same type rows. if( (ri.GroupColumns.Length == 0 ^ riCompare.GroupColumns.Length == 0 ) == false ) { // // Only include items that exist now. if( itemList.IndexOf( riCompare.Items[0] ) != -1 ) { return true; } } return false; }
public void CloningDerivatives_With_GlobalAccessDenied(Connection conn) { //Arrange var project = Utils.MakeDefaultProject(conn); project.ExtractionTemplates[0].Tables.Add(new Table { Name = "Album", DerativeTableGlobal = new DerivativeTableGlobal { GlobalAccess = DerivativeTableAccess.Denied } }); var executionPlanBuilder = new ExecutionPlanBuilder(project, Utils.MakeDefaultContext()); var source = new RowIdentifier { ServerId = conn.Id, Database = Utils.TestDatabase(conn), Schema = Utils.TestSchema(conn), Table = "Artist", Columns = new ColumnsWithValue { { "ArtistId", 1 } } }; var clonedData = new List <RowIdentifier>(); executionPlanBuilder.StatusChanged += (s, e) => { if (e.Status == Status.Cloning) { clonedData.Add(e.SourceRow); } }; //Act var query = executionPlanBuilder.Append(source, true).Compile(); query.Commiting += (s, e) => e.Cancel = true; query.Execute(); //Assert var expectedData = new List <RowIdentifier> { new RowIdentifier { ServerId = conn.Id, Database = Utils.TestDatabase(conn), Schema = Utils.TestSchema(conn), Table = "Artist", Columns = new ColumnsWithValue { { "ArtistId", 1 } } }, new RowIdentifier { ServerId = conn.Id, Database = Utils.TestDatabase(conn), Schema = Utils.TestSchema(conn), Table = "Album", Columns = new ColumnsWithValue { { "AlbumId", 1 } } }, new RowIdentifier { ServerId = conn.Id, Database = Utils.TestDatabase(conn), Schema = Utils.TestSchema(conn), Table = "Album", Columns = new ColumnsWithValue { { "AlbumId", 4 } } } }; Assert.True(Utils.ScrambledEquals(clonedData, expectedData, RowIdentifierComparer.OrdinalIgnoreCase)); }
private RowSection RowSectionFromRowIdentifier( RowIdentifier ri ) { foreach( Section section in Children ) { RowSection rowSection = section as RowSection; if( rowSection != null && rowSection.RowIdentifier == ri ) { return rowSection; } } return null; }
public bool HasFocus( RowIdentifier ri ) { return Host.FocusedSection == this && _focusedItem != null && _focusedItem.RowIdentifier == ri; }
/// <summary> /// Build an execution plan for the specified data source for blazing fast performance. /// </summary> /// <param name="sourceRow">Identify a single or multiples rows to clone.</param> /// <param name="getDerivatives">When true the data related to the input(s) line(s) from other tables will be cloned.</param> /// <param name="shouldReturnFk">Indicate that a source row should only return a single line.</param> /// <param name="level">Current recursion level.</param> /// <param name="rowsGenerating">Current stack to handle circular foreign keys.</param> /// <returns>Always return the primary key of the source row, same if the value queried is a foreign key.</returns> private RowIdentifier BuildExecutionPlan(RowIdentifier sourceRow, bool getDerivatives, bool shouldReturnFk, int level, Stack <RowIdentifier> rowsGenerating) { var srcRows = ConnectionsContext.Select(sourceRow); var nbRows = srcRows.Length; var table = Metadatas.GetTable(sourceRow); //By default the destination server is the source if no road is found. var serverDst = new SehemaIdentifier { ServerId = sourceRow.ServerId, Database = sourceRow.Database, Schema = sourceRow.Schema }; if (ExecutionContext.Map.ContainsKey(serverDst)) { serverDst = ExecutionContext.Map[serverDst]; } var riReturn = new RowIdentifier { ServerId = serverDst.ServerId, Database = serverDst.Database, Schema = serverDst.Schema, Table = sourceRow.Table }; var tiDestination = new TableIdentifier { ServerId = serverDst.ServerId, Database = serverDst.Database, Schema = serverDst.Schema, Table = sourceRow.Table }; LogStatusChanged(sourceRow, level); if (shouldReturnFk && nbRows > 1) { throw new Exception("The foreignkey is not unique!"); } //For each row for (var i = 0; i < nbRows; i++) { var currentRow = srcRows[i]; var srcKey = table.BuildRawPkFromDataRow(currentRow); //Si ligne déjà enregistrée var dstKey = _keyRelationships.GetKey(serverDst.ServerId, serverDst.Database, serverDst.Schema, sourceRow.Table, srcKey); if (dstKey != null) { if (shouldReturnFk) { //Construit la pk de retour riReturn.Columns = table.BuildPkFromRawKey(dstKey); return(riReturn); } continue; } var destinationRow = (object[])currentRow.Clone(); foreach (var fk in table.ForeignKeys) { //On skip si la FK est null var fkValue = table.BuildRawFkFromDataRow(fk, currentRow); if (fkValue.Contains(DBNull.Value)) { continue; } //Si la foreignkey a déjà été enregistrée, on l'utilise var fkDst = _keyRelationships.GetKey(fk.ServerIdTo, fk.DatabaseTo, fk.SchemaTo, fk.TableTo, fkValue); if (fkDst != null) { table.SetFkInDatarow(fk, fkDst, destinationRow); } else { var fkDestinationExists = false; var fkTable = Metadatas.GetTable(fk); var riFk = new RowIdentifier { ServerId = fk.ServerIdTo, Database = fk.DatabaseTo, Schema = fk.SchemaTo, Table = fk.TableTo, Columns = table.BuildKeyFromDerivativeDataRow(fk, currentRow) }; //On ne duplique pas la ligne si la table est statique if (fkTable.IsStatic) { //TODO : Tester si la FK existe dans la table de destination de clônage et non si la fk existe dans la bd source var fkRow = ConnectionsContext.Select(riFk); fkDestinationExists = fkRow.Length == 1; if (fkRow.Length > 1) { throw new Exception("The FK is not unique."); } //Si la ligne existe déjà, on l'utilise if (fkDestinationExists) { //Sauve la clef var colFkObj = fkTable.BuildRawPkFromDataRow(fkRow[0]); _keyRelationships.SetKey(fk.ServerIdTo, fk.DatabaseTo, fk.SchemaTo, fk.TableTo, colFkObj, colFkObj); } } //La FK n'existe pas, on la crer if (!fkDestinationExists) { //Si référence circulaire if (rowsGenerating.Contains(riFk)) { //Affecte la FK à 1 pour les contraintes NOT NULL. EnforceIntegrity doit être désactivé. var nullFk = Enumerable.Repeat <object>(1, fk.Columns.Count).ToArray(); table.SetFkInDatarow(fk, nullFk, destinationRow); //On ajoute une tâche pour réassigner la FK "correctement", une fois que toute la chaîne aura été enregistrée. _circularKeyJobs.Add(new CircularKeyJob { SourceBaseRowStartPoint = new RowIdentifier { ServerId = sourceRow.ServerId, Database = sourceRow.Database, Schema = sourceRow.Schema, Table = sourceRow.Table, Columns = table.BuildPkFromDataRow(currentRow) }, SourceFkRowStartPoint = riFk, ForeignKey = fk }); } else { //Crer la ligne et ses dépendances rowsGenerating.Push(riFk); var riNewFk = BuildExecutionPlan(riFk, false, true, level + 1, rowsGenerating); rowsGenerating.Pop(); var newFkRow = GetDataRow(riNewFk); //Affecte la clef table.SetFkFromDatarowInDatarow(fkTable, fk, newFkRow, destinationRow); } } } } var step = CreateExecutionStep(sourceRow, tiDestination, table, destinationRow, level); //Sauve la PK dans la cache dstKey = table.BuildRawPkFromDataRow(step.Datarow); _keyRelationships.SetKey(sourceRow.ServerId, sourceRow.Database, sourceRow.Schema, sourceRow.Table, srcKey, dstKey); //Ajouter les colonnes de contrainte unique dans _keyRelationships //... //On affecte la valeur de retour if (shouldReturnFk) { riReturn.Columns = table.BuildPkFromRawKey(dstKey); } //On clone les lignes des tables dépendantes GetDerivatives(table, currentRow, getDerivatives, level, rowsGenerating); } return(riReturn); }
public GroupSection( ListControl listControl, RowIdentifier ri, HeaderSection headerSection, int position, int groupIndentWidth ) : base(listControl, ri, headerSection, position) { Debug.Assert( ri is ListSection.GroupIdentifier ); _groupIndentWidth = groupIndentWidth; }
public GroupState GetGroupState( RowIdentifier ri ) { GroupState opposite = _globalGroupState == GroupState.Expanded ? GroupState.Collapsed : GroupState.Expanded; GroupState gs = _groupExpansionState.Contains( ri ) ? opposite : _globalGroupState; GroupState gsCopy = gs; ListControl.GetGroupedState( ri, ref gs ); if( gsCopy != gs ) { if( _groupExpansionState.Contains( ri ) ) { _groupExpansionState.Remove( ri ); } else { _groupExpansionState.Add( ri ); } } return gs; }
private void HandleSyncing( RowIdentifier ri, int newPosition, PositionedRowIdentifier[] trackableItems, List<PositionedRowIdentifier> newSelection ) { foreach( PositionedRowIdentifier si in trackableItems ) { if( si != null ) { if( ri.Equals( si.RowIdentifier ) ) { si.Position = newPosition; } } } if( SelectedItems.Contains( ri ) ) { newSelection.Add( new PositionedRowIdentifier( ri, newPosition ) ); } }