Пример #1
0
        /// <summary>
        /// Retrieve a completed scope from the persistence store.
        /// </summary>
        /// <param name="scopeId"></param>
        /// <returns></returns>
        public Byte[] RetrieveCompletedScope(Guid scopeId)
        {
            Byte[] completedScope = null;

            using (DbCommand dbCommand = CreateCommand(_nameResolver.ResolveCommandName(PersistenceCommandName.RetrieveCompletedScope), CommandType.StoredProcedure))
            {
                AddParameter(dbCommand, _nameResolver.ResolveParameterName(
                                 PersistenceCommandName.RetrieveCompletedScope,
                                 PersistenceParameterName.ScopeId), scopeId, AdoDbType.Guid);

                AddParameter(dbCommand, _nameResolver.ResolveParameterName(
                                 PersistenceCommandName.RetrieveCompletedScope,
                                 PersistenceParameterName.Result), AdoDbType.Int32,
                             ParameterDirection.Output);

                AddParameter(dbCommand, _nameResolver.ResolveParameterName(
                                 PersistenceCommandName.RetrieveCompletedScope,
                                 PersistenceParameterName.State), AdoDbType.Cursor,
                             ParameterDirection.Output);

                Int32?result;
                using (IDataReader dataReader = dbCommand.ExecuteReader())
                {
                    if (dataReader.Read())
                    {
                        completedScope = (Byte[])_valueReader.GetValue(dataReader, 0);
                    }

                    result = _valueReader.GetNullableInt32(dbCommand,
                                                           _nameResolver.ResolveParameterName(
                                                               PersistenceCommandName.RetrieveInstanceState,
                                                               PersistenceParameterName.Result));
                }

                if (completedScope == null && result > 0)
                {
                    // scope could not be found
                    throw new PersistenceException(RM.Get_Error_ScopeCouldNotBeLoaded(scopeId));
                }
            }

            return(completedScope);
        }
Пример #2
0
        /// <summary>
        /// Retrieve instance state from the persistence store.
        /// </summary>
        /// <param name="instanceId"></param>
        /// <param name="ownerId"></param>
        /// <param name="ownedUntil"></param>
        /// <returns></returns>
        public byte[] RetrieveInstanceState(Guid instanceId, Guid ownerId, DateTime ownedUntil)
        {
            byte[] instanceState = null;

            using (DbCommand dbCommand = resourceProvider.CreateCommand(this.dbConnection, nameResolver.ResolveCommandName(CommandNames.RetrieveInstanceState), CommandType.StoredProcedure))
            {
                string instanceParameter = nameResolver.ResolveParameterName(
                    CommandNames.InsertInstanceState, ParameterNames.InstanceId);

                string resultParameter = nameResolver.ResolveParameterName(
                    CommandNames.InsertInstanceState, ParameterNames.Result);

                resourceProvider.AddParameter(dbCommand,
                                              instanceParameter, instanceId, AdoDbType.Guid);

                resourceProvider.AddParameter(dbCommand,
                                              nameResolver.ResolveParameterName(CommandNames.RetrieveInstanceState,
                                                                                ParameterNames.OwnerId), ownerId, AdoDbType.Guid);

                resourceProvider.AddParameter(dbCommand,
                                              nameResolver.ResolveParameterName(CommandNames.RetrieveInstanceState,
                                                                                ParameterNames.OwnedUntil), ownedUntil, AdoDbType.DateTime);

                resourceProvider.AddParameter(dbCommand,
                                              resultParameter, AdoDbType.Int32, ParameterDirection.Output);

                resourceProvider.AddParameter(dbCommand,
                                              nameResolver.ResolveParameterName(CommandNames.RetrieveInstanceState,
                                                                                ParameterNames.CurrentOwnerId), AdoDbType.Guid, ParameterDirection.Output);

                resourceProvider.AddParameter(dbCommand,
                                              nameResolver.ResolveParameterName(CommandNames.RetrieveInstanceState,
                                                                                ParameterNames.State), AdoDbType.Cursor, ParameterDirection.Output);

                int?result;
                using (IDataReader dataReader = dbCommand.ExecuteReader())
                {
                    if (dataReader.Read())
                    {
                        instanceState = (byte[])valueReader.GetValue(dataReader, 0);
                    }

                    result = valueReader.GetNullableInt32(dbCommand, resultParameter);
                }

                if (instanceState == null && result > 0)
                {
                    // workflow could not be found
                    WorkflowPersistenceException e =
                        new WorkflowPersistenceException(string.Format(
                                                             "Instance with identifier {0} could not be loaded.", instanceId));

                    e.Data["WorkflowNotFound"] = true;
                }
                else
                {
                    checkResult(dbCommand, resultParameter, instanceParameter);
                }
            }

            return(instanceState);
        }