public void Save(long ghLocationId, HttpPostedFileBase sound, string soundDescription, string userName) { try { var arr = new byte[sound.ContentLength]; sound.InputStream.Read(arr, 0, sound.ContentLength); var rawSound = new RawSound(); rawSound.Data = arr; rawSound.FileName = sound.FileName; rawSound.MIMEType = sound.ContentType; var s = new Sound(); s.GHLocationID = ghLocationId; s.Description = soundDescription; s.UserName = userName; _sr.Insert(s); rawSound.RawSoundID = s.SoundID; _rsr.Insert(rawSound); } catch (Exception ex) { Log.Error(ex.Message, ex); } }
public void Delete(RawSound rawSound) { try { db.Entry(rawSound).State = EntityState.Deleted; db.SaveChanges(); } catch (Exception ex) { Log.Error(ex.Message, ex); } }
public void Insert(RawSound rawSound) { try { db.RawSounds.Add(rawSound); db.SaveChanges(); } catch (Exception ex) { Log.Error(ex.Message, ex); } }
private void SeedSounds() { FileStream fs = null; try { fs = File.OpenRead(@"C:\Users\user\Dropbox\Cloud\Projects\Ghosts\SeedData\test.mp3"); byte[] bytes = new byte[fs.Length]; fs.Read(bytes, 0, Convert.ToInt32(fs.Length)); if (fs != null) { fs.Close(); fs.Dispose(); } for (var i = 0; i < 100; i++) { var rawSound = new RawSound(); rawSound.Data = bytes; rawSound.FileName = "test.mp3"; rawSound.MIMEType = "audio/mpeg"; var s = new Sound(); s.GHLocationID = 1; s.Description = "Test Description " + i; s.UserName = "******"; db.Sounds.Add(s); db.SaveChanges(); rawSound.RawSoundID = s.SoundID; db.RawSounds.Add(rawSound); db.SaveChanges(); rawSound = new RawSound(); rawSound.Data = bytes; rawSound.FileName = "test.mp3"; rawSound.MIMEType = "audio/mpeg"; s = new Sound(); s.GHLocationID = 2; s.Description = "Test Description " + i; s.UserName = "******"; db.Sounds.Add(s); db.SaveChanges(); rawSound.RawSoundID = s.SoundID; db.RawSounds.Add(rawSound); db.SaveChanges(); } } finally { if (fs != null) { fs.Close(); fs.Dispose(); } } }
public ActionResult SoundTests() { try { var ctm = new CacheTestModel(); var c = CacheHelper <GHLocationTransmitModel> .Instance.GetCacheable("1"); if (c == null) { ctm.Message = "Initial Get Failed"; return(View(ctm)); } var dt = DateTime.Parse(c.DateLastModified, null, DateTimeStyles.AdjustToUniversal); var rawSound = new RawSound(); rawSound.Data = new byte[1]; rawSound.FileName = "LocationControllerTest"; rawSound.MIMEType = "audio/mpeg"; var s = new Sound(); s.GHLocationID = 1; s.Description = "Location Controller Test"; s.UserName = UserHelper.Instance.CurrentUserName; _sr.Insert(s); rawSound.RawSoundID = s.SoundID; _rsr.Insert(rawSound); c = CacheHelper <GHLocationTransmitModel> .Instance.GetCacheable("1"); if (DateTime.Parse(c.DateLastModified, null, DateTimeStyles.AdjustToUniversal) == dt) { ctm.Message = "Update Date Last Modified On Sound Insert Failed"; return(View(ctm)); } dt = DateTime.Parse(c.DateLastModified, null, DateTimeStyles.AdjustToUniversal); s.Description = "Cache Update Test"; _sr.Update(s); c = CacheHelper <GHLocationTransmitModel> .Instance.GetCacheable("1"); if (DateTime.Parse(c.DateLastModified, null, DateTimeStyles.AdjustToUniversal) == dt) { ctm.Message = "Update Date Last Modified On Sound Update Failed"; return(View(ctm)); } dt = DateTime.Parse(c.DateLastModified, null, DateTimeStyles.AdjustToUniversal); _sr.Delete(s); _rsr.Delete(rawSound); c = CacheHelper <GHLocationTransmitModel> .Instance.GetCacheable("1"); if (DateTime.Parse(c.DateLastModified, null, DateTimeStyles.AdjustToUniversal) == dt) { ctm.Message = "Update Date Last Modified On Sound Delete Failed"; return(View(ctm)); } c = CacheHelper <GHLocationTransmitModel> .Instance.GetCacheable("1"); ctm.Message = "Success"; return(View(ctm)); } catch (Exception ex) { Log.Error(ex.Message, ex); return(new HttpStatusCodeResult(500)); } }