public Task Save(PerformancePlanOrReport report, CancellationToken token = default(CancellationToken)) { return(UseClient(async client => { report.id = await GetCosmosId(report, token); await client.UpsertDocumentAsync(this.DataPath, report); })); }
public async Task <StrategicPlan> TransformPlan([FromBody] PerformancePlanOrReport plan, bool persist = false, CancellationToken token = default(CancellationToken)) { var strat = this.Transform.Transform(plan); if (persist) { await this.LogicOne.Save(strat, token); } return(strat); }
public Task Save(PerformancePlanOrReport report, CancellationToken token = default(CancellationToken)) { if (report.AdministrativeInformation == null) { report.AdministrativeInformation = new AdministrativeInformationType(); } if (report.AdministrativeInformation.Identifier == null) { report.AdministrativeInformation.Identifier = Guid.NewGuid().ToString(); } return(this.Data.Save(report, token)); }
protected async Task <string> GetCosmosId(PerformancePlanOrReport report, CancellationToken token = default(CancellationToken)) { List <string> ids = new List <string>(); await UseClient(async client => { var query = CreateQuery <PerformancePlanOrReport>(client, new FeedOptions() { MaxItemCount = 1 }).Where( c => c.AdministrativeInformation.Identifier == report.AdministrativeInformation.Identifier).Select(c => c.id).AsDocumentQuery(); while (query.HasMoreResults) { ids.AddRange(await query.ExecuteNextAsync <string>(token)); } }); return(ids.SingleOrDefault()); }
public async Task <IActionResult> Save([FromBody] PerformancePlanOrReport plan, CancellationToken token = default(CancellationToken)) { await this.Logic.Save(plan, token); return(Ok()); }
private async Task RunAsync(CancellationToken cancellationToken) { var context = new AuthenticationContext("https://login.microsoftonline.com/88c25c7a-38aa-45d5-bd8d-e939dd68c4f2"); var queue = new QueueClient(ConfigurationManager.AppSettings["connectionString"], "2009v13-990EZ"); RestClient rest = new RestClient("http://s3.amazonaws.com/irs-form-990/"); DateTimeOffset hasExpired = DateTimeOffset.MinValue; string accessToken = null; queue.RegisterMessageHandler(async(msg, token) => { var url = Encoding.UTF8.GetString(msg.Body); string version = null; try { var resp = rest.Get(new RestRequest(url)); XDocument doc = XDocument.Parse(resp.Content.Replace("xsi:schemaLocation=\"http://www.irs.gov/efile\"", "").Replace( "xmlns=\"http://www.irs.gov/efile\"", "").Replace("<?xml version=\"1.0\" encoding=\"utf-8\"?>", "").Replace("\r\n", "")); version = doc.Root.Attribute("returnVersion").Value.Replace(".", ""); var rtn = doc.Element("Return"); PerformancePlanOrReport report = new PerformancePlanOrReport(); report.OtherInformation = "FORM-990"; report.Name = rtn.Element("ReturnHeader").Element("Filer").Element("Name").Element("BusinessNameLine1").Value + "- FORM 990 " + rtn.Element("ReturnHeader").Element("TaxPeriodEndDate").Value; report.Type = PerformancePlanOrReportType.Performance_Report; report.AdministrativeInformation = new AdministrativeInformationType(); report.AdministrativeInformation.EndDate = rtn.Element("ReturnHeader").Element("TaxPeriodEndDate").Value; report.AdministrativeInformation.Identifier = Guid.NewGuid().ToString(); report.AdministrativeInformation.Source = "http://s3.amazonaws.com/irs-form-990/" + url; report.AdministrativeInformation.PublicationDate = rtn.Element("ReturnHeader").Element("Timestamp").Value; report.Description = rtn.Element("ReturnHeader").Element("ReturnType").Value; report.StrategicPlanCore = new StrategicPlanCore(); report.StrategicPlanCore.Mission = new Mission(); report.StrategicPlanCore.Mission.Description = rtn.Element("ReturnData").Element("IRS990EZ").Element("PrimaryExemptPurpose").Value; report.StrategicPlanCore.Mission.Identifier = Guid.NewGuid().ToString(); var stakeholders = rtn.Element("ReturnData").Element("IRS990EZ" ).Elements("OfficerDirectorTrusteeKeyEmpl").Select(o => new Stakeholder() { StakeholderTypeType = StakeholderStakeholderTypeType.Person, StakeholderTypeTypeSpecified = true, Name = o.Element("PersonName").Value, Role = new Core.Two.Role[] { new Core.Two.Role() { RoleType = new RoleType[] { RoleType.Performer }, Name = o.Element("Title").Value, Description = "Title" } } }).ToArray(); report.StrategicPlanCore.Organization = new Organization[] { new Organization() { Identifier = rtn.Element("ReturnHeader").Element("Filer").Element("EIN").Value, Acronym = rtn.Element("ReturnHeader").Element("Filer").Element("NameControl").Value, Name = rtn.Element("ReturnHeader").Element("Filer").Element("Name").Element("BusinessNameLine1").Value, Stakeholder = stakeholders } }; report.StrategicPlanCore.Goal = new Goal[] { new Goal() { Identifier = "UID-EmployeeHours", Name = "Employee Hours and Compensation", SequenceIndicator = "2", Objective = rtn.Element("ReturnData").Element("IRS990EZ").Elements("OfficerDirectorTrusteeKeyEmpl").Select(e => new ObjectiveType() { Identifier = Guid.NewGuid().ToString(), Name = e.Element("PersonName").Value, Description = e.Element("Title").Value, PerformanceIndicator = new PerformanceIndicator[] { new PerformanceIndicator() { PerformanceIndicatorType = PerformanceIndicatorTypeType.Quantitative, PerformanceIndicatorTypeSpecified = true, Identifier = Guid.NewGuid().ToString(), MeasurementInstance = new MeasurementInstance[] { new MeasurementInstance() { ActualResult = new ActualResult[] { new ActualResult() { Description = "Average Hours Per Week", NumberOfUnits = e.Element("AvgHoursPerWkDevotedToPosition").Value } } }, new MeasurementInstance() { ActualResult = new ActualResult[] { new ActualResult() { Description = "Compensation", NumberOfUnits = e.Element("Compensation").Value } } } } } } }).ToArray(), Stakeholder = stakeholders } }; RestClient client = new RestClient("https://stratml.services/api/PartTwo"); var request = new RestRequest(Method.POST) { RequestFormat = DataFormat.Xml }; request.AddParameter("application/xml", report.Serialize(), ParameterType.RequestBody); var response = await client.ExecuteTaskAsync(request, token); } catch (Exception ex) { if (version != null) { var cerificateThumbprint = CloudConfigurationManager.GetSetting("KeyVaultAuthCertThumbprint"); var authenticationClientId = CloudConfigurationManager.GetSetting("KeyVaultAuthClientId"); var cert = CertificateHelper.FindCertificateByThumbprint(cerificateThumbprint); var assertionCert = new ClientAssertionCertificate(authenticationClientId, cert); string connectionStirng = null; string subscriptionID = null; using (var vault = new KeyVaultClient(async(authority, resource, scope) => { var authenticationContext = new AuthenticationContext(authority); var result = await authenticationContext.AcquireTokenAsync(resource, assertionCert); return(result.AccessToken); })) { connectionStirng = (await vault.GetSecretAsync("https://stratml-keys.vault.azure.net/secrets/ServiceBusConnectionString/", cancellationToken)).Value; subscriptionID = (await vault.GetSecretAsync("https://stratml-keys.vault.azure.net/secrets/SubscriptionID/", cancellationToken)).Value; } if (hasExpired < DateTime.UtcNow.AddMinutes(-2)) { var loginContext = new AuthenticationContext("https://login.microsoftonline.com/88c25c7a-38aa-45d5-bd8d-e939dd68c4f2"); var result = await loginContext.AcquireTokenAsync( "https://management.core.windows.net/", assertionCert ); accessToken = result.AccessToken; hasExpired = result.ExpiresOn; } TokenCredentials creds = new TokenCredentials(accessToken); using (ServiceBusManagementClient sb = new ServiceBusManagementClient(creds) { SubscriptionId = subscriptionID }) { await sb.Queues.CreateOrUpdateAsync("stratml", "stratml", version + "-errors", new SBQueue()); var q = new QueueClient(connectionStirng, version + "-errors"); await q.SendAsync(new Message(Encoding.UTF8.GetBytes($"{{'url':'{url}','ex':'{ex.ToString()}'}}"))); await q.CloseAsync(); } } } }, new MessageHandlerOptions(evt => Task.FromException(evt.Exception)) { MaxConcurrentCalls = 4, AutoComplete = true }); while (!cancellationToken.IsCancellationRequested) { await Task.Delay(60000, cancellationToken); } await queue.CloseAsync(); }
public StrategicPlan Transform(PerformancePlanOrReport plan) { return(plan.CreateRelatedInstance <StrategicPlan>()); }