Sunday February 05 , 2012

Category: Engineering

Strong product recommendation: Awesomium and AwesomiumSharp

We do a lot of WPF/Silverlight development here at ManageScope and we’ve been working with the Facebook C# SDK in *****, our new product that’s inflight. And yes — no comment.

We recently ran into an issue with WPF’s WebBrowser not handling #’s introduced by Facebook in URIs during the authentication process. There’s been some good discussion on workarounds … host Winforms (which for WPF proponents like me is disappointing) … distribute your FB app secret and use “code” instead of “token” on responsetype and then exchange the code for a token. Smart thinking, but I wasn’t really satisfied with either solution.

So for community commentary and/or usage, I thought we’d share what we did to resolve this issue. We decided to use AwesomiumSharp and Awesomium’s WebControl in-place of the WebBrowser control from Microsoft.

A little background … when you’re using WebBrowser in WPF, you’re using Internet Explorer. There are many great products from Microsoft, but I’ve never included Internet Explorer among them. Not only do I have to use a browser I’m not fond of, but I’m stuck using whatever version of IE the user has installed on their deck. Not a great experience if you have users like we do who thought a recent upgrade from IE6 was awesome (just poking fun, guys!).

Awesomium on the other hand uses the Chromium project as its basis. And for those of you who are Chrome users, you know the elegance and speed that Chromium provides since you’re using the same foundation. And these kind and extremely talented gentlemen at Awesomium have also worked to provide a .NET wrapper around this Chromium base as well as a pre-rolled WebControl that replaces the functionality of WebBrowser. There are a ton of great things to say about this product … but they say it better here.

Long story short, the issue went away immediately and we were getting our access token without distributing our app secret or hosting the Winform’s browser. Not to mention we got a better control for creating integrated client and Internet experiences and we’re using something other than IE under the hood. If you’re developing in WPF, check it out.

 

New Release: Clamr! 2010 enables calling from Outlook with Gmail Chat!

The best calling, texting and file transfer solution for Outlook 2010 just got even better. We’ve just released a new version of Clamr! 2010 that allows you to use Gmail Chat as your phone for calling! No need for a separate phone number – e.g. Skype, mobile, desk – and no reason to leave Outlook 2010 and your keyboard in order to actually take the call.

Download the latest version of Clamr! 2010 on the Download & Buy page. Install the new client and service. Enable your Gmail Chat (click the photo to go to the Gmail Chat instructions site) and then set your forwarding number in Clamr! 2010 Options to “Gmail Chat — username@gmail.com”.

Now all your calls will be handled with Gmail Chat (for free, we might add) and you can use your computer speakers and microphone to handle your calls.

Also — for those of you who use non-US date formats locally … we now support non-US date formats as well.

Enjoy the sweetness of Clamr! And stay tuned as we add more features and functionality …

 

Dealing with errors …

Dealing with error gracefully is the mark of a mature organization. This article is a very interesting discussion with a Google search executive about how Google deals with error from anorganizational and technological perspective.

 

Sending Multiple Notifications in SharePoint

In Sharepoint there are many ways of notifying a user when an item gets updated on a list.

1. Setting up an alert.

2. Subscribing to an RSS Feed.

3. Using workflow via the List Settings, Sharepoint Designer or Visual Studio.

All these mechanisms have their pros and cons, but there is one thing that is not supported by any of them: Sending a notification to users when they are set up in a multi-choice person list within the SAME list. Additionally, 1 and 2 above require the user to set this up manually on their own, while 3  is much more complicated and has limitations. I chose to write my own Event Receiver in order to accomplish this task.

I won’t go into the details of creating an Event Receiver in Sharepoint and publishing it, since there is already a lot of documentation on this on the internet. In my example, the List Name is called “MyDocs” and the field that contains the users is called “Notifiers” (note: this field can contains a multiple users).

    public class MyDocsItemEventReceiver : SPItemEventReceiver
    {

        public override void ItemUpdated(SPItemEventProperties properties)
        {
            base.ItemUpdated(properties);
            DisableEventFiring();

            try
            {
                SPListItem myDocsItem = properties.ListItem;
                var notifiers = myDocsItem["Notifiers"] as SPFieldUserValueCollection;
                SendEmailToNotifiers(notifiers);
            }
            finally
            {
                EnableEventFiring();
            }

        }
        private void SendEmailToNotifiers(SPFieldUserValueCollection _notifiers)
        {

            if (_notifiers != null)
            {
                List<string> _notifierList = new List<string>();

                foreach (SPFieldUserValue _notifier in _notifiers)
                {
                    if (!string.IsNullOrEmpty(_notifier.User.Email))
                        _notifierList.Add(_notifier.User.Email.Trim());
                }

                if (_notifierList.Count > 0)
                {
                    SmtpClient _smtpClient = new SmtpClient();
                    _smtpClient.Host = "email_server_name";
                    _smtpClient.Port = 25;
                    _smtpClient.EnableSsl = false;

                    MailMessage _mailMessage = new MailMessage();

                    foreach (string _reviewer in _notifierList)
                    {
                        _mailMessage.To.Add(new MailAddress(_reviewer));
                    }

                    _mailMessage.From = new MailAddress("fromaddress@company.com");
                    _mailMessage.Subject = "the subject line";
                    _mailMessage.Body = "the body of the email";

                    _smtpClient.Send(_mailMessage);
                }
            }

        }
}
You will need to import “System.Net.Mail” and get the mail server/port info, but it gives you the basis of accomplishing a very flexible solution for sending emails from an updated list. A possible use is to send notifications from Project Server 2007 when Issues/Risks are updated. The Event Receiver above will send emails to the users that are defined in the list item itself without having to create another list for lookup or managing a sharepoint group which usually required elevated privileges.
Enjoy!
 

Sharepoint (WSS/MOSS) Auditing VIEW On List Items

Recently I had a request from a client to log/audit when a user clicks on anything on a Sharepoint site. At first I thought, this will be easy, I will just turn on Auditing and select to log all VIEWs on all Items and then produce a report based on the Audit log. Well, things were not that simple.

It appears that Sharepoint logs VIEWs for Document Libraries very well, but fails miserably for logging VIEWs on every other type of Item, including Picture Libraries (this is true for WSS and MOSS). Basically, Sharepoint logs the List that the Item is contained in, but there is no logging as to the actual Item that was clicked on. So after Googling around bit I found that there was very little information on how to get around this and wanted to post a solution that works for most Items, but still fails for certain ones, e.g. Discussion Items for one. Maybe someone else here can enhance this solution to grab the missing ones.

My solution involves a custom HttpModule (not an HttpHandler), that inspects the IIS requests and if can load the Sharepoint context, Site, List and Item, then it manually adds the Audit Entry via the Sharepoint Object Model. This approach is only needed for non Document Libraries, since the regular Sharepoint Auditing does a better job at logging these types of Items.

The code for the HttpModule is below. You will need to do a bit of research on how to deploy an HttpModule, but there is plenty of information on this on the web. Essentially, you will need to compile this, strong name it, deploy it to the GAC and add an entry to the web.config of the Sharepoint site you wish to Audit.

Enjoy!

Imports System.Web
Imports Microsoft.SharePoint

Public Class AuditViewHttpModule
    Implements IHttpModule

    Public Sub Dispose() Implements System.Web.IHttpModule.Dispose

    End Sub

    Public Sub Init(ByVal context As System.Web.HttpApplication) _
    Implements System.Web.IHttpModule.Init

        AddHandler context.PreRequestHandlerExecute, _
        AddressOf Application_PreRequestHandlerExecute
    End Sub

    Private Sub Application_PreRequestHandlerExecute( _
        ByVal _source As Object, ByVal e As EventArgs)

        Dim _application As HttpApplication = Nothing
        Dim _context As HttpContext = Nothing

        Try

            _application = CType(_source, HttpApplication)
            _context = _application.Context

            Dim _site As SPSite = SPContext.Current.Site
            Dim _list As SPList = SPContext.Current.List
            Dim _item As SPListItem = SPContext.Current.ListItem

            If Not _site Is Nothing Then
                If Not _list Is Nothing Then
                    If Not _item Is Nothing Then
                        If _
                        _list.BaseTemplate <> _
                        SPListTemplateType.DocumentLibrary _
                        Then

                            _list.Audit.WriteAuditEvent( _
                            SPAuditEventType.View, "", "")
                        End If
                    End If
                End If
            End If

        Catch ex As Exception
            ' handle the error otherwise your
            ' sharepoint pages will crash!
        End Try
    End Sub

End Class