Example #1
0
        /// <summary>
        /// Sends simple message to contact.
        /// </summary>
        /// <param name="message">
        /// Message string to send.
        /// </param>
        public void SendMessage(string message)
        {
            var eventInfo = new DBEventInfo();
            eventInfo.eventType = DBEventInfo.EVENTTYPE_MESSAGE;
            eventInfo.flags = DBEventInfo.DBEF_SENT;
            eventInfo.szModule = Protocol;
            eventInfo.timestamp = (int)(DateTime.Now.ToUniversalTime() -
                                        new DateTime(1970, 1, 1)).TotalSeconds;

            using (var pString =
                new AutoPtr(Marshal.StringToHGlobalAnsi(message)))
            using (var pDBEventInfo = new AutoPtr(
                Marshal.AllocHGlobal(Marshal.SizeOf(typeof (DBEventInfo)))))
            {
                eventInfo.cbBlob = (uint)message.Length + 1;
                eventInfo.pBlob = pString;

                Marshal.StructureToPtr(eventInfo, pDBEventInfo, false);

                Plugin.m_CallService("DB/Event/Add", hContact, pDBEventInfo);
                Plugin.m_CallContactService(hContact, "/SendMsg", IntPtr.Zero, pString);
            }
        }
Example #2
0
        private int EventAdded(IntPtr wParam, IntPtr lParam)
        {
            IntPtr hContact = wParam;
            IntPtr hDBEvent = lParam;

            int blobSize = this.CallService("DB/Event/GetBlobSize",
                hDBEvent, IntPtr.Zero).ToInt32();

            using (var pBlob = new AutoPtr(Marshal.AllocHGlobal(blobSize)))
            using (var pDBEventInfo = new AutoPtr(
                Marshal.AllocHGlobal(Marshal.SizeOf(typeof (DBEventInfo)))))
            {
                var eventInfo = new DBEventInfo();
                eventInfo.pBlob = pBlob;
                eventInfo.cbBlob = (uint)blobSize;

                Marshal.StructureToPtr(eventInfo, pDBEventInfo, false);
                this.CallService("DB/Event/Get", hDBEvent, pDBEventInfo);

                eventInfo = (DBEventInfo)Marshal.PtrToStructure(pDBEventInfo,
                    typeof (DBEventInfo));

                if (eventInfo.eventType == DBEventInfo.EVENTTYPE_MESSAGE)
                {
                    using (var pDBEventGetText = new AutoPtr(
                        Marshal.AllocHGlobal(Marshal.SizeOf(
                            typeof (DBEventGetText)))))
                    {
                        var getText = new DBEventGetText();
                        getText.dbei = pDBEventInfo;
                        getText.datatype = Utils.DBVT_ASCIIZ;
                        getText.codepage = 1251;

                        Marshal.StructureToPtr(getText, pDBEventGetText,
                            false);

                        IntPtr pString = this.CallService(
                            "DB/Event/GetText", IntPtr.Zero, pDBEventGetText);
                        string message = Marshal.PtrToStringAnsi(pString);

                        mmi.mmi_free(pString);

                        var contact = new Contact(hContact);

                        DateTime eventTime = new DateTime(1970, 1, 1).
                            AddSeconds(eventInfo.timestamp).ToUniversalTime();
                        if ((eventInfo.flags & DBEventInfo.DBEF_SENT) != 0)
                        {
                            if (MessageSentEvent != null)
                                MessageSentEvent(contact, eventTime, message);
                        }
                        else
                        {
                            if (MessageReceivedEvent != null)
                                MessageReceivedEvent(contact, eventTime,
                                    message);
                        }
                    }
                }
            }

            return 0;
        }
Example #3
0
        /// <summary>
        /// Saves this history item to database for selected contact.
        /// </summary>
        public void Save()
        {
            var eventInfo = new DBEventInfo();
            eventInfo.eventType = (ushort)Type;
            eventInfo.flags = DBEventInfo.DBEF_SENT;
            eventInfo.szModule = Contact.Protocol;
            eventInfo.timestamp = (int)(DateTime -
                                        new DateTime(1970, 1, 1)).TotalSeconds;

            using (var pDbEventInfo = new AutoPtr(
                Marshal.AllocHGlobal(Marshal.SizeOf(typeof (DBEventInfo)))))
            {
                if (MessageText != null)
                {
                    using (var pString =
                        new AutoPtr(Marshal.StringToHGlobalAnsi(MessageText)))
                    {
                        eventInfo.cbBlob = (uint)MessageText.Length + 1;
                        eventInfo.pBlob = pString;
                    }
                }

                Marshal.StructureToPtr(eventInfo, pDbEventInfo, false);
                Plugin.m_CallService(
                    "DB/Event/Add",
                    Contact.hContact,
                    pDbEventInfo);
            }
        }