/// <summary> /// Check the import mailbox. Returns the first CSV file in the mailbox. /// </summary> /// <returns></returns> public async Task CheckMailBoxForImport(PerformContext hangfireContext) { Pop3Client pop3Client = new Pop3Client(); await pop3Client.ConnectAsync(Configuration["SPD_IMPORT_POP3_SERVER"], Configuration["SPD_IMPORT_POP3_USERNAME"], Configuration["SPD_IMPORT_POP3_PASSWORD"], true); List <Pop3Message> messages = (await pop3Client.ListAndRetrieveAsync()).ToList(); foreach (Pop3Message message in messages) { var attachments = message.Attachments.ToList(); if (attachments.Count > 0) { // string payload = null; // File.ReadAllText("C:\\tmp\\testimport.csv"); string payload = Encoding.Default.GetString(attachments[0].GetData()); if (payload != null) // parse the payload { List <WorkerResponse> responses = WorkerResponseParser.ParseWorkerResponse(payload); foreach (WorkerResponse workerResponse in responses) { // search for the Personal History Record. MicrosoftDynamicsCRMadoxioPersonalhistorysummary record = _dynamics.Personalhistorysummaries.GetByWorkerJobNumber(workerResponse.RecordIdentifier); if (record != null) { // update the record. MicrosoftDynamicsCRMadoxioPersonalhistorysummary patchRecord = new MicrosoftDynamicsCRMadoxioPersonalhistorysummary() { AdoxioSecuritystatus = SPDResultTranslate.GetTranslatedSecurityStatus(workerResponse.Result), AdoxioCompletedon = workerResponse.DateProcessed }; try { _dynamics.Personalhistorysummaries.Update(record.AdoxioPersonalhistorysummaryid, patchRecord); } catch (OdataerrorException odee) { hangfireContext.WriteLine("Error updating worker personal history"); hangfireContext.WriteLine("Request:"); hangfireContext.WriteLine(odee.Request.Content); hangfireContext.WriteLine("Response:"); hangfireContext.WriteLine(odee.Response.Content); } } } } } await pop3Client.DeleteAsync(message); hangfireContext.WriteLine("Deleted message:"); } }
public async Task UpdateSecurityClearance(PerformContext hangfireContext, WorkerResponse spdResponse, string id) { var filter = "adoxio_workerjobnumber eq '" + id + "'"; List <string> expand = new List <string> { "adoxio_WorkerId" }; MicrosoftDynamicsCRMadoxioPersonalhistorysummary response = null; try { response = _dynamics.Personalhistorysummaries.Get(filter: filter).Value.FirstOrDefault(); } catch (OdataerrorException odee) { hangfireContext.WriteLine("Unable to get personal history summary."); hangfireContext.WriteLine("Request:"); hangfireContext.WriteLine(odee.Request.Content); hangfireContext.WriteLine("Response:"); hangfireContext.WriteLine(odee.Response.Content); _logger.LogError("Unable to get personal history summary."); _logger.LogError("Request:"); _logger.LogError(odee.Request.Content); _logger.LogError("Response:"); _logger.LogError(odee.Request.Content); throw odee; } MicrosoftDynamicsCRMadoxioPersonalhistorysummary patchPHS = new MicrosoftDynamicsCRMadoxioPersonalhistorysummary { AdoxioSecuritystatus = (int)Enum.Parse(typeof(SecurityStatusPicklist), spdResponse.Result, true), AdoxioCompletedon = spdResponse.DateProcessed }; try { await _dynamics.Personalhistorysummaries.UpdateAsync(response.AdoxioPersonalhistorysummaryid, patchPHS); } catch (OdataerrorException odee) { hangfireContext.WriteLine("Unable to patch personal history summary."); hangfireContext.WriteLine("Request:"); hangfireContext.WriteLine(odee.Request.Content); hangfireContext.WriteLine("Response:"); hangfireContext.WriteLine(odee.Response.Content); _logger.LogError("Unable to patch personal history summary."); _logger.LogError("Request:"); _logger.LogError(odee.Request.Content); _logger.LogError("Response:"); _logger.LogError(odee.Request.Content); throw odee; } }
public void ReceiveWorkerImportJob(PerformContext hangfireContext, List <CompletedWorkerScreening> responses) { hangfireContext.WriteLine("Starting SPICE Import Job for Worker Screening."); _logger.LogError("Starting SPICE Import Job for Worker Screening."); foreach (var workerResponse in responses) { try { string contactId; // 3 different ways to send an identifier 😷 if (workerResponse.RecordIdentifier == null) { MicrosoftDynamicsCRMcontact contact = _dynamicsClient.Contacts.Get(filter: $"adoxio_spdjobid eq {workerResponse.SpdJobId}").Value[0]; contactId = contact.Contactid; } else if (workerResponse.RecordIdentifier.Substring(0, 2) == "WR") { // Check if using old WR record MicrosoftDynamicsCRMadoxioPersonalhistorysummary history = _dynamicsClient.Personalhistorysummaries.Get(filter: $"adoxio_workerjobnumber eq '{workerResponse.RecordIdentifier}'").Value[0]; contactId = history._adoxioContactidValue; } else { contactId = workerResponse.RecordIdentifier; } string filter = $"_adoxio_contactid_value eq {contactId}"; MicrosoftDynamicsCRMadoxioWorker worker = _dynamicsClient.Workers.Get(filter: filter).Value.FirstOrDefault(); if (worker != null) { // update the record. MicrosoftDynamicsCRMadoxioWorker patchRecord = new MicrosoftDynamicsCRMadoxioWorker() { Statuscode = workerResponse.ScreeningResult switch { WorkerSecurityStatus.Pass => (int)WorkerSecurityStatusCode.Active, WorkerSecurityStatus.Fail => (int)WorkerSecurityStatusCode.Rejected, WorkerSecurityStatus.Withdrawn => (int)WorkerSecurityStatusCode.Withdrawn }, AdoxioSecuritystatus = (int)workerResponse.ScreeningResult, AdoxioSecuritycompletedon = DateTimeOffset.Now }; // Do passed worker things if (workerResponse.ScreeningResult == WorkerSecurityStatus.Pass) { patchRecord.AdoxioExpirydate = DateTimeOffset.Now.AddYears(2); } _dynamicsClient.Workers.Update(worker.AdoxioWorkerid, patchRecord); }
public static MicrosoftDynamicsCRMadoxioPersonalhistorysummary GetByWorkerJobNumber(this IPersonalhistorysummaries operations, string workerJobNumber) { MicrosoftDynamicsCRMadoxioPersonalhistorysummary result = null; try { string jobNumberFilter = "adoxio_workerjobnumber eq '" + workerJobNumber + "'"; IEnumerable <MicrosoftDynamicsCRMadoxioPersonalhistorysummary> dataRows = operations.Get(filter: jobNumberFilter).Value; result = dataRows.FirstOrDefault(); } catch (OdataerrorException) { result = null; } return(result); }
/// <summary> /// Import responses to Dynamics. /// </summary> /// <returns></returns> private void ImportResponses(PerformContext hangfireContext, List <WorkerResponse> responses) { foreach (WorkerResponse workerResponse in responses) { // search for the Personal History Record. MicrosoftDynamicsCRMadoxioPersonalhistorysummary record = _dynamics.Personalhistorysummaries.GetByWorkerJobNumber(workerResponse.RecordIdentifier); if (record != null) { // update the record. MicrosoftDynamicsCRMadoxioPersonalhistorysummary patchRecord = new MicrosoftDynamicsCRMadoxioPersonalhistorysummary() { AdoxioSecuritystatus = SPDResultTranslate.GetTranslatedSecurityStatus(workerResponse.Result), AdoxioCompletedon = workerResponse.DateProcessed }; try { _dynamics.Personalhistorysummaries.Update(record.AdoxioPersonalhistorysummaryid, patchRecord); } catch (HttpOperationException odee) { hangfireContext.WriteLine("Error updating worker personal history"); hangfireContext.WriteLine("Request:"); hangfireContext.WriteLine(odee.Request.Content); hangfireContext.WriteLine("Response:"); hangfireContext.WriteLine(odee.Response.Content); _logger.LogError("Error updating worker personal history"); _logger.LogError("Request:"); _logger.LogError(odee.Request.Content); _logger.LogError("Response:"); _logger.LogError(odee.Response.Content); } } } }
/// <summary> /// Update entity in adoxio_personalhistorysummaries /// </summary> /// <param name='adoxioPersonalhistorysummaryid'> /// key: adoxio_personalhistorysummaryid /// </param> /// <param name='body'> /// New property values /// </param> /// <param name='customHeaders'> /// Headers that will be added to request. /// </param> /// <param name='cancellationToken'> /// The cancellation token. /// </param> /// <exception cref="OdataerrorException"> /// Thrown when the operation returned an invalid status code /// </exception> /// <exception cref="ValidationException"> /// Thrown when a required parameter is null /// </exception> /// <exception cref="System.ArgumentNullException"> /// Thrown when a required parameter is null /// </exception> /// <return> /// A response object containing the response body and response headers. /// </return> public async Task <HttpOperationResponse> UpdateWithHttpMessagesAsync(string adoxioPersonalhistorysummaryid, MicrosoftDynamicsCRMadoxioPersonalhistorysummary body, Dictionary <string, List <string> > customHeaders = null, CancellationToken cancellationToken = default(CancellationToken)) { if (adoxioPersonalhistorysummaryid == null) { throw new ValidationException(ValidationRules.CannotBeNull, "adoxioPersonalhistorysummaryid"); } if (body == null) { throw new ValidationException(ValidationRules.CannotBeNull, "body"); } // Tracing bool _shouldTrace = ServiceClientTracing.IsEnabled; string _invocationId = null; if (_shouldTrace) { _invocationId = ServiceClientTracing.NextInvocationId.ToString(); Dictionary <string, object> tracingParameters = new Dictionary <string, object>(); tracingParameters.Add("adoxioPersonalhistorysummaryid", adoxioPersonalhistorysummaryid); tracingParameters.Add("body", body); tracingParameters.Add("cancellationToken", cancellationToken); ServiceClientTracing.Enter(_invocationId, this, "Update", tracingParameters); } // Construct URL var _baseUrl = Client.BaseUri.AbsoluteUri; var _url = new System.Uri(new System.Uri(_baseUrl + (_baseUrl.EndsWith("/") ? "" : "/")), "adoxio_personalhistorysummaries({adoxio_personalhistorysummaryid})").ToString(); _url = _url.Replace("{adoxio_personalhistorysummaryid}", System.Uri.EscapeDataString(adoxioPersonalhistorysummaryid)); // Create HTTP transport objects var _httpRequest = new HttpRequestMessage(); HttpResponseMessage _httpResponse = null; _httpRequest.Method = new HttpMethod("PATCH"); _httpRequest.RequestUri = new System.Uri(_url); // Set Headers if (customHeaders != null) { foreach (var _header in customHeaders) { if (_httpRequest.Headers.Contains(_header.Key)) { _httpRequest.Headers.Remove(_header.Key); } _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); } } // Serialize Request string _requestContent = null; if (body != null) { _requestContent = Microsoft.Rest.Serialization.SafeJsonConvert.SerializeObject(body, Client.SerializationSettings); _httpRequest.Content = new StringContent(_requestContent, System.Text.Encoding.UTF8); _httpRequest.Content.Headers.ContentType = System.Net.Http.Headers.MediaTypeHeaderValue.Parse("application/json; charset=utf-8"); } // Set Credentials if (Client.Credentials != null) { cancellationToken.ThrowIfCancellationRequested(); await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); } // Send Request if (_shouldTrace) { ServiceClientTracing.SendRequest(_invocationId, _httpRequest); } cancellationToken.ThrowIfCancellationRequested(); _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); if (_shouldTrace) { ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); } HttpStatusCode _statusCode = _httpResponse.StatusCode; cancellationToken.ThrowIfCancellationRequested(); string _responseContent = null; if ((int)_statusCode != 204) { var ex = new OdataerrorException(string.Format("Operation returned an invalid status code '{0}'", _statusCode)); try { _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); Odataerror _errorBody = Microsoft.Rest.Serialization.SafeJsonConvert.DeserializeObject <Odataerror>(_responseContent, Client.DeserializationSettings); if (_errorBody != null) { ex.Body = _errorBody; } } catch (JsonException) { // Ignore the exception } ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); if (_shouldTrace) { ServiceClientTracing.Error(_invocationId, ex); } _httpRequest.Dispose(); if (_httpResponse != null) { _httpResponse.Dispose(); } throw ex; } // Create Result var _result = new HttpOperationResponse(); _result.Request = _httpRequest; _result.Response = _httpResponse; if (_shouldTrace) { ServiceClientTracing.Exit(_invocationId, _result); } return(_result); }
/// <summary> /// Update entity in adoxio_personalhistorysummaries /// </summary> /// <param name='operations'> /// The operations group for this extension method. /// </param> /// <param name='adoxioPersonalhistorysummaryid'> /// key: adoxio_personalhistorysummaryid of adoxio_personalhistorysummary /// </param> /// <param name='body'> /// New property values /// </param> /// <param name='customHeaders'> /// Headers that will be added to request. /// </param> public static HttpOperationResponse UpdateWithHttpMessages(this IPersonalhistorysummaries operations, string adoxioPersonalhistorysummaryid, MicrosoftDynamicsCRMadoxioPersonalhistorysummary body, Dictionary <string, List <string> > customHeaders = null) { return(operations.UpdateWithHttpMessagesAsync(adoxioPersonalhistorysummaryid, body, customHeaders, CancellationToken.None).ConfigureAwait(false).GetAwaiter().GetResult()); }
/// <summary> /// Update entity in adoxio_personalhistorysummaries /// </summary> /// <param name='operations'> /// The operations group for this extension method. /// </param> /// <param name='adoxioPersonalhistorysummaryid'> /// key: adoxio_personalhistorysummaryid of adoxio_personalhistorysummary /// </param> /// <param name='body'> /// New property values /// </param> /// <param name='cancellationToken'> /// The cancellation token. /// </param> public static async Task UpdateAsync(this IPersonalhistorysummaries operations, string adoxioPersonalhistorysummaryid, MicrosoftDynamicsCRMadoxioPersonalhistorysummary body, CancellationToken cancellationToken = default(CancellationToken)) { (await operations.UpdateWithHttpMessagesAsync(adoxioPersonalhistorysummaryid, body, null, cancellationToken).ConfigureAwait(false)).Dispose(); }
/// <summary> /// Update entity in adoxio_personalhistorysummaries /// </summary> /// <param name='operations'> /// The operations group for this extension method. /// </param> /// <param name='adoxioPersonalhistorysummaryid'> /// key: adoxio_personalhistorysummaryid of adoxio_personalhistorysummary /// </param> /// <param name='body'> /// New property values /// </param> public static void Update(this IPersonalhistorysummaries operations, string adoxioPersonalhistorysummaryid, MicrosoftDynamicsCRMadoxioPersonalhistorysummary body) { operations.UpdateAsync(adoxioPersonalhistorysummaryid, body).GetAwaiter().GetResult(); }
/// <summary> /// Add new entity to adoxio_personalhistorysummaries /// </summary> /// <param name='operations'> /// The operations group for this extension method. /// </param> /// <param name='body'> /// New entity /// </param> /// <param name='prefer'> /// Required in order for the service to return a JSON representation of the /// object. /// </param> /// <param name='customHeaders'> /// Headers that will be added to request. /// </param> public static HttpOperationResponse <MicrosoftDynamicsCRMadoxioPersonalhistorysummary> CreateWithHttpMessages(this IPersonalhistorysummaries operations, MicrosoftDynamicsCRMadoxioPersonalhistorysummary body, string prefer = "return=representation", Dictionary <string, List <string> > customHeaders = null) { return(operations.CreateWithHttpMessagesAsync(body, prefer, customHeaders, CancellationToken.None).ConfigureAwait(false).GetAwaiter().GetResult()); }
/// <summary> /// Add new entity to adoxio_personalhistorysummaries /// </summary> /// <param name='operations'> /// The operations group for this extension method. /// </param> /// <param name='body'> /// New entity /// </param> /// <param name='prefer'> /// Required in order for the service to return a JSON representation of the /// object. /// </param> /// <param name='cancellationToken'> /// The cancellation token. /// </param> public static async Task <MicrosoftDynamicsCRMadoxioPersonalhistorysummary> CreateAsync(this IPersonalhistorysummaries operations, MicrosoftDynamicsCRMadoxioPersonalhistorysummary body, string prefer = "return=representation", CancellationToken cancellationToken = default(CancellationToken)) { using (var _result = await operations.CreateWithHttpMessagesAsync(body, prefer, null, cancellationToken).ConfigureAwait(false)) { return(_result.Body); } }
/// <summary> /// Add new entity to adoxio_personalhistorysummaries /// </summary> /// <param name='operations'> /// The operations group for this extension method. /// </param> /// <param name='body'> /// New entity /// </param> /// <param name='prefer'> /// Required in order for the service to return a JSON representation of the /// object. /// </param> public static MicrosoftDynamicsCRMadoxioPersonalhistorysummary Create(this IPersonalhistorysummaries operations, MicrosoftDynamicsCRMadoxioPersonalhistorysummary body, string prefer = "return=representation") { return(operations.CreateAsync(body, prefer).GetAwaiter().GetResult()); }