/// <summary> /// Initializes a new instance of the <see cref="ActiveMQTriggerParameters"/> class. /// </summary> /// <param name="connectionParameters"></param> /// <param name="serviceOperationRequest"></param> public ActiveMQTriggerParameters(InsensitiveDictionary <JToken> connectionParameters, ServiceOperationRequest serviceOperationRequest) { this.connectionParameters = connectionParameters; this.serviceOperationRequest = serviceOperationRequest; BrokerUri = ServiceOperationsProviderUtilities.GetParameterValue("BrokerUri", connectionParameters).ToValue <string>(); ClientId = ServiceOperationsProviderUtilities.GetParameterValue("ClientId", connectionParameters).ToValue <string>(); UserName = ServiceOperationsProviderUtilities.GetParameterValue("UserName", connectionParameters).ToValue <string>(); Password = ServiceOperationsProviderUtilities.GetParameterValue("Password", connectionParameters).ToValue <string>(); MaximumNumber = serviceOperationRequest.Parameters["MaximumNumber"].ToValue <int>(); QueueName = serviceOperationRequest.Parameters["queue"].ToValue <string>(); }
public triggerPramsDto(InsensitiveDictionary <JToken> connectionParameters, ServiceOperationRequest serviceOperationRequest) { this.connectionParameters = connectionParameters; this.serviceOperationRequest = serviceOperationRequest; this.BrokerUri = ServiceOperationsProviderUtilities.GetParameterValue("BrokerUri", connectionParameters).ToValue <string>(); this.ClientId = ServiceOperationsProviderUtilities.GetParameterValue("ClientId", connectionParameters).ToValue <string>(); this.UserName = ServiceOperationsProviderUtilities.GetParameterValue("UserName", connectionParameters).ToValue <string>(); this.Password = ServiceOperationsProviderUtilities.GetParameterValue("Password", connectionParameters).ToValue <string>(); this.MaximumNo = serviceOperationRequest.Parameters["MaximumNo"].ToValue <int>(); this.QueueName = serviceOperationRequest.Parameters["queue"].ToValue <string>(); }
/// <summary> /// the InvokeOperation will be executed periodical to fetch the new ActiveMQ messages /// </summary> /// <param name="operationId"></param> /// <param name="connectionParameters"></param> /// <param name="serviceOperationRequest"></param> /// <returns></returns> public Task <ServiceOperationResponse> InvokeOperation(string operationId, InsensitiveDictionary <JToken> connectionParameters, ServiceOperationRequest serviceOperationRequest) { try { ServiceOpertionsProviderValidation.OperationId(operationId); ActiveMQTriggerParameters activeMQTriggerParameters = new ActiveMQTriggerParameters(connectionParameters, serviceOperationRequest); var connectionFactory = new NmsConnectionFactory(activeMQTriggerParameters.UserName, activeMQTriggerParameters.Password, activeMQTriggerParameters.BrokerUri); using (var connection = connectionFactory.CreateConnection()) { connection.ClientId = activeMQTriggerParameters.ClientId; using (var session = connection.CreateSession(AcknowledgementMode.Transactional)) { using (var queue = session.GetQueue(activeMQTriggerParameters.QueueName)) { using (var consumer = session.CreateConsumer(queue)) { connection.Start(); List <JObject> receiveMessages = new List <JObject>(); for (int i = 0; i < activeMQTriggerParameters.MaximumNumber; i++) { var message = consumer.Receive(messageReceiveTimeout) as ITextMessage; if (message != null) { receiveMessages.Add(new JObject { { "contentData", message.Text }, { "Properties", new JObject { { "NMSMessageId", message.NMSMessageId } } }, }); } else { //Will exit the loop if there are no message break; } } session.Commit(); session.Close(); connection.Close(); if (receiveMessages.Count == 0) { return(Task.FromResult((ServiceOperationResponse) new ActiveMQTriggerResponse(JObject.FromObject(new { message = "No messages" }), System.Net.HttpStatusCode.Accepted))); } else { return(Task.FromResult((ServiceOperationResponse) new ActiveMQTriggerResponse(JArray.FromObject(receiveMessages), System.Net.HttpStatusCode.OK))); } } } } } } catch (Exception e) { var error = e.Message; return(Task.FromResult((ServiceOperationResponse) new ActiveMQTriggerResponse(JObject.FromObject(new { message = error }), System.Net.HttpStatusCode.InternalServerError))); } }
Task <ServiceOperationResponse> IServiceOperationsProvider.InvokeOperation(string operationId, InsensitiveDictionary <JToken> connectionParameters, ServiceOperationRequest serviceOperationRequest) { string path = string.Empty; string outputParam = string.Empty; string serverName = string.Empty; string userName = string.Empty; string password = string.Empty; bool useSSL = false; bool implicitMode = false; bool activeMode = false; bool useSelfSignedCert = false; bool useBinaryMode = false; ServiceOperationResponse resp = null; var opResp = Task.Run(() => { try { //serverName = GetBindingConnectionInformation(operationId, connectionParameters); var folderToken = serviceOperationRequest.Parameters.GetValueOrDefault("inputParam"); if (folderToken != null) { path = folderToken.ToString(); } if (folderToken == null || string.IsNullOrEmpty(path)) { throw new ApplicationException("Unable to obtain path"); } serverName = GetBindingConnectionParameter(operationId, connectionParameters, "servername"); userName = GetBindingConnectionParameter(operationId, connectionParameters, "username"); password = GetBindingConnectionParameter(operationId, connectionParameters, "password"); useSSL = System.Convert.ToBoolean(GetBindingConnectionParameter(operationId, connectionParameters, "usessl")); implicitMode = System.Convert.ToBoolean(GetBindingConnectionParameter(operationId, connectionParameters, "implicitmode")); activeMode = System.Convert.ToBoolean(GetBindingConnectionParameter(operationId, connectionParameters, "activemode")); useSelfSignedCert = System.Convert.ToBoolean(GetBindingConnectionParameter(operationId, connectionParameters, "useSelfsignedcert")); useBinaryMode = System.Convert.ToBoolean(GetBindingConnectionParameter(operationId, connectionParameters, "usebinarymode")); FTPConfig ftpConfig = new FTPConfig(serverName, userName, password, useSSL, implicitMode, useSelfSignedCert, activeMode, useBinaryMode); Connectors.FTPCore.FTP FTP = new Connectors.FTPCore.FTP(ftpConfig); switch (operationId) { case ServiceOperationGetFile: var file = FTP.FluentGetFile(path); JProperty fileProp = new JProperty("body", file.Result); resp = new ServiceOperationResponse(fileProp.Value, System.Net.HttpStatusCode.OK); break; case ServiceOperationUploadFile: string content; var con = serviceOperationRequest.Parameters.GetValueOrDefault("content"); if (con == null) { throw new ApplicationException("Unable to read content"); } content = con.ToString(); var output = FTP.FluentUploadFile(path, content); JProperty outProp = new JProperty("body", output.Result); resp = new ServiceOperationResponse(outProp.Value, System.Net.HttpStatusCode.OK); break; case ServiceOperationDeleteFile: var deleteOutput = FTP.FluentDeleteFile(path); JProperty deleteProp = new JProperty("body", deleteOutput.Result); resp = new ServiceOperationResponse(deleteProp.Value, System.Net.HttpStatusCode.OK); break; case ServiceOperationCopyFileToBlob: string storageConnectionString; var storageConn = serviceOperationRequest.Parameters.GetValueOrDefault("storageconnectionstring"); if (storageConn == null) { throw new ApplicationException("Unable to read Storage Connection String"); } storageConnectionString = storageConn.ToString(); string targetContainer; var targetContainerParam = serviceOperationRequest.Parameters.GetValueOrDefault("targetcontainer"); if (targetContainerParam == null) { throw new ApplicationException("Unable to read Target Container"); } targetContainer = targetContainerParam.ToString(); var copyFileOutput = FTP.FluentCopyFileToBlob(path, storageConnectionString, targetContainer); JProperty copyProp = new JProperty("body", copyFileOutput.Result); resp = new ServiceOperationResponse(copyProp.Value, System.Net.HttpStatusCode.OK); break; case ServiceOperationListFile: var fileList = FTP.FluentListFiles(path); var obj = fileList.Result; List <JObject> jobjects = new List <JObject>(); foreach (var doc in fileList.Result) { jobjects.Add((JObject)doc.ToJToken()); } JProperty prop = new JProperty("body", jobjects); resp = new ServiceOperationResponse(prop.Value, System.Net.HttpStatusCode.OK); break; default: throw new NotImplementedException(); } } catch (FtpCommandException ex) { HttpStatusCode code = GetStatusCode(ex.CompletionCode); throw new ServiceOperationsProviderException( httpStatus: code, errorCode: ServiceOperationsErrorResponseCode.ServiceOperationFailed, errorMessage: ex.Message + ", completion code: " + ex.CompletionCode, null); } catch (Exception ex) { throw new ServiceOperationsProviderException( httpStatus: HttpStatusCode.InternalServerError, errorCode: ServiceOperationsErrorResponseCode.ServiceOperationFailed, errorMessage: ex.Message, innerException: ex.InnerException ); } return(resp); }); return(opResp); }
public Task <ServiceOperationResponse> InvokeActionOperation(string operationId, InsensitiveDictionary <JToken> connectionParameters, ServiceOperationRequest serviceOperationRequest) { throw new NotImplementedException(); }
public Task <ServiceOperationResponse> InvokeOperation(string operationId, InsensitiveDictionary <JToken> connectionParameters, ServiceOperationRequest serviceOperationRequest) { //System.IO.File.AppendAllText("c:\\temp\\lalogdll2.txt", $"\r\n({DateTime.Now}) start InvokeOperation "); string Error = ""; try { ServiceOpertionsProviderValidation.OperationId(operationId); triggerPramsDto _triggerPramsDto = new triggerPramsDto(connectionParameters, serviceOperationRequest); var connectionFactory = new NmsConnectionFactory(_triggerPramsDto.UserName, _triggerPramsDto.Password, _triggerPramsDto.BrokerUri); using (var connection = connectionFactory.CreateConnection()) { connection.ClientId = _triggerPramsDto.ClientId; using (var session = connection.CreateSession(AcknowledgementMode.Transactional)) { using (var queue = session.GetQueue(_triggerPramsDto.QueueName)) { using (var consumer = session.CreateConsumer(queue)) { connection.Start(); List <JObject> receiveMessages = new List <JObject>(); for (int i = 0; i < _triggerPramsDto.MaximumNo; i++) { var message = consumer.Receive(new TimeSpan(0, 0, 0, 1)) as ITextMessage; //System.IO.File.AppendAllText("c:\\temp\\lalogdll2.txt", $"\r\n({DateTime.Now}) message != null {(message != null).ToString()} "); if (message != null) { receiveMessages.Add(new JObject { { "contentData", message.Text }, { "Properties", new JObject { { "NMSMessageId", message.NMSMessageId } } }, }); } else { //the we will exit the loop if there are no message break; } } session.Commit(); session.Close(); connection.Close(); if (receiveMessages.Count == 0) { //System.IO.File.AppendAllText("c:\\temp\\lalogdll2.txt", $"\r\n({DateTime.Now}) Skip { JObject.FromObject(new { message = "No messages"} ) }"); return(Task.FromResult((ServiceOperationResponse) new ActiveMQTriggerResponse(JObject.FromObject(new { message = "No messages" }), System.Net.HttpStatusCode.Accepted))); } else { //System.IO.File.AppendAllText("c:\\temp\\lalogdll2.txt", $"\r\n({DateTime.Now}) Ok {JArray.FromObject(receiveMessages)}"); return(Task.FromResult((ServiceOperationResponse) new ActiveMQTriggerResponse(JArray.FromObject(receiveMessages), System.Net.HttpStatusCode.OK))); } } } } } } catch (Exception e) { Error = e.Message; //System.IO.File.AppendAllText("c:\\temp\\lalogdll2.txt", $"\r\n({DateTime.Now}) error {e.Message}"); } return(Task.FromResult((ServiceOperationResponse) new ActiveMQTriggerResponse(JObject.FromObject(new { message = Error }), System.Net.HttpStatusCode.InternalServerError))); }