AgGateway.ADAPT.ISOv4Plugin.Writers.PrescriptionWriter.WritePrescription C# (CSharp) Method

WritePrescription() private method

private WritePrescription ( AgGateway.ADAPT.ApplicationDataModel.Prescriptions.RasterGridPrescription prescription ) : void
prescription AgGateway.ADAPT.ApplicationDataModel.Prescriptions.RasterGridPrescription
return void
        private void WritePrescription(RasterGridPrescription prescription)
        {
            var writer = TaskWriter.RootWriter;

            if (!IsValidPrescription(prescription))
                return;

            var prescriptionId = prescription.Id.FindIsoId() ?? GenerateId();

            writer.WriteStartElement(XmlPrefix);
            writer.WriteAttributeString("A", prescriptionId);
            writer.WriteAttributeString("B", prescription.Description);

            WriteFieldMeta(writer, prescription.FieldId);

            // Task status - planned
            writer.WriteAttributeString("G", "1");

            var defaultTreatmentZone = WriteTreatmentZones(writer, prescription);

            _gridWriter.Write(writer, prescription, defaultTreatmentZone);
            var matchingLoggedData = null as LoggedData;

            if (TaskWriter.DataModel.Documents != null && TaskWriter.DataModel.Documents.LoggedData != null)
                matchingLoggedData = TaskWriter.DataModel.Documents.LoggedData.Where(ld => ld.OperationData != null).SingleOrDefault(x => x.OperationData.FirstOrDefault(y => y.PrescriptionId == prescription.Id.ReferenceId) != null);

            if (matchingLoggedData != null)
            {
                var taskMapper = new TaskMapper();
                var isoInt = Convert.ToInt32(prescriptionId.Remove(0, 3))-1;

                var mappedTsk = taskMapper.Map(new List<LoggedData> { matchingLoggedData }, TaskWriter.DataModel.Catalog, TaskWriter.BaseFolder, isoInt, TaskWriter).First();

                foreach (var item in mappedTsk.Items)
                {
                    item.WriteXML(TaskWriter.RootWriter);
                }
            }
            else
            {
                TaskWriter.Ids.Add(prescriptionId, prescription.Id);
            }

            writer.WriteEndElement();
        }

Usage Example

Example #1
0
 public static void WriteSingle(TaskDocumentWriter taskWriter, Prescription prescription)
 {
     if (prescription == null)
         return;
     var rasterPrescription = prescription as RasterGridPrescription;
     if (rasterPrescription != null)
     {
         var writer = new PrescriptionWriter(taskWriter);
         writer.WritePrescription(rasterPrescription);
     }
 }
All Usage Examples Of AgGateway.ADAPT.ISOv4Plugin.Writers.PrescriptionWriter::WritePrescription