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(); }
private void nikotalkieItem_ItemSelected(object sender, EventArgs e) { NikotalkieItem selectedNikotalkieItem = (NikotalkieItem)sender; this.mSelectedMessage = (NMessage)selectedNikotalkieItem.Tag; this.mSelectedMessageIndex = mNikotalkieItems.IndexOf(selectedNikotalkieItem); this.RefreshView(); }
private void buttonDelete_Click(object sender, EventArgs e) { if (this.mSelectedMessage != null) { if (this.mSelectedMessage != null) { mOwner.MessageDelete(this.mSelectedMessage); this.SelectedMessage = null; } } }
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)); }
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); }
//----------------------------------------------------------------------------------------- public bool GetNextMsg(out NMessage nm) { nm = _buffers[_curReadIndex]; if (_curPushIndex == _curReadIndex) { hasPendingMessages = false; return(false); } ++_curReadIndex; if (_curReadIndex >= _bufferSize) { _curReadIndex = 0; } return(true); }
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; }
public NikotalkieItem(NMessage message) { this.Dock = DockStyle.Top; InitializeComponent(); this.SetItem(message); }
public void MessageReply(NMessage message) { mComposeMessageView.SetRecipient(message.Header.From); SwitchActiveView(ControlView.ComposeMessage); }
public void MessageDelete(NMessage message) { mStorage.DeleteMessage(message); }
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)); }
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); }
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); }
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; }
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()); }
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; }
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; }
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 } }
public void MoveMessage(NStorageFolder destination, NMessage message) { }
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(); }
public LoginMessage(NMessage message) : base(message.Buffer) { }
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); }