Exemple #1
0
 public static string GetSourceType(this PageViewerWebPart wp)
 {
     return(wp.SourceType.ToString());
 }
        /// <summary>
        /// Replaces the content of a <see cref="PageViewerWebPart" /> web part.
        /// </summary>
        /// <param name="web">The web that the file belongs to.</param>
        /// <param name="file">The file that the web part is associated with.</param>
        /// <param name="settings">The settings object containing user provided parameters.</param>
        /// <param name="wp">The web part whose content will be replaced.</param>
        /// <param name="regex">The regular expression object which contains the search pattern.</param>
        /// <param name="manager">The web part manager.  This value may get updated during this method call.</param>
        /// <param name="wasCheckedOut">if set to <c>true</c> then the was checked out prior to this method being called.</param>
        /// <param name="modified">if set to <c>true</c> then the web part was modified as a result of this method being called.</param>
        /// <returns>The modified web part.  This returned web part is what must be used when saving any changes.</returns>
        internal static WebPart ReplaceValues(SPWeb web,
            SPFile file,
            Settings settings,
            PageViewerWebPart wp,
            Regex regex,
            ref SPLimitedWebPartManager manager,
            ref bool wasCheckedOut,
            ref bool modified)
        {
            if (string.IsNullOrEmpty(wp.ContentLink))
                return wp;

            bool isLinkMatch = regex.IsMatch(wp.ContentLink);

            if (!isLinkMatch)
                return wp;

            string content = wp.ContentLink;
            string result = content;

            if (!string.IsNullOrEmpty(content))
                result = regex.Replace(content, settings.ReplaceString);

            Logger.Write("Match found: File={0}, WebPart={1}, Replacement={2} => {3}",
                              file.ServerRelativeUrl, wp.Title, content, result);
            if (!settings.Test)
            {
                if (file.CheckOutType == SPFile.SPCheckOutType.None)
                {
                    file.CheckOut();
                    wasCheckedOut = false;
                }
                // We need to reset the manager and the web part because a checkout (now or from an earlier call)
                // could mess things up so safest to just reset every time.
                manager.Web.Dispose(); // manager.Dispose() does not dispose of the SPWeb object and results in a memory leak.
                manager.Dispose();
                manager = web.GetLimitedWebPartManager(file.Url, PersonalizationScope.Shared);

                wp.Dispose();
                wp = (PageViewerWebPart)manager.WebParts[wp.ID];

                wp.ContentLink = result;

                modified = true;
            }
            return wp;
        }