kythyria / msnp-sharp

Automatically exported from code.google.com/p/msnp-sharp
0 stars 0 forks source link

CreateConversation does not generate a switchboard #222

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Hi,
I have recently discovered Msnp-sharp and tried to use it in an easy situation. 
But somehow I can't manage to create a conversation object with a Switchboard 
object(to initiate a conversation myself). I managed to answer conversation or 
send offline messages but even after a carefull look at the example I can't 
figure out where is the problem.

I tried to go back to an esier application to focus on my problem. Here is the 
code:

using System;
using System.Threading;
using MSNPSharp;

namespace ClassLibrary1
{
    public class Class1
    {

        public static void SendIm()
        {
            var messenger = new Messenger();
            var message = new TextMessage("This works!! Give Andy a dollar... Now please..");
            messenger.Credentials = new Credentials("RPITBot@hotmail.co.uk", "32572rpit", MsnProtocol.MSNP18);
            messenger.Nameserver.BotMode = false;
            messenger.Nameserver.AutoSynchronize = true;
            messenger.Connect();
            Thread.Sleep(5000);

            try
            {
                // here is the problem conv always have null as switchboard
                Conversation conv = messenger.CreateConversation();
                conv.Switchboard.Invite(messenger.ContactList[0]);
                Thread.Sleep(5000);
                conv.Switchboard.SendTextMessage(message);
            }

            catch (NullReferenceException nullex)
            {
                //fall back email or logging   
            }
            catch (Exception ex)
            {
                //fall back email or logging
            }
        }
    }
}

What steps will reproduce the problem?
1. Create a console project and Add the reference to the Dll
2. Call SendIm in the main function
3. Run/Debug...

What is the expected output? What do you see instead?
I was expecting the switchboard value of my conversation object to be not null.

What version of the product are you using? (MSNPSharp, OS, Mono etc.)
3.1.0.RC MSNPSHARP_310_RC
3.0.3    MSNPSHARP_303_RELEASE

Windows 7

VS2008

Is your code check out from SVN or download from our download site?
Recovered from the download site

Please provide any additional information below:
My account have a contact so there is no problem on this side.

Original issue reported on code.google.com by Harme...@gmail.com on 6 Oct 2010 at 7:40

GoogleCodeExporter commented 9 years ago
Hello,

The idea behind MSNPSharp's degin is event driven, message oriented model. If 
you insist to let it work in a procedure oriented way, you will run into a lot 
of difficulties. Please separate the procedure of initializing your Messenger 
object and sending IM. You should always using the same Messenger object to 
communicate with others instead of create one and login every time the SendIm() 
was called. 

Your null switchboad problem is, at the time you want to send a message, the 
remote user has not yet connected to the switchboard. And one more, the example 
client for 3.1 does not use Conversation and switchboard to send message 
anymore (Although they are still supported if you use them properly), you can 
send a message with following code:

TextMessage message = new TextMessage("Hello");
ConversationID conversationIdentifier = Messenger.MessageManager.GetID(contact);
conversationIdentifier = 
Messenger.MessageManager.SendTextMessage(ConversationID, message);

Please read the example client again, especially for ConversationForm.cs, I 
think that's all you want.

Thank you.

Original comment by freezing...@gmail.com on 7 Oct 2010 at 1:45

GoogleCodeExporter commented 9 years ago
Sorry, there's some typo in my last post, the code should be:
TextMessage message = new TextMessage("Hello");
ConversationID conversationIdentifier = Messenger.MessageManager.GetID(contact);
conversationIdentifier = 
Messenger.MessageManager.SendTextMessage(conversationIdentifier, message);

The contact is and Contact object, get from your contact list.

Original comment by freezing...@gmail.com on 7 Oct 2010 at 1:47

GoogleCodeExporter commented 9 years ago
Thank you for the direction, it helped a lot. I switched to the 3.1 syntax and 
it talked to me a lot more. 
My proper application is actually event driven, this example was really an 
attempt to understand why my switchboard wasn't instantiated properly.

So to conclude, thanks a lot problem solved.

Everything works smoothly now. You really do a great job with msnp-sharp.

Original comment by Harme...@gmail.com on 7 Oct 2010 at 8:46

GoogleCodeExporter commented 9 years ago
You are welcome, and one more suggestion: I recommend you check out our code 
from the trunk of SVN repository, because we get some bug fixed there, but not 
yet release for downloading. 

Original comment by freezing...@gmail.com on 8 Oct 2010 at 1:51