public RevaleeTask GetTask(Guid callbackId) { if (_EseInstance == null) { throw new InvalidOperationException("Storage provider has not been opened."); } EseConnection connection = _ConnectionPool.OpenConnection(); try { using (Table table = connection.GetTable(_TableNameCallbacks, OpenTableGrbit.Updatable)) { IDictionary <string, JET_COLUMNID> columnIds = connection.GetSchema(_TableNameCallbacks); Api.JetSetCurrentIndex(connection, table, null); Api.MakeKey(connection, table, callbackId, MakeKeyGrbit.NewKey); if (Api.TrySeek(connection, table, SeekGrbit.SeekEQ)) { Guid? storedCallbackId = Api.RetrieveColumnAsGuid(connection, table, columnIds[_ColumnNameCallbackId]); DateTime?createdTime = Api.RetrieveColumnAsDateTime(connection, table, columnIds[_ColumnNameCreatedTime]); DateTime?callbackTime = Api.RetrieveColumnAsDateTime(connection, table, columnIds[_ColumnNameCallbackTime]); string callbackUrl = Api.RetrieveColumnAsString(connection, table, columnIds[_ColumnNameCallbackUrl]); int? attemptsRemainingColumn = Api.RetrieveColumnAsInt32(connection, table, columnIds[_ColumnNameAttemptsRemaining]); string authorizationCipher = Api.RetrieveColumnAsString(connection, table, columnIds[_ColumnNameAuthorizationCipher]); Uri callbackUri = null; if (callbackTime.HasValue && Uri.TryCreate(callbackUrl, UriKind.Absolute, out callbackUri) && createdTime.HasValue && storedCallbackId.HasValue && attemptsRemainingColumn.HasValue) { RevaleeTask revivedTask = RevaleeTask.Revive( DateTime.SpecifyKind(callbackTime.Value, DateTimeKind.Utc), callbackUri, DateTime.SpecifyKind(createdTime.Value, DateTimeKind.Utc), storedCallbackId.Value, attemptsRemainingColumn.Value, string.IsNullOrEmpty(authorizationCipher) ? null : authorizationCipher); return(revivedTask); } } } return(null); } finally { _ConnectionPool.CloseConnection(connection); } }
public void Open(string connectionString) { if (_EseInstance == null) { if (string.IsNullOrWhiteSpace(connectionString)) { connectionString = ApplicationFolderHelper.ApplicationFolderName; } this._DatabasePath = Path.Combine(connectionString, Path.ChangeExtension(_DatabaseName, _StorageEngineBaseName)); _EseInstance = new Instance(_DatabaseName); _EseInstance.Parameters.CreatePathIfNotExist = true; _EseInstance.Parameters.CircularLog = true; _EseInstance.Parameters.Recovery = true; _EseInstance.Parameters.BaseName = _StorageEngineBaseName; _EseInstance.Parameters.MaxSessions = _ConnectionPoolSize * 2; _EseInstance.Parameters.NoInformationEvent = true; if (!string.IsNullOrEmpty(connectionString)) { _EseInstance.Parameters.SystemDirectory = connectionString; _EseInstance.Parameters.LogFileDirectory = connectionString; _EseInstance.Parameters.TempDirectory = connectionString; _EseInstance.Parameters.AlternateDatabaseRecoveryDirectory = connectionString; } InitGrbit grbit = default(InitGrbit); if (EsentVersion.SupportsWindows7Features) { grbit = Windows7Grbits.ReplayIgnoreLostLogs; } else { grbit = InitGrbit.None; } _EseInstance.Init(grbit); _ConnectionPool = new EseConnectionPool(_EseInstance, _DatabasePath, _ConnectionPoolSize); EseConnection connection = _ConnectionPool.OpenConnection(); try { using (connection.GetTable(_TableNameCallbacks, OpenTableGrbit.ReadOnly)) { } } catch (EsentErrorException eeex) { if (eeex.Error == JET_err.ObjectNotFound) { CreateTaskTable(connection); } else { throw; } } finally { _ConnectionPool.CloseConnection(connection); } } }
public void Open(string connectionString) { if (_EseInstance == null) { if (string.IsNullOrWhiteSpace(connectionString)) { connectionString = ApplicationFolderHelper.ApplicationFolderName; } this._DatabasePath = Path.Combine(connectionString, Path.ChangeExtension(_DatabaseName, _StorageEngineBaseName)); _EseInstance = new Instance(_DatabaseName); _EseInstance.Parameters.CreatePathIfNotExist = true; _EseInstance.Parameters.CircularLog = true; _EseInstance.Parameters.Recovery = true; _EseInstance.Parameters.BaseName = _StorageEngineBaseName; _EseInstance.Parameters.MaxSessions = _ConnectionPoolSize * 2; _EseInstance.Parameters.NoInformationEvent = true; if (!string.IsNullOrEmpty(connectionString)) { _EseInstance.Parameters.SystemDirectory = connectionString; _EseInstance.Parameters.LogFileDirectory = connectionString; _EseInstance.Parameters.TempDirectory = connectionString; _EseInstance.Parameters.AlternateDatabaseRecoveryDirectory = connectionString; } InitGrbit grbit = default(InitGrbit); if (EsentVersion.SupportsWindows7Features) { grbit = Windows7Grbits.ReplayIgnoreLostLogs; } else { grbit = InitGrbit.None; } _EseInstance.Init(grbit); _ConnectionPool = new EseConnectionPool(_EseInstance, _DatabasePath, _ConnectionPoolSize); EseConnection connection = _ConnectionPool.OpenConnection(); try { using (connection.GetTable(_TableNameCallbacks, OpenTableGrbit.ReadOnly)) { } } catch (EsentErrorException eeex) { if (eeex.Error == JET_err.ObjectNotFound) { CreateTaskTable(connection); } else { throw; } } finally { _ConnectionPool.CloseConnection(connection); } } }