Пример #1
0
        void mRecordingView_RecordingSend(object sender, EventArgs e)
        {
            //simple version, wrap up what we have and send out;

            NMessage message = new NMessage();

            message.Header      = new NMessageHeader();
            message.Header.From = mConfiguration.Username;
            message.Header.To   = mComposeMessageView.Recipients;
            message.Header.AttachementHeaders = new List <NMessageAttachementHeader>();
            NMessageAttachementHeader attachement = new NMessageAttachementHeader();

            attachement.AttachementType = NMessageAttachementType.Audio;
            attachement.ID = 0;
            message.Header.AttachementHeaders.Add(attachement);
            message.Body = new NMessageBody();
            message.Body.AttachementBodys = new List <NMessageAttachementBody>();
            NMessageAttachementBody attachementBody = new NMessageAttachementBody();

            attachementBody.AttachementType = NMessageAttachementType.Audio;
            attachementBody.ID   = 0;
            attachementBody.Name = "Voice Message";
            attachementBody.Data = mCodec.Encode(mRecordingView.CapturedStream).ToArray();
            attachementBody.Size = attachementBody.Data.Length;
            message.Body.AttachementBodys.Add(attachementBody);
            mStorage.SaveOutbox(message);
            SwitchActiveView(ControlView.ComposeMessage);
            mComposeMessageView.NewMessage();
        }
Пример #2
0
        private void nikotalkieItem_ItemSelected(object sender, EventArgs e)
        {
            NikotalkieItem selectedNikotalkieItem = (NikotalkieItem)sender;

            this.mSelectedMessage      = (NMessage)selectedNikotalkieItem.Tag;
            this.mSelectedMessageIndex = mNikotalkieItems.IndexOf(selectedNikotalkieItem);
            this.RefreshView();
        }
Пример #3
0
 private void buttonDelete_Click(object sender, EventArgs e)
 {
     if (this.mSelectedMessage != null)
     {
         if (this.mSelectedMessage != null)
         {
             mOwner.MessageDelete(this.mSelectedMessage);
             this.SelectedMessage = null;
         }
     }
 }
Пример #4
0
        public void StartPlayingMessage(NMessage message)
        {
            NMessage tmpMessage = mStorage.GetMessage(message);

            if (tmpMessage == null || tmpMessage.Body.AttachementBodys.Count == 0)
            {
                return;
            }
            MemoryStream memoryStream = new MemoryStream(tmpMessage.Body.AttachementBodys[0].Data);

            mDXSound.StartPlaying(mCodec.Decode(memoryStream));
        }
Пример #5
0
        void nikotalkieItem_ItemActionPlay(object sender, EventArgs e)
        {
            //TO DO PLAY SELECTED MESSAGE;
            if (mSelectedMessage == null)
            {
                return;
            }
            NikotalkieItem selectedNikotalkieItem = (NikotalkieItem)sender;

            this.mSelectedMessage = (NMessage)selectedNikotalkieItem.Tag;
            this.RefreshView();
            mOwner.StartPlayingMessage(this.mSelectedMessage);
        }
Пример #6
0
        //-----------------------------------------------------------------------------------------
        public bool GetNextMsg(out NMessage nm)
        {
            nm = _buffers[_curReadIndex];
            if (_curPushIndex == _curReadIndex)
            {
                hasPendingMessages = false;
                return(false);
            }

            ++_curReadIndex;
            if (_curReadIndex >= _bufferSize)
            {
                _curReadIndex = 0;
            }
            return(true);
        }
Пример #7
0
 public void SetItem(NMessage message)
 {
     this.LabelFrom.Text = message.Header.From;
     if (DateTime.Now.ToShortDateString() == message.Header.Date.ToShortDateString())
     {//today
         this.LabelDate.Text = "Today, " + message.Header.Date.ToShortTimeString();
     }
     else if (DateTime.Now.AddDays(-7) < message.Header.Date)
     {//day of week
         this.LabelDate.Text = message.Header.Date.DayOfWeek.ToString() + ", " + message.Header.Date.ToShortTimeString();
     }
     else
     {
         this.LabelDate.Text = message.Header.Date.ToShortDateString();
     }
     
     this.Tag = message;
     this.Visible = true;   
 }
Пример #8
0
        public void SetItem(NMessage message)
        {
            this.LabelFrom.Text = message.Header.From;
            if (DateTime.Now.ToShortDateString() == message.Header.Date.ToShortDateString())
            {//today
                this.LabelDate.Text = "Today, " + message.Header.Date.ToShortTimeString();
            }
            else if (DateTime.Now.AddDays(-7) < message.Header.Date)
            {//day of week
                this.LabelDate.Text = message.Header.Date.DayOfWeek.ToString() + ", " + message.Header.Date.ToShortTimeString();
            }
            else
            {
                this.LabelDate.Text = message.Header.Date.ToShortDateString();
            }

            this.Tag     = message;
            this.Visible = true;
        }
Пример #9
0
 public NikotalkieItem(NMessage message)
 {
     this.Dock = DockStyle.Top;
     InitializeComponent();
     this.SetItem(message);
 }
Пример #10
0
 public void MessageReply(NMessage message)
 {
     mComposeMessageView.SetRecipient(message.Header.From);
     SwitchActiveView(ControlView.ComposeMessage);
 }
Пример #11
0
 public void MessageDelete(NMessage message)
 {
     mStorage.DeleteMessage(message);
 }
Пример #12
0
 public void StartPlayingMessage(NMessage message)
 {
     NMessage tmpMessage = mStorage.GetMessage(message);
     if (tmpMessage == null || tmpMessage.Body.AttachementBodys.Count == 0) return;
     MemoryStream memoryStream = new MemoryStream(tmpMessage.Body.AttachementBodys[0].Data);
     mDXSound.StartPlaying(mCodec.Decode(memoryStream));
 }
Пример #13
0
 void nikotalkieItem_ItemActionPlay(object sender, EventArgs e)
 {
     //TO DO PLAY SELECTED MESSAGE;
     if (mSelectedMessage == null) return;
    NikotalkieItem selectedNikotalkieItem = (NikotalkieItem)sender;
    this.mSelectedMessage = (NMessage)selectedNikotalkieItem.Tag;
         this.RefreshView();
         mOwner.StartPlayingMessage(this.mSelectedMessage);
 }
Пример #14
0
        public void DeleteMessage(NMessage message)
        {
            NMessage tmpMessage = this.GetMessage(message);
            if (tmpMessage != null)
            {
                tmpMessage.Deleted = true;
                try
                {
                    if (File.Exists(message.LocalFileName)) File.Delete(message.LocalFileName);
                    String fileName = ArchivePath + GenerateId() + ".xml";
                    tmpMessage.LocalFileName = fileName;
                    using (StreamWriter sw = new StreamWriter(fileName))
                    {
                        XmlSerializer ser = new XmlSerializer(typeof(NMessage));
                        ser.Serialize(sw, tmpMessage);
                        sw.Close();
                    }

                }
                catch (Exception)
                {
#if (DEBUG)
                throw;
#endif
                }

            }
            this.UpdateIndex(NStorageFolder.Inbox);
            this.UpdateIndex(NStorageFolder.Archive);


        }
Пример #15
0
        internal NMessage GetMessage(NMessage message)
        {
            NMessage tmpMessage = null;
            try
            {
                using (StreamReader sr = new StreamReader(message.LocalFileName))
                {
                    if (File.Exists(message.LocalFileName))
                    {
                        tmpMessage = new NMessage();
                        XmlSerializer des = new XmlSerializer(typeof(NMessage));
                        tmpMessage = (NMessage)des.Deserialize(new System.Xml.XmlTextReader(sr));
                        sr.Close();
                    }
                }
            }
            catch (Exception)
            {
#if(DEBUG)                  
                  throw;
#endif
            }
            return tmpMessage;
        }
Пример #16
0
        public void UpdateIndex(NStorageFolder folder)
        {
            NStorageIndex storageIndex = null;
            String storagePath = null;
            switch (folder)
            {
                case NStorageFolder.Inbox:
                    storageIndex = InboxIndex;
                    break;
                case NStorageFolder.Archive:
                    storageIndex = ArchiveIndex;
                    break;
                case NStorageFolder.Outbox:
                    storageIndex = OutboxIndex;
                    break;
                case NStorageFolder.Sent:
                    storageIndex = SentIndex;
                    break;
                default:
                    break;
            }
            if (storageIndex == null || !Directory.Exists(storageIndex.Path)) return;

            String[] files = Directory.GetFiles(storageIndex.Path, "*.xml");

            //remove deleted
            
            for (int i = storageIndex.Messages.Count - 1; i >= 0; i--)
            {
                bool exists = false;
                for (int j = 0; j < files.Length; j++)
                {
                    if (files[j] == storageIndex.Messages[i].LocalFileName) exists = true;
                }
                if (!exists)
                {
                    storageIndex.Messages.RemoveAt(i);
                }
            }
            //add new
            for (int i = 0; i < files.Length; i++)
            {

                if (!storageIndex.ExistsFile(files[i]))
                {
                    NMessage message = new NMessage();
                    using (StreamReader sr = new StreamReader(files[i]))
                    {
                        if (File.Exists(files[i]))
                        {
                            XmlSerializer des = new XmlSerializer(typeof(NMessage));
                            message = (NMessage)des.Deserialize(new System.Xml.XmlTextReader(sr));
                            sr.Close();
                        }
                    }

                    if (message != null)
                    {
                        message.Body = null;
                        storageIndex.Messages.Add(message);
                        storageIndex.LastMessageId = message.Header.MsgID;
                    }

                }
            }

            //save index
            try
            {
                using (StreamWriter sw = new StreamWriter(storagePath + ".index"))
                {
                    XmlSerializer ser = new XmlSerializer(typeof(NStorageIndex));
                    ser.Serialize(sw, storageIndex);
                    sw.Close();
                }

            }
            catch (Exception ex)
            {
#if (DEBUG)
                        throw;
#endif
            }

            storageIndex.SortIndex();
            storageIndex.OnIndexChanged(storageIndex, new EventArgs());
        }
Пример #17
0
 private void nikotalkieItem_ItemSelected(object sender, EventArgs e)
  {
      NikotalkieItem selectedNikotalkieItem = (NikotalkieItem)sender;
      this.mSelectedMessage = (NMessage)selectedNikotalkieItem.Tag;
     this.mSelectedMessageIndex = mNikotalkieItems.IndexOf(selectedNikotalkieItem);
      this.RefreshView();
  }
Пример #18
0
        public NResultSend SendMessage(NMessage message)
        {
            NResultSend resultSend = new NResultSend();
            resultSend.Success = false;
            //$username, $password, $recipients, $compression, $bytes, $type, $format
            try
            {

                String recipients = "";
                foreach (String recipient in message.Header.To)
                {
                    recipients += recipient + ";";
                }
                //XMLSendMessage($username, $password, $recipients, $compression, $bytes, $type, $format)
                Hashtable parameters = new Hashtable();
                parameters.Add("username", mUserConfiguration.Username);
                parameters.Add("password", mUserConfiguration.Password);
                parameters.Add("recipients", recipients);
                parameters.Add("compression", "none");
                parameters.Add("bytes", 0);
                parameters.Add("type", "XML");
                parameters.Add("format", "amr");

                
                try
                {
                    String boundary = Guid.NewGuid().ToString();
                    WebRequest requestSendMessage = WebRequest.Create(mUserConfiguration.Url + BulildWebRequestQuery("XMLSendMessage", parameters));
                    
                  

                    requestSendMessage.ContentType = "multipart/form-data; boundary=" + boundary;
                    requestSendMessage.Method = "POST";


                    //encode header
                    String postHeader="";
                    postHeader += "\r\n" + @"--" + boundary + "\r\n";
                    postHeader += "Content-Disposition: form-data; name=\"uploadFile1\"; filename=\"uploadFile1\"\r\n";
                    postHeader += "Content-Type: application/octet-stream\r\n\r\n";

                    byte[] postHeaderBytes = Encoding.UTF8.GetBytes(postHeader);
                    byte[] boundaryBytes = Encoding.UTF8.GetBytes("\r\n" + @"--" + boundary + @"--" + "\r\n");
                    //read in the file as a stream
                    long contentLength = postHeaderBytes.Length + message.Body.AttachementBodys[0].Data.Length + boundaryBytes.Length;

                    requestSendMessage.ContentLength = contentLength;

                    Stream requestStream = requestSendMessage.GetRequestStream();
                    requestStream.Write(postHeaderBytes, 0, postHeaderBytes.Length);
                    requestStream.Write(message.Body.AttachementBodys[0].Data, 0, message.Body.AttachementBodys[0].Data.Length);
                    requestStream.Write(boundaryBytes, 0, boundaryBytes.Length);
                    //requestStream.Close();


                    HttpWebResponse responseSendMessage = (HttpWebResponse)requestSendMessage.GetResponse();
                    Stream dataStream = responseSendMessage.GetResponseStream();
                    XmlSerializer des = new XmlSerializer(typeof(NResultSend));
                    resultSend = (NResultSend)des.Deserialize(new System.Xml.XmlTextReader(dataStream));
                    dataStream.Close();

                }
                catch (Exception ex)
                {
#if(DEBUG)
                    throw;
#endif
                }


            }
            catch (Exception)
            {
#if (DEBUG)
                throw;
#endif
            }
            return resultSend;
        }
Пример #19
0
        public NMessage ReciveMessage(NMessageHeader messageHeader)
        {
            NMessage message = null;
            if (mUserConfiguration == null) return message;
                //Authorize(username, password, lastmsg,type) type=XML
                Hashtable parameters = new Hashtable();
                parameters.Add("username", mUserConfiguration.Username);
                parameters.Add("password", mUserConfiguration.Password);
                parameters.Add("messageid", messageHeader.MsgID);
                parameters.Add("type", "XML");
                parameters.Add("format", "amr");

                try
                {
                    List<NMessageBody> messageBodysList = new List<NMessageBody>();

                    WebRequest requestGetMessage = WebRequest.Create(mUserConfiguration.Url + BulildWebRequestQuery("XMLGetMessage", parameters));
                    HttpWebResponse responseGetMessage = (HttpWebResponse)requestGetMessage.GetResponse();
                    Stream dataStream = responseGetMessage.GetResponseStream();

                    //String DATA = new StreamReader(dataStream).ReadToEnd();
                    XmlSerializer des = new XmlSerializer(typeof(NMessageBody));
                    NMessageBody messageBody = (NMessageBody)des.Deserialize(new System.Xml.XmlTextReader(dataStream));
                    dataStream.Close();
                    message = new NMessage(messageHeader, messageBody);
                    
                }
                catch (Exception ex)
                {
#if(DEBUG)
                    throw;
#endif
                }
                return message;
            }
Пример #20
0
 private void buttonDelete_Click(object sender, EventArgs e)
 {
     if (this.mSelectedMessage != null)
     {
         if (this.mSelectedMessage != null)
         {
             mOwner.MessageDelete(this.mSelectedMessage);
             this.SelectedMessage = null;
         }
     }
 }
Пример #21
0
        public void SaveInbox(NMessage message)
        {
            try
            {
                String fileName = InboxPath + GenerateId() + ".xml";
                message.LocalFileName = fileName;
                using (StreamWriter sw = new StreamWriter(fileName))
                {
                    XmlSerializer ser = new XmlSerializer(typeof(NMessage));
                    ser.Serialize(sw, message);
                    sw.Close();
                }
                InboxIndex.LastMessageId = message.Header.MsgID;
            }
            catch (Exception)
            {
#if (DEBUG)
                throw;
#endif
            }

        }
Пример #22
0
 public void MessageDelete(NMessage message)
 {
     mStorage.DeleteMessage(message);
 }
Пример #23
0
        public void MoveMessage(NStorageFolder destination, NMessage message)
        {

        }
Пример #24
0
 public void MessageReply(NMessage message)
 {
     mComposeMessageView.SetRecipient(message.Header.From);
     SwitchActiveView(ControlView.ComposeMessage);
 }
Пример #25
0
 public NikotalkieItem(NMessage message)
 {
     this.Dock = DockStyle.Top;
     InitializeComponent();
     this.SetItem(message);
 }
Пример #26
0
        void mRecordingView_RecordingSend(object sender, EventArgs e)
        {
            //simple version, wrap up what we have and send out;

            NMessage message = new NMessage();
            message.Header = new NMessageHeader();
            message.Header.From = mConfiguration.Username;
            message.Header.To = mComposeMessageView.Recipients;
            message.Header.AttachementHeaders = new List<NMessageAttachementHeader>();
            NMessageAttachementHeader attachement = new NMessageAttachementHeader();
            attachement.AttachementType = NMessageAttachementType.Audio;
            attachement.ID = 0;
            message.Header.AttachementHeaders.Add(attachement);
            message.Body = new NMessageBody();
            message.Body.AttachementBodys = new List<NMessageAttachementBody>();
            NMessageAttachementBody attachementBody = new NMessageAttachementBody();
            attachementBody.AttachementType = NMessageAttachementType.Audio;
            attachementBody.ID = 0;
            attachementBody.Name = "Voice Message";
            attachementBody.Data = mCodec.Encode(mRecordingView.CapturedStream).ToArray();
            attachementBody.Size = attachementBody.Data.Length;
            message.Body.AttachementBodys.Add(attachementBody);
            mStorage.SaveOutbox(message);
            SwitchActiveView(ControlView.ComposeMessage);
            mComposeMessageView.NewMessage();
        }   
Пример #27
0
 public LoginMessage(NMessage message) : base(message.Buffer) {
 }
Пример #28
0
        public DeliveryWorker(Configuration configuration, NSettings settings, NStorage storage, BackgroundWorker backgroundWorker)
        {
            try
            {
                this.NewMessages = 0;
                int i = 0;
                mConfiguration = configuration;
                mSettings = settings;
                mStorage = storage;
                Boolean updateIndex = false;
                NTransport mTransport = new NTransport(this.mConfiguration);

                backgroundWorker.ReportProgress(0);

                #region RECEIVING
                //Receiving Headers
                List<NMessageHeader> messageHeaders = mTransport.ReciveHeaders();

                if (messageHeaders != null && !mCancel)
                {
                    i = 0;
                    foreach (NMessageHeader messageHeader in messageHeaders)
                    {


                        if (!mStorage.InboxIndex.ExistsID(messageHeader.MsgID) && !mStorage.ArchiveIndex.ExistsID(messageHeader.MsgID)) 
                       {   //skip already downloaded
                            NMessage message = mTransport.ReciveMessage(messageHeader);
                            if(message!=null)  mStorage.SaveInbox(message);
                            updateIndex = true;
                            NewMessages++;
                       }
                        backgroundWorker.ReportProgress(100 * i / (messageHeaders.Count));
                      i++;
                      
                    }
                    
                }

                if (updateIndex)
                {
                    mStorage.UpdateIndex(NStorageFolder.Inbox);
                }
              
                #endregion

                #region SENDING
                //Sending
                updateIndex = false;
                string[] mFileList = Directory.GetFiles(mStorage.OutboxPath, "*.xml");
                i = 1;
                if (mFileList.Length > 0)
                {
                    backgroundWorker.ReportProgress(100 * i / (mFileList.Length + 1));
                    foreach (String file in mFileList)
                    {
                        if (mCancel) break;
                        NMessage message = new NMessage();
                        using (StreamReader sr = new StreamReader(file))
                        {
                            if (File.Exists(file))
                            {
                                XmlSerializer des = new XmlSerializer(typeof(NMessage));
                                message = (NMessage)des.Deserialize(new System.Xml.XmlTextReader(sr));
                                sr.Close();
                            }
                        }

                        if (message != null)
                        {
                            NResultSend resultSend = mTransport.SendMessage(message);
                            if (resultSend.Success)
                            {
                                if (File.Exists(storage.SentPath + file)) File.Delete(storage.SentPath + file);
                                File.Move(file, storage.SentPath + Path.GetFileName(file));
                                updateIndex = true;
                            };
                        }
                        i++;
                        backgroundWorker.ReportProgress(100 * i / (mFileList.Length + 1));
                    }
                    if (updateIndex)
                    {
                        mStorage.UpdateIndex(NStorageFolder.Outbox);
                        mStorage.UpdateIndex(NStorageFolder.Sent);
                    }
                }
                #endregion

            }
            catch (Exception)
            {

#if (DEBUG)
                throw;
#endif
            }
            backgroundWorker.ReportProgress(100);
        }