public void GetAppliedMigrations_finds_migrations() { var testConnection = SqliteTestConnection.CreateScratch(); testConnection.Open(); using (var command = testConnection.DbConnection.CreateCommand()) { command.CommandText = CreateSqliteHistoryRepo().Create(true); command.ExecuteNonQuery(); } using (var command = testConnection.DbConnection.CreateCommand()) { command.CommandText = "INSERT INTO __migrationHistory VALUES ('different_context','SomeFakeContext','1');"; command.ExecuteNonQuery(); } var row = new HistoryRow("Mig1", "7"); using (var command = testConnection.DbConnection.CreateCommand()) { var operation = CreateSqliteHistoryRepo() .GetInsertOperation(row) as SqlOperation; command.CommandText = operation?.Sql; command.ExecuteNonQuery(); } var hp = new SqliteHistoryRepository(testConnection, new TestContext(), new SqliteUpdateSqlGenerator()); Assert.Collection(hp.GetAppliedMigrations(), p => { Assert.Equal(row.MigrationId, p.MigrationId); Assert.Equal(row.ProductVersion, p.ProductVersion); }); testConnection.Close(); }
public virtual IReadOnlyList <IHistoryRow> GetAppliedMigrations() { var migrations = new List <IHistoryRow>(); if (!Exists()) { return(migrations); } using (var connection = _connection.DbConnection) { if (connection.State != ConnectionState.Open) { connection.Open(); } var command = connection.CreateCommand(); command.CommandText = $"SELECT MigrationId, ProductVersion FROM {_sql.DelimitIdentifier(MigrationTableName)} " + $"WHERE ContextKey = '{_sql.EscapeLiteral(_contextKey)}' ORDER BY MigrationId;"; using (var reader = command.ExecuteReader()) { while (reader.Read()) { var row = new HistoryRow(reader.GetString(0), reader.GetString(1)); migrations.Add(row); } } } return(migrations.AsReadOnly()); }
public static string BuildInsertScript(HistoryRow row, HistoryRepositoryDependencies dependencies, MigrationHistoryTable historyTable) { var sqlGenerationHelper = dependencies.SqlGenerationHelper; var stringTypeMapping = dependencies.TypeMappingSource.GetMapping(typeof(string)); return(new StringBuilder().Append("INSERT INTO ") .Append(sqlGenerationHelper.DelimitIdentifier(historyTable.TableName, historyTable.TableSchema)) .Append(" (") .Append(sqlGenerationHelper.DelimitIdentifier(historyTable.MigrationIdColumnName)) .Append(", ") .Append(sqlGenerationHelper.DelimitIdentifier(historyTable.ProductVersionColumnName)) .Append(", ") .Append(sqlGenerationHelper.DelimitIdentifier(historyTable.AppliedVersionColumnName)) .Append(", ") .Append(sqlGenerationHelper.DelimitIdentifier(historyTable.AppliedDateColumnName)) .AppendLine(")") .Append("VALUES (") .Append(stringTypeMapping.GenerateSqlLiteral(row.MigrationId)) .Append(", ") .Append(stringTypeMapping.GenerateSqlLiteral(row.ProductVersion)) .Append(", ") .Append(stringTypeMapping.GenerateSqlLiteral(Constants.Version)) .Append(", ") .Append(stringTypeMapping.GenerateSqlLiteral(DateTime.Now.ToString("yyyy'-'MM'-'dd' 'HH':'mm':'ss'.'fffffffK"))) .Append(")") .AppendLine(sqlGenerationHelper.StatementTerminator) .ToString()); }
public override string GetInsertScript(HistoryRow row) { var stringTypeMapping = Dependencies.TypeMappingSource.GetMapping(typeof(string)); var datetimeTypeMapping = Dependencies.TypeMappingSource.GetMapping(typeof(DateTime)); return(new StringBuilder().Append("INSERT INTO ") .Append(SqlGenerationHelper.DelimitIdentifier(TableName, TableSchema)) .Append(" (") .Append(SqlGenerationHelper.DelimitIdentifier(MigrationIdColumnName)) .Append(", ") .Append(SqlGenerationHelper.DelimitIdentifier(ProductVersionColumnName)) .Append(", ") .Append(SqlGenerationHelper.DelimitIdentifier("ContextKey")) .Append(", ") .Append(SqlGenerationHelper.DelimitIdentifier("Applied")) .AppendLine(")") .Append("VALUES (") .Append(stringTypeMapping.GenerateSqlLiteral(row.MigrationId)) .Append(", ") .Append(stringTypeMapping.GenerateSqlLiteral(row.ProductVersion)) .Append(", ") .Append(stringTypeMapping.GenerateSqlLiteral("iSpindelContext")) .Append(", ") .Append(datetimeTypeMapping.GenerateSqlLiteral(DateTime.Now)) .Append(")") .AppendLine(SqlGenerationHelper.StatementTerminator) .ToString()); }
public void Generate_can_output_delete_history_statement() { var migrationSqlGenerator = new SqlCeMigrationSqlGenerator(); using (var historyContext = new HistoryContext()) { var historyRow = new HistoryRow { MigrationId = "House Lannister", ContextKey = "The pointy end" }; historyContext.History.Attach(historyRow); historyContext.History.Remove(historyRow); using (var commandTracer = new CommandTracer(historyContext)) { historyContext.SaveChanges(); var deleteHistoryOperation = new HistoryOperation(commandTracer.CommandTrees.OfType <DbModificationCommandTree>().ToList()); var sql = migrationSqlGenerator .Generate(new[] { deleteHistoryOperation }, "4.0") .Single(); Assert.Equal(@"DELETE [__MigrationHistory] WHERE (([MigrationId] = N'House Lannister') AND ([ContextKey] = N'The pointy end'))", sql.Sql.Trim()); } } }
protected string GetMigrationHistory(DbMigrationsConfiguration migrationConfiguration, string migrationName) { // I would rather not use reflection to get the needed DbConnection but the alternative is requiring // more configuraton or hardcoding to SQL Server. This looks to be the lesser of multiple evils MigratorBase migrator = CreateMigrator(migrationConfiguration); MethodInfo method = migrator.GetType().GetMethod("CreateConnection", BindingFlags.NonPublic | BindingFlags.Instance); using (DbConnection dbConnection = (DbConnection)method.Invoke(migrator, null)) { dbConnection.Open(); using (HistoryContext historyContext = new HistoryContext(dbConnection, null)) { HistoryRow history = historyContext.History.SingleOrDefault(x => x.MigrationId == migrationName); if (history != null) { using (MemoryStream stream = new MemoryStream(history.Model)) { using (GZipStream gzip = new GZipStream(stream, CompressionMode.Decompress)) { return(XDocument.Load(gzip).ToString()); } } } else { return("Migration name not found"); } } } }
public override string GetInsertScript(HistoryRow row) { if (row == null) { throw new ArgumentNullException(nameof(row)); } return(MigrationUtils.BuildInsertScript(row, Dependencies, _migrationHistoryTable)); }
/// <summary> /// Add a new history row /// </summary> /// <param name="model"></param> /// <param name="historyId"></param> public void AddHistoryRow(HistoryRow model, string historyId) { var history = this.context.AssetHistories.Find(historyId); var row = this.context.HistoryRows.Add(model); history.Rows.Add(row); this.context.SaveChanges(); }
public override string GetInsertScript(HistoryRow row) { // Add tenant prefix to any new rows if (modulePrefix != null) { row = new HistoryRow(modulePrefix + row.MigrationId, row.ProductVersion); } return(base.GetInsertScript(row)); }
HistoryRow ToHistoryRow(PageTestedResult testedResult) { var hr = new HistoryRow { Id = CurrentId, Date = DateTime.UtcNow }; Map(hr, testedResult); return(hr); }
internal void Fill(HistoryRow row) { if (row.Data is ReceivedUrl) { this.Title.TextFormatted = GetCardTitle("Link", row.RemoteDeviceName); this.TextPreview.Text = Concat($"{(row.Data as ReceivedUrl).Uri.OriginalString}"); SetButtonsVisibility(this, HistoryItemState.Url); } else if (row.Data is ReceivedText) { this.Title.TextFormatted = GetCardTitle("Clipboard content", row.RemoteDeviceName); DataStorageProviders.TextReceiveContentManager.OpenAsync().GetAwaiter().GetResult(); if (DataStorageProviders.TextReceiveContentManager.ContainsKey(row.Id)) { this.TextPreview.Text = Concat(DataStorageProviders.TextReceiveContentManager.GetItemContent(row.Id)); SetButtonsVisibility(this, HistoryItemState.Text); } else { this.TextPreview.Text = "Corrupted data."; SetButtonsVisibility(this, HistoryItemState.None); } DataStorageProviders.TextReceiveContentManager.Close(); } else if (row.Data is ReceivedFile) { this.Title.TextFormatted = GetCardTitle("File", row.RemoteDeviceName); this.TextPreview.Text = Concat($"{System.IO.Path.GetFileName((row.Data as ReceivedFile).Name)}"); SetButtonsVisibility(this, HistoryItemState.SingleFile); } else if (row.Data is ReceivedFileCollection) { var files = row.Data as ReceivedFileCollection; if (files.Files.Count == 1) { this.Title.TextFormatted = GetCardTitle("File", row.RemoteDeviceName); SetButtonsVisibility(this, HistoryItemState.SingleFile); } else { this.Title.TextFormatted = GetCardTitle($"{files.Files.Count} files", row.RemoteDeviceName); SetButtonsVisibility(this, HistoryItemState.MultipleFiles); } this.TextPreview.Text = Concat(GetFileListPreview(row.Data as ReceivedFileCollection)) + "\n\n" + $"Stored in {files.StoreRootPath}"; } this.Date.Text = $"{row.ReceiveTime}"; }
protected override async void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); SetContentView(Resource.Layout.HistoryBrowse); var guid = Guid.Parse(Intent.GetStringExtra("guid")); HistoryRow history = await LoadHistoryRow(guid); InitPage(history); }
void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e) { if (e.RowIndex >= 0) { HistoryRow row = (HistoryRow)dataGridView1.Rows[e.RowIndex]; if (row.Alert.Type != "info") { row.Expanded = !row.Expanded; row.RefreshRow(); } } }
/// <summary> /// Generates up SQL scripts. /// </summary> /// <param name="plugin">The plugin.</param> /// <param name="migration">The migration.</param> /// <returns></returns> protected virtual IReadOnlyList <MigrationCommand> GenerateUpSql(EntityPlugin plugin, Migration migration) { var migrationId = migration.GetType().GetCustomAttribute <MigrationAttribute>()?.Id; var historyRow = new HistoryRow(migrationId, ProductInfo.GetVersion()); var historyScript = PluginHistoryRepository.GetInsertScript(plugin, historyRow); var historyCommand = RawSqlCommandBuilder.Build(historyScript); return(MigrationsSqlGenerator .Generate(migration.UpOperations, migration.TargetModel) .Concat(new[] { new MigrationCommand(historyCommand, CurrentContext.Context, CommandLogger) }) .ToList()); }
private void dataGridViewRunHistory_CellClick(object sender, DataGridViewCellEventArgs e) { if (e.RowIndex >= 0 && e.RowIndex < dataGridViewRunHistory.RowCount) { HistoryRow row = (HistoryRow)dataGridViewRunHistory.Rows[e.RowIndex]; if (row.Alert.Type == PolicyAlertType.Error) { row.Expanded = !row.Expanded; row.RefreshRow(); } } }
internal HistoryRow ValidateCollectedRow() { var historyRow = new HistoryRow() { Symbols = CollectedSymbolRow.Symbols.ToArray(), Hints = GenerateHints(CollectedSymbolRow) }; PuzzleHistoryRows.Add(historyRow); return(historyRow); }
public HistoryRow AddHistoryRow(string URL, System.DateTime DATE, string RESULT) { HistoryRow rowHistoryRow = ((HistoryRow)(this.NewRow())); object[] columnValuesArray = new object[] { URL, DATE, RESULT }; rowHistoryRow.ItemArray = columnValuesArray; this.Rows.Add(rowHistoryRow); return(rowHistoryRow); }
public async Task RightDownExchange(HistoryRowDto rowDto) { if (!rowDto.ToAmount.HasValue) { throw new ArgumentException(); } //var from = await _dbContext.Currencies.FindAsync(rowDto.FromCurrency); //var to = await _dbContext.Currencies.FindAsync(rowDto.ToCurrency); var historyRow = new HistoryRow { FromAmount = rowDto.FromAmount, ToAmount = rowDto.ToAmount.Value, FromCurrency = rowDto.FromCurrency, ToCurrency = rowDto.ToCurrency }; await _dbContext.History.AddAsync(historyRow); await _dbContext.SaveChangesAsync(); }
public void GetInsertOperation_deletes_row() { var hp = CreateSqliteHistoryRepo(); var typename = typeof(TestContext).FullName; var expected = new SqlOperation { Sql = $"INSERT INTO \"__migrationHistory\" (\"MigrationId\", \"ContextKey\", \"ProductVersion\") VALUES ('m5', '{typename}', '7');" }; var historyRow = new HistoryRow("m5", "7"); var actual = hp.GetInsertOperation(historyRow) as SqlOperation; Assert.Equal(expected.IsDestructiveChange, actual.IsDestructiveChange); Assert.Equal(expected.Sql, actual.Sql); Assert.Equal(expected.SuppressTransaction, actual.SuppressTransaction); }
public override string GetInsertScript(HistoryRow row) { Check.NotNull(row, nameof(row)); return(new StringBuilder().Append("INSERT INTO ") .Append(SqlGenerationHelper.DelimitIdentifier(TableName, TableSchema)) .Append(" (") .Append(SqlGenerationHelper.DelimitIdentifier(MigrationIdColumnName)) .Append(", ") .Append(SqlGenerationHelper.DelimitIdentifier(ProductVersionColumnName)) .AppendLine(")") .Append("VALUES (N'") .Append(SqlGenerationHelper.EscapeLiteral(row.MigrationId)) .Append("', N'") .Append(SqlGenerationHelper.EscapeLiteral(row.ProductVersion)) .AppendLine("');") .ToString()); }
public override string GetInsertScript(HistoryRow row) { Check.NotNull(row, nameof(row)); return new StringBuilder().Append("INSERT INTO ") .Append(SqlGenerator.DelimitIdentifier(TableName, TableSchema)) .Append(" (") .Append(SqlGenerator.DelimitIdentifier(MigrationIdColumnName)) .Append(", ") .Append(SqlGenerator.DelimitIdentifier(ProductVersionColumnName)) .AppendLine(")") .Append("VALUES (N'") .Append(SqlGenerator.EscapeLiteral(row.MigrationId)) .Append("', N'") .Append(SqlGenerator.EscapeLiteral(row.ProductVersion)) .AppendLine("');") .ToString(); }
/// <summary> /// Generates a SQL script to insert a row into the history table. /// </summary> /// <param name="row">The row to insert, represented as a <see cref="HistoryRow" /> entity.</param> /// <returns>The generated SQL.</returns> public virtual string GetInsertScript(HistoryRow row) { var stringTypeMapping = Dependencies.TypeMappingSource.GetMapping(typeof(string)); return(new StringBuilder().Append("INSERT INTO ") .Append(SqlGenerationHelper.DelimitIdentifier(TableName, TableSchema)) .Append(" (") .Append(SqlGenerationHelper.DelimitIdentifier(MigrationIdColumnName)) .Append(", ") .Append(SqlGenerationHelper.DelimitIdentifier(ProductVersionColumnName)) .AppendLine(")") .Append("VALUES (") .Append(stringTypeMapping.GenerateSqlLiteral(row.MigrationId)) .Append(", ") .Append(stringTypeMapping.GenerateSqlLiteral(row.ProductVersion)) .Append(')') .AppendLine(SqlGenerationHelper.StatementTerminator) .ToString()); }
//Retry once private static async Task <HistoryRow> GetItem(Guid guid) { HistoryRow data = null; await DataStorageProviders.HistoryManager.OpenAsync(); try { data = DataStorageProviders.HistoryManager.GetItem(guid); } catch { await Task.Delay(500); data = DataStorageProviders.HistoryManager.GetItem(guid); } DataStorageProviders.HistoryManager.Close(); return(data); }
/// <summary> /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to /// the same compatibility standards as public APIs. It may be changed or removed without notice in /// any release. You should only use it directly in your code with extreme caution and knowing that /// doing so can result in application failures when updating to a new Entity Framework Core release. /// </summary> public override string GetInsertScript(HistoryRow row) { Check.NotNull(row, nameof(row)); var stringTypeMapping = Dependencies.TypeMappingSource.GetMapping(typeof(string)); return(new StringBuilder().Append("INSERT INTO ") .Append(SqlGenerationHelper.DelimitIdentifier(TableName)) .Append(" (") .Append(SqlGenerationHelper.DelimitIdentifier(MigrationIdColumnName)) .Append(", ") .Append(SqlGenerationHelper.DelimitIdentifier(ProductVersionColumnName)) .AppendLine(")") .Append("VALUES (") .Append(stringTypeMapping.GenerateSqlLiteral(row.MigrationId)) .Append(", ") .Append(stringTypeMapping.GenerateSqlLiteral(row.ProductVersion)) .AppendLine(");") .ToString()); }
private void InitPage(HistoryRow history) { dataAdapter = new HistoryBrowseAdapter(history.Data as ReceivedFileCollection); recyclerView = FindViewById <RecyclerView>(Resource.Id.historyBrowse_RecyclerView); recyclerView.SetAdapter(dataAdapter); layoutManager = new LinearLayoutManager(this); recyclerView.SetLayoutManager(layoutManager); var toolbar = FindViewById <Toolbar>(Resource.Id.historyBrowse_toolbar); SetSupportActionBar(toolbar); SupportActionBar.Title = $"Browse files"; dataAdapter.ShareFileRequested += DataAdapter_ShareFileRequested; dataAdapter.OpenFileRequested += DataAdapter_OpenFileRequested; dataAdapter.FolderExpanded += DataAdapter_FolderExpanded; dataAdapter.GoneBack += DataAdapter_GoneBack; }
public void Add <T>(T obj) { SitemapRow sr = obj as SitemapRow; if (sr != null) { Add(sr); } else { HistoryRow hr = obj as HistoryRow; if (hr != null) { Add(hr); } else { throw new ArgumentException("Parameter type must be either HistoryRow or SitemapRow.", nameof(obj)); } } }
/// <summary> /// Gets the SQL script to be executed in order to save the <see cref="HistoryRow" /> /// to the database. /// </summary> /// <param name="plugin">The plugin.</param> /// <param name="historyRow">The history row.</param> /// <returns> /// A string containg the SQL statement. /// </returns> public virtual string GetInsertScript(EntityPlugin plugin, HistoryRow historyRow) { var stringTypeMapping = Dependencies.TypeMappingSource.GetMapping(typeof(string)); var migrationIdColumn = Dependencies.SqlGenerationHelper .DelimitIdentifier(nameof(PluginHistoryRow.MigrationId)); var productVersionColumn = Dependencies.SqlGenerationHelper .DelimitIdentifier(nameof(PluginHistoryRow.ProductVersion)); var pluginColumn = Dependencies.SqlGenerationHelper .DelimitIdentifier(nameof(PluginHistoryRow.Plugin)); var tableName = Dependencies.SqlGenerationHelper .DelimitIdentifier(TableName); var pluginName = stringTypeMapping.GenerateSqlLiteral(plugin.Identifier); var migrationId = stringTypeMapping.GenerateSqlLiteral(historyRow.MigrationId); var productVersion = stringTypeMapping.GenerateSqlLiteral(historyRow.ProductVersion); return($"INSERT INTO {tableName} ({pluginColumn}, {migrationIdColumn}, {productVersionColumn}) VALUES ({pluginName}, {migrationId}, {productVersion})"); }
public HistoryRowChangeEvent(HistoryRow row, global::System.Data.DataRowAction action) { this.eventRow = row; this.eventAction = action; }
public string GetInsertScript(HistoryRow row) => throw new NotImplementedException();
public string GetInsertScript(HistoryRow row) => null;
public void RemoveHistoryRow(HistoryRow row) { this.Rows.Remove(row); }
public void AddHistoryRow(HistoryRow row) { this.Rows.Add(row); }
public Asset_InfoRow AddAsset_InfoRow(HistoryRow parentHistoryRowByFK_History_Asset_Info, string Asset_Name, string Asset_Acquisition_Cost, string Asset_Depreciation_Years, string Asset_Useful_Life, string Asset_Category) { Asset_InfoRow rowAsset_InfoRow = ((Asset_InfoRow)(this.NewRow())); object[] columnValuesArray = new object[] { null, Asset_Name, Asset_Acquisition_Cost, Asset_Depreciation_Years, Asset_Useful_Life, Asset_Category}; if ((parentHistoryRowByFK_History_Asset_Info != null)) { columnValuesArray[0] = parentHistoryRowByFK_History_Asset_Info[0]; } rowAsset_InfoRow.ItemArray = columnValuesArray; this.Rows.Add(rowAsset_InfoRow); return rowAsset_InfoRow; }
public HistoryRowChangeEvent(HistoryRow row, global::System.Data.DataRowAction action) { this.eventRow = row; this.eventAction = action; }
public void RemoveHistoryRow(HistoryRow row) { this.Rows.Remove(row); }