Modify Silverlight Slideshow code

Apr 2, 2010 at 11:02 PM

I may be asking too much here but can someone give me some direction.  I am using the silverlight slideshow extension and it is written to only handle displaying on post OR pages.  I want to add logic that will allow it to do both.  

So, if request is for a post then do this

code.....

if request is for a page then do this

code.....

Below is the relevant section of the code.  My question is where would I insert the logic and how to deliniate between post request and page request.

Thanks in advance from a rookie.

 

/// <summary>
    /// Adds a Silverlight Slide Show to the post.
    /// </summary>
    public SilverlightSlideShow()
          
                {
                    Post.Serving += new EventHandler<ServingEventArgs>(Post_Serving); //For Posts
                      //BlogEngine.Core.Page.Serving += new EventHandler<ServingEventArgs>(Post_Serving); //For Pages
                }

                private void Post_Serving(object sender, ServingEventArgs e)
                {
                    if (e.Location != ServingLocation.PostList && e.Location != ServingLocation.SinglePost)  // for post
                    //if (e.Location != ServingLocation.SinglePage) //for pages
                        return;

                    String regex = @"\[silverlightslideshow:.*?]";
                    MatchCollection matches = Regex.Matches(e.Body, regex);

                    if (matches.Count == 0)
                        return;

                    AddJavascriptToHeader();

                    for (int i = 0; i < matches.Count; i++)
                    {

                        Int32 length = "[silverlightslideshow:".Length;
                        String slides = matches[i].Value.Substring(length, matches[i].Value.Length - length - 1);
                        slides = @"{url: """ + contentRoot + @"/Configuration.xml""}";

                        String slideshow = @"<div id=""silverlightslideshow_{0}"">
		                                        <script type='text/javascript'>
			                                        new SlideShow.Control(new SlideShow.XmlConfigProvider({1}));
		                                        </script>
                                            </div>";

                        e.Body = e.Body.Replace(matches[i].Value, String.Format(slideshow,i, slides));
                    }
    }

 

 

/// <summary>
    /// Adds a Silverlight Slide Show to the post.
    /// </summary>
    public SilverlightSlideShow()
          
                {
                    Post.Serving += new EventHandler<ServingEventArgs>(Post_Serving); //For Posts
                      //BlogEngine.Core.Page.Serving += new EventHandler<ServingEventArgs>(Post_Serving); //For Pages
                }
                private void Post_Serving(object sender, ServingEventArgs e)
                {
                    if (e.Location != ServingLocation.PostList && e.Location != ServingLocation.SinglePost)  // for post
                    //if (e.Location != ServingLocation.SinglePage) //for pages
                        return;
                    String regex = @"\[silverlightslideshow:.*?]";
                    MatchCollection matches = Regex.Matches(e.Body, regex);
                    if (matches.Count == 0)
                        return;
                    AddJavascriptToHeader();
                    for (int i = 0; i < matches.Count; i++)
                    {
                        Int32 length = "[silverlightslideshow:".Length;
                        String slides = matches[i].Value.Substring(length, matches[i].Value.Length - length - 1);
                        slides = @"{url: """ + contentRoot + @"/Configuration.xml""}";
                        String slideshow = @"<div id=""silverlightslideshow_{0}"">
                                       <script type='text/javascript'>
                                       new SlideShow.Control(new SlideShow.XmlConfigProvider({1}));
                                       </script>
                                            </div>";
                        e.Body = e.Body.Replace(matches[i].Value, String.Format(slideshow,i, slides));
                    }
    }

 

 

Coordinator
Apr 3, 2010 at 3:09 AM

If you uncomment that one line of code (remove the two forward slashes)

//BlogEngine.Core.Page.Serving += new EventHandler<ServingEventArgs>(Post_Serving); //For Pages

then Post_Serving() will get called for both Posts and Pages.  You could then use that other piece of commented code:

//if (e.Location != ServingLocation.SinglePage) //for pages
to determine if you're handling a Page or Post.

Apr 5, 2010 at 6:16 PM

So Simple.

 

Thanks