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. }
public static void Export(string path) { ApplicationDataModel adm = new ApplicationDataModel(); adm.Catalog = new Catalog(); adm.Documents = new Documents(); //-------------------------- //Setup information //-------------------------- //Add a crop Crop corn = new Crop() { Name = "Corn" }; adm.Catalog.Crops.Add(corn); //Add some seed varieties CropVarietyProduct seedVariety1 = new CropVarietyProduct() { CropId = corn.Id.ReferenceId, Description = "Variety 1" }; CropVarietyProduct seedVariety2 = new CropVarietyProduct() { CropId = corn.Id.ReferenceId, Description = "Variety 2" }; adm.Catalog.Products.Add(seedVariety1); adm.Catalog.Products.Add(seedVariety2); //Add a liquid product CropNutritionProduct fertilizer = new CropNutritionProduct() { Description = "Starter", Form = ProductFormEnum.Liquid }; fertilizer.ProductType = ProductTypeEnum.Fertilizer; adm.Catalog.Products.Add(fertilizer); //Add a granular product CropProtectionProduct insecticide = new CropProtectionProduct() { Description = "Insecticide", Form = ProductFormEnum.Solid }; insecticide.ProductType = ProductTypeEnum.Chemical; adm.Catalog.Products.Add(insecticide); //GFF Grower grower = new Grower() { Name = "Example Grower" }; adm.Catalog.Growers.Add(grower); Farm farm = new Farm() { Description = "Example Farm", GrowerId = grower.Id.ReferenceId }; adm.Catalog.Farms.Add(farm); Field field = new Field() { Description = "Example Field", FarmId = farm.Id.ReferenceId, GrowerId = grower.Id.ReferenceId }; field.Area = GetNumericRepresentationValue(23d, "ha", "vrReportedFieldArea"); adm.Catalog.Fields.Add(field); //Crop zone TimeScope season = new TimeScope() { DateContext = DateContextEnum.CropSeason, TimeStamp1 = new DateTime(2021, 1, 1) }; CropZone cropZone = new CropZone() { CropId = corn.Id.ReferenceId, FieldId = field.Id.ReferenceId, TimeScopes = new List <TimeScope>() { season } }; adm.Catalog.CropZones.Add(cropZone); //Field boundary FieldBoundary boundary = new FieldBoundary() { SpatialData = new MultiPolygon() { Polygons = new List <Polygon>() { new Polygon() { ExteriorRing = new LinearRing() { Points = new List <Point>() { new Point() { X = -89.488565, Y = 40.478304 }, new Point() { X = -89.485439, Y = 40.478304 }, new Point() { X = -89.485439, Y = 40.475010 }, new Point() { X = -89.488565, Y = 40.475010 } } }, InteriorRings = new List <LinearRing>() { new LinearRing() { Points = new List <Point>() { new Point() { X = -89.487719, Y = 40.478091 }, new Point() { X = -89.487536, Y = 40.478091 }, new Point() { X = -89.487536, Y = 40.477960 }, new Point() { X = -89.487719, Y = 40.477960 }, new Point() { X = -89.487719, Y = 40.478091 } } }, new LinearRing() { Points = new List <Point>() { new Point() { X = -89.486732, Y = 40.478172 }, new Point() { X = -89.486453, Y = 40.478172 }, new Point() { X = -89.486453, Y = 40.478082 }, new Point() { X = -89.486732, Y = 40.478082 }, new Point() { X = -89.486732, Y = 40.478172 } } } } } } }, FieldId = field.Id.ReferenceId }; adm.Catalog.FieldBoundaries.Add(boundary); field.ActiveBoundaryId = boundary.Id.ReferenceId; //-------------------------- //Prescription //-------------------------- //Prescription setup data //Setup the representation and units for seed rate & seed depth prescriptions NumericRepresentation seedRate = GetNumericRepresentation("vrSeedRateSeedsTarget"); UnitOfMeasure seedUOM = UnitInstance.UnitSystemManager.GetUnitOfMeasure("seeds1ac-1"); RxProductLookup seedVariety1RateLookup = new RxProductLookup() { ProductId = seedVariety1.Id.ReferenceId, Representation = seedRate, UnitOfMeasure = seedUOM }; RxProductLookup seedVariety2RateLookup = new RxProductLookup() { ProductId = seedVariety2.Id.ReferenceId, Representation = seedRate, UnitOfMeasure = seedUOM }; NumericRepresentation seedDepth = GetNumericRepresentation("vrSeedDepthTarget"); UnitOfMeasure depthUOM = UnitInstance.UnitSystemManager.GetUnitOfMeasure("cm"); RxProductLookup seedVariety1DepthLookup = new RxProductLookup() { ProductId = seedVariety1.Id.ReferenceId, Representation = seedDepth, UnitOfMeasure = depthUOM }; RxProductLookup seedVariety2DepthLookup = new RxProductLookup() { ProductId = seedVariety2.Id.ReferenceId, Representation = seedDepth, UnitOfMeasure = depthUOM }; //Setup liquid rx representation/units NumericRepresentation fertilizerRate = GetNumericRepresentation("vrAppRateVolumeTarget"); UnitOfMeasure fertilizerUOM = UnitInstance.UnitSystemManager.GetUnitOfMeasure("gal1ac-1"); RxProductLookup fertilizerRateLookup = new RxProductLookup() { ProductId = fertilizer.Id.ReferenceId, Representation = fertilizerRate, UnitOfMeasure = fertilizerUOM }; //Setup granular rx representation/units NumericRepresentation insecticideRate = GetNumericRepresentation("vrAppRateMassTarget"); UnitOfMeasure insecticideUOM = UnitInstance.UnitSystemManager.GetUnitOfMeasure("lb1ac-1"); RxProductLookup insecticideRateLookup = new RxProductLookup() { ProductId = insecticide.Id.ReferenceId, Representation = insecticideRate, UnitOfMeasure = insecticideUOM }; //Prescription zones //Zone 1 - Variety 1 at 32000 seeds/acre, 4 cm depth target; Starter at 7 gal/ac; Insecticide at 5 lb/ac RxShapeLookup zone1 = new RxShapeLookup() { Rates = new List <RxRate>() { new RxRate() { Rate = 32000d, RxProductLookupId = seedVariety1RateLookup.Id.ReferenceId }, new RxRate() { Rate = 4d, RxProductLookupId = seedVariety1DepthLookup.Id.ReferenceId }, new RxRate() { Rate = 7d, RxProductLookupId = fertilizerRateLookup.Id.ReferenceId }, new RxRate() { Rate = 5d, RxProductLookupId = insecticideRateLookup.Id.ReferenceId } }, Shape = new MultiPolygon() { Polygons = new List <Polygon>() { new Polygon() { ExteriorRing = new LinearRing() { Points = new List <Point>() { new Point() { X = -89.488565, Y = 40.478304 }, new Point() { X = -89.485439, Y = 40.478304 }, new Point() { X = -89.485439, Y = 40.477404 }, new Point() { X = -89.488565, Y = 40.477756 }, new Point() { X = -89.488565, Y = 40.478304 } } }, InteriorRings = new List <LinearRing>() { new LinearRing() { Points = new List <Point>() { new Point() { X = -89.487719, Y = 40.478091 }, new Point() { X = -89.487536, Y = 40.478091 }, new Point() { X = -89.487536, Y = 40.477960 }, new Point() { X = -89.487719, Y = 40.477960 }, new Point() { X = -89.487719, Y = 40.478091 } } }, new LinearRing() { Points = new List <Point>() { new Point() { X = -89.486732, Y = 40.478172 }, new Point() { X = -89.486453, Y = 40.478172 }, new Point() { X = -89.486453, Y = 40.478082 }, new Point() { X = -89.486732, Y = 40.478082 }, new Point() { X = -89.486732, Y = 40.478172 } } } } } } } }; //Zone 2 - Variety 1 at 34000 seeds/acre, depth target 5cm; Starter at 4 gal/ac; Insecticide at 2.5 lb/ac RxShapeLookup zone2 = new RxShapeLookup() { Rates = new List <RxRate>() { new RxRate() { Rate = 34000d, RxProductLookupId = seedVariety1RateLookup.Id.ReferenceId }, new RxRate() { Rate = 5d, RxProductLookupId = seedVariety1DepthLookup.Id.ReferenceId }, new RxRate() { Rate = 4d, RxProductLookupId = fertilizerRateLookup.Id.ReferenceId }, new RxRate() { Rate = 2.5, RxProductLookupId = insecticideRateLookup.Id.ReferenceId } }, Shape = new MultiPolygon() { Polygons = new List <Polygon>() { new Polygon() { ExteriorRing = new LinearRing() { Points = new List <Point>() { new Point() { X = -89.488565, Y = 40.477756 }, new Point() { X = -89.485439, Y = 40.477404 }, new Point() { X = -89.485439, Y = 40.476688 }, new Point() { X = -89.488565, Y = 40.476688 }, new Point() { X = -89.488565, Y = 40.477756 } } } } } } }; //Zone 3 - Variety 2 at 29000 seeds/acre, depth target 6 cm; Starter at 6 gal/ac ; Insecticide at 2.75 lb/ac RxShapeLookup zone3 = new RxShapeLookup() { Rates = new List <RxRate>() { new RxRate() { Rate = 29000d, RxProductLookupId = seedVariety2RateLookup.Id.ReferenceId }, new RxRate() { Rate = 6d, RxProductLookupId = seedVariety2DepthLookup.Id.ReferenceId }, new RxRate() { Rate = 6d, RxProductLookupId = fertilizerRateLookup.Id.ReferenceId }, new RxRate() { Rate = 2.75, RxProductLookupId = insecticideRateLookup.Id.ReferenceId } }, Shape = new MultiPolygon() { Polygons = new List <Polygon>() { new Polygon() { ExteriorRing = new LinearRing() { Points = new List <Point>() { new Point() { X = -89.488565, Y = 40.476688 }, new Point() { X = -89.485439, Y = 40.476688 }, new Point() { X = -89.485439, Y = 40.475010 }, new Point() { X = -89.488565, Y = 40.475010 }, new Point() { X = -89.488565, Y = 40.476688 } } } } } } }; //Assembled Rx VectorPrescription vectorPrescription = new VectorPrescription() { Description = "Test Prescription", RxProductLookups = new List <RxProductLookup>() { seedVariety1RateLookup, seedVariety2RateLookup, fertilizerRateLookup, seedVariety1DepthLookup, seedVariety2DepthLookup, insecticideRateLookup }, RxShapeLookups = new List <RxShapeLookup>() { zone1, zone2, zone3 }, CropZoneId = cropZone.Id.ReferenceId, FieldId = field.Id.ReferenceId }; (adm.Catalog.Prescriptions as List <Prescription>).Add(vectorPrescription); //-------------------------- //Export data to file via the Plugin //-------------------------- PrecisionPlanting.ADAPT._2020.Plugin plugin = new Plugin(); plugin.Export(adm, path); }