public SPObjectTypeAttribute(SPObjectModelType objectModelType, string className, string assemblyName) { ObjectModelType = objectModelType; ClassName = className; AssemblyName = assemblyName; }
private IEnumerable <Type> GetParentHostAdditionalTypes(Type type, SPObjectModelType objectModelType) { var hostAtrrs = type .GetCustomAttributes(false) .OfType <DefaultParentHostAttribute>() .ToList(); if (hostAtrrs.Count == 0) { return(null); } if (hostAtrrs.Count == 1) { return(hostAtrrs[0].AdditionalHostTypes); } switch (objectModelType) { case SPObjectModelType.CSOM: { var csomHost = hostAtrrs.FirstOrDefault(a => a.GetType() == typeof(CSOMParentHostAttribute)); return(csomHost.AdditionalHostTypes); } case SPObjectModelType.SSOM: { var defaultHost = hostAtrrs.FirstOrDefault(a => a.GetType() == typeof(DefaultParentHostAttribute)); return(defaultHost.AdditionalHostTypes); } } throw new SPMeta2NotImplementedException(string.Format("Unsupported SPObjectModelType:[{0}]", objectModelType)); }
protected ModelNode GetVeryRandomModel(Type definitionType, SPObjectModelType spObjectModelType) { var definitionSandbox = ModelGeneratorService.GenerateModelTreeForDefinition(definitionType, spObjectModelType); var additionalDefinitions = ModelGeneratorService.GetAdditionalDefinitions(definitionType); ModelGeneratorService.ComposeModelWithAdditionalDefinitions(definitionSandbox, additionalDefinitions, spObjectModelType); // more random definitions var messyDefinitions = new List <DefinitionBase>(); var flatNodes = definitionSandbox.Flatten().ToArray(); foreach (var node in flatNodes) { if (node.ChildModels.Count == 0) { continue; } var defType = node.ChildModels[0].Value.GetType(); var randomFactor = Rnd.Int(5) + 3; for (var i = 0; i < randomFactor; i++) { node.AddDefinitionNode(ModelGeneratorService.GetRandomDefinition(defType)); } } return(definitionSandbox); }
private Type GetRootHostType <TDefinition>(SPObjectModelType objectModelType) { var hostAtrrs = typeof(TDefinition) .GetCustomAttributes(false) .OfType <DefaultRootHostAttribute>() .ToList(); if (hostAtrrs.Count == 0) { return(null); } if (hostAtrrs.Count == 1) { return(hostAtrrs[0].HostType); } switch (objectModelType) { case SPObjectModelType.CSOM: { var csomHost = hostAtrrs.FirstOrDefault(a => a.GetType() == typeof(CSOMRootHostAttribute)); return(csomHost.HostType); }; break; case SPObjectModelType.SSOM: { var defaultHost = hostAtrrs.FirstOrDefault(a => a.GetType() == typeof(DefaultRootHostAttribute)); return(defaultHost.HostType); }; break; } throw new SPMeta2NotImplementedException(string.Format("Unsupported SPObjectModelType:[{0}]", objectModelType)); }
public void ComposeModelWithAdditionalDefinitions(ModelNode definitionSandbox, IEnumerable <DefinitionBase> additionalDefinitions, SPObjectModelType objectModelType) { if (additionalDefinitions == null) { return; } foreach (var definition in additionalDefinitions) { var parentHostType = GetParentHostType(definition.GetType(), objectModelType); var targetNode = definitionSandbox .FindNodes(model => { var featureDefinition = definition as FeatureDefinition; if (featureDefinition != null) { if (featureDefinition.Scope == FeatureDefinitionScope.Web) { return(model.Value.GetType() == typeof(WebDefinition) || model.Value.GetType() == typeof(RootWebDefinition)); } if (featureDefinition.Scope == FeatureDefinitionScope.Site) { return(model.Value.GetType() == typeof(SiteDefinition)); } } return(model.Value.GetType() == parentHostType); }) .FirstOrDefault(); // additional definitions should be 'first' // no NULL ref check, as it means that the model was constructed in the wrong way targetNode .ChildModels.Insert(0, new ModelNode { Value = definition }); } }
public ModelNode GenerateModelTreeForDefinition(Type definitionType, SPObjectModelType objectModelType) { ModelNode result = null; var rootHostType = GetRootHostType(definitionType, objectModelType); var parentHostType = GetParentHostType(definitionType, objectModelType); var currentDefinition = GetRandomDefinition(definitionType); var expectManyInstancesAttr = definitionType.GetCustomAttribute <ExpectManyInstances>(false); var manyInstances = new List <DefinitionBase>(); if (expectManyInstancesAttr != null) { var maxCount = expectManyInstancesAttr.MinInstancesCount + Rnd.Int(expectManyInstancesAttr.MaxInstancesCount - expectManyInstancesAttr.MinInstancesCount); for (int i = 0; i < maxCount; i++) { manyInstances.Add(GetRandomDefinition(definitionType)); } } CurrentDefinitions.Clear(); CurrentDefinitions.Add(currentDefinition); CurrentDefinitions.AddRange(manyInstances); //CurrentDefinition = currentDefinition; var defs = new List <GeneratedNodes>(); LookupModelTree(rootHostType, definitionType, defs, objectModelType); if (defs.Count > 0) { defs.Reverse(); var rootHost = defs[0].ModelNode; parentHostType = rootHost.Value.GetType(); defs.RemoveAt(0); ModelNode model = null; if (parentHostType == typeof(FarmDefinition)) { model = SPMeta2Model.NewFarmModel(); } if (parentHostType == typeof(WebApplicationDefinition)) { model = SPMeta2Model.NewWebApplicationModel(); } if (parentHostType == typeof(SiteDefinition)) { model = SPMeta2Model.NewSiteModel(); } if (parentHostType == typeof(WebDefinition)) { model = SPMeta2Model.NewWebModel(); } var _m = model; foreach (var def in defs) { _m.ChildModels.Add(def.ModelNode); _m = def.ModelNode; } _m.AddDefinitionNode(currentDefinition); foreach (var manyDef in manyInstances) { _m.AddDefinitionNode(manyDef); } result = model; } else { ModelNode resultModel = null; if (currentDefinition.GetType() == typeof(FarmDefinition)) { resultModel = SPMeta2Model.NewFarmModel(); } if (currentDefinition.GetType() == typeof(WebApplicationDefinition)) { resultModel = SPMeta2Model.NewWebApplicationModel(); } if (currentDefinition.GetType() == typeof(SiteDefinition)) { resultModel = SPMeta2Model.NewSiteModel(); } if (currentDefinition.GetType() == typeof(WebDefinition)) { resultModel = SPMeta2Model.NewWebModel(); } if (resultModel == null) { throw new SPMeta2NotImplementedException(string.Format("Cannot find host model for type:[{0}]. Ensure correct RootHostAttribute/ParentHostAttribute/SPObjectTypeAttribute attributes.", definitionType.AssemblyQualifiedName)); } resultModel.Value = currentDefinition; result = resultModel; } // ProcessAdditionalArtifacts(result, defs); return(result); }
public ModelNode GenerateModelTreeForDefinition <TDefinition>(SPObjectModelType objectModelType) where TDefinition : DefinitionBase, new() { return(GenerateModelTreeForDefinition(typeof(TDefinition), objectModelType)); }
private Type GetParentHostType <TDefinition>(SPObjectModelType objectModelType) { return(GetParentHostType(typeof(TDefinition), objectModelType)); }
private void LookupModelTree(Type rootHostType, Type definitionType, List <GeneratedNodes> defs, SPObjectModelType objectModelType) { if (rootHostType == null) { return; } if (rootHostType == definitionType) { return; } var parentHostType = definitionType; var customParentHost = GetDefinitionParentHost(definitionType); if (customParentHost == null) { var upParentHostType = GetParentHostType(parentHostType, objectModelType); var definition = new ModelNode { Value = GetRandomDefinition(upParentHostType) }; defs.Add(new GeneratedNodes { ModelNode = definition }); var additionalParentHostTypes = GetParentHostAdditionalTypes(definitionType, objectModelType); Type lastHostType = null; foreach (var additionalParentHostType in additionalParentHostTypes) { var def = GetRandomDefinition(additionalParentHostType); var node = new ModelNode { Value = def }; // in paraller tests these should not be processed // we need RootWebDefinition as a parent onmly to llokup the wroot web if (def is RootWebDefinition) { node.Options.RequireSelfProcessing = false; } defs.Add(new GeneratedNodes { ModelNode = node }); lastHostType = additionalParentHostType; } if (lastHostType != null) { upParentHostType = GetParentHostType(lastHostType, objectModelType); } LookupModelTree(rootHostType, upParentHostType, defs, objectModelType); } else { defs.Add(new GeneratedNodes { ModelNode = customParentHost }); var additionalParentHostTypes = GetParentHostAdditionalTypes(definitionType, objectModelType); Type lastHostType = null; foreach (var additionalParentHostType in additionalParentHostTypes) { var def = GetRandomDefinition(additionalParentHostType); var node = new ModelNode { Value = def }; // in paraller tests these should not be processed // we need RootWebDefinition as a parent onmly to llokup the wroot web if (def is RootWebDefinition) { node.Options.RequireSelfProcessing = false; } defs.Add(new GeneratedNodes { ModelNode = node }); lastHostType = additionalParentHostType; } if (lastHostType != null) { LookupModelTree(rootHostType, lastHostType, defs, objectModelType); } else { LookupModelTree(rootHostType, customParentHost.Value.GetType(), defs, objectModelType); } } }
private void LookupModelTree <TDefinition>(Type rootHostType, List <GeneratedNodes> defs, SPObjectModelType objectModelType) { LookupModelTree(rootHostType, typeof(TDefinition), defs, objectModelType); }
private void LookupModelTree(Type rootHostType, Type type, List <GeneratedNodes> defs, SPObjectModelType objectModelType) { if (rootHostType == null) { return; } if (rootHostType == type) { return; } var parentHostType = type; var customParentHost = GetDefinitionParentHost(type); if (customParentHost == null) { var upParentHostType = GetParentHostType(parentHostType, objectModelType); var definition = new ModelNode { Value = GetRandomDefinition(upParentHostType) }; defs.Add(new GeneratedNodes { ModelNode = definition }); var additionalParentHostTypes = GetParentHostAdditionalTypes(type, objectModelType); Type lastHostType = null; foreach (var additionalParentHostType in additionalParentHostTypes) { var def = GetRandomDefinition(additionalParentHostType); var node = new ModelNode { Value = def }; defs.Add(new GeneratedNodes { ModelNode = node }); lastHostType = additionalParentHostType; } if (lastHostType != null) { upParentHostType = GetParentHostType(lastHostType, objectModelType); } LookupModelTree(rootHostType, upParentHostType, defs, objectModelType); } else { defs.Add(new GeneratedNodes { ModelNode = customParentHost }); var additionalParentHostTypes = GetParentHostAdditionalTypes(type, objectModelType); Type lastHostType = null; foreach (var additionalParentHostType in additionalParentHostTypes) { var def = GetRandomDefinition(additionalParentHostType); var node = new ModelNode { Value = def }; defs.Add(new GeneratedNodes { ModelNode = node }); lastHostType = additionalParentHostType; } if (lastHostType != null) { LookupModelTree(rootHostType, lastHostType, defs, objectModelType); } else { LookupModelTree(rootHostType, customParentHost.Value.GetType(), defs, objectModelType); } } }
public ModelNode GenerateModelTreeForDefinition <TDefinition>(SPObjectModelType objectModelType) where TDefinition : DefinitionBase, new() { ModelNode result = null; var rootHostType = GetRootHostType <TDefinition>(objectModelType); var parentHostType = GetParentHostType <TDefinition>(objectModelType); var currentDefinition = GetRandomDefinition <TDefinition>(); CurrentDefinition = currentDefinition; var defs = new List <GeneratedArtifact>(); LookupModelTree <TDefinition>(rootHostType, defs, objectModelType); if (defs.Count > 0) { defs.Reverse(); var rootHost = defs[0].Definition; parentHostType = rootHost.GetType(); defs.RemoveAt(0); ModelNode model = null; if (parentHostType == typeof(FarmDefinition)) { model = SPMeta2Model.NewFarmModel(); } if (parentHostType == typeof(WebApplicationDefinition)) { model = SPMeta2Model.NewWebApplicationModel(); } if (parentHostType == typeof(SiteDefinition)) { model = SPMeta2Model.NewSiteModel(); } if (parentHostType == typeof(WebDefinition)) { model = SPMeta2Model.NewWebModel(); } var _m = model; foreach (var def in defs) { _m .AddDefinitionNode(def.Definition, currentDef => { currentDef.Options.RequireSelfProcessing = def.Definition.RequireSelfProcessing; _m = currentDef; }); } _m.AddDefinitionNode(currentDefinition); result = model; } else { ModelNode resultModel = null; if (currentDefinition.GetType() == typeof(FarmDefinition)) { resultModel = SPMeta2Model.NewFarmModel(); } if (currentDefinition.GetType() == typeof(WebApplicationDefinition)) { resultModel = SPMeta2Model.NewWebApplicationModel(); } if (currentDefinition.GetType() == typeof(SiteDefinition)) { resultModel = SPMeta2Model.NewSiteModel(); } if (currentDefinition.GetType() == typeof(WebDefinition)) { resultModel = SPMeta2Model.NewWebModel(); } if (resultModel == null) { throw new SPMeta2NotImplementedException(string.Format("Cannot find host model for type:[{0}]. Ensure correct RootHostAttribute/ParentHostAttribute/SPObjectTypeAttribute attributes.", typeof(TDefinition).AssemblyQualifiedName)); } resultModel.Value = currentDefinition; result = resultModel; } // ProcessAdditionalArtifacts(result, defs); return(result); }