/// <summary> /// GetStatus /// </summary> /// <param name="securityToken"></param> /// <param name="transactionId"></param> /// <returns></returns> string INetworkNodeBinding.GetStatus(string securityToken, string transactionId) { Init(); LOG.Debug("GetStatus"); #region Validate if (string.IsNullOrEmpty(transactionId)) { throw _service11Provider.FaultProvider.GetFault(EndpointVersionType.EN11, ENExceptionCodeType.E_InvalidParameter, "NULL transactionId argument"); } #endregion try { LOG.Debug("Getting visit"); NamedEndpointVisit visit = _service11Provider.VisitProvider.GetVisit(securityToken); LOG.Debug("GetStatus using visit: " + visit); TransactionStatus tranStatus = _service11Provider.TransactionService.GetStatus( new SimpleId(transactionId), visit); LOG.Debug("TransactionStatus: " + tranStatus); return(CommonTransactionStatusCodeProvider.ConvertTo11Enum(tranStatus.Status)); } catch (Exception ex) { LOG.Error("Error while getting status", ex); throw _service11Provider.FaultProvider.GetFault(EndpointVersionType.EN11, ex); } }
/// <summary> /// Get Named User Visit /// </summary> /// <param name="token"></param> /// <returns></returns> public NamedEndpointVisit GetVisit(string token) { LOG.Debug("Visit from token: " + token); NamedEndpointVisit visit = GetVisit <NamedEndpointVisit>(); visit.Token = token; LOG.Debug("Visit: " + visit); return(visit); }
/// <summary> /// Solicit /// </summary> /// <param name="securityToken"></param> /// <param name="returnURL"></param> /// <param name="request"></param> /// <param name="parameters"></param> /// <returns></returns> string INetworkNodeBinding.Solicit(string securityToken, string returnURL, string request, string[] parameters) { Init(); LOG.Debug("Solicit"); #region Validate if (string.IsNullOrEmpty(securityToken)) { throw _service11Provider.FaultProvider.GetFault(EndpointVersionType.EN11, ENExceptionCodeType.E_InvalidParameter, "NULL SecurityToken argument"); } if (string.IsNullOrEmpty(request)) { throw _service11Provider.FaultProvider.GetFault(EndpointVersionType.EN11, ENExceptionCodeType.E_InvalidParameter, "NULL Request argument"); } #endregion Validate try { LOG.Debug("Getting visit"); NamedEndpointVisit visit = _service11Provider.VisitProvider.GetVisit(securityToken); AsyncContentRequest asyncRequest = new AsyncContentRequest(); asyncRequest.FlowName = null; //TODO: Make sure the flow can't be derived from the Flow asyncRequest.OperationName = request; asyncRequest.Parameters = CreateParameters(parameters); asyncRequest.Notifications = CreateNotifications(returnURL); LOG.Debug("Soliciting: " + asyncRequest); TransactionStatus status = _service11Provider.TransactionService.Solicit(asyncRequest, visit); LOG.Debug("Status: " + status.Id); return(status.Id); } catch (Exception ex) { LOG.Error("Error while soliciting", ex); throw _service11Provider.FaultProvider.GetFault(EndpointVersionType.EN11, ex); } }
/// <summary> /// Make a generic Endpoint visit /// </summary> /// <typeparam name="T"></typeparam> /// <param name="visit"></param> /// <returns>Activity</returns> protected void MakeEndpointActivity(NamedEndpointVisit visit, ActivityType activityType, NodeMethod method, out NodeVisit nodeVisit, out Activity activity) { if (visit == null) { throw new ArgumentNullException("visit"); } activity = new Activity(method, null, null, activityType, null, visit.IP, "Visit from endpoint version {0} for method {1}.", visit.Version, method.ToString()); activity.AppendFormat("Attempting to validate user token {0} from IP {1}.", visit.Token, visit.IP); string username = AuthProvider.Validate(visit.Token, visit.IP); activity.AppendFormat("Successfully validated user token {0} with user name {1}.", visit.Token, username); bool wasCreated; UserAccount userAccount = AccountManager.GetOrCreate(username, true, out wasCreated); activity.ModifiedById = userAccount.Id; IDictionary <string, string> flowsIdToNameMap = _flowManager.GetAllFlowsIdToNameMap(); nodeVisit = new NodeVisit(userAccount, visit.IP, flowsIdToNameMap); if (wasCreated) { activity.AppendFormat("Successfully created local user account for {0}.", username); } else { activity.AppendFormat("Successfully got local user account for {0}.", username); } }
public SimpleContent GetMetaData(string category, NamedEndpointVisit visit) { PaginatedContentRequest request = new PaginatedContentRequest(); request.FlowName = "ENDS_v20"; request.OperationName = "GetServices"; request.Paging = new PaginationIndicator(); request.Paging.Start = 0; request.Paging.Count = -1; if (visit.Version == EndpointVersionType.EN20) { request.Parameters = new ByIndexOrNameDictionary <string>(true); request.Parameters.Add("ServiceCategory", category); } else { request.Parameters = new ByIndexOrNameDictionary <string>(false); request.Parameters.Add(category); } PaginatedContentResult result = _transactionService.Query(request, visit); return(result.Content); }
/// <summary> /// Query /// </summary> /// <param name="securityToken"></param> /// <param name="request"></param> /// <param name="rowId"></param> /// <param name="maxRows"></param> /// <param name="parameters"></param> /// <returns></returns> string INetworkNodeBinding.Query(string securityToken, string request, string rowId, string maxRows, string[] parameters) { Init(); LOG.Debug("Query"); #region Validate if (string.IsNullOrEmpty(securityToken)) { throw _service11Provider.FaultProvider.GetFault(EndpointVersionType.EN11, ENExceptionCodeType.E_InvalidParameter, "NULL SecurityToken argument"); } if (string.IsNullOrEmpty(request)) { throw _service11Provider.FaultProvider.GetFault(EndpointVersionType.EN11, ENExceptionCodeType.E_InvalidParameter, "NULL Request argument"); } int rowIdValue; if (!int.TryParse(rowId, out rowIdValue) || (rowIdValue < 0)) { throw _service11Provider.FaultProvider.GetFault(EndpointVersionType.EN11, ENExceptionCodeType.E_InvalidParameter, "Invalid RowId argument"); } int maxRowsValue; if (!int.TryParse(maxRows, out maxRowsValue) || !((maxRowsValue == -1) || (maxRowsValue > 0))) { throw _service11Provider.FaultProvider.GetFault(EndpointVersionType.EN11, ENExceptionCodeType.E_InvalidParameter, "Invalid MaxRows argument"); } #endregion Validate try { LOG.Debug("Getting visit"); NamedEndpointVisit visit = _service11Provider.VisitProvider.GetVisit(securityToken); PaginatedContentRequest pagRequest = new PaginatedContentRequest(); pagRequest.FlowName = null; //TODO: use the name to derive it. pagRequest.OperationName = request; pagRequest.Paging = new PaginationIndicator(); pagRequest.Paging.Start = rowIdValue; pagRequest.Paging.Count = maxRowsValue; pagRequest.Parameters = CreateParameters(parameters); LOG.Debug("Querying: " + pagRequest); PaginatedContentResult resultSet = _service11Provider.TransactionService.Query(pagRequest, visit); LOG.Debug("ResultSet: " + resultSet); if (resultSet == null || resultSet.Content == null || resultSet.Content.Content == null) { throw _service11Provider.FaultProvider.GetFault(EndpointVersionType.EN11, ENExceptionCodeType.E_Unknown, "NULL Content"); } return(ConvertBytesToString(resultSet.Content.Content)); } catch (Exception ex) { LOG.Error("Error while querying", ex); throw _service11Provider.FaultProvider.GetFault(EndpointVersionType.EN11, ex); } }
/// <summary> /// Download /// </summary> /// <param name="securityToken"></param> /// <param name="transactionId"></param> /// <param name="dataflow"></param> /// <param name="documents"></param> void INetworkNodeBinding.Download(string securityToken, string transactionId, string dataflow, ref NodeDocument[] documents) { Init(); LOG.Debug("Download"); if (string.IsNullOrEmpty(transactionId)) { throw _service11Provider.FaultProvider.GetFault(EndpointVersionType.EN11, ENExceptionCodeType.E_InvalidParameter, "NULL Transaction Id"); } try { SoapContext res = HttpSoapContext.ResponseContext; LOG.Debug("Getting visit"); NamedEndpointVisit visit = _service11Provider.VisitProvider.GetVisit(securityToken); ComplexContent content = new ComplexContent(); if (!string.IsNullOrEmpty(dataflow)) { content.Flow = new OperationDataFlow(dataflow); } content.Transaction = new SimpleId(transactionId); LOG.Debug("Submitting: " + content); IList <Document> wnosDocs = _service11Provider.ContentService.Download(content, visit); List <NodeDocument> wsdlDocList = new List <NodeDocument>(); if (!CollectionUtils.IsNullOrEmpty(wnosDocs)) { Dictionary <string, string> docIdList = new Dictionary <string, string>(); LOG.Debug("Spooling documents"); foreach (Document wnosDoc in wnosDocs) { NodeDocument doc = new NodeDocument(); doc.content = wnosDoc.Content; doc.type = CommonContentAndFormatProvider.ConvertTo11Enum(wnosDoc.Type); doc.name = wnosDoc.DocumentName; LOG.Debug(" doc:" + doc); DimeAttachment attachment = new DimeAttachment(); attachment.Stream = new MemoryStream(doc.content); attachment.TypeFormat = TypeFormatEnum.MediaType; attachment.Type = "application/x-gzip"; attachment.Id = Guid.NewGuid().ToString(); //Add to the the xref filter collection docIdList.Add(doc.name, attachment.Id); res.Attachments.Add(attachment); wsdlDocList.Add(doc); } //Output filter specific res.Add("hrefs", docIdList); } documents = wsdlDocList.ToArray(); } catch (Exception ex) { LOG.Error("Error while downloading", ex); throw _service11Provider.FaultProvider.GetFault(EndpointVersionType.EN11, ex); } }
/// <summary> /// /// </summary> /// <param name="securityToken"></param> /// <param name="nodeAddress"></param> /// <param name="dataflow"></param> /// <param name="documents"></param> /// <returns></returns> string INetworkNodeBinding.Notify(string securityToken, string nodeAddress, string dataflow, NodeDocument[] documents) { Init(); LOG.Debug("Notify"); #region Validate if (documents == null || documents.Length == 0) { throw _service11Provider.FaultProvider.GetFault(EndpointVersionType.EN11, ENExceptionCodeType.E_InvalidParameter, "Document not provided"); } if (documents.Length > 1) { throw _service11Provider.FaultProvider.GetFault(EndpointVersionType.EN11, ENExceptionCodeType.E_InvalidParameter, "Only one document per notification allowed"); } SoapContext context = HttpSoapContext.RequestContext; if (context.Attachments != null && context.Attachments.Count > 0) { // TODO: Mark, why is this check here? Calling Notify() from the endpoint client NotifyEvent(), NotifyStatus(), etc. methods fail here throw _service11Provider.FaultProvider.GetFault(EndpointVersionType.EN11, ENExceptionCodeType.E_InvalidParameter, "Notify does not use DIME. Put content in the message."); } if (string.IsNullOrEmpty(dataflow)) { throw _service11Provider.FaultProvider.GetFault(EndpointVersionType.EN11, ENExceptionCodeType.E_InvalidParameter, "NULL dataflow argument"); } #endregion try { LOG.Debug("Getting visit"); NamedEndpointVisit visit = _service11Provider.VisitProvider.GetVisit(securityToken); NotificationMessageCategoryType messageCategory = NotificationMessageCategoryType.None; switch (dataflow.Trim().ToLower()) { case "http://www.exchangenetwork.net/node/event": messageCategory = NotificationMessageCategoryType.Event; break; case "http://www.exchangenetwork.net/node/status": messageCategory = NotificationMessageCategoryType.Status; break; case "other": messageCategory = NotificationMessageCategoryType.Status; break; default: throw _service11Provider.FaultProvider.GetFault(EndpointVersionType.EN11, ENExceptionCodeType.E_InvalidParameter, "Invalid dataflow argument: " + dataflow); } ComplexNotification notif = new ComplexNotification(); notif.FlowName = dataflow; notif.Uri = nodeAddress; notif.Notifications = new List <Notification>(); LOG.Debug("Spooling documents"); foreach (NodeDocument wsdlDoc in documents) { Notification not = new Notification(); not.Category = messageCategory; not.Name = wsdlDoc.name; not.Status = new TransactionStatus(); not.Status.Status = CommonTransactionStatusCodeProvider.Convert(wsdlDoc.type); not.Status.Description = Encoding.ASCII.GetString(wsdlDoc.content); LOG.Debug(" Notification:" + not); notif.Notifications.Add(not); } LOG.Debug("GetStatus using visit: " + visit); TransactionStatus tranStatus = _service11Provider.TransactionService.Notify(notif, visit); LOG.Debug("TransactionStatus: " + tranStatus); return(CommonTransactionStatusCodeProvider.ConvertTo11Enum(tranStatus.Status)); } catch (Exception ex) { LOG.Error("Error while fotifying", ex); throw _service11Provider.FaultProvider.GetFault(EndpointVersionType.EN11, ex); } }
/// <summary> /// Submit /// </summary> /// <param name="securityToken"></param> /// <param name="transactionId"></param> /// <param name="dataflow"></param> /// <param name="documents"></param> /// <returns></returns> string INetworkNodeBinding.Submit(string securityToken, string transactionId, string dataflow, NodeDocument[] documents) { Init(); LOG.Debug("Submit"); if (documents == null || documents.Length == 0) { throw _service11Provider.FaultProvider.GetFault(EndpointVersionType.EN11, ENExceptionCodeType.E_InvalidParameter, "Document not provided"); } SoapContext context = HttpSoapContext.RequestContext; bool useDimeAttachments = true; if (context == null || context.Attachments == null || context.Attachments.Count == 0) { bool allContentNull = true; bool anyContentMissing = false; foreach (NodeDocument document in documents) { if (document.content == null) { anyContentMissing = true; } else { allContentNull = false; } } if (anyContentMissing) { if (!allContentNull) { // Some documents contain content, some don't, what the heck is this??? throw _service11Provider.FaultProvider.GetFault(EndpointVersionType.EN11, ENExceptionCodeType.E_InvalidParameter, "Some documents do not contain any content."); } // All document content is null, attempt to locate all <content> elements in the xml itself XmlNodeList nodeList = context.Envelope.Body.GetElementsByTagName("content"); if ((nodeList == null) || (nodeList.Count != documents.Length)) { throw _service11Provider.FaultProvider.GetFault(EndpointVersionType.EN11, ENExceptionCodeType.E_InvalidParameter, "Could not locate the data content for the submitted documents."); } int index = 0; foreach (NodeDocument document in documents) { XmlNode contentContentNode = nodeList[index++]; if (string.IsNullOrEmpty(contentContentNode.InnerXml)) { throw _service11Provider.FaultProvider.GetFault(EndpointVersionType.EN11, ENExceptionCodeType.E_InvalidParameter, "Some documents do not contain any content."); } document.content = System.Convert.FromBase64String(contentContentNode.InnerXml); } } useDimeAttachments = false; } else if (context.Attachments.Count != documents.Length) { throw _service11Provider.FaultProvider.GetFault(EndpointVersionType.EN11, ENExceptionCodeType.E_InvalidParameter, "DIME attachment count does not equal to the number of documents."); } try { LOG.Debug("Getting visit"); NamedEndpointVisit visit = _service11Provider.VisitProvider.GetVisit(securityToken); AsyncComplexContent content = new AsyncComplexContent(); content.Documents = new List <Document>(); content.Flow = new OperationDataFlow(dataflow); content.Transaction = new SimpleId(transactionId); int attachmentCounter = 0; LOG.Debug("Spooling documents"); foreach (NodeDocument wsdlDoc in documents) { Document doc = new Document(); doc.Content = useDimeAttachments ? GetContent(context.Attachments[attachmentCounter++].Stream) : wsdlDoc.content; doc.Type = CommonContentAndFormatProvider.Convert(wsdlDoc.type); doc.DocumentId = string.Empty; doc.DocumentName = wsdlDoc.name; LOG.Debug(" doc:" + doc); content.Documents.Add(doc); } LOG.Debug("Submitting: " + content); TransactionStatus status = _service11Provider.ContentService.Submit(content, visit); LOG.Debug("Status: " + status); return(status.Id); //Status ID in this case is the transaction id } catch (Exception ex) { LOG.Error("Error while submitting", ex); throw _service11Provider.FaultProvider.GetFault(EndpointVersionType.EN11, ex); } }
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); } } }