예제 #1
0
        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(InformationRightsManagementSettings),
                ObjectDefinition = definition,
                ModelHost        = modelHost
            });

            MapInformationRightsManagementSettings(currentSettings, definition);

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

            currentSettings.Update();
        }
예제 #2
0
        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 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
            {
                // ??
            }
        }
예제 #4
0
        private Field DeployListField(ListModelHost modelHost, FieldDefinition fieldModel)
        {
            TraceService.Verbose((int)LogEventId.ModelProvisionCoreCall, "Deploying list field");

            var list    = modelHost.HostList;
            var context = list.Context;

            var scope = new ExceptionHandlingScope(context);

            Field field;

            using (scope.StartScope())
            {
                using (scope.StartTry())
                {
                    field = list.Fields.GetById(fieldModel.Id);
                    context.Load(field);
                }

                using (scope.StartCatch())
                {
                }
            }

            TraceService.Verbose((int)LogEventId.ModelProvisionCoreCall, "ExecuteQuery()");
            context.ExecuteQueryWithTrace();

            if (!scope.HasException)
            {
                field = list.Fields.GetById(fieldModel.Id);
                context.Load(field);

                TraceService.VerboseFormat((int)LogEventId.ModelProvisionCoreCall, "Found site list with Id: [{0}]", fieldModel.Id);
                TraceService.Verbose((int)LogEventId.ModelProvisionCoreCall, "ExecuteQuery()");

                context.ExecuteQueryWithTrace();

                return(EnsureField(context, field, list.Fields, fieldModel));
            }

            TraceService.VerboseFormat((int)LogEventId.ModelProvisionCoreCall, "Cannot find list field with Id: [{0}]", fieldModel.Id);
            return(EnsureField(context, null, list.Fields, fieldModel));
        }
예제 #5
0
        private void DeployNintexWorkflow(ListModelHost listModelHost, NintexWorkflowDefinition workflowDefinition)
        {
            var list = listModelHost.HostList;

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

            // TODO, add NintexWorkflowService web service ref

            //using (var nintexService = new NintexWorkflowService.NintexWorkflowWS())
            //{
            //    nintexService.Url = SPUrlUtility.CombineUrl(list.ParentWeb.Url, NintexUrls.WorkflowServiceUrl);
            //    nintexService.PreAuthenticate = true;
            //    nintexService.Credentials = System.Net.CredentialCache.DefaultCredentials;

            //    var xmlnw = Encoding.UTF8.GetString(workflowDefinition.WorkflowXml);

            //    var result = nintexService.PublishFromNWFXml(xmlnw, list.Title, workflowDefinition.WorkflowName, true);
            //}

            InvokeOnModelEvent(this, new ModelEventArgs
            {
                CurrentModelNode = null,
                Model            = null,
                EventType        = ModelEventType.OnProvisioned,
                Object           = workflowDefinition,
                ObjectType       = typeof(NintexWorkflowDefinition),
                ObjectDefinition = workflowDefinition,
                ModelHost        = list
            });
        }
예제 #6
0
 private void DeployListEventReceiver(object modelHost, ListModelHost listModelHost, EventReceiverDefinition definition)
 {
     DeployEventReceiver(modelHost, listModelHost.HostList.EventReceivers, definition);
 }
 private void ValidateListField(ListModelHost listModelHost, FieldDefinition fieldModel)
 {
     throw new SPMeta2NotImplementedException();
 }
예제 #8
0
 private void DeployListDependentLookup(object modelHost, ListModelHost listModelHost, DependentLookupFieldDefinition definition)
 {
     DeployDependentLookupField(modelHost, listModelHost.HostList.Fields, definition);
 }
예제 #9
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);
            }
        }
예제 #10
0
        private void DeploySettings(object modelHost, ListModelHost listHost, MetadataNavigationSettingsDefinition definition)
        {
            var list    = listHost.HostList;
            var context = list.Context;

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

            var needUpdate = false;

            // deploy
            var settings = GetCurrentSettings(list);

            // MetadataNavigationSettings Hierarchy missing Folders field #1064
            // https://github.com/SubPointSolutions/spmeta2/issues/1064
            // always ensure a top level NavigationHierarchies->FolderHierarchy->HideFoldersNode=false

            settings.EnsureDefaultFolderHierarchyNode();

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

                        context.Load(targetField);
                        context.ExecuteQueryWithTrace();

                        settings.AddConfiguredHierarchy(new MetadataNavigationHierarchyConfig
                        {
                            FieldId           = targetField.Id,
                            FieldType         = targetField.TypeAsString,
                            CachedDisplayName = targetField.Title,
                            CachedName        = targetField.InternalName
                        });
                    }
                }

                needUpdate = true;
            }

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

                        context.Load(targetField);
                        context.ExecuteQueryWithTrace();

                        settings.AddConfiguredKeyFilter(new MetadataNavigationKeyFilterConfig
                        {
                            FieldId           = targetField.Id,
                            FieldType         = targetField.TypeAsString,
                            CachedDisplayName = targetField.Title,
                            CachedName        = targetField.InternalName
                        });
                    }
                }

                needUpdate = true;
            }

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

            if (needUpdate)
            {
                MetadataNavigationSettingsConfig.SetMetadataNavigationSettings(list, settings);
            }
        }
        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(List),
                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.GetById(h.FieldId.Value);

                        settings.AddConfiguredHierarchy(new MetadataNavigationHierarchyConfig(targetField.Id));
                    }
                }

                needUpdate = true;
            }

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

                        settings.AddConfiguredKeyFilter(new MetadataNavigationKeyFilterConfig(targetField.Id));
                    }
                }

                needUpdate = true;
            }

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


            if (needUpdate)
            {
                MetadataNavigationSettingsConfig.SetMetadataNavigationSettings(list, settings);
            }
        }
예제 #12
0
        private void DeployListWorkflowAssociationDefinition(ListModelHost modelHost, List list, WorkflowAssociationDefinition definition)
        {
            var context = list.Context;
            var existingWorkflowAssotiation = FindExistringWorkflowAssotiation(modelHost, definition);

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

            if (existingWorkflowAssotiation == null
                ||
                (existingWorkflowAssotiation.ServerObjectIsNull.HasValue &&
                 existingWorkflowAssotiation.ServerObjectIsNull.Value))
            {
                var workflowTemplate = GetWorkflowTemplate(modelHost, definition);

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

                var historyList = list.ParentWeb.QueryAndGetListByTitle(definition.HistoryListTitle);
                var taskList    = list.ParentWeb.QueryAndGetListByTitle(definition.TaskListTitle);

                var newWorkflowAssotiation = list.WorkflowAssociations.Add(new WorkflowAssociationCreationInformation
                {
                    Name        = definition.Name,
                    Template    = workflowTemplate,
                    HistoryList = historyList,
                    TaskList    = taskList
                });

                MapProperties(definition, newWorkflowAssotiation);

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

                newWorkflowAssotiation.Update();

                context.ExecuteQueryWithTrace();
            }
            else
            {
                MapProperties(definition, existingWorkflowAssotiation);

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

                existingWorkflowAssotiation.Update();
                context.ExecuteQueryWithTrace();
            }
        }
예제 #13
0
        public override void WithResolvingModelHost(ModelHostResolveContext modelHostContext)
        {
            var modelHost      = modelHostContext.ModelHost;
            var model          = modelHostContext.Model;
            var childModelType = modelHostContext.ChildModelType;
            var action         = modelHostContext.Action;

            // could either be web or list model host
            // https://github.com/SubPointSolutions/spmeta2/issues/829

            SPWeb  web      = null;
            SPList hostList = null;

            if (modelHost is WebModelHost)
            {
                web = (modelHost as WebModelHost).HostWeb;
            }
            else if (modelHost is ListModelHost)
            {
                web      = (modelHost as ListModelHost).HostList.ParentWeb;
                hostList = (modelHost as ListModelHost).HostList;
            }
            else
            {
                throw new SPMeta2UnsupportedModelHostException(
                          string.Format("Unsupported model host type:[{0}]", modelHost.GetType()));
            }

            var listDefinition = model as ListDefinition;

            if ((web != null || hostList != null) && listDefinition != null)
            {
                if (hostList == 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, SPListTemplateType.GenericList);
                        var tmpList   = web.Lists[tmpListId];

                        tmpList.Delete();
                    }
                    catch (Exception)
                    {
                    }
                }


#pragma warning disable 618
                var list = hostList ?? web.GetList(SPUtility.ConcatUrls(web.ServerRelativeUrl, listDefinition.GetListUrl()));
#pragma warning restore 618

                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);
            }
        }