Beispiel #1
0
        /// <returns>true if it has failures</returns>
        private bool ValidateAssetTypes(Facility requirement, Facility submitted, Facility retFacility)
        {
            if (requirement.AssetTypes == null)
            {
                return(true);
            }
            var ret = false;

            foreach (var assetTypeRequirement in requirement.AssetTypes)
            {
                var v = new CobieObjectValidator <AssetType, Asset>(assetTypeRequirement)
                {
                    TerminationMode = TerminationMode
                };
                if (!v.HasRequirements)
                {
                    continue;
                }
                var candidates = v.GetCandidates(submitted.AssetTypes).ToList();

                if (candidates.Any())
                {
                    foreach (var candidate in candidates)
                    {
                        if (retFacility.AssetTypes == null)
                        {
                            retFacility.AssetTypes = new List <AssetType>();
                        }
                        retFacility.AssetTypes.Add(v.Validate(candidate, retFacility));
                    }
                }
                else
                {
                    if (retFacility.AssetTypes == null)
                    {
                        retFacility.AssetTypes = new List <AssetType>();
                    }
                    retFacility.AssetTypes.Add(v.Validate((AssetType)null, retFacility));
                }
                ret |= v.HasFailures;
            }
            return(ret);
        }
Beispiel #2
0
        /// <returns>true if it has failures</returns>
        private bool ValidateZones(Facility requirement, Facility submitted, Facility retFacility)
        {
            if (requirement.Zones == null)
            {
                return(false);
            }
            var ret = false;
            // hack: create a fake modelFacility candidates from spaces.
            var fakeSubmittedFacility = new Facility();

            fakeSubmittedFacility.Floors = fakeSubmittedFacility.Clone(submitted.Floors as IEnumerable <Floor>).ToList();
            fakeSubmittedFacility.Zones  = new List <Zone>();
            var lSpaces = submitted.Get <Space>().ToList();

            foreach (var zoneRequirement in requirement.Zones)
            {
                var v = new CobieObjectValidator <Zone, Space>(zoneRequirement)
                {
                    TerminationMode = TerminationMode
                };
                if (!v.HasRequirements)
                {
                    continue;
                }

                // hack: now create a fake Zone based on candidates from spaces.
                var fakeZone = fakeSubmittedFacility.Create <Zone>();
                fakeZone.Categories     = zoneRequirement.Categories.Clone().ToList();
                fakeZone.Name           = zoneRequirement.Name;
                fakeZone.ExternalEntity = zoneRequirement.ExternalEntity;
                fakeZone.ExternalSystem = zoneRequirement.ExternalSystem;
                fakeZone.ExternalId     = zoneRequirement.ExternalId;
                fakeZone.Spaces         = new List <SpaceKey>();

                var candidateSpaces = v.GetCandidates(lSpaces).ToList();

                if (candidateSpaces.Any())
                {
                    foreach (var spaceMatch in candidateSpaces)
                    {
                        var mSpace = spaceMatch.MatchedObject as Space;
                        if (mSpace == null)
                        {
                            continue;
                        }
                        var sk = new SpaceKey {
                            Name = mSpace.Name
                        };
                        fakeZone.Spaces.Add(sk);
                    }
                    if (retFacility.Zones == null)
                    {
                        retFacility.Zones = new List <Zone>();
                    }
                    var validatedZone = v.Validate(fakeZone, retFacility);
                    retFacility.Zones.Add(validatedZone);
                    var tmpFloor = retFacility.Get <Floor>(fl => fl.Name == TemporaryFloorName).FirstOrDefault();
                    if (tmpFloor == null)
                    {
                        continue;
                    }
                    // ensure that the floor and spaces are avalialale in the report facility
                    foreach (var spaceKey in validatedZone.Spaces)
                    {
                        // 1) on the floor
                        var submissionOwningFloor =
                            submitted.Get <Floor>(f => f.Spaces != null && f.Spaces.Any(sp => sp.Name == spaceKey.Name)).FirstOrDefault();
                        if (submissionOwningFloor == null)
                        {
                            continue;
                        }
                        var destFloor = retFacility.Get <Floor>(f => f.Name == submissionOwningFloor.Name).FirstOrDefault();
                        if (destFloor == null)
                        {
                            destFloor                = retFacility.Create <Floor>();
                            destFloor.Name           = submissionOwningFloor.Name;
                            destFloor.ExternalEntity = submissionOwningFloor.ExternalEntity;
                            destFloor.ExternalId     = submissionOwningFloor.ExternalId;
                            destFloor.ExternalSystem = submissionOwningFloor.ExternalSystem;
                            destFloor.Elevation      = submissionOwningFloor.Elevation;
                            destFloor.Spaces         = new List <Space>();
                            retFacility.Floors.Add(destFloor); // finally add it in the facility tree
                        }
                        // 2) now on the space.

                        var sourceSpace = tmpFloor.Spaces.FirstOrDefault(sp => sp.Name == spaceKey.Name);
                        if (sourceSpace != null)
                        {
                            destFloor.Spaces.Add(sourceSpace);
                        }
                    }
                    retFacility.Floors.Remove(tmpFloor);
                }
                else
                {
                    if (retFacility.Zones == null)
                    {
                        retFacility.Zones = new List <Zone>();
                    }
                    retFacility.Zones.Add(v.Validate((Zone)null, retFacility));
                }
                ret |= v.HasFailures;
            }
            return(ret);
        }