public async Task EnableQueue(string queueName) { using (TransactionScope transactionScope = new TransactionScope(TransactionScopeOption.Suppress, TransactionScopeAsyncFlowOption.Enabled)) { var dbconnection = await _connectionManager.CreateSSSBConnectionAsync(CancellationToken.None); try { using (dbconnection) using (var command = dbconnection.CreateCommand()) { string sql = string.Format("alter queue {0} with status = on", queueName); command.CommandText = sql; await command.ExecuteNonQueryAsync(); } transactionScope.Complete(); } catch (SqlException ex) { DBWrapperExceptionsHelper.ThrowError(ex, _log); return; } } }
private async Task <int> _PubSub(SqlConnection dbconnection, TimeSpan lifetime, Guid initiatorConversationGroupID, string topic, string messageType, bool endDialog = false) { XElement xmessage = new XElement("message", new XAttribute("subscriberId", initiatorConversationGroupID), new XElement("topic", topic) ); byte[] body = xmessage.ConvertToBytes(); try { int result = await _manager.SendMessageWithInitiatorConversationGroup( dbconnection, fromService : SUBSCRIBER_SERVICE_NAME, toService : PUBLISHER_SERVICE_NAME, contractName : PUBLISH_SUBSCRIBE_CONTRACT_NAME, lifeTime : (int)lifetime.TotalSeconds, isWithEncryption : false, initiatorConversationGroupID : initiatorConversationGroupID, messageType : messageType, body : body, withEndDialog : endDialog); return(result); } catch (SqlException ex) { DBWrapperExceptionsHelper.ThrowError(ex, ServiceBrokerResources.SendMessageErrMsg, _logger); } catch (Exception ex) { throw new Exception(ServiceBrokerResources.SendMessageErrMsg, ex); } return(-1); }
public async Task <int> SendMessage( SqlConnection dbconnection, Guid?conversationHandle, String messageType, byte[] body) { try { using (SqlCommand command = new SqlCommand()) { command.Connection = dbconnection; command.CommandText = "SSSB.SendMessage"; command.CommandType = CommandType.StoredProcedure; command.Parameters.Add(new SqlParameter("@RETURN_VALUE", SqlDbType.Int, 0, ParameterDirection.ReturnValue, true, 0, 0, "RETURN_VALUE", DataRowVersion.Current, null)); command.Parameters.Add(new SqlParameter("@conversationHandle", SqlDbType.UniqueIdentifier, 0, ParameterDirection.Input, true, 0, 0, "conversationHandle", DataRowVersion.Current, NullableHelper.DBNullConvertFrom(conversationHandle))); command.Parameters.Add(new SqlParameter("@messageType", SqlDbType.NVarChar, 255, ParameterDirection.Input, true, 0, 0, "messageType", DataRowVersion.Current, NullableHelper.DBNullConvertFrom(messageType))); command.Parameters.Add(new SqlParameter("@body", SqlDbType.VarBinary, -1, ParameterDirection.Input, true, 0, 0, "body", DataRowVersion.Current, NullableHelper.DBNullConvertFrom(body))); await command.ExecuteNonQueryAsync(); return((Int32)command.Parameters[RETURN_VALUE_PARAMETER_NAME].Value); } } catch (SqlException ex) { DBWrapperExceptionsHelper.ThrowError(ex, _log); return(-1); } }
public async Task <IDataReader> ReceiveMessagesNoWaitAsync( SqlConnection dbconnection, String queueName, int?fetchSize, Guid?conversation_group, CommandBehavior procedureResultBehaviour, CancellationToken cancellation) { try { using (SqlCommand command = new SqlCommand()) { command.Connection = dbconnection; command.CommandTimeout = 20; command.CommandText = "SSSB.ImmediateReceiveMessagesFromQueue"; command.CommandType = CommandType.StoredProcedure; command.Parameters.Add(new SqlParameter("@RETURN_VALUE", SqlDbType.Int, 0, ParameterDirection.ReturnValue, true, 0, 0, "RETURN_VALUE", DataRowVersion.Current, null)); command.Parameters.Add(new SqlParameter("@queueName", SqlDbType.NVarChar, 128, ParameterDirection.Input, true, 0, 0, "queueName", DataRowVersion.Current, NullableHelper.DBNullConvertFrom(queueName))); command.Parameters.Add(new SqlParameter("@fetchSize", SqlDbType.Int, 0, ParameterDirection.Input, true, 0, 0, "fetchSize", DataRowVersion.Current, NullableHelper.DBNullConvertFrom(fetchSize))); command.Parameters.Add(new SqlParameter("@conversation_group", SqlDbType.UniqueIdentifier, 0, ParameterDirection.Input, true, 0, 0, "conversation_group", DataRowVersion.Current, NullableHelper.DBNullConvertFrom(conversation_group))); return(await command.ExecuteReaderAsync(procedureResultBehaviour, cancellation)); } } catch (SqlException ex) { cancellation.ThrowIfCancellationRequested(); DBWrapperExceptionsHelper.ThrowError(ex, _log); } return(null); }
public async Task <int> ProcessPendingMessages( SqlConnection dbconnection, bool processAll = false, String objectID = null ) { try { using (SqlCommand command = new SqlCommand()) { command.Connection = dbconnection; command.CommandText = "SSSB.ProcessPendingMessages"; command.CommandType = CommandType.StoredProcedure; command.Parameters.Add(new SqlParameter("@RETURN_VALUE", SqlDbType.Int, 0, ParameterDirection.ReturnValue, true, 0, 0, "RETURN_VALUE", DataRowVersion.Current, null)); command.Parameters.Add(new SqlParameter("@ProccessALL", SqlDbType.Bit, 0, ParameterDirection.Input, false, 0, 0, "ProccessALL", DataRowVersion.Current, processAll)); command.Parameters.Add(new SqlParameter("@ObjectID", SqlDbType.VarChar, 50, ParameterDirection.Input, true, 0, 0, "ObjectID", DataRowVersion.Current, NullableHelper.DBNullConvertFrom(objectID))); await command.ExecuteNonQueryAsync(); return((Int32)command.Parameters[RETURN_VALUE_PARAMETER_NAME].Value); } } catch (SqlException ex) { DBWrapperExceptionsHelper.ThrowError(ex, _log); return(-1); } }
public async Task <long?> SendPendingMessage( SqlConnection dbconnection, String objectID, DateTime?activationDate, String fromService, String toService, String contractName, int?lifeTime, bool?isWithEncryption, byte[] messageBody, String messageType ) { long?pendingMessageID = null; try { using (SqlCommand command = new SqlCommand()) { command.Connection = dbconnection; command.CommandText = "SSSB.SendPendingMessage"; command.CommandType = CommandType.StoredProcedure; command.Parameters.Add(new SqlParameter("@RETURN_VALUE", SqlDbType.Int, 0, ParameterDirection.ReturnValue, true, 0, 0, "RETURN_VALUE", DataRowVersion.Current, null)); command.Parameters.Add(new SqlParameter("@objectID", SqlDbType.VarChar, 50, ParameterDirection.Input, true, 0, 0, "objectID", DataRowVersion.Current, NullableHelper.DBNullConvertFrom(objectID))); command.Parameters.Add(new SqlParameter("@activationDate", SqlDbType.DateTime, 0, ParameterDirection.Input, true, 0, 0, "activationDate", DataRowVersion.Current, NullableHelper.DBNullConvertFrom(activationDate))); command.Parameters.Add(new SqlParameter("@fromService", SqlDbType.NVarChar, 255, ParameterDirection.Input, true, 0, 0, "fromService", DataRowVersion.Current, NullableHelper.DBNullConvertFrom(fromService))); command.Parameters.Add(new SqlParameter("@toService", SqlDbType.NVarChar, 255, ParameterDirection.Input, true, 0, 0, "toService", DataRowVersion.Current, NullableHelper.DBNullConvertFrom(toService))); command.Parameters.Add(new SqlParameter("@contractName", SqlDbType.NVarChar, 255, ParameterDirection.Input, true, 0, 0, "contractName", DataRowVersion.Current, NullableHelper.DBNullConvertFrom(contractName))); command.Parameters.Add(new SqlParameter("@lifeTime", SqlDbType.Int, 0, ParameterDirection.Input, true, 0, 0, "lifeTime", DataRowVersion.Current, NullableHelper.DBNullConvertFrom(lifeTime))); command.Parameters.Add(new SqlParameter("@isWithEncryption", SqlDbType.Bit, 0, ParameterDirection.Input, true, 0, 0, "isWithEncryption", DataRowVersion.Current, NullableHelper.DBNullConvertFrom(isWithEncryption))); command.Parameters.Add(new SqlParameter("@messageBody", SqlDbType.VarBinary, -1, ParameterDirection.Input, true, 0, 0, "messageBody", DataRowVersion.Current, NullableHelper.DBNullConvertFrom(messageBody))); command.Parameters.Add(new SqlParameter("@messageType", SqlDbType.NVarChar, 255, ParameterDirection.Input, true, 0, 0, "messageType", DataRowVersion.Current, NullableHelper.DBNullConvertFrom(messageType))); command.Parameters.Add(new SqlParameter("@pendingMessageID", SqlDbType.BigInt, 0, ParameterDirection.InputOutput, true, 0, 0, "pendingMessageID", DataRowVersion.Current, NullableHelper.DBNullConvertFrom(pendingMessageID))); await command.ExecuteNonQueryAsync(); if (command.Parameters["@pendingMessageID"].Value == DBNull.Value) { pendingMessageID = null; } else { pendingMessageID = (long)(command.Parameters["@pendingMessageID"].Value); } return(pendingMessageID); } } catch (SqlException ex) { DBWrapperExceptionsHelper.ThrowError(ex, _log); return(-1); } }
/// <summary> /// Отправка отложенного сообщения. Сообщение содержит информацию о типе, идентификатор диалога и пр. необходимую для отправки информацию. /// </summary> /// <param name="fromService"></param> /// <param name="message"></param> /// <param name="lifetime"></param> /// <param name="isWithEncryption"></param> /// <param name="activationTime"></param> /// <param name="objectID"></param> public async Task <long?> SendPendingMessage(SqlConnection dbconnection, SSSBMessage message, string fromService, TimeSpan lifetime, bool isWithEncryption, DateTime activationTime, string objectID, int attemptNumber) { Debug($"Executing method SendPendingMessage(ConversationHandle: {message.ConversationHandle}, fromService: {fromService}, activationTime: {activationTime: dd.MM.yyyy HH:mm:ss}"); try { XElement xmessage = new XElement("DeferedMessage", new XAttribute("conversationHandle", message.ConversationHandle), new XAttribute("conversationGroupID", message.ConversationGroupID), new XAttribute("messageType", message.MessageType), new XAttribute("serviceName", message.ServiceName), new XAttribute("contractName", message.ContractName), new XAttribute("sequenceNumber", message.SequenceNumber), new XAttribute("validationType", message.ValidationType), new XAttribute("attemptNumber", attemptNumber), new XElement("body", Convert.ToBase64String(message.Body)) ); byte[] body = xmessage.ConvertToBytes(); long?pendingMessageID = await _manager.SendPendingMessage( dbconnection, objectID, activationTime, fromService, message.ServiceName, message.ContractName, (int)lifetime.TotalSeconds, isWithEncryption, body, "PPS_DeferedMessageType"); return(pendingMessageID); } catch (SqlException ex) { DBWrapperExceptionsHelper.ThrowError(ex, ServiceBrokerResources.PendingMessageErrMsg, _logger); } catch (Exception ex) { _logger.LogError(ErrorHelper.GetFullMessage(ex)); throw new PPSException(ServiceBrokerResources.PendingMessageErrMsg, ex); } return(null); }
public async Task <Guid?> BeginDialogConversation( SqlConnection dbconnection, String fromService, String toService, String contractName, int?lifetime, bool?withEncryption, Guid?relatedConversationID, Guid?relatedConversationGroupID) { Guid?conversationHandle = null; try { using (SqlCommand command = new SqlCommand()) { command.Connection = dbconnection; command.CommandText = "SSSB.BeginDialogConversation"; command.CommandType = CommandType.StoredProcedure; command.Parameters.Add(new SqlParameter("@RETURN_VALUE", SqlDbType.Int, 0, ParameterDirection.ReturnValue, true, 0, 0, "RETURN_VALUE", DataRowVersion.Current, null)); command.Parameters.Add(new SqlParameter("@fromService", SqlDbType.NVarChar, 255, ParameterDirection.Input, true, 0, 0, "fromService", DataRowVersion.Current, NullableHelper.DBNullConvertFrom(fromService))); command.Parameters.Add(new SqlParameter("@toService", SqlDbType.NVarChar, 255, ParameterDirection.Input, true, 0, 0, "toService", DataRowVersion.Current, NullableHelper.DBNullConvertFrom(toService))); command.Parameters.Add(new SqlParameter("@contractName", SqlDbType.NVarChar, 128, ParameterDirection.Input, true, 0, 0, "contractName", DataRowVersion.Current, NullableHelper.DBNullConvertFrom(contractName))); command.Parameters.Add(new SqlParameter("@lifetime", SqlDbType.Int, 0, ParameterDirection.Input, true, 0, 0, "lifetime", DataRowVersion.Current, NullableHelper.DBNullConvertFrom(lifetime))); command.Parameters.Add(new SqlParameter("@withEncryption", SqlDbType.Bit, 0, ParameterDirection.Input, true, 0, 0, "withEncryption", DataRowVersion.Current, NullableHelper.DBNullConvertFrom(withEncryption))); command.Parameters.Add(new SqlParameter("@relatedConversationID", SqlDbType.UniqueIdentifier, 0, ParameterDirection.Input, true, 0, 0, "relatedConversationID", DataRowVersion.Current, NullableHelper.DBNullConvertFrom(relatedConversationID))); command.Parameters.Add(new SqlParameter("@relatedConversationGroupID", SqlDbType.UniqueIdentifier, 0, ParameterDirection.Input, true, 0, 0, "relatedConversationGroupID", DataRowVersion.Current, NullableHelper.DBNullConvertFrom(relatedConversationGroupID))); command.Parameters.Add(new SqlParameter("@conversationHandle", SqlDbType.UniqueIdentifier, 0, ParameterDirection.InputOutput, true, 0, 0, "conversationHandle", DataRowVersion.Current, NullableHelper.DBNullConvertFrom(conversationHandle))); await command.ExecuteNonQueryAsync(); if (command.Parameters["@conversationHandle"].Value == DBNull.Value) { conversationHandle = null; } else { conversationHandle = (Guid)(command.Parameters["@conversationHandle"].Value); } return(conversationHandle); } } catch (SqlException ex) { DBWrapperExceptionsHelper.ThrowError(ex, _log); return(null); } }
/// <summary> /// Отправка сообщения. Сообщение содержит информацию о типе, идентификатор диалога и пр. необходимую для отправки информацию. /// </summary> /// <param name="message"></param> public async Task SendMessage(SqlConnection dbconnection, SSSBMessage message) { Debug($"Executing method SendMessage({message.MessageType}: {message.ConversationHandle})"); try { await _manager.SendMessage(dbconnection, message.ConversationHandle, message.MessageType, message.Body); } catch (SqlException ex) { DBWrapperExceptionsHelper.ThrowError(ex, ServiceBrokerResources.SendMessageErrMsg, _logger); } catch (Exception ex) { _logger.LogError(ErrorHelper.GetFullMessage(ex)); throw new PPSException(ServiceBrokerResources.SendMessageErrMsg, ex); } }
public async Task <bool> IsQueueEnabled(string queueName) { bool result = false; using (TransactionScope transactionScope = new TransactionScope(TransactionScopeOption.Suppress, TransactionScopeAsyncFlowOption.Enabled)) { var dbconnection = await _connectionManager.CreateSSSBConnectionAsync(CancellationToken.None); try { using (dbconnection) using (var command = dbconnection.CreateCommand()) { command.CommandText = "select CAST(is_receive_enabled as BIT) as IsEnabled from sys.service_queues where Name=@queueName"; SqlParameter qnParam = command.Parameters.Add(new SqlParameter("@queueName", SqlDbType.NVarChar, 128)); qnParam.Value = queueName; SqlDataReader dr = await command.ExecuteReaderAsync(); try { if (dr.Read()) { result = dr.GetBoolean(0); } else { throw new Exception(string.Format("Queue {0} was not found in the sys.service_queues", queueName)); } } finally { dr.Close(); } } transactionScope.Complete(); return(result); } catch (SqlException ex) { DBWrapperExceptionsHelper.ThrowError(ex, _log); return(false); } } }
/// <summary> /// Завершение диалога /// </summary> /// <param name="conversationHandle"></param> /// <param name="withCleanup"></param> /// <param name="errorCode"></param> /// <param name="errorDescription"></param> private async Task EndConversation(SqlConnection dbconnection, Guid conversationHandle, bool withCleanup, int?errorCode, string errorDescription) { Debug($"Executing method EndConversation(conversationHandle: {conversationHandle}, withCleanup: {withCleanup}, errorCode: {errorCode}, errorDescription: {errorDescription})"); try { await _manager.EndConversation(dbconnection, conversationHandle, withCleanup, errorCode, errorDescription); } catch (SqlException ex) { DBWrapperExceptionsHelper.ThrowError(ex, ServiceBrokerResources.EndConversationErrMsg, _logger); } catch (Exception ex) { _logger.LogError(ErrorHelper.GetFullMessage(ex)); throw new PPSException(ServiceBrokerResources.EndConversationErrMsg, ex); } }
/// <summary> /// Послать ответное сообщение об окончании выполнения шага /// </summary> /// <param name="conversationHandle"></param> public async Task SendStepCompletedMessage(SqlConnection dbconnection, Guid conversationHandle) { Debug($"Executing method SendStepCompletedMessage, conversationHandle: {conversationHandle}"); try { await _manager.SendMessage(dbconnection, conversationHandle, SSSBMessage.PPS_StepCompleteMessageType, new byte[0]); } catch (SqlException ex) { DBWrapperExceptionsHelper.ThrowError(ex, ServiceBrokerResources.SendMessageErrMsg, _logger); } catch (Exception ex) { _logger.LogError(ErrorHelper.GetFullMessage(ex)); throw new PPSException(ServiceBrokerResources.SendMessageErrMsg, ex); } }
/// <summary> /// Возвращает название очереди сообщений для сервиса /// </summary> /// <param name="serviceName"></param> /// <returns></returns> public async Task <string> GetServiceQueueName(string serviceName) { Debug($"Executing method GetServiceQueueName({serviceName})"); try { return(await _manager.GetServiceQueueName(serviceName).ConfigureAwait(false)); } catch (SqlException ex) { DBWrapperExceptionsHelper.ThrowError(ex, ServiceBrokerResources.GetServiceQueueNameErrMsg, _logger); } catch (Exception ex) { _logger.LogError(ErrorHelper.GetFullMessage(ex)); throw new PPSException(ServiceBrokerResources.GetServiceQueueNameErrMsg, ex); } return(null); }
public async Task <int> ProcessPendingMessages(SqlConnection dbconnection, bool processAll = false, string objectID = null) { Debug("Executing method ProcessPendingMessage(..)"); try { return(await _manager.ProcessPendingMessages(dbconnection, processAll, objectID)); } catch (SqlException ex) { DBWrapperExceptionsHelper.ThrowError(ex, ServiceBrokerResources.ProcessMessagesErrMsg, _logger); } catch (Exception ex) { _logger.LogError(ErrorHelper.GetFullMessage(ex)); throw new PPSException(ServiceBrokerResources.ProcessMessagesErrMsg, ex); } return(-1); }
/// <summary> /// Отправка сообщения. Сообщение содержит информацию о типе, идентификатор диалога и пр. необходимую для отправки информацию. /// </summary> /// <param name="message"></param> public async Task SendMessage(SqlConnection dbconnection, Guid conversationHandle, string messageType, XElement xmlBody = null) { Debug($"Executing method SendMessage({messageType}: {conversationHandle})"); try { byte[] body = xmlBody?.ConvertToBytes() ?? new byte[0]; await _manager.SendMessage(dbconnection, conversationHandle, messageType, body); } catch (SqlException ex) { DBWrapperExceptionsHelper.ThrowError(ex, ServiceBrokerResources.SendMessageErrMsg, _logger); } catch (Exception ex) { _logger.LogError(ErrorHelper.GetFullMessage(ex)); throw new PPSException(ServiceBrokerResources.SendMessageErrMsg, ex); } }
public async Task <string> GetServiceQueueName(String serviceName) { string queueName = string.Empty; using (TransactionScope transactionScope = new TransactionScope(TransactionScopeOption.Suppress, TransactionScopeAsyncFlowOption.Enabled)) { var dbconnection = await _connectionManager.CreateSSSBConnectionAsync(CancellationToken.None); try { using (dbconnection) using (var command = dbconnection.CreateCommand()) { command.CommandText = "SSSB.GetServiceQueueName"; command.CommandType = CommandType.StoredProcedure; command.Parameters.Add(new SqlParameter("@RETURN_VALUE", SqlDbType.Int, 0, ParameterDirection.ReturnValue, true, 0, 0, "RETURN_VALUE", DataRowVersion.Current, null)); command.Parameters.Add(new SqlParameter("@serviceName", SqlDbType.NVarChar, 128, ParameterDirection.Input, true, 0, 0, "serviceName", DataRowVersion.Current, NullableHelper.DBNullConvertFrom(serviceName))); command.Parameters.Add(new SqlParameter("@queueName", SqlDbType.NVarChar, 128, ParameterDirection.InputOutput, true, 0, 0, "queueName", DataRowVersion.Current, NullableHelper.DBNullConvertFrom(queueName))); await command.ExecuteNonQueryAsync(); if (command.Parameters["@queueName"].Value == DBNull.Value) { queueName = null; } else { queueName = (String)(command.Parameters["@queueName"].Value); } } transactionScope.Complete(); return(queueName); } catch (SqlException ex) { DBWrapperExceptionsHelper.ThrowError(ex, _log); return(null); } } }
public async Task <int> SendMessageWithInitiatorConversationGroup( SqlConnection dbconnection, string fromService, string toService, string contractName, int?lifeTime, bool?isWithEncryption, Guid initiatorConversationGroupID, String messageType, byte[] body, bool?withEndDialog = null) { try { using (SqlCommand command = new SqlCommand()) { command.Connection = dbconnection; command.CommandText = "SSSB.SendMessageWithInitiatorConversationGroup"; command.CommandType = CommandType.StoredProcedure; command.Parameters.Add(new SqlParameter("@RETURN_VALUE", SqlDbType.Int, 0, ParameterDirection.ReturnValue, true, 0, 0, "RETURN_VALUE", DataRowVersion.Current, null)); command.Parameters.Add(new SqlParameter("@fromService", SqlDbType.NVarChar, 255, ParameterDirection.Input, true, 0, 0, "fromService", DataRowVersion.Current, NullableHelper.DBNullConvertFrom(fromService))); command.Parameters.Add(new SqlParameter("@toService", SqlDbType.NVarChar, 255, ParameterDirection.Input, true, 0, 0, "toService", DataRowVersion.Current, NullableHelper.DBNullConvertFrom(toService))); command.Parameters.Add(new SqlParameter("@contractName", SqlDbType.NVarChar, 128, ParameterDirection.Input, true, 0, 0, "contractName", DataRowVersion.Current, NullableHelper.DBNullConvertFrom(contractName))); command.Parameters.Add(new SqlParameter("@lifeTime", SqlDbType.Int, 0, ParameterDirection.Input, true, 0, 0, "lifeTime", DataRowVersion.Current, NullableHelper.DBNullConvertFrom(lifeTime))); command.Parameters.Add(new SqlParameter("@withEncryption", SqlDbType.Bit, 0, ParameterDirection.Input, true, 0, 0, "isWithEncryption", DataRowVersion.Current, isWithEncryption ?? false)); command.Parameters.Add(new SqlParameter("@initiatorConversationGroupID", SqlDbType.UniqueIdentifier, 0, ParameterDirection.Input, false, 0, 0, "initiatorConversationGroupID", DataRowVersion.Current, initiatorConversationGroupID)); command.Parameters.Add(new SqlParameter("@messageType", SqlDbType.NVarChar, 255, ParameterDirection.Input, true, 0, 0, "messageType", DataRowVersion.Current, NullableHelper.DBNullConvertFrom(messageType))); command.Parameters.Add(new SqlParameter("@body", SqlDbType.VarBinary, -1, ParameterDirection.Input, true, 0, 0, "body", DataRowVersion.Current, NullableHelper.DBNullConvertFrom(body))); command.Parameters.Add(new SqlParameter("@withEndDialog", SqlDbType.Bit, 0, ParameterDirection.Input, true, 0, 0, "withEndDialog", DataRowVersion.Current, withEndDialog ?? false)); await command.ExecuteNonQueryAsync(); return((Int32)command.Parameters[RETURN_VALUE_PARAMETER_NAME].Value); } } catch (SqlException ex) { DBWrapperExceptionsHelper.ThrowError(ex, _log); return(-1); } }
/// <summary> /// Запуск диалога обмена сообщениями. /// </summary> /// <param name="fromService"></param> /// <param name="toService"></param> /// <param name="contractName"></param> /// <param name="lifetime"></param> /// <param name="withEncryption"></param> /// <param name="relatedConversationHandle"></param> /// <param name="relatedConversationGroupID"></param> /// <returns></returns> public async Task <Guid> BeginDialogConversation(SqlConnection dbconnection, string fromService, string toService, string contractName, TimeSpan lifetime, bool withEncryption, Guid?relatedConversationHandle, Guid?relatedConversationGroupID) { Debug("Executing method BeginDialogConversation(fromService, toService, contractName, lifetime, withEncryption, relatedConversationID, relatedConversationGroupID)"); try { Guid?conversationHandle = await _manager.BeginDialogConversation(dbconnection, fromService, toService, contractName, lifetime == TimeSpan.Zero?(int?)null : (int)lifetime.TotalSeconds, withEncryption, relatedConversationHandle, relatedConversationGroupID); return(conversationHandle.Value); } catch (SqlException ex) { DBWrapperExceptionsHelper.ThrowError(ex, ServiceBrokerResources.BeginDialogConversationErrMsg, _logger); } catch (Exception ex) { _logger.LogError(ErrorHelper.GetFullMessage(ex)); throw new PPSException(ServiceBrokerResources.BeginDialogConversationErrMsg, ex); } return(Guid.Empty); }
public async Task <int> EndConversation( SqlConnection dbconnection, Guid?conversationHandle, bool?withCleanup, int?errorCode, String errorDescription) { try { using (SqlCommand command = new SqlCommand()) { command.Connection = dbconnection; command.CommandText = "SSSB.EndConversation"; command.CommandType = CommandType.StoredProcedure; if (!string.IsNullOrEmpty(errorDescription) && !errorCode.HasValue) { errorCode = 1; } command.Parameters.Add(new SqlParameter("@RETURN_VALUE", SqlDbType.Int, 0, ParameterDirection.ReturnValue, true, 0, 0, "RETURN_VALUE", DataRowVersion.Current, null)); command.Parameters.Add(new SqlParameter("@conversationHandle", SqlDbType.UniqueIdentifier, 0, ParameterDirection.Input, true, 0, 0, "conversationHandle", DataRowVersion.Current, NullableHelper.DBNullConvertFrom(conversationHandle))); command.Parameters.Add(new SqlParameter("@withCleanup", SqlDbType.Bit, 0, ParameterDirection.Input, true, 0, 0, "withCleanup", DataRowVersion.Current, NullableHelper.DBNullConvertFrom(withCleanup))); command.Parameters.Add(new SqlParameter("@errorCode", SqlDbType.Int, 0, ParameterDirection.Input, true, 0, 0, "errorCode", DataRowVersion.Current, NullableHelper.DBNullConvertFrom(errorCode))); command.Parameters.Add(new SqlParameter("@errorDescription", SqlDbType.NVarChar, 255, ParameterDirection.Input, true, 0, 0, "errorDescription", DataRowVersion.Current, NullableHelper.DBNullConvertFrom(errorDescription))); await command.ExecuteNonQueryAsync(); return((Int32)command.Parameters[RETURN_VALUE_PARAMETER_NAME].Value); } } catch (SqlException ex) { DBWrapperExceptionsHelper.ThrowError(ex, _log); return(-1); } }