private static IViewInfo FindInfo(Product owner, Guid id) { if (owner != null && owner.Info != null) { return owner.Info.Views.FirstOrDefault(v => v.Id == id); } return null; }
public void Initialize() { this.store.TransactionManager.DoWithinTransaction(() => { var productStore = this.store.ElementFactory.CreateElement<ProductState>(); this.product = productStore.Create<Product>(); }); validationContext = new ValidationContext(ValidationCategories.Custom, this.product); }
public void InitializeContext() { this.guidanceManager = new Mock<IGuidanceManager>(); this.validator = new GuidanceReferenceValidation(); this.validator.GuidanceManager = this.guidanceManager.Object; this.store.TransactionManager.DoWithinTransaction(() => { var productStore = this.store.ElementFactory.CreateElement<ProductState>(); this.product = productStore.Create<Product>(); }); validationContext = new ValidationContext(ValidationCategories.Custom, this.product); }
public void InitializeContext() { this.uriService = new Mock<IUriReferenceService>(); this.validator = new ArtifactReferenceValidation(); this.validator.UriReferenceService = this.uriService.Object; this.store.TransactionManager.DoWithinTransaction(() => { var productStore = this.store.ElementFactory.CreateElement<ProductState>(); this.product = productStore.Create<Product>(); }); validationContext = new ValidationContext(ValidationCategories.Custom, this.product); }
private static IPatternInfo FindInfo(Product product) { var patternManager = product.Store.TryGetService<IPatternManager>(); if (patternManager != null) { var toolkitInfo = patternManager.InstalledToolkits.FirstOrDefault(tk => tk.ContainsSchema(product)); if (toolkitInfo != null) { //TODO: Return unique instance (and cache) of info for parented products for same parent instance return toolkitInfo.Schema.Pattern; } } tracer.Warn(Resources.TracerWarning_ToolkitInfoNotFound, product.ExtensionId, product.InstanceName); return null; }
internal static DslModeling::LinkedElementCollection<View> GetViews(Product element) { return GetRoleCollection<DslModeling::LinkedElementCollection<View>, View>(element, ProductDomainRoleId); }
internal static void SetProduct(View element, Product newProduct) { DslModeling::DomainRoleInfo.SetLinkedElement(element, ViewDomainRoleId, newProduct); }
/// <summary> /// Constructor /// Creates a ProductHasViews link in the same Partition as the given Product /// </summary> /// <param name="source">Product to use as the source of the relationship.</param> /// <param name="target">View to use as the target of the relationship.</param> internal ProductHasViews(Product source, View target) : base((source != null ? source.Partition : null), new DslModeling::RoleAssignment[]{new DslModeling::RoleAssignment(ProductHasViews.ProductDomainRoleId, source), new DslModeling::RoleAssignment(ProductHasViews.ViewDomainRoleId, target)}, null) { }
/// <summary> /// Reads all instances of relationship ProductHasViews. /// </summary> /// <remarks> /// The caller will position the reader at the open tag of the first XML element inside the relationship tag, so it can be /// either the first instance, or a bogus tag. This method will deserialize all instances and ignore all bogus tags. When the /// method returns, the reader will be positioned at the end tag of the relationship (or EOF if somehow that happens). /// </remarks> /// <param name="serializationContext">Serialization context.</param> /// <param name="element">In-memory Product instance that will get the deserialized data.</param> /// <param name="reader">XmlReader to read serialized data from.</param> private static void ReadProductHasViewsInstances(DslModeling::SerializationContext serializationContext, Product element, global::System.Xml.XmlReader reader) { while (!serializationContext.Result.Failed && !reader.EOF && reader.NodeType == global::System.Xml.XmlNodeType.Element) { DslModeling::DomainClassXmlSerializer newViewOfProductHasViewsSerializer = serializationContext.Directory.GetSerializer(View.DomainClassId); global::System.Diagnostics.Debug.Assert(newViewOfProductHasViewsSerializer != null, "Cannot find serializer for View!"); View newViewOfProductHasViews = newViewOfProductHasViewsSerializer.TryCreateInstance(serializationContext, reader, element.Partition) as View; if (newViewOfProductHasViews != null) { element.Views.Add(newViewOfProductHasViews); DslModeling::DomainClassXmlSerializer targetSerializer = serializationContext.Directory.GetSerializer (newViewOfProductHasViews.GetDomainClass().Id); global::System.Diagnostics.Debug.Assert (targetSerializer != null, "Cannot find serializer for " + newViewOfProductHasViews.GetDomainClass().Name + "!"); targetSerializer.Read(serializationContext, newViewOfProductHasViews, reader); } else { global::System.Type typeofProductHasViews = typeof(ProductHasViews); DslModeling::DomainRelationshipXmlSerializer newProductHasViewsSerializer = serializationContext.Directory.GetSerializer(ProductHasViews.DomainClassId) as DslModeling::DomainRelationshipXmlSerializer; global::System.Diagnostics.Debug.Assert(newProductHasViewsSerializer != null, "Cannot find serializer for ProductHasViews!"); ProductHasViews newProductHasViews = newProductHasViewsSerializer.TryCreateInstance (serializationContext, reader, element.Partition) as ProductHasViews; if (newProductHasViews != null) { if (newProductHasViews.GetType() == typeofProductHasViews) { // The relationship should be serialized in short-form. ProductStateStoreSerializationBehaviorSerializationMessages.ExpectingShortFormRelationship(serializationContext, reader, typeof(ProductHasViews)); } DslModeling::DomainRoleInfo.SetRolePlayer (newProductHasViews, ProductHasViews.ProductDomainRoleId, element); DslModeling::DomainClassXmlSerializer targetSerializer = serializationContext.Directory.GetSerializer (newProductHasViews.GetDomainClass().Id); global::System.Diagnostics.Debug.Assert (targetSerializer != null, "Cannot find serializer for " + newProductHasViews.GetDomainClass().Name + "!"); targetSerializer.Read(serializationContext, newProductHasViews, reader); } else { // Unknown element, skip DslModeling::SerializationUtilities.Skip(reader); } } } }
internal static AbstractElement GetOwner(Product element) { return DslModeling::DomainRoleInfo.GetLinkedElement(element, ExtensionDomainRoleId) as AbstractElement; }
/// <summary> /// Constructor /// Creates a ElementHasExtensions link in the same Partition as the given AbstractElement /// </summary> /// <param name="source">AbstractElement to use as the source of the relationship.</param> /// <param name="target">Product to use as the target of the relationship.</param> internal ElementHasExtensions(AbstractElement source, Product target) : base((source != null ? source.Partition : null), new DslModeling::RoleAssignment[]{new DslModeling::RoleAssignment(ElementHasExtensions.AbstractElementDomainRoleId, source), new DslModeling::RoleAssignment(ElementHasExtensions.ExtensionDomainRoleId, target)}, null) { }
internal static void SetProductState(Product element, ProductState newProductState) { DslModeling::DomainRoleInfo.SetLinkedElement(element, ProductDomainRoleId, newProductState); }
internal static ProductState GetProductState(Product element) { return DslModeling::DomainRoleInfo.GetLinkedElement(element, ProductDomainRoleId) as ProductState; }
private static View CreateView(Product product, string viewName, Action<View> initializer) { var view = CreateView(product, viewName); initializer(view); return view; }
private static View CreateView(Product product, string viewName) { var view = (View)product.CreateView(); view.Info = Mock.Of<IViewInfo>(vi => vi.Name == viewName && vi.CodeIdentifier == viewName); product.Store.TransactionManager.DoWithinTransaction(() => { product.View = view; }); return view; }
/// <summary> /// Constructor /// Creates a ProductStateHasProducts link in the same Partition as the given ProductState /// </summary> /// <param name="source">ProductState to use as the source of the relationship.</param> /// <param name="target">Product to use as the target of the relationship.</param> internal ProductStateHasProducts(ProductState source, Product target) : base((source != null ? source.Partition : null), new DslModeling::RoleAssignment[]{new DslModeling::RoleAssignment(ProductStateHasProducts.ProductStateDomainRoleId, source), new DslModeling::RoleAssignment(ProductStateHasProducts.ProductDomainRoleId, target)}, null) { }
public void Initialize() { this.store = new DslTestStore<ProductStateStoreDomainModel>(); var productInfo = new Mock<IPatternInfo>(); using (var tx = this.store.TransactionManager.BeginTransaction()) { this.product = this.store.ElementFactory.CreateElement<Product>(); this.product.Info = productInfo.Object; tx.Commit(); } this.viewInfo = new Mock<IViewInfo>(); this.viewInfo.Setup(v => v.Id).Returns(Guid.NewGuid()); this.viewInfo.Setup(v => v.Pattern).Returns(this.product.Info); productInfo.Setup(p => p.Views).Returns(new[] { this.viewInfo.Object }); }
internal static void SetOwner(Product element, AbstractElement newAbstractElement) { DslModeling::DomainRoleInfo.SetLinkedElement(element, ExtensionDomainRoleId, newAbstractElement); }
/// <summary> /// This method deserializes all child model elements. /// </summary> /// <remarks> /// The caller will position the reader at the open tag of the first child XML element to deserialized. /// This method will read as many child elements as it can. It returns under three circumstances: /// 1) When an unknown child XML element is encountered. In this case, this method will position the reader at the /// open tag of the unknown element. This implies that if the first child XML element is unknown, this method /// should return immediately and do nothing. /// 2) When all child XML elemnets are read. In this case, the reader will be positioned at the end tag of the parent element. /// 3) EOF. /// </remarks> /// <param name="serializationContext">Serialization context.</param> /// <param name="reader">XmlReader to read serialized data from.</param> /// <param name="element">In-memory Product instance that will get the deserialized data.</param> private static void ReadChildElements(DslModeling::SerializationContext serializationContext, Product element, global::System.Xml.XmlReader reader) { if (!serializationContext.Result.Failed && !reader.EOF && reader.NodeType == global::System.Xml.XmlNodeType.Element) { if (string.Compare(reader.LocalName, "views", global::System.StringComparison.CurrentCulture) == 0) { if (reader.IsEmptyElement) { // No instance of this relationship, just skip DslModeling::SerializationUtilities.Skip(reader); } else { DslModeling::SerializationUtilities.SkipToFirstChild(reader); // Skip the open tag of <views> ReadProductHasViewsInstances(serializationContext, element, reader); DslModeling::SerializationUtilities.Skip(reader); // Skip the close tag of </views> } } } }
/// <summary> /// Constructor /// Creates a ViewHasExtensionProducts link in the same Partition as the given View /// </summary> /// <param name="source">View to use as the source of the relationship.</param> /// <param name="target">Product to use as the target of the relationship.</param> internal ViewHasExtensionProducts(View source, Product target) : base((source != null ? source.Partition : null), new DslModeling::RoleAssignment[]{new DslModeling::RoleAssignment(ViewHasExtensionProducts.ViewDomainRoleId, source), new DslModeling::RoleAssignment(ViewHasExtensionProducts.ExtensionDomainRoleId, target)}, null) { }
private static void WriteChildElements(DslModeling::SerializationContext serializationContext, Product element, global::System.Xml.XmlWriter writer) { // ProductHasViews global::System.Collections.ObjectModel.ReadOnlyCollection<ProductHasViews> allProductHasViewsInstances = ProductHasViews.GetLinksToViews(element); if (!serializationContext.Result.Failed && allProductHasViewsInstances.Count > 0) { writer.WriteStartElement("views"); global::System.Type typeofProductHasViews = typeof(ProductHasViews); foreach (ProductHasViews eachProductHasViewsInstance in allProductHasViewsInstances) { if (serializationContext.Result.Failed) break; if (eachProductHasViewsInstance.GetType() != typeofProductHasViews) { // Derived relationships will be serialized in full-form. DslModeling::DomainClassXmlSerializer derivedRelSerializer = serializationContext.Directory.GetSerializer(eachProductHasViewsInstance.GetDomainClass().Id); global::System.Diagnostics.Debug.Assert(derivedRelSerializer != null, "Cannot find serializer for " + eachProductHasViewsInstance.GetDomainClass().Name + "!"); derivedRelSerializer.Write(serializationContext, eachProductHasViewsInstance, writer); } else { // No need to serialize the relationship itself, just serialize the role-player directly. DslModeling::ModelElement targetElement = eachProductHasViewsInstance.View; DslModeling::DomainClassXmlSerializer targetSerializer = serializationContext.Directory.GetSerializer(targetElement.GetDomainClass().Id); global::System.Diagnostics.Debug.Assert(targetSerializer != null, "Cannot find serializer for " + targetElement.GetDomainClass().Name + "!"); targetSerializer.Write(serializationContext, targetElement, writer); } } writer.WriteEndElement(); } }
internal static View GetView(Product element) { return DslModeling::DomainRoleInfo.GetLinkedElement(element, ExtensionDomainRoleId) as View; }
private static bool IsValidExtensionPoint( Product product, IEnumerable<IExtensionPointInfo> extensionPoints, IPatternManager patternManager) { return extensionPoints.Any(x => patternManager.GetCandidateExtensionPoints(x.RequiredExtensionPointId) .Any(f => f.Id == product.ExtensionId && f.Schema.Pattern.Id == product.DefinitionId)); }
internal static void SetView(Product element, View newView) { DslModeling::DomainRoleInfo.SetLinkedElement(element, ExtensionDomainRoleId, newView); }