Ejemplo n.º 1
0
        private void GetAllAttachments()
        {
            int count;

            int ret = Interop.Messages.GetAttachmentCount(_messageHandle, out count);

            if (ret != (int)MessagesError.None)
            {
                Log.Error(Globals.LogTag, "Failed to get attachment count, Error - " + (MessagesError)ret);
                MessagesErrorFactory.ThrowMessagesException(ret, _messageHandle);
            }

            string path;
            int    type;
            var    attachmentList = new List <MessagesAttachment>();

            for (int i = 0; i < count; i++)
            {
                ret = Interop.Messages.GetAttachment(_messageHandle, i, out type, out path);
                if (ret != (int)MessagesError.None)
                {
                    Log.Error(Globals.LogTag, "Failed to get attachment, Error - " + (MessagesError)ret);
                    MessagesErrorFactory.ThrowMessagesException(ret, _messageHandle);
                }

                var attachmentItem = new MessagesAttachment((MediaType)type, path);
                attachmentList.Add(attachmentItem);
            }

            _attachment = attachmentList;
        }
Ejemplo n.º 2
0
        private void AddAttachment(MessagesAttachment attach)
        {
            int ret = Interop.Messages.AddAttachment(_messageHandle, (int)attach.Type, attach.FilePath);

            if (ret != (int)MessagesError.None)
            {
                Log.Error(Globals.LogTag, "Failed to add attachment, Error - " + (MessagesError)ret);
                MessagesErrorFactory.ThrowMessagesException(ret, _messageHandle);
            }
        }
Ejemplo n.º 3
0
        private void AddAddress(MessagesAddress address)
        {
            int ret = Interop.Messages.AddAddress(_messageHandle, address.Number, (int)address.Type);

            if (ret != (int)MessagesError.None)
            {
                Log.Error(Globals.LogTag, "Failed to add address, Error - " + (MessagesError)ret);
                MessagesErrorFactory.ThrowMessagesException(ret, _messageHandle);
            }
        }
Ejemplo n.º 4
0
        private void GetAllAddresses()
        {
            int count;

            int ret = Interop.Messages.GetAddressCount(_messageHandle, out count);

            if (ret != (int)MessagesError.None)
            {
                Log.Error(Globals.LogTag, "Failed to get address count, Error - " + (MessagesError)ret);
                MessagesErrorFactory.ThrowMessagesException(ret, _messageHandle);
            }

            string number;
            int    type;
            var    To   = new Collection <MessagesAddress>();
            var    Cc   = new Collection <MessagesAddress>();
            var    Bcc  = new Collection <MessagesAddress>();
            var    From = new Collection <MessagesAddress>();

            for (int i = 0; i < count; i++)
            {
                ret = Interop.Messages.GetAddress(_messageHandle, i, out number, out type);
                if (ret != (int)MessagesError.None)
                {
                    Log.Error(Globals.LogTag, "Failed to get address, Error - " + (MessagesError)ret);
                    MessagesErrorFactory.ThrowMessagesException(ret, _messageHandle);
                }

                var addressItem = new MessagesAddress((RecipientType)type, number);
                switch ((RecipientType)type)
                {
                case RecipientType.To:
                    To.Add(addressItem);
                    break;

                case RecipientType.Cc:
                    Cc.Add(addressItem);
                    break;

                case RecipientType.Bcc:
                    Bcc.Add(addressItem);
                    break;

                default:
                    From.Add(addressItem);
                    break;
                }
            }

            _to   = To;
            _cc   = Cc;
            _bcc  = Bcc;
            _from = From;
        }
Ejemplo n.º 5
0
        private void initialize()
        {
            int ret;

            ret = Interop.Messages.OpenService(out _MessageServiceHandle);
            if (ret != (int)MessagesError.None)
            {
                Log.Error(Globals.LogTag, "Failed to open service, Error - " + (MessagesError)ret);
                MessagesErrorFactory.ThrowMessagesException(ret);
            }
        }
Ejemplo n.º 6
0
        internal Message(MessageType type)
        {
            int ret = Interop.Messages.CreateMessage((int)type, out _messageHandle);

            if (ret != (int)MessagesError.None)
            {
                Log.Error(Globals.LogTag, "Failed to create message handle, Error - " + (MessagesError)ret);
                MessagesErrorFactory.ThrowMessagesException(ret);
            }

            GC.AddMemoryPressure(_memoryPressureSize);
        }
Ejemplo n.º 7
0
        internal Task <SentResult> SendMessageAsync(Message message, bool saveToSentbox)
        {
            TaskCompletionSource <SentResult> task = new TaskCompletionSource <SentResult>();
            int requestId = 0;

            lock (this)
            {
                requestId = _requestId++;
                _sendMessageTaskSource[requestId] = task;
            }
            message.FillHandle();
            IntPtr messageHandle = message.GetHandle();
            int    ret           = Interop.Messages.SendMessage(_MessageServiceHandle, messageHandle, saveToSentbox, _messageSentCallback, (IntPtr)requestId);

            if (ret != (int)MessagesError.None)
            {
                Log.Error(Globals.LogTag, "Failed to send message, Error - " + (MessagesError)ret);
                _sendMessageTaskSource.Remove(requestId);
                MessagesErrorFactory.ThrowMessagesException(ret, _MessageServiceHandle);
            }
            return(task.Task);
        }
Ejemplo n.º 8
0
        internal Task <SentResult> SendMessageAsync(Message message, bool saveToSentbox)
        {
            var task = new TaskCompletionSource <SentResult>();

            _messageSentCallback = (int result, IntPtr data) =>
            {
                task.SetResult((SentResult)result);
            };

            message.FillHandle();

            int    ret;
            IntPtr messageHandle = message.GetHandle();

            ret = Interop.Messages.SendMessage(_MessageServiceHandle, messageHandle, saveToSentbox, _messageSentCallback, IntPtr.Zero);
            if (ret != (int)MessagesError.None)
            {
                Log.Error(Globals.LogTag, "Failed to send message, Error - " + (MessagesError)ret);
                MessagesErrorFactory.ThrowMessagesException(ret, _MessageServiceHandle);
            }

            return(task.Task);
        }
Ejemplo n.º 9
0
        private void DuplicateMessageHandle(IntPtr sourceHandle, out IntPtr clonedHandle)
        {
            int    msgId;
            IntPtr returnedHandle = IntPtr.Zero;

            int ret = Interop.Messages.GetMessageId(sourceHandle, out msgId);

            if (ret == (int)MessagesError.None)
            {
                ret = Interop.Messages.GetMessageById(_MessageServiceHandle, msgId, out returnedHandle);
                if (ret != (int)MessagesError.None)
                {
                    Log.Error(Globals.LogTag, "Failed to get message by id, Error - " + (MessagesError)ret);
                    MessagesErrorFactory.ThrowMessagesException(ret, _MessageServiceHandle);
                }
            }
            else
            {
                Log.Error(Globals.LogTag, "Failed to get message id, Error - " + (MessagesError)ret);
                MessagesErrorFactory.ThrowMessagesException(ret, _MessageServiceHandle);
            }

            clonedHandle = returnedHandle;
        }
Ejemplo n.º 10
0
        internal Task <IEnumerable <Message> > SearchMessageAsync(MessagesSearchFilter filter)
        {
            return(Task.Run <IEnumerable <Message> >(() =>
            {
                List <Message> messageList = new List <Message>();
                int ret;

                Interop.Messages.MessageSearchCallback callback = (IntPtr messageHandle, int index, int resultCount, int totalCount, IntPtr userData) =>
                {
                    try
                    {
                        if (messageHandle != IntPtr.Zero)
                        {
                            IntPtr duplicatedMessageHandle = IntPtr.Zero;

                            DuplicateMessageHandle(messageHandle, out duplicatedMessageHandle);
                            if (duplicatedMessageHandle != IntPtr.Zero)
                            {
                                int type = (int)MessageType.Unknown;
                                int result = Interop.Messages.GetMessageType(duplicatedMessageHandle, out type);
                                if (result != (int)MessagesError.None)
                                {
                                    Log.Error(Globals.LogTag, "Failed to get message type, Error - " + (MessagesError)result);
                                }

                                switch ((MessageType)type)
                                {
                                case MessageType.Sms:
                                    {
                                        var messageItem = new SmsMessage(duplicatedMessageHandle);
                                        messageList.Add(messageItem);
                                        break;
                                    }

                                case MessageType.Mms:
                                    {
                                        var messageItem = new MmsMessage(duplicatedMessageHandle);
                                        messageList.Add(messageItem);
                                        break;
                                    }

                                case MessageType.CellBroadcast:
                                    {
                                        var messageItem = new CBMessage(duplicatedMessageHandle);
                                        messageList.Add(messageItem);
                                        break;
                                    }

                                case MessageType.Push:
                                    {
                                        var messageItem = new PushMessage(duplicatedMessageHandle);
                                        messageList.Add(messageItem);
                                        break;
                                    }

                                default:
                                    {
                                        Log.Error(Globals.LogTag, "Invaild message type - " + type);
                                        break;
                                    }
                                }

                                return true;
                            }
                        }
                    }
                    catch
                    {
                        Log.Error(Globals.LogTag, "Exception in Callback");
                    }

                    return false;
                };

                ret = Interop.Messages.SearchMessage(_MessageServiceHandle, (int)filter.MessageBoxType, (int)filter.MessageType, filter.TextKeyword, filter.AddressKeyword, 0, 0, callback, IntPtr.Zero);
                if (ret != (int)MessagesError.None)
                {
                    Log.Error(Globals.LogTag, "Failed to search message, Error - " + (MessagesError)ret);
                    MessagesErrorFactory.ThrowMessagesException(ret, _MessageServiceHandle);
                }

                return messageList;
            }));
        }