Example #1
0
		public virtual bool Validate(MARC.Everest.Interfaces.IGraphable o, string location, out MARC.Everest.Connectors.IResultDetail[] outDetails) {
			MARC.Everest.RMIM.UV.NE2008.MCCI_MT100200UV01.AttentionLine instance = o as MARC.Everest.RMIM.UV.NE2008.MCCI_MT100200UV01.AttentionLine;;
			outDetails = new MARC.Everest.Connectors.IResultDetail[0]; System.Collections.Generic.List<MARC.Everest.Connectors.IResultDetail> details = new System.Collections.Generic.List<MARC.Everest.Connectors.IResultDetail>(10);;
			bool isValid = true;;
			if(instance == null && o != null) throw new System.NullReferenceException(System.String.Format("Could not cast type '{0}' to 'MARC.Everest.RMIM.UV.NE2008.MCCI_MT100200UV01.AttentionLine'!", o.GetType().FullName));if(instance == null || instance.NullFlavor != null) return true;;
			outDetails = details.ToArray();;
			return isValid;;
		}
Example #2
0
		public virtual bool Validate(MARC.Everest.Interfaces.IGraphable o, string location, out MARC.Everest.Connectors.IResultDetail[] outDetails) {
			MARC.Everest.RMIM.UV.NE2008.MCCI_MT100200UV01.Agent instance = o as MARC.Everest.RMIM.UV.NE2008.MCCI_MT100200UV01.Agent;;
			outDetails = new MARC.Everest.Connectors.IResultDetail[0]; System.Collections.Generic.List<MARC.Everest.Connectors.IResultDetail> details = new System.Collections.Generic.List<MARC.Everest.Connectors.IResultDetail>(10);;
			bool isValid = true;;
			if(instance == null && o != null) throw new System.NullReferenceException(System.String.Format("Could not cast type '{0}' to 'MARC.Everest.RMIM.UV.NE2008.MCCI_MT100200UV01.Agent'!", o.GetType().FullName));if(instance == null || instance.NullFlavor != null) return true;if(instance.ClassCode == null || instance.ClassCode.NullFlavor != null) { isValid &= false; details.Add(new MARC.Everest.Connectors.MandatoryElementMissingResultDetail(MARC.Everest.Connectors.ResultDetailType.Error, "Property ClassCode in MARC.Everest.RMIM.UV.NE2008.MCCI_MT100200UV01.Agent is marked mandatory and is either not assigned, or is assigned a null flavor. This is not permitted.", location));  } 
;
			outDetails = details.ToArray();;
			return isValid;;
		}
Example #3
0
		public virtual bool Validate(MARC.Everest.Interfaces.IGraphable o, string location, out MARC.Everest.Connectors.IResultDetail[] outDetails) {
			MARC.Everest.RMIM.UV.NE2008.PRPA_MT201306UV02.LivingSubjectBirthPlaceName instance = o as MARC.Everest.RMIM.UV.NE2008.PRPA_MT201306UV02.LivingSubjectBirthPlaceName;;
			outDetails = new MARC.Everest.Connectors.IResultDetail[0]; System.Collections.Generic.List<MARC.Everest.Connectors.IResultDetail> details = new System.Collections.Generic.List<MARC.Everest.Connectors.IResultDetail>(10);;
			bool isValid = true;;
			if(instance == null && o != null) throw new System.NullReferenceException(System.String.Format("Could not cast type '{0}' to 'MARC.Everest.RMIM.UV.NE2008.PRPA_MT201306UV02.LivingSubjectBirthPlaceName'!", o.GetType().FullName));if(instance == null || instance.NullFlavor != null) return true;if(instance.Value == null) { isValid &= Host.CreateRequiredElements; details.Add(new MARC.Everest.Connectors.RequiredElementMissingResultDetail(isValid ? MARC.Everest.Connectors.ResultDetailType.Warning : MARC.Everest.Connectors.ResultDetailType.Error, "Property Value in MARC.Everest.RMIM.UV.NE2008.PRPA_MT201306UV02.LivingSubjectBirthPlaceName is marked 'populated' and isn't assigned (you must at minimum, assign a nullFlavor for this attribute)!", location));  } 
if(instance.SemanticsText == null) { isValid &= Host.CreateRequiredElements; details.Add(new MARC.Everest.Connectors.RequiredElementMissingResultDetail(isValid ? MARC.Everest.Connectors.ResultDetailType.Warning : MARC.Everest.Connectors.ResultDetailType.Error, "Property SemanticsText in MARC.Everest.RMIM.UV.NE2008.PRPA_MT201306UV02.LivingSubjectBirthPlaceName is marked 'populated' and isn't assigned (you must at minimum, assign a nullFlavor for this attribute)!", location));  } 
;
			outDetails = details.ToArray();;
			return isValid;;
		}
Example #4
0
		public virtual bool Validate(MARC.Everest.Interfaces.IGraphable o, string location, out MARC.Everest.Connectors.IResultDetail[] outDetails) {
			MARC.Everest.RMIM.UV.NE2008.COCT_MT510000UV06.CoveredParty instance = o as MARC.Everest.RMIM.UV.NE2008.COCT_MT510000UV06.CoveredParty;;
			outDetails = new MARC.Everest.Connectors.IResultDetail[0]; System.Collections.Generic.List<MARC.Everest.Connectors.IResultDetail> details = new System.Collections.Generic.List<MARC.Everest.Connectors.IResultDetail>(10);;
			bool isValid = true;;
			if(instance == null && o != null) throw new System.NullReferenceException(System.String.Format("Could not cast type '{0}' to 'MARC.Everest.RMIM.UV.NE2008.COCT_MT510000UV06.CoveredParty'!", o.GetType().FullName));if(instance == null || instance.NullFlavor != null) return true;if(instance.ClassCode == null || instance.ClassCode.NullFlavor != null) { isValid &= false; details.Add(new MARC.Everest.Connectors.MandatoryElementMissingResultDetail(MARC.Everest.Connectors.ResultDetailType.Error, "Property ClassCode in MARC.Everest.RMIM.UV.NE2008.COCT_MT510000UV06.CoveredParty is marked mandatory and is either not assigned, or is assigned a null flavor. This is not permitted.", location));  } 
if(instance.Id == null) { isValid &= Host.CreateRequiredElements; details.Add(new MARC.Everest.Connectors.RequiredElementMissingResultDetail(isValid ? MARC.Everest.Connectors.ResultDetailType.Warning : MARC.Everest.Connectors.ResultDetailType.Error, "Property Id in MARC.Everest.RMIM.UV.NE2008.COCT_MT510000UV06.CoveredParty is marked 'populated' and isn't assigned (you must at minimum, assign a nullFlavor for this attribute)!", location));  } 
;
			outDetails = details.ToArray();;
			return isValid;;
		}
Example #5
0
		public virtual bool Validate(MARC.Everest.Interfaces.IGraphable o, string location, out MARC.Everest.Connectors.IResultDetail[] outDetails) {
			MARC.Everest.RMIM.UV.NE2008.COCT_MT150003UV03.Organization instance = o as MARC.Everest.RMIM.UV.NE2008.COCT_MT150003UV03.Organization;;
			outDetails = new MARC.Everest.Connectors.IResultDetail[0]; System.Collections.Generic.List<MARC.Everest.Connectors.IResultDetail> details = new System.Collections.Generic.List<MARC.Everest.Connectors.IResultDetail>(10);;
			bool isValid = true;;
			if(instance == null && o != null) throw new System.NullReferenceException(System.String.Format("Could not cast type '{0}' to 'MARC.Everest.RMIM.UV.NE2008.COCT_MT150003UV03.Organization'!", o.GetType().FullName));if(instance == null || instance.NullFlavor != null) return true;if(instance.ClassCode == null || instance.ClassCode.NullFlavor != null) { isValid &= false; details.Add(new MARC.Everest.Connectors.MandatoryElementMissingResultDetail(MARC.Everest.Connectors.ResultDetailType.Error, "Property ClassCode in MARC.Everest.RMIM.UV.NE2008.COCT_MT150003UV03.Organization is marked mandatory and is either not assigned, or is assigned a null flavor. This is not permitted.", location));  } 
if(instance.DeterminerCode == null || instance.DeterminerCode.NullFlavor != null) { isValid &= false; details.Add(new MARC.Everest.Connectors.MandatoryElementMissingResultDetail(MARC.Everest.Connectors.ResultDetailType.Error, "Property DeterminerCode in MARC.Everest.RMIM.UV.NE2008.COCT_MT150003UV03.Organization is marked mandatory and is either not assigned, or is assigned a null flavor. This is not permitted.", location));  } 
if(instance.Id == null || instance.Id.NullFlavor != null) { isValid &= false; details.Add(new MARC.Everest.Connectors.MandatoryElementMissingResultDetail(MARC.Everest.Connectors.ResultDetailType.Error, "Property Id in MARC.Everest.RMIM.UV.NE2008.COCT_MT150003UV03.Organization is marked mandatory and is either not assigned, or is assigned a null flavor. This is not permitted.", location));  } 
if(instance.ContactParty != null && (instance.ContactParty.Count > 2147483647 ||  instance.ContactParty.Count < 1)) { isValid &= false; details.Add(new MARC.Everest.Connectors.InsufficientRepetionsResultDetail(MARC.Everest.Connectors.ResultDetailType.Error, "Property ContactParty in MARC.Everest.RMIM.UV.NE2008.COCT_MT150003UV03.Organization does not have enough elements in the list, need between 1 and 2147483647 elements!", location));  } 
;
			outDetails = details.ToArray();;
			return isValid;;
		}
Example #6
0
		public virtual bool Validate(MARC.Everest.Interfaces.IGraphable o, string location, out MARC.Everest.Connectors.IResultDetail[] outDetails) {
			MARC.Everest.RMIM.UV.NE2008.Interactions.PRPA_IN201305UV02 instance = o as MARC.Everest.RMIM.UV.NE2008.Interactions.PRPA_IN201305UV02;;
			outDetails = new MARC.Everest.Connectors.IResultDetail[0]; System.Collections.Generic.List<MARC.Everest.Connectors.IResultDetail> details = new System.Collections.Generic.List<MARC.Everest.Connectors.IResultDetail>(10);;
			bool isValid = true;;
			if(instance == null && o != null) throw new System.NullReferenceException(System.String.Format("Could not cast type '{0}' to 'MARC.Everest.RMIM.UV.NE2008.Interactions.PRPA_IN201305UV02'!", o.GetType().FullName));if(instance == null || instance.NullFlavor != null) return true;if(instance.Id == null || instance.Id.NullFlavor != null) { isValid &= false; details.Add(new MARC.Everest.Connectors.MandatoryElementMissingResultDetail(MARC.Everest.Connectors.ResultDetailType.Error, "Property Id in MARC.Everest.RMIM.UV.NE2008.Interactions.PRPA_IN201305UV02 is marked mandatory and is either not assigned, or is assigned a null flavor. This is not permitted.", location));  } 
if(instance.CreationTime == null || instance.CreationTime.NullFlavor != null) { isValid &= false; details.Add(new MARC.Everest.Connectors.MandatoryElementMissingResultDetail(MARC.Everest.Connectors.ResultDetailType.Error, "Property CreationTime in MARC.Everest.RMIM.UV.NE2008.Interactions.PRPA_IN201305UV02 is marked mandatory and is either not assigned, or is assigned a null flavor. This is not permitted.", location));  } 
if(instance.InteractionId == null || instance.InteractionId.NullFlavor != null) { isValid &= false; details.Add(new MARC.Everest.Connectors.MandatoryElementMissingResultDetail(MARC.Everest.Connectors.ResultDetailType.Error, "Property InteractionId in MARC.Everest.RMIM.UV.NE2008.Interactions.PRPA_IN201305UV02 is marked mandatory and is either not assigned, or is assigned a null flavor. This is not permitted.", location));  } 
if(instance.ProcessingCode == null || instance.ProcessingCode.NullFlavor != null) { isValid &= false; details.Add(new MARC.Everest.Connectors.MandatoryElementMissingResultDetail(MARC.Everest.Connectors.ResultDetailType.Error, "Property ProcessingCode in MARC.Everest.RMIM.UV.NE2008.Interactions.PRPA_IN201305UV02 is marked mandatory and is either not assigned, or is assigned a null flavor. This is not permitted.", location));  } 
if(instance.ProcessingModeCode == null || instance.ProcessingModeCode.NullFlavor != null) { isValid &= false; details.Add(new MARC.Everest.Connectors.MandatoryElementMissingResultDetail(MARC.Everest.Connectors.ResultDetailType.Error, "Property ProcessingModeCode in MARC.Everest.RMIM.UV.NE2008.Interactions.PRPA_IN201305UV02 is marked mandatory and is either not assigned, or is assigned a null flavor. This is not permitted.", location));  } 
if(instance.AcceptAckCode == null || instance.AcceptAckCode.NullFlavor != null) { isValid &= false; details.Add(new MARC.Everest.Connectors.MandatoryElementMissingResultDetail(MARC.Everest.Connectors.ResultDetailType.Error, "Property AcceptAckCode in MARC.Everest.RMIM.UV.NE2008.Interactions.PRPA_IN201305UV02 is marked mandatory and is either not assigned, or is assigned a null flavor. This is not permitted.", location));  } 
if(instance.Receiver != null && (instance.Receiver.Count > 2147483647 ||  instance.Receiver.Count < 1)) { isValid &= false; details.Add(new MARC.Everest.Connectors.InsufficientRepetionsResultDetail(MARC.Everest.Connectors.ResultDetailType.Error, "Property Receiver in MARC.Everest.RMIM.UV.NE2008.Interactions.PRPA_IN201305UV02 does not have enough elements in the list, need between 1 and 2147483647 elements!", location));  } 
if(instance.Sender == null || instance.Sender.NullFlavor != null) { isValid &= false; details.Add(new MARC.Everest.Connectors.MandatoryElementMissingResultDetail(MARC.Everest.Connectors.ResultDetailType.Error, "Property Sender in MARC.Everest.RMIM.UV.NE2008.Interactions.PRPA_IN201305UV02 is marked mandatory and is either not assigned, or is assigned a null flavor. This is not permitted.", location));  } 
if(instance.controlActProcess == null || instance.controlActProcess.NullFlavor != null) { isValid &= false; details.Add(new MARC.Everest.Connectors.MandatoryElementMissingResultDetail(MARC.Everest.Connectors.ResultDetailType.Error, "Property controlActProcess in MARC.Everest.RMIM.UV.NE2008.Interactions.PRPA_IN201305UV02 is marked mandatory and is either not assigned, or is assigned a null flavor. This is not permitted.", location));  } 
;
			outDetails = details.ToArray();;
			return isValid;;
		}
Example #7
0
		public virtual bool Validate(MARC.Everest.Interfaces.IGraphable o, string location, out MARC.Everest.Connectors.IResultDetail[] outDetails) {
			MARC.Everest.RMIM.UV.NE2008.MFMI_MT700711UV01.ControlActProcess<MARC.Everest.RMIM.UV.NE2008.PRPA_MT201306UV02.QueryByParameter,MARC.Everest.RMIM.UV.NE2008.PRPA_MT201310UV02.Patient,System.Object> instance = o as MARC.Everest.RMIM.UV.NE2008.MFMI_MT700711UV01.ControlActProcess<MARC.Everest.RMIM.UV.NE2008.PRPA_MT201306UV02.QueryByParameter,MARC.Everest.RMIM.UV.NE2008.PRPA_MT201310UV02.Patient,System.Object>;;
			outDetails = new MARC.Everest.Connectors.IResultDetail[0]; System.Collections.Generic.List<MARC.Everest.Connectors.IResultDetail> details = new System.Collections.Generic.List<MARC.Everest.Connectors.IResultDetail>(10);;
			bool isValid = true;;
			if(instance == null && o != null) throw new System.NullReferenceException(System.String.Format("Could not cast type '{0}' to 'MARC.Everest.RMIM.UV.NE2008.MFMI_MT700711UV01.ControlActProcess<MARC.Everest.RMIM.UV.NE2008.PRPA_MT201306UV02.QueryByParameter,MARC.Everest.RMIM.UV.NE2008.PRPA_MT201310UV02.Patient,System.Object>'!", o.GetType().FullName));if(instance == null || instance.NullFlavor != null) return true;if(instance.ClassCode == null || instance.ClassCode.NullFlavor != null) { isValid &= false; details.Add(new MARC.Everest.Connectors.MandatoryElementMissingResultDetail(MARC.Everest.Connectors.ResultDetailType.Error, "Property ClassCode in MARC.Everest.RMIM.UV.NE2008.MFMI_MT700711UV01.ControlActProcess`3 is marked mandatory and is either not assigned, or is assigned a null flavor. This is not permitted.", location));  } 
if(instance.MoodCode == null || instance.MoodCode.NullFlavor != null) { isValid &= false; details.Add(new MARC.Everest.Connectors.MandatoryElementMissingResultDetail(MARC.Everest.Connectors.ResultDetailType.Error, "Property MoodCode in MARC.Everest.RMIM.UV.NE2008.MFMI_MT700711UV01.ControlActProcess`3 is marked mandatory and is either not assigned, or is assigned a null flavor. This is not permitted.", location));  } 
if(instance.QueryAck == null || instance.QueryAck.NullFlavor != null) { isValid &= false; details.Add(new MARC.Everest.Connectors.MandatoryElementMissingResultDetail(MARC.Everest.Connectors.ResultDetailType.Error, "Property QueryAck in MARC.Everest.RMIM.UV.NE2008.MFMI_MT700711UV01.ControlActProcess`3 is marked mandatory and is either not assigned, or is assigned a null flavor. This is not permitted.", location));  } 
;
			outDetails = details.ToArray();;
			return isValid;;
		}
Example #8
0
        /// <summary>
        /// Graphs an object to the specified stream
        /// </summary>
        public void Graph(System.Xml.XmlWriter s, object o, MARC.Everest.Interfaces.IGraphable context, XmlIts1FormatterGraphResult resultContext)
        {
            ResultCode rc = ResultCode.Accepted;
            Type instanceType = o.GetType();

            // Verify o is not null
            if (o == null) throw new System.ArgumentNullException("o");

            // Attempt to get null flavor
            
            var nfp = o.GetType().GetProperty("NullFlavor");
            bool isInstanceNull = false, 
                isEntryPoint = false;
            if (nfp != null)
                isInstanceNull = nfp.GetValue(o, null) != null;

            // Interaction?
            object[] structureAttributes = instanceType.GetCustomAttributes(typeof(StructureAttribute), false);
            StructureAttribute structureAttribute = structureAttributes[0] as StructureAttribute;
            if (structureAttribute.StructureType == StructureAttribute.StructureAttributeType.Interaction)
            {
                isEntryPoint = true;
                s.WriteStartElement(structureAttribute.Name, structureAttribute.NamespaceUri);
                s.WriteAttributeString("ITSVersion","XML_1.0"); // Add ITS version
                s.WriteAttributeString("xmlns", "xsi", null, XmlIts1Formatter.NS_XSI);
            }
            else if (structureAttribute.IsEntryPoint && (s is MARC.Everest.Xml.XmlStateWriter && (s as MARC.Everest.Xml.XmlStateWriter).ElementStack.Count == 0 || s.WriteState == System.Xml.WriteState.Start))
            {
                isEntryPoint = true;
                if (isEntryPoint)
                {
                    s.WriteStartElement(structureAttribute.Name, structureAttribute.NamespaceUri);
                    s.WriteAttributeString("xmlns", "xsi", null, XmlIts1Formatter.NS_XSI);
                }
            }
                
            // Validate
            this.Host.ValidateHelper(s, o as IGraphable, this, resultContext);

            // Reflect the properties and ensure they are in the appropriate order
            List<PropertyInfo> buildProperties = GetBuildProperties(instanceType);
            
            // Attributes first
            foreach (var pi in buildProperties)
            {

                object[] propertyAttributes = pi.GetCustomAttributes(typeof(PropertyAttribute), false);
                object instance = pi.GetValue(o, null);

                if (propertyAttributes.Length == 1) // Not a choice
                {
                    PropertyAttribute pa = propertyAttributes[0] as PropertyAttribute;

                    // Validation Rule Change: We'll require the user to perform this
                    // Is this a required attribute that is null? We'll set a null flavor 
                    if ((pa.Conformance == PropertyAttribute.AttributeConformanceType.Required || pa.Conformance == PropertyAttribute.AttributeConformanceType.Populated) &&
                        pa.PropertyType != PropertyAttribute.AttributeAttributeType.Structural &&
                        pi.PropertyType.GetProperty("NullFlavor") != null &&
                        !pi.PropertyType.IsAbstract &&
                        pi.CanWrite)
                    {
                        var nullFlavorProperty = pi.PropertyType.GetProperty("NullFlavor");
                        // Locate the default property 
                        if (instance == null && Host.CreateRequiredElements && nullFlavorProperty != null)
                        {
                            ConstructorInfo ci = pi.PropertyType.GetConstructor(Type.EmptyTypes);
                            instance = ci.Invoke(null);
                            nullFlavorProperty.SetValue(instance, Util.FromWireFormat("NI", nullFlavorProperty.PropertyType), null);
                        }
                    }


                    // Property type
                    switch (pa.PropertyType)
                    {
                        case PropertyAttribute.AttributeAttributeType.Structural:
                            if ((Host.Settings & SettingsType.SuppressNullEnforcement) == 0)
                            {
                                if (instance != null && !isInstanceNull)
                                    s.WriteAttributeString(pa.Name, Util.ToWireFormat(instance));
                                else if (isInstanceNull && pi.Name == "NullFlavor")
                                    Host.WriteNullFlavorUtil(s, (IGraphable)instance);
                            }
                            else if (instance != null)
                            {
                                if (instance != null && pi.Name == "NullFlavor")
                                    Host.WriteNullFlavorUtil(s, (IGraphable)instance);
                                else if (instance != null)
                                    s.WriteAttributeString(pa.Name, Util.ToWireFormat(instance));
                            }

                            break;
                        default:

                            // Instance is null
                            if (instance == null)
                                continue;
                            else if (isInstanceNull && (Host.Settings & (SettingsType.SuppressNullEnforcement | SettingsType.SuppressXsiNil)) != 0)
                                resultContext.AddResultDetail(new FormalConstraintViolationResultDetail(ResultDetailType.Information, "The context is null however SuppressNullEnforcement and SuppressXsiNil are set, therefore elements will be graphed. This is not necessarily HL7v3 compliant", s.ToString(), null));
                            else if (isInstanceNull)
                                continue;

                            // Impose flavors or code?
                            if (pa.DefaultUpdateMode != MARC.Everest.DataTypes.UpdateMode.Unknown &&
                                pi.PropertyType.GetProperty("UpdateMode") != null &&
                                pi.PropertyType.GetProperty("UpdateMode").GetValue(instance, null) == null &&
                                (this.Host.Settings & SettingsType.AllowUpdateModeImposing) == SettingsType.AllowUpdateModeImposing)
                                pi.PropertyType.GetProperty("UpdateMode").SetValue(instance, Util.FromWireFormat(pa.DefaultUpdateMode, pi.PropertyType.GetProperty("UpdateMode").PropertyType), null);
                            if (pa.ImposeFlavorId != null &&
                                instance is IAny &&
                                (Host.Settings & SettingsType.AllowFlavorImposing) == SettingsType.AllowFlavorImposing)
                                (instance as IAny).Flavor = pa.ImposeFlavorId;
                            if (pa.SupplierDomain != null &&
                                instance is ICodedValue &&
                                (instance as ICodedSimple).CodeValue != null &&
                                (instance as ICodedValue).CodeSystem == null &&
                                (instance as IImplementsNullFlavor).NullFlavor == null &&
                                (Host.Settings & SettingsType.AllowSupplierDomainImposing) == SettingsType.AllowSupplierDomainImposing)
                                (instance as ICodedValue).CodeSystem = pa.SupplierDomain;

                            // Instance is graphable
                            if (instance is IGraphable)
                            {
                                // Ensure the data is not empty
                                if (instance is IColl && (instance as IColl).IsEmpty && (instance as IImplementsNullFlavor).NullFlavor == null)
                                    continue;
                                Host.WriteElementUtil(s, pa.NamespaceUri, pa.Name, instance as IGraphable, pi.PropertyType, context, resultContext);
                            }
                            else if (instance is ICollection)
                            {
                                Type genType = pi.PropertyType.GetGenericArguments()[0];
                                foreach (object itm in (instance as ICollection))
                                    Host.WriteElementUtil(s, pa.NamespaceUri, pa.Name, itm as IGraphable, genType, context, resultContext);
                            }
                            else
                                s.WriteElementString(pa.Name, instance.ToString());
                            break;
                    }
                }
                else if(propertyAttributes.Length > 1) // Choice
                {
                    // Instance is null
                    if (instance == null)
                        continue;
                    else if (isInstanceNull && (Host.Settings & (SettingsType.SuppressNullEnforcement | SettingsType.SuppressXsiNil)) != 0)
                        resultContext.AddResultDetail(new FormalConstraintViolationResultDetail(ResultDetailType.Information, "The context is null however SuppressNullEnforcement and SuppressXsiNil are set, therefore elements will be graphed. This is not necessarily HL7v3 compliant", s.ToString(), null));
                    else if (isInstanceNull)
                        continue;
#if WINDOWS_PHONE
                    PropertyAttribute formatAs = propertyAttributes.Find(cpa => (cpa as PropertyAttribute).Type == null) as PropertyAttribute;
#else
                    PropertyAttribute formatAs = Array.Find(propertyAttributes, cpa => (cpa as PropertyAttribute).Type == null) as PropertyAttribute;
#endif
                    // Search by type and interaction
                    foreach (PropertyAttribute pa in propertyAttributes)
                    {
                        if (pa.Type != null && instance.GetType() == pa.Type && (context != null && context.GetType() == pa.InteractionOwner || (pa.InteractionOwner == null && formatAs == null)))
                        {
                            formatAs = pa;
                            if(context == null || context.GetType() == formatAs.InteractionOwner) 
                                break;
                        }
                    }

                    // Slow check
                    if (formatAs == null && (this.Host.Settings & SettingsType.AlwaysCheckForOverrides) != 0)
                    {
                        foreach (PropertyAttribute pa in propertyAttributes)
                        {
                            if (pa.Type != null && pa.Type.IsAssignableFrom(instance.GetType()) && (context != null && context.GetType() == pa.InteractionOwner || (pa.InteractionOwner == null && formatAs == null)))
                            {
                                formatAs = pa;
                                if (context == null || context.GetType() == formatAs.InteractionOwner)
                                    break;
                            }
                        }
                    }

                    //if(formatAs == null) // try to find a regular choice
                    //    foreach(PropertyAttribute pa in propertyAttributes)
                    //        if (pa.Type != null && instance.GetType() == pa.Type)
                    //        {
                    //            formatAs = pa;
                    //            break;
                    //        }


                    // Format
                    if (formatAs == null)
                        resultContext.AddResultDetail(new NotSupportedChoiceResultDetail(ResultDetailType.Error, String.Format("Type {0} is not a valid choice according to available choice elements and won't be formatted", instance.GetType()), s.ToString(), null));
                    else if (instance.GetType().GetInterface("MARC.Everest.Interfaces.IGraphable", false) != null) // Non Graphable
                        Host.WriteElementUtil(s, formatAs.NamespaceUri, formatAs.Name, (MARC.Everest.Interfaces.IGraphable)instance, formatAs.Type, context, resultContext);
                    else if (instance.GetType().GetInterface("System.Collections.IEnumerable", false) != null) // List
                        foreach (MARC.Everest.Interfaces.IGraphable ig in instance as IEnumerable) { Host.WriteElementUtil(s, formatAs.NamespaceUri, formatAs.Name, ig, instance.GetType(), context, resultContext); }
                    else // Not recognized
                        s.WriteElementString(formatAs.Name, formatAs.NamespaceUri, instance.ToString());

                }
            }

            // Is Entry point
            if (isEntryPoint)
                s.WriteEndElement();

        }
Example #9
0
        /// <summary>
        /// Validates the specified object
        /// </summary>
        public bool Validate(MARC.Everest.Interfaces.IGraphable o, string location, out MARC.Everest.Connectors.IResultDetail[] details)
        {
            List<IResultDetail> dtls = new List<IResultDetail>(10);
            bool isValid = true;

            // Null return bool
            if (o == null)
            {
                details = dtls.ToArray();
                return true;
            }

            PropertyInfo nullFlavorAttrib = o.GetType().GetProperty("NullFlavor");
            if (nullFlavorAttrib != null && nullFlavorAttrib.GetValue(o, null) != null)
            {
                details = dtls.ToArray();
                return true;
            }

            // Scan property info for violations
            foreach (var pi in this.GetBuildProperties(o.GetType()))
            {

                if (pi.GetGetMethod().GetParameters().Length != 0)
                {
                    dtls.Add(new NotImplementedResultDetail(
                        ResultDetailType.Warning,
                        String.Format("Could not validate '{0}' as the property is indexed", pi.Name),
                        location
                    ));
                    continue;
                }

                object piValue = pi.GetValue(o, null);
                object[] propAttributes = pi.GetCustomAttributes(typeof(PropertyAttribute), true);
                
                if (propAttributes.Length > 0)
                {
                    PropertyAttribute pa = propAttributes[0] as PropertyAttribute;
                    if (pa.Conformance == PropertyAttribute.AttributeConformanceType.Mandatory &&
                        pi.PropertyType.GetInterface(typeof(IImplementsNullFlavor).FullName, false) != null &&
                        (piValue == null || (piValue as IImplementsNullFlavor).NullFlavor != null))
                    {
                        isValid = false;
                        dtls.Add(new MandatoryElementMissingResultDetail(ResultDetailType.Error, String.Format("Property {0} in {1} is marked mandatory and is either not assigned, or is assigned a null flavor. This is not permitted.", pi.Name, o.GetType().FullName), location));
                    }
                    else if (pa.Conformance == PropertyAttribute.AttributeConformanceType.Populated && piValue == null)
                    {
                        isValid &= Host.CreateRequiredElements;
                        dtls.Add(new RequiredElementMissingResultDetail(isValid ? ResultDetailType.Warning : ResultDetailType.Error, String.Format("Property {0} in {1} is marked 'populated' and isn't assigned (you must at minimum, assign a nullFlavor for this attribute)!", pi.Name, o.GetType().FullName), location));
                    }
                    else if (pa.MinOccurs != 0)
                    {
                        int minOccurs = pa.MinOccurs, 
                            maxOccurs = pa.MaxOccurs < 0 ? Int32.MaxValue : pa.MaxOccurs;
                        var piCollection = piValue as ICollection;
                        if(piCollection != null && (piCollection.Count > maxOccurs || piCollection.Count < minOccurs))
                        { 
                            isValid = false; 
                            dtls.Add(new InsufficientRepetitionsResultDetail(ResultDetailType.Error, String.Format("Property {0} in {2} does not have enough elements in the list, need between {1} and {3} elements!", pi.Name, minOccurs, o.GetType().FullName, maxOccurs), location));
                        }
                    }
                }
            }

            details = dtls.ToArray();
            return isValid;
        }