public ActionResult UpdateRecording(Recording recording) { if (channelRepository.FindRecording(recording.ID) == null) return Json(new { Message = "Not Found", Result = -1, ID = recording.ID }); channelRepository.InsertOrUpdateRecording(recording); channelRepository.Save(); return Json(new { Message = "Success", Result = 0, ID = recording.ID }); }
private Recording SaveRecording(int UserID, string stream, string sig, int? fileID, out string message) { JavaScriptSerializer ser = new JavaScriptSerializer(); Signature signature = null; try { signature = ser.Deserialize<Signature>(sig); } catch (Exception) { } string name = "New Recording"; if (fileID.HasValue) { VirtualFile virtualFile = crumbsRepository.FindVirtualFile(fileID.Value); if (virtualFile != null) { name = virtualFile.Name; } } Recording recording = new Recording(); recording.Name = name; recording.UserID = UserID; recording.Date = DateTime.Now; recording.RecordingStream = stream; recording.VirtualFileID = fileID; if (signature != null) { recording.Numerator = signature.numerator; recording.Denominator = signature.denominator; recording.BeatsPerMinute = signature.beatsPerMinute; } channelRepository.InsertOrUpdateRecording(recording); channelRepository.Save(); int result = MidiFileHelper.writeRecordingStream(UserID, recording, out message); return recording; }
public static int writeRecordingStream(int UserID, Recording recording, out string message) { string appPhysicalPath = HostingEnvironment.ApplicationPhysicalPath; string path = MidiFileHelper.getRecordingPath(UserID, recording.ID); string FullPath = appPhysicalPath + path; string folder = Path.GetDirectoryName(FullPath); if (false == Directory.Exists(folder)) { Directory.CreateDirectory(folder); } JavaScriptSerializer ser = new JavaScriptSerializer(); List<MidiEvent> events = ser.Deserialize<List<MidiEvent>>(recording.RecordingStream); try { FileStream fs = new FileStream(FullPath, FileMode.Create, FileAccess.Write); BinaryFormatter bin = new BinaryFormatter(); bin.Serialize(fs, events); fs.Close(); } catch (Exception e) { message = string.Format("Can't save the file {0}: {1}", FullPath, e.Message); return -1; } message = FullPath; return 0; }