Write() public static method

public static Write ( XmlWriter writer, string zoneId, TreatmentZone treatmentZone ) : string
writer System.Xml.XmlWriter
zoneId string
treatmentZone AgGateway.ADAPT.ISOv4Plugin.Models.TreatmentZone
return string
Example #1
0
        private TreatmentZone WriteTreatmentZones(XmlWriter writer, RasterGridPrescription prescription)
        {
            if (prescription.ProductIds == null)
            {
                return(null);
            }

            var lossOfSignalTreatmentZone = new TreatmentZone {
                Name = "Loss of GPS", Variables = new List <DataVariable>()
            };
            var outOfFieldTreatmentZone = new TreatmentZone {
                Name = "Out of Field", Variables = new List <DataVariable>()
            };
            var defaultTreatmentZone = new TreatmentZone {
                Name = "Default", Variables = new List <DataVariable>()
            };

            var defaultRate = new NumericRepresentationValue(null, new NumericValue(prescription.RxProductLookups.First().UnitOfMeasure, 0));
            var isoUnit     = DetermineIsoUnit(prescription.RxProductLookups.First().UnitOfMeasure);

            foreach (var productId in prescription.ProductIds)
            {
                var isoProductId = TaskWriter.Products.FindById(productId) ?? TaskWriter.CropVarieties.FindById(productId);

                AddDataVariable(lossOfSignalTreatmentZone, prescription.LossOfGpsRate, isoProductId, isoUnit);
                AddDataVariable(outOfFieldTreatmentZone, prescription.OutOfFieldRate, isoProductId, isoUnit);
                AddDataVariable(defaultTreatmentZone, defaultRate, isoProductId, isoUnit);
            }

            var lossOfSignalZoneId = "253";

            if (lossOfSignalTreatmentZone.Variables.Count > 0)
            {
                writer.WriteXmlAttribute("I", lossOfSignalZoneId);
            }

            var outOfFieldZoneId = "254";

            if (outOfFieldTreatmentZone.Variables.Count > 0)
            {
                writer.WriteXmlAttribute("J", outOfFieldZoneId);
            }

            TreatmentZoneWriter.Write(writer, "1", defaultTreatmentZone);
            if (lossOfSignalTreatmentZone.Variables.Count > 0)
            {
                TreatmentZoneWriter.Write(writer, lossOfSignalZoneId, lossOfSignalTreatmentZone);
            }
            if (outOfFieldTreatmentZone.Variables.Count > 0)
            {
                TreatmentZoneWriter.Write(writer, outOfFieldZoneId, outOfFieldTreatmentZone);
            }

            return(defaultTreatmentZone);
        }