コード例 #1
0
        public static int writeRoomRecordingStream(int RoomID, RoomRecording recording)
        {
            string appPhysicalPath = HostingEnvironment.ApplicationPhysicalPath;
            string path = MidiFileHelper.getRoomRecordingPath(RoomID, 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)
            {
                return -1;
            }

            return 0;
        }
コード例 #2
0
        public ActionResult SaveRecording(string stream, int roomID, string name, string client)
        {
            if (string.IsNullOrEmpty(stream))
                return null;

            Room room = roomRepository.AllRooms.FirstOrDefault(item => item.ID == roomID);
            if (room == null)
                return null;

            RoomRecording recording = new RoomRecording();
            recording.RoomID = roomID;

            if (string.IsNullOrEmpty(name))
            {
                recording.Name = DateTime.Now.ToShortTimeString();
            }
            else
            {
                recording.Name = name;
            }
            recording.Client = client;
            recording.Date = DateTime.Now;
            recording.RecordingStream = stream;

            roomRepository.InsertOrUpdateRoomRecording(recording);
            roomRepository.Save();

            int result = MidiFileHelper.writeRoomRecordingStream(roomID, recording);
            if (result == 0)
            {
                var context = GlobalHost.ConnectionManager.GetHubContext<HubController>();

                IEnumerable<RoomRecording> recordings = roomRepository.AllRoomRecordings.Where(item => item.RoomID == roomID);
                context.Clients.Group(room.Name).updateRecordings(recordings.ToList());
            }

            return Json(new
            {
                Result = recording.ID,
                ID = recording.ID
            });
        }