예제 #1
0
 public static void AreEqual(XmlNodeList ctpNodes, List<Crop> crops, Catalog catalog, Dictionary<string, List<UniqueId>> linkList)
 {
     for (var i = 0; i < ctpNodes.Count; i++)
     {
         AreEqual(ctpNodes[i], crops[i], catalog, linkList);
     }
 }
예제 #2
0
 public static void AreEqual(XmlNodeList prnNodes, List<ProductComponent> productComponents, XmlNodeList productNodes, Catalog catalog, Dictionary<string, List<UniqueId>> linkList)
 {
     for (int i = 0; i < prnNodes.Count; i++)
     {
         AreEqual(prnNodes[i], productComponents[i], productNodes, catalog, linkList);
     }
 }
예제 #3
0
 public static void AreEqual(XmlNodeList fieldNodes, List<Field> fields, Catalog catalog, Dictionary<string, List<UniqueId>> linkList)
 {
     for (int i = 0; i < fieldNodes.Count; i++)
     {
         AreEqual(fieldNodes[i], fields[i], catalog, linkList);
     }
 }
예제 #4
0
        private static void AreEqual(LoggedData loggedData, TSK tsk, Catalog catalog, string cardPath)
        {
            var grower = catalog.Growers.SingleOrDefault(x => x.Id.ReferenceId == loggedData.GrowerId);
            var farm = catalog.Farms.SingleOrDefault(x => x.Id.ReferenceId == loggedData.FarmId);
            var field = catalog.Fields.SingleOrDefault(x => x.Id.ReferenceId == loggedData.FieldId);

            if(grower != null)
                Assert.AreEqual(grower.Id.FindIsoId(), tsk.C);
            if (farm != null)
                Assert.AreEqual(farm.Id.FindIsoId(), tsk.D);
            if (field != null)
                Assert.AreEqual(field.Id.FindIsoId(), tsk.E);

            if(loggedData.TimeScopes != null && loggedData.TimeScopes.Any())
            {
                var tims = tsk.Items.Where(x => x.GetType() == typeof(TIM)).Cast<TIM>().ToList();
                TimAssert.AreEqual(loggedData.TimeScopes, tims);
            }

            if(loggedData.OperationData != null && loggedData.OperationData.Any())
            {
                var tlgs = tsk.Items.Where(x => x.GetType() == typeof(TLG)).Cast<TLG>().ToList();
                TlgAssert.AreEqual(loggedData.OperationData.ToList(), tlgs, catalog, cardPath);
            }
        }
예제 #5
0
        public List<PFD> Map(List<Field> fields, Dictionary<int, string> keyToIsoId, Catalog setupCatalog)
        {
            if (fields == null || !fields.Any())
                return new List<PFD>();

            int fieldIndex = 0;
            return fields.Select(x => MapField(x, keyToIsoId, fieldIndex++, setupCatalog)).ToList();
        }
예제 #6
0
 public static void AreEqual(XmlNode taskData, Catalog catalog, Dictionary<string, List<UniqueId>> linkList)
 {
     CropAssert.AreEqual(taskData.SelectNodes("CTP"), catalog.Crops, catalog, linkList);
     FarmAssert.AreEqual(taskData.SelectNodes("FRM"), catalog.Farms, catalog, linkList);
     FieldAssert.AreEqual(taskData.SelectNodes("PFD"), catalog.Fields, catalog, linkList);
     GrowerAssert.AreEqual(taskData.SelectNodes("CTR"), catalog.Growers, linkList);
     ProductAssert.AreEqual(taskData.SelectNodes("PDT"), catalog, linkList);
 }
예제 #7
0
        private static void AreEqual(XmlNode ctpNode, Crop crop, Catalog catalog, Dictionary<string, List<UniqueId>> linkList)
        {
            UniqueIdAssert.AreEqual(linkList, ctpNode.GetXmlAttribute("A"), crop.Id.UniqueIds);
            Assert.AreEqual(ctpNode.GetXmlAttribute("A"), crop.Id.FindIsoId());
            Assert.AreEqual(ctpNode.GetXmlAttribute("B"), crop.Name);

            var matchingCropVarieties = catalog.Products.Where(x => x is CropVariety).Cast<CropVariety>().Where(cv => cv.CropId == crop.Id.ReferenceId).ToList();
            CropVarietyAssert.AreEqual(ctpNode.SelectNodes("CVT"), matchingCropVarieties, linkList);
        }
예제 #8
0
        private static void CheckBoundary(XmlNode fieldNode, Field field, Catalog catalog)
        {
            var polygons = fieldNode.SelectNodes("PLN");
            if(polygons.Count == 0)
                return;

            var boundary = catalog.FieldBoundaries.Single(b => b.Id.ReferenceId == field.ActiveBoundaryId);
            MultiPolygonAssert.AreEqual(polygons, boundary.SpatialData);
        }
예제 #9
0
 public static void AreEqual(List<LoggedData> loggedDatas, List<TSK> tsks, Catalog catalog, string cardPath)
 {
     tsks = tsks.OrderBy(x => x.A).ToList();
     for (int i = 0; i < loggedDatas.Count; i++)
     {
         var loggedData = loggedDatas[i];
         var matchingTask = tsks[tsks.Count - loggedDatas.Count + i];
         AreEqual(loggedData, matchingTask, catalog, cardPath);
     }
 }
예제 #10
0
        public static void AreEqual(XmlNode productNode, XmlNodeList productNodes, ProductMix productMix, Catalog catalog, Dictionary<string, List<UniqueId>> linkList)
        {
            if (productNode.GetXmlAttribute("A") == null || productNode.GetXmlAttribute("B") == null)
                return;

            UniqueIdAssert.AreEqual(linkList, productNode.GetXmlAttribute("A"), productMix.Id.UniqueIds);
            Assert.AreEqual(productNode.GetXmlAttribute("A"), productMix.Id.FindIsoId());
            Assert.AreEqual(productNode.GetXmlAttribute("B"), productMix.Description);

            var prnNodes = productNode.SelectNodes("PRN");
            ProductComponentAssert.AreEqual(prnNodes, productMix.ProductComponents, productNodes, catalog, linkList);
        }
예제 #11
0
        private static void AreEqual(XmlNode prnNode, ProductComponent productComponent, XmlNodeList productNodes, Catalog catalog, Dictionary<string, List<UniqueId>> linkList)
        {
            var productNode = FindMatchingProductNode(prnNode.GetXmlAttribute("A"), productNodes);
            if (productNode == null)
                return;

            var quantityDdi = Int32.Parse(productNode.GetXmlAttribute("E"));
            var uom = new RepresentationMapper().GetUnitForDdi(quantityDdi);
            Assert.AreEqual(uom, productComponent.Quantity.Value.UnitOfMeasure);
            Assert.AreEqual(prnNode.GetXmlAttribute("B"), productComponent.Quantity.Value.Value);

            var ingredient = catalog.Ingredients.Single(x => x.Id.ReferenceId == productComponent.IngredientId);
            Assert.AreEqual(productNode.GetXmlAttribute("B"), ingredient.Description);
        }
예제 #12
0
        private static void AreEqual(XmlNode fieldNode, Field field, Catalog catalog, Dictionary<string, List<UniqueId>> linkList)
        {
            if (fieldNode.GetXmlAttribute("A") == null || fieldNode.GetXmlAttribute("C") == null || fieldNode.GetXmlAttribute("D") == null)
                return;

            UniqueIdAssert.AreEqual(linkList, fieldNode.GetXmlAttribute("A"), field.Id.UniqueIds);
            Assert.AreEqual(fieldNode.GetXmlAttribute("A"), field.Id.FindIsoId());
            Assert.AreEqual(fieldNode.GetXmlAttribute("C"), field.Description);

            CheckArea(fieldNode, field);
            CheckFarm(fieldNode, field, catalog);
            CheckBoundary(fieldNode, field, catalog);
            CheckGuidanceGroups(fieldNode, field, catalog, linkList);
            CheckCropZone(fieldNode, field, catalog);
        }
예제 #13
0
        public static void AreEqual(XmlNodeList tskNodes, string currentPath, List<LoggedData> loggedData, Catalog catalog)
        {
            int tsksWithTlgs = 0;
            foreach (XmlNode node in tskNodes)
            {
                if (node.SelectNodes("TLG").Count > 0)
                {
                    tsksWithTlgs++;

                    var matchingLoggedData = loggedData.SingleOrDefault(x => x.Id.FindIsoId() == node.Attributes["A"].Value);
                    AreEqual(node, currentPath, matchingLoggedData, catalog);
                }
            }

            Assert.AreEqual(tsksWithTlgs, loggedData.Count);
        }
예제 #14
0
        private TimeScope Map(TIM tim, Catalog catalog)
        {
            DateTime? stamp1 = null;
            if (tim.A.HasValue)
                stamp1 = tim.A.Value;

            DateTime? stamp2 = null;
            if (tim.B.HasValue)
                stamp2 = tim.B.Value;

            var timeScope = new TimeScope {TimeStamp1 = stamp1, TimeStamp2 = stamp2, DateContext = DateContextEnum.ActualStart};

            if(catalog.TimeScopes == null)
                catalog.TimeScopes = new List<TimeScope>();
            catalog.TimeScopes.Add(timeScope);
            return timeScope;
        }
예제 #15
0
        private static void CheckCropZone(XmlNode fieldNode, Field field, Catalog catalog)
        {
            var cropId = fieldNode.GetXmlAttribute("G");
            if(String.IsNullOrEmpty(cropId))
               return;

            var cropZone = catalog.CropZones.Single(cz => cz.FieldId == field.Id.ReferenceId);
            var crop = catalog.Crops.Single(c => c.Id.ReferenceId == cropZone.CropId);

            Assert.AreEqual(cropId, crop.Id.FindIsoId());
            Assert.AreEqual(field.Id.ReferenceId, cropZone.FieldId);
            Assert.AreEqual(field.Description, cropZone.Description);
            Assert.AreEqual(field.Area.Value.Value, cropZone.Area.Value.Value);

            if(field.GuidanceGroupIds != null)
                Assert.AreEqual(field.GuidanceGroupIds, cropZone.GuidanceGroupIds);
        }
예제 #16
0
        public static void AreEqual(XmlNodeList productNodes, Catalog catalog, Dictionary<string, List<UniqueId>> linkList)
        {
            for (int i = 0; i < productNodes.Count; i++)
            {
                if (productNodes[i].GetXmlAttribute("F") == "1")//fertilizerProduct
                {
                    var matchingFertilizer = catalog.Products.Single(fp => fp.Id.FindIsoId() == productNodes[i].GetXmlAttribute("A")) as FertilizerProduct;
                    FertilizerProductAssert.AreEqual(productNodes[i], matchingFertilizer, linkList);

                }
                else if (productNodes[i].GetXmlAttribute("F") == "2")//productMix
                {
                    var matchingProductMix = catalog.Products.Single(pm => pm.Id.FindIsoId() == productNodes[i].GetXmlAttribute("A")) as ProductMix;
                    ProductMixAssert.AreEqual(productNodes[i], productNodes, matchingProductMix, catalog, linkList);
                }
            }
        }
예제 #17
0
 private static void AreEqual(XmlNode tskNode, string currentPath, LoggedData loggedData, Catalog catalog)
 {
     var tlgNodes = tskNode.SelectNodes("TLG");
     OperationDataAssert.AreEqual(tlgNodes, currentPath, loggedData.OperationData.ToList());
 }
예제 #18
0
        private PFD MapField(Field field, Dictionary<int, string> keyToIsoId, int fieldIndex, Catalog setupCatalog)
        {
            var isoField = new PFD
            {
                C = field.Description,
                D = (ulong) Math.Round(field.Area.Value.Value, 0)
            };
            isoField.A = isoField.GetIsoId(fieldIndex);
            if (field.FarmId != null)
            {
                isoField.F = keyToIsoId[field.FarmId.Value];
                var farm = setupCatalog.Farms.First(f => f.Id.ReferenceId == field.FarmId.Value);
                if (farm.GrowerId != null)
                {
                    isoField.E = keyToIsoId[farm.GrowerId.Value];
                }
            }
            if (field.ActiveBoundaryId != null)
            {
                var boundary = setupCatalog.FieldBoundaries.Single(b => b.Id.ReferenceId == field.ActiveBoundaryId.Value);
                isoField.Items = new IWriter[] {_boundaryMapper.Map(boundary.SpatialData, BoundaryType.Field, boundary.Description)};
            }

            keyToIsoId.Add(field.Id.ReferenceId, isoField.A);
            return isoField;
        }
예제 #19
0
 public List<TimeScope> Map(IEnumerable<TIM> tims, Catalog catalog)
 {
     return tims == null ? null : tims.Select(x => Map(x, catalog)).ToList();
 }
예제 #20
0
 public void Setup()
 {
     _timeScopeMapper = new TimeScopeMapper();
     _tims = new List<TIM>();
     _catalog = new Catalog {TimeScopes = new List<TimeScope>()};
 }
예제 #21
0
파일: Plugin.cs 프로젝트: ADAPT/ISOv4Plugin
        private static TaskDataDocument ConvertTaskDataFileToModel(string taskDataFile, ApplicationDataModel.ADM.ApplicationDataModel dataModel)
        {
            var taskDocument = new TaskDataDocument();
            if (taskDocument.LoadFromFile(taskDataFile) == false)
                return taskDocument;

            var catalog = new Catalog();
            catalog.Growers = taskDocument.Customers.Values.ToList();
            catalog.Farms = taskDocument.Farms.Values.ToList();
            catalog.Fields = taskDocument.Fields.Values.ToList();
            catalog.GuidanceGroups = taskDocument.GuidanceGroups.Values.Select(x => x.Group).ToList();
            catalog.GuidancePatterns = taskDocument.GuidanceGroups.Values.SelectMany(x => x.Patterns.Values).ToList();
            catalog.Crops = taskDocument.Crops.Values.ToList();
            catalog.CropZones = taskDocument.CropZones.Values.ToList();
            catalog.DeviceElements = taskDocument.Machines.Values.ToList();
            catalog.FieldBoundaries = taskDocument.FieldBoundaries;
            catalog.Ingredients = taskDocument.Ingredients;
            catalog.Prescriptions = taskDocument.RasterPrescriptions.Cast<Prescription>().ToList();
            catalog.ContactInfo = taskDocument.Contacts;
            catalog.Products = AddAllProducts(taskDocument);

            dataModel.Catalog = catalog;

            var documents = new Documents();
            documents.GuidanceAllocations = taskDocument.GuidanceAllocations;
            documents.LoggedData = taskDocument.Tasks;

            dataModel.Documents = documents;

            return taskDocument;
        }
예제 #22
0
        private static void CheckFarm(XmlNode fieldNode, Field field, Catalog catalog)
        {
            var farmId = fieldNode.GetXmlAttribute("F");
            if (String.IsNullOrEmpty(farmId))
                return;

            var farm = catalog.Farms.Single(f => f.Id.ReferenceId == field.FarmId);
            Assert.AreEqual(farmId, farm.Id.FindIsoId());
        }
예제 #23
0
        private static void CheckGuidanceGroups(XmlNode fieldNode, Field field, Catalog catalog, Dictionary<string, List<UniqueId>> linkList)
        {
            var ggps = fieldNode.SelectNodes("GGP");
            if(ggps.Count == 0)
                return;

            var guidanceGroups = catalog.GuidanceGroups.Where(gg => field.GuidanceGroupIds.Contains(gg.Id.ReferenceId));
            GuidanceGroupAssert.AreEqual(ggps, guidanceGroups, catalog, linkList);
        }
예제 #24
0
        public void Setup()
        {
            _loggedData = new LoggedData();
            _loggedDatas = new List<LoggedData>{ _loggedData };
            _catalog = new Catalog();
            _datacardPath = "";
            _taskDocumentWriter = new TaskDocumentWriter();

            _timeMapperMock = new Mock<ITimeMapper>();
            _tlgMapperMock = new Mock<ITlgMapper>();

            _taskMapper = new TaskMapper(_timeMapperMock.Object, _tlgMapperMock.Object);
        }
예제 #25
0
        public static void AreEqual(XmlNode taskData, Documents documents, Catalog catalog, string currentPath)
        {
            var tskNodes = taskData.SelectNodes("TSK");

            LoggedDataAssert.AreEqual(tskNodes, currentPath, documents.LoggedData.ToList(), catalog);
        }
예제 #26
0
        public void Setup()
        {
            _tsk = new TSK();
            _tsks = new List<TSK>{ _tsk };
            _dataPath = Path.GetTempPath();
            _documents = new Documents();
            _catalog = new Catalog();
            _linkIds = new Dictionary<string, List<UniqueId>>();

            _dataModel = new ApplicationDataModel();
            _dataModel.Documents = _documents;
            _dataModel.Catalog = _catalog;

            _operationDataMapper = new Mock<IOperationDataMapper>();

            _loggedDataMapper = new LoggedDataMapper(_operationDataMapper.Object);
        }