Exemplo n.º 1
0
        protected override void ProcessWebpartProperties(WebPart webpartInstance, WebPartDefinition webpartModel)
        {
            base.ProcessWebpartProperties(webpartInstance, webpartModel);

            var typedWebpart = webpartInstance.WithAssertAndCast <PageViewerWebPart>("webpartInstance", value => value.RequireNotNull());
            var definition   = webpartModel.WithAssertAndCast <PageViewerWebPartDefinition>("webpartModel", value => value.RequireNotNull());

            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 = CurrentHost.PageListItem.Web
                }).Value;

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

                typedWebpart.ContentLink = contentLinkValue;
            }

            if (!string.IsNullOrEmpty(definition.SourceType))
            {
                typedWebpart.SourceType = (PathPattern)Enum.Parse(typeof(PathPattern), definition.SourceType);
            }
        }
        protected override void ProcessWebpartProperties(WebPart webpartInstance, WebPartDefinition webpartModel)
        {
            base.ProcessWebpartProperties(webpartInstance, webpartModel);

            var typedWebpart = webpartInstance.WithAssertAndCast<SilverlightWebPart>("webpartInstance", value => value.RequireNotNull());
            var typedDefinition = webpartModel.WithAssertAndCast<SilverlightWebPartDefinition>("webpartModel", value => value.RequireNotNull());

            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 = CurrentHost.HostFile.Web
                }).Value;

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

                typedWebpart.Url = linkValue;
            }

            if (!string.IsNullOrEmpty(typedDefinition.CustomInitParameters))
            {
                typedWebpart.CustomInitParameters = typedDefinition.CustomInitParameters;
            }
        }
Exemplo n.º 3
0
        protected virtual IEnumerable <ScriptDescriptor> GetScriptDescriptors()
        {
            ScriptControlDescriptor descriptor = new ScriptControlDescriptor("Sys.Preview.UI.Controls.WebParts.WebPartZone", ClientID);

            descriptor.AddProperty("uniqueId", UniqueID);
            descriptor.AddComponentProperty("webPartManager", BaseWebPartManager.ClientID);
            descriptor.AddProperty("allowLayoutChange", AllowLayoutChange);
            yield return(descriptor);

            AtlasWebPartChrome chrome = new AtlasWebPartChrome(this, BaseWebPartManager);

            System.Web.UI.WebControls.WebParts.WebPartCollection webParts = WebParts;
            for (int i = 0; i < webParts.Count; i++)
            {
                System.Web.UI.WebControls.WebParts.WebPart webPart = webParts[i];
                ScriptControlDescriptor wpDescriptor = new ScriptControlDescriptor("Sys.Preview.UI.Controls.WebParts.WebPart", chrome.GetWebPartChromeClientID(webPart));

                // Only render titleElement in xml-script if the titleElement was actually rendered
                // in the HTML by WebPartChrome.
                System.Web.UI.WebControls.WebParts.PartChromeType effectiveChromeType =
                    GetEffectiveChromeType(webPart);
                if (effectiveChromeType == System.Web.UI.WebControls.WebParts.PartChromeType.TitleOnly ||
                    effectiveChromeType == System.Web.UI.WebControls.WebParts.PartChromeType.TitleAndBorder)
                {
                    wpDescriptor.AddElementProperty("titleElement", chrome.GetWebPartTitleClientID(webPart));
                }

                wpDescriptor.AddComponentProperty("zone", ClientID);
                wpDescriptor.AddProperty("zoneIndex", i.ToString());
                wpDescriptor.AddProperty("allowZoneChange", webPart.AllowZoneChange);
                yield return(wpDescriptor);
            }
        }
        protected override void ProcessWebpartProperties(WebPart webpartInstance, WebPartDefinition webpartModel)
        {
            base.ProcessWebpartProperties(webpartInstance, webpartModel);

            var typedWebpart = webpartInstance.WithAssertAndCast <ListViewWebPart>("webpartInstance", value => value.RequireNotNull());
            var typedModel   = webpartModel.WithAssertAndCast <ListViewWebPartDefinition>("webpartModel", value => value.RequireNotNull());

            var    web  = _host.SPLimitedWebPartManager.Web;
            SPList list = null;

            if (typedModel.ListId.HasValue)
            {
                list = web.Lists[typedModel.ListId.Value];
            }
            else if (!string.IsNullOrEmpty(typedModel.ListUrl))
            {
                list = web.GetList(SPUrlUtility.CombineUrl(web.ServerRelativeUrl, typedModel.ListUrl));
            }
            else if (!string.IsNullOrEmpty(typedModel.ListTitle))
            {
                list = web.Lists.TryGetList(typedModel.ListTitle);
            }


            typedWebpart.ListName = list.ID.ToString();
            typedWebpart.ListId   = list.ID;
            typedWebpart.TitleUrl = list.DefaultViewUrl;
        }
        protected override void ProcessWebpartProperties(WebPart webpartInstance, WebPartDefinition webpartModel)
        {
            base.ProcessWebpartProperties(webpartInstance, webpartModel);

            var typedWebpart = webpartInstance.WithAssertAndCast <ContactFieldControl>("webpartInstance", value => value.RequireNotNull());
            var typedModel   = webpartModel.WithAssertAndCast <ContactFieldControlDefinition>("webpartModel", value => value.RequireNotNull());
        }
Exemplo n.º 6
0
        protected override void ProcessWebpartProperties(WebPart webpartInstance, WebPartDefinition webpartModel)
        {
            base.ProcessWebpartProperties(webpartInstance, webpartModel);

            var typedWebpart = webpartInstance.WithAssertAndCast<SPUserCodeWebPart>("webpartInstance", value => value.RequireNotNull());
            var typedModel = webpartModel.WithAssertAndCast<UserCodeWebPartDefinition>("webpartModel", value => value.RequireNotNull());


            // TODO
            typedWebpart.SolutionId = typedModel.SolutionId;
            typedWebpart.AssemblyFullName = typedModel.AssemblyFullName;
            typedWebpart.TypeFullName = typedModel.TypeFullName;

            foreach (var prop in typedModel.UserCodeProperties)
            {
                var currentProperty = typedWebpart.Properties
                    .OfType<SPUserCodeProperty>()
                    .FirstOrDefault(p => p.Name.ToUpper() == prop.Name.ToUpper());

                if (currentProperty == null)
                {
                    currentProperty = new SPUserCodeProperty();
                    currentProperty.Name = prop.Name;

                    typedWebpart.Properties.Add(currentProperty);
                }

                currentProperty.Value = prop.Value;
            }
        }
Exemplo n.º 7
0
        protected override void ProcessWebpartProperties(WebPart webpartInstance, WebPartDefinition webpartModel)
        {
            base.ProcessWebpartProperties(webpartInstance, webpartModel);

            var typedWebpart    = webpartInstance.WithAssertAndCast <SilverlightWebPart>("webpartInstance", value => value.RequireNotNull());
            var typedDefinition = webpartModel.WithAssertAndCast <SilverlightWebPartDefinition>("webpartModel", value => value.RequireNotNull());

            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 = CurrentHost.HostFile.Web
                }).Value;

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

                typedWebpart.Url = linkValue;
            }

            if (!string.IsNullOrEmpty(typedDefinition.CustomInitParameters))
            {
                typedWebpart.CustomInitParameters = typedDefinition.CustomInitParameters;
            }
        }
Exemplo n.º 8
0
        /// <summary>
        /// Add the web part to page.
        /// </summary>
        /// <param name="web">The web.</param>
        /// <param name="pageUrl">The page URL.</param>
        /// <param name="webPartName">Name of the web part.</param>
        /// <param name="zoneID">The zone ID.</param>
        /// <param name="zoneIndex">Index of the zone.</param>
        /// <returns></returns>
        public static string AddWebPartToPage(SPWeb web, string pageUrl, string webPartName, string zoneID, int zoneIndex, bool isHidden)
        {
            using (SPLimitedWebPartManager webPartManager = web.GetLimitedWebPartManager(
                       pageUrl, System.Web.UI.WebControls.WebParts.PersonalizationScope.Shared))
            {
                using (System.Web.UI.WebControls.WebParts.WebPart webPart = CreateWebPart(web, webPartName, webPartManager, isHidden))
                {
                    bool isExists = false;
                    foreach (System.Web.UI.WebControls.WebParts.WebPart wp in webPartManager.WebParts)
                    {
                        if (wp.Title.Equals(webPartName.Replace(".webpart", "")))
                        {
                            isExists = true;
                            break;
                        }
                        else
                        {
                            isExists = false;
                        }
                    }
                    if (!isExists)
                    {
                        webPartManager.AddWebPart(webPart, zoneID, zoneIndex);
                    }

                    return(webPart.ID);
                }
            }
        }
Exemplo n.º 9
0
        /// <summary>
        /// Creates the web part.
        /// </summary>
        /// <param name="web">The web.</param>
        /// <param nme="webPartName">Name of the web part.</param>
        /// <param name="webPartManager">The web part manager.</param>
        /// <returns></returns>
        public static System.Web.UI.WebControls.WebParts.WebPart CreateWebPart(SPWeb web, string webPartName, SPLimitedWebPartManager webPartManager, bool isHidden)
        {
            SPQuery qry = new SPQuery();

            qry.Query = String.Format(CultureInfo.CurrentCulture,
                                      "<Where><Eq><FieldRef Name='FileLeafRef'/><Value Type='File'>{0}</Value></Eq></Where>",
                                      webPartName);
            SPList webPartGallery = null;

            if (web.ParentWeb == null)
            {
                webPartGallery = web.GetCatalog(
                    SPListTemplateType.WebPartCatalog);
            }
            else
            {
                webPartGallery = web.Site.RootWeb.GetCatalog(
                    SPListTemplateType.WebPartCatalog);
            }

            SPListItemCollection webParts = webPartGallery.GetItems(qry);

            XmlReader xmlReader = new XmlTextReader(webParts[0].File.OpenBinaryStream());
            string    errorMsg;

            System.Web.UI.WebControls.WebParts.WebPart webPart = webPartManager.ImportWebPart(xmlReader, out errorMsg);
            webPart.Hidden = isHidden;

            return(webPart);
        }
        protected override void ProcessWebpartProperties(WebPart webpartInstance, WebPartDefinition webpartModel)
        {
            base.ProcessWebpartProperties(webpartInstance, webpartModel);

            var typedWebpart = webpartInstance.WithAssertAndCast<PageViewerWebPart>("webpartInstance", value => value.RequireNotNull());
            var definition = webpartModel.WithAssertAndCast<PageViewerWebPartDefinition>("webpartModel", value => value.RequireNotNull());

            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 = CurrentHost.HostFile.Web
                }).Value;

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

                typedWebpart.ContentLink = contentLinkValue;
            }

            if (!string.IsNullOrEmpty(definition.SourceType))
            {
                typedWebpart.SourceType = (PathPattern)Enum.Parse(typeof(PathPattern), definition.SourceType);
            }
        }
Exemplo n.º 11
0
        protected override void ProcessWebpartProperties(WebPart webpartInstance, WebPartDefinition webpartModel)
        {
            base.ProcessWebpartProperties(webpartInstance, webpartModel);

            var typedWebpart = webpartInstance.WithAssertAndCast <SPUserCodeWebPart>("webpartInstance", value => value.RequireNotNull());
            var typedModel   = webpartModel.WithAssertAndCast <UserCodeWebPartDefinition>("webpartModel", value => value.RequireNotNull());


            // TODO
            typedWebpart.SolutionId       = typedModel.SolutionId;
            typedWebpart.AssemblyFullName = typedModel.AssemblyFullName;
            typedWebpart.TypeFullName     = typedModel.TypeFullName;

            foreach (var prop in typedModel.UserCodeProperties)
            {
                var currentProperty = typedWebpart.Properties
                                      .OfType <SPUserCodeProperty>()
                                      .FirstOrDefault(p => p.Name.ToUpper() == prop.Name.ToUpper());

                if (currentProperty == null)
                {
                    currentProperty      = new SPUserCodeProperty();
                    currentProperty.Name = prop.Name;

                    typedWebpart.Properties.Add(currentProperty);
                }

                currentProperty.Value = prop.Value;
            }
        }
        protected override void ProcessWebpartProperties(WebPart webpartInstance, WebPartDefinition webpartModel)
        {
            base.ProcessWebpartProperties(webpartInstance, webpartModel);

            var typedWebpart = webpartInstance.WithAssertAndCast<ContactFieldControl>("webpartInstance", value => value.RequireNotNull());
            var typedModel = webpartModel.WithAssertAndCast<ContactFieldControlDefinition>("webpartModel", value => value.RequireNotNull());

        }
        protected override void ProcessWebpartProperties(WebPart webpartInstance, WebPartDefinition webpartModel)
        {
            base.ProcessWebpartProperties(webpartInstance, webpartModel);

            var typedWebpart = webpartInstance.WithAssertAndCast <ScriptEditorWebPart>("webpartInstance", value => value.RequireNotNull());
            var typedModel   = webpartModel.WithAssertAndCast <ScriptEditorWebPartDefinition>("webpartModel", value => value.RequireNotNull());

            typedWebpart.Content = typedModel.Content ?? string.Empty;
        }
        protected override void ProcessWebpartProperties(WebPart webpartInstance, WebPartDefinition webpartModel)
        {
            base.ProcessWebpartProperties(webpartInstance, webpartModel);

            var typedWebpart = webpartInstance.WithAssertAndCast <PictureLibrarySlideshowWebPart>("webpartInstance", value => value.RequireNotNull());
            var definition   = webpartModel.WithAssertAndCast <PictureLibrarySlideshowWebPartDefinition>("webpartModel", value => value.RequireNotNull());

            // TODO, specific provision
        }
        protected override void ProcessWebpartProperties(WebPart webpartInstance, WebPartDefinition webpartModel)
        {
            base.ProcessWebpartProperties(webpartInstance, webpartModel);

            var typedWebpart = webpartInstance.WithAssertAndCast<ScriptEditorWebPart>("webpartInstance", value => value.RequireNotNull());
            var typedModel = webpartModel.WithAssertAndCast<ScriptEditorWebPartDefinition>("webpartModel", value => value.RequireNotNull());

            typedWebpart.Content = typedModel.Content ?? string.Empty;
        }
        public override System.Web.UI.WebControls.WebParts.WebPart Instantiate()
        {
            string fileAsString;

            try
            {
                fileAsString = SPContext.Current.Site.RootWeb.GetFileAsString(this.dwpUrl);
            }
            catch (Exception ex)
            {
                SPDiagnosticsService.Local.WriteTrace(0, new SPDiagnosticsCategory(ex.Source, TraceSeverity.High, EventSeverity.Error), TraceSeverity.High, ex.Message, ex.Data);
                throw;
            }
            System.Web.UI.WebControls.WebParts.WebPart part = base.InstantiateFromXml(fileAsString);
            if (!string.IsNullOrEmpty(this.WebPartContent))
            {
                /*
                 * if (part is ContentEditorWebPart)
                 * {
                 *  ContentEditorWebPart part2 = part as ContentEditorWebPart;
                 *  XmlDocument document = new XmlDocument();
                 *  document.LoadXml("<Content></Content>");
                 *  document.DocumentElement.InnerText = this.WebPartContent;
                 *  part2.Content = document.DocumentElement;
                 *  part.ChromeType = PartChromeType.None;
                 *  return part;
                 * }
                 */
                if (!(part is SilverlightWebPart))
                {
                    return(part);
                }

                /*
                 * SilverlightWebPart slwp = part as SilverlightWebPart;
                 * if (this.WebPartContent.StartsWith("<"))
                 * {
                 *  SPExternalApplication appInfo = null;
                 *  try
                 *  {
                 *      appInfo = SPExternalApplication.ParseFromXml(this.WebPartContent);
                 *  }
                 *  catch (Exception)
                 *  {
                 *      throw new SPExternalApplicationRegistrationException(SPResource.GetString("InvalidApplicationXml", new object[0]));
                 *  }
                 *  slwp.ApplicationXml = SPExternalApplication.RemoveWebPartProperties(this.WebPartContent);
                 *  SetSilverlightWebPartPropsFromApplicationInfo(slwp, appInfo);
                 *  return part;
                 * }
                 * SPExternalApplication defaultValues = SPExternalApplication.GetDefaultValues();
                 * slwp.Url = this.WebPartContent;
                 * SetSilverlightWebPartPropsFromApplicationInfo(slwp, defaultValues);
                 */
            }
            return(part);
        }
Exemplo n.º 17
0
        protected override void ProcessWebpartProperties(WebPart webpartInstance, WebPartDefinition webpartModel)
        {
            base.ProcessWebpartProperties(webpartInstance, webpartModel);

            var typedWebpart = webpartInstance.WithAssertAndCast <BlogMonthQuickLaunch>("webpartInstance", value => value.RequireNotNull());
            var definition   = webpartModel.WithAssertAndCast <BlogMonthQuickLaunchDefinition>("webpartModel", value => value.RequireNotNull());

            // TODO, specific provision
        }
        protected override void ProcessWebpartProperties(WebPart webpartInstance, WebPartDefinition webpartModel)
        {
            base.ProcessWebpartProperties(webpartInstance, webpartModel);

            var typedWebpart = webpartInstance.WithAssertAndCast<UserDocsWebPart>("webpartInstance", value => value.RequireNotNull());
            var definition = webpartModel.WithAssertAndCast<UserDocsWebPartDefinition>("webpartModel", value => value.RequireNotNull());

            // TODO, specific provision
        }
Exemplo n.º 19
0
        protected override void ProcessWebpartProperties(WebPart webpartInstance, WebPartDefinition webpartModel)
        {
            base.ProcessWebpartProperties(webpartInstance, webpartModel);

            var typedWebpart = webpartInstance.WithAssertAndCast <ListViewWebPart>("webpartInstance", value => value.RequireNotNull());
            var typedModel   = webpartModel.WithAssertAndCast <ListViewWebPartDefinition>("webpartModel", value => value.RequireNotNull());

            var    web  = _host.SPLimitedWebPartManager.Web;
            SPList list = null;

            if (typedModel.ListId.HasGuidValue())
            {
                list = web.Lists[typedModel.ListId.Value];
            }
            else if (!string.IsNullOrEmpty(typedModel.ListUrl))
            {
                list = web.GetList(SPUrlUtility.CombineUrl(web.ServerRelativeUrl, typedModel.ListUrl));
            }
            else if (!string.IsNullOrEmpty(typedModel.ListTitle))
            {
                list = web.Lists.TryGetList(typedModel.ListTitle);
            }


            typedWebpart.ListName = list.ID.ToString();
            typedWebpart.ListId   = list.ID;

            // view check
            if (list != null)
            {
                SPView view = null;

                if (typedModel.ViewId.HasGuidValue())
                {
                    view = list.Views[typedModel.ViewId.Value];
                }
                else if (!string.IsNullOrEmpty(typedModel.ViewName))
                {
                    view = list.Views[typedModel.ViewName];
                }

                if (view != null)
                {
                    typedWebpart.ViewGuid = view.ID.ToString("B").ToUpperInvariant();
                    typedWebpart.TitleUrl = view.ServerRelativeUrl;
                }
            }

            // able to 'reset', if NULL or use list-view based URLs
            if (!string.IsNullOrEmpty(typedModel.TitleUrl))
            {
                typedWebpart.TitleUrl = typedModel.TitleUrl;
            }
        }
Exemplo n.º 20
0
        protected override void ProcessWebpartProperties(WebPart webpartInstance, WebPartDefinition webpartModel)
        {
            base.ProcessWebpartProperties(webpartInstance, webpartModel);

            var typedWebpart = webpartInstance.WithAssertAndCast <ListViewWebPart>("webpartInstance", value => value.RequireNotNull());
            var typedModel   = webpartModel.WithAssertAndCast <ListViewWebPartDefinition>("webpartModel", value => value.RequireNotNull());

            var web = _host.SPLimitedWebPartManager.Web;

            var targetWeb = web;

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

            var list = XsltListViewWebPartModelHandler.GetTargetList(targetWeb, typedModel.ListTitle, typedModel.ListUrl, typedModel.ListId);

            typedWebpart.ListName = list.ID.ToString();
            typedWebpart.ListId   = list.ID;

            // view check
            if (list != null)
            {
                SPView view = null;

                if (typedModel.ViewId.HasGuidValue())
                {
                    view = list.Views[typedModel.ViewId.Value];
                }
                else if (!string.IsNullOrEmpty(typedModel.ViewName))
                {
                    view = list.Views[typedModel.ViewName];
                }
                else if (!string.IsNullOrEmpty(typedModel.ViewUrl))
                {
                    view = list.Views.OfType <SPView>()
                           .FirstOrDefault(v => v.ServerRelativeUrl.ToUpper().EndsWith(typedModel.ViewUrl.ToUpper()));
                }

                if (view != null)
                {
                    typedWebpart.ViewGuid = view.ID.ToString("B").ToUpperInvariant();
                    typedWebpart.TitleUrl = view.ServerRelativeUrl;
                }
            }

            // able to 'reset', if NULL or use list-view based URLs
            if (!string.IsNullOrEmpty(typedModel.TitleUrl))
            {
                typedWebpart.TitleUrl = typedModel.TitleUrl;
            }
        }
Exemplo n.º 21
0
        protected override void ProcessWebpartProperties(WebPart webpartInstance, WebPartDefinition webpartModel)
        {
            base.ProcessWebpartProperties(webpartInstance, webpartModel);

            var typedWebpart = webpartInstance.WithAssertAndCast <ClientWebPart>("webpartInstance", value => value.RequireNotNull());
            var typedModel   = webpartModel.WithAssertAndCast <ClientWebPartDefinition>("webpartModel", value => value.RequireNotNull());

            typedWebpart.FeatureId    = typedModel.FeatureId;
            typedWebpart.ProductId    = typedModel.ProductId;
            typedWebpart.WebPartName  = typedModel.WebPartName;
            typedWebpart.ProductWebId = _host.SPLimitedWebPartManager.Web.ID;
        }
Exemplo n.º 22
0
        protected override void ProcessWebpartProperties(WebPart webpartInstance, WebPartDefinition webpartModel)
        {
            base.ProcessWebpartProperties(webpartInstance, webpartModel);

            var typedWebpart = webpartInstance.WithAssertAndCast<ClientWebPart>("webpartInstance", value => value.RequireNotNull());
            var typedModel = webpartModel.WithAssertAndCast<ClientWebPartDefinition>("webpartModel", value => value.RequireNotNull());

            typedWebpart.FeatureId = typedModel.FeatureId;
            typedWebpart.ProductId = typedModel.ProductId;
            typedWebpart.WebPartName = typedModel.WebPartName;
            typedWebpart.ProductWebId = _host.SPLimitedWebPartManager.Web.ID;
        }
        protected override void ProcessWebpartProperties(WebPart webpartInstance, WebPartDefinition webpartModel)
        {
            base.ProcessWebpartProperties(webpartInstance, webpartModel);

            var typedWebpart = webpartInstance.WithAssertAndCast<SiteFeedWebPart>("webpartInstance", value => value.RequireNotNull());
            var typedModel = webpartModel.WithAssertAndCast<SiteFeedWebPartDefinition>("webpartModel", value => value.RequireNotNull());

            //typedWebpart.ContentLink = typedModel.ContentLink ?? string.Empty;

            //var xmlDoc = new XmlDocument();
            //var xmlElement = xmlDoc.CreateElement("ContentElement");
            //xmlElement.InnerText = typedModel.Content ?? string.Empty;

            //typedWebpart.Content = xmlElement;
        }
Exemplo n.º 24
0
        protected override void ProcessWebpartProperties(WebPart webpartInstance, WebPartDefinition webpartModel)
        {
            base.ProcessWebpartProperties(webpartInstance, webpartModel);

            var typedWebpart = webpartInstance.WithAssertAndCast <SiteFeedWebPart>("webpartInstance", value => value.RequireNotNull());
            var typedModel   = webpartModel.WithAssertAndCast <SiteFeedWebPartDefinition>("webpartModel", value => value.RequireNotNull());

            //typedWebpart.ContentLink = typedModel.ContentLink ?? string.Empty;

            //var xmlDoc = new XmlDocument();
            //var xmlElement = xmlDoc.CreateElement("ContentElement");
            //xmlElement.InnerText = typedModel.Content ?? string.Empty;

            //typedWebpart.Content = xmlElement;
        }
Exemplo n.º 25
0
        protected override void ProcessWebpartProperties(WebPart webpartInstance, WebPartDefinition webpartModel)
        {
            base.ProcessWebpartProperties(webpartInstance, webpartModel);

            var typedWebpart = webpartInstance.WithAssertAndCast <SPUserCodeWebPart>("webpartInstance", value => value.RequireNotNull());
            var typedModel   = webpartModel.WithAssertAndCast <UserCodeWebPartDefinition>("webpartModel", value => value.RequireNotNull());


            // TODO
            typedWebpart.SolutionId       = typedModel.SolutionId;
            typedWebpart.AssemblyFullName = typedModel.AssemblyFullName;
            typedWebpart.TypeFullName     = typedModel.TypeFullName;

            foreach (var prop in typedModel.UserCodeProperties)
            {
                var currentProperty = typedWebpart.Properties
                                      .OfType <SPUserCodeProperty>()
                                      .FirstOrDefault(p => p.Name.ToUpper() == prop.Name.ToUpper());

                if (currentProperty == null)
                {
                    currentProperty = new SPUserCodeProperty
                    {
                        Name = prop.Name
                    };

                    typedWebpart.Properties.Add(currentProperty);
                }

                if (prop.IsTokenisable.HasValue && prop.IsTokenisable.Value)
                {
                    // Enhance 'UserCodeWebPartDefinition'
                    // UserCodeProperty should support ~sitecollection/~site tokens #485

                    var value = TokenReplacementService.ReplaceTokens(new TokenReplacementContext
                    {
                        Value   = prop.Value,
                        Context = CurrentHost.HostFile.Web
                    }).Value;

                    currentProperty.Value = value;
                }
                else
                {
                    currentProperty.Value = prop.Value;
                }
            }
        }
Exemplo n.º 26
0
        protected override void ProcessWebpartProperties(WebPart webpartInstance, WebPartDefinition webpartModel)
        {
            base.ProcessWebpartProperties(webpartInstance, webpartModel);

            var typedWebpart = webpartInstance.WithAssertAndCast<SPUserCodeWebPart>("webpartInstance", value => value.RequireNotNull());
            var typedModel = webpartModel.WithAssertAndCast<UserCodeWebPartDefinition>("webpartModel", value => value.RequireNotNull());


            // TODO
            typedWebpart.SolutionId = typedModel.SolutionId;
            typedWebpart.AssemblyFullName = typedModel.AssemblyFullName;
            typedWebpart.TypeFullName = typedModel.TypeFullName;

            foreach (var prop in typedModel.UserCodeProperties)
            {
                var currentProperty = typedWebpart.Properties
                    .OfType<SPUserCodeProperty>()
                    .FirstOrDefault(p => p.Name.ToUpper() == prop.Name.ToUpper());

                if (currentProperty == null)
                {
                    currentProperty = new SPUserCodeProperty
                    {
                        Name = prop.Name
                    };

                    typedWebpart.Properties.Add(currentProperty);
                }

                if (prop.IsTokenisable.HasValue && prop.IsTokenisable.Value)
                {
                    // Enhance 'UserCodeWebPartDefinition' 
                    // UserCodeProperty should support ~sitecollection/~site tokens #485

                    var value = TokenReplacementService.ReplaceTokens(new TokenReplacementContext
                    {
                        Value = prop.Value,
                        Context = CurrentHost.HostFile.Web
                    }).Value;

                    currentProperty.Value = value;
                }
                else
                {
                    currentProperty.Value = prop.Value;
                }
            }
        }
 public WebPartDescription(System.Web.UI.WebControls.WebParts.WebPart part)
 {
     string iD = part.ID;
     if (string.IsNullOrEmpty(iD))
     {
         throw new ArgumentException(System.Web.SR.GetString("WebPartManager_NoWebPartID"), "part");
     }
     this._id = iD;
     string displayTitle = part.DisplayTitle;
     this._title = (displayTitle != null) ? displayTitle : string.Empty;
     string description = part.Description;
     this._description = (description != null) ? description : string.Empty;
     string catalogIconImageUrl = part.CatalogIconImageUrl;
     this._imageUrl = (catalogIconImageUrl != null) ? catalogIconImageUrl : string.Empty;
     this._part = part;
 }
        protected override void ProcessWebpartProperties(WebPart webpartInstance, WebPartDefinition definition)
        {
            base.ProcessWebpartProperties(webpartInstance, definition);

            var typedWebpart = webpartInstance.WithAssertAndCast<ContentBySearchWebPart>("webpartInstance", value => value.RequireNotNull());
            var typedModel = definition.WithAssertAndCast<ContentBySearchWebPartDefinition>("webpartModel", value => value.RequireNotNull());

            // templates
            if (!string.IsNullOrEmpty(typedModel.GroupTemplateId))
                typedWebpart.GroupTemplateId = typedModel.GroupTemplateId;

            if (!string.IsNullOrEmpty(typedModel.ItemTemplateId))
                typedWebpart.ItemTemplateId = typedModel.ItemTemplateId;

            if (!string.IsNullOrEmpty(typedModel.RenderTemplateId))
                typedWebpart.RenderTemplateId = typedModel.RenderTemplateId;

            if (!string.IsNullOrEmpty(typedModel.DataProviderJSON))
                typedWebpart.DataProviderJSON = typedModel.DataProviderJSON;

            if (!string.IsNullOrEmpty(typedModel.PropertyMappings))
                typedWebpart.PropertyMappings = typedModel.PropertyMappings;

            if (typedModel.OverwriteResultPath.HasValue)
                typedWebpart.OverwriteResultPath = typedModel.OverwriteResultPath.Value;

            if (typedModel.ShouldHideControlWhenEmpty.HasValue)
                typedWebpart.ShouldHideControlWhenEmpty = typedModel.ShouldHideControlWhenEmpty.Value;

            if (typedModel.LogAnalyticsViewEvent.HasValue)
                typedWebpart.LogAnalyticsViewEvent = typedModel.LogAnalyticsViewEvent.Value;

            if (typedModel.AddSEOPropertiesFromSearch.HasValue)
                typedWebpart.AddSEOPropertiesFromSearch = typedModel.AddSEOPropertiesFromSearch.Value;

            if (typedModel.StartingItemIndex.HasValue)
                typedWebpart.StartingItemIndex = typedModel.StartingItemIndex.Value;

            // misc
            if (typedModel.NumberOfItems.HasValue)
                typedWebpart.NumberOfItems = typedModel.NumberOfItems.Value;

            if (typedModel.ResultsPerPage.HasValue)
                typedWebpart.ResultsPerPage = typedModel.ResultsPerPage.Value;
        }
Exemplo n.º 29
0
        protected override void ProcessWebpartProperties(WebPart webpartInstance, WebPartDefinition webpartModel)
        {
            base.ProcessWebpartProperties(webpartInstance, webpartModel);

            var typedWebpart = webpartInstance.WithAssertAndCast<ClientWebPart>("webpartInstance", value => value.RequireNotNull());
            var typedModel = webpartModel.WithAssertAndCast<ClientWebPartDefinition>("webpartModel", value => value.RequireNotNull());

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

            if (!productId.HasGuidValue())
                productId = _host.SPLimitedWebPartManager.Web.ID;

            typedWebpart.FeatureId = typedModel.FeatureId;
            typedWebpart.ProductId = productId.Value;
            typedWebpart.WebPartName = typedModel.WebPartName;
            typedWebpart.ProductWebId = _host.SPLimitedWebPartManager.Web.ID;
        }
Exemplo n.º 30
0
        protected override void ProcessWebpartProperties(WebPart webpartInstance, WebPartDefinition webpartModel)
        {
            base.ProcessWebpartProperties(webpartInstance, webpartModel);

            var typedWebpart = webpartInstance.WithAssertAndCast<ListViewWebPart>("webpartInstance", value => value.RequireNotNull());
            var typedModel = webpartModel.WithAssertAndCast<ListViewWebPartDefinition>("webpartModel", value => value.RequireNotNull());

            var web = _host.SPLimitedWebPartManager.Web;
            SPList list = null;

            if (typedModel.ListId.HasGuidValue())
                list = web.Lists[typedModel.ListId.Value];
            else if (!string.IsNullOrEmpty(typedModel.ListUrl))
                list = web.GetList(SPUrlUtility.CombineUrl(web.ServerRelativeUrl, typedModel.ListUrl));
            else if (!string.IsNullOrEmpty(typedModel.ListTitle))
                list = web.Lists.TryGetList(typedModel.ListTitle);


            typedWebpart.ListName = list.ID.ToString();
            typedWebpart.ListId = list.ID;

            // view check
            if (list != null)
            {
                SPView view = null;

                if (typedModel.ViewId.HasGuidValue())
                    view = list.Views[typedModel.ViewId.Value];
                else if (!string.IsNullOrEmpty(typedModel.ViewName))
                    view = list.Views[typedModel.ViewName];

                if (view != null)
                {
                    typedWebpart.ViewGuid = view.ID.ToString("B").ToUpperInvariant();
                    typedWebpart.TitleUrl = view.ServerRelativeUrl;
                }
            }

            // able to 'reset', if NULL or use list-view based URLs
            if (!string.IsNullOrEmpty(typedModel.TitleUrl))
                typedWebpart.TitleUrl = typedModel.TitleUrl;
        }
        public WebPartDescription(System.Web.UI.WebControls.WebParts.WebPart part)
        {
            string iD = part.ID;

            if (string.IsNullOrEmpty(iD))
            {
                throw new ArgumentException(System.Web.SR.GetString("WebPartManager_NoWebPartID"), "part");
            }
            this._id = iD;
            string displayTitle = part.DisplayTitle;

            this._title = (displayTitle != null) ? displayTitle : string.Empty;
            string description = part.Description;

            this._description = (description != null) ? description : string.Empty;
            string catalogIconImageUrl = part.CatalogIconImageUrl;

            this._imageUrl = (catalogIconImageUrl != null) ? catalogIconImageUrl : string.Empty;
            this._part     = part;
        }
Exemplo n.º 32
0
        protected override void ProcessWebpartProperties(WebPart webpartInstance, WebPartDefinition webpartModel)
        {
            base.ProcessWebpartProperties(webpartInstance, webpartModel);

            var typedWebpart = webpartInstance.WithAssertAndCast <ClientWebPart>("webpartInstance", value => value.RequireNotNull());
            var typedModel   = webpartModel.WithAssertAndCast <ClientWebPartDefinition>("webpartModel", value => value.RequireNotNull());

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

            if (!productId.HasGuidValue())
            {
                productId = _host.SPLimitedWebPartManager.Web.ID;
            }

            typedWebpart.FeatureId    = typedModel.FeatureId;
            typedWebpart.ProductId    = productId.Value;
            typedWebpart.WebPartName  = typedModel.WebPartName;
            typedWebpart.ProductWebId = _host.SPLimitedWebPartManager.Web.ID;
        }
        protected override void ProcessWebpartProperties(WebPart webpartInstance, WebPartDefinition webpartModel)
        {
            base.ProcessWebpartProperties(webpartInstance, webpartModel);

            var typedWebpart = webpartInstance.WithAssertAndCast<ContentEditorWebPart>("webpartInstance", value => value.RequireNotNull());
            var typedModel = webpartModel.WithAssertAndCast<ContentEditorWebPartDefinition>("webpartModel", value => value.RequireNotNull());

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

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

                contentLinkValue = TokenReplacementService.ReplaceTokens(new TokenReplacementContext
                {
                    Value = contentLinkValue,
                    Context = CurrentHost.PageListItem.Web
                }).Value;

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

                typedWebpart.ContentLink = contentLinkValue;
            }

            if (!string.IsNullOrEmpty(typedModel.Content))
            {

                var xmlDoc = new XmlDocument();
                var xmlElement = xmlDoc.CreateElement("ContentElement");

                var content = typedModel.Content ?? string.Empty;

                xmlElement.InnerText = content;
                typedWebpart.Content = xmlElement;
            }
        }
        protected override void ProcessWebpartProperties(WebPart webpartInstance, WebPartDefinition webpartModel)
        {
            base.ProcessWebpartProperties(webpartInstance, webpartModel);

            var typedWebpart = webpartInstance.WithAssertAndCast <ContentEditorWebPart>("webpartInstance", value => value.RequireNotNull());
            var typedModel   = webpartModel.WithAssertAndCast <ContentEditorWebPartDefinition>("webpartModel", value => value.RequireNotNull());

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

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

                contentLinkValue = TokenReplacementService.ReplaceTokens(new TokenReplacementContext
                {
                    Value   = contentLinkValue,
                    Context = CurrentHost.HostFile.Web
                }).Value;

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

                typedWebpart.ContentLink = contentLinkValue;
            }

            if (!string.IsNullOrEmpty(typedModel.Content))
            {
                var xmlDoc     = new XmlDocument();
                var xmlElement = xmlDoc.CreateElement("ContentElement");

                var content = typedModel.Content ?? string.Empty;

                xmlElement.InnerText = content;
                typedWebpart.Content = xmlElement;
            }
        }
Exemplo n.º 35
0
 public new string GetWebPartTitleClientID(System.Web.UI.WebControls.WebParts.WebPart webPart)
 {
     return(base.GetWebPartTitleClientID(webPart));
 }
        protected override void ProcessWebpartProperties(WebPart webpartInstance, WebPartDefinition webpartModel)
        {
            base.ProcessWebpartProperties(webpartInstance, webpartModel);

            var typedWebpart = webpartInstance.WithAssertAndCast <AdvancedSearchBox>("webpartInstance", value => value.RequireNotNull());
            var definition   = webpartModel.WithAssertAndCast <AdvancedSearchBoxDefinition>("webpartModel", value => value.RequireNotNull());

            if (!string.IsNullOrEmpty(definition.AndQueryTextBoxLabelText))
            {
                typedWebpart.AndQueryTextBoxLabelText = definition.AndQueryTextBoxLabelText;
            }

            if (!string.IsNullOrEmpty(definition.DisplayGroup))
            {
                typedWebpart.DisplayGroup = definition.DisplayGroup;
            }

            if (!string.IsNullOrEmpty(definition.LanguagesLabelText))
            {
                typedWebpart.LanguagesLabelText = definition.LanguagesLabelText;
            }

            if (!string.IsNullOrEmpty(definition.NotQueryTextBoxLabelText))
            {
                typedWebpart.NotQueryTextBoxLabelText = definition.NotQueryTextBoxLabelText;
            }

            if (!string.IsNullOrEmpty(definition.OrQueryTextBoxLabelText))
            {
                typedWebpart.OrQueryTextBoxLabelText = definition.OrQueryTextBoxLabelText;
            }

            if (!string.IsNullOrEmpty(definition.PhraseQueryTextBoxLabelText))
            {
                typedWebpart.PhraseQueryTextBoxLabelText = definition.PhraseQueryTextBoxLabelText;
            }

            if (!string.IsNullOrEmpty(definition.AdvancedSearchBoxProperties))
            {
                typedWebpart.Properties = definition.AdvancedSearchBoxProperties;
            }

            if (!string.IsNullOrEmpty(definition.PropertiesSectionLabelText))
            {
                typedWebpart.PropertiesSectionLabelText = definition.PropertiesSectionLabelText;
            }

            if (!string.IsNullOrEmpty(definition.ResultTypeLabelText))
            {
                typedWebpart.ResultTypeLabelText = definition.ResultTypeLabelText;
            }

            if (!string.IsNullOrEmpty(definition.ScopeLabelText))
            {
                typedWebpart.ScopeLabelText = definition.ScopeLabelText;
            }

            if (!string.IsNullOrEmpty(definition.ScopeSectionLabelText))
            {
                typedWebpart.ScopeSectionLabelText = definition.ScopeSectionLabelText;
            }

            if (!string.IsNullOrEmpty(definition.SearchResultPageURL))
            {
                typedWebpart.SearchResultPageURL = definition.SearchResultPageURL;
            }

            if (definition.ShowAndQueryTextBox.HasValue)
            {
                typedWebpart.ShowAndQueryTextBox = definition.ShowAndQueryTextBox.Value;
            }

            if (definition.ShowLanguageOptions.HasValue)
            {
                typedWebpart.ShowLanguageOptions = definition.ShowLanguageOptions.Value;
            }

            if (definition.ShowNotQueryTextBox.HasValue)
            {
                typedWebpart.ShowNotQueryTextBox = definition.ShowNotQueryTextBox.Value;
            }

            if (definition.ShowOrQueryTextBox.HasValue)
            {
                typedWebpart.ShowOrQueryTextBox = definition.ShowOrQueryTextBox.Value;
            }

            if (definition.ShowPhraseQueryTextBox.HasValue)
            {
                typedWebpart.ShowPhraseQueryTextBox = definition.ShowPhraseQueryTextBox.Value;
            }

            if (definition.ShowPropertiesSection.HasValue)
            {
                typedWebpart.ShowPropertiesSection = definition.ShowPropertiesSection.Value;
            }

            if (definition.ShowResultTypePicker.HasValue)
            {
                typedWebpart.ShowResultTypePicker = definition.ShowResultTypePicker.Value;
            }

            if (definition.ShowScopes.HasValue)
            {
                typedWebpart.ShowScopes = definition.ShowScopes.Value;
            }

            if (!string.IsNullOrEmpty(definition.TextQuerySectionLabelText))
            {
                typedWebpart.TextQuerySectionLabelText = definition.TextQuerySectionLabelText;
            }
        }
        protected override void ProcessWebpartProperties(WebPart webpartInstance, WebPartDefinition webpartModel)
        {
            base.ProcessWebpartProperties(webpartInstance, webpartModel);

            var typedWebpart = webpartInstance.WithAssertAndCast<XsltListViewWebPart>("webpartInstance", value => value.RequireNotNull());
            var typedModel = webpartModel.WithAssertAndCast<XsltListViewWebPartDefinition>("webpartModel", value => value.RequireNotNull());

            var web = _host.SPLimitedWebPartManager.Web;

            // bind list
            SPList list = null;

            if (typedModel.ListId.HasValue && typedModel.ListId != default(Guid))
                list = web.Lists[typedModel.ListId.Value];
            else if (!string.IsNullOrEmpty(typedModel.ListUrl))
                list = web.GetList(SPUrlUtility.CombineUrl(web.ServerRelativeUrl, typedModel.ListUrl));
            else if (!string.IsNullOrEmpty(typedModel.ListTitle))
                list = web.Lists.TryGetList(typedModel.ListTitle);
            else
            {
                throw new SPMeta2Exception("ListUrl, ListTitle or ListId should be defined.");
            }

            if (list != null)
            {
                typedWebpart.ListName = list.ID.ToString("B").ToUpperInvariant();
                typedWebpart.TitleUrl = list.DefaultViewUrl;
            }

            // view check
            if (list != null)
            {
                SPView srcView = null;

                if (typedModel.ViewId.HasValue && typedModel.ViewId != default(Guid))
                    srcView = list.Views[typedModel.ViewId.Value];
                else if (!string.IsNullOrEmpty(typedModel.ViewName))
                    srcView = list.Views[typedModel.ViewName];

                if (srcView != null)
                {
                    if (!string.IsNullOrEmpty(typedWebpart.ViewGuid))
                    {
                        // update hidden view, otherwise we can have weird SharePoint exception
                        // https://github.com/SubPointSolutions/spmeta2/issues/487

                        var hiddenView = list.Views[new Guid(typedWebpart.ViewGuid)];

                        hiddenView.ViewFields.DeleteAll();

                        foreach (string f in srcView.ViewFields)
                            hiddenView.ViewFields.Add(f);

                        hiddenView.RowLimit = srcView.RowLimit;
                        hiddenView.Query = srcView.Query;
#if !NET35
                        hiddenView.JSLink = srcView.JSLink;
#endif
                        hiddenView.IncludeRootFolder = srcView.IncludeRootFolder;
                        hiddenView.Scope = srcView.Scope;

                        hiddenView.Update();
                    }
                    else
                    {
                        typedWebpart.ViewGuid = srcView.ID.ToString("B").ToUpperInvariant();
                    }

                    typedWebpart.TitleUrl = srcView.ServerRelativeUrl;
                }
            }

            // able to 'reset', if NULL or use list-view based URLs
            if (!string.IsNullOrEmpty(typedModel.TitleUrl))
                typedWebpart.TitleUrl = typedModel.TitleUrl;

            // weird, but it must be set to avoid null-ref exceptions
            typedWebpart.GhostedXslLink = "main.xsl";

#if !NET35
            // rest
            typedWebpart.JSLink = typedModel.JSLink;
#endif

            if (typedModel.CacheXslStorage.HasValue)
                typedWebpart.CacheXslStorage = typedModel.CacheXslStorage.Value;

            if (typedModel.CacheXslTimeOut.HasValue)
                typedWebpart.CacheXslTimeOut = typedModel.CacheXslTimeOut.Value;

#if !NET35
            if (typedModel.ShowTimelineIfAvailable.HasValue)
                typedWebpart.ShowTimelineIfAvailable = typedModel.ShowTimelineIfAvailable.Value;
#endif

            if (!string.IsNullOrEmpty(typedModel.Xsl))
            {
                typedWebpart.Xsl = typedModel.Xsl;
            }

            if (!string.IsNullOrEmpty(typedModel.XslLink))
            {
                var urlValue = typedModel.XslLink;

                typedWebpart.XslLink = urlValue;
            }

            if (!string.IsNullOrEmpty(typedModel.XmlDefinition))
            {
                typedWebpart.XmlDefinition = typedModel.XmlDefinition;
            }

            if (!string.IsNullOrEmpty(typedModel.XmlDefinitionLink))
            {
                var urlValue = typedModel.XmlDefinitionLink;
                typedWebpart.XmlDefinitionLink = urlValue;
            }

            if (!string.IsNullOrEmpty(typedModel.GhostedXslLink))
            {
                var urlValue = typedModel.GhostedXslLink;
                typedWebpart.GhostedXslLink = urlValue;
            }

            if (!string.IsNullOrEmpty(typedModel.BaseXsltHashKey))
                typedWebpart.BaseXsltHashKey = typedModel.BaseXsltHashKey;

            if (typedModel.DisableColumnFiltering.HasValue)
                typedWebpart.DisableColumnFiltering = typedModel.DisableColumnFiltering.Value;

#if !NET35
            if (typedModel.DisableSaveAsNewViewButton.HasValue)
                typedWebpart.DisableSaveAsNewViewButton = typedModel.DisableSaveAsNewViewButton.Value;

            if (typedModel.DisableViewSelectorMenu.HasValue)
                typedWebpart.DisableViewSelectorMenu = typedModel.DisableViewSelectorMenu.Value;

            if (typedModel.InplaceSearchEnabled.HasValue)
                typedWebpart.InplaceSearchEnabled = typedModel.InplaceSearchEnabled.Value;
#endif
        }
        protected override void ProcessWebpartProperties(WebPart webpartInstance, WebPartDefinition definition)
        {
            base.ProcessWebpartProperties(webpartInstance, definition);

            var typedWebpart = webpartInstance.WithAssertAndCast<ContentByQueryWebPart>("webpartInstance", value => value.RequireNotNull());
            var typedDefinition = definition.WithAssertAndCast<ContentByQueryWebPartDefinition>("webpartModel", value => value.RequireNotNull());

            // xslt links
            if (!string.IsNullOrEmpty(typedDefinition.MainXslLink))
            {
                var linkValue = typedDefinition.MainXslLink;

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

                linkValue = TokenReplacementService.ReplaceTokens(new TokenReplacementContext
                {
                    Value = linkValue,
                    Context = CurrentHost.PageListItem.Web
                }).Value;

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

                typedWebpart.MainXslLink = linkValue;
            }

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

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

                linkValue = TokenReplacementService.ReplaceTokens(new TokenReplacementContext
                {
                    Value = linkValue,
                    Context = CurrentHost.PageListItem.Web
                }).Value;

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

                typedWebpart.ItemXslLink = linkValue;
            }

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

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

                linkValue = TokenReplacementService.ReplaceTokens(new TokenReplacementContext
                {
                    Value = linkValue,
                    Context = CurrentHost.PageListItem.Web
                }).Value;

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

                typedWebpart.HeaderXslLink = linkValue;
            }

            // styles
            if (!string.IsNullOrEmpty(typedDefinition.ItemStyle))
                typedWebpart.ItemStyle = typedDefinition.ItemStyle;

            if (!string.IsNullOrEmpty(typedDefinition.GroupStyle))
                typedWebpart.GroupStyle = typedDefinition.GroupStyle;


            // cache settings
            if (typedDefinition.UseCache.HasValue)
                typedWebpart.UseCache = typedDefinition.UseCache.Value;

            if (typedDefinition.CacheXslStorage.HasValue)
                typedWebpart.CacheXslStorage = typedDefinition.CacheXslStorage.Value;

            if (typedDefinition.CacheXslTimeOut.HasValue)
                typedWebpart.CacheXslTimeOut = typedDefinition.CacheXslTimeOut.Value;

            // item limit
            if (typedDefinition.ItemLimit.HasValue)
                typedWebpart.ItemLimit = typedDefinition.ItemLimit.Value;

            // mappings
            if (!string.IsNullOrEmpty(typedDefinition.DataMappings))
                typedWebpart.DataMappings = typedDefinition.DataMappings;

            if (!string.IsNullOrEmpty(typedDefinition.DataMappingViewFields))
                typedWebpart.DataMappingViewFields = typedDefinition.DataMappingViewFields;

            // misc
            if (typedDefinition.ShowUntargetedItems.HasValue)
                typedWebpart.ShowUntargetedItems = typedDefinition.ShowUntargetedItems.Value;

            if (typedDefinition.PlayMediaInBrowser.HasValue)
                typedWebpart.PlayMediaInBrowser = typedDefinition.PlayMediaInBrowser.Value;

            // FilterTypeXXX
            if (!string.IsNullOrEmpty(typedDefinition.FilterType1))
                typedWebpart.FilterType1 = typedDefinition.FilterType1;

            if (!string.IsNullOrEmpty(typedDefinition.FilterType2))
                typedWebpart.FilterType2 = typedDefinition.FilterType2;

            if (!string.IsNullOrEmpty(typedDefinition.FilterType3))
                typedWebpart.FilterType3 = typedDefinition.FilterType3;

            // FilterFieldXXX
            if (!string.IsNullOrEmpty(typedDefinition.FilterField1))
                typedWebpart.FilterField1 = typedDefinition.FilterField1;

            if (!string.IsNullOrEmpty(typedDefinition.FilterField2))
                typedWebpart.FilterField2 = typedDefinition.FilterField2;

            if (!string.IsNullOrEmpty(typedDefinition.FilterField3))
                typedWebpart.FilterField3 = typedDefinition.FilterField3;

            // FilterXXXIsCustomValue
            if (typedDefinition.Filter1IsCustomValue.HasValue)
                typedWebpart.Filter1IsCustomValue = typedDefinition.Filter1IsCustomValue.Value;

            if (typedDefinition.Filter2IsCustomValue.HasValue)
                typedWebpart.Filter2IsCustomValue = typedDefinition.Filter2IsCustomValue.Value;

            if (typedDefinition.Filter3IsCustomValue.HasValue)
                typedWebpart.Filter3IsCustomValue = typedDefinition.Filter3IsCustomValue.Value;

            // FilterValueXXX
            if (!string.IsNullOrEmpty(typedDefinition.FilterValue1))
                typedWebpart.FilterValue1 = typedDefinition.FilterValue1;

            if (!string.IsNullOrEmpty(typedDefinition.FilterValue2))
                typedWebpart.FilterValue2 = typedDefinition.FilterValue2;

            if (!string.IsNullOrEmpty(typedDefinition.FilterValue3))
                typedWebpart.FilterValue3 = typedDefinition.FilterValue3;


            if (!string.IsNullOrEmpty(typedDefinition.Filter1ChainingOperator))
            {
                typedWebpart.Filter1ChainingOperator = (ContentByQueryWebPart.FilterChainingOperator)
                   Enum.Parse(typeof(ContentByQueryWebPart.FilterChainingOperator), typedDefinition.Filter1ChainingOperator);
            }

            if (!string.IsNullOrEmpty(typedDefinition.Filter2ChainingOperator))
            {
                typedWebpart.Filter2ChainingOperator = (ContentByQueryWebPart.FilterChainingOperator)
                   Enum.Parse(typeof(ContentByQueryWebPart.FilterChainingOperator), typedDefinition.Filter2ChainingOperator);
            }


            // sorting
            if (!string.IsNullOrEmpty(typedDefinition.SortBy))
                typedWebpart.SortBy = typedDefinition.SortBy;

            if (!string.IsNullOrEmpty(typedDefinition.SortByDirection))
                typedWebpart.SortByDirection = (ContentByQueryWebPart.SortDirection)
                    Enum.Parse(typeof(ContentByQueryWebPart.SortDirection), typedDefinition.SortByDirection);

            if (!string.IsNullOrEmpty(typedDefinition.SortByFieldType))
                typedWebpart.SortByFieldType = typedDefinition.SortByFieldType;

            if (!string.IsNullOrEmpty(typedDefinition.GroupByDirection))
            {
                typedWebpart.GroupByDirection = (ContentByQueryWebPart.SortDirection)
                    Enum.Parse(typeof(ContentByQueryWebPart.SortDirection), typedDefinition.GroupByDirection);
            }


            // FilterOperatorXXX
            if (!string.IsNullOrEmpty(typedDefinition.FilterOperator1))
            {
                typedWebpart.FilterOperator1 = (ContentByQueryWebPart.FilterFieldQueryOperator)
                    Enum.Parse(typeof(ContentByQueryWebPart.FilterFieldQueryOperator), typedDefinition.FilterOperator1);
            }

            if (!string.IsNullOrEmpty(typedDefinition.FilterOperator2))
            {
                typedWebpart.FilterOperator2 = (ContentByQueryWebPart.FilterFieldQueryOperator)
                    Enum.Parse(typeof(ContentByQueryWebPart.FilterFieldQueryOperator), typedDefinition.FilterOperator2);
            }

            if (!string.IsNullOrEmpty(typedDefinition.FilterOperator3))
            {
                typedWebpart.FilterOperator3 = (ContentByQueryWebPart.FilterFieldQueryOperator)
                    Enum.Parse(typeof(ContentByQueryWebPart.FilterFieldQueryOperator), typedDefinition.FilterOperator3);
            }

            // FilterDisplayValueXXX

            if (!string.IsNullOrEmpty(typedDefinition.FilterDisplayValue1))
                typedWebpart.FilterDisplayValue1 = typedDefinition.FilterDisplayValue1;

            if (!string.IsNullOrEmpty(typedDefinition.FilterDisplayValue2))
                typedWebpart.FilterDisplayValue2 = typedDefinition.FilterDisplayValue2;

            if (!string.IsNullOrEmpty(typedDefinition.FilterDisplayValue3))
                typedWebpart.FilterDisplayValue3 = typedDefinition.FilterDisplayValue3;


            // bindings
            if (typedDefinition.ServerTemplate.HasValue)
                typedWebpart.ServerTemplate = typedDefinition.ServerTemplate.ToString();

            if (!string.IsNullOrEmpty(typedDefinition.ContentTypeName))
                typedWebpart.ContentTypeName = typedDefinition.ContentTypeName;

            if (!string.IsNullOrEmpty(typedDefinition.ContentTypeBeginsWithId))
                typedWebpart.ContentTypeBeginsWithId = typedDefinition.ContentTypeBeginsWithId;

            if (typedDefinition.ListId.HasGuidValue())
                typedWebpart.ListId = typedDefinition.ListId.Value;

            if (typedDefinition.ListGuid.HasGuidValue())
                typedWebpart.ListGuid = typedDefinition.ListGuid.Value.ToString("D");

            if (!string.IsNullOrEmpty(typedDefinition.ListName))
                typedWebpart.ListName = typedDefinition.ListName;

            if (!string.IsNullOrEmpty(typedDefinition.WebUrl))
                typedWebpart.WebUrl = typedDefinition.WebUrl;

            // overrides
            if (!string.IsNullOrEmpty(typedDefinition.ListsOverride))
                typedWebpart.ListsOverride = typedDefinition.ListsOverride;

            if (!string.IsNullOrEmpty(typedDefinition.ViewFieldsOverride))
                typedWebpart.ViewFieldsOverride = typedDefinition.ViewFieldsOverride;

            if (!string.IsNullOrEmpty(typedDefinition.QueryOverride))
                typedWebpart.QueryOverride = typedDefinition.QueryOverride;

            if (!string.IsNullOrEmpty(typedDefinition.CommonViewFields))
                typedWebpart.CommonViewFields = typedDefinition.CommonViewFields;

            if (typedDefinition.FilterByAudience.HasValue)
                typedWebpart.FilterByAudience = typedDefinition.FilterByAudience.Value;
        }
        protected override void ProcessWebpartProperties(WebPart webpartInstance, WebPartDefinition definition)
        {
            base.ProcessWebpartProperties(webpartInstance, definition);

            var typedWebpart = webpartInstance.WithAssertAndCast <ContentBySearchWebPart>("webpartInstance", value => value.RequireNotNull());
            var typedModel   = definition.WithAssertAndCast <ContentBySearchWebPartDefinition>("webpartModel", value => value.RequireNotNull());

            // templates
            if (!string.IsNullOrEmpty(typedModel.GroupTemplateId))
            {
                typedWebpart.GroupTemplateId = typedModel.GroupTemplateId;
            }

            if (!string.IsNullOrEmpty(typedModel.ItemTemplateId))
            {
                typedWebpart.ItemTemplateId = typedModel.ItemTemplateId;
            }

            if (!string.IsNullOrEmpty(typedModel.RenderTemplateId))
            {
                typedWebpart.RenderTemplateId = typedModel.RenderTemplateId;
            }

            if (!string.IsNullOrEmpty(typedModel.DataProviderJSON))
            {
                typedWebpart.DataProviderJSON = typedModel.DataProviderJSON;
            }

            if (!string.IsNullOrEmpty(typedModel.PropertyMappings))
            {
                typedWebpart.PropertyMappings = typedModel.PropertyMappings;
            }

            if (typedModel.OverwriteResultPath.HasValue)
            {
                typedWebpart.OverwriteResultPath = typedModel.OverwriteResultPath.Value;
            }

            if (typedModel.ShouldHideControlWhenEmpty.HasValue)
            {
                typedWebpart.ShouldHideControlWhenEmpty = typedModel.ShouldHideControlWhenEmpty.Value;
            }

            if (typedModel.LogAnalyticsViewEvent.HasValue)
            {
                typedWebpart.LogAnalyticsViewEvent = typedModel.LogAnalyticsViewEvent.Value;
            }

            if (typedModel.AddSEOPropertiesFromSearch.HasValue)
            {
                typedWebpart.AddSEOPropertiesFromSearch = typedModel.AddSEOPropertiesFromSearch.Value;
            }

            if (typedModel.StartingItemIndex.HasValue)
            {
                typedWebpart.StartingItemIndex = typedModel.StartingItemIndex.Value;
            }

            // misc
            if (typedModel.NumberOfItems.HasValue)
            {
                typedWebpart.NumberOfItems = typedModel.NumberOfItems.Value;
            }

            if (typedModel.ResultsPerPage.HasValue)
            {
                typedWebpart.ResultsPerPage = typedModel.ResultsPerPage.Value;
            }
        }
 public WebPartEventArgs(System.Web.UI.WebControls.WebParts.WebPart webPart)
 {
     this._webPart = webPart;
 }
        protected override void ProcessWebpartProperties(WebPart webpartInstance, WebPartDefinition webpartModel)
        {
            base.ProcessWebpartProperties(webpartInstance, webpartModel);

            var typedWebpart = webpartInstance.WithAssertAndCast<ListViewWebPart>("webpartInstance", value => value.RequireNotNull());
            var typedModel = webpartModel.WithAssertAndCast<ListViewWebPartDefinition>("webpartModel", value => value.RequireNotNull());

            var web = _host.SPLimitedWebPartManager.Web;

            var targetWeb = web;

            if (!string.IsNullOrEmpty(typedModel.WebUrl) || typedModel.WebId.HasGuidValue())
                targetWeb = new LookupFieldModelHandler().GetTargetWeb(web.Site, typedModel.WebUrl, typedModel.WebId);

            var list = XsltListViewWebPartModelHandler.GetTargetList(targetWeb, typedModel.ListTitle, typedModel.ListUrl, typedModel.ListId);

            typedWebpart.ListName = list.ID.ToString();
            typedWebpart.ListId = list.ID;

            // view check
            if (list != null)
            {
                SPView view = null;

                if (typedModel.ViewId.HasGuidValue())
                    view = list.Views[typedModel.ViewId.Value];
                else if (!string.IsNullOrEmpty(typedModel.ViewName))
                    view = list.Views[typedModel.ViewName];
                else if (!string.IsNullOrEmpty(typedModel.ViewUrl))
                {
                    view = list.Views.OfType<SPView>()
                        .FirstOrDefault(v => v.ServerRelativeUrl.ToUpper().EndsWith(typedModel.ViewUrl.ToUpper()));
                }

                if (view != null)
                {
                    typedWebpart.ViewGuid = view.ID.ToString("B").ToUpperInvariant();
                    typedWebpart.TitleUrl = view.ServerRelativeUrl;
                }
            }

            // able to 'reset', if NULL or use list-view based URLs
            if (!string.IsNullOrEmpty(typedModel.TitleUrl))
                typedWebpart.TitleUrl = typedModel.TitleUrl;
        }
Exemplo n.º 42
0
    /// <summary>
    ///
    /// </summary>
    /// <param name="web"></param>
    /// <param name="page"></param>
    /// <param name="webPartZone"></param>
    /// <param name="order"></param>
    /// <param name="webpart"></param>
    public static void AddWebPartToPage(this SPWeb web, string page, string webPartZone, int order, System.Web.UI.WebControls.WebParts.WebPart webpart)
    {
        try
        {
            SPFile file = web.GetFile(page);

            if (!file.Exists)
            {
                throw new SPException(string.Format("File '{0}' does not exist", file.ServerRelativeUrl));
            }

            SPLimitedWebPartManager partManager = file.GetLimitedWebPartManager(System.Web.UI.WebControls.WebParts.PersonalizationScope.Shared);

            partManager.AddWebPart(webpart, webPartZone, order);
        }
        catch (Exception ex)
        {
            SPDiagnosticsService.Local.WriteTrace(0, new SPDiagnosticsCategory("CORE:HELPERS", TraceSeverity.Unexpected, EventSeverity.Error), TraceSeverity.Unexpected, String.Format("Exception happened in Helpers:AddWebPartToPage. MESSAGE: {0}. EXCEPTION TRACE: {1} ", ex.Message, ex.StackTrace), ex.StackTrace);
        }
    }
Exemplo n.º 43
0
 public override string GetWebPartLanguage(System.Web.UI.WebControls.WebParts.WebPart webPart)
 {
     return(_currentHelper.GetWebPartLanguage(webPart));
 }
Exemplo n.º 44
0
        public static void GetFilterInfo(IDictionary inst, string schemaName, ref string clickScript, SystemWebPart webPart, Page page, ref bool includeFilters, ref string fj, ref List <KeyValuePair <string, KeyValuePair <List <KeyValuePair <string, CamlOperator> >, bool> > > effectiveFilters)
        {
            int              i1, i2;
            object           val;
            SPWebPartManager wpMan      = null;
            SystemWebPart    filterPart = null;
            IList            flist      = null;
            List <string>    andFilters = new List <string> ();
            List <object []> filters    = new List <object []> ();
            KeyValuePair <string, KeyValuePair <List <KeyValuePair <string, CamlOperator> >, bool> > kvp;

            includeFilters = false;
            if (inst ["filter"] != null)
            {
                try {
                    includeFilters = (bool)inst ["filter"];
                } catch {
                    includeFilters = false;
                }
            }
            if (includeFilters && !IsLic(2))
            {
                includeFilters = false;
                clickScript    = "alert(\'" + SPEncode.ScriptEncode(ProductPage.GetResource("NopeEd", ProductPage.GetProductResource("PC_" + schemaName + "_filter"), "Basic")) + "\');";
            }
            if (includeFilters && (effectiveFilters == null))
            {
                effectiveFilters = new List <KeyValuePair <string, KeyValuePair <List <KeyValuePair <string, CamlOperator> >, bool> > > ();
                try {
                    wpMan = SPWebPartManager.GetCurrentWebPartManager(page) as SPWebPartManager;
                } catch {
                }
                if ((webPart != null) && (wpMan != null))
                {
                    foreach (SystemWebPart wp in ProductPage.TryEach <SystemWebPart> (wpMan.WebParts))
                    {
                        if (wp.GetType().AssemblyQualifiedName == ProductPage.FILTERZEN_TYPENAME)
                        {
                            foreach (SystemWebPart cwp in (((getConnPartMethod == null) ? (getConnPartMethod = wp.GetType().GetMethod("GetConnectedParts", BindingFlags.Instance | BindingFlags.Public | BindingFlags.DeclaredOnly, null, Type.EmptyTypes, null)) : getConnPartMethod).Invoke(wp, null) as IEnumerable <SystemWebPart>))
                            {
                                if (cwp.ID.Equals(webPart.ID))
                                {
                                    filterPart = wp;
                                    break;
                                }
                            }
                        }
                        if (filterPart != null)
                        {
                            break;
                        }
                    }
                }
                if (filterPart != null)
                {
                    try {
                        if (!((bool)filterPart.GetType().GetMethod("LicEd", BindingFlags.NonPublic | BindingFlags.Instance).Invoke(filterPart, new object [] { 2 })))
                        {
                            clickScript = "alert(\'" + SPEncode.ScriptEncode(ProductPage.GetProductResource("Old_NoFilterZenEnt")) + "\');";
                            filterPart  = null;
                        }
                    } catch {
                        clickScript = "alert(\'" + SPEncode.ScriptEncode(ProductPage.GetProductResource("Old_NoFilterZenEnt")) + "\');";
                        filterPart  = null;
                    }
                }
                fj = string.Empty;
                if (filterPart != null)
                {
                    try {
                        flist = ((partFiltersProp == null) ? (partFiltersProp = filterPart.GetType().GetProperty("PartFilters", BindingFlags.Instance | BindingFlags.Public)) : partFiltersProp).GetValue(filterPart, null) as IList;
                        fj    = ((partJsonProp == null) ? (partJsonProp = filterPart.GetType().GetProperty("JsonFilters", BindingFlags.Instance | BindingFlags.Public)) : partJsonProp).GetValue(filterPart, null) as string;
                        andFilters.AddRange(((string)((camlAndProp == null) ? (camlAndProp = filterPart.GetType().GetProperty("CamlFiltersAndCombined", BindingFlags.Instance | BindingFlags.Public)) : camlAndProp).GetValue(filterPart, null)).Split(new char [] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries));
                    } catch {
                    }
                    if (flist != null)
                    {
                        foreach (object kv in flist)
                        {
                            if (kvpValProp == null)
                            {
                                kvpValProp = kv.GetType().GetProperty("Value", BindingFlags.Instance | BindingFlags.Public);
                            }
                            if ((val = kvpValProp.GetValue(kv, null)) != null)
                            {
                                if (fpKeyProp == null)
                                {
                                    fpKeyProp = val.GetType().GetProperty("Key", BindingFlags.Public | BindingFlags.Instance);
                                }
                                if (fpValProp == null)
                                {
                                    fpValProp = val.GetType().GetProperty("Value", BindingFlags.Public | BindingFlags.Instance);
                                }
                                if (fpOpProp == null)
                                {
                                    fpOpProp = val.GetType().GetProperty("CamlOperator", BindingFlags.Public | BindingFlags.Instance);
                                }
                                filters.Add(new object [] { fpKeyProp.GetValue(val, null), fpValProp.GetValue(val, null), (CamlOperator)Enum.Parse(typeof(CamlOperator), fpOpProp.GetValue(val, null).ToString(), true) });
                            }
                        }
                    }
                    foreach (object [] f in filters)
                    {
                        kvp = new KeyValuePair <string, KeyValuePair <List <KeyValuePair <string, CamlOperator> >, bool> > (f [0] as string, new KeyValuePair <List <KeyValuePair <string, CamlOperator> >, bool> (new List <KeyValuePair <string, CamlOperator> > (), andFilters.Contains(f [0] as string)));
                        i1  = i2 = -1;
                        foreach (KeyValuePair <string, KeyValuePair <List <KeyValuePair <string, CamlOperator> >, bool> > k in effectiveFilters)
                        {
                            i2++;
                            if (k.Key == kvp.Key)
                            {
                                i1  = i2;
                                kvp = k;
                                break;
                            }
                        }
                        kvp.Value.Key.Add(new KeyValuePair <string, CamlOperator> (f [1] as string, (CamlOperator)f [2]));
                        if (i1 >= 0)
                        {
                            effectiveFilters [i1] = kvp;
                        }
                        else
                        {
                            effectiveFilters.Add(kvp);
                        }
                    }
                }
            }
        }
Exemplo n.º 45
0
        protected override void ProcessWebpartProperties(WebPart webpartInstance, WebPartDefinition definition)
        {
            base.ProcessWebpartProperties(webpartInstance, definition);

            var typedWebpart    = webpartInstance.WithAssertAndCast <ContentByQueryWebPart>("webpartInstance", value => value.RequireNotNull());
            var typedDefinition = definition.WithAssertAndCast <ContentByQueryWebPartDefinition>("webpartModel", value => value.RequireNotNull());

            // xslt links
            if (!string.IsNullOrEmpty(typedDefinition.MainXslLink))
            {
                var linkValue = typedDefinition.MainXslLink;

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

                linkValue = TokenReplacementService.ReplaceTokens(new TokenReplacementContext
                {
                    Value   = linkValue,
                    Context = CurrentHost.HostFile.Web
                }).Value;

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

                typedWebpart.MainXslLink = linkValue;
            }

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

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

                linkValue = TokenReplacementService.ReplaceTokens(new TokenReplacementContext
                {
                    Value   = linkValue,
                    Context = CurrentHost.HostFile.Web
                }).Value;

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

                typedWebpart.ItemXslLink = linkValue;
            }

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

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

                linkValue = TokenReplacementService.ReplaceTokens(new TokenReplacementContext
                {
                    Value   = linkValue,
                    Context = CurrentHost.HostFile.Web
                }).Value;

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

                typedWebpart.HeaderXslLink = linkValue;
            }

            // styles
            if (!string.IsNullOrEmpty(typedDefinition.ItemStyle))
            {
                typedWebpart.ItemStyle = typedDefinition.ItemStyle;
            }

            if (!string.IsNullOrEmpty(typedDefinition.GroupStyle))
            {
                typedWebpart.GroupStyle = typedDefinition.GroupStyle;
            }


            // cache settings
            if (typedDefinition.UseCache.HasValue)
            {
                typedWebpart.UseCache = typedDefinition.UseCache.Value;
            }

            if (typedDefinition.CacheXslStorage.HasValue)
            {
                typedWebpart.CacheXslStorage = typedDefinition.CacheXslStorage.Value;
            }

            if (typedDefinition.CacheXslTimeOut.HasValue)
            {
                typedWebpart.CacheXslTimeOut = typedDefinition.CacheXslTimeOut.Value;
            }

            // item limit
            if (typedDefinition.ItemLimit.HasValue)
            {
                typedWebpart.ItemLimit = typedDefinition.ItemLimit.Value;
            }

            // mappings
            if (!string.IsNullOrEmpty(typedDefinition.DataMappings))
            {
                typedWebpart.DataMappings = typedDefinition.DataMappings;
            }

            if (!string.IsNullOrEmpty(typedDefinition.DataMappingViewFields))
            {
                typedWebpart.DataMappingViewFields = typedDefinition.DataMappingViewFields;
            }

            // misc
            if (typedDefinition.ShowUntargetedItems.HasValue)
            {
                typedWebpart.ShowUntargetedItems = typedDefinition.ShowUntargetedItems.Value;
            }

            if (typedDefinition.PlayMediaInBrowser.HasValue)
            {
                typedWebpart.PlayMediaInBrowser = typedDefinition.PlayMediaInBrowser.Value;
            }

            if (typedDefinition.UseCopyUtil.HasValue)
            {
                typedWebpart.UseCopyUtil = typedDefinition.UseCopyUtil.Value;
            }

            // FilterTypeXXX
            if (!string.IsNullOrEmpty(typedDefinition.FilterType1))
            {
                typedWebpart.FilterType1 = typedDefinition.FilterType1;
            }

            if (!string.IsNullOrEmpty(typedDefinition.FilterType2))
            {
                typedWebpart.FilterType2 = typedDefinition.FilterType2;
            }

            if (!string.IsNullOrEmpty(typedDefinition.FilterType3))
            {
                typedWebpart.FilterType3 = typedDefinition.FilterType3;
            }

            // FilterFieldXXX
            if (!string.IsNullOrEmpty(typedDefinition.FilterField1))
            {
                typedWebpart.FilterField1 = typedDefinition.FilterField1;
            }

            if (!string.IsNullOrEmpty(typedDefinition.FilterField2))
            {
                typedWebpart.FilterField2 = typedDefinition.FilterField2;
            }

            if (!string.IsNullOrEmpty(typedDefinition.FilterField3))
            {
                typedWebpart.FilterField3 = typedDefinition.FilterField3;
            }

            // FilterXXXIsCustomValue
            if (typedDefinition.Filter1IsCustomValue.HasValue)
            {
                typedWebpart.Filter1IsCustomValue = typedDefinition.Filter1IsCustomValue.Value;
            }

            if (typedDefinition.Filter2IsCustomValue.HasValue)
            {
                typedWebpart.Filter2IsCustomValue = typedDefinition.Filter2IsCustomValue.Value;
            }

            if (typedDefinition.Filter3IsCustomValue.HasValue)
            {
                typedWebpart.Filter3IsCustomValue = typedDefinition.Filter3IsCustomValue.Value;
            }

            // FilterValueXXX
            if (!string.IsNullOrEmpty(typedDefinition.FilterValue1))
            {
                typedWebpart.FilterValue1 = typedDefinition.FilterValue1;
            }

            if (!string.IsNullOrEmpty(typedDefinition.FilterValue2))
            {
                typedWebpart.FilterValue2 = typedDefinition.FilterValue2;
            }

            if (!string.IsNullOrEmpty(typedDefinition.FilterValue3))
            {
                typedWebpart.FilterValue3 = typedDefinition.FilterValue3;
            }


            if (!string.IsNullOrEmpty(typedDefinition.Filter1ChainingOperator))
            {
                typedWebpart.Filter1ChainingOperator = (ContentByQueryWebPart.FilterChainingOperator)
                                                       Enum.Parse(typeof(ContentByQueryWebPart.FilterChainingOperator), typedDefinition.Filter1ChainingOperator);
            }

            if (!string.IsNullOrEmpty(typedDefinition.Filter2ChainingOperator))
            {
                typedWebpart.Filter2ChainingOperator = (ContentByQueryWebPart.FilterChainingOperator)
                                                       Enum.Parse(typeof(ContentByQueryWebPart.FilterChainingOperator), typedDefinition.Filter2ChainingOperator);
            }


            // sorting
            if (!string.IsNullOrEmpty(typedDefinition.SortBy))
            {
                typedWebpart.SortBy = typedDefinition.SortBy;
            }

            if (!string.IsNullOrEmpty(typedDefinition.SortByDirection))
            {
                typedWebpart.SortByDirection = (ContentByQueryWebPart.SortDirection)
                                               Enum.Parse(typeof(ContentByQueryWebPart.SortDirection), typedDefinition.SortByDirection);
            }

            if (!string.IsNullOrEmpty(typedDefinition.SortByFieldType))
            {
                typedWebpart.SortByFieldType = typedDefinition.SortByFieldType;
            }

            if (!string.IsNullOrEmpty(typedDefinition.GroupByDirection))
            {
                typedWebpart.GroupByDirection = (ContentByQueryWebPart.SortDirection)
                                                Enum.Parse(typeof(ContentByQueryWebPart.SortDirection), typedDefinition.GroupByDirection);
            }


            // FilterOperatorXXX
            if (!string.IsNullOrEmpty(typedDefinition.FilterOperator1))
            {
                typedWebpart.FilterOperator1 = (ContentByQueryWebPart.FilterFieldQueryOperator)
                                               Enum.Parse(typeof(ContentByQueryWebPart.FilterFieldQueryOperator), typedDefinition.FilterOperator1);
            }

            if (!string.IsNullOrEmpty(typedDefinition.FilterOperator2))
            {
                typedWebpart.FilterOperator2 = (ContentByQueryWebPart.FilterFieldQueryOperator)
                                               Enum.Parse(typeof(ContentByQueryWebPart.FilterFieldQueryOperator), typedDefinition.FilterOperator2);
            }

            if (!string.IsNullOrEmpty(typedDefinition.FilterOperator3))
            {
                typedWebpart.FilterOperator3 = (ContentByQueryWebPart.FilterFieldQueryOperator)
                                               Enum.Parse(typeof(ContentByQueryWebPart.FilterFieldQueryOperator), typedDefinition.FilterOperator3);
            }

            // FilterDisplayValueXXX

            if (!string.IsNullOrEmpty(typedDefinition.FilterDisplayValue1))
            {
                typedWebpart.FilterDisplayValue1 = typedDefinition.FilterDisplayValue1;
            }

            if (!string.IsNullOrEmpty(typedDefinition.FilterDisplayValue2))
            {
                typedWebpart.FilterDisplayValue2 = typedDefinition.FilterDisplayValue2;
            }

            if (!string.IsNullOrEmpty(typedDefinition.FilterDisplayValue3))
            {
                typedWebpart.FilterDisplayValue3 = typedDefinition.FilterDisplayValue3;
            }


            // bindings
            if (typedDefinition.ServerTemplate.HasValue)
            {
                typedWebpart.ServerTemplate = typedDefinition.ServerTemplate.ToString();
            }

            if (!string.IsNullOrEmpty(typedDefinition.ContentTypeName))
            {
                typedWebpart.ContentTypeName = typedDefinition.ContentTypeName;
            }

            if (!string.IsNullOrEmpty(typedDefinition.ContentTypeBeginsWithId))
            {
                typedWebpart.ContentTypeBeginsWithId = typedDefinition.ContentTypeBeginsWithId;
            }


            if (!string.IsNullOrEmpty(typedDefinition.WebUrl))
            {
                // go with OOTB one, no changes are required

                //var webLookup = new LookupFieldModelHandler();

                //using (var targetWeb = webLookup.GetTargetWeb(CurrentHost.HostFile.Web.Site,
                //    typedDefinition.WebUrl,
                //    typedDefinition.WebId))
                //{
                //    typedWebpart.WebUrl = targetWeb.ServerRelativeUrl;
                //}

                typedWebpart.WebUrl = typedDefinition.WebUrl;
            }

            #region list URL

            if (typedDefinition.ListId.HasGuidValue())
            {
                //typedWebpart.ListId = typedDefinition.ListId.Value;
                // fallback to ListGuid

                typedWebpart.ListGuid = typedDefinition.ListId.Value.ToString("D");
            }

            if (typedDefinition.ListGuid.HasGuidValue())
            {
                typedWebpart.ListGuid = typedDefinition.ListGuid.Value.ToString("D");
            }

            if (!string.IsNullOrEmpty(typedDefinition.ListName))
            {
                // lookup from the target web
                // fallback to ListGuid

                var webLookup = new LookupFieldModelHandler();

                using (var targetWeb = webLookup.GetTargetWeb(CurrentHost.HostFile.Web.Site,
                                                              typedDefinition.WebUrl,
                                                              typedDefinition.WebId))
                {
                    var list = targetWeb.Lists[typedDefinition.ListName];
                    typedWebpart.ListGuid = list.ID.ToString("D");
                }
            }

            if (!string.IsNullOrEmpty(typedDefinition.ListUrl))
            {
                // lookup from the target web
                // fallback to ListGuid

                var webLookup = new LookupFieldModelHandler();

                using (var targetWeb = webLookup.GetTargetWeb(CurrentHost.HostFile.Web.Site,
                                                              typedDefinition.WebUrl,
                                                              typedDefinition.WebId))
                {
                    var listUrl = SPUrlUtility.CombineUrl(targetWeb.ServerRelativeUrl, typedDefinition.ListUrl);
                    var list    = targetWeb.GetList(listUrl);

                    typedWebpart.ListGuid = list.ID.ToString("D");
                }
            }

            #endregion

            // overrides
            if (!string.IsNullOrEmpty(typedDefinition.ListsOverride))
            {
                typedWebpart.ListsOverride = typedDefinition.ListsOverride;
            }

            if (!string.IsNullOrEmpty(typedDefinition.ViewFieldsOverride))
            {
                typedWebpart.ViewFieldsOverride = typedDefinition.ViewFieldsOverride;
            }

            if (!string.IsNullOrEmpty(typedDefinition.QueryOverride))
            {
                typedWebpart.QueryOverride = typedDefinition.QueryOverride;
            }

            if (!string.IsNullOrEmpty(typedDefinition.CommonViewFields))
            {
                typedWebpart.CommonViewFields = typedDefinition.CommonViewFields;
            }

            if (typedDefinition.FilterByAudience.HasValue)
            {
                typedWebpart.FilterByAudience = typedDefinition.FilterByAudience.Value;
            }

            // misc
            if (!string.IsNullOrEmpty(typedDefinition.GroupBy))
            {
                typedWebpart.GroupBy = typedDefinition.GroupBy;
            }

            if (typedDefinition.DisplayColumns.HasValue)
            {
                typedWebpart.DisplayColumns = typedDefinition.DisplayColumns.Value;
            }
        }
 public abstract string GetWebPartLanguage(System.Web.UI.WebControls.WebParts.WebPart webPart);
        protected override void ProcessWebpartProperties(WebPart webpartInstance, WebPartDefinition webpartModel)
        {
            base.ProcessWebpartProperties(webpartInstance, webpartModel);

            var typedWebpart = webpartInstance.WithAssertAndCast<XsltListViewWebPart>("webpartInstance", value => value.RequireNotNull());
            var typedModel = webpartModel.WithAssertAndCast<XsltListViewWebPartDefinition>("webpartModel", value => value.RequireNotNull());

            var web = _host.SPLimitedWebPartManager.Web;

            // bind list
            var targetWeb = web;

            if (!string.IsNullOrEmpty(typedModel.WebUrl) || typedModel.WebId.HasGuidValue())
                targetWeb = new LookupFieldModelHandler().GetTargetWeb(web.Site, typedModel.WebUrl, typedModel.WebId);

            var list = GetTargetList(targetWeb, typedModel.ListTitle, typedModel.ListUrl, typedModel.ListId);

            if (list != null)
            {
                typedWebpart.ListName = list.ID.ToString("B").ToUpperInvariant();
                typedWebpart.TitleUrl = list.DefaultViewUrl;
            }

            // view check
            if (list != null)
            {
                SPView srcView = null;

                if (typedModel.ViewId.HasValue && typedModel.ViewId != default(Guid))
                    srcView = list.Views[typedModel.ViewId.Value];
                else if (!string.IsNullOrEmpty(typedModel.ViewName))
                    srcView = list.Views[typedModel.ViewName];

                if (srcView != null)
                {
                    if (!string.IsNullOrEmpty(typedWebpart.ViewGuid))
                    {
                        // update hidden view, otherwise we can have weird SharePoint exception
                        // https://github.com/SubPointSolutions/spmeta2/issues/487

                        var hiddenView = list.Views[new Guid(typedWebpart.ViewGuid)];

                        hiddenView.SetViewXml(srcView.GetViewXml());
                     
                        hiddenView.Update();
                    }
                    else
                    {
                        typedWebpart.ViewGuid = srcView.ID.ToString("B").ToUpperInvariant();
                    }

                    typedWebpart.TitleUrl = srcView.ServerRelativeUrl;
                }
            }

            // able to 'reset', if NULL or use list-view based URLs
            if (!string.IsNullOrEmpty(typedModel.TitleUrl))
                typedWebpart.TitleUrl = typedModel.TitleUrl;

            // weird, but it must be set to avoid null-ref exceptions
            typedWebpart.GhostedXslLink = "main.xsl";

#if !NET35
            // rest
            typedWebpart.JSLink = typedModel.JSLink;
#endif

            if (typedModel.CacheXslStorage.HasValue)
                typedWebpart.CacheXslStorage = typedModel.CacheXslStorage.Value;

            if (typedModel.CacheXslTimeOut.HasValue)
                typedWebpart.CacheXslTimeOut = typedModel.CacheXslTimeOut.Value;

#if !NET35
            if (typedModel.ShowTimelineIfAvailable.HasValue)
                typedWebpart.ShowTimelineIfAvailable = typedModel.ShowTimelineIfAvailable.Value;
#endif

            if (!string.IsNullOrEmpty(typedModel.Xsl))
            {
                typedWebpart.Xsl = typedModel.Xsl;
            }

            if (!string.IsNullOrEmpty(typedModel.XslLink))
            {
                var urlValue = typedModel.XslLink;

                typedWebpart.XslLink = urlValue;
            }

            if (!string.IsNullOrEmpty(typedModel.XmlDefinition))
            {
                typedWebpart.XmlDefinition = typedModel.XmlDefinition;
            }

            if (!string.IsNullOrEmpty(typedModel.XmlDefinitionLink))
            {
                var urlValue = typedModel.XmlDefinitionLink;
                typedWebpart.XmlDefinitionLink = urlValue;
            }

            if (!string.IsNullOrEmpty(typedModel.GhostedXslLink))
            {
                var urlValue = typedModel.GhostedXslLink;
                typedWebpart.GhostedXslLink = urlValue;
            }

            if (!string.IsNullOrEmpty(typedModel.BaseXsltHashKey))
                typedWebpart.BaseXsltHashKey = typedModel.BaseXsltHashKey;

            if (typedModel.DisableColumnFiltering.HasValue)
                typedWebpart.DisableColumnFiltering = typedModel.DisableColumnFiltering.Value;

#if !NET35
            if (typedModel.DisableSaveAsNewViewButton.HasValue)
                typedWebpart.DisableSaveAsNewViewButton = typedModel.DisableSaveAsNewViewButton.Value;

            if (typedModel.DisableViewSelectorMenu.HasValue)
                typedWebpart.DisableViewSelectorMenu = typedModel.DisableViewSelectorMenu.Value;

            if (typedModel.InplaceSearchEnabled.HasValue)
                typedWebpart.InplaceSearchEnabled = typedModel.InplaceSearchEnabled.Value;
#endif
        }
        protected override void ProcessWebpartProperties(WebPart webpartInstance, WebPartDefinition webpartModel)
        {
            base.ProcessWebpartProperties(webpartInstance, webpartModel);

            var typedWebpart = webpartInstance.WithAssertAndCast <XsltListViewWebPart>("webpartInstance", value => value.RequireNotNull());
            var typedModel   = webpartModel.WithAssertAndCast <XsltListViewWebPartDefinition>("webpartModel", value => value.RequireNotNull());

            var web = _host.SPLimitedWebPartManager.Web;

            // bind list
            var targetWeb = web;

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

            var list = GetTargetList(targetWeb, typedModel.ListTitle, typedModel.ListUrl, typedModel.ListId);

            if (list != null)
            {
                typedWebpart.ListName = list.ID.ToString("B").ToUpperInvariant();
                typedWebpart.TitleUrl = list.DefaultViewUrl;
            }

            // view check
            if (list != null)
            {
                SPView srcView = null;

                if (typedModel.ViewId.HasValue && typedModel.ViewId != default(Guid))
                {
                    srcView = list.Views[typedModel.ViewId.Value];
                }
                else if (!string.IsNullOrEmpty(typedModel.ViewName))
                {
                    srcView = list.Views[typedModel.ViewName];
                }

                if (srcView != null)
                {
                    if (!string.IsNullOrEmpty(typedWebpart.ViewGuid))
                    {
                        // update hidden view, otherwise we can have weird SharePoint exception
                        // https://github.com/SubPointSolutions/spmeta2/issues/487

                        var hiddenView = list.Views[new Guid(typedWebpart.ViewGuid)];

                        hiddenView.SetViewXml(srcView.GetViewXml());

                        hiddenView.Update();
                    }
                    else
                    {
                        typedWebpart.ViewGuid = srcView.ID.ToString("B").ToUpperInvariant();
                    }

                    typedWebpart.TitleUrl = srcView.ServerRelativeUrl;
                }
            }

            // able to 'reset', if NULL or use list-view based URLs
            if (!string.IsNullOrEmpty(typedModel.TitleUrl))
            {
                typedWebpart.TitleUrl = typedModel.TitleUrl;
            }

            // weird, but it must be set to avoid null-ref exceptions
            typedWebpart.GhostedXslLink = "main.xsl";

#if !NET35
            // rest
            typedWebpart.JSLink = typedModel.JSLink;
#endif

            if (typedModel.CacheXslStorage.HasValue)
            {
                typedWebpart.CacheXslStorage = typedModel.CacheXslStorage.Value;
            }

            if (typedModel.CacheXslTimeOut.HasValue)
            {
                typedWebpart.CacheXslTimeOut = typedModel.CacheXslTimeOut.Value;
            }

#if !NET35
            if (typedModel.ShowTimelineIfAvailable.HasValue)
            {
                typedWebpart.ShowTimelineIfAvailable = typedModel.ShowTimelineIfAvailable.Value;
            }
#endif

            if (!string.IsNullOrEmpty(typedModel.Xsl))
            {
                typedWebpart.Xsl = typedModel.Xsl;
            }

            if (!string.IsNullOrEmpty(typedModel.XslLink))
            {
                var urlValue = typedModel.XslLink;

                typedWebpart.XslLink = urlValue;
            }

            if (!string.IsNullOrEmpty(typedModel.XmlDefinition))
            {
                typedWebpart.XmlDefinition = typedModel.XmlDefinition;
            }

            if (!string.IsNullOrEmpty(typedModel.XmlDefinitionLink))
            {
                var urlValue = typedModel.XmlDefinitionLink;
                typedWebpart.XmlDefinitionLink = urlValue;
            }

            if (!string.IsNullOrEmpty(typedModel.GhostedXslLink))
            {
                var urlValue = typedModel.GhostedXslLink;
                typedWebpart.GhostedXslLink = urlValue;
            }

            if (!string.IsNullOrEmpty(typedModel.BaseXsltHashKey))
            {
                typedWebpart.BaseXsltHashKey = typedModel.BaseXsltHashKey;
            }

            if (typedModel.DisableColumnFiltering.HasValue)
            {
                typedWebpart.DisableColumnFiltering = typedModel.DisableColumnFiltering.Value;
            }

#if !NET35
            if (typedModel.DisableSaveAsNewViewButton.HasValue)
            {
                typedWebpart.DisableSaveAsNewViewButton = typedModel.DisableSaveAsNewViewButton.Value;
            }

            if (typedModel.DisableViewSelectorMenu.HasValue)
            {
                typedWebpart.DisableViewSelectorMenu = typedModel.DisableViewSelectorMenu.Value;
            }

            if (typedModel.InplaceSearchEnabled.HasValue)
            {
                typedWebpart.InplaceSearchEnabled = typedModel.InplaceSearchEnabled.Value;
            }
#endif
        }
Exemplo n.º 49
0
        //public virtual void ExportWebPart(WebPart webPart, XmlWriter writer)
        //{
        //    if (webPart == null)
        //    {
        //        throw new ArgumentNullException("webPart");
        //    }
        //    if (!this.Controls.Contains(webPart))
        //    {
        //        throw new ArgumentException(SR.GetString("UnknownWebPart"), "webPart");
        //    }
        //    if (writer == null)
        //    {
        //        throw new ArgumentNullException("writer");
        //    }
        //    if (webPart.ExportMode == WebPartExportMode.None)
        //    {
        //        throw new ArgumentException(SR.GetString("WebPartManager_PartNotExportable"), "webPart");
        //    }
        //    bool arg_79_0 = (webPart.ExportMode != WebPartExportMode.NonSensitiveData) ? false : (this.Personalization.Scope != PersonalizationScope.Shared);
        //    bool flag = arg_79_0;
        //    writer.WriteStartElement("webParts");
        //    writer.WriteStartElement("webPart");
        //    writer.WriteAttributeString("xmlns", "http://schemas.microsoft.com/WebPart/v3");
        //    writer.WriteStartElement("metaData");
        //    writer.WriteStartElement("type");
        //    Control control = webPart.ToControl();
        //    UserControl userControl = control as UserControl;
        //    if (userControl == null)
        //    {
        //        writer.WriteAttributeString("name", WebPartUtil.SerializeType(control.GetType()));
        //    }
        //    else
        //    {
        //        writer.WriteAttributeString("src", userControl.AppRelativeVirtualPath);
        //    }
        //    writer.WriteEndElement();
        //    writer.WriteElementString("importErrorMessage", webPart.ImportErrorMessage);
        //    writer.WriteEndElement();
        //    writer.WriteStartElement("data");
        //    IDictionary personalizablePropertyValues = PersonalizableAttribute.GetPersonalizablePropertyValues(webPart, PersonalizationScope.Shared, flag);
        //    writer.WriteStartElement("properties");
        //    if (!(webPart is GenericWebPart))
        //    {
        //        this.ExportIPersonalizable(writer, webPart, flag);
        //        this.ExportToWriter(personalizablePropertyValues, writer);
        //    }
        //    else
        //    {
        //        this.ExportIPersonalizable(writer, control, flag);
        //        IDictionary personalizablePropertyValues2 = PersonalizableAttribute.GetPersonalizablePropertyValues(control, PersonalizationScope.Shared, flag);
        //        this.ExportToWriter(personalizablePropertyValues2, writer);
        //        writer.WriteEndElement();
        //        writer.WriteStartElement("genericWebPartProperties");
        //        this.ExportIPersonalizable(writer, webPart, flag);
        //        this.ExportToWriter(personalizablePropertyValues, writer);
        //    }
        //    writer.WriteEndElement();
        //    writer.WriteEndElement();
        //    writer.WriteEndElement();
        //    writer.WriteEndElement();
        //}

        private static void CreateDefaultWebPart(SPWeb web, SPLimitedWebPartManager webPartManager, WebpartDefinition wp, System.Web.UI.WebControls.WebParts.WebPart concerateWP)
        {
            //TODO : find a solution to create default webpart late
            return;

            if (wp is XSLTListViewWP)
            {
                XSLTListViewWP xstlWP = wp as XSLTListViewWP;
                if (xstlWP.CreateDefaultWP)
                {
                    using (MemoryStream ms = new MemoryStream())
                    {
                        XmlWriter writer = new XmlTextWriter(ms, Encoding.UTF8);
                        concerateWP.ExportMode = System.Web.UI.WebControls.WebParts.WebPartExportMode.All;

                        webPartManager.ExportWebPart(concerateWP, writer);


                        var webPartGallery = web.GetCatalog(SPListTemplateType.WebPartCatalog);

                        //var fileStream
                        SPFile spfile = webPartGallery.RootFolder.Files.Add(wp.Title + ".webpart", ms.GetBuffer(), true);

                        // Commit
                        webPartGallery.RootFolder.Update();
                        webPartGallery.Update();
                    }
                }
            }
        }
 protected ConnectionPointInfo(System.Web.UI.WebControls.WebParts.WebPart webPart)
 {
     this._webPart = webPart;
 }
        protected override void ProcessWebpartProperties(WebPart webpartInstance, WebPartDefinition definition)
        {
            base.ProcessWebpartProperties(webpartInstance, definition);

            var typedWebpart = webpartInstance.WithAssertAndCast<ContentByQueryWebPart>("webpartInstance", value => value.RequireNotNull());
            var typedDefinition = definition.WithAssertAndCast<ContentByQueryWebPartDefinition>("webpartModel", value => value.RequireNotNull());

            // xslt links
            if (!string.IsNullOrEmpty(typedDefinition.MainXslLink))
            {
                var linkValue = typedDefinition.MainXslLink;

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

                linkValue = TokenReplacementService.ReplaceTokens(new TokenReplacementContext
                {
                    Value = linkValue,
                    Context = CurrentHost.HostFile.Web
                }).Value;

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

                typedWebpart.MainXslLink = linkValue;
            }

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

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

                linkValue = TokenReplacementService.ReplaceTokens(new TokenReplacementContext
                {
                    Value = linkValue,
                    Context = CurrentHost.HostFile.Web
                }).Value;

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

                typedWebpart.ItemXslLink = linkValue;
            }

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

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

                linkValue = TokenReplacementService.ReplaceTokens(new TokenReplacementContext
                {
                    Value = linkValue,
                    Context = CurrentHost.HostFile.Web
                }).Value;

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

                typedWebpart.HeaderXslLink = linkValue;
            }

            // styles
            if (!string.IsNullOrEmpty(typedDefinition.ItemStyle))
                typedWebpart.ItemStyle = typedDefinition.ItemStyle;

            if (!string.IsNullOrEmpty(typedDefinition.GroupStyle))
                typedWebpart.GroupStyle = typedDefinition.GroupStyle;

            // cache settings
            if (typedDefinition.UseCache.HasValue)
                typedWebpart.UseCache = typedDefinition.UseCache.Value;

            if (typedDefinition.CacheXslStorage.HasValue)
                typedWebpart.CacheXslStorage = typedDefinition.CacheXslStorage.Value;

            if (typedDefinition.CacheXslTimeOut.HasValue)
                typedWebpart.CacheXslTimeOut = typedDefinition.CacheXslTimeOut.Value;

            // item limit
            if (typedDefinition.ItemLimit.HasValue)
                typedWebpart.ItemLimit = typedDefinition.ItemLimit.Value;

            // mappings
            if (!string.IsNullOrEmpty(typedDefinition.DataMappings))
                typedWebpart.DataMappings = typedDefinition.DataMappings;

            if (!string.IsNullOrEmpty(typedDefinition.DataMappingViewFields))
                typedWebpart.DataMappingViewFields = typedDefinition.DataMappingViewFields;

            // misc
            if (typedDefinition.ShowUntargetedItems.HasValue)
                typedWebpart.ShowUntargetedItems = typedDefinition.ShowUntargetedItems.Value;

            if (typedDefinition.PlayMediaInBrowser.HasValue)
                typedWebpart.PlayMediaInBrowser = typedDefinition.PlayMediaInBrowser.Value;

            if (typedDefinition.UseCopyUtil.HasValue)
                typedWebpart.UseCopyUtil = typedDefinition.UseCopyUtil.Value;

            // FilterTypeXXX
            if (!string.IsNullOrEmpty(typedDefinition.FilterType1))
                typedWebpart.FilterType1 = typedDefinition.FilterType1;

            if (!string.IsNullOrEmpty(typedDefinition.FilterType2))
                typedWebpart.FilterType2 = typedDefinition.FilterType2;

            if (!string.IsNullOrEmpty(typedDefinition.FilterType3))
                typedWebpart.FilterType3 = typedDefinition.FilterType3;

            // FilterFieldXXX
            if (!string.IsNullOrEmpty(typedDefinition.FilterField1))
                typedWebpart.FilterField1 = typedDefinition.FilterField1;

            if (!string.IsNullOrEmpty(typedDefinition.FilterField2))
                typedWebpart.FilterField2 = typedDefinition.FilterField2;

            if (!string.IsNullOrEmpty(typedDefinition.FilterField3))
                typedWebpart.FilterField3 = typedDefinition.FilterField3;

            // FilterXXXIsCustomValue
            if (typedDefinition.Filter1IsCustomValue.HasValue)
                typedWebpart.Filter1IsCustomValue = typedDefinition.Filter1IsCustomValue.Value;

            if (typedDefinition.Filter2IsCustomValue.HasValue)
                typedWebpart.Filter2IsCustomValue = typedDefinition.Filter2IsCustomValue.Value;

            if (typedDefinition.Filter3IsCustomValue.HasValue)
                typedWebpart.Filter3IsCustomValue = typedDefinition.Filter3IsCustomValue.Value;

            // FilterValueXXX
            if (!string.IsNullOrEmpty(typedDefinition.FilterValue1))
                typedWebpart.FilterValue1 = typedDefinition.FilterValue1;

            if (!string.IsNullOrEmpty(typedDefinition.FilterValue2))
                typedWebpart.FilterValue2 = typedDefinition.FilterValue2;

            if (!string.IsNullOrEmpty(typedDefinition.FilterValue3))
                typedWebpart.FilterValue3 = typedDefinition.FilterValue3;

            if (!string.IsNullOrEmpty(typedDefinition.Filter1ChainingOperator))
            {
                typedWebpart.Filter1ChainingOperator = (ContentByQueryWebPart.FilterChainingOperator)
                   Enum.Parse(typeof(ContentByQueryWebPart.FilterChainingOperator), typedDefinition.Filter1ChainingOperator);
            }

            if (!string.IsNullOrEmpty(typedDefinition.Filter2ChainingOperator))
            {
                typedWebpart.Filter2ChainingOperator = (ContentByQueryWebPart.FilterChainingOperator)
                   Enum.Parse(typeof(ContentByQueryWebPart.FilterChainingOperator), typedDefinition.Filter2ChainingOperator);
            }

            // sorting
            if (!string.IsNullOrEmpty(typedDefinition.SortBy))
                typedWebpart.SortBy = typedDefinition.SortBy;

            if (!string.IsNullOrEmpty(typedDefinition.SortByDirection))
                typedWebpart.SortByDirection = (ContentByQueryWebPart.SortDirection)
                    Enum.Parse(typeof(ContentByQueryWebPart.SortDirection), typedDefinition.SortByDirection);

            if (!string.IsNullOrEmpty(typedDefinition.SortByFieldType))
                typedWebpart.SortByFieldType = typedDefinition.SortByFieldType;

            if (!string.IsNullOrEmpty(typedDefinition.GroupByDirection))
            {
                typedWebpart.GroupByDirection = (ContentByQueryWebPart.SortDirection)
                    Enum.Parse(typeof(ContentByQueryWebPart.SortDirection), typedDefinition.GroupByDirection);
            }

            // FilterOperatorXXX
            if (!string.IsNullOrEmpty(typedDefinition.FilterOperator1))
            {
                typedWebpart.FilterOperator1 = (ContentByQueryWebPart.FilterFieldQueryOperator)
                    Enum.Parse(typeof(ContentByQueryWebPart.FilterFieldQueryOperator), typedDefinition.FilterOperator1);
            }

            if (!string.IsNullOrEmpty(typedDefinition.FilterOperator2))
            {
                typedWebpart.FilterOperator2 = (ContentByQueryWebPart.FilterFieldQueryOperator)
                    Enum.Parse(typeof(ContentByQueryWebPart.FilterFieldQueryOperator), typedDefinition.FilterOperator2);
            }

            if (!string.IsNullOrEmpty(typedDefinition.FilterOperator3))
            {
                typedWebpart.FilterOperator3 = (ContentByQueryWebPart.FilterFieldQueryOperator)
                    Enum.Parse(typeof(ContentByQueryWebPart.FilterFieldQueryOperator), typedDefinition.FilterOperator3);
            }

            // FilterDisplayValueXXX

            if (!string.IsNullOrEmpty(typedDefinition.FilterDisplayValue1))
                typedWebpart.FilterDisplayValue1 = typedDefinition.FilterDisplayValue1;

            if (!string.IsNullOrEmpty(typedDefinition.FilterDisplayValue2))
                typedWebpart.FilterDisplayValue2 = typedDefinition.FilterDisplayValue2;

            if (!string.IsNullOrEmpty(typedDefinition.FilterDisplayValue3))
                typedWebpart.FilterDisplayValue3 = typedDefinition.FilterDisplayValue3;

            // bindings
            if (typedDefinition.ServerTemplate.HasValue)
                typedWebpart.ServerTemplate = typedDefinition.ServerTemplate.ToString();

            if (!string.IsNullOrEmpty(typedDefinition.ContentTypeName))
                typedWebpart.ContentTypeName = typedDefinition.ContentTypeName;

            if (!string.IsNullOrEmpty(typedDefinition.ContentTypeBeginsWithId))
                typedWebpart.ContentTypeBeginsWithId = typedDefinition.ContentTypeBeginsWithId;

            if (!string.IsNullOrEmpty(typedDefinition.WebUrl))
            {
                // go with OOTB one, no changes are required

                //var webLookup = new LookupFieldModelHandler();

                //using (var targetWeb = webLookup.GetTargetWeb(CurrentHost.HostFile.Web.Site,
                //    typedDefinition.WebUrl,
                //    typedDefinition.WebId))
                //{
                //    typedWebpart.WebUrl = targetWeb.ServerRelativeUrl;
                //}

                typedWebpart.WebUrl = typedDefinition.WebUrl;
            }

            #region list URL

            if (typedDefinition.ListId.HasGuidValue())
            {
                //typedWebpart.ListId = typedDefinition.ListId.Value;
                // fallback to ListGuid

                typedWebpart.ListGuid = typedDefinition.ListId.Value.ToString("D");
            }

            if (typedDefinition.ListGuid.HasGuidValue())
            {
                typedWebpart.ListGuid = typedDefinition.ListGuid.Value.ToString("D");
            }

            if (!string.IsNullOrEmpty(typedDefinition.ListName))
            {
                // lookup from the target web
                // fallback to ListGuid

                var webLookup = new LookupFieldModelHandler();

                using (var targetWeb = webLookup.GetTargetWeb(CurrentHost.HostFile.Web.Site,
                    typedDefinition.WebUrl,
                    typedDefinition.WebId))
                {
                    var list = targetWeb.Lists[typedDefinition.ListName];
                    typedWebpart.ListGuid = list.ID.ToString("D");
                }
            }

            if (!string.IsNullOrEmpty(typedDefinition.ListUrl))
            {
                // lookup from the target web
                // fallback to ListGuid

                var webLookup = new LookupFieldModelHandler();

                using (var targetWeb = webLookup.GetTargetWeb(CurrentHost.HostFile.Web.Site,
                    typedDefinition.WebUrl,
                    typedDefinition.WebId))
                {
                    var listUrl = SPUrlUtility.CombineUrl(targetWeb.ServerRelativeUrl, typedDefinition.ListUrl);
                    var list = targetWeb.GetList(listUrl);

                    typedWebpart.ListGuid = list.ID.ToString("D");
                }
            }

            #endregion

            // overrides
            if (!string.IsNullOrEmpty(typedDefinition.ListsOverride))
                typedWebpart.ListsOverride = typedDefinition.ListsOverride;

            if (!string.IsNullOrEmpty(typedDefinition.ViewFieldsOverride))
                typedWebpart.ViewFieldsOverride = typedDefinition.ViewFieldsOverride;

            if (!string.IsNullOrEmpty(typedDefinition.QueryOverride))
                typedWebpart.QueryOverride = typedDefinition.QueryOverride;

            if (!string.IsNullOrEmpty(typedDefinition.CommonViewFields))
                typedWebpart.CommonViewFields = typedDefinition.CommonViewFields;

            if (typedDefinition.FilterByAudience.HasValue)
                typedWebpart.FilterByAudience = typedDefinition.FilterByAudience.Value;
        }