Ejemplo n.º 1
0
        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);
            }
        }
Ejemplo n.º 2
0
        public IEnumerable <RevaleeTask> ListTasksDueBetween(DateTime startTime, DateTime endTime)
        {
            if (_EseInstance == null)
            {
                throw new InvalidOperationException("Storage provider has not been opened.");
            }

            DateTime rangeStartTime = EnforceMinimumDateTime(NormalizeDateTime(startTime));
            DateTime rangeEndTime   = EnforceMinimumDateTime(NormalizeDateTime(endTime));

            // Inclusive Upper Limit does not work properly for the CLR DateTime type.
            // Add the smallest amount of time that the Esent engine will detect to include the ending range inclusively.
            rangeEndTime = rangeEndTime.AddMilliseconds(1.0);

            EseConnection connection = this._ConnectionPool.OpenConnection();

            try
            {
                using (Table table = connection.GetTable(_TableNameCallbacks, OpenTableGrbit.DenyWrite | OpenTableGrbit.Preread | OpenTableGrbit.ReadOnly | OpenTableGrbit.Sequential))
                {
                    IDictionary <string, JET_COLUMNID> columnIds = connection.GetSchema(_TableNameCallbacks);
                    Api.JetSetCurrentIndex(connection, table, "due");
                    Api.MakeKey(connection, table, rangeStartTime, MakeKeyGrbit.NewKey);

                    if (Api.TrySeek(connection, table, SeekGrbit.SeekGE))
                    {
                        Api.MakeKey(connection, table, rangeEndTime, MakeKeyGrbit.NewKey);
                        if (Api.TrySetIndexRange(connection, table, SetIndexRangeGrbit.RangeInclusive | SetIndexRangeGrbit.RangeUpperLimit))
                        {
                            JET_SESID    jetSession                   = connection;
                            JET_TABLEID  jetTable                     = table;
                            JET_COLUMNID jetColumnCallbackId          = columnIds[_ColumnNameCallbackId];
                            JET_COLUMNID jetColumnCreatedTime         = columnIds[_ColumnNameCreatedTime];
                            JET_COLUMNID jetColumnCallbackTime        = columnIds[_ColumnNameCallbackTime];
                            JET_COLUMNID jetColumnCallbackUrl         = columnIds[_ColumnNameCallbackUrl];
                            JET_COLUMNID jetColumnAttemptsRemaining   = columnIds[_ColumnNameAttemptsRemaining];
                            JET_COLUMNID jetColumnAuthorizationCipher = columnIds[_ColumnNameAuthorizationCipher];

                            do
                            {
                                Guid?    callbackId              = Api.RetrieveColumnAsGuid(jetSession, jetTable, jetColumnCallbackId);
                                DateTime?createdTime             = Api.RetrieveColumnAsDateTime(jetSession, jetTable, jetColumnCreatedTime);
                                DateTime?callbackTime            = Api.RetrieveColumnAsDateTime(jetSession, jetTable, jetColumnCallbackTime);
                                string   callbackUrl             = Api.RetrieveColumnAsString(jetSession, jetTable, jetColumnCallbackUrl);
                                int?     attemptsRemainingColumn = Api.RetrieveColumnAsInt32(jetSession, jetTable, jetColumnAttemptsRemaining);
                                string   authorizationCipher     = Api.RetrieveColumnAsString(jetSession, jetTable, jetColumnAuthorizationCipher);

                                Uri callbackUri = null;

                                if (callbackTime.HasValue &&
                                    Uri.TryCreate(callbackUrl, UriKind.Absolute, out callbackUri) &&
                                    createdTime.HasValue &&
                                    callbackId.HasValue &&
                                    attemptsRemainingColumn.HasValue)
                                {
                                    RevaleeTask revivedTask = RevaleeTask.Revive(
                                        DateTime.SpecifyKind(callbackTime.Value, DateTimeKind.Utc),
                                        callbackUri,
                                        DateTime.SpecifyKind(createdTime.Value, DateTimeKind.Utc),
                                        callbackId.Value,
                                        attemptsRemainingColumn.Value,
                                        string.IsNullOrEmpty(authorizationCipher) ? null : authorizationCipher);

                                    yield return(revivedTask);
                                }
                            } while (Api.TryMoveNext(jetSession, jetTable));
                        }
                    }
                }
            }
            finally
            {
                _ConnectionPool.CloseConnection(connection);
            }

            yield break;
        }
Ejemplo n.º 3
0
        public IEnumerable <RevaleeTask> ListAllTasks()
        {
            if (_EseInstance == null)
            {
                throw new InvalidOperationException("Storage provider has not been opened.");
            }

            EseConnection connection = this._ConnectionPool.OpenConnection();

            try
            {
                using (Table table = connection.GetTable(_TableNameCallbacks, OpenTableGrbit.DenyWrite | OpenTableGrbit.Preread | OpenTableGrbit.ReadOnly | OpenTableGrbit.Sequential))
                {
                    IDictionary <string, JET_COLUMNID> columnIds = connection.GetSchema(_TableNameCallbacks);

                    if (Api.TryMoveFirst(connection, table))
                    {
                        JET_SESID    jetSession                   = connection;
                        JET_TABLEID  jetTable                     = table;
                        JET_COLUMNID jetColumnCallbackId          = columnIds[_ColumnNameCallbackId];
                        JET_COLUMNID jetColumnCreatedTime         = columnIds[_ColumnNameCreatedTime];
                        JET_COLUMNID jetColumnCallbackTime        = columnIds[_ColumnNameCallbackTime];
                        JET_COLUMNID jetColumnCallbackUrl         = columnIds[_ColumnNameCallbackUrl];
                        JET_COLUMNID jetColumnAttemptsRemaining   = columnIds[_ColumnNameAttemptsRemaining];
                        JET_COLUMNID jetColumnAuthorizationCipher = columnIds[_ColumnNameAuthorizationCipher];

                        do
                        {
                            Guid?    callbackId              = Api.RetrieveColumnAsGuid(jetSession, jetTable, jetColumnCallbackId);
                            DateTime?createdTime             = Api.RetrieveColumnAsDateTime(jetSession, jetTable, jetColumnCreatedTime);
                            DateTime?callbackTime            = Api.RetrieveColumnAsDateTime(jetSession, jetTable, jetColumnCallbackTime);
                            string   callbackUrl             = Api.RetrieveColumnAsString(jetSession, jetTable, jetColumnCallbackUrl);
                            int?     attemptsRemainingColumn = Api.RetrieveColumnAsInt32(jetSession, jetTable, jetColumnAttemptsRemaining);
                            string   authorizationCipher     = Api.RetrieveColumnAsString(jetSession, jetTable, jetColumnAuthorizationCipher);

                            Uri callbackUri = null;

                            if (callbackTime.HasValue &&
                                Uri.TryCreate(callbackUrl, UriKind.Absolute, out callbackUri) &&
                                createdTime.HasValue &&
                                callbackId.HasValue &&
                                attemptsRemainingColumn.HasValue)
                            {
                                RevaleeTask revivedTask = RevaleeTask.Revive(
                                    DateTime.SpecifyKind(callbackTime.Value, DateTimeKind.Utc),
                                    callbackUri,
                                    DateTime.SpecifyKind(createdTime.Value, DateTimeKind.Utc),
                                    callbackId.Value,
                                    attemptsRemainingColumn.Value,
                                    string.IsNullOrEmpty(authorizationCipher) ? null : authorizationCipher);

                                yield return(revivedTask);
                            }
                        } while (Api.TryMoveNext(jetSession, jetTable));
                    }
                }
            }
            finally
            {
                _ConnectionPool.CloseConnection(connection);
            }

            yield break;
        }