Пример #1
0
        protected SPGroup ResolveSecurityGroup(SPWeb web, SecurityGroupLinkDefinition securityGroupLinkModel)
        {
            SPGroup securityGroup = null;

            if (securityGroupLinkModel.IsAssociatedMemberGroup)
            {
                TraceService.Verbose((int)LogEventId.ModelProvisionCoreCall, "IsAssociatedMemberGroup = true. Resolving AssociatedMemberGroup");
                securityGroup = web.AssociatedMemberGroup;
            }
            else if (securityGroupLinkModel.IsAssociatedOwnerGroup)
            {
                TraceService.Verbose((int)LogEventId.ModelProvisionCoreCall, "IsAssociatedOwnerGroup = true. Resolving IsAssociatedOwnerGroup");
                securityGroup = web.AssociatedOwnerGroup;
            }
            else if (securityGroupLinkModel.IsAssociatedVisitorGroup)
            {
                TraceService.Verbose((int)LogEventId.ModelProvisionCoreCall, "IsAssociatedVisitorGroup = true. Resolving IsAssociatedVisitorGroup");
                securityGroup = web.AssociatedVisitorGroup;
            }
            else if (!string.IsNullOrEmpty(securityGroupLinkModel.SecurityGroupName))
            {
                TraceService.VerboseFormat((int)LogEventId.ModelProvisionCoreCall, "Resolving group by name: [{0}]", securityGroupLinkModel.SecurityGroupName);
                securityGroup = web.SiteGroups[securityGroupLinkModel.SecurityGroupName];
            }
            else
            {
                TraceService.Error((int)LogEventId.ModelProvisionCoreCall, "IsAssociatedMemberGroup/IsAssociatedOwnerGroup/IsAssociatedVisitorGroup/SecurityGroupName should be defined. Throwing SPMeta2Exception");

                throw new SPMeta2Exception("securityGroupLinkModel");
            }

            return(securityGroup);
        }
Пример #2
0
        private void CheckSharePointRuntimeVersion()
        {
            // Require minimum SP2013 SP1 which is 15.0.4569.1000
            // We need 15.0.4569.1000 as this allows to create content types with particular ID
            // If current assembly version is lover than 15.0.4569.1000, then we gonna have missing field exception on ContentTypeCreationInformation.Id
            // http://blogs.technet.com/b/steve_chen/archive/2013/03/26/3561010.aspx
            var minimalVersion = new Version("15.0.4569.1000");

            var spAssembly            = typeof(Field).Assembly;
            var spAssemblyFileVersion = FileVersionInfo.GetVersionInfo(spAssembly.Location);

            var versionInfo = new Version(spAssemblyFileVersion.ProductVersion);

            TraceService.InformationFormat((int)LogEventId.ModelProcessing,
                                           "CSOM - CheckSharePointRuntimeVersion. Required minimal version :[{0}]. Current version: [{1}] Location: [{2}]",
                                           new object[]
            {
                minimalVersion,
                spAssemblyFileVersion,
                spAssemblyFileVersion.ProductVersion
            });

            if (versionInfo < minimalVersion)
            {
                TraceService.Error((int)LogEventId.ModelProcessing, "CSOM - CheckSharePointRuntimeVersion failed. Throwing SPMeta2NotSupportedException");

                var exceptionMessage = string.Empty;

                exceptionMessage += string.Format("SPMeta2.CSOM.dll requires at least SP2013 SP1 runtime ({0}).{1}", minimalVersion, Environment.NewLine);
                exceptionMessage += string.Format(" Current Microsoft.SharePoint.Client.dll version:[{0}].{1}", spAssemblyFileVersion.ProductVersion, Environment.NewLine);
                exceptionMessage += string.Format(" Current Microsoft.SharePoint.Client.dll location:[{0}].{1}", spAssembly.Location, Environment.NewLine);

                throw new SPMeta2NotSupportedException(exceptionMessage);
            }
        }
Пример #3
0
        private void DeployFeatureInternal(object modelHost, FeatureDefinition featureModel)
        {
            switch (featureModel.Scope)
            {
            case FeatureDefinitionScope.Farm:
            {
                TraceService.Error((int)LogEventId.ModelProvisionCoreCall, "Farm features are not supported with CSOM. Throwing SPMeta2NotSupportedException.");
                throw new SPMeta2NotSupportedException("Farm features are not supported with CSOM.");
            }

            case FeatureDefinitionScope.WebApplication:
            {
                TraceService.Error((int)LogEventId.ModelProvisionCoreCall, "Web application features are not supported with CSOM. Throwing SPMeta2NotSupportedException.");
                throw new SPMeta2NotSupportedException("Web application features are not supported with CSOM.");
            }

            case FeatureDefinitionScope.Site:
                DeploySiteFeature(modelHost, featureModel);
                break;

            case FeatureDefinitionScope.Web:
                DeployWebFeature(modelHost, featureModel);
                break;
            }
        }
        protected virtual void CheckCSOMRuntimeVersion()
        {
            // Require minimum SP2013 SP1 which is 15.0.4569.1000
            // We need 15.0.4569.1000 as this allows to create content types with particular ID
            // If current assembly version is lover than 15.0.4569.1000, then we gonna have missing field exception on ContentTypeCreationInformation.Id
            // http://blogs.technet.com/b/steve_chen/archive/2013/03/26/3561010.aspx

            var spAssembly  = GetCSOMRuntimeAssembly();
            var versionInfo = GetCSOMRuntimeVersion();

            var assemblyLocation = string.Empty;

            // RequireCSOMRuntimeVersionDeploymentService does not work under Azure Funtions #962
            // https://github.com/SubPointSolutions/spmeta2/issues/962
            try
            {
                assemblyLocation = spAssembly.Location;
            }
            catch (Exception assemblyLocationLoadException)
            {
                assemblyLocation = string.Format("Coudn't load .Location property. Exception was:[{0}]", assemblyLocationLoadException);
            }

            TraceService.InformationFormat((int)LogEventId.ModelProcessing,
                                           "CSOM - CheckSharePointRuntimeVersion. Required minimal version :[{0}]. Current version: [{1}] Location: [{2}]",
                                           new object[]
            {
                MinimalVersion,
                versionInfo,
                assemblyLocation
            });

            if (versionInfo.Major == 14)
            {
                // TODO, SP2010 check later
            }
            else if (versionInfo.Major == 15)
            {
                if (versionInfo < SP2013MinimalVersion)
                {
                    TraceService.Error((int)LogEventId.ModelProcessing, "CSOM - CheckSharePointRuntimeVersion failed. Throwing SPMeta2NotSupportedException");

                    var exceptionMessage = string.Empty;

                    exceptionMessage += string.Format("SPMeta2.CSOM.dll requires at least SP2013 SP1 runtime ({0}).{1}", MinimalVersion, Environment.NewLine);
                    exceptionMessage += string.Format(" Current Microsoft.SharePoint.Client.dll version:[{0}].{1}", versionInfo.Major, Environment.NewLine);
                    exceptionMessage += string.Format(" Current Microsoft.SharePoint.Client.dll location:[{0}].{1}", assemblyLocation, Environment.NewLine);

                    throw new SPMeta2NotSupportedException(exceptionMessage);
                }
            }
            else if (versionInfo.Major == 16)
            {
                // TODO, SP2016 check later
            }
        }
Пример #5
0
        public override void DeployModel(object modelHost, DefinitionBase model)
        {
            TraceService.Error((int)LogEventId.ModelProvisionCoreCall, "AppPrincipal provision via CSOM is not supported by SharePoint. Throwing SPMeta2NotSupportedException");

            throw new SPMeta2NotSupportedException("AppPrincipal provision via CSOM is not supported by SharePoint.");

            //var webHost = modelHost.WithAssertAndCast<WebModelHost>("modelHost", value => value.RequireNotNull());
            //var appPrincipalModel = model.WithAssertAndCast<AppPrincipalDefinition>("model", value => value.RequireNotNull());

            //DeployAppPrincipal(modelHost, webHost, appPrincipalModel);
        }
Пример #6
0
        private void DeployInternall(SPList list, SPFolder folder, ListItemDefinition listItemModel)
        {
            if (IsDocumentLibray(list))
            {
                TraceService.Error((int)LogEventId.ModelProvisionCoreCall, "Please use ModuleFileDefinition to deploy files to the document libraries. Throwing SPMeta2NotImplementedException");

                throw new SPMeta2NotImplementedException("Please use ModuleFileDefinition to deploy files to the document libraries");
            }

            EnsureListItem(list, folder, listItemModel);
        }
Пример #7
0
        private void DeployInternall(List list, Folder folder, ListItemDefinition listItemModel)
        {
            if (IsDocumentLibray(list))
            {
                TraceService.Error((int)LogEventId.ModelProvisionCoreCall, "Please use ModuleFileDefinition to deploy files to the document libraries. Throwing SPMeta2NotImplementedException");

                throw new SPMeta2NotImplementedException("Please use ModuleFileDefinition to deploy files to the document libraries");
            }

            ListItem currentItem = null;

            InvokeOnModelEvent <ListItemDefinition, ListItem>(currentItem, ModelEventType.OnUpdating);
            currentItem = EnsureListItem(list, folder, listItemModel);
            InvokeOnModelEvent <ListItemDefinition, ListItem>(currentItem, ModelEventType.OnUpdated);
        }
Пример #8
0
        protected virtual Group ResolveSecurityGroup(SecurityGroupLinkDefinition securityGroupLinkModel, Web web, ClientRuntimeContext context)
        {
            Group securityGroup = null;

            if (securityGroupLinkModel.IsAssociatedMemberGroup)
            {
                TraceService.Verbose((int)LogEventId.ModelProvisionCoreCall, "IsAssociatedMemberGroup = true. Resolving AssociatedMemberGroup");

                context.Load(web, w => w.AssociatedMemberGroup);
                context.ExecuteQueryWithTrace();

                securityGroup = web.AssociatedMemberGroup;
            }
            else if (securityGroupLinkModel.IsAssociatedOwnerGroup)
            {
                TraceService.Verbose((int)LogEventId.ModelProvisionCoreCall, "IsAssociatedOwnerGroup = true. Resolving IsAssociatedOwnerGroup");

                context.Load(web, w => w.AssociatedOwnerGroup);
                context.ExecuteQueryWithTrace();

                securityGroup = web.AssociatedOwnerGroup;
            }
            else if (securityGroupLinkModel.IsAssociatedVisitorGroup)
            {
                TraceService.Verbose((int)LogEventId.ModelProvisionCoreCall, "IsAssociatedVisitorGroup = true. Resolving IsAssociatedVisitorGroup");

                context.Load(web, w => w.AssociatedVisitorGroup);
                context.ExecuteQueryWithTrace();

                securityGroup = web.AssociatedVisitorGroup;
            }
            else if (!string.IsNullOrEmpty(securityGroupLinkModel.SecurityGroupName))
            {
                TraceService.VerboseFormat((int)LogEventId.ModelProvisionCoreCall, "Resolving group by name: [{0}]", securityGroupLinkModel.SecurityGroupName);

                securityGroup = WebExtensions.FindGroupByName(web.SiteGroups, securityGroupLinkModel.SecurityGroupName);
            }
            else
            {
                TraceService.Error((int)LogEventId.ModelProvisionCoreCall,
                                   "IsAssociatedMemberGroup/IsAssociatedOwnerGroup/IsAssociatedVisitorGroup/SecurityGroupName should be defined. Throwing SPMeta2Exception");

                throw new SPMeta2Exception("securityGroupLinkModel");
            }

            return(securityGroup);
        }
Пример #9
0
        protected ModelHandlerBase ResolveModelHandlerForNode(ModelNode modelNode)
        {
            var modelDefinition = modelNode.Value as DefinitionBase;
            var modelHandler    = ResolveModelHandler(modelDefinition.GetType());

            if (modelHandler == null)
            {
                TraceService.Error((int)LogEventId.ModelProcessingNullModelHandler, string.Format("Model handler instance is NULL. Throwing ArgumentNullException exception."));

                throw new ArgumentNullException(
                          string.Format("Can't find model handler for type:[{0}]. Current ModelService type: [{1}].",
                                        modelDefinition.GetType(),
                                        GetType()));
            }

            return(modelHandler);
        }
Пример #10
0
        private void DeployHideContentTypeLinks(object modelHost, List list, RemoveContentTypeLinksDefinition contentTypeOrderDefinition)
        {
            var context = list.Context;

            TraceService.Verbose((int)LogEventId.ModelProvisionCoreCall, "Fetching list content types");

            context.Load(list, l => l.ContentTypes);
            context.ExecuteQueryWithTrace();

            var listContentTypes = list.ContentTypes.ToList();

            InvokeOnModelEvent(this, new ModelEventArgs
            {
                CurrentModelNode = null,
                Model            = null,
                EventType        = ModelEventType.OnProvisioning,
                Object           = list,
                ObjectType       = typeof(List),
                ObjectDefinition = contentTypeOrderDefinition,
                ModelHost        = modelHost
            });

            // re-order
            foreach (var srcContentTypeDef in contentTypeOrderDefinition.ContentTypes)
            {
                ContentType listContentType = null;

                if (!string.IsNullOrEmpty(srcContentTypeDef.ContentTypeName))
                {
                    listContentType = listContentTypes.FirstOrDefault(c => c.Name.ToUpper() == srcContentTypeDef.ContentTypeName.ToUpper());

                    if (listContentType != null)
                    {
                        TraceService.Verbose((int)LogEventId.ModelProvisionCoreCall,
                                             string.Format("Found content type by name:[{0}]", srcContentTypeDef.ContentTypeName));
                    }
                }

                if (listContentType == null && !string.IsNullOrEmpty(srcContentTypeDef.ContentTypeId))
                {
                    listContentType =
                        listContentTypes.FirstOrDefault(
                            c => c.Id.ToString().ToUpper().StartsWith(srcContentTypeDef.ContentTypeId.ToUpper()));

                    if (listContentType != null)
                    {
                        TraceService.Verbose((int)LogEventId.ModelProvisionCoreCall,
                                             string.Format("Found content type by matching ID start:[{0}]", srcContentTypeDef.ContentTypeId));
                    }
                }

                if (listContentType != null)
                {
                    try
                    {
                        TraceService.Verbose((int)LogEventId.ModelProvisionCoreCall, string.Format("Deleting list content type"));
                        listContentType.DeleteObject();
                    }
                    catch (Exception e)
                    {
                        TraceService.Error((int)LogEventId.ModelProvisionCoreCall, e);
                    }
                }
            }

            InvokeOnModelEvent(this, new ModelEventArgs
            {
                CurrentModelNode = null,
                Model            = null,
                EventType        = ModelEventType.OnProvisioned,
                Object           = list,
                ObjectType       = typeof(List),
                ObjectDefinition = contentTypeOrderDefinition,
                ModelHost        = modelHost
            });

            context.ExecuteQueryWithTrace();
        }
Пример #11
0
        public override void DeployModel(object modelHost, DefinitionBase model)
        {
            var webModelHost = modelHost.WithAssertAndCast <WebModelHost>("modelHost", value => value.RequireNotNull());

            var web       = webModelHost.HostWeb;
            var listModel = model.WithAssertAndCast <ListDefinition>("model", value => value.RequireNotNull());

            var context = web.Context;

            context.Load(web, w => w.ServerRelativeUrl);
            context.ExecuteQueryWithTrace();

            List currentList = null;

            var loadedList = LoadCurrentList(web, listModel);

            if (loadedList != null)
            {
                currentList = loadedList;
            }

            InvokeOnModelEvent(this, new ModelEventArgs
            {
                CurrentModelNode = null,
                Model            = null,
                EventType        = ModelEventType.OnProvisioning,
                Object           = null,
                ObjectType       = typeof(List),
                ObjectDefinition = model,
                ModelHost        = modelHost
            });

            // gosh!
            //currentList = FindListByUrl(lists, listModel.GetListUrl());

            if (currentList == null)
            {
                TraceService.Information((int)LogEventId.ModelProvisionProcessingNewObject, "Processing new list");

                // no support for the TemplateName yet
                var listInfo = new ListCreationInformation
                {
                    Title       = listModel.Title,
                    Description = listModel.Description ?? string.Empty,
#pragma warning disable 618
                    Url = listModel.GetListUrl()
#pragma warning restore 618
                };

                if (listModel.TemplateType > 0)
                {
                    TraceService.VerboseFormat((int)LogEventId.ModelProvisionCoreCall, "Creating list by TemplateType: [{0}]", listModel.TemplateType);

                    listInfo.TemplateType = listModel.TemplateType;
                }
                else if (!string.IsNullOrEmpty(listModel.TemplateName))
                {
                    TraceService.VerboseFormat((int)LogEventId.ModelProvisionCoreCall, "Creating list by TemplateName: [{0}]", listModel.TemplateName);

                    var listTemplate = ResolveListTemplate(webModelHost, listModel);

                    listInfo.TemplateFeatureId = listTemplate.FeatureId;
                    listInfo.TemplateType      = listTemplate.ListTemplateTypeKind;
                }
                else
                {
                    TraceService.Error((int)LogEventId.ModelProvisionCoreCall, "Either TemplateType or TemplateName has to be specified. Throwing SPMeta2Exception");

                    throw new SPMeta2Exception("Either TemplateType or TemplateName has to be specified.");
                }

                var newList = web.Lists.Add(listInfo);
                currentList = newList;

                currentList.Update();
                context.ExecuteQueryWithTrace();

                currentList = LoadCurrentList(web, listModel);
            }
            else
            {
                TraceService.Information((int)LogEventId.ModelProvisionProcessingExistingObject, "Processing existing list");
            }

            MapListProperties(modelHost, currentList, listModel);

            InvokeOnModelEvent(this, new ModelEventArgs
            {
                CurrentModelNode = null,
                Model            = null,
                EventType        = ModelEventType.OnProvisioned,
                Object           = currentList,
                ObjectType       = typeof(List),
                ObjectDefinition = model,
                ModelHost        = modelHost
            });

            TraceService.Verbose((int)LogEventId.ModelProvisionCoreCall, "Calling currentList.Update()");

            currentList.Update();
            context.ExecuteQueryWithTrace();
        }
        private void DeployHideContentTypeLinks(object modelHost, SPList list, RemoveContentTypeLinksDefinition contentTypeOrderDefinition)
        {
            var listContentTypes = list.ContentTypes.OfType <SPContentType>().ToList();

            InvokeOnModelEvent(this, new ModelEventArgs
            {
                CurrentModelNode = null,
                Model            = null,
                EventType        = ModelEventType.OnProvisioning,
                Object           = list,
                ObjectType       = typeof(SPList),
                ObjectDefinition = contentTypeOrderDefinition,
                ModelHost        = modelHost
            });

            // re-order
            foreach (var srcContentTypeDef in contentTypeOrderDefinition.ContentTypes)
            {
                SPContentType listContentType = null;

                if (!string.IsNullOrEmpty(srcContentTypeDef.ContentTypeName))
                {
                    listContentType = listContentTypes.FirstOrDefault(c => c.Name.ToUpper() == srcContentTypeDef.ContentTypeName.ToUpper());

                    if (listContentType != null)
                    {
                        TraceService.Verbose((int)LogEventId.ModelProvisionCoreCall,
                                             string.Format("Found content type by name:[{0}]", srcContentTypeDef.ContentTypeName));
                    }
                }

                if (listContentType == null && !string.IsNullOrEmpty(srcContentTypeDef.ContentTypeId))
                {
                    var spContentTypeId = new SPContentTypeId(srcContentTypeDef.ContentTypeId);
                    listContentType = listContentTypes.FirstOrDefault(c => c.Parent.Id == spContentTypeId);

                    if (listContentType != null)
                    {
                        TraceService.Verbose((int)LogEventId.ModelProvisionCoreCall,
                                             string.Format("Found content type by matching parent ID:[{0}]", srcContentTypeDef.ContentTypeId));
                    }
                }

                if (listContentType != null)
                {
                    try
                    {
                        TraceService.Verbose((int)LogEventId.ModelProvisionCoreCall, string.Format("Deleting list content type"));
                        list.ContentTypes.Delete(listContentType.Id);
                    }
                    catch (Exception e)
                    {
                        TraceService.Error((int)LogEventId.ModelProvisionCoreCall, e);
                    }
                }
            }

            InvokeOnModelEvent(this, new ModelEventArgs
            {
                CurrentModelNode = null,
                Model            = null,
                EventType        = ModelEventType.OnProvisioned,
                Object           = list,
                ObjectType       = typeof(SPList),
                ObjectDefinition = contentTypeOrderDefinition,
                ModelHost        = modelHost
            });
        }