Exemplo n.º 1
0
        public static string GetServerRelativeUrl(this ListDefinition listDef, Web web)
        {
#pragma warning disable 618
            return(UrlUtility.CombineUrl(web.ServerRelativeUrl, listDef.GetListUrl()));

#pragma warning restore 618
        }
        //[SampleMetadataTag(Name = BuiltInTagNames.SampleHidden)]
        public void CanBindListViewWebPartByListViewTitle()
        {
            var incidentsLibrary = new ListDefinition
            {
                Title        = "Incidents library",
                Description  = "A document library.",
                TemplateType = BuiltInListTemplateTypeId.DocumentLibrary,
                Url          = "m2Incidents"
            };

            var incidentsView = new ListViewDefinition
            {
                Title  = "Last Incidents",
                Fields = new Collection <string>
                {
                    BuiltInInternalFieldNames.Edit,
                    BuiltInInternalFieldNames.ID,
                    BuiltInInternalFieldNames.FileLeafRef
                },
                RowLimit = 10
            };

            var listView = new ListViewWebPartDefinition
            {
                Title     = "Last Incidents binding by List View Title",
                Id        = "m2LastIncidentsView",
                ZoneIndex = 10,
                ZoneId    = "Main",
                ListUrl   = incidentsLibrary.GetListUrl(),
                ViewName  = incidentsView.Title
            };

            var webPartPage = new WebPartPageDefinition
            {
                Title              = "M2 List View provision",
                FileName           = "listview-webpart-provision.aspx",
                PageLayoutTemplate = BuiltInWebPartPageTemplates.spstd1
            };

            var model = SPMeta2Model.NewWebModel(web =>
            {
                web
                .AddList(incidentsLibrary, list =>
                {
                    list.AddListView(incidentsView);
                })
                .AddHostList(BuiltInListDefinitions.SitePages, list =>
                {
                    list.AddWebPartPage(webPartPage, page =>
                    {
                        page.AddListViewWebPart(listView);
                    });
                });
            });

            DeployModel(model);
        }
Exemplo n.º 3
0
        //[SampleMetadataTag(Name = BuiltInTagNames.SampleHidden)]
        public void CanDeploySimpleSP2013WorkflowSubscriptionToList()
        {
            var writeToHistoryListWorkflow = new SP2013WorkflowDefinition
            {
                DisplayName = "M2 - Write to history list",
                Override    = true,
                Xaml        = WorkflowTemplates.WriteToHistoryListWorkflow
            };

            var taskList = new ListDefinition
            {
                Title        = "Workflow Enabled List Tasks",
                TemplateType = BuiltInListTemplateTypeId.Tasks,
                Url          = "m2WorkflowEnabledListTasks"
            };

            var historyList = new ListDefinition
            {
                Title        = "Workflow Enabled List History",
                TemplateType = BuiltInListTemplateTypeId.WorkflowHistory,
                Url          = "m2WorkflowEnabledListHistory"
            };

            var workflowEnabledList = new ListDefinition
            {
                Title        = "Workflow Enabled List",
                Description  = "Workflow enabled list.",
                TemplateType = BuiltInListTemplateTypeId.GenericList,
                Url          = "WorkflowEnabledList"
            };

            var model = SPMeta2Model.NewWebModel(web =>
            {
                web
                .AddSP2013Workflow(writeToHistoryListWorkflow)
                .AddList(historyList)
                .AddList(taskList)
                .AddList(workflowEnabledList, list =>
                {
                    list
                    .AddSP2013WorkflowSubscription(new SP2013WorkflowSubscriptionDefinition
                    {
                        Name = "Write To History List Workflow",
                        WorkflowDisplayName = writeToHistoryListWorkflow.DisplayName,
                        HistoryListUrl      = historyList.GetListUrl(),
                        TaskListUrl         = taskList.GetListUrl()
                    });
                });
            });

            DeployModel(model);
        }
Exemplo n.º 4
0
        private static SPList GetListByUrl(SPWeb web, ListDefinition listModel)
        {
            SPList result;

            try
            {
                var targetListUrl = SPUrlUtility.CombineUrl(web.Url, listModel.GetListUrl());
                result = web.GetList(targetListUrl);
            }
            catch
            {
                result = null;
            }

            return(result);
        }
Exemplo n.º 5
0
        private static List LoadCurrentList(Web web, ListDefinition listModel)
        {
            var context = web.Context;

            List currentList = null;

#pragma warning disable 618
            var listUrl = UrlUtility.CombineUrl(web.ServerRelativeUrl, listModel.GetListUrl());
#pragma warning restore 618

            Folder folder = null;

            var scope = new ExceptionHandlingScope(context);

            using (scope.StartScope())
            {
                using (scope.StartTry())
                {
                    folder = web.GetFolderByServerRelativeUrl(listUrl);
                    context.Load(folder);
                }

                using (scope.StartCatch())
                {
                }
            }

            context.ExecuteQueryWithTrace();

            if (!scope.HasException && folder != null && folder.ServerObjectIsNull != true)
            {
                folder = web.GetFolderByServerRelativeUrl(listUrl);
                context.Load(folder.Properties);
                context.ExecuteQueryWithTrace();

                var listId = new Guid(folder.Properties["vti_listname"].ToString());
                var list   = web.Lists.GetById(listId);

                context.Load(list);
                context.ExecuteQueryWithTrace();

                currentList = list;
            }

            return(currentList);
        }
        //[SampleMetadataTag(Name = BuiltInTagNames.SampleHidden)]
        public void CanBindListViewWebPartToCalendarView()
        {
            var companyEvents = new ListDefinition
            {
                Title        = "Company Events",
                Description  = "A document library.",
                TemplateType = BuiltInListTemplateTypeId.Events,
                Url          = "m2CompanyEvents"
            };

            var webPartPage = new WebPartPageDefinition
            {
                Title              = "M2 List View provision",
                FileName           = "listview-webpart-provision.aspx",
                PageLayoutTemplate = BuiltInWebPartPageTemplates.spstd1
            };

            var listView = new ListViewWebPartDefinition
            {
                Title     = "Company Events by List View Title",
                Id        = "m2CompanyEvents",
                ZoneIndex = 10,
                ZoneId    = "Main",
                ListUrl   = companyEvents.GetListUrl(),
                ViewName  = "Calendar"
            };

            var model = SPMeta2Model.NewWebModel(web =>
            {
                web
                .AddList(companyEvents)
                .AddHostList(BuiltInListDefinitions.SitePages, list =>
                {
                    list.AddWebPartPage(webPartPage, page =>
                    {
                        page.AddListViewWebPart(listView);
                    });
                });
            });

            DeployModel(model);
        }
        //[SampleMetadataTag(Name = BuiltInTagNames.SampleHidden)]
        public void CanBindListViewWebPartByListUrl()
        {
            var annualReviewsLibrary = new ListDefinition
            {
                Title        = "Annual Reviews",
                Description  = "A document library.",
                TemplateType = BuiltInListTemplateTypeId.DocumentLibrary,
                Url          = "m2AnnualReviews"
            };

            var listView = new ListViewWebPartDefinition
            {
                Title     = "Annual Reviews Default View by List Url",
                Id        = "m2AnnualReviewsView",
                ZoneIndex = 10,
                ZoneId    = "Main",
                ListUrl   = annualReviewsLibrary.GetListUrl()
            };

            var webPartPage = new WebPartPageDefinition
            {
                Title              = "M2 List View provision",
                FileName           = "listview-webpart-provision.aspx",
                PageLayoutTemplate = BuiltInWebPartPageTemplates.spstd1
            };

            var model = SPMeta2Model.NewWebModel(web =>
            {
                web
                .AddList(annualReviewsLibrary)
                .AddHostList(BuiltInListDefinitions.SitePages, list =>
                {
                    list.AddWebPartPage(webPartPage, page =>
                    {
                        page.AddListViewWebPart(listView);
                    });
                });
            });

            DeployModel(model);
        }
Exemplo n.º 8
0
        private static List LoadCurrentList(Web web, ListDefinition listModel)
        {
            var context = web.Context;

            List currentList = null;

#pragma warning disable 618
            var listUrl = UrlUtility.CombineUrl(web.ServerRelativeUrl, listModel.GetListUrl());
#pragma warning restore 618

            Folder folder;

            var scope = new ExceptionHandlingScope(context);

            using (scope.StartScope())
            {
                using (scope.StartTry())
                {
                    folder = web.GetFolderByServerRelativeUrl(listUrl);
                    context.Load(folder);
                }

                using (scope.StartCatch())
                {
                }
            }

            context.ExecuteQueryWithTrace();

            if (!scope.HasException && folder != null && folder.ServerObjectIsNull != true)
            {
#if !NET35
                folder = web.GetFolderByServerRelativeUrl(listUrl);

                context.Load(folder.Properties);
                context.ExecuteQueryWithTrace();

                var listId = new Guid(folder.Properties["vti_listname"].ToString());
                var list   = web.Lists.GetById(listId);

                context.Load(list);

                if (listModel.IndexedRootFolderPropertyKeys.Any())
                {
                    context.Load(list, l => l.RootFolder.Properties);
                }

                context.ExecuteQueryWithTrace();

                currentList = list;
#endif

#if NET35
                // SP2010 CSOM hack
                // http://impl.com/questions/4284722/sharepoint-2010-client-object-model-get-a-list-item-from-a-url

                var listQuery = from list in web.Lists
                                where list.RootFolder.ServerRelativeUrl == listUrl
                                select list;

                var queryResult = context.LoadQuery(listQuery);
                context.ExecuteQueryWithTrace();

                var resultList = queryResult.FirstOrDefault();

                currentList = resultList;
#endif
            }

            return(currentList);
        }
Exemplo n.º 9
0
 public static string GetServerRelativeUrl(this ListDefinition listDef, Web web)
 {
     return(UrlUtility.CombineUrl(web.ServerRelativeUrl, listDef.GetListUrl()));
 }
Exemplo n.º 10
0
        private SPList GetOrCreateList(
            object modelHost,
            SPWeb web, ListDefinition listModel)
        {
            var result = GetListByUrl(web, listModel);

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

                var listId = default(Guid);

                // "SPBug", there are two ways to create lists
                // (1) by TemplateName (2) by TemplateType
                if (listModel.TemplateType > 0)
                {
                    TraceService.VerboseFormat((int)LogEventId.ModelProvisionCoreCall, "Creating list by TemplateType: [{0}]", listModel.TemplateType);

                    //listId = web.Lists.Add(listModel.Url, listModel.Description ?? string.Empty, (SPListTemplateType)listModel.TemplateType);
                    listId = web.Lists.Add(
                        listModel.Title,
                        listModel.Description ?? string.Empty,
                        listModel.GetListUrl(),
                        string.Empty,
                        (int)listModel.TemplateType,
                        string.Empty);
                }
                else if (!string.IsNullOrEmpty(listModel.TemplateName))
                {
                    TraceService.VerboseFormat((int)LogEventId.ModelProvisionCoreCall, "Creating list by TemplateName: [{0}]", listModel.TemplateName);

                    var listTemplate = web.ListTemplates
                                       .OfType <SPListTemplate>()
                                       .FirstOrDefault(t => t.InternalName == listModel.TemplateName);

                    //listId = web.Lists.Add(listModel.Url, listModel.Description ?? string.Empty, listTemplate);
                    listId = web.Lists.Add(
                        listModel.Title,
                        listModel.Description ?? string.Empty,
                        listModel.GetListUrl(),
                        listTemplate.FeatureId.ToString(),
                        (int)listTemplate.Type,
                        listTemplate.DocumentTemplate);
                }
                else
                {
                    throw new ArgumentException("TemplateType or TemplateName must be defined");
                }

                result = web.Lists[listId];

                InvokeOnModelEvent(this, new ModelEventArgs
                {
                    CurrentModelNode = null,
                    Model            = null,
                    EventType        = ModelEventType.OnProvisioning,
                    Object           = result,
                    ObjectType       = typeof(SPList),
                    ObjectDefinition = listModel,
                    ModelHost        = modelHost
                });
            }
            else
            {
                TraceService.Information((int)LogEventId.ModelProvisionProcessingExistingObject, "Processing existing list");

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

            return(result);
        }
 public static string GetServerRelativeUrl(this ListDefinition listDef, Web web)
 {
     return(web.ServerRelativeUrl + "/" + listDef.GetListUrl());
 }