public List <List <double> > GetRatesForGridType2(string dataPath, ISOTreatmentZone treatmentZone)
        {
            if (treatmentZone == null || treatmentZone.ProcessDataVariables.Count <= 0)
            {
                return(null);
            }

            List <List <double> >        productRates = new List <List <double> >();
            Dictionary <string, ISOUnit> unitsByDDI   = new Dictionary <string, ISOUnit>();
            string filePath = Path.ChangeExtension(Path.Combine(dataPath, Filename), ".bin");

            using (var fileStream = File.OpenRead(filePath))
            {
                var bytes     = new byte[4];
                var rates     = new List <double>();
                var rateCount = 0;

                while (true)
                {
                    var result = fileStream.Read(bytes, 0, bytes.Length);
                    if (result == 0)
                    {
                        break;
                    }

                    var rate = BitConverter.ToInt32(bytes, 0);

                    ISOProcessDataVariable pdv = treatmentZone.ProcessDataVariables[rateCount];
                    ISOUnit unit = null;
                    if (!unitsByDDI.ContainsKey(pdv.ProcessDataDDI))
                    {
                        unit = UnitFactory.Instance.GetUnitByDDI(pdv.ProcessDataDDI.AsInt32DDI());
                        unitsByDDI.Add(pdv.ProcessDataDDI, unit);
                    }
                    unit = unitsByDDI[pdv.ProcessDataDDI];

                    if (unit != null)
                    {
                        rates.Add(unit.ConvertFromIsoUnit(rate));
                    }
                    else
                    {
                        throw new ApplicationException("Missing unit on rate calculation from PDV.");
                    }
                    rateCount++;

                    if (rateCount == treatmentZone.ProcessDataVariables.Count)
                    {
                        productRates.Add(rates);
                        rateCount = 0;
                        rates     = new List <double>();
                    }
                }
            }

            return(productRates);
        }
示例#2
0
        public static List <ISOTreatmentZone> ReadXML(XmlNodeList nodes)
        {
            List <ISOTreatmentZone> items = new List <ISOTreatmentZone>();

            foreach (XmlNode node in nodes)
            {
                items.Add(ISOTreatmentZone.ReadXML(node));
            }
            return(items);
        }
示例#3
0
        public static ISOTreatmentZone ReadXML(XmlNode tznNode)
        {
            ISOTreatmentZone treatmentZone = new ISOTreatmentZone();

            treatmentZone.TreatmentZoneCode       = tznNode.GetXmlNodeValueAsByte("@A");
            treatmentZone.TreatmentZoneDesignator = tznNode.GetXmlNodeValue("@B");
            treatmentZone.TreatmentZoneColour     = tznNode.GetXmlNodeValueAsNullableByte("@C");

            XmlNodeList pdvNodes = tznNode.SelectNodes("PDV");

            if (pdvNodes != null)
            {
                treatmentZone.ProcessDataVariables.AddRange(ISOProcessDataVariable.ReadXML(pdvNodes));
            }

            XmlNodeList plnNodes = tznNode.SelectNodes("PLN");

            if (plnNodes != null)
            {
                treatmentZone.Polygons.AddRange(ISOPolygon.ReadXML(plnNodes));
            }
            return(treatmentZone);
        }
        public static ISOTask ReadXML(XmlNode taskNode)
        {
            ISOTask task = new ISOTask();

            task.TaskID                        = taskNode.GetXmlNodeValue("@A");
            task.TaskDesignator                = taskNode.GetXmlNodeValue("@B");
            task.CustomerIdRef                 = taskNode.GetXmlNodeValue("@C");
            task.FarmIdRef                     = taskNode.GetXmlNodeValue("@D");
            task.PartFieldIdRef                = taskNode.GetXmlNodeValue("@E");
            task.ResponsibleWorkerIdRef        = taskNode.GetXmlNodeValue("@F");
            task.TaskStatusInt                 = taskNode.GetXmlNodeValueAsInt("@G");
            task.DefaultTreatmentZoneCode      = taskNode.GetXmlNodeValueAsNullableInt("@H");
            task.PositionLostTreatmentZoneCode = taskNode.GetXmlNodeValueAsNullableInt("@I");
            task.OutOfFieldTreatmentZoneCode   = taskNode.GetXmlNodeValueAsNullableInt("@J");

            //Treatment Zones
            XmlNodeList tznNodes = taskNode.SelectNodes("TZN");

            if (tznNodes != null)
            {
                task.TreatmentZones.AddRange(ISOTreatmentZone.ReadXML(tznNodes));
            }

            //Times
            XmlNodeList timNodes = taskNode.SelectNodes("TIM");

            if (timNodes != null)
            {
                task.Times.AddRange(ISOTime.ReadXML(timNodes));
            }

            //Worker Allocations
            XmlNodeList wanNodes = taskNode.SelectNodes("WAN");

            if (wanNodes != null)
            {
                task.WorkerAllocations.AddRange(ISOWorkerAllocation.ReadXML(wanNodes));
            }

            //Device Allocations
            XmlNodeList danNodes = taskNode.SelectNodes("DAN");

            if (danNodes != null)
            {
                task.DeviceAllocations.AddRange(ISODeviceAllocation.ReadXML(danNodes));
            }

            //Connections
            XmlNodeList cnnNodes = taskNode.SelectNodes("CNN");

            if (cnnNodes != null)
            {
                task.Connections.AddRange(ISOConnection.ReadXML(cnnNodes));
            }

            //Product Allocations
            XmlNodeList panNodes = taskNode.SelectNodes("PAN");

            if (panNodes != null)
            {
                task.ProductAllocations.AddRange(ISOProductAllocation.ReadXML(panNodes));
            }

            //Data Log Triggers
            XmlNodeList dltNodes = taskNode.SelectNodes("DLT");

            if (dltNodes != null)
            {
                task.DataLogTriggers.AddRange(ISODataLogTrigger.ReadXML(dltNodes));
            }

            //Comment Allocations
            XmlNodeList canNodes = taskNode.SelectNodes("CAN");

            if (canNodes != null)
            {
                task.CommentAllocations.AddRange(ISOCommentAllocation.ReadXML(canNodes));
            }

            //Grid
            XmlNode grdNode = taskNode.SelectSingleNode("GRD");

            if (grdNode != null)
            {
                task.Grid = ISOGrid.ReadXML(grdNode);
            }

            //TimeLogs
            XmlNodeList tlgNodes = taskNode.SelectNodes("TLG");

            if (tlgNodes != null)
            {
                task.TimeLogs.AddRange(ISOTimeLog.ReadXML(tlgNodes));
            }

            //Guidance Allocations
            XmlNodeList ganNodes = taskNode.SelectNodes("GAN");

            if (ganNodes != null)
            {
                task.GuidanceAllocations.AddRange(ISOGuidanceAllocation.ReadXML(ganNodes));
            }

            //OperTechPractice
            XmlNode otpNode = taskNode.SelectSingleNode("OTP");

            if (otpNode != null)
            {
                task.OperationTechPractice = ISOOperTechPractice.ReadXML(otpNode);
            }

            return(task);
        }