/// <summary> /// Does the validate. /// </summary> /// <param name="objectToValidate">The object to validate.</param> /// <param name="currentTarget">The current target.</param> /// <param name="key">The key.</param> /// <param name="validationResults">The validation results.</param> protected override void DoValidate(ModelBusReference objectToValidate, object currentTarget, string key, ValidationResults validationResults) { ModelElement currentElement = currentTarget as ModelElement; Debug.Assert(currentElement != null); if (!validationResults.IsValid) { return; } if (objectToValidate != null) { using (ModelBusReferenceResolver resolver = new ModelBusReferenceResolver()) { ModelElement referenced = resolver.Resolve(objectToValidate); // Check if we are not in the same model and we had visited this model before if (!currentElement.Store.Id.Equals(referenced.Store.Id) && Visited(referenced.Store.Id)) { this.LogValidationResult(validationResults, String.Format(CultureInfo.CurrentUICulture, this.MessageTemplate, ValidatorUtility.GetTargetName(currentTarget), objectToValidate.ElementDisplayName, objectToValidate.ModelDisplayName), currentTarget, key); return; } } // store the current model to compare with references // If referenced model == current model implies that we have a circular ref. alreadyVisited.Add(currentElement.Store.Id); } }
/// <summary> /// Does the validate. /// </summary> /// <param name="objectToValidate">The object to validate.</param> /// <param name="currentTarget">The current target.</param> /// <param name="key">The key.</param> /// <param name="validationResults">The validation results.</param> protected override void DoValidate(ModelBusReference objectToValidate, object currentTarget, string key, ValidationResults validationResults) { // store default message (in case the error comes from a DC element) and set our new message dcModelMessageTemplate = this.MessageTemplate; this.MessageTemplate = currentMessageTemplate; // Validate cross model references base.DoValidate(objectToValidate, currentTarget, key, validationResults); if (!validationResults.IsValid) { return; } using (ModelBusReferenceResolver resolver = new ModelBusReferenceResolver()) { ModelElement referencedElement = resolver.Resolve(objectToValidate); if (referencedElement != null) { DataContractModel dcm = referencedElement.Store.ElementDirectory.FindElements <DataContractModel>()[0]; if (dcm.ImplementationTechnology == null || String.IsNullOrWhiteSpace(dcm.ProjectMappingTable) || !dcm.ImplementationTechnology.Name.Equals(GetItName(currentTarget), StringComparison.OrdinalIgnoreCase)) { validationResults.AddResult( new ValidationResult(String.Format(CultureInfo.CurrentUICulture, this.dcModelMessageTemplate, ValidatorUtility.GetTargetName(currentTarget)), currentTarget, key, String.Empty, this)); } } } }
/// <summary> /// Does the validate. /// </summary> /// <param name="objectToValidate">The object to validate.</param> /// <param name="currentTarget">The current target.</param> /// <param name="key">The key.</param> /// <param name="validationResults">The validation results.</param> protected override void DoValidate(ModelBusReference objectToValidate, object currentTarget, string key, ValidationResults validationResults) { this.MessageTemplate = currentMessageTemplate; base.DoValidate(objectToValidate, currentTarget, key, validationResults); if (!validationResults.IsValid) { return; } ServiceReference serviceReference = currentTarget as ServiceReference; if (serviceReference == null) { return; } using (ModelBusReferenceResolver resolver = new ModelBusReferenceResolver()) { ModelElement referencedElement = resolver.Resolve(objectToValidate); if (referencedElement != null) { ServiceContractModel dcm = referencedElement.Store.ElementDirectory.FindElements <ServiceContractModel>()[0]; if (dcm.ImplementationTechnology == null || String.IsNullOrWhiteSpace(dcm.ProjectMappingTable) || !dcm.ImplementationTechnology.Name.Equals(GetItName(currentTarget), StringComparison.OrdinalIgnoreCase)) { validationResults.AddResult( new ValidationResult(String.Format(CultureInfo.CurrentUICulture, this.MessageTemplate, ValidatorUtility.GetTargetName(currentTarget)), currentTarget, key, String.Empty, this)); } } } }
private string GetDcImplementationTechnology(ModelBusReference reference) { using (ModelBusReferenceResolver resolver = new ModelBusReferenceResolver()) { ModelElement referencedElement = resolver.Resolve(reference); DataContractModel dcm = DomainModelHelper.GetElement <DataContractModel>(referencedElement.Store); return((dcm == null || dcm.ImplementationTechnology == null) ? string.Empty : dcm.ImplementationTechnology.Name); } }
protected override void DoValidate(IEnumerable <Fault> objectToValidate, object currentTarget, string key, ValidationResults validationResults) { Operation operation = currentTarget as Operation; if (operation == null) { return; } // Validation Application block doesn't recreate validators every time. // Reset fc counter before validating the collection faultContracts.Clear(); foreach (Fault item in objectToValidate) { DataContractFault fault = item as DataContractFault; if (fault == null || fault.Type == null) { continue; } if (!fault.Type.IsValidReference()) { validationResults.AddResult( new ValidationResult( String.Format(CultureInfo.CurrentUICulture, Resources.CannotResolveReference, currentTarget.GetType().Name, fault.Name, fault.Type.GetDisplayName()), fault, key, String.Empty, this)); return; } ModelElement mel = ModelBusReferenceResolver.ResolveAndDispose(fault.Type); if (mel == null) { return; } FaultContract dcFault = mel as FaultContract; if (dcFault == null) { return; } if (faultContracts.Contains(dcFault)) { validationResults.AddResult( new ValidationResult(String.Format(CultureInfo.CurrentUICulture, this.MessageTemplate, fault.Name, operation.Name), objectToValidate, key, String.Empty, this) ); } else { faultContracts.Add(dcFault); } } }
/// <summary> /// Does the validate. /// </summary> /// <param name="objectToValidate">The object to validate.</param> /// <param name="currentTarget">The current target.</param> /// <param name="key">The key.</param> /// <param name="validationResults">The validation results.</param> protected override void DoValidate(ModelBusReference objectToValidate, object currentTarget, string key, ValidationResults validationResults) { ModelElement currentElement = currentTarget as ModelElement; Debug.Assert(currentElement != null); string elementNamePropertyValue = ValidationEngine.GetUniquePropertyValue(currentTarget, elementNameProperty); if (!validationResults.IsValid) { return; } if (objectToValidate == null) { validationResults.AddResult( new ValidationResult(String.Format(CultureInfo.CurrentUICulture, Resources.ModelReferenceValidatorMessage, key, currentTarget.GetType().Name, elementNamePropertyValue), currentTarget, key, String.Empty, this)); return; } //Check if we need to refresh an updated DC reference. ModelElement element = ModelBusReferenceResolver.ResolveAndDispose(objectToValidate); if (element == null) { validationResults.AddResult( new ValidationResult( String.Format(CultureInfo.CurrentUICulture, Resources.CannotResolveReference, currentTarget.GetType().Name, elementNamePropertyValue, objectToValidate.GetDisplayName()), currentTarget, key, String.Empty, this)); return; } string referenceElementDisplayName = ValidationEngine.GetUniquePropertyValue(element, "Name"); if (!objectToValidate.ElementDisplayName.Equals(referenceElementDisplayName, StringComparison.CurrentCulture)) { using (Transaction tx = ((ModelElement)currentTarget).Store.TransactionManager.BeginTransaction("Update reference value")) { ModelBusReference refresh = new ModelBusReference( objectToValidate.ModelBus, objectToValidate.LogicalAdapterId, objectToValidate.ModelDisplayName, referenceElementDisplayName, objectToValidate.SerializedAdapterReference, objectToValidate.ReferenceContext); // refresh value PropertyInfo typeProp = currentTarget.GetType().GetProperty("Type"); typeProp.SetValue(currentTarget, null, null); //Set it null to force updating typeProp.SetValue(currentTarget, refresh, null); //Now set the final value tx.Commit(); } validationResults.AddResult(new ValidationResult( string.Format(CultureInfo.CurrentCulture, Resources.ModelBusRefrenceUpdate, elementNamePropertyValue, referenceElementDisplayName), currentTarget, key, Constants.LogWarningTag, this)); } }
/// <summary> /// Does the validate. /// </summary> /// <param name="objectToValidate">The object to validate.</param> /// <param name="currentTarget">The current target.</param> /// <param name="key">The key.</param> /// <param name="validationResults">The validation results.</param> protected override void DoValidate(ModelBusReference objectToValidate, object currentTarget, string key, ValidationResults validationResults) { base.DoValidate(objectToValidate, currentTarget, key, validationResults); if (!validationResults.IsValid) { return; } ServiceReference serviceReference = currentTarget as ServiceReference; if (serviceReference == null) { return; } using (ModelBusReferenceResolver resolver = new ModelBusReferenceResolver()) { ModelElement referencedElement = resolver.Resolve(objectToValidate); if (referencedElement != null) { ServiceContractModel scm = DomainModelHelper.GetElement <ServiceContractModel>(referencedElement.Store); if (scm != null && scm.ImplementationTechnology != null) { if (serviceReference.HostApplication.ImplementationTechnology != null && !serviceReference.HostApplication.ImplementationTechnology.Name.Equals( scm.ImplementationTechnology.Name)) { this.LogValidationResult( validationResults, string.Format(CultureInfo.CurrentCulture, this.MessageTemplate, serviceReference.Name), currentTarget, key); } } } } }
private bool VisitElementAndLinks(ModelElement e) { bool keepVisiting = VisitElement(e); if (keepVisiting) { ElementLink thisLink = e as ElementLink; if (thisLink != null) { keepVisiting = VisitRolePlayers(thisLink); } if (keepVisiting) { IList <ModelElement> elems = GetRelatedElements(e); foreach (ModelElement child in elems) { if (!Visited(child)) { keepVisiting = DoVisitElement(child); } } ICrossModelingPropertyHolder holder = e as ICrossModelingPropertyHolder; if (holder != null) { ModelElement refElement = ModelBusReferenceResolver.ResolveAndCache(holder.Type); if (refElement != null) { DoVisitElement(refElement); } } } } return(keepVisiting); }
/// <summary> /// Resolves the model reference. /// </summary> /// <param name="mbReference">The ModelBusReference intance.</param> /// <returns></returns> // FXCOP: False positive public ModelElement ResolveModelReference(ModelBusReference mbRefenrece) { return(ModelBusReferenceResolver.ResolveAndDispose(mbRefenrece)); }
protected override void DoValidate(IEnumerable <Fault> objectToValidate, object currentTarget, string key, ValidationResults validationResults) { Operation operation = currentTarget as Operation; if (operation == null) { return; } string serviceContractImplementationTech = String.Empty; if (operation.ServiceContractModel.ImplementationTechnology == null) { return; } else { serviceContractImplementationTech = operation.ServiceContractModel.ImplementationTechnology.Name; } SerializerType serviceContractSerializer = operation.ServiceContractModel.SerializerType; foreach (Fault item in objectToValidate) { bool isValid = true; DataContractFault fault = item as DataContractFault; if (fault == null || fault.Type == null) { continue; } if (!fault.Type.IsValidReference()) { validationResults.AddResult( new ValidationResult( String.Format(CultureInfo.CurrentUICulture, Resources.CannotResolveReference, currentTarget.GetType().Name, fault.Name, fault.Type.GetDisplayName()), fault, key, String.Empty, this)); return; } ModelElement mel = ModelBusReferenceResolver.ResolveAndDispose(fault.Type); if (mel == null) { return; } FaultContract dcFault = mel as FaultContract; if (dcFault == null || dcFault.DataContractModel == null || dcFault.DataContractModel.ImplementationTechnology == null) { return; } if (serviceContractImplementationTech.Equals(ASMXExtension, StringComparison.OrdinalIgnoreCase)) { if (serviceContractSerializer.Equals(SerializerType.XmlSerializer)) { isValid = !(dcFault.DataContractModel.ImplementationTechnology.Name.Equals(WCFExtension, StringComparison.OrdinalIgnoreCase)); } else { // Asmx Extension only supports XmlSerializer validationResults.AddResult( new ValidationResult(String.Format(CultureInfo.CurrentUICulture, asmxExtensionInvalidSerializerMessage, fault.Name, operation.Name), objectToValidate, key, String.Empty, this) ); return; } } else if (serviceContractImplementationTech.Equals(WCFExtension, StringComparison.OrdinalIgnoreCase)) { if (serviceContractSerializer.Equals(SerializerType.DataContractSerializer)) { isValid = !(dcFault.DataContractModel.ImplementationTechnology.Name.Equals(ASMXExtension, StringComparison.OrdinalIgnoreCase)); } else { if (dcFault.DataContractModel.ImplementationTechnology.Name.Equals(ASMXExtension, StringComparison.OrdinalIgnoreCase)) { // Faults cannot be XMLSerializable validationResults.AddResult( new ValidationResult(String.Format(CultureInfo.CurrentUICulture, faultInvalidSerializerMessage, operation.Name, fault.Name), objectToValidate, key, String.Empty, this) ); return; } } } if (!isValid) { validationResults.AddResult( new ValidationResult(String.Format(CultureInfo.CurrentUICulture, this.MessageTemplate, fault.Name, operation.Name), objectToValidate, key, String.Empty, this) ); } } }
private TReferencedMEL GetMelReference <TReferencedMEL>(ModelBusReference moniker) where TReferencedMEL : ModelElement { TReferencedMEL mel = (TReferencedMEL)ModelBusReferenceResolver.ResolveAndDispose(moniker); return(mel); }