Chunliang


Hello,

is here anyone who knows how to send a Activity request with dotMSN in C# code example thanks a lot!







Re: how to send a Activity request with dotMSN in C#

Sebastien WARIN


Implement this function :
Code Snippet

private const string ActivityTypeGuid = "{6A13AF9C-5308-4F35-923A-67E8DDA40C2F}";
private P2PTransferSession SendActivityInternal(P2PMessageSession p2pSession, string localContact, string remoteContact, string activityNumber, string activityName)
{
MSNSLPHandler handlerObject = (MSNSLPHandler)p2pSession.GetHandler(typeof(MSNSLPHandler));

MSNObject msnObject = new MSNObject();
msnObject.Creator = localContact;

// set class variables
MSNSLPTransferProperties properties = new MSNSLPTransferProperties();
properties.SessionId = (uint)(new Random().Next(50000, int.MaxValue));

properties.LocalContact = localContact;
properties.RemoteContact = remoteContact;

properties.DataType = DataTransferType.Unknown;

MSNSLPMessage slpMessage = new MSNSLPMessage();

string activityUrl = activityNumber + ";1;" + activityName;
byte[] contextData = UnicodeEncoding.Unicode.GetBytes(activityUrl);
string base64Context = Convert.ToBase64String(contextData, 0, contextData.Length);
properties.Context = base64Context;

properties.LastBranch = Guid.NewGuid();
properties.CallId = Guid.NewGuid();

slpMessage.StartLine = "INVITE MSNMSGR:" + remoteContact + " MSNSLP/1.0";
slpMessage.To = "<msnmsgr:" + remoteContact + ">";
slpMessage.From = "<msnmsgr:" + localContact + ">";
slpMessage.Via = "MSNSLP/1.0/TLP ;branch=" + properties.LastBranch.ToString("B").ToUpper(System.Globalization.CultureInfo.InvariantCulture);
slpMessage.CSeq = 0;
slpMessage.CallId = properties.CallId.ToString("B").ToUpper(System.Globalization.CultureInfo.InvariantCulture);
slpMessage.MaxForwards = 0;
slpMessage.ContentType = "application/x-msnmsgr-sessionreqbody";

slpMessage.Body = "EUF-GUID: " + ActivityTypeGuid + "\r\nSessionID: " + properties.SessionId + "\r\nSChannelState: 0\r\nAppID: " + activityNumber + "\r\n" +
"Context: " + base64Context + "\r\n\r\n";

ConsoleBot.WriteLine("Sending activity ivitation with SID:" + properties.SessionId);

P2PMessage p2pMessage = new P2PMessage();
p2pMessage.InnerMessage = slpMessage;

// set the size, it could be more than 1202 bytes. This will make sure it is split in multiple messages by the processor.
p2pMessage.MessageSize = (uint)slpMessage.GetBytes().Length;

// store the transferproperties
handlerObject.AddTransferProperties(properties.CallId, properties);

// create a transfer session to handle the actual data transfer
P2PTransferSession session = Factory.CreateP2PTransferSession();
session.MessageSession = (P2PMessageSession)handlerObject.MessageProcessor;
session.SessionId = properties.SessionId;

handlerObject.MessageSession.AddTransferSession(session);

// set the data stream to write to
session.DataStream = msnObject.OpenStream();
session.IsSender = false;
session.CallId = properties.CallId;

handlerObject.OnTransferSessionCreated(session);

// send the invitation
handlerObject.MessageSession.SendMessage(p2pMessage);

return session;
}


And call him by this code :

Code Snippet

P2PMessageSession session = messenger.P2PHandler.GetSession(messenger.Credentials.Account, e.Sender.Mail);
// To see AppID list: http://siebe.bot2k3.net/docs/ url=appids.html
P2PTransferSession p2psession = SendActivityInternal(session, messenger.Credentials.Account, e.Sender.Mail, "10361021", "Activity Test");


Best Regards,

Sebastien WARIN