コード例 #1
0
ファイル: HistoryItem.cs プロジェクト: ForNeVeR/hell-api
        /// <summary>
        /// Creates instance of history item and loads its content from
        /// database.
        /// </summary>
        /// <param name="contact">
        /// Contact with whom history this item is associated.
        /// </param>
        /// <param name="hEvent">
        /// Miranda event handle.
        /// </param>
        internal static HistoryItem Load(Contact contact,
            IntPtr hEvent)
        {
            if (hEvent == IntPtr.Zero)
                throw new ArgumentException("hEvent cannot be zero.");

            // Miranda interface for freeing strings:
            var mmi = MMInterface.GetMMI();

            using (var pDbEventInfo = new AutoPtr(Marshal.AllocHGlobal(
                Marshal.SizeOf(typeof (DBEventInfo)))))
            {
                var result = Plugin.m_CallService(
                    "DB/Event/Get",
                    hEvent,
                    pDbEventInfo);
                if (result != IntPtr.Zero)
                    throw new DatabaseException();

                var eventInfo =
                    (DBEventInfo)
                        Marshal.PtrToStructure(pDbEventInfo, typeof (DBEventInfo));

                var type = (HistoryItemType)eventInfo.eventType;
                var direction = (eventInfo.flags & DBEventInfo.DBEF_SENT) != 0
                    ? HistoryItemDirection.Outgoing
                    : HistoryItemDirection.Incoming;
                var historyItem = new HistoryItem(type, direction);
                if (type == HistoryItemType.Message)
                {
                    // Get message text:
                    using (var pDbEventGetText = new AutoPtr(
                        Marshal.AllocHGlobal(Marshal.SizeOf(
                            typeof (DBEventGetText)))))
                    {
                        var getText = new DBEventGetText();
                        getText.dbei = pDbEventInfo;
                        getText.datatype = Utils.DBVT_WCHAR;

                        Marshal.StructureToPtr(getText, pDbEventGetText, false);

                        var pString = Plugin.m_CallService(
                            "DB/Event/GetText",
                            IntPtr.Zero,
                            pDbEventGetText);
                        mmi.mmi_free(pString);

                        var message = Marshal.PtrToStringUni(pString);
                        historyItem.MessageText = message;
                    }
                }

                historyItem.Contact = contact;
                historyItem.DateTime = new DateTime(1970, 1, 1)
                    .AddSeconds(eventInfo.timestamp);

                return historyItem;
            }
        }
コード例 #2
0
ファイル: HistoryItem.cs プロジェクト: ForNeVeR/hell-api
 /// <summary>
 /// Compares this history item with other.
 /// </summary>
 /// <param name="other">
 /// History item to be compared to
 /// </param>
 /// <returns>
 /// true if objects are equal.
 /// </returns>
 public bool Equals(HistoryItem other)
 {
     if (ReferenceEquals(null, other)) return false;
     if (ReferenceEquals(this, other)) return true;
     return Equals(other.Contact, Contact) &&
            Equals(other.Type, Type) &&
            Equals(other.MessageText, MessageText) &&
            other.DateTime.Equals(DateTime);
 }