AgGateway.ADAPT.ISOv4Plugin.Writers.GridWriter.WriteGridFile C# (CSharp) Метод

WriteGridFile() приватный Метод

private WriteGridFile ( AgGateway.ADAPT.ApplicationDataModel.Prescriptions.RasterGridPrescription prescription, TreatmentZone treatmentZone ) : string
prescription AgGateway.ADAPT.ApplicationDataModel.Prescriptions.RasterGridPrescription
treatmentZone AgGateway.ADAPT.ISOv4Plugin.Models.TreatmentZone
Результат string
        private string WriteGridFile(RasterGridPrescription prescription, TreatmentZone treatmentZone)
        {
            var gridFileName = GenerateId(5);
            using (var binaryWriter = CreateWriter(Path.ChangeExtension(gridFileName, ".BIN")))
            {
                byte[] previousBytes = BitConverter.GetBytes(0);
                foreach (var rxRate in prescription.Rates)
                {
                    if (rxRate.RxRate == null || !rxRate.RxRate.Any())
                    {
                        //If there is null or no rate, write the previous rate (or 0 if we have not yet entered a valid rate)
                        binaryWriter.Write(previousBytes, 0, previousBytes.Length);
                    } else
                    for (int index = 0; index < rxRate.RxRate.Count; index++)
                    {
                        var dataVariable = treatmentZone.Variables[index];
                        var rate = rxRate.RxRate[index].Rate;
                        if (dataVariable.UserUnit != null)
                            rate = _unitConverter.Convert(dataVariable.UserUnit.ToInternalUom(), dataVariable.IsoUnit.ToAdaptUnit().ToInternalUom(), rate);

                        previousBytes = BitConverter.GetBytes((int)Math.Round(dataVariable.IsoUnit.ConvertToIsoUnit(rate), 0));
                        binaryWriter.Write(previousBytes, 0, previousBytes.Length);
                    }
                }
            }

            return gridFileName;
        }