public void TestAdd() { byte[] output = { 11, 12 }; byte[] error = { 13, 14 }; string[] expectedCachedCommand = { "git command" }; _cache.Add("git command", output, error); Assert.IsTrue(expectedCachedCommand.SequenceEqual(_cache.GetCachedCommands())); }
/// <summary> /// Initializes a new instance of the <see cref="Command"/> class. /// </summary> /// <param name="commandName">The command name used for retreiving command in Xaml.</param> public Command(string commandName) { if (CommandCache.ContainsKey(commandName)) { throw new ArgumentException("A command with the same name '{0}' is already registered.", commandName); } Name = commandName; CommandCache.Add(commandName, this); }
public override ICommand CreateUpdateByIdCommand(object data, Type type) { string uniqueId = "80065C07-24CD-40E8-9642-A46085892480"; if (!CommandCache.ContainsKey(string.Format(CACHE_KEY, uniqueId, type.FullName))) { Command sqlCommand = _CreateUpdateByIdCommand(data, type); CommandCache.Add(string.Format(CACHE_KEY, uniqueId, type.FullName), sqlCommand); } return(CommandCache[string.Format(CACHE_KEY, uniqueId, type.FullName)]); }
public override ICommand CreateUpdateByKeyCommand(object data, Type type) { string uniqueId = "34FD7357-8114-4f36-825E-77C3F819B39F"; if (!CommandCache.ContainsKey(string.Format(CACHE_KEY, uniqueId, type.FullName))) { Command sqlCommand = _CreateUpdateByKeyCommand(data, type); CommandCache.Add(string.Format(CACHE_KEY, uniqueId, type.FullName), sqlCommand); } return(CommandCache[string.Format(CACHE_KEY, uniqueId, type.FullName)]); }
/// <summary> /// Initializes a new instance of the <see cref="Command"/> class. /// </summary> /// <param name="commandName">The command name used for retreiving command in Xaml.</param> public Command(string commandName) { if (CommandCache.ContainsKey(commandName)) { // Not throwing exception to prevent error in blend return; //throw new ArgumentException(Resource.CommandNameAlreadyRegistered, commandName); } Name = commandName; CommandCache.Add(commandName, this); }
public override ICommand CreateCountCommand <T>() { Type typeT = typeof(T); string uniqueId = "1801F51F-A4EC-4A78-8AE8-BCB30402E4B5"; if (!CommandCache.ContainsKey(string.Format(CACHE_KEY, uniqueId, typeT.FullName))) { Anito.Data.Schema.TypeTable schemaTable = Provider.GetSchema(typeT); Command sqlCommand = (Command)CreateCountCommand(schemaTable.ViewSource); CommandCache.Add(string.Format(CACHE_KEY, uniqueId, typeT.FullName), sqlCommand); } return(CommandCache[string.Format(CACHE_KEY, uniqueId, typeT.FullName)]); }
public override ICommand CreateDeleteByKeyCommand(object data, Type type) { string uniqueId = "92C92A43-D467-4931-8C12-F26AA936E7D7"; if (!CommandCache.ContainsKey(string.Format(CACHE_KEY, uniqueId, type.FullName))) { Anito.Data.Schema.TypeTable schemaTable = Provider.GetSchema(type); Command sqlCommand = _CreateDeletebyKeyCommand(data, schemaTable); CommandCache.Add(string.Format(CACHE_KEY, uniqueId, type.FullName), sqlCommand); } return(CommandCache[string.Format(CACHE_KEY, uniqueId, type.FullName)]); }
public override ICommand CreateDeleteByIdCommand(object data, Type type) { string uniqueId = "F58B3FAE-6E43-4B39-9850-8E2D4EC63419"; if (!CommandCache.ContainsKey(string.Format(CACHE_KEY, uniqueId, type.FullName))) { Anito.Data.Schema.TypeTable schemaTable = Provider.GetSchema(type); Command sqlCommand = _CreateDeletebyIdCommand(data, schemaTable); CommandCache.Add(string.Format(CACHE_KEY, uniqueId, type.FullName), sqlCommand); } return(CommandCache[string.Format(CACHE_KEY, uniqueId, type.FullName)]); }
public void GetOutput_with_cache_hit() { const string arguments = "abc"; var cache = new CommandCache(); cache.Add( arguments, output: GitModule.SystemEncoding.GetBytes("Hello"), error: GitModule.SystemEncoding.GetBytes("World!")); var output = _executable.GetOutput(arguments, cache: cache); Assert.AreEqual($"Hello{Environment.NewLine}World!", output); // Cache should still have a single item Assert.AreEqual(1, cache.GetCachedCommands().Count); }
/// <summary> /// Handles enter /// </summary> private async Task HandleEnter() { var command = Sb.ToString(); //cache the executing command if (!string.IsNullOrWhiteSpace(command) && (CommandCache.Count == 0 || CommandCache[CommandCache.Count - 1] != command)) { CommandCache.Add(command); } ResetPreviousCommandCacheIndex(); //finalise the line with Prompt and command as it was... Console.Write(Environment.NewLine); //and redirect the command handling to the cmd handler try { await CmdHandler.HandleCommand(command); } catch (Exception ex) { Console.WriteLine(); ConsoleEx.WriteErr("Uncaught exception occurred:"); while (ex != null) { ConsoleEx.WriteLine(ex.Message, ConsoleColor.DarkMagenta); ConsoleEx.WriteLine(new string('-', 25), ConsoleColor.DarkMagenta); ex = ex.InnerException; } Console.WriteLine(); } //check if should continue watching cmd or can quit if (!CmdHandler.Exit()) { //wipe out string builder Sb.Clear(); PrintPrompt(); } }
public override ICommand CreateGetListCommand <T>(IFilterCriteria criteria) { Type typeT = typeof(T); string uniqueId = "232FDED0-6C97-40B4-930F-FC190124D181"; if (!CommandCache.ContainsKey(string.Format(CACHE_KEY, uniqueId, typeT.FullName))) { Anito.Data.Schema.TypeTable schemaTable = Provider.GetSchema(typeT); Command sqlCommand = new Command(); sqlCommand.SqlCommand.CommandText = string.Format( "{0} {1} {2} {3}", SELECT, SelectColumnsStatement(typeT), FROM, schemaTable.ViewSource ); CommandCache.Add(string.Format(CACHE_KEY, uniqueId, typeT.FullName), sqlCommand); } return(CommandCache[string.Format(CACHE_KEY, uniqueId, typeT.FullName)]); }
public override ICommand CreateGetObjectByKeyCommand <T>() { Type typeT = typeof(T); string uniqueId = "4F9C6FBE-2971-46A8-A367-B28AB5F65895"; if (!CommandCache.ContainsKey(string.Format(CACHE_KEY, uniqueId, typeT.FullName))) { Anito.Data.Schema.TypeTable schemaTable = Provider.GetSchema(typeT); Command sqlCommand = new Command(); var keyList = from column in schemaTable where column.IsPrimaryKey select column; if (keyList.Count() < 1) { throw new TypeNoKeyException(typeof(T)); } StringBuilder paramBuilder = new StringBuilder(); foreach (Anito.Data.Schema.TypeColumn column in keyList) { if (paramBuilder.Length > 0) { paramBuilder.Append(string.Format("{0}{1}{2}", SPACE, AND, SPACE)); } paramBuilder.Append(string.Format("{0} = {1}{2}", column.Name, PARAM_IDENTIFIER, column.Name)); sqlCommand.AddParam(string.Format("{0}{1}", PARAM_IDENTIFIER, column.Name)); } sqlCommand.SqlCommand.CommandText = string.Format("{0} {1} {2} {3} {4} {5}", SELECT, SelectColumnsStatement(typeT), FROM, schemaTable.ViewSource, WHERE, paramBuilder.ToString()); CommandCache.Add(string.Format(CACHE_KEY, uniqueId, typeT.FullName), sqlCommand); } return(CommandCache[string.Format(CACHE_KEY, uniqueId, typeT.FullName)]); }
/// <summary> /// Builds the commands. /// </summary> protected override void BuildCommands() { CommandCache.Add(CommandStringTypes.DeleteFromErrorTracking, $"delete from {TableNameHelper.ErrorTrackingName} where queueID = @QueueID"); CommandCache.Add(CommandStringTypes.DeleteFromQueue, $"delete from {TableNameHelper.QueueName} where queueID = @QueueID"); CommandCache.Add(CommandStringTypes.DeleteFromMetaData, $"delete from {TableNameHelper.MetaDataName} where queueID = @QueueID"); CommandCache.Add(CommandStringTypes.DeleteFromMetaDataErrors, $"delete from {TableNameHelper.MetaDataErrorsName} where queueID = @QueueID"); CommandCache.Add(CommandStringTypes.DeleteFromStatus, $"delete from {TableNameHelper.StatusName} where queueID = @QueueID"); CommandCache.Add(CommandStringTypes.SaveConfiguration, $"insert into {TableNameHelper.ConfigurationName} (Configuration) Values (@Configuration)"); CommandCache.Add(CommandStringTypes.UpdateStatusRecord, $"update {TableNameHelper.StatusName} set status = @Status where queueID = @QueueID"); CommandCache.Add(CommandStringTypes.ResetHeartbeat, $"update {TableNameHelper.MetaDataName} set status = @Status, heartbeat = null where queueID = @QueueID and status = @SourceStatus and HeartBeat = @HeartBeat"); CommandCache.Add(CommandStringTypes.SendHeartBeat, $"Update {TableNameHelper.MetaDataName} set HeartBeat = @date where status = @Status and queueID = @QueueID"); CommandCache.Add(CommandStringTypes.InsertMessageBody, $"Insert into {TableNameHelper.QueueName} (Body, Headers) VALUES (@Body, @Headers); "); CommandCache.Add(CommandStringTypes.UpdateErrorCount, $"update {TableNameHelper.ErrorTrackingName} set retrycount = retrycount + 1 where queueid = @QueueID and ExceptionType = @ExceptionType"); CommandCache.Add(CommandStringTypes.InsertErrorCount, $"Insert into {TableNameHelper.ErrorTrackingName} (QueueID,ExceptionType, RetryCount) VALUES (@QueueID,@ExceptionType,1)"); CommandCache.Add(CommandStringTypes.GetHeartBeatExpiredMessageIds, $"select {TableNameHelper.MetaDataName}.queueid, heartbeat, headers from {TableNameHelper.MetaDataName} inner join {TableNameHelper.QueueName} on {TableNameHelper.QueueName}.queueid = {TableNameHelper.MetaDataName}.queueid where status = @Status and heartbeat is not null and heartbeat < @Time"); CommandCache.Add(CommandStringTypes.GetErrorRecordExists, $"Select 1 from {TableNameHelper.ErrorTrackingName} where queueid = @QueueID and ExceptionType = @ExceptionType"); CommandCache.Add(CommandStringTypes.GetErrorRetryCount, $"Select RetryCount from {TableNameHelper.ErrorTrackingName} where queueid = @QueueID and ExceptionType = @ExceptionType"); CommandCache.Add(CommandStringTypes.GetMessageErrors, $"Select ExceptionType, RetryCount from {TableNameHelper.ErrorTrackingName} where queueid = @QueueID"); CommandCache.Add(CommandStringTypes.GetConfiguration, $"select Configuration from {TableNameHelper.ConfigurationName}"); CommandCache.Add(CommandStringTypes.GetTableExists, "SELECT 1 FROM sqlite_master WHERE type='table' AND name=@Table;"); CommandCache.Add(CommandStringTypes.GetPendingExcludeDelayCount, $"Select count(queueid) from {TableNameHelper.MetaDataName} where status = {Convert.ToInt32(QueueStatuses.Waiting)} AND (QueueProcessTime < @CurrentDateTime)"); CommandCache.Add(CommandStringTypes.GetPendingCount, $"Select count(queueid) from {TableNameHelper.StatusName} where status = {Convert.ToInt32(QueueStatuses.Waiting)} "); CommandCache.Add(CommandStringTypes.GetWorkingCount, $"Select count(queueid) from {TableNameHelper.StatusName} where status = {Convert.ToInt32(QueueStatuses.Processing)} "); CommandCache.Add(CommandStringTypes.GetErrorCount, $"Select count(queueid) from {TableNameHelper.StatusName} where status = {Convert.ToInt32(QueueStatuses.Error)} "); CommandCache.Add(CommandStringTypes.GetPendingDelayCount, $"Select count(queueid) from {TableNameHelper.MetaDataName} where status = {Convert.ToInt32(QueueStatuses.Waiting)} AND (QueueProcessTime > @CurrentDateTime) "); CommandCache.Add(CommandStringTypes.GetJobLastKnownEvent, $"Select JobEventTime from {TableNameHelper.JobTableName} where JobName = @JobName"); CommandCache.Add(CommandStringTypes.SetJobLastKnownEvent, $"UPDATE {TableNameHelper.JobTableName} SET JobEventTime = @JobEventTime, JobScheduledTime = @JobScheduledTime WHERE JobName=@JobName; INSERT OR IGNORE INTO {TableNameHelper.JobTableName}(JobName, JobEventTime, JobScheduledTime) VALUES(@JobName, @JobEventTime, @JobScheduledTime);"); CommandCache.Add(CommandStringTypes.GetJobLastScheduleTime, $"Select JobScheduledTime from {TableNameHelper.JobTableName} where JobName = @JobName"); CommandCache.Add(CommandStringTypes.DoesJobExist, $"Select Status from {TableNameHelper.StatusName} where JobName = @JobName"); CommandCache.Add(CommandStringTypes.GetJobId, $"Select QueueID from {TableNameHelper.StatusName} where JobName = @JobName"); CommandCache.Add(CommandStringTypes.FindExpiredRecordsToDelete, $"select queueid from {TableNameHelper.MetaDataName} where @CurrentDateTime > ExpirationTime"); CommandCache.Add(CommandStringTypes.FindExpiredRecordsWithStatusToDelete, $"select queueid from {TableNameHelper.MetaDataName} where status = {Convert.ToInt16(QueueStatuses.Waiting)} and @CurrentDateTime > ExpirationTime"); CommandCache.Add(CommandStringTypes.FindErrorRecordsToDelete, $"select queueid from {TableNameHelper.MetaDataErrorsName} where @CurrentDateTime > LastExceptionDate"); CommandCache.Add(CommandStringTypes.GetColumnNamesFromTable, "PRAGMA table_info('{0}')"); CommandCache.Add(CommandStringTypes.DeleteTable, "drop table {0}"); CommandCache.Add(CommandStringTypes.GetHeader, $"select headers from {TableNameHelper.QueueName} where queueID = @queueID"); }
/// <inheritdoc /> protected override void BuildCommands() { CommandCache.Add(CommandStringTypes.DeleteFromErrorTracking, $"delete from {TableNameHelper.ErrorTrackingName} where queueID = @queueID"); CommandCache.Add(CommandStringTypes.DeleteFromQueue, $"delete from {TableNameHelper.QueueName} where queueID = @queueID"); CommandCache.Add(CommandStringTypes.DeleteFromMetaData, $"delete from {TableNameHelper.MetaDataName} where queueID = @queueID"); CommandCache.Add(CommandStringTypes.DeleteFromMetaDataErrors, $"delete from {TableNameHelper.MetaDataErrorsName} where queueID = @queueID"); CommandCache.Add(CommandStringTypes.DeleteFromStatus, $"delete from {TableNameHelper.StatusName} where queueID = @queueID"); CommandCache.Add(CommandStringTypes.SaveConfiguration, $"insert into {TableNameHelper.ConfigurationName} (Configuration) Values (@Configuration)"); CommandCache.Add(CommandStringTypes.UpdateStatusRecord, $"update {TableNameHelper.StatusName} set status = @status where queueID = @queueID"); CommandCache.Add(CommandStringTypes.ResetHeartbeat, $"update {TableNameHelper.MetaDataName} set status = @Status, heartbeat = null where queueID = @QueueID and status = @SourceStatus and HeartBeat = @HeartBeat"); CommandCache.Add(CommandStringTypes.SendHeartBeat, $"Update {TableNameHelper.MetaDataName} set HeartBeat = @date where status = @status and queueID = @queueID"); CommandCache.Add(CommandStringTypes.InsertMessageBody, $"Insert into {TableNameHelper.QueueName} (Body, Headers) VALUES (@Body, @Headers); SELECT lastval(); "); CommandCache.Add(CommandStringTypes.UpdateErrorCount, $"update {TableNameHelper.ErrorTrackingName} set retrycount = retrycount + 1 where queueid = @queueid and ExceptionType = @ExceptionType"); CommandCache.Add(CommandStringTypes.InsertErrorCount, $"Insert into {TableNameHelper.ErrorTrackingName} (QueueID,ExceptionType, RetryCount) VALUES (@QueueID,@ExceptionType,1)"); CommandCache.Add(CommandStringTypes.GetHeartBeatExpiredMessageIds, $"select {TableNameHelper.MetaDataName}.queueid, heartbeat, headers from {TableNameHelper.MetaDataName} inner join {TableNameHelper.QueueName} on {TableNameHelper.QueueName}.queueid = {TableNameHelper.MetaDataName}.queueid where status = @status and heartbeat is not null and heartbeat < @time FOR UPDATE SKIP LOCKED"); CommandCache.Add(CommandStringTypes.GetColumnNamesFromTable, "select column_name FROM information_schema.columns WHERE table_schema = 'public' AND table_name = @TableName"); CommandCache.Add(CommandStringTypes.GetErrorRecordExists, $"Select 1 from {TableNameHelper.ErrorTrackingName} where queueid = @queueid and ExceptionType = @ExceptionType"); CommandCache.Add(CommandStringTypes.GetErrorRetryCount, $"Select RetryCount from {TableNameHelper.ErrorTrackingName} where queueid = @queueid and ExceptionType = @ExceptionType"); CommandCache.Add(CommandStringTypes.GetMessageErrors, $"Select ExceptionType, RetryCount from {TableNameHelper.ErrorTrackingName} where queueid = @queueid"); CommandCache.Add(CommandStringTypes.GetConfiguration, $"select Configuration from {TableNameHelper.ConfigurationName}"); CommandCache.Add(CommandStringTypes.GetTableExists, "SELECT 1 FROM pg_catalog.pg_class c JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace WHERE n.nspname = 'public' AND c.relname = @Table;"); CommandCache.Add(CommandStringTypes.GetUtcDate, "select now() at time zone 'utc'"); CommandCache.Add(CommandStringTypes.GetPendingExcludeDelayCount, $"Select count(queueid) from {TableNameHelper.MetaDataName} where status = {Convert.ToInt32(QueueStatuses.Waiting)} AND (QueueProcessTime < @CurrentDate)"); CommandCache.Add(CommandStringTypes.GetPendingCount, $"Select count(queueid) from {TableNameHelper.StatusName} where status = {Convert.ToInt32(QueueStatuses.Waiting)} "); CommandCache.Add(CommandStringTypes.GetWorkingCount, $"Select count(queueid) from {TableNameHelper.StatusName} where status = {Convert.ToInt32(QueueStatuses.Processing)} "); CommandCache.Add(CommandStringTypes.GetErrorCount, $"Select count(queueid) from {TableNameHelper.StatusName} where status = {Convert.ToInt32(QueueStatuses.Error)} "); CommandCache.Add(CommandStringTypes.GetPendingDelayCount, $"Select count(queueid) from {TableNameHelper.MetaDataName} where status = {Convert.ToInt32(QueueStatuses.Waiting)} AND (QueueProcessTime > @CurrentDate) "); CommandCache.Add(CommandStringTypes.GetJobLastKnownEvent, $"Select JobEventTime from {TableNameHelper.JobTableName} where JobName = @JobName"); CommandCache.Add(CommandStringTypes.SetJobLastKnownEvent, $"Insert into {TableNameHelper.JobTableName} (JobName, JobEventTime, JobScheduledTime) values (@JobName, @JobEventTime, @JobScheduledTime) on conflict (JobName) do update set (JobEventTime, JobScheduledTime) = (@JobEventTime, @JobScheduledTime) where {TableNameHelper.JobTableName}.JobName = @JobName"); CommandCache.Add(CommandStringTypes.DoesJobExist, $"Select Status from {TableNameHelper.StatusName} where JobName = @JobName"); CommandCache.Add(CommandStringTypes.GetJobId, $"Select QueueID from {TableNameHelper.StatusName} where JobName = @JobName"); CommandCache.Add(CommandStringTypes.GetJobLastScheduleTime, $"Select JobScheduledTime from {TableNameHelper.JobTableName} where JobName = @JobName"); CommandCache.Add(CommandStringTypes.FindExpiredRecordsWithStatusToDelete, $"select queueid from {TableNameHelper.MetaDataName} where status = {Convert.ToInt16(QueueStatuses.Waiting)} and @CurrentDate > ExpirationTime FOR UPDATE SKIP LOCKED"); CommandCache.Add(CommandStringTypes.FindErrorRecordsToDelete, $"select queueid from {TableNameHelper.MetaDataErrorsName} where @CurrentDate > lastexceptiondate FOR UPDATE SKIP LOCKED"); CommandCache.Add(CommandStringTypes.FindExpiredRecordsToDelete, $"select queueid from {TableNameHelper.MetaDataName} where @CurrentDate > ExpirationTime FOR UPDATE SKIP LOCKED"); CommandCache.Add(CommandStringTypes.DeleteTable, "DROP TABLE IF EXISTS {0} CASCADE;"); CommandCache.Add(CommandStringTypes.GetHeader, $"select headers from {TableNameHelper.QueueName} where queueID = @queueID"); }
public override ICommand CreateGetListByPageCommand <T>() { Type typeT = typeof(T); string uniqueId = "D89646AE-F93B-4D59-9A0C-7AF5A6B79F5D"; if (!CommandCache.ContainsKey(string.Format(CACHE_KEY, uniqueId, typeT.FullName))) { Anito.Data.Schema.TypeTable schemaTable = Provider.GetSchema(typeT); Command sqlCommand = new Command(); string tempTable = SHARP + "D89646AE" + schemaTable.ViewSource; StringBuilder columnBuilder = new StringBuilder(); StringBuilder keyBuilder = new StringBuilder(); StringBuilder keyCompareBuilder = new StringBuilder(); foreach (Anito.Data.Schema.TypeColumn column in schemaTable) { if (columnBuilder.Length > 0) { columnBuilder.Append(COMMA + SPACE); } columnBuilder.Append(schemaTable.ViewSource + DOT + column.Name); if (column.IsPrimaryKey) { if (keyBuilder.Length > 0) { keyBuilder.Append(COMMA + SPACE); } keyBuilder.Append(column.Name); if (keyCompareBuilder.Length > 0) { keyCompareBuilder.Append(SPACE + AND + SPACE); } keyCompareBuilder.Append(tempTable + DOT + column.Name); keyCompareBuilder.Append(SPACE + EQUALS + SPACE); keyCompareBuilder.Append(schemaTable.ViewSource + DOT + column.Name); } } sqlCommand.SqlCommand.CommandText = string.Format(GET_TABLE_BY_PAGE, tempTable, tempTable, keyBuilder.ToString(), keyBuilder.ToString(), tempTable, schemaTable.ViewSource, SelectColumnsStatement(typeT), schemaTable.ViewSource, tempTable, keyCompareBuilder.ToString(), tempTable, tempTable); sqlCommand.AddParam(string.Format("{0}{1}", PARAM_IDENTIFIER, PAGE)); sqlCommand.AddParam(string.Format("{0}{1}", PARAM_IDENTIFIER, PAGE_SIZE)); CommandCache.Add(string.Format(CACHE_KEY, uniqueId, typeT.FullName), sqlCommand); } return(CommandCache[string.Format(CACHE_KEY, uniqueId, typeT.FullName)]); }
public override ICommand CreateInsertCommand(object data) { Type typeT = data.GetType(); string uniqueId = "26ABBE10-3D2A-40be-ABAC-F92EF9040608"; if (!CommandCache.ContainsKey(string.Format(CACHE_KEY, uniqueId, typeT.FullName))) { Anito.Data.Schema.TypeTable schemaTable = Provider.GetSchema(typeT); Command sqlCommand = new Command(); StringBuilder commandTextBuilder = new StringBuilder(); StringBuilder paramBuilder = new StringBuilder(); StringBuilder columnBuilder = new StringBuilder(); TypeColumn identityColumn = null; foreach (TypeColumn column in (from col in schemaTable where !col.ViewOnly select col)) { if (column.IsIdentity) { identityColumn = column; continue; } if (sqlCommand.Parameters.ContainsKey(string.Format("{0}{1}", PARAM_IDENTIFIER, column.Name))) { continue; } if (columnBuilder.Length > 0 && paramBuilder.Length > 0) { columnBuilder.Append(COMMA); paramBuilder.Append(COMMA); } columnBuilder.Append(column.Name); paramBuilder.Append(PARAM_IDENTIFIER + column.Name); if (!sqlCommand.Parameters.ContainsKey(string.Format("{0}{1}", PARAM_IDENTIFIER, column.Name))) { sqlCommand.AddParam(string.Format("{0}{1}", PARAM_IDENTIFIER, column.Name)); } } commandTextBuilder.Append(string.Format("{0} {1} {2}", INSERT, INTO, schemaTable.UpdateSource)); commandTextBuilder.Append(OPEN_PARENTHESES); commandTextBuilder.Append(columnBuilder.ToString()); commandTextBuilder.Append(CLOSE_PARENTHESES); commandTextBuilder.Append(SPACE); commandTextBuilder.Append(VALUES + OPEN_PARENTHESES); commandTextBuilder.Append(paramBuilder.ToString()); commandTextBuilder.Append(CLOSE_PARENTHESES + SEMI_COLON); if (identityColumn != null) { commandTextBuilder.Append(string.Format("SELECT {0} FROM {1} WHERE {2} = (SELECT IDENT_CURRENT('{3}'));" , schemaTable.ColumnList , schemaTable.ViewSource , identityColumn.Name , schemaTable.ViewSource)); } sqlCommand.SqlCommand.CommandText = commandTextBuilder.ToString(); CommandCache.Add(string.Format(CACHE_KEY, uniqueId, typeT.FullName), sqlCommand); } return(CommandCache[string.Format(CACHE_KEY, uniqueId, typeT.FullName)]); }
public StaticCommand(string commandName) { CommandName = commandName; CommandCache.Add(commandName, this); }
/// <summary> /// Builds the commands. /// </summary> protected override void BuildCommands() { CommandCache.Add(CommandStringTypes.DeleteFromErrorTracking, $"delete from {TableNameHelper.ErrorTrackingName} where queueID = @queueID"); CommandCache.Add(CommandStringTypes.DeleteFromQueue, $"delete from {TableNameHelper.QueueName} where queueID = @queueID"); CommandCache.Add(CommandStringTypes.DeleteFromMetaData, $"delete from {TableNameHelper.MetaDataName} where queueID = @queueID"); CommandCache.Add(CommandStringTypes.DeleteFromMetaDataErrors, $"delete from {TableNameHelper.MetaDataErrorsName} where queueID = @queueID"); CommandCache.Add(CommandStringTypes.DeleteFromStatus, $"delete from {TableNameHelper.StatusName} where queueID = @queueID"); CommandCache.Add(CommandStringTypes.SaveConfiguration, $"insert into {TableNameHelper.ConfigurationName} (Configuration) Values (@Configuration)"); CommandCache.Add(CommandStringTypes.UpdateStatusRecord, $"update {TableNameHelper.StatusName} set status = @status where queueID = @queueID"); CommandCache.Add(CommandStringTypes.ResetHeartbeat, $"update {TableNameHelper.MetaDataName} with (updlock, readpast, rowlock) set status = @Status, heartbeat = null where queueID = @QueueID and status = @SourceStatus and HeartBeat = @HeartBeat"); CommandCache.Add(CommandStringTypes.SendHeartBeat, $"declare @date as datetime set @date = GETUTCDATE() Update {TableNameHelper.MetaDataName} set HeartBeat = @date where status = @status and queueID = @queueID select @date"); CommandCache.Add(CommandStringTypes.InsertMessageBody, $"Insert into {TableNameHelper.QueueName} (Body, Headers) VALUES (@Body, @Headers) select SCOPE_IDENTITY() "); CommandCache.Add(CommandStringTypes.UpdateErrorCount, $"update {TableNameHelper.ErrorTrackingName} set retrycount = retrycount + 1 where queueid = @queueid and ExceptionType = @ExceptionType"); CommandCache.Add(CommandStringTypes.InsertErrorCount, $"Insert into {TableNameHelper.ErrorTrackingName} (QueueID,ExceptionType, RetryCount) VALUES (@QueueID,@ExceptionType,1)"); CommandCache.Add(CommandStringTypes.GetHeartBeatExpiredMessageIds, $"select {TableNameHelper.MetaDataName}.queueid, heartbeat, headers from {TableNameHelper.MetaDataName} with (updlock, readpast, rowlock) inner join {TableNameHelper.QueueName} on {TableNameHelper.QueueName}.queueid = {TableNameHelper.MetaDataName}.queueid where status = @status and heartbeat is not null and (DATEDIFF(SECOND, heartbeat, GETUTCDATE()) > @time)"); CommandCache.Add(CommandStringTypes.GetColumnNamesFromTable, "SELECT c.name FROM sys.columns c WHERE c.object_id = OBJECT_ID(@TableName)"); CommandCache.Add(CommandStringTypes.GetErrorRecordExists, $"Select 1 from {TableNameHelper.ErrorTrackingName} where queueid = @queueid and ExceptionType = @ExceptionType"); CommandCache.Add(CommandStringTypes.GetErrorRetryCount, $"Select RetryCount from {TableNameHelper.ErrorTrackingName} where queueid = @queueid and ExceptionType = @ExceptionType"); CommandCache.Add(CommandStringTypes.GetMessageErrors, $"Select ExceptionType, RetryCount from {TableNameHelper.ErrorTrackingName} where queueid = @QueueID"); CommandCache.Add(CommandStringTypes.GetConfiguration, $"select Configuration from {TableNameHelper.ConfigurationName}"); CommandCache.Add(CommandStringTypes.GetTableExists, $"SELECT 1 FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_CATALOG = @Database AND TABLE_NAME = @Table and TABLE_SCHEMA = '{_schema.Schema}'"); CommandCache.Add(CommandStringTypes.GetUtcDate, "select getutcdate()"); CommandCache.Add(CommandStringTypes.GetPendingExcludeDelayCount, $"Select count(queueid) from {TableNameHelper.MetaDataName} with (NOLOCK) where status = {Convert.ToInt32(QueueStatuses.Waiting)} AND (QueueProcessTime < getutcdate())"); CommandCache.Add(CommandStringTypes.GetPendingCount, $"Select count(queueid) from {TableNameHelper.StatusName} with (NOLOCK) where status = {Convert.ToInt32(QueueStatuses.Waiting)} "); CommandCache.Add(CommandStringTypes.GetWorkingCount, $"Select count(queueid) from {TableNameHelper.StatusName} with (NOLOCK) where status = {Convert.ToInt32(QueueStatuses.Processing)} "); CommandCache.Add(CommandStringTypes.GetErrorCount, $"Select count(queueid) from {TableNameHelper.StatusName} with (NOLOCK) where status = {Convert.ToInt32(QueueStatuses.Error)} "); CommandCache.Add(CommandStringTypes.GetPendingDelayCount, $"Select count(queueid) from {TableNameHelper.MetaDataName} with (NOLOCK) where status = {Convert.ToInt32(QueueStatuses.Waiting)} AND (QueueProcessTime > getutcdate()) "); CommandCache.Add(CommandStringTypes.GetJobLastKnownEvent, $"Select JobEventTime from {TableNameHelper.JobTableName} where JobName = @JobName"); CommandCache.Add(CommandStringTypes.SetJobLastKnownEvent, $"MERGE {TableNameHelper.JobTableName} USING(VALUES(@JobName, @JobEventTime, @JobScheduledTime)) AS updateJob(JobName, JobEventTime, JobScheduledTime) ON {TableNameHelper.JobTableName}.JobName = updateJob.JobName WHEN MATCHED THEN UPDATE SET JobEventTime = updateJob.JobEventTime, JobScheduledTime = updateJob.JobScheduledTime WHEN NOT MATCHED THEN INSERT(JobName, JobEventTime, JobScheduledTime) VALUES(JobName, JobEventTime, JobScheduledTime); "); CommandCache.Add(CommandStringTypes.DoesJobExist, $"Select Status from {TableNameHelper.StatusName} where JobName = @JobName"); CommandCache.Add(CommandStringTypes.GetJobId, $"Select QueueID from {TableNameHelper.StatusName} where JobName = @JobName"); CommandCache.Add(CommandStringTypes.GetJobLastScheduleTime, $"Select JobScheduledTime from {TableNameHelper.JobTableName} where JobName = @JobName"); CommandCache.Add(CommandStringTypes.FindExpiredRecordsWithStatusToDelete, $"select queueid from {TableNameHelper.MetaDataName} with (updlock, readpast, rowlock) where status = {Convert.ToInt16(QueueStatuses.Waiting)} and GETUTCDate() > ExpirationTime"); CommandCache.Add(CommandStringTypes.FindErrorRecordsToDelete, $"select queueid from {TableNameHelper.MetaDataErrorsName} with (updlock, readpast, rowlock) where @CurrentDate > lastexceptiondate"); CommandCache.Add(CommandStringTypes.FindExpiredRecordsToDelete, $"select queueid from {TableNameHelper.MetaDataName} with (updlock, readpast, rowlock) where GETUTCDate() > ExpirationTime"); CommandCache.Add(CommandStringTypes.DeleteTable, "IF OBJECT_ID('{0}', 'U') IS NOT NULL DROP TABLE {0};"); CommandCache.Add(CommandStringTypes.GetHeader, $"select headers from {TableNameHelper.QueueName} WITH (NOLOCK) where queueid = @queueid "); }