Messenger Plus! Live and .NET working together

Posted on 8:34pm 11/30/2007 by Bruno Silva in Programming

I and some colleagues are working in a university assignment which involves manipulating Windows Live Messenger messages. Since the official API doesn’t allow us to alter the messages we had to use Messenger Plus! Live. In the other hand the rest of our project was meant to be developed in .NET because we wanted to use web-services and other .NET features that can help us to do a decent project without too much trouble.

I will briefly try to explain to you how you can create a .NET class library and use it in a Messenger Plus! Plugin (which is written in Javascript).

First of all you have to create your class library in Visual Studio 2005.

Visual Studio 2005

Then write down your login into the new Class1.cs file (or Class1.vb, if you prefer programming in that awful language :-P) I have highlighted some elements that you must have. You will notice the declaration of an interface. Honestly, I haven’t tried this code without it, and in the place I learned how to do this they mentioned the need to have it.

using System;

using System.Collections;

using System.Text;

using System.Runtime.InteropServices;

using System.Collections.Generic;

namespace myFirstPlugin{

    public interface PluginInterface{

        string addToLog(string sender,string recipient,string message);

        string getFullLog();

    }

    [ClassInterface(ClassInterfaceType.AutoDual)]

    public class Plugin{

        public class Message{

            string sender;

            string recipient;

            string message;

            public Message(string sender, string recipient, string message){

                this.sender = sender;

                this.recipient = recipient;

                this.message = message;

            }

        }

        private List<Message> _log new List<Message>();

        public string addToLog (string sender, string recipient, string message){

            _log.Add(new Message(sender, recipient, message));

            return sender + recipient + message;

        }

        public string getFullLog(){

            string log = “”;

            foreach (Message msg in _log)

                                  log += msg.sender + “>” + msg.recipient + “: “ + msg.message + “\r\n”;

                            return log;

        }

    }

}

All the extra code will be used to create an ActiveX control, which can be used in Javascript code in a HTML page or in this case in a Messenger Plus! plugin.

You can compile your class just to make sure it is ok, but to use it in your plugin the easy way is to compile it from Visual Studi 2005 Command Prompt. Run it with administrator privileges.

 

Visual Studio 2005 Command Prompt

Change to your Class Library Project directory. You will have to create a Key.

> sn -k sgKey.snk 

Compile your class signing your Assembly with a Strong Name. This way you will avoid some security warnings when you register your Assembly and use your ActiveX control.

> csc /t:library Plugin.cs /keyfile:sgkey.snk

This next step must be done in every computer where you install your plugin. In VS Command Prompt the executable is in PATH. In other computers, you can find it in \Windows\Microsoft.NET\Framework\v2.0.XXXXX\.

> regasm Plugin.dll /tlb:PluginNet.dll /codebase

(after this command you won’t be able to delete Plugin.dll. You must unregister the Assembly using: regasm /unregister Plugin.dll)

Ok. The .Net part is done! Now let’s do some Javascript.

When you reach this step you must install Messenger Plus! Live. Then create a new plugin like shown in the picture.

Messenger Plus! Live

In the script window you can create an object of your class and use it as you want! In the middle of the code I have some comments that can help you to understand myFirstPlugin.

var myPlugin; //store object during chat session

var lastSent; //just a trick to prevent an outbound message from being seen as an inbound message. Kind of a Messenger Plus! bug…

function OnEvent_ChatWndCreated(ChatWnd){

    //new chat window -> new plugin object

    myPlugin= new ActiveXObject(“MyFirstPlugin.Plugin”);

}

function OnEvent_ChatWndDestroyed(ChatWnd){

    //in the end print out the log

    Debug.Trace(myPlugin.getFullLog());

}

function OnEvent_ChatWndReceiveMessage(ChatWnd,Origin,Message,MessageKind){

    //messageKind == 1 is a user message. Other values means nudges, winks, etc.

    if(MessageKind==1 && lastSent!=Message){

        //get your buddy e-mail. Assumes that you’re not in a group chat

        var e = new Enumerator(ChatWnd.Contacts);

        var email;

        for(; !e.atEnd(); e.moveNext()) {

            var Contact = e.item();

            email= Contact.Email;

        }

        //log you message into the plugin

        myPlugin.addToLog(Messenger.MyEmail,email,Message);

        return Message;

    }else{

        lastSent=“”;

        return Message;

    }

}

//Same stuff as above

function OnEvent_ChatWndSendMessage(ChatWnd,Message){

    var e = new Enumerator(ChatWnd.Contacts);

    var email;

    for(; !e.atEnd(); e.moveNext()) {

        var Contact = e.item();

        email= Contact.Email;

    }

    myPlugin.addToLog(email,Messenger.MyEmail,Message);

    lastSent=Message;

    return Message;

}

In the end enable your plugin and pray that it works :)

Silverlight 2.0

Posted on 8:20pm 11/29/2007 by Bruno Silva in Microsoft, Programming, Silverlight

Dado o vasto conjunto de novas funcionalidades ao até agora chamado Silverlight 1.1, ainda em Alpha Stage, a Microsoft decidiu que não fazia sentido chamar versão 1.1 a um produto completamente diferente da versão 1.0. Portanto o que até agora era chamado Silverlight 1.1 passará a ser referido como Silverlight 2.0. A grande diferença nesta versão é que ao invés de Javascript é utilizado .NET como base para a programação do comportamento das aplicações.

Algumas funcionalidades referidas foram

WPF UI Framework: O Silverlight vai comportar uma maior fatia dos componentes do WPF. Vai também permitir databinding, e incluir suporte para templates e skinning.

Rich Controls: Como seria de esperar vão estar disponíveis mais controlos para simplificar a contrução das aplicações. Neste momento basicamente temos caixas de texto e reprodutores de multimédia. Esperam-se controlos como Datagrids, ProgressBar, TabControl, Checkbox, Radiobutton, etc.

Rich Networking Support: Suporte para comunicações em REST, POX, RSS, e WebServices. Vai ser também permitido o “Cross domain network access”. Ou seja, uma aplicação Silverlight pode beber recursos em domínios que não sejam o local.

Rich Base Class Library Support: Collections, IO, generics, threading, globalization, XML, local storage, etc. Como já se sabia o LINQ será suportado.

MSN SOM SISTEMA - Música com andamento

Posted on 9:25am 11/27/2007 by Bruno Silva in Events, Microsoft

MSN Som Sistema MSN Som Sistema

Como forma de divulgação do novo portal MSN em Português, em parceria com a Mega FM e a Sic Radical, a Microsoft está a promover um evento amanhã. Evento… ok não sei se é a melhor designação. Basicamente vão haver 3 autocarros pelas ruas de Lisboa com música ao vivo no seu interior. Vão ser oferecidos vários prémios. Vejam detalhes no site da Mega FM (http://www.mega.fm/LdestaqueSel.asp?id=1257).

Imagine Cup @ Instituto Superior Técnico

Posted on 10:32pm 11/25/2007 by Bruno Silva in Events, Imagine Cup, Microsoft, Popfly, Silverlight

Imagine Cup 2008

Vai haver um evento sobre o concurso Imagine Cup (edição 2008).
Além de um representante da Microsoft, vão falar concorrentes do IST da edição anterior, e vai haver uma sessão sobre Silverlight e Popfly.

Auditório A5 – IST-Taguspark
Quarta-Feira
28 de Novembro
15h00

No mesmo dia pelas 10 horas vai haver um evento semelhante no pólo da Alameda.

Agenda
15h00 – Imagine Cup 2008 (Vitor Santos, Microsoft Portugal)
Apresentação do maior concurso internacional para estudantes de tecnologia – O que é o Imagine Cup? Como posso participar? Quais as categorias existentes? E como decorrem?

15h45 – Team Sevric – Imagine Cup na 1ª Pessoa (João Severino e Ricardo Vieira, Instituto Superior Técnico)
Conhece um dos projectos finalistas da edição anterior do Imagine Cup. Ouve da boca de que quem já participou o que o concurso te pode proporcionar e aproveita os conselhos de quem chegou perto da vitória nacional!

16h00 – Microsoft Silverlight & Popfly (Bruno Silva, Instituto Superior Técnico)
Se o nome desta apresentação não te diz nada, ou muito pouco aproveita! Vem conhecer a nova proposta da Microsoft para a Internet do futuro. O mote é criar interfaces apelativas e funcionais.

Conto com a presença de quem estiver disponível. Apareçam!

Eu no Live Search e no Google

Posted on 4:13pm 11/24/2007 by Bruno Silva in Curiosities, Web

Andei a pesquisar pelo meu nome no Live Search e no Google para ver se este novo domínio já aparecia num ranking decente.

Realmente já aparece na 1ª página do Google e do Live. No entanto queria chamar à atenção para outro “pormenor” com o qual me deparei. O meu blog do Blogger (AKA do Google) nem sequer aparece até á página 10 de resultados do Live Search. Artigos do meu blog que no google aparecem facilmente nos resultados de uma pesquisa mais genérica, no Live Search nem sequer aparecem.

Das duas uma, ou o google benificia imenso os conteúdos “da casa” ou o Live Search irradica os resultados referentes ao Blogger…

A nice and useless geek trick

Posted on 3:54pm 11/24/2007 by Bruno Silva in Curiosities, Funny

Go into any website with images on it. (Like Flickr).

In the address bar type

javascript:R=0; x1=.1; y1=.05; x2=.25; y2=.24; x3=1.6; y3=.24; x4=300; y4=200; x5=300; y5=200; DI= document.images; DIL=DI.length; function A(){for(i=0; i<DIL; i++){DIS=DI[ i ].style; DIS.position=’absolute’; DIS.left=Math.sin(R*x1+i*x2+x3)*x4+x5; DIS.top=Math.cos(R*y1+i*y2+y3)*y4+y5}R++}setInterval(’A()’,5 ); void(0)

Then you get something like this.

Completly uselessI know… But i thought it was funny :)

© Bruno Silva | Powered by Wordpress