private bool ValidateTransaction(EndpointVersionType endpointVersion, NodeMethod transactionWebMethod, ComplexContent content, bool doValidateFlowOperation, string flowId, out string networkId) { networkId = null; string dbOperation; NodeMethod webMethod; bool isNetworkTransactionId = false; string transactionFlowId; TransactionStatus transactionStatus = TransactionManager.GetTransactionStatus(content.Transaction.Id, out transactionFlowId, out dbOperation, out webMethod); if (transactionStatus == null) { transactionStatus = TransactionManager.GetTransactionStatusByNetworkId(content.Transaction.Id, out transactionFlowId, out dbOperation, out webMethod); if (transactionStatus == null) { throw FaultProvider.GetFault(endpointVersion, ENExceptionCodeType.E_TransactionId, "Transaction \"{0}\" was not found", content.Transaction.Id); } isNetworkTransactionId = true; } if (transactionFlowId != flowId) { throw FaultProvider.GetFault(endpointVersion, ENExceptionCodeType.E_InvalidDataflow, "Flow operation \"{0}\" is not valid for transaction \"{1}\"", content.Flow.Operation, content.Transaction.Id); } if (doValidateFlowOperation && !string.Equals(dbOperation, content.Flow.Operation ?? string.Empty, StringComparison.InvariantCultureIgnoreCase)) { throw FaultProvider.GetFault(endpointVersion, ENExceptionCodeType.E_InvalidDataflow, "Flow operation \"{0}\" is not valid for transaction \"{1}\"", content.Flow.Operation, content.Transaction.Id); } if ((transactionWebMethod == NodeMethod.Submit) && (webMethod != NodeMethod.Submit)) { // Create new transaction and reference the input transaction id as the network id for // the new transcation networkId = content.Transaction.Id; } if (networkId != null) { content.Transaction.Id = string.Empty; return(true); } else { if (isNetworkTransactionId) { // Use the "real" db transcation id content.Transaction.Id = transactionStatus.Id; } return(false); } }
protected virtual void ValidateQueryResult(PaginatedContentResult result, FormattedPaginatedContentRequest request, NamedOrAuthEndpointVisit visit) { if ((result != null) && result.HasContent) { if (MaxRestQueryResponseKilobytes > 0) { if (result.Content.Content.Length > (MaxRestQueryResponseKilobytes * 1024L)) { throw FaultProvider.GetFault(visit.Version, ENExceptionCodeType.E_QueryReturnSetTooBig, "The requested data result set is too large. Please modify the query parameters so that a smaller data result set is returned."); } } } }
/// <summary> /// Authenticate /// </summary> /// <param name="request"></param> /// <returns></returns> public string Authenticate(AuthEndpointVisit request) { //Create a visit from the request Activity activity = null; try { NodeVisit nodeVisit; string token; AuthenticateEndpointActivity(request, ActivityType.Audit, NodeMethod.Authenticate, out nodeVisit, out token, out activity); return(token); } catch (Exception ex) { if (activity != null) { activity.Append(ExceptionUtils.GetDeepExceptionMessage(ex)); activity.Type = ActivityType.Error; } if (ex is InvalidCredentialException) { throw FaultProvider.GetFault(EndpointVersionType.EN20, ENExceptionCodeType.E_InvalidCredential, ex.Message); } else { throw FaultProvider.GetFault(request.Version, ex); } } finally { if (activity != null) { ActivityManager.Log(activity); } } }
public TransactionStatus Submit(AsyncComplexContent content, NamedEndpointVisit visit) { Activity activity = null; IList <string> newDocumentIds = null; bool isNewTransaction = false; try { // Validate inputs NodeVisit nodeVisit; MakeEndpointActivity(visit, ActivityType.Audit, NodeMethod.Submit, out nodeVisit, out activity); if (content == null) { throw FaultProvider.GetFault(visit.Version, ENExceptionCodeType.E_InvalidParameter, "Input content is null"); } if (CollectionUtils.IsNullOrEmpty(content.Documents)) { throw FaultProvider.GetFault(visit.Version, ENExceptionCodeType.E_InvalidParameter, "Input document list is empty"); } if (content.Transaction == null) { throw FaultProvider.GetFault(visit.Version, ENExceptionCodeType.E_InvalidParameter, "Input transaction is null"); } if ((content.Flow == null) || string.IsNullOrEmpty(content.Flow.FlowName)) { throw FaultProvider.GetFault(visit.Version, ENExceptionCodeType.E_InvalidParameter, "Input flow is null"); } bool isFlowProtected; string flowId = FlowManager.GetDataFlowIdByName(content.Flow.FlowName, out isFlowProtected); if (flowId == null) { throw FaultProvider.GetFault(visit.Version, ENExceptionCodeType.E_InvalidDataflow, "Flow \"{0}\" was not found", content.Flow.FlowName); } activity.FlowName = content.Flow.FlowName; activity.Operation = content.Flow.Operation; isNewTransaction = string.IsNullOrEmpty(content.Transaction.Id); string networkId = null; // Get the flow id associated with the transaction if (isNewTransaction) { } else { // Existing transaction isNewTransaction = ValidateTransaction(visit.Version, NodeMethod.Submit, content, (visit.Version != EndpointVersionType.EN11), flowId, out networkId); if (!isNewTransaction) { activity.TransactionId = content.Transaction.Id; } } DataService documentService = FlowManager.GetSubmitDocumentServiceForFlow(flowId, content.Flow.Operation); if (documentService == null) { if (!string.IsNullOrEmpty(content.Flow.Operation)) { throw FaultProvider.GetFault(visit.Version, ENExceptionCodeType.E_ServiceUnavailable, "A valid Submit service was not found for the flow \"{0}\"", content.Flow.FlowName); } // Let empty operation pass through, even without a valid service, per Mark } else if (!documentService.IsActive) { throw FaultProvider.GetFault(visit.Version, ENExceptionCodeType.E_ServiceUnavailable, "The Submit service is not active for the flow \"{0}\"", content.Flow.FlowName); } if (isFlowProtected) { ValidateUserPermissions(nodeVisit, content.Flow.FlowName, content.Flow.Operation, NodeMethod.Submit, activity); } if (isNewTransaction) { // Create a new transaction content.Transaction.Id = TransactionManager.CreateTransaction(NodeMethod.Submit, visit.Version, flowId, content.Flow.Operation, nodeVisit.Account.Id, CommonTransactionStatusCode.Unknown, null, content.Notifications, content.Recipients, false); activity.TransactionId = content.Transaction.Id; if (networkId != null) { TransactionManager.SetNetworkId(content.Transaction.Id, networkId, EndpointVersionType.Undefined, null, null, null); } activity.AppendFormat("Created new submit transaction id: {0}.", activity.TransactionId); } else { activity.AppendFormat("Retrieved existing submit transaction id: {0}.", activity.TransactionId); } foreach (Document document in content.Documents) { activity.AppendFormat("Adding submit document to transaction: {0}.", document); } // Add the documents to repository and DB newDocumentIds = DocumentManager.AddDocuments(content.Transaction.Id, content.Documents); #if DEBUG //NodeTransaction nodeTransaction = TransactionManager.GetTransaction(content.Transaction.Id, // CommonTransactionStatusCode.Received); #endif // DEBUG TransactionStatus rtnTransactionStatus = TransactionManager.SetTransactionStatus(content.Transaction.Id, nodeVisit.Account.Id, CommonTransactionStatusCode.Received, null, false); NotificationManager.DoSubmitNotifications(rtnTransactionStatus, flowId, content.Flow.FlowName, content.Flow.Operation, nodeVisit.Account.NaasAccount); SubmitProcessor.Wakeup(); return(rtnTransactionStatus); } catch (Exception ex) { if (newDocumentIds != null) { DocumentManager.RollbackDocuments(content.Transaction.Id, newDocumentIds); } if (isNewTransaction && !string.IsNullOrEmpty(content.Transaction.Id)) { TransactionManager.SetTransactionStatusNoThrow(content.Transaction.Id, CommonTransactionStatusCode.Failed, ex.Message, false); } if (activity != null) { activity.Append(ExceptionUtils.ToShortString(ex)); activity.Type = ActivityType.Error; } if (ex is SoapException) { throw; // Throw directly since already SoapException } else { throw FaultProvider.GetFault(visit.Version, ex); } } finally { if (activity != null) { ActivityManager.Log(activity); } } }
public IList <Document> Download(ComplexContent content, NamedEndpointVisit visit) { Activity activity = null; try { // Validate inputs NodeVisit nodeVisit; MakeEndpointActivity(visit, ActivityType.Audit, NodeMethod.Download, out nodeVisit, out activity); if (content == null) { throw FaultProvider.GetFault(visit.Version, ENExceptionCodeType.E_InvalidParameter, "Input content is null"); } if ((content.Transaction == null) || string.IsNullOrEmpty(content.Transaction.Id)) { throw FaultProvider.GetFault(visit.Version, ENExceptionCodeType.E_InvalidParameter, "Input transaction is null"); } bool isFlowProtected; string flowName, flowOperation; string flowId = TransactionManager.GetTransactionFlowId(content.Transaction.Id, out flowName, out flowOperation, out isFlowProtected); if (flowId == null) { throw FaultProvider.GetFault(visit.Version, ENExceptionCodeType.E_InvalidDataflow, "A flow with transaction id \"{0}\" was not found", content.Transaction.Id); } if ((content.Flow != null) && !string.IsNullOrEmpty(content.Flow.FlowName)) { if (!string.Equals(flowName, content.Flow.FlowName, StringComparison.InvariantCultureIgnoreCase)) { throw FaultProvider.GetFault(visit.Version, ENExceptionCodeType.E_InvalidDataflow, "The input dataflow name \"{0}\" does not match the dataflow name for transaction id \"{1}\"", content.Flow.FlowName, content.Transaction.Id); } } if (content.Flow == null) { content.Flow = new OperationDataFlow(flowName); } else if (string.IsNullOrEmpty(content.Flow.FlowName)) { content.Flow.FlowName = flowName; } activity.FlowName = content.Flow.FlowName; activity.Operation = content.Flow.Operation; string networkId; ValidateTransaction(visit.Version, NodeMethod.Download, content, false, flowId, out networkId); activity.TransactionId = content.Transaction.Id; if (isFlowProtected) { ValidateUserPermissions(nodeVisit, content.Flow.FlowName, content.Flow.Operation, NodeMethod.Download, activity); } IList <Document> documents; try { documents = DocumentManager.GetDocuments(content.Transaction.Id, content.Documents, true); } catch (FileNotFoundException fileNotFoundException) { throw FaultProvider.GetFault(visit.Version, ENExceptionCodeType.E_FileNotFound, string.Format("The document \"{0}\" was not found.", Path.GetFileName(fileNotFoundException.FileName))); } if (!CollectionUtils.IsNullOrEmpty(documents)) { foreach (Document document in documents) { activity.AppendFormat("Document: {0}.", document); } } NotificationManager.DoDownloadNotifications(content.Transaction.Id, flowId, content.Flow.FlowName, nodeVisit.Account.NaasAccount); return(documents); } catch (Exception ex) { if (activity != null) { activity.Append(ExceptionUtils.ToShortString(ex)); activity.Type = ActivityType.Error; } if (ex is SoapException) { throw; // Throw directly since already SoapException } else { throw FaultProvider.GetFault(visit.Version, ex); } } finally { if (activity != null) { ActivityManager.Log(activity); } } }
public TransactionStatus GetStatus(SimpleId transaction, NamedEndpointVisit visit) { Activity activity = null; try { NodeVisit nodeVisit; MakeEndpointActivity(visit, ActivityType.Audit, NodeMethod.GetStatus, out nodeVisit, out activity); if ((transaction == null) || string.IsNullOrEmpty(transaction.Id)) { throw FaultProvider.GetFault(visit.Version, ENExceptionCodeType.E_InvalidParameter, "Empty input transaction"); } string flowId, operation; NodeMethod webMethod; TransactionStatus transactionStatus = TransactionManager.GetTransactionStatus(transaction.Id, out flowId, out operation, out webMethod); if (transactionStatus == null) { throw FaultProvider.GetFault(visit.Version, ENExceptionCodeType.E_TransactionId, "Transaction not found: \"{0}\"", transaction.Id); } activity.TransactionId = transaction.Id; bool isFlowProtected; string flowCode = FlowManager.GetDataFlowNameById(flowId, out isFlowProtected); activity.FlowName = flowCode; activity.Operation = operation; if (flowCode == null) { throw FaultProvider.GetFault(visit.Version, ENExceptionCodeType.E_InvalidDataflow, "Flow id not found: \"{0}\" for transaction: \"{1}\"", flowId, transaction.Id); } if (isFlowProtected) { ValidateUserPermissions(nodeVisit, flowCode, operation, NodeMethod.GetStatus, activity); } activity.AppendFormat("GetStatus request from {0} by {1} for transaction Id {2}. ", visit.IP, nodeVisit.Account.NaasAccount, transaction.Id); activity.AppendFormat("Result: {0}", transactionStatus); return(transactionStatus); } catch (Exception ex) { if (activity != null) { activity.Append(ExceptionUtils.ToShortString(ex)); activity.Type = ActivityType.Error; } if (ex is SoapException) { throw; // Throw directly since already SoapException } else { throw FaultProvider.GetFault(visit.Version, ex); } } finally { if (activity != null) { ActivityManager.Log(activity); } } }
public ExecuteContentResultEx Execute(ServiceContentRequest request, NamedEndpointVisit visit) { Activity activity = null; string transactionId = null; try { NodeVisit nodeVisit; MakeEndpointActivity(visit, ActivityType.Audit, NodeMethod.Execute, out nodeVisit, out activity); if (request == null) { throw FaultProvider.GetFault(visit.Version, ENExceptionCodeType.E_InvalidParameter, "Empty input request"); } if ((request.Interface == null) || string.IsNullOrEmpty(request.Interface)) { throw FaultProvider.GetFault(visit.Version, ENExceptionCodeType.E_InvalidParameter, "Input interface is null"); } bool isFlowProtected; string flowId = FlowManager.GetDataFlowIdByName(request.Interface, out isFlowProtected); if (flowId == null) { throw FaultProvider.GetFault(visit.Version, ENExceptionCodeType.E_InvalidDataflow, "Interface \"{0}\" was not found", request.Interface); } activity.FlowName = request.Interface; activity.Operation = request.OperationName; DataService executeService = FlowManager.GetExecuteServiceForFlow(flowId, request.OperationName); if ((executeService == null) || !executeService.IsActive) { throw FaultProvider.GetFault(visit.Version, ENExceptionCodeType.E_ServiceUnavailable, "A valid Execute service was not found for the interface \"{0}\" and method \"{1}\"", request.Interface, request.OperationName); } if (isFlowProtected) { ValidateUserPermissions(nodeVisit, request.Interface, request.OperationName, NodeMethod.Execute, activity); } activity.AppendFormat("Execute request from {0} by {1}. ", visit.IP, nodeVisit.Account.NaasAccount); activity.AppendFormat("Service:{0} Parameters:{1}. ", request.OperationName, ParsingHelper.ToQualifiedString(request.Parameters)); // Load the service plugin IExecuteProcessor plugin; IPluginDisposer disposer; try { string flowName = FlowManager.GetDataFlowNameById(executeService.FlowId); disposer = PluginLoader.LoadExecuteProcessor(executeService, out plugin); } catch (Exception) { throw FaultProvider.GetFault(visit.Version, ENExceptionCodeType.E_ServiceUnavailable, "Failed to load the Execute service for the interface \"{0}\" and method \"{1}\"", request.Interface, request.OperationName); } ExecuteContentResultEx result = new ExecuteContentResultEx(); using (disposer) { transactionId = TransactionManager.CreateTransaction(NodeMethod.Execute, visit.Version, flowId, request.OperationName, nodeVisit.Account.Id, CommonTransactionStatusCode.Received, null, null, null, false); activity.TransactionId = transactionId; string requestId = RequestManager.CreateDataRequest(transactionId, executeService.Id, 0, -1, RequestType.Execute, nodeVisit.Account.Id, request.Parameters); try { ExecuteContentResult result2 = plugin.ProcessExecute(requestId); result.Content = result2.Content; result.Id = transactionId; result.Status = result2.Status; } finally { activity.Append(plugin.GetAuditLogEvents()); } } TransactionManager.SetTransactionStatus(transactionId, result.Status, string.Empty, false); NotificationManager.DoExecuteNotifications(result.Id, result.Status, flowId, request.Interface, nodeVisit.Account.NaasAccount, request.OperationName, request.Parameters); ExecuteProcessor.Wakeup(); return(result); } catch (Exception ex) { if (transactionId != null) { TransactionManager.SetTransactionStatusNoThrow(transactionId, CommonTransactionStatusCode.Failed, ex.Message, false); } if (activity != null) { activity.Append(ExceptionUtils.ToShortString(ex)); activity.Type = ActivityType.Error; } if (ex is SoapException) { throw; // Throw directly since already SoapException } else { throw FaultProvider.GetFault(visit.Version, ex); } } finally { if (activity != null) { ActivityManager.Log(activity); } } }
public TransactionStatus Solicit(AsyncContentRequest request, NamedEndpointVisit visit) { Activity activity = null; string transactionId = null; try { NodeVisit nodeVisit; MakeEndpointActivity(visit, ActivityType.Audit, NodeMethod.Solicit, out nodeVisit, out activity); if (request == null) { throw FaultProvider.GetFault(visit.Version, ENExceptionCodeType.E_InvalidParameter, "Empty input request"); } if (string.IsNullOrEmpty(request.OperationName)) { throw FaultProvider.GetFault(visit.Version, ENExceptionCodeType.E_InvalidParameter, "Input request is null"); } if ((request.FlowName == null) || string.IsNullOrEmpty(request.FlowName)) { if (visit.Version == EndpointVersionType.EN11) { bool moreThanOneFlowFound; string flowNameByServiceName = FlowManager.GetDataFlowNameByServiceName(request.OperationName, out moreThanOneFlowFound); if (string.IsNullOrEmpty(flowNameByServiceName)) { if (moreThanOneFlowFound) { throw FaultProvider.GetFault(visit.Version, ENExceptionCodeType.E_InvalidParameter, string.Format("More than one flow was found for the service \"{0}\"", request.OperationName)); } else { throw FaultProvider.GetFault(visit.Version, ENExceptionCodeType.E_InvalidParameter, string.Format("Could not find a flow for the service \"{0}\"", request.OperationName)); } } request.FlowName = flowNameByServiceName; } else { throw FaultProvider.GetFault(visit.Version, ENExceptionCodeType.E_InvalidParameter, "Input flow is null"); } } bool isFlowProtected; string flowId = FlowManager.GetDataFlowIdByName(request.FlowName, out isFlowProtected); if (flowId == null) { throw FaultProvider.GetFault(visit.Version, ENExceptionCodeType.E_InvalidDataflow, "Flow \"{0}\" was not found", request.FlowName); } activity.FlowName = request.FlowName; activity.Operation = request.OperationName; DataService solicitService = FlowManager.GetSolicitServiceForFlow(flowId, request.OperationName); if ((solicitService == null) || !solicitService.IsActive) { throw FaultProvider.GetFault(visit.Version, ENExceptionCodeType.E_ServiceUnavailable, "A valid Solicit service was not found for the flow \"{0}\" and request \"{1}\"", request.FlowName, request.OperationName); } if (isFlowProtected) { ValidateUserPermissions(nodeVisit, request.FlowName, request.OperationName, NodeMethod.Solicit, activity); } activity.AppendFormat("Solicit request from {0} by {1}. ", visit.IP, nodeVisit.Account.NaasAccount); activity.AppendFormat("Service:{0} Parameters:{1}. ", request.OperationName, ParsingHelper.ToQualifiedString(request.Parameters)); // Validate the service plugin try { PluginLoader.ValidateSolicitProcessor(solicitService); } catch (Exception) { throw FaultProvider.GetFault(visit.Version, ENExceptionCodeType.E_ServiceUnavailable, "Failed to load the Solicit service for the flow \"{0}\" and request \"{1}\"", request.FlowName, request.OperationName); } transactionId = TransactionManager.CreateTransaction(NodeMethod.Solicit, visit.Version, flowId, request.OperationName, nodeVisit.Account.Id, CommonTransactionStatusCode.Unknown, null, request.Notifications, request.Recipients, false); activity.TransactionId = transactionId; string requestId = RequestManager.CreateDataRequest(transactionId, solicitService.Id, 0, -1, RequestType.Solicit, nodeVisit.Account.Id, request.Parameters); TransactionStatus transactionStatus = TransactionManager.SetTransactionStatus(transactionId, CommonTransactionStatusCode.Received, null, false); NotificationManager.DoSolicitNotifications(transactionStatus, flowId, request.FlowName, nodeVisit.Account.NaasAccount, request.OperationName, request.Parameters); SolicitProcessor.Wakeup(); return(transactionStatus); } catch (Exception ex) { if (transactionId != null) { TransactionManager.SetTransactionStatusNoThrow(transactionId, CommonTransactionStatusCode.Failed, ex.Message, false); } if (activity != null) { activity.Append(ExceptionUtils.ToShortString(ex)); activity.Type = ActivityType.Error; } if (ex is SoapException) { throw; // Throw directly since already SoapException } else { throw FaultProvider.GetFault(visit.Version, ex); } } finally { if (activity != null) { ActivityManager.Log(activity); } } }
public PaginatedContentResult Query(PaginatedContentRequest request, NamedEndpointVisit visit) { Activity activity = null; string transactionId = null; try { NodeVisit nodeVisit; MakeEndpointActivity(visit, ActivityType.Audit, NodeMethod.Query, out nodeVisit, out activity); if (request == null) { throw FaultProvider.GetFault(visit.Version, ENExceptionCodeType.E_InvalidParameter, "Empty input request"); } if (string.IsNullOrEmpty(request.OperationName)) { throw FaultProvider.GetFault(visit.Version, ENExceptionCodeType.E_InvalidParameter, "Input request is null"); } if (string.IsNullOrEmpty(request.FlowName)) { bool moreThanOneFlowFound; string flowNameByServiceName = FlowManager.GetDataFlowNameByServiceName(request.OperationName, out moreThanOneFlowFound); if (string.IsNullOrEmpty(flowNameByServiceName)) { if (moreThanOneFlowFound) { throw FaultProvider.GetFault(visit.Version, ENExceptionCodeType.E_InvalidParameter, string.Format("More than one flow was found for the service \"{0}\"", request.OperationName)); } else { throw FaultProvider.GetFault(visit.Version, ENExceptionCodeType.E_InvalidParameter, string.Format("Could not find a flow for the service \"{0}\"", request.OperationName)); } } request.FlowName = flowNameByServiceName; } bool isFlowProtected; string flowId = FlowManager.GetDataFlowIdByName(request.FlowName, out isFlowProtected); if (flowId == null) { throw FaultProvider.GetFault(visit.Version, ENExceptionCodeType.E_InvalidDataflow, "Flow \"{0}\" was not found", request.FlowName); } activity.FlowName = request.FlowName; activity.Operation = request.OperationName; if (request.Paging == null) { throw FaultProvider.GetFault(visit.Version, ENExceptionCodeType.E_InvalidParameter, "Input paging is null"); } if (request.Paging.Count == -1) { if (request.Paging.Start != 0) { throw FaultProvider.GetFault(visit.Version, ENExceptionCodeType.E_InvalidParameter, "Start row is not valid: \"{0}\"", request.Paging.Start); } } else if (request.Paging.Count > 0) { } else { throw FaultProvider.GetFault(visit.Version, ENExceptionCodeType.E_InvalidParameter, "Max row count is not valid: \"{0}\"", request.Paging.Count); } DataService queryService = FlowManager.GetQueryServiceForFlow(flowId, request.OperationName); if ((queryService == null) || !queryService.IsActive) { throw FaultProvider.GetFault(visit.Version, ENExceptionCodeType.E_ServiceUnavailable, "A valid Query service was not found for the flow \"{0}\" and request \"{1}\"", request.FlowName, request.OperationName); } if (isFlowProtected) { ValidateUserPermissions(nodeVisit, request.FlowName, request.OperationName, NodeMethod.Query, activity); } activity.AppendFormat("Query request from {0} by {1}. ", visit.IP, nodeVisit.Account.NaasAccount); activity.AppendFormat("Service:{0} Parameters:{1} Row:{2} Rows:{3}. ", request.OperationName, ParsingHelper.ToQualifiedString(request.Parameters), request.Paging.Start.ToString(), request.Paging.Count.ToString()); // Load the service plugin IQueryProcessor plugin; IPluginDisposer disposer; try { string flowName = FlowManager.GetDataFlowNameById(queryService.FlowId); disposer = PluginLoader.LoadQueryProcessor(queryService, out plugin); } catch (Exception) { throw FaultProvider.GetFault(visit.Version, ENExceptionCodeType.E_ServiceUnavailable, "Failed to load the Query service for the flow \"{0}\" and request \"{1}\"", request.FlowName, request.OperationName); } PaginatedContentResult result; using (disposer) { transactionId = TransactionManager.CreateTransaction(NodeMethod.Query, visit.Version, flowId, request.OperationName, nodeVisit.Account.Id, CommonTransactionStatusCode.Pending, null, null, null, false); activity.TransactionId = transactionId; string requestId = RequestManager.CreateDataRequest(transactionId, queryService.Id, request.Paging.Start, request.Paging.Count, RequestType.Query, nodeVisit.Account.Id, request.Parameters); try { result = plugin.ProcessQuery(requestId); } finally { activity.Append(plugin.GetAuditLogEvents()); } } TransactionManager.SetTransactionStatus(transactionId, CommonTransactionStatusCode.Processed, null, false); NotificationManager.DoQueryNotifications(flowId, transactionId, request.FlowName, nodeVisit.Account.NaasAccount, request.OperationName, request.Paging.Start, request.Paging.Count, request.Parameters); return(result); } catch (Exception ex) { if (transactionId != null) { TransactionManager.SetTransactionStatusNoThrow(transactionId, CommonTransactionStatusCode.Failed, ex.Message, false); } if (activity != null) { activity.Append(ExceptionUtils.ToShortString(ex)); activity.Type = ActivityType.Error; } if (ex is SoapException) { throw; // Throw directly since already SoapException } else { throw FaultProvider.GetFault(visit.Version, ex); } } finally { if (activity != null) { ActivityManager.Log(activity); } } }
public TransactionStatus Notify(ComplexNotification notification, NamedEndpointVisit visit) { Activity activity = null; string transactionId = null; try { NodeVisit nodeVisit; MakeEndpointActivity(visit, ActivityType.Audit, NodeMethod.Notify, out nodeVisit, out activity); if (notification == null) { throw FaultProvider.GetFault(visit.Version, ENExceptionCodeType.E_InvalidParameter, "Empty input notification"); } if (string.IsNullOrEmpty(notification.FlowName)) { throw FaultProvider.GetFault(visit.Version, ENExceptionCodeType.E_InvalidDataflow, "Empty dataflow name"); } bool isFlowProtected; string flowId = FlowManager.GetDataFlowIdByName(notification.FlowName, out isFlowProtected); if (flowId == null) { throw FaultProvider.GetFault(visit.Version, ENExceptionCodeType.E_InvalidDataflow, "Flow \"{0}\" was not found", notification.FlowName); } activity.FlowName = notification.FlowName; if (CollectionUtils.IsNullOrEmpty(notification.Notifications)) { throw FaultProvider.GetFault(visit.Version, ENExceptionCodeType.E_InvalidParameter, "Notifications array is empty"); } if (isFlowProtected) { ValidateUserPermissions(nodeVisit, notification.FlowName, null, NodeMethod.Notify, activity); } activity.AppendFormat("Notify request from {0} by {1}.", visit.IP, nodeVisit.Account.NaasAccount); foreach (Notification notifyElement in notification.Notifications) { activity.AppendFormat("Notify element name {0}, type {1}, status.", notifyElement.Name, notifyElement.Category.ToString(), notifyElement.Status.ToString()); } transactionId = TransactionManager.CreateNotifyTransaction(flowId, string.Empty, nodeVisit.Account.Id, CommonTransactionStatusCode.Received, null, notification, visit.Version, true); activity.TransactionId = transactionId; TransactionStatus rtnTransactionStatus = new TransactionStatus(transactionId, CommonTransactionStatusCode.Received); NotificationManager.DoNotifyNotifications(rtnTransactionStatus, flowId, notification.FlowName, nodeVisit.Account.NaasAccount); NotifyProcessor.Wakeup(); return(rtnTransactionStatus); } catch (Exception ex) { if (transactionId != null) { TransactionManager.SetTransactionStatusNoThrow(transactionId, CommonTransactionStatusCode.Failed, ex.Message, false); } if (activity != null) { activity.Append(ExceptionUtils.ToShortString(ex)); activity.Type = ActivityType.Error; } if (ex is SoapException) { throw; // Throw directly since already SoapException } else { throw FaultProvider.GetFault(visit.Version, ex); } } finally { if (activity != null) { ActivityManager.Log(activity); } } }