/// <summary> /// Hangfire job to send LicenceCreationMessage to One stop. /// </summary> public async Task SendLicenceCreationMessage(PerformContext hangfireContext, string licenceGuidRaw, string suffix) { hangfireContext.WriteLine("Starting OneStop SendLicenceCreationMessage Job."); string licenceGuid = Utils.ParseGuid(licenceGuidRaw); OneStopHubService.receiveFromPartnerResponse output; var serviceClient = new OneStopHubService.http___SOAP_BCPartnerPortTypeClient(); serviceClient.ClientCredentials.UserName.UserName = Configuration["ONESTOP_HUB_USERNAME"]; serviceClient.ClientCredentials.UserName.Password = Configuration["ONESTOP_HUB_PASSWORD"]; var basicHttpBinding = new BasicHttpBinding(BasicHttpSecurityMode.Transport); basicHttpBinding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Basic; serviceClient.Endpoint.Binding = basicHttpBinding; using (new OperationContextScope(serviceClient.InnerChannel)) { //Create message header containing the credentials var header = new OneStopServiceReference.SoapSecurityHeader("", Configuration["ONESTOP_HUB_USERNAME"], Configuration["ONESTOP_HUB_PASSWORD"], ""); //Add the credentials message header to the outgoing request OperationContext.Current.OutgoingMessageHeaders.Add(header); try { var req = new ProgramAccountRequest(); var innerXML = req.CreateXML(_dynamics.GetLicenceByIdWithChildren(licenceGuid), suffix); var request = new OneStopHubService.receiveFromPartnerRequest(innerXML, "out"); output = serviceClient.receiveFromPartnerAsync(request).GetAwaiter().GetResult(); } catch (Exception ex) { hangfireContext.WriteLine($"Exception occured. {ex.Message}"); hangfireContext.WriteLine($"Cancelling"); if (_logger != null) { _logger.LogError(ex.Message); _logger.LogError(ex.StackTrace); } throw; } } hangfireContext.WriteLine(Newtonsoft.Json.JsonConvert.SerializeObject(output)); hangfireContext.WriteLine("End ofOneStop SendLicenceCreationMessage Job."); }
public System.Threading.Tasks.Task <OneStopHubService.receiveFromPartnerResponse> receiveFromPartnerAsync(OneStopHubService.receiveFromPartnerRequest request) { return(base.Channel.receiveFromPartnerAsync(request)); }
/// <summary> /// Hangfire job to send an export to SPD. /// </summary> public async Task SendLicenceCreationMessage(PerformContext hangfireContext, string licenceGuild) { hangfireContext.WriteLine("Starting OneStop SendLicenceCreationMessage Job."); OneStopHubService.receiveFromPartnerResponse output; var serviceClient = new OneStopHubService.http___SOAP_BCPartnerPortTypeClient(); serviceClient.ClientCredentials.UserName.UserName = Configuration["ONESTOP_HUB_USERNAME"]; serviceClient.ClientCredentials.UserName.Password = Configuration["ONESTOP_HUB_PASSWORD"]; var basicHttpBinding = new BasicHttpBinding(BasicHttpSecurityMode.Transport); basicHttpBinding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Basic; serviceClient.Endpoint.Binding = basicHttpBinding; using (new OperationContextScope(serviceClient.InnerChannel)) { //Create message header containing the credentials var header = new OneStopServiceReference.SoapSecurityHeader("", Configuration["ONESTOP_HUB_USERNAME"], Configuration["ONESTOP_HUB_PASSWORD"], ""); //Add the credentials message header to the outgoing request OperationContext.Current.OutgoingMessageHeaders.Add(header); try { var req = new ProgramAccountRequest(); var innerXML = req.CreateXML("guid"); var request = new OneStopHubService.receiveFromPartnerRequest(innerXML, "out"); output = serviceClient.receiveFromPartnerAsync(request).GetAwaiter().GetResult(); } catch (Exception ex) { throw; } } hangfireContext.WriteLine(Newtonsoft.Json.JsonConvert.SerializeObject(output)); //Type type = typeof(MicrosoftDynamicsCRMadoxioSpddatarow); //var csvList = new List<List<string>>(); //var headers = new List<string>(); //var headerDefinition = GetExportHeadersWorker(); //headerDefinition.ForEach(h => //{ // headers.Add($"\"{h.Value}\""); //}); //csvList.Add(headers); //string filter = $"adoxio_isexport eq true and adoxio_exporteddate eq null"; //List<MicrosoftDynamicsCRMadoxioSpddatarow> result = null; //try //{ // result = _dynamics.Spddatarows.Get(filter: filter).Value.ToList(); //} //catch (OdataerrorException odee) //{ // hangfireContext.WriteLine("Error getting SPD data rows"); // hangfireContext.WriteLine("Request:"); // hangfireContext.WriteLine(odee.Request.Content); // hangfireContext.WriteLine("Response:"); // hangfireContext.WriteLine(odee.Response.Content); // fail if we can't get results. // throw (odee); //} //var batch = GetBatchNumber().ToString(); //batch = AddZeroPadding(batch); //if (result != null && result.Count > 0) //{ // foreach (var row in result) // { // var item = new List<string>(); // foreach (var h in headerDefinition) // { // try // { // object value = row[h.Key]; // if (value != null) // { // item.Add($"\"{value.ToString()}\""); // } // else // { // item.Add("\"\""); // } // } // catch (Exception) // { // item.Add("\"\""); ; // } // } // csvList.Add(item); // } // var csv = new StringBuilder(); // csvList.ForEach(row => // { // var line = String.Join(",", row); // csv.AppendLine(line); // }); // var datePart = DateTime.Now.ToString("yyyyMMdd_HHmmss"); // var attachmentName = $@"{batch}_Request_Worker_{datePart}.csv"; // File.WriteAllText($@".\{attachmentName}", csv.ToString()); // if (SendSPDEmail(csv.ToString(), attachmentName)) // { // hangfireContext.WriteLine("Sent SPD email. Now updating Dynamics..."); // update exporteddate in dynamics // var exportDate = DateTime.Now; // result.ForEach(row => // { // var patchApplication = new MicrosoftDynamicsCRMadoxioSpddatarow() // { // AdoxioExporteddate = exportDate // }; // try // { // if (row.AdoxioSpddatarowid != null) // skip test data // { // _dynamics.Spddatarows.Update(row.AdoxioSpddatarowid, patchApplication); // } // } // catch (OdataerrorException odee) // { // hangfireContext.WriteLine("Error updating application"); // hangfireContext.WriteLine("Request:"); // hangfireContext.WriteLine(odee.Request.Content); // hangfireContext.WriteLine("Response:"); // hangfireContext.WriteLine(odee.Response.Content); // fail if we can't create. // throw (odee); // } // }); // hangfireContext.WriteLine("Dynamics update complete."); // } // else // { // hangfireContext.WriteLine("Error sending SPD email."); // } //} //else //{ // hangfireContext.WriteLine("No data to send, sending a null email."); // SendSPDNoResultsEmail(batch); //} hangfireContext.WriteLine("End ofOneStop SendLicenceCreationMessage Job."); }
/// <summary> /// Hangfire job to send LicenceDetailsMessage to One stop. /// </summary> public async Task SendProgramAccountDetailsBroadcastMessage(PerformContext hangfireContext, string licenceGuidRaw) { if (hangfireContext != null) { hangfireContext.WriteLine("Starting OneStop SendLicenceCreationMessage Job."); } string licenceGuid = FormatGuidForDynamics(licenceGuidRaw); OneStopHubService.receiveFromPartnerResponse output; var serviceClient = new OneStopHubService.http___SOAP_BCPartnerPortTypeClient(); serviceClient.ClientCredentials.UserName.UserName = Configuration["ONESTOP_HUB_USERNAME"]; serviceClient.ClientCredentials.UserName.Password = Configuration["ONESTOP_HUB_PASSWORD"]; var basicHttpBinding = new BasicHttpBinding(BasicHttpSecurityMode.Transport); basicHttpBinding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Basic; serviceClient.Endpoint.Binding = basicHttpBinding; using (new OperationContextScope(serviceClient.InnerChannel)) { //Create message header containing the credentials var header = new OneStopServiceReference.SoapSecurityHeader("", Configuration["ONESTOP_HUB_USERNAME"], Configuration["ONESTOP_HUB_PASSWORD"], ""); //Add the credentials message header to the outgoing request OperationContext.Current.OutgoingMessageHeaders.Add(header); try { var req = new ProgramAccountDetailsBroadcast(); if (hangfireContext != null) { hangfireContext.WriteLine($"Getting licence {licenceGuid}"); } MicrosoftDynamicsCRMadoxioLicences licence = GetLicenceFromDynamics(hangfireContext, licenceGuid); if (hangfireContext != null) { hangfireContext.WriteLine("Got licence. Creating XML request"); } var innerXML = req.CreateXML(licence); hangfireContext.WriteLine("Sending request."); var request = new OneStopHubService.receiveFromPartnerRequest(innerXML, "out"); output = serviceClient.receiveFromPartnerAsync(request).GetAwaiter().GetResult(); } catch (Exception ex) { if (_logger != null) { _logger.LogError(ex.Message); _logger.LogError(ex.StackTrace); } if (hangfireContext != null) { hangfireContext.WriteLine("Error sending program account details broadcast:"); hangfireContext.WriteLine(ex.Message); } throw; } } if (hangfireContext != null) { hangfireContext.WriteLine(Newtonsoft.Json.JsonConvert.SerializeObject(output)); hangfireContext.WriteLine("End ofOneStop SendLicenceCreationMessage Job."); } }