Exemple #1
0
        static void Main(string[] argv)
        {
            Jabber = new JabberService();

            appDir  = Path.GetDirectoryName(Application.ExecutablePath) + "\\";
            dataDir = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\miniConf\\";
            System.IO.Directory.CreateDirectory(dataDir);
            System.IO.Directory.CreateDirectory(dataDir + "Received Files");
            System.IO.Directory.CreateDirectory(dataDir + "Temporary Data");
            System.IO.Directory.CreateDirectory(dataDir + "Avatars");
            System.IO.Directory.CreateDirectory(dataDir + "Emoticons");
            tempDir = dataDir + "Temporary Data\\";

            singleInstanceMutex = new Mutex(true, "*****@*****.**");
            if (singleInstanceMutex.WaitOne(TimeSpan.Zero, true))
            {
                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault(false);
                MainWnd   = new Form1();
                isAutorun = !(argv.Length < 1 || argv[0] != "/autostart");
                //MainWnd.Show();
                //MainWnd.onIni(shouldShow);
                //if (!shouldShow) MainWnd.Hide();
                Application.Run(MainWnd);
                singleInstanceMutex.ReleaseMutex();
            }
            else
            {
                WindowHelper.PostMessage((IntPtr)WindowHelper.HWND_BROADCAST,
                                         WindowHelper.WM_SHOWME, IntPtr.Zero, IntPtr.Zero);
            }
        }
        public void OnPrivateMessage(agsXMPP.protocol.client.Message msg)
        {
            try {
                agsXMPP.protocol.x.muc.User x = (agsXMPP.protocol.x.muc.User)msg.SelectSingleElement(typeof(agsXMPP.protocol.x.muc.User));
                if (x != null && x.Invite != null)
                {
                    Program.Jabber.muc.handleInvitation(msg, x.Invite);
                    return;
                }

                // Ignore Chatstate notifications if no conversation is open
                if (!msg.HasTag("body") && !this.HasWindow(msg.From))
                {
                    return;
                }

                Jid relevantJid = msg.From;
                // XEP-0280, Message Carbons
                var carbonsSent     = msg.SelectSingleElement("sent", JabberService.URN_CARBONS);
                var carbonsReceived = msg.SelectSingleElement("received", JabberService.URN_CARBONS);
                if (carbonsSent != null)
                {
                    msg         = (agsXMPP.protocol.client.Message)carbonsSent.SelectSingleElement("message", true);
                    relevantJid = msg.To;
                }
                else if (carbonsReceived != null)
                {
                    msg         = (agsXMPP.protocol.client.Message)carbonsReceived.SelectSingleElement("message", true);
                    relevantJid = msg.From;
                }

                string dt = JabberService.GetMessageDt(msg);
                if (msg.HasTag("body"))
                {
                    Program.db.InsertMessage(relevantJid.Bare, msg.Id, msg.From, msg.Body, dt);
                }

                DirectMessageForm dmfrm = GetWindow(relevantJid);
                dmfrm.onMessage(msg); dmfrm.Show();
                if (msg.HasTag("body"))
                {
                    dmfrm.Activate();
                }
                else
                {
                    if (!String.IsNullOrEmpty(msg.Subject))
                    {
                        dmfrm.onNotice("Subject set: " + msg.Subject.Replace("<", "&lt;"));
                    }
                    else if (msg.Error != null)
                    {
                        dmfrm.onNotice("An error occured: " + msg.Error.ToString().Replace("<", "&lt;"));
                    }
                    //else dmfrm.onNotice("Unknown message stanza: " + msg.ToString().Replace("<", "&lt;"));
                }
            } catch (Exception ex) {
                return;
            }
        }