public static Models.Data.LiveStream CreateLiveStream(Service service) { string wscapikey = ConfigurationManager.AppSettings["wowzaApiKey"]; string wscaccesskey = ConfigurationManager.AppSettings["wowzaAccessKey"]; string name = service.FirstName + " " + service.LastName + " " + service.FuneralHome.UserName + service.Id; LiveStreamPost ls = new LiveStreamPost() { aspect_ratio_height = 720, aspect_ratio_width = 1280, billing_mode = "pay_as_you_go", broadcast_location = "us_west_california", closed_caption_type = "none", encoder = "wowza_gocoder", hosted_page = false, name = name, player_countdown = false, player_responsive = true, player_type = "wowza_player", player_width = 0, recording = true, target_delivery_protocol = "hls", transcoder_type = "transcoded", use_stream_source = false, }; var client = new RestClient(WowzaApi + "live_streams"); client.AddDefaultHeader("wsc-api-key", wscapikey); client.AddDefaultHeader("wsc-access-key", wscaccesskey); var request = new RestRequest(Method.POST); WowzaPost root = new WowzaPost() { live_stream = ls }; request.RequestFormat = DataFormat.Json; request.AddBody(root); var response = client.Execute(request); WowzaResponse wr = JsonConvert.DeserializeObject <WowzaResponse>(response.Content); if (wr != null && wr.live_stream != null) { Models.Data.LiveStream liveStream = CreateAndStoreLiveStream(service, wr.live_stream.id, wr.live_stream.player_hls_playback_url, wr.live_stream.connection_code); liveStream.Started = false; return(liveStream); } return(null); }
private static Models.Data.LiveStream CreateAndStoreLiveStream(Service service, string streamId, string playbackUrl, string connectionCode) { Guid guidid = Guid.NewGuid(); Models.Data.LiveStream ls = new Models.Data.LiveStream() { ServiceId = service.Id, StreamId = streamId, SourceURL = playbackUrl, StartStreamAccessToken = guidid, ConnectionCode = connectionCode }; ApplicationDbContext db = new ApplicationDbContext(); db.LiveStreams.Add(ls); db.SaveChanges(); return(ls); }
public ActionResult DeleteConfirmed(int id) { Service service = db.Services.Find(id); Video video = service.Video; if (video != null) { if (video.ConvertedFilePath != null) { CloudStorageAccount storageAccount = CloudStorageAccount.Parse(ConfigurationManager.AppSettings["StorageConnectionString"]); CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient(); CloudBlobContainer container = blobClient.GetContainerReference("videos"); CloudBlockBlob blockBlob = container.GetBlockBlobReference(video.ConvertedFilePath); if (blockBlob.Exists()) { blockBlob.Delete(); } } if (video.Analytics != null) { List <Analytic> anly = video.Analytics.ToList(); if (anly.Count > 0) { try { db.Entry(anly).State = EntityState.Deleted; } catch { foreach (var an in anly) { an.VideoId = 5850; db.Entry(an).State = EntityState.Modified; } } } } db.Entry(video).State = EntityState.Deleted; } if (service.PDF != null) { CloudStorageAccount storageAccount = CloudStorageAccount.Parse(ConfigurationManager.AppSettings["StorageConnectionString"]); CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient(); CloudBlobContainer container = blobClient.GetContainerReference("pdfs"); CloudBlockBlob blockBlob = container.GetBlockBlobReference(service.PDF.PDFPath); if (blockBlob.Exists()) { blockBlob.Delete(); } PDF pdf = service.PDF; db.Entry(pdf).State = EntityState.Deleted; } if (service.LiveStream != null) { Models.Data.LiveStream ls = service.LiveStream; db.Entry(ls).State = EntityState.Deleted; } service.LiveStream = null; service.LiveStreamId = null; db.Entry(service).State = EntityState.Deleted; db.SaveChanges(); return(RedirectToAction("Index")); }