public static async Task Main(string[] args) { TccCommand parsed = args.ParseCommandLine(); if (parsed.ReturnCode == 1) { Environment.Exit(1); } var serviceCollection = new ServiceCollection(); serviceCollection.AddTcc(); serviceCollection.AddSerilog(parsed.Mode != Mode.Benchmark && parsed.Option.Verbose); if (parsed.Mode != Mode.Benchmark) { serviceCollection.AddSingleton <IBlockListener, CommandLineBlockListener>(); } IServiceProvider provider = serviceCollection.BuildServiceProvider(); provider.GetRequiredService <CancellationTokenSource>().HookTermination(); await provider.GetRequiredService <ExternalDependencies>().EnsureAllDependenciesPresent(); OperationSummary op = await RunTcc(provider, parsed); if (op == null || !op.IsSuccess) { Environment.Exit(1); } }
public async Task EgressListTest() { await ScenarioRunner.SingleTarget( _outputHelper, _httpClientFactory, DiagnosticPortConnectionMode.Connect, TestAppScenarios.AsyncWait.Name, appValidate : async(appRunner, apiClient) => { int processId = await appRunner.ProcessIdTask; OperationResponse response1 = await EgressTraceWithDelay(apiClient, processId); OperationResponse response2 = await EgressTraceWithDelay(apiClient, processId, delay: false); await CancelEgressOperation(apiClient, response2); List <OperationSummary> result = await apiClient.GetOperations(); Assert.Equal(2, result.Count); OperationStatusResponse status1 = await apiClient.GetOperationStatus(response1.OperationUri); OperationSummary summary1 = result.First(os => os.OperationId == status1.OperationStatus.OperationId); ValidateOperation(status1.OperationStatus, summary1); OperationStatusResponse status2 = await apiClient.GetOperationStatus(response2.OperationUri); OperationSummary summary2 = result.First(os => os.OperationId == status2.OperationStatus.OperationId); ValidateOperation(status2.OperationStatus, summary2); await appRunner.SendCommandAsync(TestAppScenarios.AsyncWait.Commands.Continue); }, configureTool : (toolRunner) => { toolRunner.WriteKeyPerValueConfiguration(new RootOptions().AddFileSystemEgress(FileProviderName, _tempDirectory.FullName)); }); }
private OperationSummary GetOperationSummary(IEnumerable <ISOTime> timeElements, string productIDRef, IEnumerable <string> deviceElementIDRefs = null) { OperationSummary operationSummary = null; int?productID = TaskDataMapper.InstanceIDMap.GetADAPTID(productIDRef); if (productID.HasValue) { operationSummary = new OperationSummary(); operationSummary.ProductId = productID.Value; operationSummary.Data = new List <StampedMeteredValues>(); operationSummary.Data.Add(GetStampedMeteredValuesForTimes(timeElements, deviceElementIDRefs)); } return(operationSummary); }
private List <OperationSummary> ImportOperationSummaries(ISOTask isoLoggedTask) { List <OperationSummary> operationSummaries = null; if (isoLoggedTask.ProductAllocations.Any()) { IEnumerable <ISOTime> timeElements = isoLoggedTask.Times.Where(t => t.HasStart && t.HasType); operationSummaries = new List <OperationSummary>(); if (isoLoggedTask.ProductAllocations.Count == 1) { //There is a single product allocation on the task string isoProductRef = isoLoggedTask.ProductAllocations.Single().ProductIdRef; OperationSummary summary = GetOperationSummary(timeElements, isoProductRef); if (summary != null) { operationSummaries.Add(summary); } } else if (isoLoggedTask.ProductAllocations.Select(p => p.ProductIdRef).Distinct().Count() == 1) { //There is a single product on multiple allocations string isoProductRef = isoLoggedTask.ProductAllocations.Select(p => p.ProductIdRef).First(); OperationSummary summary = GetOperationSummary(timeElements, isoProductRef); if (summary != null) { operationSummaries.Add(summary); } } else { //There are multiple products. Use any DeviceElements on the PANs to reconcile summaries. foreach (string isoProductRef in isoLoggedTask.ProductAllocations.Select(p => p.ProductIdRef).Distinct()) { IEnumerable <string> deviceElementIDs = isoLoggedTask.ProductAllocations.Where(p => p.ProductIdRef == isoProductRef && p.DeviceElementIdRef != null) .Select(p => p.DeviceElementIdRef); OperationSummary summary = GetOperationSummary(timeElements, isoProductRef, deviceElementIDs); if (summary != null) { operationSummaries.Add(summary); } } } } return(operationSummaries); }
public async Task CompressDecompress(PasswordMode mode, CompressionAlgo algo) { await _externalDependencies.EnsureAllDependenciesPresent(); string toCompressFolder = TestFileHelper.NewFolder(); string compressedFolder = TestFileHelper.NewFolder(); string decompressedFolder = TestFileHelper.NewFolder(); string keysFolder = TestFileHelper.NewFolder(); var data = await TestData.CreateFiles(1, 1024, toCompressFolder); OperationSummary resultCompress = await Compress(mode, algo, compressedFolder, keysFolder, data); resultCompress.ThrowOnError(); Assert.True(resultCompress.IsSuccess); Assert.NotEmpty(resultCompress.OperationBlocks.Select(i => i.Block)); Assert.NotEmpty(resultCompress.OperationBlocks.Select(i => i.CommandResult)); var decomp = new TestData { Directories = new List <DirectoryInfo> { new DirectoryInfo(compressedFolder) } }; OperationSummary resultDecompress = await Decompress(mode, decompressedFolder, keysFolder, decomp); resultDecompress.ThrowOnError(); Assert.True(resultDecompress.IsSuccess); Assert.NotEmpty(resultDecompress.OperationBlocks.Select(i => i.Block)); Assert.NotEmpty(resultDecompress.OperationBlocks.Select(i => i.CommandResult)); FileInfo src = new DirectoryInfo(toCompressFolder).EnumerateFiles().FirstOrDefault(); FileInfo dst = new DirectoryInfo(decompressedFolder).EnumerateFiles().FirstOrDefault(); Assert.True(TestFileHelper.FilesAreEqual(src, dst)); }
static void Main(string[] args) { var testData = JArray.Parse(File.ReadAllText("data.json")); string applicationPath = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetEntryAssembly().Location); var pluginFactory = new PluginFactory(applicationPath); var admPlugin = pluginFactory.GetPlugin("ADMPlugin"); admPlugin.Initialize(); ApplicationDataModel export = new ApplicationDataModel(); export.Catalog = new Catalog(); export.Documents = new Documents(); List <WorkRecord> workRecords = new List <WorkRecord>(); List <Summary> summaries = new List <Summary>(); // All of these records are for the same Grower/Farm/Field/CropZone/CropYear so I'm just // pulling the common info from the first record. #region Create a "crop year" TimeScope to tag each of the WorkRecords with. TimeScope cropYear = new TimeScope(); UniqueId ourId = new UniqueId(); ourId.Id = testData[0]["CropYear"].ToString(); ourId.IdType = IdTypeEnum.String; ourId.Source = "www.somecompany.com"; ourId.SourceType = IdSourceTypeEnum.URI; cropYear.Id.UniqueIds.Add(ourId); cropYear.Description = testData[0]["CropYear"].ToString(); cropYear.DateContext = DateContextEnum.CropSeason; export.Catalog.TimeScopes.Add(cropYear); #endregion #region Create the Grower/Farm/Field/CropZone objects for this group of applications Grower grower = new Grower(); ourId = new UniqueId(); ourId.Id = testData[0]["ApplicationId"]["DataSourceId"].ToString(); ourId.IdType = IdTypeEnum.UUID; ourId.Source = "www.somecompany.com"; ourId.SourceType = IdSourceTypeEnum.URI; grower.Id.UniqueIds.Add(ourId); grower.Name = testData[0]["GrowerName"].ToString(); export.Catalog.Growers.Add(grower); Farm farm = new Farm(); ourId = new UniqueId(); ourId.Id = testData[0]["FarmId"]["Id"].ToString(); ourId.IdType = IdTypeEnum.UUID; ourId.Source = "www.somecompany.com"; ourId.SourceType = IdSourceTypeEnum.URI; farm.Id.UniqueIds.Add(ourId); farm.Description = testData[0]["FarmName"].ToString(); farm.GrowerId = grower.Id.ReferenceId; export.Catalog.Farms.Add(farm); Field field = new Field(); ourId = new UniqueId(); ourId.Id = testData[0]["FieldId"].ToString(); ourId.IdType = IdTypeEnum.UUID; ourId.Source = "www.somecompany.com"; ourId.SourceType = IdSourceTypeEnum.URI; field.Id.UniqueIds.Add(ourId); field.Description = testData[0]["FieldName"].ToString(); field.FarmId = farm.Id.ReferenceId; export.Catalog.Fields.Add(field); Crop crop = new Crop(); ourId = new UniqueId(); ourId.Id = testData[0]["CropId"]["Id"].ToString(); ourId.IdType = IdTypeEnum.UUID; ourId.Source = "www.somecompany.com"; ourId.SourceType = IdSourceTypeEnum.URI; crop.Id.UniqueIds.Add(ourId); crop.Name = testData[0]["Crop"].ToString(); // Add EPPO code as ContextItem at some point in the future export.Catalog.Crops.Add(crop); CropZone cropZone = new CropZone(); ourId = new UniqueId(); ourId.Id = testData[0]["CropZoneId"].ToString(); ourId.IdType = IdTypeEnum.UUID; ourId.Source = "www.somecompany.com"; ourId.SourceType = IdSourceTypeEnum.URI; cropZone.Id.UniqueIds.Add(ourId); cropZone.Description = testData[0]["CropZoneName"].ToString(); cropZone.FieldId = field.Id.ReferenceId; cropZone.CropId = crop.Id.ReferenceId; cropZone.TimeScopes.Add(cropYear); string areaString = testData[0]["AreaApplied"].ToString(); double area = Convert.ToDouble(areaString); cropZone.Area = new NumericRepresentationValue(RepresentationInstanceList.vrReportedFieldArea.ToModelRepresentation(), new NumericValue(UnitSystemManager.GetUnitOfMeasure("ac1"), area)); export.Catalog.CropZones.Add(cropZone); #endregion // Foreach Application var applicationIds = ((from c in testData select c["ApplicationId"]["Id"]).Distinct()).ToList(); foreach (var applicationId in applicationIds) { var appliedProducts = (from c in testData where (string)c["ApplicationId"]["Id"] == applicationId.ToString() select c).ToList(); // Create a WorkRecord and Summary (ADAPT's version of an Application) WorkRecord workRecord = new WorkRecord(); ourId = new UniqueId(); ourId.Id = appliedProducts[0]["ApplicationId"]["Id"].ToString(); ourId.IdType = IdTypeEnum.UUID; ourId.Source = "www.somecompany.com"; ourId.SourceType = IdSourceTypeEnum.URI; workRecord.Id.UniqueIds.Add(ourId); workRecord.Description = appliedProducts[0]["ApplicationName"].ToString(); workRecord.TimeScopes.Add(cropYear); TimeScope timingEvent = new TimeScope(); timingEvent.DateContext = DateContextEnum.TimingEvent; timingEvent.Description = appliedProducts[0]["TimingEvent"].ToString(); workRecord.TimeScopes.Add(timingEvent); TimeScope startDate = new TimeScope(); startDate.DateContext = DateContextEnum.ActualStart; startDate.TimeStamp1 = DateTime.Parse(appliedProducts[0]["StartDate"].ToString()); workRecord.TimeScopes.Add(startDate); TimeScope endDate = new TimeScope(); endDate.DateContext = DateContextEnum.ActualEnd; endDate.TimeStamp1 = DateTime.Parse(appliedProducts[0]["EndDate"].ToString()); workRecord.TimeScopes.Add(endDate); Summary summary = new Summary(); // This property linking the Summary to its parent WorkRecord doesn't exist in ADAPT 1.1.0.8. // Slated to be added in next release. // summary.WorkRecordId = workRecord.Id.ReferenceId; // This property linking the Summary to its Grower doesn't exist in ADAPT 1.1.0.8. // Slated to be added in next release. // summary.GrowerId = grower.Id.ReferenceId; summary.FarmId = farm.Id.ReferenceId; summary.FieldId = field.Id.ReferenceId; summary.CropZoneId = cropZone.Id.ReferenceId; // Foreach Product foreach (var appliedProduct in appliedProducts) { //Note that Manufacturer is not a required property for a given product. Manufacturer manufacturer = null; var manufacturers = export.Catalog.Manufacturers.Where(x => (x.Description == appliedProduct["Manufacturer"].ToString())).ToList(); if (manufacturers.Count > 0) { manufacturer = manufacturers[0]; } else { manufacturer = new Manufacturer(); ourId = new UniqueId(); // Couldn't find Manufacturer id in your data ourId.Id = "00000000-0000-0000-0000-000000000000"; ourId.IdType = IdTypeEnum.UUID; ourId.Source = "www.somecompany.com"; ourId.SourceType = IdSourceTypeEnum.URI; manufacturer.Id.UniqueIds.Add(ourId); manufacturer.Description = appliedProduct["Manufacturer"].ToString(); export.Catalog.Manufacturers.Add(manufacturer); } // This is sub-optimal, but it is what we have to work with at the moment. // We're creating the use of each product as its own "operation" OperationSummary operation = new OperationSummary(); operation.Data = new List <StampedMeteredValues>(); if (appliedProduct["Type"].ToString() == "Seed") { #region Handle Seed CropVariety cropVariety = null; var products = export.Catalog.Products.Where(x => (x.Description == appliedProduct["Product"].ToString())).ToList(); if (products.Count > 0) { cropVariety = products[0] as CropVariety; } else { cropVariety = new CropVariety(); ourId = new UniqueId(); ourId.Id = appliedProduct["ProductId"]["Id"].ToString(); ourId.IdType = IdTypeEnum.UUID; ourId.Source = "www.somecompany.com"; ourId.SourceType = IdSourceTypeEnum.URI; cropVariety.Id.UniqueIds.Add(ourId); cropVariety.Description = appliedProduct["Product"].ToString(); cropVariety.CropId = crop.Id.ReferenceId; if (manufacturer != null) { cropVariety.ManufacturerId = manufacturer.Id.ReferenceId; } export.Catalog.Products.Add(cropVariety); } operation.ProductId = cropVariety.Id.ReferenceId; operation.OperationType = OperationTypeEnum.SowingAndPlanting; #endregion } else if (appliedProduct["Type"].ToString() == "CropProtection") { #region Handle CropProtection CropProtectionProduct cropProtection = null; var products = export.Catalog.Products.Where(x => (x.Description == appliedProduct["Product"].ToString())).ToList(); if (products.Count > 0) { cropProtection = products[0] as CropProtectionProduct; } else { cropProtection = new CropProtectionProduct(); ourId = new UniqueId(); ourId.Id = appliedProduct["ProductId"]["Id"].ToString(); ourId.IdType = IdTypeEnum.UUID; ourId.Source = "www.somecompany.com"; ourId.SourceType = IdSourceTypeEnum.URI; cropProtection.Id.UniqueIds.Add(ourId); cropProtection.Description = appliedProduct["Product"].ToString(); if (manufacturer != null) { cropProtection.ManufacturerId = manufacturer.Id.ReferenceId; } if (!string.IsNullOrEmpty(appliedProduct["RegNo"].ToString())) { ContextItem epaNumber = new ContextItem(); epaNumber.Code = "US-EPA-N"; epaNumber.Value = ConditionEPA(appliedProduct["RegNo"].ToString(), true, true); cropProtection.ContextItems.Add(epaNumber); } export.Catalog.Products.Add(cropProtection); } operation.ProductId = cropProtection.Id.ReferenceId; operation.OperationType = OperationTypeEnum.CropProtection; #endregion } else if (appliedProduct["Type"].ToString() == "Fertilizer") { #region Handle Fertilizer FertilizerProduct cropNutrition = null; var products = export.Catalog.Products.Where(x => (x.Description == appliedProduct["Product"].ToString())).ToList(); if (products.Count > 0) { cropNutrition = products[0] as FertilizerProduct; } else { cropNutrition = new FertilizerProduct(); ourId = new UniqueId(); ourId.Id = appliedProduct["ProductId"]["Id"].ToString(); ourId.IdType = IdTypeEnum.UUID; ourId.Source = "www.somecompany.com"; ourId.SourceType = IdSourceTypeEnum.URI; cropNutrition.Id.UniqueIds.Add(ourId); cropNutrition.Description = appliedProduct["Product"].ToString(); if (manufacturer != null) { cropNutrition.ManufacturerId = manufacturer.Id.ReferenceId; } export.Catalog.Products.Add(cropNutrition); } operation.ProductId = cropNutrition.Id.ReferenceId; operation.OperationType = OperationTypeEnum.Fertilizing; #endregion } StampedMeteredValues smv = new StampedMeteredValues(); MeteredValue mv = null; NumericRepresentationValue rateValue = null; #region Set the product rate (currently hardcoded to be per acre) switch (appliedProduct["RateUnit"].ToString()) { case ("seed"): rateValue = new NumericRepresentationValue(RepresentationInstanceList.vrSeedRateSeedsActual.ToModelRepresentation(), new NumericValue(UnitSystemManager.GetUnitOfMeasure("seeds1ac-1"), Convert.ToDouble(appliedProduct["RateValue"].ToString()))); break; case ("kernel"): rateValue = new NumericRepresentationValue(RepresentationInstanceList.vrSeedRateSeedsActual.ToModelRepresentation(), new NumericValue(UnitSystemManager.GetUnitOfMeasure("seeds1ac-1"), Convert.ToDouble(appliedProduct["RateValue"].ToString()))); break; case ("short ton"): rateValue = new NumericRepresentationValue(RepresentationInstanceList.vrAppRateMassActual.ToModelRepresentation(), new NumericValue(UnitSystemManager.GetUnitOfMeasure("ton1ac-1"), Convert.ToDouble(appliedProduct["RateValue"].ToString()))); break; case ("metric ton"): rateValue = new NumericRepresentationValue(RepresentationInstanceList.vrAppRateMassActual.ToModelRepresentation(), new NumericValue(UnitSystemManager.GetUnitOfMeasure("t1ac-1"), Convert.ToDouble(appliedProduct["RateValue"].ToString()))); break; case ("pound"): if (appliedProduct["Type"].ToString() == "Seed") { rateValue = new NumericRepresentationValue(RepresentationInstanceList.vrSeedRateMassActual.ToModelRepresentation(), new NumericValue(UnitSystemManager.GetUnitOfMeasure("lb1ac-1"), Convert.ToDouble(appliedProduct["RateValue"].ToString()))); } else { rateValue = new NumericRepresentationValue(RepresentationInstanceList.vrAppRateMassActual.ToModelRepresentation(), new NumericValue(UnitSystemManager.GetUnitOfMeasure("lb1ac-1"), Convert.ToDouble(appliedProduct["RateValue"].ToString()))); } break; case ("ounce"): rateValue = new NumericRepresentationValue(RepresentationInstanceList.vrAppRateMassActual.ToModelRepresentation(), new NumericValue(UnitSystemManager.GetUnitOfMeasure("oz1ac-1"), Convert.ToDouble(appliedProduct["RateValue"].ToString()))); break; case ("kilogram"): if (appliedProduct["Type"].ToString() == "Seed") { rateValue = new NumericRepresentationValue(RepresentationInstanceList.vrSeedRateMassActual.ToModelRepresentation(), new NumericValue(UnitSystemManager.GetUnitOfMeasure("kg1ac-1"), Convert.ToDouble(appliedProduct["RateValue"].ToString()))); } else { rateValue = new NumericRepresentationValue(RepresentationInstanceList.vrAppRateMassActual.ToModelRepresentation(), new NumericValue(UnitSystemManager.GetUnitOfMeasure("kg1ac-1"), Convert.ToDouble(appliedProduct["RateValue"].ToString()))); } break; case ("gram"): rateValue = new NumericRepresentationValue(RepresentationInstanceList.vrAppRateMassActual.ToModelRepresentation(), new NumericValue(UnitSystemManager.GetUnitOfMeasure("g1ac-1"), Convert.ToDouble(appliedProduct["RateValue"].ToString()))); break; case ("fluid ounce"): rateValue = new NumericRepresentationValue(RepresentationInstanceList.vrAppRateVolumeActual.ToModelRepresentation(), new NumericValue(UnitSystemManager.GetUnitOfMeasure("floz1ac-1"), Convert.ToDouble(appliedProduct["RateValue"].ToString()))); break; case ("quart"): rateValue = new NumericRepresentationValue(RepresentationInstanceList.vrAppRateVolumeActual.ToModelRepresentation(), new NumericValue(UnitSystemManager.GetUnitOfMeasure("qt1ac-1"), Convert.ToDouble(appliedProduct["RateValue"].ToString()))); break; case ("pint"): rateValue = new NumericRepresentationValue(RepresentationInstanceList.vrAppRateVolumeActual.ToModelRepresentation(), new NumericValue(UnitSystemManager.GetUnitOfMeasure("pt1ac-1"), Convert.ToDouble(appliedProduct["RateValue"].ToString()))); break; case ("milliliter"): rateValue = new NumericRepresentationValue(RepresentationInstanceList.vrAppRateVolumeActual.ToModelRepresentation(), new NumericValue(UnitSystemManager.GetUnitOfMeasure("ml1ac-1"), Convert.ToDouble(appliedProduct["RateValue"].ToString()))); break; case ("liter"): rateValue = new NumericRepresentationValue(RepresentationInstanceList.vrAppRateVolumeActual.ToModelRepresentation(), new NumericValue(UnitSystemManager.GetUnitOfMeasure("l1ac-1"), Convert.ToDouble(appliedProduct["RateValue"].ToString()))); break; case ("gallon"): rateValue = new NumericRepresentationValue(RepresentationInstanceList.vrAppRateVolumeActual.ToModelRepresentation(), new NumericValue(UnitSystemManager.GetUnitOfMeasure("gal1ac-1"), Convert.ToDouble(appliedProduct["RateValue"].ToString()))); break; case ("centiliter"): rateValue = new NumericRepresentationValue(RepresentationInstanceList.vrAppRateVolumeActual.ToModelRepresentation(), new NumericValue(UnitSystemManager.GetUnitOfMeasure("cl1ac-1"), Convert.ToDouble(appliedProduct["RateValue"].ToString()))); break; case ("acre"): break; default: break; } if (rateValue != null) { mv = new MeteredValue(); mv.Value = rateValue; smv.Values.Add(mv); } #endregion // Set the "applied area" for this use of the product (currently hardcoded to be in acres) NumericRepresentationValue areaValue = new NumericRepresentationValue(RepresentationInstanceList.vrTotalAreaCovered.ToModelRepresentation(), new NumericValue(UnitSystemManager.GetUnitOfMeasure("ac1"), Convert.ToDouble(appliedProduct["AreaApplied"].ToString()))); mv = new MeteredValue(); mv.Value = areaValue; smv.Values.Add(mv); if (!string.IsNullOrEmpty(appliedProduct["ApplicationMethod"].ToString())) { EnumeratedValue applicationMethod = null; #region Set the product application method switch (appliedProduct["ApplicationMethod"].ToString()) { case ("Aerial"): applicationMethod = new EnumeratedValue { Value = DefinedTypeEnumerationInstanceList.dtiAerial.ToModelEnumMember() }; applicationMethod.Representation = RepresentationInstanceList.dtApplicationMethod.ToModelRepresentation(); break; case ("Air Blast"): applicationMethod = new EnumeratedValue { Value = DefinedTypeEnumerationInstanceList.dtiAirBlast.ToModelEnumMember() }; applicationMethod.Representation = RepresentationInstanceList.dtApplicationMethod.ToModelRepresentation(); break; case ("Chemigation"): applicationMethod = new EnumeratedValue { Value = DefinedTypeEnumerationInstanceList.dtiChemigation.ToModelEnumMember() }; applicationMethod.Representation = RepresentationInstanceList.dtApplicationMethod.ToModelRepresentation(); break; case ("Fertigation"): applicationMethod = new EnumeratedValue { Value = DefinedTypeEnumerationInstanceList.dtiFertigation.ToModelEnumMember() }; applicationMethod.Representation = RepresentationInstanceList.dtApplicationMethod.ToModelRepresentation(); break; case ("Ground - Banded"): applicationMethod = new EnumeratedValue { Value = DefinedTypeEnumerationInstanceList.dtiBand.ToModelEnumMember() }; applicationMethod.Representation = RepresentationInstanceList.dtApplicationMethod.ToModelRepresentation(); break; case ("Ground - Broadcast"): applicationMethod = new EnumeratedValue { Value = DefinedTypeEnumerationInstanceList.dtiBroadcast.ToModelEnumMember() }; applicationMethod.Representation = RepresentationInstanceList.dtApplicationMethod.ToModelRepresentation(); break; case ("Ground - Hooded"): applicationMethod = new EnumeratedValue { Value = DefinedTypeEnumerationInstanceList.dtiHoodedSprayer.ToModelEnumMember() }; applicationMethod.Representation = RepresentationInstanceList.dtApplicationMethod.ToModelRepresentation(); break; case ("Ground - In Furrow"): applicationMethod = new EnumeratedValue { Value = DefinedTypeEnumerationInstanceList.dtiInFurrow.ToModelEnumMember() }; applicationMethod.Representation = RepresentationInstanceList.dtApplicationMethod.ToModelRepresentation(); break; case ("Ground Application"): applicationMethod = new EnumeratedValue { Value = DefinedTypeEnumerationInstanceList.dtiInGround.ToModelEnumMember() }; applicationMethod.Representation = RepresentationInstanceList.dtApplicationMethod.ToModelRepresentation(); break; case ("Planting"): applicationMethod = new EnumeratedValue { Value = DefinedTypeEnumerationInstanceList.dtiPlanter.ToModelEnumMember() }; applicationMethod.Representation = RepresentationInstanceList.dtApplicationMethod.ToModelRepresentation(); break; case ("Re-Planting"): applicationMethod = new EnumeratedValue { Value = DefinedTypeEnumerationInstanceList.dtiPlanter.ToModelEnumMember() }; applicationMethod.Representation = RepresentationInstanceList.dtApplicationMethod.ToModelRepresentation(); break; case ("Sidedress"): applicationMethod = new EnumeratedValue { Value = DefinedTypeEnumerationInstanceList.dtiSideDress.ToModelEnumMember() }; applicationMethod.Representation = RepresentationInstanceList.dtApplicationMethod.ToModelRepresentation(); break; case ("Fumigation"): case ("Ground - Incorporated"): case ("Ground - Seed Treatment"): case ("Ground - Variable Rate"): case ("Storage"): case ("Topdress"): case ("Tree Injection"): case ("Water Run"): default: applicationMethod = new EnumeratedValue { Value = DefinedTypeEnumerationInstanceList.dtiInGround.ToModelEnumMember() }; applicationMethod.Representation = RepresentationInstanceList.dtApplicationMethod.ToModelRepresentation(); break; } if (applicationMethod != null) { mv = new MeteredValue(); mv.Value = applicationMethod; smv.Values.Add(mv); } #endregion } // There is a problem here handling seed totals by bag....will have to come back to this at some point NumericRepresentationValue totalProductValue = null; #region Set the total product switch (appliedProduct["TotalProductUnit"].ToString()) { case ("seed"): totalProductValue = new NumericRepresentationValue(RepresentationInstanceList.vrTotalSeedQuantityAppliedSeed.ToModelRepresentation(), new NumericValue(UnitSystemManager.GetUnitOfMeasure("seeds"), Convert.ToDouble(appliedProduct["TotalProductQty"].ToString()))); break; case ("kernel"): totalProductValue = new NumericRepresentationValue(RepresentationInstanceList.vrTotalSeedQuantityAppliedSeed.ToModelRepresentation(), new NumericValue(UnitSystemManager.GetUnitOfMeasure("seeds"), Convert.ToDouble(appliedProduct["TotalProductQty"].ToString()))); break; case ("short ton"): totalProductValue = new NumericRepresentationValue(RepresentationInstanceList.vrTotalQuantityAppliedMass.ToModelRepresentation(), new NumericValue(UnitSystemManager.GetUnitOfMeasure("ton"), Convert.ToDouble(appliedProduct["TotalProductQty"].ToString()))); break; case ("metric ton"): totalProductValue = new NumericRepresentationValue(RepresentationInstanceList.vrTotalQuantityAppliedMass.ToModelRepresentation(), new NumericValue(UnitSystemManager.GetUnitOfMeasure("t"), Convert.ToDouble(appliedProduct["TotalProductQty"].ToString()))); break; case ("pound"): if (appliedProduct["Type"].ToString() == "Seed") { totalProductValue = new NumericRepresentationValue(RepresentationInstanceList.vrTotalSeedQuantityAppliedMass.ToModelRepresentation(), new NumericValue(UnitSystemManager.GetUnitOfMeasure("lb"), Convert.ToDouble(appliedProduct["TotalProductQty"].ToString()))); } else { totalProductValue = new NumericRepresentationValue(RepresentationInstanceList.vrTotalQuantityAppliedMass.ToModelRepresentation(), new NumericValue(UnitSystemManager.GetUnitOfMeasure("lb"), Convert.ToDouble(appliedProduct["TotalProductQty"].ToString()))); } break; case ("ounce"): totalProductValue = new NumericRepresentationValue(RepresentationInstanceList.vrTotalQuantityAppliedMass.ToModelRepresentation(), new NumericValue(UnitSystemManager.GetUnitOfMeasure("oz"), Convert.ToDouble(appliedProduct["TotalProductQty"].ToString()))); break; case ("kilogram"): if (appliedProduct["Type"].ToString() == "Seed") { totalProductValue = new NumericRepresentationValue(RepresentationInstanceList.vrTotalSeedQuantityAppliedMass.ToModelRepresentation(), new NumericValue(UnitSystemManager.GetUnitOfMeasure("kg"), Convert.ToDouble(appliedProduct["TotalProductQty"].ToString()))); } else { totalProductValue = new NumericRepresentationValue(RepresentationInstanceList.vrTotalQuantityAppliedMass.ToModelRepresentation(), new NumericValue(UnitSystemManager.GetUnitOfMeasure("kg"), Convert.ToDouble(appliedProduct["TotalProductQty"].ToString()))); } break; case ("gram"): totalProductValue = new NumericRepresentationValue(RepresentationInstanceList.vrTotalQuantityAppliedMass.ToModelRepresentation(), new NumericValue(UnitSystemManager.GetUnitOfMeasure("g1ac-1"), Convert.ToDouble(appliedProduct["TotalProductQty"].ToString()))); break; case ("fluid ounce"): totalProductValue = new NumericRepresentationValue(RepresentationInstanceList.vrTotalQuantityAppliedVolume.ToModelRepresentation(), new NumericValue(UnitSystemManager.GetUnitOfMeasure("floz"), Convert.ToDouble(appliedProduct["TotalProductQty"].ToString()))); break; case ("quart"): totalProductValue = new NumericRepresentationValue(RepresentationInstanceList.vrTotalQuantityAppliedVolume.ToModelRepresentation(), new NumericValue(UnitSystemManager.GetUnitOfMeasure("qt"), Convert.ToDouble(appliedProduct["TotalProductQty"].ToString()))); break; case ("pint"): totalProductValue = new NumericRepresentationValue(RepresentationInstanceList.vrTotalQuantityAppliedVolume.ToModelRepresentation(), new NumericValue(UnitSystemManager.GetUnitOfMeasure("pt"), Convert.ToDouble(appliedProduct["TotalProductQty"].ToString()))); break; case ("milliliter"): totalProductValue = new NumericRepresentationValue(RepresentationInstanceList.vrTotalQuantityAppliedVolume.ToModelRepresentation(), new NumericValue(UnitSystemManager.GetUnitOfMeasure("ml"), Convert.ToDouble(appliedProduct["TotalProductQty"].ToString()))); break; case ("liter"): totalProductValue = new NumericRepresentationValue(RepresentationInstanceList.vrTotalQuantityAppliedVolume.ToModelRepresentation(), new NumericValue(UnitSystemManager.GetUnitOfMeasure("l"), Convert.ToDouble(appliedProduct["TotalProductQty"].ToString()))); break; case ("gallon"): totalProductValue = new NumericRepresentationValue(RepresentationInstanceList.vrTotalQuantityAppliedVolume.ToModelRepresentation(), new NumericValue(UnitSystemManager.GetUnitOfMeasure("gal"), Convert.ToDouble(appliedProduct["TotalProductQty"].ToString()))); break; case ("centiliter"): totalProductValue = new NumericRepresentationValue(RepresentationInstanceList.vrTotalQuantityAppliedVolume.ToModelRepresentation(), new NumericValue(UnitSystemManager.GetUnitOfMeasure("cl"), Convert.ToDouble(appliedProduct["TotalProductQty"].ToString()))); break; case ("acre"): break; default: break; } if (totalProductValue != null) { mv = new MeteredValue(); mv.Value = totalProductValue; smv.Values.Add(mv); } #endregion operation.Data.Add(smv); // Add the OperationSummary to the collection in Summary summary.OperationSummaries.Add(operation); // End - Foreach Product } // Add this Summary to the list summaries.Add(summary); // Add the WorkRecord to the list workRecords.Add(workRecord); // End - Foreach Application } // This property is an IEnumerable so we had to build up the collection in a local list then assign it export.Documents.Summaries = summaries; // This property is an IEnumerable so we had to build up the collection in a local list then assign it export.Documents.WorkRecords = workRecords; // Make sure the target directory exits string outputPath = applicationPath + @"\Output"; if (Directory.Exists(outputPath)) { Directory.Delete(outputPath, true); } if (!Directory.Exists(outputPath)) { Directory.CreateDirectory(outputPath); } admPlugin.Export(export, outputPath); // NOTE: There is a fundamental problem with this version of ADAPT 1.1.0.8 and the ADMPlugin that prevents // the Summary and WorkRecord objects from serializing correctly. This sample will be updated after the MVP // process is complete. }
private void ValidateOperation(OperationStatus expected, OperationSummary summary) { Assert.Equal(expected.OperationId, summary.OperationId); Assert.Equal(expected.Status, summary.Status); Assert.Equal(expected.CreatedDateTime, summary.CreatedDateTime); }
public async Task <OperationSummary> RunBenchmark(BenchmarkOption benchmarkOption) { var operationSummaries = new List <OperationSummary>(); var keysFolder = TestFileHelper.NewFolder(); var iterations = await _iterationGenerator.PrepareIteration(benchmarkOption); var threads = benchmarkOption.Threads == 0 ? Environment.ProcessorCount : benchmarkOption.Threads; foreach (var iteration in iterations) { PasswordMode pm = iteration.Encryption ? PasswordMode.PublicKey : PasswordMode.None; var compressedFolder = TestFileHelper.NewFolder(benchmarkOption.OutputCompressed); var outputFolder = TestFileHelper.NewFolder(benchmarkOption.OutputDecompressed); // compress var compressOption = new CompressOption { Algo = iteration.Algo, CompressionRatio = iteration.CompressionRatio, BlockMode = BlockMode.Individual, SourceDirOrFile = iteration.Content.Source, DestinationDir = compressedFolder, Threads = threads, PasswordOption = await _benchmarkOptionHelper.GenerateCompressPasswordOption(pm, keysFolder) }; OperationSummary resultCompress = await _tarCompressCrypt.Compress(compressOption); if (_cancellationTokenSource.IsCancellationRequested) { await Cleanup(); return(null); } operationSummaries.Add(resultCompress); resultCompress.ThrowOnError(); // decompress var decompressOption = new DecompressOption { SourceDirOrFile = compressedFolder, DestinationDir = outputFolder, Threads = threads, PasswordOption = _benchmarkOptionHelper.GenerateDecompressPasswordOption(pm, keysFolder) }; OperationSummary resultDecompress = await _tarCompressCrypt.Decompress(decompressOption); if (_cancellationTokenSource.IsCancellationRequested) { await Cleanup(); return(null); } operationSummaries.Add(resultDecompress); resultDecompress.ThrowOnError(); StringBuilder sb = FormatResultSummary(iteration, resultCompress, resultDecompress); Console.Out.WriteLine(sb.ToString()); async Task Cleanup() { if (benchmarkOption.Cleanup) { await "del /f /s /q * > NUL".Run(compressedFolder, CancellationToken.None); Directory.Delete(compressedFolder, true); await "del /f /s /q * > NUL".Run(outputFolder, CancellationToken.None); Directory.Delete(outputFolder, true); } } await Cleanup(); } return(new OperationSummary(operationSummaries.SelectMany(i => i.OperationBlocks), 0, default)); }
private static StringBuilder FormatResultSummary(BenchmarkIteration iteration, OperationSummary resultCompress, OperationSummary resultDecompress) { string aes = iteration.Encryption ? "yes" : "no "; var statComp = resultCompress.Statistics; var statDecomp = resultDecompress.Statistics; var sb = new StringBuilder(); sb.Append($"{iteration.Algo}".PadRight(6)); sb.Append($"[{iteration.CompressionRatio.ToString().PadLeft(2)}] "); sb.Append($"aes:{aes} "); if (iteration.Content.Content != BenchmarkContent.UserDefined) { sb.Append($"{iteration.Content.Content.ToString().PadRight(6)} "); } sb.Append("compress "); sb.Append(statComp.AverageThroughput.HumanizedBandwidth().Pad(12)); sb.Append($" [{resultCompress.Stopwatch.Elapsed.HumanizedTimeSpan().Pad(10)}] "); sb.Append("decompress "); sb.Append(statDecomp.AverageThroughput.HumanizedBandwidth().Pad(12)); sb.Append($" [{resultDecompress.Stopwatch.Elapsed.HumanizedTimeSpan().Pad(10)}] "); sb.Append($"ratio:{resultCompress.CompressionRatio:0.####}"); return(sb); }