private void OnTimerTick(object sender, EventArgs e) { // Get the last partial buffer int sampleSize = _microphone.GetSampleSizeInBytes(_microphone.BufferDuration); byte[] extraBuffer = new byte[sampleSize]; int extraBytes = _microphone.GetData(extraBuffer); // Create MemoInfo object and add at top of collection int totalSize = _memoBufferCollection.Count * sampleSize + extraBytes; TimeSpan duration = _microphone.GetSampleDuration(totalSize); MemoInfo memoInfo = new MemoInfo(DateTime.UtcNow, totalSize, duration); FormattedSpace = memoInfo.SpaceTime.FormattedSpace; }
private void StoreEntry(MemoInfo memoInfo) { TimeSpan timeSpan = DateTime.Now - CreateTime; string minStr = timeSpan.Minutes == 0 ? string.Empty : string.Format(@"{0}'", timeSpan.Minutes); string secStr = timeSpan.Seconds == 0 ? string.Empty : string.Format(@"{0}s", timeSpan.Seconds); if (!(string.IsNullOrEmpty(minStr) && string.IsNullOrEmpty(secStr))) { Entry entry = new Entry { EntryId = System.Guid.NewGuid().ToString(), EntryType = EntryType.Memo.ToString(), CreateTime = CreateTime, StartTime = StartTime, ExpirationTime = DateCalculator.LastTime(StartTime), RepeatType = RepeatType.NotRepeated.ToString(), ExtraInfo = minStr + secStr, AlarmOn = false, AlarmTime = DateTime.Now, AttachmentFile = memoInfo.FileName }; EntryDataContext.Instance.EntryTable.InsertOnSubmit(entry); EntryDataContext.Instance.SubmitChanges(); } }
public void StopRecording() { // Get the last partial buffer int sampleSize = _microphone.GetSampleSizeInBytes(_microphone.BufferDuration); byte[] extraBuffer = new byte[sampleSize]; int extraBytes = _microphone.GetData(extraBuffer); // Stop recording _microphone.Stop(); // Stop timer _timer.Stop(); _statusTimer.Stop(); // Create MemoInfo object and add at top of collection int totalSize = _memoBufferCollection.Count * sampleSize + extraBytes; TimeSpan duration = _microphone.GetSampleDuration(totalSize); MemoInfo memoInfo = new MemoInfo(DateTime.UtcNow, totalSize, duration); // Save data in isolated storage using (IsolatedStorageFile storage = IsolatedStorageFile.GetUserStoreForApplication()) { using (IsolatedStorageFileStream stream = storage.CreateFile(memoInfo.FileName)) { // Write buffers from collection foreach (byte[] buffer in _memoBufferCollection) stream.Write(buffer, 0, buffer.Length); // Write partial buffer stream.Write(extraBuffer, 0, extraBytes); } } StoreEntry(memoInfo); }