Beispiel #1
0
        //protected override void InternalOnAfterWebPartProvision(WebPartProcessingContext provisionContext)
        //{
        //    base.InternalOnAfterWebPartProvision(provisionContext);

        //    var webPartModel = provisionContext.WebPartDefinition;

        //    var listItemModelHost = provisionContext.ListItemModelHost;
        //    var wpModel = webPartModel.WithAssertAndCast<ListViewWebPartDefinition>("model", value => value.RequireNotNull());

        //    var webPartStoreKey = provisionContext.WebPartStoreKey;
        //    var context = provisionContext.ListItemModelHost.HostWeb.Context;

        //    var bindContext = LookupBindContext(listItemModelHost, wpModel);

        //    if (bindContext.TargetViewId.HasValue
        //        && bindContext.TargetViewId != default(Guid)
        //        && provisionContext.WebPartStoreKey.HasValue
        //        && provisionContext.WebPartStoreKey.Value != default(Guid))
        //    {
        //        var list = LookupList(listItemModelHost, wpModel);

        //        var srcView = list.Views.GetById(bindContext.TargetViewId.Value);
        //        var hiddenView = list.Views.GetById(provisionContext.WebPartStoreKey.Value);

        //        context.Load(srcView, s => s.ViewFields);

        //        context.Load(srcView, s => s.RowLimit);
        //        context.Load(srcView, s => s.ViewQuery);
        //        context.Load(srcView, s => s.JSLink);

        //        context.Load(srcView, s => s.IncludeRootFolder);
        //        context.Load(srcView, s => s.Scope);

        //        context.Load(hiddenView);

        //        context.ExecuteQueryWithTrace();

        //        hiddenView.ViewFields.RemoveAll();

        //        foreach (var f in srcView.ViewFields)
        //            hiddenView.ViewFields.Add(f);


        //        hiddenView.RowLimit = srcView.RowLimit;
        //        hiddenView.ViewQuery = srcView.ViewQuery;
        //        hiddenView.JSLink = srcView.JSLink;

        //        hiddenView.IncludeRootFolder = srcView.IncludeRootFolder;
        //        hiddenView.Scope = srcView.Scope;

        //        hiddenView.Update();
        //        context.ExecuteQueryWithTrace();
        //    }
        //}

        private List LookupList(ListItemModelHost listItemModelHost, ListViewWebPartDefinition wpModel)
        {
            var web     = listItemModelHost.HostWeb;
            var context = listItemModelHost.HostWeb.Context;

            List list = null;

            if (!string.IsNullOrEmpty(wpModel.ListUrl))
            {
                list = web.QueryAndGetListByUrl(wpModel.ListUrl);
            }
            else if (!string.IsNullOrEmpty(wpModel.ListTitle))
            {
                list = web.Lists.GetByTitle(wpModel.ListTitle);
            }
            else if (wpModel.ListId != default(Guid))
            {
                list = web.Lists.GetById(wpModel.ListId.Value);
            }
            else
            {
                throw new SPMeta2Exception("ListUrl, ListTitle or ListId should be defined.");
            }

            return(list);
        }
        protected override string GetWebpartXmlDefinition(ListItemModelHost listItemModelHost, WebPartDefinitionBase webPartModel)
        {
            var definition = webPartModel.WithAssertAndCast <PageViewerWebPartDefinition>("model", value => value.RequireNotNull());
            var wpXml      = WebpartXmlExtensions
                             .LoadWebpartXmlDocument(BuiltInWebPartTemplates.PageViewerWebPart);

            if (!string.IsNullOrEmpty(definition.ContentLink))
            {
                var contentLinkValue = definition.ContentLink ?? string.Empty;

                TraceService.VerboseFormat((int)LogEventId.ModelProvisionCoreCall, "Original contentLinkValue: [{0}]", contentLinkValue);

                contentLinkValue = TokenReplacementService.ReplaceTokens(new TokenReplacementContext
                {
                    Value   = contentLinkValue,
                    Context = listItemModelHost.HostClientContext
                }).Value;

                TraceService.VerboseFormat((int)LogEventId.ModelProvisionCoreCall, "Token replaced contentLinkValue: [{0}]", contentLinkValue);

                wpXml.SetOrUpdatePageViewerWebPartProperty("ContentLink", contentLinkValue);
            }

            if (!string.IsNullOrEmpty(definition.SourceType))
            {
                wpXml.SetOrUpdatePageViewerWebPartProperty("SourceType", definition.SourceType);
            }

            return(wpXml.ToString());
        }
Beispiel #3
0
        protected override string GetWebpartXmlDefinition(ListItemModelHost listItemModelHost, WebPartDefinitionBase webPartModel)
        {
            if (!listItemModelHost.HostWeb.IsObjectPropertyInstantiated("Id"))
            {
                var webContext = listItemModelHost.HostWeb.Context;
                webContext.Load(listItemModelHost.HostWeb, w => w.Id);
                webContext.ExecuteQueryWithTrace();
            }

            var webId   = listItemModelHost.HostWeb.Id.ToString();
            var wpModel = webPartModel.WithAssertAndCast <ClientWebPartDefinition>("model", value => value.RequireNotNull());

            // Enhance 'ClientWebPart' provision - ProductWebId should be current web by default #623
            // https://github.com/SubPointSolutions/spmeta2/issues/623
            var productId = wpModel.ProductId;

            if (!productId.HasGuidValue())
            {
                productId = listItemModelHost.HostWeb.Id;
            }

            var wpXml = WebpartXmlExtensions
                        .LoadWebpartXmlDocument(BuiltInWebPartTemplates.ClientWebPart)
                        .SetOrUpdateProperty("FeatureId", wpModel.FeatureId.ToString())
                        .SetOrUpdateProperty("ProductId", productId.ToString())
                        .SetOrUpdateProperty("WebPartName", wpModel.WebPartName)
                        .SetOrUpdateProperty("ProductWebId", webId)
                        .ToString();

            return(wpXml);
        }
Beispiel #4
0
        protected override void OnBeforeDeploy(ListItemModelHost host, WebPartDefinitionBase webpart)
        {
            base.OnBeforeDeploy(host, webpart);

            // pre-load web id
            if (!host.HostWeb.IsPropertyAvailable("Id"))
            {
                host.HostWeb.Context.Load(host.HostWeb, w => w.Id);
                host.HostWeb.Context.ExecuteQueryWithTrace();
            }

            var context = host.HostClientContext;
            var wpModel = webpart.WithAssertAndCast <ListViewWebPartDefinition>("model", value => value.RequireNotNull());

            // save the old default view ID, then restore in OnAfterDeploy
            _currentListBindContext = XsltListViewWebPartModelHandler.LookupBindContext(host,
                                                                                        wpModel.WebUrl, wpModel.WebId,
                                                                                        wpModel.ListUrl, wpModel.ListTitle, wpModel.ListId,
                                                                                        wpModel.ViewUrl, wpModel.ViewName, wpModel.ViewId,
                                                                                        wpModel.TitleUrl);

            if (_currentListBindContext.TargetView != null)
            {
                _currentListBindContext.TargetView.DefaultView = true;
                _currentListBindContext.TargetView.Update();

                context.ExecuteQueryWithTrace();
            }
        }
 private static List LookupList(ListItemModelHost listItemModelHost, XsltListViewWebPartDefinition wpModel)
 {
     return(LookupList(listItemModelHost.HostWeb,
                       wpModel.ListUrl,
                       wpModel.ListTitle,
                       wpModel.ListId));
 }
        protected override string GetWebpartXmlDefinition(
            ListItemModelHost listItemModelHost,
            WebPartDefinitionBase webPartModel)
        {
            var typedDefinition = webPartModel.WithAssertAndCast <SilverlightWebPartDefinition>("model", value => value.RequireNotNull());
            var wpXml           = WebpartXmlExtensions.LoadWebpartXmlDocument(this.ProcessCommonWebpartProperties(BuiltInWebPartTemplates.SilverlightWebPart, webPartModel));

            if (!string.IsNullOrEmpty(typedDefinition.Url))
            {
                var linkValue = typedDefinition.Url;

                TraceService.VerboseFormat((int)LogEventId.ModelProvisionCoreCall, "Original Url: [{0}]", linkValue);

                linkValue = TokenReplacementService.ReplaceTokens(new TokenReplacementContext
                {
                    Value   = linkValue,
                    Context = listItemModelHost
                }).Value;

                TraceService.VerboseFormat((int)LogEventId.ModelProvisionCoreCall, "Token replaced Url: [{0}]", linkValue);

                wpXml.SetOrUpdateProperty("Url", linkValue);
            }

            if (!string.IsNullOrEmpty(typedDefinition.CustomInitParameters))
            {
                wpXml.SetOrUpdateProperty("CustomInitParameters", typedDefinition.CustomInitParameters);
            }

            return(wpXml.ToString());
        }
        protected override string GetWebpartXmlDefinition(ListItemModelHost listItemModelHost, WebPartDefinitionBase webPartModel)
        {
            var typedModel = webPartModel.WithAssertAndCast <ContentEditorWebPartDefinition>("model", value => value.RequireNotNull());

            var wpXml = WebpartXmlExtensions.LoadWebpartXmlDocument(BuiltInWebPartTemplates.ContentEditorWebPart);

            if (!string.IsNullOrEmpty(typedModel.Content))
            {
                wpXml.SetOrUpdateContentEditorWebPartProperty("Content", typedModel.Content, true);
            }

            if (!string.IsNullOrEmpty(typedModel.ContentLink))
            {
                var urlValue = typedModel.ContentLink ?? string.Empty;

                TraceService.VerboseFormat((int)LogEventId.ModelProvisionCoreCall, "Original value: [{0}]", urlValue);

                urlValue = TokenReplacementService.ReplaceTokens(new TokenReplacementContext
                {
                    Value   = urlValue,
                    Context = listItemModelHost
                }).Value;

                TraceService.VerboseFormat((int)LogEventId.ModelProvisionCoreCall, "Token replaced value: [{0}]", urlValue);

                wpXml.SetOrUpdateContentEditorWebPartProperty("ContentLink", urlValue);
            }

            return(wpXml.ToString());
        }
        public override void WithResolvingModelHost(object modelHost, DefinitionBase model, Type childModelType, Action <object> action)
        {
            var listModeHost  = modelHost.WithAssertAndCast <ListModelHost>("modelHost", value => value.RequireNotNull());
            var listItemModel = model.WithAssertAndCast <ListItemDefinition>("model", value => value.RequireNotNull());

            List   list       = null;
            Folder rootFolder = null;

            if (modelHost is ListModelHost)
            {
                list       = (modelHost as ListModelHost).HostList;
                rootFolder = (modelHost as ListModelHost).HostList.RootFolder;

                if (!rootFolder.IsPropertyAvailable("ServerRelativeUrl"))
                {
                    rootFolder.Context.Load(rootFolder, f => f.ServerRelativeUrl);
                    rootFolder.Context.ExecuteQueryWithTrace();
                }
            }
            else if (modelHost is FolderModelHost)
            {
                list       = (modelHost as FolderModelHost).CurrentList;
                rootFolder = (modelHost as FolderModelHost).CurrentListItem.Folder;

                if (!rootFolder.IsPropertyAvailable("ServerRelativeUrl"))
                {
                    rootFolder.Context.Load(rootFolder, f => f.ServerRelativeUrl);
                    rootFolder.Context.ExecuteQueryWithTrace();
                }
            }

            var item    = EnsureListItem(list, rootFolder, listItemModel);
            var context = list.Context;

            // naaaaah, just gonna get a new one list item
            // keep it simple and safe, really really really safe with all that SharePoint stuff...
            // var currentItem = list.GetItemById(item.Id);

            //context.Load(currentItem);
            //context.ExecuteQueryWithTrace();

            if (childModelType == typeof(ListItemFieldValueDefinition) ||
                childModelType == typeof(ListItemFieldValuesDefinition))
            {
                var listItemPropertyHost = new ListItemModelHost
                {
                    HostListItem = item
                };

                action(listItemPropertyHost);
            }
            else
            {
                action(item);
            }

            item.Update();
            context.ExecuteQueryWithTrace();
        }
Beispiel #9
0
        protected File GetCurrentPageFile(ListItemModelHost listItemModelHost)
        {
            var listItem = listItemModelHost.HostListItem;
            var filePath = listItem["FileRef"].ToString();

            var web = listItem.ParentList.ParentWeb;

            return(web.GetFileByServerRelativeUrl(filePath));
        }
Beispiel #10
0
        protected File GetCurrentPageFile(ListItemModelHost listItemModelHost)
        {
            if (listItemModelHost.HostFile != null)
            {
                return(listItemModelHost.HostFile);
            }

            return(listItemModelHost.HostListItem.File);
        }
 internal static ListBindContext LookupBindContext(ListItemModelHost listItemModelHost,
                                                   XsltListViewWebPartDefinition wpModel)
 {
     return(LookupBindContext(listItemModelHost,
                              wpModel.WebUrl, wpModel.WebId,
                              wpModel.ListUrl, wpModel.ListTitle, wpModel.ListId,
                              wpModel.ViewName, wpModel.ViewId,
                              wpModel.TitleUrl));
 }
Beispiel #12
0
        protected override string GetWebpartXmlDefinition(ListItemModelHost listItemModelHost, WebPartDefinitionBase webPartModel)
        {
            var wpModel = webPartModel.WithAssertAndCast <SiteFeedWebPartDefinition>("model", value => value.RequireNotNull());
            var wpXml   = WebpartXmlExtensions
                          .LoadWebpartXmlDocument(BuiltInWebPartTemplates.SiteFeedWebPart)
                          .ToString();

            return(wpXml);
        }
Beispiel #13
0
        private ListBindContext LookupBindContext(ListItemModelHost listItemModelHost, XsltListViewWebPartDefinition wpModel)
        {
            var result = new ListBindContext
            {
            };

            var web     = listItemModelHost.HostWeb;
            var context = listItemModelHost.HostWeb.Context;

            var list = LookupList(listItemModelHost, wpModel);

            View view = null;

            if (wpModel.ViewId.HasValue && wpModel.ViewId != default(Guid))
            {
                view = list.Views.GetById(wpModel.ViewId.Value);
            }
            else if (!string.IsNullOrEmpty(wpModel.ViewName))
            {
                view = list.Views.GetByTitle(wpModel.ViewName);
            }

            context.Load(list, l => l.Id);
            context.Load(list, l => l.DefaultViewUrl);
            context.Load(list, l => l.Title);
            context.Load(list, l => l.DefaultView);

            if (view != null)
            {
                context.Load(view);
                context.ExecuteQueryWithTrace();

                result.OriginalView   = list.DefaultView;
                result.OriginalViewId = list.DefaultView.Id;

                result.TargetView   = view;
                result.TargetViewId = view.Id;

                result.TitleUrl = view.ServerRelativeUrl;
            }
            else
            {
                context.ExecuteQueryWithTrace();
            }

            result.ListId = list.Id;

            if (wpModel.TitleUrl == null)
            {
                if (string.IsNullOrEmpty(result.TitleUrl))
                {
                    result.TitleUrl = list.DefaultViewUrl;
                }
            }

            return(result);
        }
Beispiel #14
0
        public override void WithResolvingModelHost(ModelHostResolveContext modelHostContext)
        {
            var modelHost      = modelHostContext.ModelHost;
            var model          = modelHostContext.Model;
            var childModelType = modelHostContext.ChildModelType;
            var action         = modelHostContext.Action;


            var folderHost = modelHost.WithAssertAndCast <FolderModelHost>("modelHost", value => value.RequireNotNull());
            var moduleFile = model.WithAssertAndCast <ModuleFileDefinition>("model", value => value.RequireNotNull());

            var web     = folderHost.CurrentWeb;
            var file    = ProcessFile(folderHost, moduleFile);
            var context = file.Context;

            if (childModelType == typeof(ListItemFieldValueDefinition))
            {
                var fileListItem = file.ListItemAllFields;

                context.Load(fileListItem, i => i.Id, i => i.ParentList);
                context.ExecuteQueryWithTrace();

                var list = fileListItem.ParentList;
                var item = list.GetItemById(fileListItem.Id);

                context.ExecuteQueryWithTrace();

                var listItemPropertyHost = new ListItemModelHost
                {
                    HostListItem = item
                };

                action(listItemPropertyHost);

                item.Update();

                context.ExecuteQueryWithTrace();
            }
            else if (childModelType == typeof(PropertyDefinition))
            {
                var propModelHost = new PropertyModelHost
                {
                    CurrentFile = file
                };

                action(propModelHost);

                context.ExecuteQueryWithTrace();
            }
            else
            {
                action(file);

                context.ExecuteQueryWithTrace();
            }
        }
        protected override string GetWebpartXmlDefinition(ListItemModelHost listItemModelHost, WebPartDefinitionBase webPartModel)
        {
            var wpModel = webPartModel.WithAssertAndCast <CommunityAdminWebPartDefinition>("model", value => value.RequireNotNull());
            var wpXml   = WebpartXmlExtensions
                          .LoadWebpartXmlDocument(BuiltInWebPartTemplates.CommunityAdminWebPart);

            // TODO, process XML

            return(wpXml.ToString());
        }
        protected override string GetWebpartXmlDefinition(ListItemModelHost listItemModelHost, WebPartDefinitionBase webPartModel)
        {
            var typedModel = webPartModel.WithAssertAndCast <MembersWebPartDefinition>("model", value => value.RequireNotNull());

            var wpXml = WebpartXmlExtensions.LoadWebpartXmlDocument(BuiltInWebPartTemplates.MembersWebPart);

            // TODO, specific XML processing

            return(wpXml.ToString());
        }
Beispiel #17
0
        protected override void OnBeforeDeploy(ListItemModelHost host, WebPartDefinitionBase webpart)
        {
            base.OnBeforeDeploy(host, webpart);

            // pre-load web id
            if (!host.HostWeb.IsPropertyAvailable("Id"))
            {
                host.HostWeb.Context.Load(host.HostWeb, w => w.Id);
                host.HostWeb.Context.ExecuteQueryWithTrace();
            }
        }
        protected override string GetWebpartXmlDefinition(ListItemModelHost listItemModelHost, WebPartDefinitionBase webPartModel)
        {
            var wpModel = webPartModel.WithAssertAndCast <ScriptEditorWebPartDefinition>("model", value => value.RequireNotNull());
            var wpXml   = WebpartXmlExtensions
                          .LoadWebpartXmlDocument(BuiltInWebPartTemplates.ScriptEditorWebPart)
                          //.SetOrUpdateProperty("Content", HttpUtility.HtmlEncode(wpModel.Content))
                          .SetOrUpdateProperty("Content", wpModel.Content, true)
                          .ToString();

            return(wpXml);
        }
        protected override string GetWebpartXmlDefinition(ListItemModelHost listItemModelHost, WebPartDefinitionBase webPartModel)
        {
            var wpModel     = webPartModel.WithAssertAndCast <XsltListViewWebPartDefinition>("model", value => value.RequireNotNull());
            var bindContext = LookupBindContext(listItemModelHost, wpModel);

            var wpXml = WebpartXmlExtensions.LoadWebpartXmlDocument(BuiltInWebPartTemplates.XsltListViewWebPart)
                        .SetListName(bindContext.ListId.ToString())
                        .SetListId(bindContext.ListId.ToString())
                        .SetTitleUrl(bindContext.TitleUrl)
                        .SetOrUpdateProperty("JSLink", wpModel.JSLink)
                        .ToString();

            return(wpXml);
        }
        protected override string GetWebpartXmlDefinition(ListItemModelHost listItemModelHost, WebPartDefinitionBase webPartModel)
        {
            throw new SPMeta2NotSupportedException("UserCode web part provision is not supported by CSOM (SP API limitations) - https://officespdev.uservoice.com/forums/224641-general/suggestions/7300326-add-support-for-spusercodewebpart-import-via-limit");

            var wpModel = webPartModel.WithAssertAndCast <UserCodeWebPartDefinition>("model", value => value.RequireNotNull());
            var wpXml   = WebpartXmlExtensions
                          .LoadWebpartXmlDocument(BuiltInWebPartTemplates.UserCodeWebPart)
                          .SetOrUpdateMetadataPropertyAttribute("type", "name", wpModel.AssemblyFullName)
                          .SetOrUpdateMetadataPropertyAttribute("Solution", "SolutionId", wpModel.SolutionId.ToString("D"))
                          //.SetOrUpdateMetadataPropertyAttribute("Solution", "xmlns", "http://schemas.microsoft.com/sharepoint/")
                          .ToString();

            return(wpXml);
        }
Beispiel #21
0
        protected override string GetWebpartXmlDefinition(ListItemModelHost listItemModelHost, WebPartDefinitionBase webPartModel)
        {
            var wpModel = webPartModel.WithAssertAndCast <ListViewWebPartDefinition>("model", value => value.RequireNotNull());

            var bindContext = LookupBindContext(listItemModelHost, wpModel);

            var wpXml = WebpartXmlExtensions.LoadWebpartXmlDocument(BuiltInWebPartTemplates.ListViewWebPart)
                        .SetOrUpdateListVieweWebPartProperty("ListName", bindContext.ListId.ToString("B"))
                        .SetOrUpdateListVieweWebPartProperty("ListId", bindContext.ListId.ToString("D").ToLower())
                        //.SetOrUpdateListVieweWebPartProperty("ViewGuid", bindContext.ViewId.ToString("D").ToLower())
                        .SetTitleUrl(bindContext.TitleUrl)
                        .ToString();

            return(wpXml);
        }
Beispiel #22
0
        private List LookupList(ListItemModelHost listItemModelHost,
                                XsltListViewWebPartDefinition wpModel
                                , out Guid webId)
        {
            var web     = listItemModelHost.HostWeb;
            var context = web.Context;

            if (wpModel.WebId.HasGuidValue() || !string.IsNullOrEmpty(wpModel.WebUrl))
            {
                web = new LookupFieldModelHandler()
                      .GetTargetWeb(listItemModelHost.HostClientContext.Site,
                                    wpModel.WebUrl, wpModel.WebId,
                                    listItemModelHost);

                webId = web.Id;
            }
            else
            {
                context.Load(web);
                context.Load(web, w => w.Id);

                context.ExecuteQueryWithTrace();


                webId = web.Id;
            }

            List list = null;

            if (!string.IsNullOrEmpty(wpModel.ListUrl))
            {
                list = web.QueryAndGetListByUrl(wpModel.ListUrl);
            }
            else if (!string.IsNullOrEmpty(wpModel.ListTitle))
            {
                list = web.Lists.GetByTitle(wpModel.ListTitle);
            }
            else if (wpModel.ListId != default(Guid))
            {
                list = web.Lists.GetById(wpModel.ListId.Value);
            }
            else
            {
                throw new SPMeta2Exception("ListUrl, ListTitle or ListId should be defined.");
            }

            return(list);
        }
        protected override void OnAfterDeploy(ListItemModelHost host, WebPartDefinitionBase webpart)
        {
            if (_currentListBindContext != null)
            {
                var context = host.HostClientContext;
                var wpModel = webpart.WithAssertAndCast <XsltListViewWebPartDefinition>("model", value => value.RequireNotNull());

                var bindingContext = LookupBindContext(host, wpModel);

                // reverting back the dafult view
                var view = bindingContext.List.GetView(_currentListBindContext.DefaultViewId);
                view.DefaultView = true;
                view.Update();

                context.ExecuteQueryWithTrace();
            }
        }
        protected override void OnBeforeDeploy(ListItemModelHost host, WebPartDefinitionBase webpart)
        {
            base.OnBeforeDeploy(host, webpart);

            var context = host.HostClientContext;
            var wpModel = webpart.WithAssertAndCast <XsltListViewWebPartDefinition>("model", value => value.RequireNotNull());

            // save the old default view ID, then restore in OnAfterDeploy
            _currentListBindContext = LookupBindContext(host, wpModel);

            if (_currentListBindContext.TargetView != null)
            {
                _currentListBindContext.TargetView.DefaultView = true;
                _currentListBindContext.TargetView.Update();

                context.ExecuteQueryWithTrace();
            }
        }
Beispiel #25
0
        protected override string GetWebpartXmlDefinition(ListItemModelHost listItemModelHost, WebPartDefinitionBase webPartModel)
        {
            var definition = webPartModel.WithAssertAndCast <RefinementScriptWebPartDefinition>("model", value => value.RequireNotNull());
            var xml        = WebpartXmlExtensions.LoadWebpartXmlDocument(ProcessCommonWebpartProperties(BuiltInWebPartTemplates.RefinementScriptWebPart, webPartModel));

            if (!string.IsNullOrEmpty(definition.SelectedRefinementControlsJson))
            {
                xml.SetOrUpdateProperty("SelectedRefinementControlsJson", definition.SelectedRefinementControlsJson);
            }

            if (!string.IsNullOrEmpty(definition.EmptyMessage))
            {
                xml.SetOrUpdateProperty("EmptyMessage", definition.EmptyMessage);
            }


            return(xml.ToString());
        }
Beispiel #26
0
        private ListBindContext LookupBindContext(ListItemModelHost listItemModelHost, XsltListViewWebPartDefinition wpModel)
        {
            var result = new ListBindContext
            {
            };

            var web     = listItemModelHost.HostWeb;
            var context = listItemModelHost.HostWeb.Context;

            List list = null;

            if (!string.IsNullOrEmpty(wpModel.ListUrl))
            {
                list = web.QueryAndGetListByUrl(wpModel.ListUrl);
            }
            else if (!string.IsNullOrEmpty(wpModel.ListTitle))
            {
                list = web.Lists.GetByTitle(wpModel.ListTitle);
            }
            else if (wpModel.ListId != default(Guid))
            {
                list = web.Lists.GetById(wpModel.ListId.Value);
            }
            else
            {
                throw new ArgumentException("ListUrl, ListTitle or ListId should be defined.");
            }

            context.Load(list, l => l.Id);
            context.Load(list, l => l.DefaultViewUrl);
            context.Load(list, l => l.Title);
            context.Load(list, l => l.DefaultView);

            context.ExecuteQueryWithTrace();

            result.ListId   = list.Id;
            result.TitleUrl = list.DefaultViewUrl;
            result.ViewId   = list.DefaultView.Id;

            return(result);
        }
Beispiel #27
0
        private void ProcessFieldValues(ListItemModelHost modelHost, ListItem listItem, ListItemFieldValuesDefinition fieldValues)
        {
            InvokeOnModelEvent(this, new ModelEventArgs
            {
                CurrentModelNode = null,
                Model            = null,
                EventType        = ModelEventType.OnProvisioning,
                Object           = listItem,
                ObjectType       = typeof(ListItem),
                ObjectDefinition = fieldValues,
                ModelHost        = modelHost
            });

            foreach (var fieldValue in fieldValues.Values)
            {
                if (!string.IsNullOrEmpty(fieldValue.FieldName))
                {
                    TraceService.VerboseFormat((int)LogEventId.ModelProvisionCoreCall,
                                               "Processing field value with Name: [{0}] and value: [{1}]",
                                               new object[]
                    {
                        fieldValue.FieldName,
                        fieldValue.Value
                    });

                    listItem[fieldValue.FieldName] = fieldValue.Value;
                }
            }

            InvokeOnModelEvent(this, new ModelEventArgs
            {
                CurrentModelNode = null,
                Model            = null,
                EventType        = ModelEventType.OnProvisioned,
                Object           = listItem,
                ObjectType       = typeof(ListItem),
                ObjectDefinition = fieldValues,
                ModelHost        = modelHost
            });
        }
Beispiel #28
0
        protected override string GetWebpartXmlDefinition(ListItemModelHost listItemModelHost, WebPartDefinitionBase webPartModel)
        {
            if (!listItemModelHost.HostWeb.IsObjectPropertyInstantiated("Id"))
            {
                var webContext = listItemModelHost.HostWeb.Context;
                webContext.Load(listItemModelHost.HostWeb, w => w.Id);
                webContext.ExecuteQueryWithTrace();
            }

            var webId = listItemModelHost.HostWeb.Id.ToString();

            var wpModel = webPartModel.WithAssertAndCast <ClientWebPartDefinition>("model", value => value.RequireNotNull());
            var wpXml   = WebpartXmlExtensions
                          .LoadWebpartXmlDocument(BuiltInWebPartTemplates.ClientWebPart)
                          .SetOrUpdateProperty("FeatureId", wpModel.FeatureId.ToString())
                          .SetOrUpdateProperty("ProductId", wpModel.ProductId.ToString())
                          .SetOrUpdateProperty("WebPartName", wpModel.WebPartName)
                          .SetOrUpdateProperty("ProductWebId", webId)
                          .ToString();

            return(wpXml);
        }
        protected override string GetWebpartXmlDefinition(ListItemModelHost listItemModelHost, WebPartDefinitionBase webPartModel)
        {
            var wpModel     = webPartModel.WithAssertAndCast <XsltListViewWebPartDefinition>("model", value => value.RequireNotNull());
            var bindContext = LookupBindContext(listItemModelHost, wpModel);

            var wpXml = WebpartXmlExtensions.LoadWebpartXmlDocument(BuiltInWebPartTemplates.XsltListViewWebPart)
                        .SetListName(bindContext.ListId.ToString())
                        .SetListId(bindContext.ListId.ToString())
                        .SetTitleUrl(bindContext.TitleUrl)
                        .SetJSLink(wpModel.JSLink);

            if (wpModel.CacheXslStorage.HasValue)
            {
                wpXml.SetOrUpdateProperty("CacheXslStorage", wpModel.CacheXslStorage.Value.ToString());
            }

            if (wpModel.CacheXslTimeOut.HasValue)
            {
                wpXml.SetOrUpdateProperty("CacheXslTimeOut", wpModel.CacheXslTimeOut.Value.ToString());
            }

            if (!string.IsNullOrEmpty(wpModel.BaseXsltHashKey))
            {
                wpXml.SetOrUpdateProperty("BaseXsltHashKey", wpModel.BaseXsltHashKey);
            }

            // xsl
            if (!string.IsNullOrEmpty(wpModel.Xsl))
            {
                wpXml.SetOrUpdateCDataProperty("Xsl", wpModel.Xsl);
            }

            if (!string.IsNullOrEmpty(wpModel.XslLink))
            {
                wpXml.SetOrUpdateProperty("XslLink", wpModel.XslLink);
            }

            if (!string.IsNullOrEmpty(wpModel.GhostedXslLink))
            {
                wpXml.SetOrUpdateProperty("GhostedXslLink", wpModel.GhostedXslLink);
            }

            // xml
            if (!string.IsNullOrEmpty(wpModel.XmlDefinition))
            {
                wpXml.SetOrUpdateCDataProperty("XmlDefinition", wpModel.XmlDefinition);
            }

            if (!string.IsNullOrEmpty(wpModel.XmlDefinitionLink))
            {
                wpXml.SetOrUpdateProperty("XmlDefinitionLink", wpModel.XmlDefinitionLink);
            }

#if !NET35
            if (wpModel.ShowTimelineIfAvailable.HasValue)
            {
                wpXml.SetOrUpdateProperty("ShowTimelineIfAvailable", wpModel.ShowTimelineIfAvailable.Value.ToString());
            }
#endif

            return(wpXml.ToString());
        }
        internal static ListBindContext LookupBindContext(ListItemModelHost listItemModelHost,
                                                          string webUrl, Guid?webId,
                                                          string listUrl, string listTitle, Guid?listId,
                                                          string viewTitle, Guid?viewId,
                                                          string webPartTitleUrl
                                                          )
        {
            var result = new ListBindContext
            {
            };

            var web     = listItemModelHost.HostWeb;
            var context = listItemModelHost.HostWeb.Context;

            var targetWeb = listItemModelHost.HostWeb;

            if (webId.HasGuidValue() || !string.IsNullOrEmpty(webUrl))
            {
                targetWeb = new LookupFieldModelHandler()
                            .GetTargetWeb(listItemModelHost.HostClientContext.Site,
                                          webUrl, webId);
            }

            var list = LookupList(targetWeb, listUrl, listTitle, listId);

            View view = null;

            if (viewId.HasValue && viewId != default(Guid))
            {
                view = list.Views.GetById(viewId.Value);
            }
            else if (!string.IsNullOrEmpty(viewTitle))
            {
                view = list.Views.GetByTitle(viewTitle);
            }

            context.Load(list, l => l.Id);
            context.Load(list, l => l.DefaultViewUrl);
            context.Load(list, l => l.Title);
            context.Load(list, l => l.DefaultView);

            if (view != null)
            {
                context.Load(view);
                context.ExecuteQueryWithTrace();

                result.OriginalView   = list.DefaultView;
                result.OriginalViewId = list.DefaultView.Id;

                result.TargetView   = view;
                result.TargetViewId = view.Id;

                result.TitleUrl = view.ServerRelativeUrl;
            }
            else
            {
                context.ExecuteQueryWithTrace();
            }

            result.ListId = list.Id;
            result.List   = list;

            if (webPartTitleUrl == null)
            {
                if (string.IsNullOrEmpty(result.TitleUrl))
                {
                    result.TitleUrl = list.DefaultViewUrl;
                }
            }

            result.DefaultViewId = list.DefaultView.Id;

            return(result);
        }