Example #1
0
        private void LoadRates(XmlNode inputNode, GridDescriptor gridDescriptor, Dictionary<int, TreatmentZone> treatmentZones, RasterGridPrescription prescription)
        {
            prescription.LossOfGpsRate = LoadRateFromTreatmentZones(inputNode.GetXmlNodeValue("@I"), treatmentZones).FirstOrDefault();
            prescription.OutOfFieldRate = LoadRateFromTreatmentZones(inputNode.GetXmlNodeValue("@J"), treatmentZones).FirstOrDefault();

            if (gridDescriptor.TreatmentZones != null)
            {
                var treatmentZone = treatmentZones.FindById(gridDescriptor.TreatmentZones.First());
                if (treatmentZone == null)
                    return;

                LoadProducts(treatmentZone, prescription);
                LoadRateUnits(treatmentZone, prescription);
                prescription.Rates = LoadRatesFromTreatmentZones(gridDescriptor, treatmentZones, prescription.ProductIds, prescription);
            }
            else if (gridDescriptor.ProductRates != null)
            {
                var treatmentZoneTemplate = treatmentZones.FindById(gridDescriptor.ProductRateTemplateId);
                if (treatmentZoneTemplate == null)
                    return;

                LoadProducts(treatmentZoneTemplate, prescription);
                LoadRateUnits(treatmentZoneTemplate, prescription);
                prescription.Rates = LoadRatesFromProducts(gridDescriptor, prescription.ProductIds, prescription);
            }
        }
Example #2
0
        private static List<RxRates> LoadRatesFromTreatmentZones(GridDescriptor gridDescriptor, Dictionary<int, TreatmentZone> treatmentZones, List<int> productIds, RasterGridPrescription prescription)
        {
            var rates = new List<RxRates>();
            foreach (var treatmentZoneId in gridDescriptor.TreatmentZones)
            {
                var treatmentZone = treatmentZones.FindById(treatmentZoneId);
                if (treatmentZone == null)
                    return null;

                var rate = new RxRates { RxRate = new List<RxRate>() };

                for (int i = 0; i < treatmentZone.Variables.Count; i++)
                {
                    var dataVariable = treatmentZone.Variables[i];
                    AddRate(productIds[i], dataVariable.Value, rate, prescription, treatmentZone.Variables[i].IsoUnit.ToAdaptUnit());
                }

                rates.Add(rate);
            }

            return rates;
        }