コード例 #1
0
        protected ModelProvisionCompatibilityResult CheckProvisionCompatibility(ModelNode model, DefinitionBase definition)
        {
            var result = new ModelProvisionCompatibilityResult
            {
                Model = model
            };

            if (model != null)
            {
                var modelNodes = model.Flatten();
                var rootNode   = model;

                foreach (var modelNode in modelNodes)
                {
                    var def = modelNode.Value;
                    CheckDefinition(result, rootNode, modelNode, def);
                }
            }
            else
            {
                CheckDefinition(result, null, null, definition);
            }

            return(result);
        }
コード例 #2
0
 protected virtual IEnumerable <TDefinition> GetAllDefinitionOfType <TDefinition>(ModelNode model)
     where TDefinition : DefinitionBase
 {
     return(model.Flatten()
            .Where(n => n.Value is TDefinition)
            .Select(s => s.Value as TDefinition));
 }
コード例 #3
0
        public override ModelProvisionCompatibilityResult CheckProvisionCompatibility(ModelNode model)
        {
            var result = new ModelProvisionCompatibilityResult
            {
                Model = model
            };

            var modelNodes = model.Flatten();
            var rootNode = model;

            foreach (var modelNode in modelNodes)
            {
                var def = modelNode.Value;
                var defType = def.GetType();

                var defResult = new ModelProvisionCompatibilityResultValue();
                var attrs = (SPObjectTypeAttribute[])defType
                                .GetCustomAttributes(typeof(SPObjectTypeAttribute), true);

                defResult.ModelNode = modelNode;
                defResult.Definition = def;

                if (attrs.Length > 0)
                {
                    defResult.IsCSOMCompatible = attrs.Any(a => a.ObjectModelType == SPObjectModelType.CSOM);
                    defResult.IsSSOMCompatible = attrs.Any(a => a.ObjectModelType == SPObjectModelType.SSOM);
                }

                // temporary fix for SiteDefinition, it cannot be yet provisioned with M2 CSOM
                if (def.GetType() == typeof(SiteDefinition))
                {
                    if (modelNode.Options.RequireSelfProcessing)
                    {
                        // that's farm / web model or an attempt to provision a new site w/ M2
                        defResult.IsCSOMCompatible = false;
                    }
                    else
                    {
                        // SiteModel, all valid
                        defResult.IsCSOMCompatible = true;
                    }
                }

                // fixing up root definitions
                // farm and web app model cannot be provisioned with M2
                if (modelNode == rootNode)
                {
                    if (defType == typeof(FarmDefinition)
                        || defType == typeof(WebApplicationDefinition))
                    {
                        defResult.IsCSOMCompatible = false;
                    }
                }

                result.Result.Add(defResult);
            }

            return result;
        }
コード例 #4
0
        public override ModelProvisionCompatibilityResult CheckProvisionCompatibility(ModelNode model)
        {
            var result = new ModelProvisionCompatibilityResult
            {
                Model = model
            };

            var modelNodes = model.Flatten();
            var rootNode   = model;

            foreach (var modelNode in modelNodes)
            {
                var def     = modelNode.Value;
                var defType = def.GetType();

                var defResult = new ModelProvisionCompatibilityResultValue();
                var attrs     = (SPObjectTypeAttribute[])defType
                                .GetCustomAttributes(typeof(SPObjectTypeAttribute), true);

                defResult.ModelNode  = modelNode;
                defResult.Definition = def;

                if (attrs.Length > 0)
                {
                    defResult.IsCSOMCompatible = attrs.Any(a => a.ObjectModelType == SPObjectModelType.CSOM);
                    defResult.IsSSOMCompatible = attrs.Any(a => a.ObjectModelType == SPObjectModelType.SSOM);
                }

                // temporary fix for SiteDefinition, it cannot be yet provisioned with M2 CSOM
                if (def.GetType() == typeof(SiteDefinition))
                {
                    if (modelNode.Options.RequireSelfProcessing)
                    {
                        // that's farm / web model or an attempt to provision a new site w/ M2
                        defResult.IsCSOMCompatible = false;
                    }
                    else
                    {
                        // SiteModel, all valid
                        defResult.IsCSOMCompatible = true;
                    }
                }

                // fixing up root definitions
                // farm and web app model cannot be provisioned with M2
                if (modelNode == rootNode)
                {
                    if (defType == typeof(FarmDefinition) ||
                        defType == typeof(WebApplicationDefinition))
                    {
                        defResult.IsCSOMCompatible = false;
                    }
                }

                result.Result.Add(defResult);
            }

            return(result);
        }
コード例 #5
0
        public override ModelStatInfo GetModelStat(ModelNode modelNode, ModelStatInfoServiceOptions options)
        {
            if (options == null)
            {
                throw new ArgumentNullException("options");
            }

            var result = new ModelStatInfo();

            var allModelNodes = modelNode.Flatten();

            result.TotalModelNodeCount = allModelNodes.Count;

            foreach (var node in allModelNodes)
            {
                var def = node.Value;

                var defAssemblyTypeName      = def.GetType().AssemblyQualifiedName;
                var defAssemblyTypeShortName = def.GetType().Name;

                var nodeStat = result.NodeStat.FirstOrDefault(s => s.DefinitionAssemblyQualifiedName == defAssemblyTypeName);

                if (nodeStat == null)
                {
                    nodeStat = new ModelNodeStatInfo
                    {
                        DefinitionAssemblyQualifiedName = defAssemblyTypeName,
                        DefinitionName = defAssemblyTypeShortName
                    };

                    result.NodeStat.Add(nodeStat);
                }

                nodeStat.Count++;

                if (options.IncludeModelNodes)
                {
                    nodeStat.ModelNodes.Add(modelNode);
                }
            }

            return(result);
        }
コード例 #6
0
        public override void DeployModel(ModelHostBase modelHost, ModelNode model)
        {
            Exceptions.Clear();

            var exceptionMessage = "List node:[{0}] has [{1}] with ContentTypeId value:[{2}]. ContentTypeId does not work on the list scoped content type operations. Use ContentTypeName for list scoped content type operations.";

            var allNodes = model.Flatten();

            //var addContentTypes = GetParenChildNodes<ListDefinition, ContentTypeLinkDefinition>(allNodes);
            var hideContentTypes   = GetParenChildNodes <ListDefinition, HideContentTypeLinksDefinition>(allNodes);
            var removeContentTypes = GetParenChildNodes <ListDefinition, RemoveContentTypeLinksDefinition>(allNodes);
            var uniqueContentTypes = GetParenChildNodes <ListDefinition, UniqueContentTypeOrderDefinition>(allNodes);

            //ValidateChildNodes<ContentTypeLinkDefinition>(addContentTypes, (node, child) =>
            //{
            //    var typedDef = child.Value as ContentTypeLinkDefinition;

            //    if (!string.IsNullOrEmpty(typedDef.ContentTypeId))
            //    {
            //        Exceptions.Add(new SPMeta2ModelValidationException(
            //            string.Format(exceptionMessage,
            //            new object[]{
            //                    node,
            //                    typedDef.GetType(),
            //                    typedDef.ContentTypeName
            //                })));
            //    }
            //});

            ValidateChildNodes <HideContentTypeLinksDefinition>(hideContentTypes, (node, child) =>
            {
                var typedDef = child.Value as HideContentTypeLinksDefinition;

                foreach (var ctLink in typedDef.ContentTypes)
                {
                    if (!string.IsNullOrEmpty(ctLink.ContentTypeId))
                    {
                        Exceptions.Add(new SPMeta2ModelValidationException(
                                           string.Format(exceptionMessage,
                                                         new object[] {
                            node,
                            typedDef.GetType(),
                            ctLink.ContentTypeId
                        })));
                    }
                }
            });

            ValidateChildNodes <RemoveContentTypeLinksDefinition>(removeContentTypes, (node, child) =>
            {
                var typedDef = child.Value as RemoveContentTypeLinksDefinition;

                foreach (var ctLink in typedDef.ContentTypes)
                {
                    if (!string.IsNullOrEmpty(ctLink.ContentTypeId))
                    {
                        Exceptions.Add(new SPMeta2ModelValidationException(
                                           string.Format(exceptionMessage,
                                                         new object[] {
                            node,
                            typedDef.GetType(),
                            ctLink.ContentTypeId
                        })));
                    }
                }
            });

            ValidateChildNodes <UniqueContentTypeOrderDefinition>(uniqueContentTypes, (node, child) =>
            {
                var typedDef = child.Value as UniqueContentTypeOrderDefinition;

                foreach (var ctLink in typedDef.ContentTypes)
                {
                    if (!string.IsNullOrEmpty(ctLink.ContentTypeId))
                    {
                        Exceptions.Add(new SPMeta2ModelValidationException(
                                           string.Format(exceptionMessage,
                                                         new object[] {
                            node,
                            typedDef.GetType(),
                            ctLink.ContentTypeId
                        })));
                    }
                }
            });

            if (Exceptions.Count > 0)
            {
                throw new SPMeta2ModelDeploymentException("Errors while validating the model",
                                                          new SPMeta2AggregateException(Exceptions.OfType <Exception>()));
            }
        }