public async Task SendProgramAccountRequestREST(PerformContext hangfireContext, string licenceGuidRaw, string suffix, string queueItemId) { hangfireContext?.WriteLine("Starting OneStop ProgramAccountRequest Job."); IDynamicsClient dynamicsClient = DynamicsSetupUtil.SetupDynamics(_configuration); string licenceGuid = Utils.ParseGuid(licenceGuidRaw); // prepare soap message var req = new ProgramAccountRequest(); hangfireContext?.WriteLine($"Getting Licence {licenceGuid}"); var licence = dynamicsClient.GetLicenceByIdWithChildren(licenceGuid); if (hangfireContext != null && licence != null) { hangfireContext.WriteLine($"Got Licence {licenceGuid}."); } if (licence == null) { hangfireContext?.WriteLine($"Unable to get licence {licenceGuid}."); Log.Logger?.Error($"Unable to get licence {licenceGuid}."); } else { // only send the request if Dynamics says the licence is not sent yet. if (licence.AdoxioOnestopsent == null || licence.AdoxioOnestopsent == false) { var innerXml = req.CreateXML(licence, suffix); innerXml = _onestopRestClient.CleanXML(innerXml); Log.Logger?.Information(innerXml); // send message to Onestop hub var outputXml = await _onestopRestClient.ReceiveFromPartner(innerXml); UpdateQueueItemForSend(dynamicsClient, hangfireContext, queueItemId, innerXml, outputXml); if (hangfireContext != null) { hangfireContext.WriteLine(outputXml); } } else { hangfireContext?.WriteLine($"Skipping ProgramAccountRequest for Licence {licence.AdoxioName} {licenceGuid} as the record is marked as sent to OneStop."); Log.Logger?.Error($"Skipping ProgramAccountRequest for Licence {licence.AdoxioName} {licenceGuid} as the record is marked as sent to OneStop."); } } hangfireContext?.WriteLine("End of OneStop ProgramAccountRequest Job."); }
public async Task SendLicenceCreationMessageREST(PerformContext hangfireContext, string licenceGuidRaw, string suffix) { if (hangfireContext != null) { hangfireContext.WriteLine("Starting OneStop SendLicenceCreationMessage Job."); } string licenceGuid = Utils.ParseGuid(licenceGuidRaw); // prepare soap message var req = new ProgramAccountRequest(); if (hangfireContext != null) { hangfireContext.WriteLine($"Getting Licence {licenceGuid}"); } var licence = _dynamics.GetLicenceByIdWithChildren(licenceGuid); if (hangfireContext != null && licence != null) { hangfireContext.WriteLine($"Got Licence {licenceGuid}."); } if (licence == null) { if (hangfireContext != null) { hangfireContext.WriteLine($"Unable to get licence {licenceGuid}."); } if (_logger != null) { _logger.LogError($"Unable to get licence {licenceGuid}."); } } else { var innerXML = req.CreateXML(licence, suffix); // send message to Onestop hub var outputXML = await _onestopRestClient.receiveFromPartner(innerXML); if (hangfireContext != null) { hangfireContext.WriteLine(outputXML); hangfireContext.WriteLine("End ofOneStop SendLicenceCreationMessage Job."); } } }
/// <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."); }
/// <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."); }