Пример #1
0
        private void LogginMsn(string name, string password)
        {
            menuItemLoggOfMSN.Enabled = true;
            msnMessenger = new Messenger();
            try
            {
                msnMessenger.ConnectionFailure += new DotMSN.Messenger.ConnectionFailureHandler(msnMessenger_ConnectionFailure);
                msnMessenger.MailboxStatus += new DotMSN.Messenger.MailboxStatusHandler(msnMessenger_MailboxStatus);
                msnMessenger.ErrorReceived += new DotMSN.Messenger.ErrorReceivedHandler(msnMessenger_ErrorReceived);
                msnMessenger.ListReceived += new DotMSN.Messenger.ListReceivedHandler(msnMessenger_ListReceived);
                // Event när contact har lagts till..
                msnMessenger.ContactAdded += new DotMSN.Messenger.ContactAddedHandler(msnMessenger_ContactAdded);
                // setup the callbacks
                // we log when someone goes online
                msnMessenger.ContactOnline += new Messenger.ContactOnlineHandler(ContactOnline);

                msnMessenger.ContactOffline += new DotMSN.Messenger.ContactOfflineHandler(ContactOffline);

                // we want to do something when we have a conversation
                msnMessenger.ConversationCreated += new DotMSN.Messenger.ConversationCreatedHandler(msnMessenger_ConversationCreated);

                // notify us when synchronization is completed
                msnMessenger.SynchronizationCompleted += new Messenger.SynchronizationCompletedHandler(OnSynchronizationCompleted);

                DotMSN.Owner owner = new DotMSN.Owner(logginDialog.MsnName, logginDialog.MsnPassword);

                owner.ScreenNameChanged += new DotMSN.Contact.ScreenNameChangedHandler(Owner_ScreenNameChanged);
                owner.StatusChanged		+= new DotMSN.Contact.StatusChangedHandler(Owner_StatusChanged);

                DotMSN.Connection connection = new DotMSN.Connection("64.4.13.58", 1863);

                // everything is setup, now connect to the msnMessenger service
                msnMessenger.Connect(connection, owner);

                msnMessenger.InitialStatus = MSNStatus.Online;

                //Log.Text += "Connected!\r\n";

                // synchronize the whole list.
                // remember you can only do this once per session!
                // after synchronizing the initial status will be set.
                msnMessenger.SynchronizeList();

                /* uncomment this when you want to automatically add
                      people who have added you to their contactlist on your own
                      contactlist. (remember the pop-up dialog in MSN Messenger client when someone adds you, this is the 'automatic' method)
                */	foreach(Contact contact in
                        msnMessenger.GetListEnumerator(MSNList.ReverseList))
                    {
                        msnMessenger.AddContact(contact.Mail);
                    }

            }
            catch(MSNException)
            {
                MessageBox.Show(this, "Problem vid MSN inloggingen!", "Connection Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                Loggout(Protokoll.ALL);
                // in case of an error, report this to the user (or developer)
                //MessageBox.Show(this, "Connecting failed: " + e.ToString());
            }
        }