private void DeployDefinition(object modelHost, ListModelHost siteModelHost, InformationRightsManagementSettingsDefinition definition)
        {
            var currentSettings = GetCurrentInformationRightsManagementSettings(siteModelHost.HostList);

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

            MapInformationRightsManagementSettings(currentSettings, definition);

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

            currentSettings.Update();
        }
        private void DeployListWorkflowAssociationDefinition(ListModelHost modelHost, SPList list, WorkflowAssociationDefinition definition)
        {
            var existingWorkflowAssotiation = FindExistringWorkflowAssotiation(modelHost, definition);

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

            bool isNew = false;

            if (existingWorkflowAssotiation == null)
            {
                var workflowTemplate = GetWorkflowTemplate(modelHost, definition);

                existingWorkflowAssotiation = SPWorkflowAssociation.CreateListAssociation(workflowTemplate,
                           definition.Name,
                           list.Lists[definition.TaskListTitle],
                           list.Lists[definition.HistoryListTitle]);

                isNew = true;
            }

            MapProperties(definition, existingWorkflowAssotiation);

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

            if (isNew)
            {
                list.WorkflowAssociations.Add(existingWorkflowAssotiation);
            }
            else
            {
                // ??
            }
        }
 private void DeployListDependentLookup(object modelHost, ListModelHost listModelHost, DependentLookupFieldDefinition definition)
 {
     DeployDependentLookupField(modelHost, listModelHost.HostList.Fields, definition);
 }
        private void DeployListWorkflowAssociationDefinition(ListModelHost modelHost, SPList list, WorkflowAssociationDefinition definition)
        {
            var existingWorkflowAssotiation = FindExistringWorkflowAssotiation(modelHost, definition);

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

            bool isNew = false;

            if (existingWorkflowAssotiation == null)
            {
                var workflowTemplate = GetWorkflowTemplate(modelHost, definition);

                if (workflowTemplate == null)
                {
                    throw new SPMeta2Exception(
                        string.Format("Cannot find workflow template by definition:[{0}]", definition));
                }

                existingWorkflowAssotiation = SPWorkflowAssociation.CreateListAssociation(workflowTemplate,
                           definition.Name,
                           list.ParentWeb.Lists[definition.TaskListTitle],
                           list.ParentWeb.Lists[definition.HistoryListTitle]);

                isNew = true;
            }

            MapProperties(definition, existingWorkflowAssotiation);

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

            if (isNew)
            {
                list.WorkflowAssociations.Add(existingWorkflowAssotiation);
                list.Update();
            }
            else
            {
                list.WorkflowAssociations.Update(existingWorkflowAssotiation);
            }
        }
 private void DeployListEventReceiver(object modelHost, ListModelHost listModelHost, EventReceiverDefinition definition)
 {
     DeployEventReceiver(modelHost, listModelHost.HostList.EventReceivers, definition);
 }
        private void DeploySettings(object modelHost, ListModelHost listHost, MetadataNavigationSettingsDefinition definition)
        {
            var list = listHost.HostList;

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

            var needUpdate = false;

            // deploy
            var settings = GetCurrentSettings(list);

            if (definition.Hierarchies.Count() > 0)
            {
                foreach (var h in definition.Hierarchies)
                {
                    if (h.FieldId.HasGuidValue())
                    {
                        var targetField = list.Fields[h.FieldId.Value];

                        settings.AddConfiguredHierarchy(new MetadataNavigationHierarchy(targetField));
                    }
                }

                needUpdate = true;
            }

            if (definition.KeyFilters.Count() > 0)
            {
                foreach (var h in definition.KeyFilters)
                {
                    if (h.FieldId.HasGuidValue())
                    {
                        var targetField = list.Fields[h.FieldId.Value];

                        settings.AddConfiguredKeyFilter(new MetadataNavigationKeyFilter(targetField));
                    }
                }

                needUpdate = true;
            }

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


            if (needUpdate)
            {
                MetadataNavigationSettings.SetMetadataNavigationSettings(list, settings);
            }

        }
Beispiel #7
0
        public override void WithResolvingModelHost(object modelHost, DefinitionBase model, Type childModelType, Action<object> action)
        {
            var webModelHost = modelHost.WithAssertAndCast<WebModelHost>("modelHost", value => value.RequireNotNull());
            var web = webModelHost.HostWeb;

            var listDefinition = model as ListDefinition;

            if (web != null && listDefinition != null)
            {
                // This is very important line ->  adding new 'fake list'
                //
                // Nintex workflow deployment web service updates the list, so that version of the list becomes +4
                // Current SPWeb has not been updated, current list will be 4 versions behind so you will have 'Save conflict' exception
                //
                // We try to add new list, so SPListCollection is invalidated.
                // Surely, we won't save this list.
                try
                {
                    var tmpListId = web.Lists.Add(Guid.NewGuid().ToString(), string.Empty, Microsoft.SharePoint.SPListTemplateType.GenericList);
                    var tmpList = web.Lists[tmpListId];
                    tmpList.Delete();
                }
                catch (Exception)
                {
                }

                var list = web.GetList(SPUtility.ConcatUrls(web.ServerRelativeUrl, listDefinition.GetListUrl()));

                var listModelHost = new ListModelHost
                {
                    HostList = list
                };

                if (childModelType == typeof(ModuleFileDefinition))
                {
                    var folderModelHost = new FolderModelHost
                    {
                        CurrentLibrary = list as SPDocumentLibrary,
                        CurrentLibraryFolder = list.RootFolder,

                        CurrentList = (list as SPDocumentLibrary != null) ? null : list,
                        CurrentListItem = null,
                    };

                    action(folderModelHost);
                }
                else if (childModelType == typeof(FolderDefinition))
                {
                    var folderModelHost = new FolderModelHost
                    {
                        CurrentLibrary = list as SPDocumentLibrary,
                        CurrentLibraryFolder = list.RootFolder,

                        CurrentList = (list as SPDocumentLibrary != null) ? null : list,
                        CurrentListItem = null,
                    };

                    action(folderModelHost);
                }
                else if (typeof(PageDefinitionBase).IsAssignableFrom(childModelType))
                {
                    var folderModelHost = new FolderModelHost
                    {
                        CurrentLibrary = list as SPDocumentLibrary,
                        CurrentLibraryFolder = list.RootFolder,

                        CurrentList = (list as SPDocumentLibrary != null) ? null : list,
                        CurrentListItem = null,
                    };

                    action(folderModelHost);
                }

                else
                {
                    action(listModelHost);
                }

                if (listModelHost.ShouldUpdateHost)
                    list.Update();
            }
            else
            {
                action(modelHost);
            }
        }