Exemplo n.º 1
0
        private static void WritePoint(XmlWriter writer, Point point, string label)
        {
            writer.WriteStartElement("PNT");
            writer.WriteXmlAttribute("A", "2");
            writer.WriteXmlAttribute("B", label);
            writer.WriteXmlAttribute("C", point.Y.ToString(CultureInfo.InvariantCulture)); // Latitude
            writer.WriteXmlAttribute("D", point.X.ToString(CultureInfo.InvariantCulture)); // Longitude

            writer.WriteEndElement();
        }
Exemplo n.º 2
0
        private static void WriteContacts(XmlWriter writer, List<Contact> contacts)
        {
            if (contacts == null || contacts.Count == 0)
                return;

            writer.WriteXmlAttribute("J", GetContactForType(contacts, ContactTypeEnum.FixedPhone));
            writer.WriteXmlAttribute("K", GetContactForType(contacts, ContactTypeEnum.MobilePhone));
            writer.WriteXmlAttribute("L", GetContactForType(contacts, ContactTypeEnum.Fax));
            writer.WriteXmlAttribute("M", GetContactForType(contacts, ContactTypeEnum.Email));
        }
Exemplo n.º 3
0
        private static void WriteTotalQuantity(XmlWriter writer, NumericRepresentationValue quantity)
        {
            if (quantity == null || quantity.Value == null)
                return;

            writer.WriteXmlAttribute("G", quantity.Value.Value.ToString("F0", CultureInfo.InvariantCulture));
        }
Exemplo n.º 4
0
        private void WriteCustomerReference(XmlWriter writer, int? growerId)
        {
            if (!growerId.HasValue)
                return;

            writer.WriteXmlAttribute("I", TaskWriter.Customers.FindById(growerId.Value));
        }
Exemplo n.º 5
0
        private static void WriteDataVariable(XmlWriter writer, DataVariable dataVariable)
        {
            writer.WriteStartElement("PDV");

            var variableDdi = DetermineVariableDdi(dataVariable);
            writer.WriteAttributeString("A", string.Format(CultureInfo.InvariantCulture, "{0:X4}", variableDdi));
            writer.WriteAttributeString("B", dataVariable.IsoUnit.ConvertToIsoUnit(dataVariable.Value).ToString("F0", CultureInfo.InvariantCulture));
            writer.WriteXmlAttribute("C", dataVariable.ProductId);

            writer.WriteEndElement();
        }
Exemplo n.º 6
0
        private void WriteGuidacenGroup(XmlWriter writer, GuidanceGroup guidanceGroup)
        {
            writer.WriteStartElement(XmlPrefix);
            var guidanceGroupId = guidanceGroup.Id.FindIsoId() ?? GenerateId();
            TaskWriter.Ids.Add(guidanceGroupId, guidanceGroup.Id);

            writer.WriteAttributeString("A", guidanceGroupId);
            writer.WriteXmlAttribute("B", guidanceGroup.Description);

            WriteGuidancePatterns(writer, guidanceGroup.GuidancePatternIds);
            WriteBoundary(writer, guidanceGroup.BoundingPolygon);

            writer.WriteEndElement();
        }
Exemplo n.º 7
0
        public static void WriteLine(XmlWriter writer, LineString line, string lineType)
        {
            if (line == null || line.Points == null || line.Points.Count == 0)
                return;

            writer.WriteStartElement("LSG");
            writer.WriteXmlAttribute("A", lineType);

            for (int i = 0; i < line.Points.Count; i++)
            {
                var pointLabel = i == 0 ? "start" : i == line.Points.Count - 1 ? "end" : "";
                WritePoint(writer, line.Points[i], pointLabel);
            }

            writer.WriteEndElement();
        }
Exemplo n.º 8
0
        private static void WriteRing(XmlWriter writer, LinearRing ring, bool isExterior)
        {
            if (ring.Points == null ||
                ring.Points.Count == 0)
                return;

            writer.WriteStartElement("LSG");
            writer.WriteXmlAttribute("A", isExterior ? "1" : "2");

            for (int i = 0; i < ring.Points.Count; i++)
            {
                var pointLabel = i == 0 ? "start" : i == ring.Points.Count - 1 ? "end" : "";
                WritePoint(writer, ring.Points[i], pointLabel);
            }

            writer.WriteEndElement();
        }
Exemplo n.º 9
0
        private static void WriteContactInfo(XmlWriter writer, ContactInfo contactInfo)
        {
            if (contactInfo == null)
                return;

            writer.WriteXmlAttribute("D", contactInfo.AddressLine1);
            writer.WriteXmlAttribute("E", contactInfo.PoBoxNumber);
            writer.WriteXmlAttribute("F", contactInfo.PostalCode);
            writer.WriteXmlAttribute("G", contactInfo.City);
            writer.WriteXmlAttribute("H", contactInfo.StateOrProvince);
            writer.WriteXmlAttribute("I", contactInfo.Country);
        }
Exemplo n.º 10
0
        public static void WritePolygon(XmlWriter writer, Polygon polygon)
        {
            if (polygon.ExteriorRing == null)
                return;

            writer.WriteStartElement("PLN");
            writer.WriteXmlAttribute("A", "1");

            WriteRing(writer, polygon.ExteriorRing, true);
            if (polygon.InteriorRings != null)
            {
                foreach (var ring in polygon.InteriorRings)
                {
                    WriteRing(writer, ring, false);
                }
            }

            writer.WriteEndElement();
        }
Exemplo n.º 11
0
        public static string Write(XmlWriter writer, string zoneId, TreatmentZone treatmentZone)
        {
            if (treatmentZone == null)
                return null;

            writer.WriteStartElement("TZN");
            writer.WriteAttributeString("A", zoneId);
            writer.WriteXmlAttribute("B", treatmentZone.Name);

            if (treatmentZone.Variables != null)
            {
                foreach (var dataVariable in treatmentZone.Variables)
                {
                    WriteDataVariable(writer, dataVariable);
                }
            }

            writer.WriteEndElement();
            return zoneId;
        }
Exemplo n.º 12
0
        private void WriteFarmReference(XmlWriter writer, int? farmId)
        {
            if (!farmId.HasValue)
                return;

            writer.WriteXmlAttribute("F", TaskWriter.Farms.FindById(farmId.Value));
        }
Exemplo n.º 13
0
        private void WriteCropZone(XmlWriter writer, CompoundIdentifier fieldId)
        {
            if (TaskWriter.DataModel.Catalog.CropZones == null ||
                TaskWriter.DataModel.Catalog.CropZones.Count == 0)
                return;

            foreach (var cropZone in TaskWriter.DataModel.Catalog.CropZones)
            {
                if (cropZone.FieldId == fieldId.ReferenceId)
                {
                    var cropId = TaskWriter.Crops.FindById(cropZone.CropId.Value);
                    writer.WriteXmlAttribute("G", cropId);
                    break;
                }
            }
        }
Exemplo n.º 14
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;
        }
Exemplo n.º 15
0
        private void WriteFieldMeta(XmlWriter writer, int fieldId)
        {
            var field = TaskWriter.Fields.FindById(fieldId);
            writer.WriteXmlAttribute("E", field);

            if (!string.IsNullOrEmpty(field))
                WriteFarmMeta(writer, fieldId);
        }
Exemplo n.º 16
0
        private void WriteFarmMeta(XmlWriter writer, int fieldId)
        {
            foreach (var field in TaskWriter.DataModel.Catalog.Fields)
            {
                if (field.Id.ReferenceId == fieldId)
                {
                    if (field.FarmId.HasValue)
                    {
                        var farmId = TaskWriter.Farms.FindById(field.FarmId.Value);
                        writer.WriteXmlAttribute("D", farmId);

                        if (!string.IsNullOrEmpty(farmId))
                            WriteCustomerMeta(writer, field.FarmId.Value);
                    }
                    break;
                }
            }
        }
Exemplo n.º 17
0
 private void WriteCustomerMeta(XmlWriter writer, int farmId)
 {
     foreach (var farm in TaskWriter.DataModel.Catalog.Farms)
     {
         if (farm.Id.ReferenceId == farmId)
         {
             if (farm.GrowerId.HasValue)
             {
                 var customerId = TaskWriter.Customers.FindById(farm.GrowerId.Value);
                 writer.WriteXmlAttribute("C", customerId);
             }
             break;
         }
     }
 }
Exemplo n.º 18
0
        private static string WriteGpsData(XmlWriter writer, GpsSource gpsSource)
        {
            if (gpsSource == null)
                return null;

            if (_SourceMapping.ContainsKey(gpsSource.SourceType))
                writer.WriteXmlAttribute("I", _SourceMapping[gpsSource.SourceType]);

            writer.WriteXmlAttribute("J", GetAccuracy(gpsSource.HorizontalAccuracy));
            writer.WriteXmlAttribute("K", GetAccuracy(gpsSource.VerticalAccuracy));

            return null;
        }
Exemplo n.º 19
0
        private void WriteGuidancePattern(XmlWriter writer, GuidancePattern guidancePattern)
        {
            var patternType = ValidateAndGetPatternType(guidancePattern);
            // Bail out for inconsistent pattern type.
            if (string.IsNullOrEmpty(patternType))
                return;

            var guidancePatternId = guidancePattern.Id.FindIsoId() ?? GenerateId();
            TaskWriter.Ids.Add(guidancePatternId, guidancePattern.Id);

            writer.WriteStartElement(XmlPrefix);
            writer.WriteAttributeString("A", guidancePatternId);
            writer.WriteXmlAttribute("B", guidancePattern.Description);
            writer.WriteAttributeString("C", patternType);
            writer.WriteXmlAttribute("D", GetPropagationDirection(guidancePattern.PropagationDirection));
            writer.WriteXmlAttribute("E", GetExtension(guidancePattern.Extension));
            writer.WriteXmlAttribute("G", GetHeading(guidancePattern));
            writer.WriteXmlAttribute("M", guidancePattern.OriginalEpsgCode);

            WriteGpsData(writer, guidancePattern.GpsSource);
            WritePattern(writer, guidancePattern);

            WriteBoundary(writer, guidancePattern.BoundingPolygon);

            writer.WriteEndElement();
        }
Exemplo n.º 20
0
        private string WriteWorker(XmlWriter writer, Person person)
        {
            var workerId = person.Id.FindIsoId() ?? GenerateId();
            TaskWriter.Ids.Add(workerId, person.Id);

            writer.WriteStartElement(XmlPrefix);
            writer.WriteAttributeString("A", workerId);
            writer.WriteAttributeString("B", person.LastName);
            writer.WriteXmlAttribute("C", person.FirstName);

            var contactInfo = FindContactInfo(person.ContactInfoId);
            WriteContactInfo(writer, contactInfo);

            writer.WriteEndElement();

            return workerId;
        }