Ejemplo n.º 1
0
        protected View FindView(List list, ListViewDefinition listViewModel)
        {
            // lookup by title
            var currentView = FindViewByTitle(list.Views, listViewModel.Title);

            // lookup by URL match
            if (currentView == null && !string.IsNullOrEmpty(listViewModel.Url))
            {
                TraceService.VerboseFormat((int)LogEventId.ModelProvisionCoreCall, "Resolving view by URL: [{0}]", listViewModel.Url);

                var safeUrl = listViewModel.Url.ToUpper();

                foreach (var view in list.Views)
                {
                    if (view.ServerRelativeUrl.ToUpper().EndsWith(safeUrl))
                    {
                        return view;
                    }
                }

                return null;
            }

            return currentView;
        }
Ejemplo n.º 2
0
        protected void ProcessView(object modelHost, SPList targetList, ListViewDefinition viewModel)
        {
            var currentView = targetList.Views.FindByName(viewModel.Title);

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

            if (currentView == null)
            {
                var viewFields = new StringCollection();
                viewFields.AddRange(viewModel.Fields.ToArray());

                // TODO, handle personal view creation
                currentView = targetList.Views.Add(viewModel.Title, viewFields,
                            viewModel.Query,
                            (uint)viewModel.RowLimit,
                            viewModel.IsPaged,
                            viewModel.IsDefault);
            }

            // viewModel.InvokeOnDeployingModelEvents<ListViewDefinition, SPView>(currentView);

            // if any fields specified, overwrite
            if (viewModel.Fields.Any())
            {
                currentView.ViewFields.DeleteAll();

                foreach (var viewField in viewModel.Fields)
                    currentView.ViewFields.Add(viewField);
            }

            // viewModel.InvokeOnModelUpdatedEvents<ListViewDefinition, SPView>(currentView);

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

            currentView.Update();
        }
        public override ModelNode ReverseSingleHost(object reverseHost, ReverseOptions options)
        {
            var list = (reverseHost as ListViewReverseHost).HostList;
            var item = (reverseHost as ListViewReverseHost).HostListView;

            if (!item.IsPropertyAvailable("Fields"))
            {
                item.Context.Load(item);
                item.Context.Load(item, i => i.ViewFields);

                item.Context.ExecuteQueryWithTrace();
            }

            var def = new ListViewDefinition();

            var xmlDoc = XDocument.Parse(item.ListViewXml);
            var viewXmlNode = xmlDoc.Descendants("View").First();

            var url = viewXmlNode.Attribute("Url")
                                  .Value
                                  .Split('/')
                                  .LastOrDefault();

            def.Title = item.Title;
            def.Url = url;



            def.Hidden = item.Hidden;

            def.IsDefault = item.DefaultView;
            def.IsPaged = item.Paged;

            def.Scope = item.Scope.ToString();

            def.RowLimit = (int)item.RowLimit;
            def.Query = item.ViewQuery;

            def.Type = viewXmlNode.Attribute("Type").Value;

            def.Fields = new System.Collections.ObjectModel.Collection<string>(
                item.ViewFields.ToArray()
                );

            return new ListViewModelNode
            {
                Options = { RequireSelfProcessing = true },
                Value = def
            };
        }
Ejemplo n.º 4
0
        public static ListViewDefinition GetListViewTestTemplate(string name, Action<ListViewDefinition> action)
        {
            var result = new ListViewDefinition
            {
                Title = string.Format("{0} test view {1}", name, Environment.TickCount),
                RowLimit = new Random(Environment.TickCount).Next(1, 100),
                IsPaged = Environment.TickCount % 2 == 0,
                IsDefault = Environment.TickCount % 2 == 0
            };

            if (action != null) action(result);

            return result;
        }
Ejemplo n.º 5
0
        protected SPView FindView(SPList targetList, ListViewDefinition listViewModel)
        {
            // lookup by title
            var currentView = targetList.Views.FindByName(listViewModel.Title);

            // lookup by URL match
            if (currentView == null && !string.IsNullOrEmpty(listViewModel.Url))
            {
                TraceService.VerboseFormat((int)LogEventId.ModelProvisionCoreCall, "Resolving view by URL: [{0}]", listViewModel.Url);

                var safeUrl = listViewModel.Url.ToUpper();
                currentView = targetList.Views.OfType<SPView>().FirstOrDefault(w => w.Url.ToUpper().EndsWith(safeUrl));
            }

            return currentView;
        }
        private static ModelNode GetTestModel()
        {
            var approvedDocuments = new ListViewDefinition
            {
                Title = "Approved Documents",
                Fields = new Collection<string>
            {
            BuiltInInternalFieldNames.ID,
            BuiltInInternalFieldNames.FileLeafRef
            }
            };

            var inProgressDocuments = new ListViewDefinition
            {
                Title = "In Progress Documents",
                Fields = new Collection<string>
            {
            BuiltInInternalFieldNames.ID,
            BuiltInInternalFieldNames.FileLeafRef
            }
            };

            var documentLibrary = new ListDefinition
            {
                Title = "CustomerDocuments",
                Description = "A customr document library.",
                TemplateType = BuiltInListTemplateTypeId.DocumentLibrary,
                Url = "CustomerDocuments"
            };

            var model = SPMeta2Model.NewWebModel(web =>
            {
                web.AddList(documentLibrary, list =>
                {
                    list.AddListView(approvedDocuments);
                    list.AddListView(inProgressDocuments);

                });
            });

            return model;
        }
Ejemplo n.º 7
0
        private void MapProperties(SPList targetList, SPView currentView, ListViewDefinition listViewModel)
        {
            // if any fields specified, overwrite
            if (listViewModel.Fields.Any())
            {
                currentView.ViewFields.DeleteAll();

                foreach (var viewField in listViewModel.Fields)
                    currentView.ViewFields.Add(viewField);
            }

            if (!string.IsNullOrEmpty(listViewModel.ViewData))
                currentView.ViewData = listViewModel.ViewData;

            if (!string.IsNullOrEmpty(listViewModel.Scope))
            {
                var scopeValue = ListViewScopeTypesConvertService.NormilizeValueToSSOMType(listViewModel.Scope);

                currentView.Scope = (SPViewScope)Enum.Parse(
                    typeof(SPViewScope), scopeValue);
            }

            // There is no value in setting Aggregations if AggregationsStatus is not to "On"
            if (!string.IsNullOrEmpty(listViewModel.AggregationsStatus) && listViewModel.AggregationsStatus == "On")
            {
                currentView.AggregationsStatus = listViewModel.AggregationsStatus;

                if (!string.IsNullOrEmpty(listViewModel.Aggregations))
                    currentView.Aggregations = listViewModel.Aggregations;
            }

            currentView.Hidden = listViewModel.Hidden;
            if (listViewModel.InlineEdit.HasValue)
            {
                currentView.InlineEdit = listViewModel.InlineEdit.Value.ToString(CultureInfo.InvariantCulture);
            }

            currentView.Title = listViewModel.Title;

            currentView.RowLimit = (uint)listViewModel.RowLimit;
            currentView.DefaultView = listViewModel.IsDefault;
            currentView.Paged = listViewModel.IsPaged;

            #if !NET35
            if (!string.IsNullOrEmpty(listViewModel.JSLink))
                currentView.JSLink = listViewModel.JSLink;
            #endif

            if (!string.IsNullOrEmpty(listViewModel.Query))
                currentView.Query = listViewModel.Query;

            if (listViewModel.DefaultViewForContentType.HasValue)
                currentView.DefaultViewForContentType = listViewModel.DefaultViewForContentType.Value;

            if (!string.IsNullOrEmpty(listViewModel.ContentTypeName))
                currentView.ContentTypeId = LookupListContentTypeByName(targetList, listViewModel.ContentTypeName);

            if (!string.IsNullOrEmpty(listViewModel.ContentTypeId))
                currentView.ContentTypeId = LookupListContentTypeById(targetList, listViewModel.ContentTypeId);

            if (listViewModel.ViewStyleId.HasValue)
            {
                var viewStyle = targetList.ParentWeb.ViewStyles.StyleByID(listViewModel.ViewStyleId.Value);
                currentView.ApplyStyle(viewStyle);
            }

            if (listViewModel.TabularView.HasValue)
            {
                currentView.TabularView = listViewModel.TabularView.Value;
            }
        }
        public void Deploy_ListsViews()
        {
            // Step 1, define lists
            var customerClaims = new ListDefinition
            {
                Title = "Customer claims",
                Url = "CustomerClaims",
                Description = "Stores customer related claims.",
                TemplateType = BuiltInListTemplateTypeId.DocumentLibrary
            };


            var lastTenClaims = new ListViewDefinition
            {
                Title = "Last 10 claims",
                IsDefault = false,
                RowLimit = 10,
                Query = string.Format("<OrderBy><FieldRef Name='{0}' Ascending='FALSE' /></OrderBy>", BuiltInInternalFieldNames.Created),
                Fields = new System.Collections.ObjectModel.Collection<string>
                {
                    BuiltInInternalFieldNames.ID,
                    BuiltInInternalFieldNames.File_x0020_Type,
                    BuiltInInternalFieldNames.FileLeafRef,
                    BuiltInInternalFieldNames.Created,
                    BuiltInInternalFieldNames.Modified,
                    BuiltInInternalFieldNames.Author,
                }
            };

            var lastTenEditedClaims = new ListViewDefinition
            {
                Title = "Last 10 edited claims",
                IsDefault = false,
                RowLimit = 10,
                Query = string.Format("<OrderBy><FieldRef Name='{0}' Ascending='FALSE' /></OrderBy>", BuiltInInternalFieldNames.Modified),
                Fields = new System.Collections.ObjectModel.Collection<string>
                {
                    BuiltInInternalFieldNames.ID,
                    BuiltInInternalFieldNames.File_x0020_Type,
                    BuiltInInternalFieldNames.FileLeafRef,
                    BuiltInInternalFieldNames.Created,
                    BuiltInInternalFieldNames.Modified,
                    BuiltInInternalFieldNames.Author,
                }
            };

            // Step 2, define web model and artifact relationships - add feature to the web 
            var model = SPMeta2Model
                             .NewWebModel(web =>
                             {
                                 web
                                   .AddList(customerClaims, list =>
                                   {
                                       list
                                           .AddView(lastTenClaims)
                                           .AddView(lastTenEditedClaims);
                                   });
                             });

            // Step 3, deploy model
            DeployWebModel(model);
        }
Ejemplo n.º 9
0
 protected virtual void ProcessLocalization(View obj, ListViewDefinition definition)
 {
     ProcessGenericLocalization(obj, new Dictionary<string, List<ValueForUICulture>>
     {
         { "TitleResource", definition.TitleResource }
     });
 }
Ejemplo n.º 10
0
        public virtual void MapListViewProperties(List list, View listView, ListViewDefinition definition)
        {
            if (definition.RowLimit > 0)
                listView.RowLimit = (uint)definition.RowLimit;

            listView.DefaultView = definition.IsDefault;
            listView.Paged = definition.IsPaged;

            if (!string.IsNullOrEmpty(definition.Query))
                listView.ViewQuery = definition.Query;

            if (definition.Fields != null && definition.Fields.Any())
            {
                listView.ViewFields.RemoveAll();

                foreach (var f in definition.Fields)
                    listView.ViewFields.Add(f);
            }

            if (!string.IsNullOrEmpty(definition.ViewData))
                listView.ViewData = definition.ViewData;

            if (!string.IsNullOrEmpty(definition.ContentTypeName))
                listView.ContentTypeId = LookupListContentTypeByName(list, definition.ContentTypeName);

            if (!string.IsNullOrEmpty(definition.ContentTypeId))
                listView.ContentTypeId = LookupListContentTypeById(list, definition.ContentTypeId);

            if (!string.IsNullOrEmpty(definition.JSLink))
                listView.JSLink = definition.JSLink;

            if (definition.DefaultViewForContentType.HasValue)
                listView.DefaultViewForContentType = definition.DefaultViewForContentType.Value;

            listView.Hidden = definition.Hidden;

            if (!string.IsNullOrEmpty(definition.Scope))
            {
                var scopeValue = ListViewScopeTypesConvertService.NormilizeValueToCSOMType(definition.Scope);

                listView.Scope = (ViewScope)Enum.Parse(
                    typeof(ViewScope), scopeValue);
            }

            listView.Title = definition.Title;
        }
Ejemplo n.º 11
0
 public static ModelNode AddHostView(this ModelNode model, ListViewDefinition definition, Action<ModelNode> action)
 {
     return model.AddDefinitionNodeWithOptions(definition, action, ModelNodeOptions.New().NoSelfProcessing());
 }
Ejemplo n.º 12
0
 public static ModelNode AddHostView(this ModelNode model, ListViewDefinition definition)
 {
     return AddHostView(model, definition, null);
 }
Ejemplo n.º 13
0
 public static ModelNode AddListView(this ModelNode model, ListViewDefinition definition, Action<ModelNode> action)
 {
     return model.AddDefinitionNode(definition, action);
 }
Ejemplo n.º 14
0
        protected void ProcessView(object modelHost, SPList targetList, ListViewDefinition listViewModel)
        {
            var currentView = FindView(targetList, listViewModel);

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

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

                var viewFields = new StringCollection();
                viewFields.AddRange(listViewModel.Fields.ToArray());

                // TODO, handle personal view creation
                currentView = targetList.Views.Add(
                            string.IsNullOrEmpty(listViewModel.Url) ? listViewModel.Title : GetSafeViewUrl(listViewModel.Url),
                            viewFields,
                            listViewModel.Query,
                            (uint)listViewModel.RowLimit,
                            listViewModel.IsPaged,
                            listViewModel.IsDefault);

                currentView.Title = listViewModel.Title;
            }
            else
            {
                TraceService.Information((int)LogEventId.ModelProvisionProcessingExistingObject, "Processing existing list view");
            }

            // viewModel.InvokeOnDeployingModelEvents<ListViewDefinition, SPView>(currentView);

            // if any fields specified, overwrite
            if (listViewModel.Fields.Any())
            {
                currentView.ViewFields.DeleteAll();

                foreach (var viewField in listViewModel.Fields)
                    currentView.ViewFields.Add(viewField);
            }

            currentView.Hidden = listViewModel.Hidden;
            currentView.Title = listViewModel.Title;
            currentView.RowLimit = (uint)listViewModel.RowLimit;
            currentView.DefaultView = listViewModel.IsDefault;
            currentView.Paged = listViewModel.IsPaged;

#if !NET35
            if (!string.IsNullOrEmpty(listViewModel.JSLink))
                currentView.JSLink = listViewModel.JSLink;
#endif

            if (!string.IsNullOrEmpty(listViewModel.Query))
                currentView.Query = listViewModel.Query;

            if (listViewModel.DefaultViewForContentType.HasValue)
                currentView.DefaultViewForContentType = listViewModel.DefaultViewForContentType.Value;

            if (!string.IsNullOrEmpty(listViewModel.ContentTypeName))
                currentView.ContentTypeId = LookupListContentTypeByName(targetList, listViewModel.ContentTypeName);

            if (!string.IsNullOrEmpty(listViewModel.ContentTypeId))
                currentView.ContentTypeId = LookupListContentTypeById(targetList, listViewModel.ContentTypeId);

            // viewModel.InvokeOnModelUpdatedEvents<ListViewDefinition, SPView>(currentView);

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

            TraceService.Verbose((int)LogEventId.ModelProvisionCoreCall, "Calling currentView.Update()");
            currentView.Update();
        }
Ejemplo n.º 15
0
        protected virtual void ProcessLocalization(SPView obj, ListViewDefinition definition)
        {

            if (definition.TitleResource.Any())
            {
#if !NET35
                foreach (var locValue in definition.TitleResource)
                    LocalizationService.ProcessUserResource(obj, obj.TitleResource, locValue);
#endif
            }

        }
Ejemplo n.º 16
0
        private void MapProperties(SPList targetList, SPView currentView, ListViewDefinition listViewModel)
        {
            // if any fields specified, overwrite
            if (listViewModel.Fields.Any())
            {
                currentView.ViewFields.DeleteAll();

                foreach (var viewField in listViewModel.Fields)
                    currentView.ViewFields.Add(viewField);
            }

            if (!string.IsNullOrEmpty(listViewModel.ViewData))
                currentView.ViewData = listViewModel.ViewData;

            if (!string.IsNullOrEmpty(listViewModel.Scope))
            {
                var scopeValue = ListViewScopeTypesConvertService.NormilizeValueToSSOMType(listViewModel.Scope);

                currentView.Scope = (SPViewScope)Enum.Parse(
                    typeof(SPViewScope), scopeValue);
            }

            currentView.Hidden = listViewModel.Hidden;
            currentView.Title = listViewModel.Title;
            currentView.RowLimit = (uint)listViewModel.RowLimit;
            currentView.DefaultView = listViewModel.IsDefault;
            currentView.Paged = listViewModel.IsPaged;

#if !NET35
            if (!string.IsNullOrEmpty(listViewModel.JSLink))
                currentView.JSLink = listViewModel.JSLink;
#endif

            if (!string.IsNullOrEmpty(listViewModel.Query))
                currentView.Query = listViewModel.Query;

            if (listViewModel.DefaultViewForContentType.HasValue)
                currentView.DefaultViewForContentType = listViewModel.DefaultViewForContentType.Value;

            if (!string.IsNullOrEmpty(listViewModel.ContentTypeName))
                currentView.ContentTypeId = LookupListContentTypeByName(targetList, listViewModel.ContentTypeName);

            if (!string.IsNullOrEmpty(listViewModel.ContentTypeId))
                currentView.ContentTypeId = LookupListContentTypeById(targetList, listViewModel.ContentTypeId);

            if (listViewModel.ViewStyleId.HasValue)
            {
                var viewStyle = targetList.ParentWeb.ViewStyles.StyleByID(listViewModel.ViewStyleId.Value);
                currentView.ApplyStyle(viewStyle);
            }
        }
Ejemplo n.º 17
0
        protected void ProcessView(object modelHost, SPList targetList, ListViewDefinition listViewModel)
        {
            var currentView = FindView(targetList, listViewModel);

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

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

                var viewFields = new StringCollection();
                viewFields.AddRange(listViewModel.Fields.ToArray());

                var isPersonalView = false;
                var viewType = (Microsoft.SharePoint.SPViewCollection.SPViewType)Enum.Parse(typeof(Microsoft.SharePoint.SPViewCollection.SPViewType),
                    string.IsNullOrEmpty(listViewModel.Type) ? BuiltInViewType.Html : listViewModel.Type);

                // TODO, handle personal view creation
                currentView = targetList.Views.Add(
                            string.IsNullOrEmpty(listViewModel.Url) ? listViewModel.Title : GetSafeViewUrl(listViewModel.Url),
                            viewFields,
                            listViewModel.Query,
                            (uint)listViewModel.RowLimit,
                            listViewModel.IsPaged,
                            listViewModel.IsDefault,
                            viewType,
                            isPersonalView);

                currentView.Title = listViewModel.Title;
            }
            else
            {
                TraceService.Information((int)LogEventId.ModelProvisionProcessingExistingObject, "Processing existing list view");
            }

            // viewModel.InvokeOnDeployingModelEvents<ListViewDefinition, SPView>(currentView);

            MapProperties(targetList, currentView, listViewModel);

            // viewModel.InvokeOnModelUpdatedEvents<ListViewDefinition, SPView>(currentView);

            ProcessLocalization(currentView, listViewModel);

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

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