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

            var webPartModel = provisionContext.WebPartDefinition;

            var listItemModelHost = provisionContext.ListItemModelHost;
            var wpModel           = webPartModel.WithAssertAndCast <XsltListViewWebPartDefinition>("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();
            }
        }
        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.ExecuteQuery();

                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.ExecuteQuery();
            }
        }
        protected override void InternalOnAfterWebPartProvision(WebPartProcessingContext provisionContext)
        {
            base.InternalOnAfterWebPartProvision(provisionContext);

            var webPartModel = provisionContext.WebPartDefinition;

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

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

            var bindContext = XsltListViewWebPartModelHandler.LookupBindContext(listItemModelHost,
                                    typedDefinition.WebUrl, typedDefinition.WebId,
                                    typedDefinition.ListUrl, typedDefinition.ListTitle, typedDefinition.ListId,
                                    typedDefinition.ViewName, typedDefinition.ViewId,
                                    typedDefinition.TitleUrl);

            if (provisionContext.WebPartStoreKey.HasValue
                && provisionContext.WebPartStoreKey.Value != default(Guid))
            {
                var targetWeb = listItemModelHost.HostWeb;

                if (typedDefinition.WebId.HasGuidValue() || !string.IsNullOrEmpty(typedDefinition.WebUrl))
                {
                    targetWeb = new LookupFieldModelHandler()
                                    .GetTargetWeb(this.CurrentClientContext.Site, typedDefinition.WebUrl, typedDefinition.WebId);
                }

                var list = XsltListViewWebPartModelHandler.LookupList(targetWeb, typedDefinition.ListUrl, typedDefinition.ListTitle, typedDefinition.ListId);
                var hiddenView = list.Views.GetById(provisionContext.WebPartStoreKey.Value);

                context.Load(hiddenView, s => s.HtmlSchemaXml);

                context.Load(hiddenView);
                context.ExecuteQueryWithTrace();

                // patching the toolbar value

                if (!string.IsNullOrEmpty(typedDefinition.Toolbar))
                {
                    var htmlSchemaXml = XDocument.Parse(hiddenView.HtmlSchemaXml);

                    var useShowAlwaysValue =
                        (typedDefinition.Toolbar.ToUpper() == BuiltInToolbarType.Standard.ToUpper())
                        && typedDefinition.ToolbarShowAlways.HasValue
                        && typedDefinition.ToolbarShowAlways.Value;

                    var toolbarNode = htmlSchemaXml.Root
                        .Descendants("Toolbar")
                        .FirstOrDefault();

                    if (toolbarNode == null)
                    {
                        toolbarNode = new XElement("Toolbar");
                        htmlSchemaXml.Root.Add(toolbarNode);
                    }

                    toolbarNode.SetAttributeValue("Type", typedDefinition.Toolbar);

                    if (useShowAlwaysValue)
                    {
                        toolbarNode.SetAttributeValue("ShowAlways", "TRUE");
                    }
                    else
                    {
                        XAttribute attr = toolbarNode.Attribute("ShowAlways");
                        if (attr != null && string.IsNullOrEmpty(attr.Value))
                            attr.Remove();
                    }

                    hiddenView.ListViewXml = htmlSchemaXml.Root.GetInnerXmlAsString();

                    hiddenView.Update();
                    context.ExecuteQueryWithTrace();
                }
            }
        }
        protected override void InternalOnAfterWebPartProvision(WebPartProcessingContext provisionContext)
        {
            base.InternalOnAfterWebPartProvision(provisionContext);

            var webPartModel = provisionContext.WebPartDefinition;

            var listItemModelHost = provisionContext.ListItemModelHost;
            var typedDefinition   = webPartModel.WithAssertAndCast <XsltListViewWebPartDefinition>("model", value => value.RequireNotNull());

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

            var bindContext = LookupBindContext(listItemModelHost, typedDefinition);

            if (provisionContext.WebPartStoreKey.HasValue &&
                provisionContext.WebPartStoreKey.Value != default(Guid))
            {
                var targetWeb = listItemModelHost.HostWeb;

                if (typedDefinition.WebId.HasGuidValue() || !string.IsNullOrEmpty(typedDefinition.WebUrl))
                {
                    targetWeb = new LookupFieldModelHandler()
                                .GetTargetWeb(this.CurrentClientContext.Site, typedDefinition.WebUrl, typedDefinition.WebId);
                }

                var list       = LookupList(targetWeb, typedDefinition.ListUrl, typedDefinition.ListTitle, typedDefinition.ListId);
                var hiddenView = list.Views.GetById(provisionContext.WebPartStoreKey.Value);

                context.Load(hiddenView, s => s.HtmlSchemaXml);

                context.Load(hiddenView);
                context.ExecuteQueryWithTrace();

                // always replace HtmlSchemaXml witjh the real view
                // some properties aren't coming with CSOM


                if (bindContext.OriginalView != null)
                {
                    var updatedSchemaXml  = XDocument.Parse(hiddenView.HtmlSchemaXml);
                    var originalSchemaXml = XDocument.Parse(bindContext.OriginalView.HtmlSchemaXml);

                    updatedSchemaXml.Root.ReplaceWith(originalSchemaXml.Root);

                    hiddenView.ListViewXml = updatedSchemaXml.Root.GetInnerXmlAsString();
                }

                if (!string.IsNullOrEmpty(typedDefinition.Toolbar))
                {
                    // work with the update schema XML
                    var htmlSchemaXml = XDocument.Parse(hiddenView.HtmlSchemaXml);

                    if (bindContext.OriginalView != null)
                    {
                        htmlSchemaXml = XDocument.Parse(bindContext.OriginalView.HtmlSchemaXml);
                    }

                    var useShowAlwaysValue =
                        (typedDefinition.Toolbar.ToUpper() == BuiltInToolbarType.Standard.ToUpper()) &&
                        typedDefinition.ToolbarShowAlways.HasValue &&
                        typedDefinition.ToolbarShowAlways.Value;

                    var toolbarNode = htmlSchemaXml.Root
                                      .Descendants("Toolbar")
                                      .FirstOrDefault();

                    if (toolbarNode == null)
                    {
                        toolbarNode = new XElement("Toolbar");
                        htmlSchemaXml.Root.Add(toolbarNode);
                    }

                    toolbarNode.SetAttributeValue("Type", typedDefinition.Toolbar);

                    if (useShowAlwaysValue)
                    {
                        toolbarNode.SetAttributeValue("ShowAlways", "TRUE");
                    }
                    else
                    {
                        XAttribute attr = toolbarNode.Attribute("ShowAlways");
                        if (attr != null && string.IsNullOrEmpty(attr.Value))
                        {
                            attr.Remove();
                        }
                    }

                    hiddenView.ListViewXml = htmlSchemaXml.Root.GetInnerXmlAsString();
                }

                hiddenView.Update();
                context.ExecuteQueryWithTrace();
            }
        }
Beispiel #5
0
        protected virtual void InternalOnAfterWebPartProvision(WebPartProcessingContext context)
        {

        }
Beispiel #6
0
 protected virtual void InternalOnAfterWebPartProvision(WebPartProcessingContext context)
 {
 }
        protected override void InternalOnAfterWebPartProvision(WebPartProcessingContext provisionContext)
        {
            base.InternalOnAfterWebPartProvision(provisionContext);

            var webPartModel = provisionContext.WebPartDefinition;

            var listItemModelHost = provisionContext.ListItemModelHost;
            var typedDefinition   = webPartModel.WithAssertAndCast <XsltListViewWebPartDefinition>("model", value => value.RequireNotNull());

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

            var bindContext = LookupBindContext(listItemModelHost, typedDefinition);

            if (provisionContext.WebPartStoreKey.HasValue &&
                provisionContext.WebPartStoreKey.Value != default(Guid))
            {
                var targetWeb = listItemModelHost.HostWeb;

                if (typedDefinition.WebId.HasGuidValue() || !string.IsNullOrEmpty(typedDefinition.WebUrl))
                {
                    var lookupFieldModelHandler = new LookupFieldModelHandler();

                    targetWeb = lookupFieldModelHandler.GetTargetWeb(
                        this.CurrentClientContext.Site,
                        typedDefinition.WebUrl,
                        typedDefinition.WebId,
                        provisionContext.ListItemModelHost);
                }

                var list       = LookupList(targetWeb, typedDefinition.ListUrl, typedDefinition.ListTitle, typedDefinition.ListId);
                var hiddenView = list.Views.GetById(provisionContext.WebPartStoreKey.Value);

                context.Load(hiddenView, s => s.HtmlSchemaXml);

                context.Load(hiddenView);
                context.ExecuteQueryWithTrace();

                // always replace HtmlSchemaXml witjh the real view
                // some properties aren't coming with CSOM

                if (bindContext.OriginalView != null)
                {
                    var updatedSchemaXml  = XDocument.Parse(hiddenView.HtmlSchemaXml);
                    var originalSchemaXml = XDocument.Parse(bindContext.OriginalView.HtmlSchemaXml);

                    updatedSchemaXml.Root.ReplaceWith(originalSchemaXml.Root);

#if !NET35
                    // updating inner xml definition for view
                    hiddenView.ListViewXml = updatedSchemaXml.Root.GetInnerXmlAsString();

                    // updating other attribute based properties, in the root node
                    // partly related to following issue
                    // List view scope does not apply in xslt list view webpart #1030
                    // https://github.com/SubPointSolutions/spmeta2/issues/1030

                    var scopeValue = updatedSchemaXml.Root.GetAttributeValue("Scope");

                    if (!string.IsNullOrEmpty(scopeValue))
                    {
                        hiddenView.Scope = (ViewScope)Enum.Parse(typeof(ViewScope), scopeValue);
                    }
#endif
                }

                if (!string.IsNullOrEmpty(typedDefinition.Toolbar))
                {
                    // work with the update schema XML
                    var htmlSchemaXml = XDocument.Parse(hiddenView.HtmlSchemaXml);

                    if (bindContext.OriginalView != null)
                    {
                        htmlSchemaXml = XDocument.Parse(bindContext.OriginalView.HtmlSchemaXml);
                    }

                    var useShowAlwaysValue =
                        (typedDefinition.Toolbar.ToUpper() == BuiltInToolbarType.Standard.ToUpper()) &&
                        typedDefinition.ToolbarShowAlways.HasValue &&
                        typedDefinition.ToolbarShowAlways.Value;

                    var toolbarNode = htmlSchemaXml.Root
                                      .Descendants("Toolbar")
                                      .FirstOrDefault();

                    if (toolbarNode == null)
                    {
                        toolbarNode = new XElement("Toolbar");
                        htmlSchemaXml.Root.Add(toolbarNode);
                    }

                    toolbarNode.SetAttributeValue("Type", typedDefinition.Toolbar);

                    if (useShowAlwaysValue)
                    {
                        toolbarNode.SetAttributeValue("ShowAlways", "TRUE");
                    }
                    else
                    {
                        XAttribute attr = toolbarNode.Attribute("ShowAlways");
                        if (attr != null && string.IsNullOrEmpty(attr.Value))
                        {
                            attr.Remove();
                        }
                    }

#if !NET35
                    hiddenView.ListViewXml = htmlSchemaXml.Root.GetInnerXmlAsString();
#endif
                }

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