Playing with Facebook Connect BlogEngine.NET Extension

by Bobbi Perreault 11. January 2010 02:47
Share on Facebook

Mouthful!  Long subject, short post.  I need to be able to pull comments out of Facebook Notes and back into a BlogEngine.NET site. 

I'm starting by playing around with an extension for BlogEngine.NET that incorporates the Facebook produced comments widget.  This extension provides an admin page for the blog owner to enter application API key, and if enabled will incorporate Facebook Comments widget after every post.  There's a different implementation (V2) of this extension here.

If you'd like the code to incorporate FaceBook comments widget as a BlogEngine.NET extension, there's a link below. 

And here are a few notes on the code.

This extension uses
admin tool - User controls\FacebookNotes\adminNotesComments.aspx
extension code:  \BL\Extensions\FaceBookNotes.cs

Copy the files into included folders.  It won't work until you plug in your Facebook APIKey into the admin page.  You'll find the admin page on extensions admin list after you copy these files to their folders and restart your blog application.

Facebook instructions for embedding the comments widget directly:
http://developers.facebook.com/news.php?blog=1&story=198

FacebookNotes_1.0.zip (6.92 kb)

Happy Thanksgiving

by Bobbi Perreault 25. November 2009 05:42
Share on Facebook

Tags:

Identify the Active Directory Username from Silverlight app from Sharepoint

by Bobbi Perreault 25. November 2009 01:10
Share on Facebook

I needed to know the Active Directory username of the current user from my Silverlight app.  The Silverlight control is running from a Sharepoint site. 

It seems that this isn't as easy as you would think.  I found several ways, but the one I ended up using wasn't one of them.

  1. Page.User.Identity.Name.Split('\\')[1];  - this would work from code behind or even in alligator tags in front end - but my Sharepoint page wouldn't allow them.
  2. var wshshell=new ActiveXObject("wscript.shell");
    var username=wshshell.ExpandEnvironmentStrings("%usern ame%");

For i As Integer = 0 To Request.ServerVariables.Count - 1
Response.Write(Request.ServerVariables.Keys(i) & " : <br /> [ " & Request.ServerVariables(i) & " ] <br /> ")
Next

This one is totally hard to do under any type of security scenario.

  1. HttpContext.Current.Profile.UserName  - again, this would work from code behind or even in alligator tags in front end - but my Sharepoint page wouldn't allow them.
  2. <script type="text/vbscript" language="VBscript">
    Dim X
    set X = createobject("WSCRIPT.Network")
    dim U
    U=x.UserName
    'MsgBox "username: " & U
    </script>
    <script type="text/javascript" language="Javascript">
        var a = U;
        $("#name").text(a.toString());
    </script>

Hard to even print these two that use active x!  But for the sake of completeness, here they are.

AND - The way I used:

When my Silverlight app is loaded, the first thing I do is send a web service request to add a list item to a log list.  The list has only one field, that is Title.  So I add an "application opened" record to the log.   What I get in return is an xml confirmation that the record was added - the confirmation contains the name of the logged in user - which is their active directory name.  I just parse the correct element out "ows_Author" using XLinq and have what I needed.

Is this weird?  Cause I wouldn't be surprised!  Anyway, it works for me.

Tags:

How To

Use BlogEngine.Net as a Content Management System

by Bobbi Perreault 17. September 2009 18:23
Share on Facebook

I've used BlogEngine.Net for a CMS a few times now and I'm happy with the way it has worked out for the very small business sites that I maintain.   I'm comfortable in this programming environment and so that's why I choose it over WordPress.

Its easy to modify so that each BlogEngine.Net category is directed to a separate page.  So, in the case of one of my customers when they want a news page that they can update and also a tips page that they can update – I set it up like this.  Create a category called news and a category called tips in the Admin area.

Here's how I set it up.  In the [User controls] folder is a control called PostList.ascx.  I added a property to this control called PageCategory.

Here's the code from the .aspx page which will set the PageCategory properly for the page:

 
<%@ Register Src="User controls/linksSide.ascx" TagName="linksSide" TagPrefix="uc2" %>
<%@ Register Src="User controls/PostList.ascx" TagName="PostList" TagPrefix="uc1" %>
<%@ Import namespace="BlogEngine.Core"%>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
<div id="divError" runat="Server" />
<uc2:linksSide ID="LinksSide1" PageCategory="cleaningtips" runat="server" />
<uc1:PostList ID="PostList1" PageCategory="cleaningtips" runat="server" />
</asp:Content>

 Here's the code which implements the PageCategory property inside of PostList.ascx. 

Basically, it all comes down to making sure the only posts which display are those which  match the category.

  ( Linq would work great on this)


foreach (Category cat in Category.Categories)
{

string name = cat.Title;
if (name.Equals(PageCategory))
{

List<Post> visiblePosts = cat.Posts.FindAll(delegate(Post p) { return p.IsPublished; });
if (Posts == null || visiblePosts.Count == 0)
{
hlPrev.Visible = false;
hlNext.Visible = false;
return;
}
else
{
hlPrev.Visible = true;hlNext.Visible = true;
}

LoadAll(visiblePosts);
break;

}
}
 

Tags:

Silverlight Elastic List Control

by Bobbi Perreault 30. May 2009 11:59
Share on Facebook

For this contest entry, How People Use Global’s Millennium, I chose to present the data using the Elastic List concept described here.  This is a post on how I built a piece of the Elastic List control, that is the controlling ListBox.

I was asked to share the source, Sure, no problem.  If you'd like the whole package, it's right here.

Elastic List ListBox

The ListBox that controls this chart needs to do three things:  1. Display the items in descending order of occurrance.  2. Color the items in respect to their occurrance and 3. Size the items in respect to their occurrance.

The Phizzpop contest entry provided a DataVisualization project which was to serve as the starting point.  In this project was the datasource, Customersurveys.xml.

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<CustomerSurveys xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
 <Survey>
  <CustomerId>1</CustomerId>
  <Device>DX100 MP3 Player</Device>
  <Month>9</Month>
  <Year>2008</Year>
  <TimeUsed>20</TimeUsed>
  <Activity>Driving</Activity>
 </Survey>

The Xaml for the ListBox:

 

<PP4:ListControl x:Name="ActivityList" Title="Activities" Width="200" Height="343" VerticalAlignment="Top" AllClicked="ActivityList_AllClicked" FilterClicked="ActivityList_FilterClicked" SelectionChanged="ActivityList_SelectionChanged" LockClicked="ActivityList_LockClicked" Margin="0,0,5,0"/>

 

 

Loading a list from the xml file:

XmlReader reader = XmlReader.Create(s); XElement elementRoot = XElement.Load(reader); IEnumerable<DataItemXml> theBarItems = from element in elementRoot.Descendants("Survey") select new DataItemXml {  CustomerId = (int)element.Element("CustomerId"),  Device = (string)element.Element("Device"),  Month = (short)element.Element("Month"),  Year = (short)element.Element("Year"),  TimeUsed = (short)element.Element("TimeUsed"),  Activity = (string)element.Element("Activity") }; _barItems = theBarItems.ToList<DataItemXml>();

 

Use the list _barItems, to load our declared ListBox, ActivityList using this structure:

public class DataItem
 {
  public int Index { get; set; }
  public string Description { get; set; }
  public double Value { get; set; }
  public double Percentage { get; set; }
  public double ItemHeight { get; set; }
  public SolidColorBrush ItemColor { get; set; }
 }

.

 private List<DataItem> getWeightedActivityList()
{
 List<DataItemXml> activities = _barItems.GroupBy(b => b.Activity).Select(g => g.First()).ToList();
 // compute the percentage size of each activity
 List<DataItem> dataItems = new List<DataItem>();
 foreach (DataItemXml activity in activities)
 {
  DataItem dataItem = new DataItem();
  dataItem.Index = activities.IndexOf(activity);
  dataItem.Description = activity.Activity;
  double total = _barItems.Sum(b => b.TimeUsed);
  double thisTotal = _barItems.Where(b => b.Activity == activity.Activity).Sum(b => b.TimeUsed);
  dataItem.Percentage = thisTotal / total;
  dataItem.Value = thisTotal;
  
  double itemheight = 15 + (dataItem.Percentage * 100);
  dataItem.ItemHeight = itemheight;
  dataItem.ItemColor = getColorFromPercentage(dataItem.Percentage);
  dataItems.Add(dataItem);
 }
 dataItems.Sort(delegate(DataItem d1, DataItem d2) { return d2.Percentage.CompareTo(d1.Percentage); });
 return dataItems;
}

In the ListBox control, here is how we bind our ListItems so that they will use the items we initialized for Sizing and Coloring:

 <ListBox x:Name="ItemsList"  Margin="0,5,0,0" 
  Style="{StaticResource BlueListBoxStyle}" 
  SelectionChanged="ItemsList_SelectionChanged" Width="190" Height="270" >
<ListBox.ItemTemplate>
 <DataTemplate>
  <StackPanel Margin="0,0,0,0" Background="{Binding ItemColor}" Orientation="Horizontal" Height="{Binding ItemHeight}">
<TextBlock Text="{Binding Description}" x:Name="Body" Style="{StaticResource listcolumn}" Width="100"  />
<TextBlock Text="{Binding Value}" x:Name="Weight" Style="{StaticResource listcolumn}" Width="50"  />
  </StackPanel>
 </DataTemplate>
</ListBox.ItemTemplate>
 </ListBox>

A Simple Silverlight Image Rotator

by Bobbi Perreault 24. April 2009 19:05
Share on Facebook

There are a million and three photo display Silverlight applications out there.  And here's one more.  I just wanted my own.  I wanted one that I can load up the images in Xaml and push go with.  Here it is,

First, define all my images in Xaml

  <Canvas x:Name="ImageDisplay" Width="600" Height="450">
        <Image Margin="0,0,0,0" Source="images/IMG_1989.JPG"  Width="600" Height="450" x:Name="image" Opacity="0" />
        <Image Margin="0,0,0,0" Source="images/IMG_1990.JPG"  Width="600" Height="450" Opacity="0"/>
        <Image Margin="0,0,0,0" Source="images/IMG_1991.JPG"  Width="600" Height="450" Opacity="0"/>
 </Canvas>

 

Second, wire it up in the code behind:

public Page()        
{
InitializeComponent();
this.Loaded += new RoutedEventHandler(Page_Loaded);
}
void Page_Loaded(object sender, RoutedEventArgs e)
{
//start the animations
beginTheFirst();
}
private void beginTheFirst()
{
int icnt = 0;
//tell the imageRotater what it will manage.
Canvas container = ImageDisplay;
mcarousel = new imageRotater();
for (int i = container.Children.Count - 1; i >= 0; i--)
{
FrameworkElement childFE = container.Children[i] as FrameworkElement;
if (childFE is Image)
{
mcarousel.CreateItem( childFE, "resources" + icnt.ToString(), this);
icnt++;
}
}
//start the first.
mcarousel.StartRotating();
}

Everything hinges on this SwitchImage function, but that’s all.  The objects manage themselves after that.

public void SwitchImage(FrameworkElement image, FrameworkElement oldimage)

{

if (image == null)

return;

if (oldimage != null)

{

FadeOutEffect fadeOut = new FadeOutEffect();

fadeOut.Start(oldimage);

}

mImage = image;

FadeInEffect fadeIn = new FadeInEffect();

fadeIn.Start(image);

}

If you’d like the source, you can download it here: http://www.faxt.com/silverlight/code/countrylife.zip

Tags:

 

RSS Feed FriendFeed