Esempio n. 1
0
        protected virtual SPContentType GetContentType(SPWeb web, DocumentSetDefinition definition)
        {
            var contentTypeName = definition.ContentTypeName;
            var contentTypeId   = definition.ContentTypeId;

            // by ID, by Name
            SPContentType contentType = null;

            if (!string.IsNullOrEmpty(contentTypeId))
            {
                contentType = web.AvailableContentTypes[new SPContentTypeId(contentTypeId)];

                if (contentType == null)
                {
                    throw new SPMeta2Exception(string.Format("Cannot find content type by ID:[{0}]", contentTypeId));
                }
            }
            else if (!string.IsNullOrEmpty(contentTypeName))
            {
                contentType = web.AvailableContentTypes
                              .OfType <SPContentType>()
                              .FirstOrDefault(f => f.Name.ToUpper() == contentTypeName.ToUpper());

                if (contentType == null)
                {
                    throw new SPMeta2Exception(string.Format("Cannot find content type by Name:[{0}]", contentTypeName));
                }
            }

            return(contentType);
        }
Esempio n. 2
0
        protected virtual ContentType GetContentType(CSOMModelHostBase modelHost, DocumentSetDefinition definition)
        {
            var contentTypeName = definition.ContentTypeName;
            var contentTypeId   = definition.ContentTypeId;

            var context = modelHost.HostClientContext;
            var web     = modelHost.HostWeb;

            ContentType contentType = null;

#if !NET35
            if (!string.IsNullOrEmpty(contentTypeId))
            {
                var tmpContentType = context.LoadQuery(web.AvailableContentTypes.Where(ct => ct.StringId == contentTypeId));
                context.ExecuteQueryWithTrace();

                contentType = tmpContentType.FirstOrDefault();

                if (contentType == null)
                {
                    throw new SPMeta2Exception(string.Format("Cannot find content type by ID:[{0}]", contentTypeId));
                }
            }
            else if (!string.IsNullOrEmpty(contentTypeName))
            {
                var tmpContentType = context.LoadQuery(web.AvailableContentTypes.Where(ct => ct.Name == contentTypeName));
                context.ExecuteQueryWithTrace();

                contentType = tmpContentType.FirstOrDefault();

                if (contentType == null)
                {
                    throw new SPMeta2Exception(string.Format("Cannot find content type by Name:[{0}]", contentTypeName));
                }
            }
#endif

#if NET35
            // SP2010 CSOM does not have an option to get the content type by ID
            // fallback to Name, and that's a huge thing all over the M2 library and provision

            var tmpContentType = context.LoadQuery(web.AvailableContentTypes.Where(ct => ct.Name == contentTypeName));
            context.ExecuteQueryWithTrace();

            contentType = tmpContentType.FirstOrDefault();

            if (contentType == null)
            {
                throw new SPMeta2Exception(string.Format("Cannot find content type by Name:[{0}]", contentTypeName));
            }
#endif

            return(contentType);
        }
Esempio n. 3
0
        private void DeployArtifact(CSOMModelHostBase modelHost, Folder folder, DocumentSetDefinition definition)
        {
            var currentDocumentSet = GetExistingDocumentSet(modelHost, folder, definition);

            var context = modelHost.HostClientContext;
            var web     = modelHost.HostWeb;

            var documentSetName = definition.Name;

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

            if (currentDocumentSet == null)
            {
                var contentType = GetContentType(modelHost, definition);

                DocumentSet.Create(context, folder, documentSetName, contentType.Id);
                context.ExecuteQueryWithTrace();

                currentDocumentSet = GetExistingDocumentSet(modelHost, folder, definition);
            }

            if (!string.IsNullOrEmpty(definition.Description))
            {
                currentDocumentSet.ListItemAllFields["DocumentSetDescription"] = definition.Description;
                currentDocumentSet.ListItemAllFields.Update();

                context.ExecuteQueryWithTrace();
            }

            InvokeOnModelEvent(this, new ModelEventArgs
            {
                CurrentModelNode = null,
                Model            = null,
                EventType        = ModelEventType.OnProvisioned,
                Object           = currentDocumentSet,
                ObjectType       = typeof(Folder),
                ObjectDefinition = definition,
                ModelHost        = modelHost
            });
        }
Esempio n. 4
0
        private void DeployArtifact(SSOMModelHostBase modelHost, SPFolder folder, DocumentSetDefinition definition)
        {
            var currentDocumentSet = GetExistingDocumentSet(modelHost, folder, definition);

            var web             = folder.ParentWeb;
            var documentSetName = definition.Name;

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

            if (currentDocumentSet == null)
            {
                var contentType = GetContentType(web, definition);

                var props  = new Hashtable();
                var docSet = DocumentSet.Create(folder, documentSetName, contentType.Id, props);

                currentDocumentSet = docSet.Folder;
            }

            if (!string.IsNullOrEmpty(definition.Description))
            {
                currentDocumentSet.Item["DocumentSetDescription"] = definition.Description;
                currentDocumentSet.Item.Update();
            }

            InvokeOnModelEvent(this, new ModelEventArgs
            {
                CurrentModelNode = null,
                Model            = null,
                EventType        = ModelEventType.OnProvisioned,
                Object           = currentDocumentSet,
                ObjectType       = typeof(SPFolder),
                ObjectDefinition = definition,
                ModelHost        = modelHost
            });
        }
 public static TModelNode AddDocumentSet <TModelNode>(this TModelNode model, DocumentSetDefinition definition,
                                                      Action <DocumentSetModelNode> action)
     where TModelNode : ModelNode, IFolderHostModelNode, new()
 {
     return(model.AddTypedDefinitionNode(definition, action));
 }
 public static TModelNode AddDocumentSet <TModelNode>(this TModelNode model, DocumentSetDefinition definition)
     where TModelNode : ModelNode, IFolderHostModelNode, new()
 {
     return(AddDocumentSet(model, definition, null));
 }
Esempio n. 7
0
        protected virtual SPFolder GetExistingDocumentSet(object modelHost, SPFolder folder, DocumentSetDefinition definition)
        {
            var folderName   = definition.Name;
            var parentFolder = folder;

            // dirty stuff, needs to be rewritten
            var currentFolder = parentFolder
                                .SubFolders
                                .OfType <SPFolder>()
                                .FirstOrDefault(f => f.Name == folderName);

            if (currentFolder != null)
            {
                return(currentFolder);
            }

            return(null);
        }
Esempio n. 8
0
        protected virtual Folder GetExistingDocumentSet(CSOMModelHostBase modelHost, Folder folder, DocumentSetDefinition definition)
        {
            var folderName   = definition.Name;
            var parentFolder = folder;

            var context = parentFolder.Context;

            context.Load(parentFolder, f => f.Folders);
            context.ExecuteQueryWithTrace();

            // dirty stuff, needs to be rewritten
            var currentFolder = parentFolder
                                .Folders
                                .OfType <Folder>()
                                .FirstOrDefault(f => f.Name == folderName);

            if (currentFolder != null)
            {
                return(currentFolder);
            }

            return(null);
        }