Exemplo n.º 1
0
        public ActionResult VideoDelete(long?videoID, long?eventID)
        {
            Video deletedVideo = db.Videos.Find(videoID);

            db.Videos.Remove(deletedVideo);
            db.SaveChanges();
            return(RedirectToAction("Details", "Event", new { id = eventID }));
        }
Exemplo n.º 2
0
        public ActionResult VideoAdd(String VideoURL, long LocationID, long EventID)
        {
            User user = UserHelpers.GetCurrentUser(Session);

            if (user == null)
            {
                if (Request.Cookies["userName"] != null && Request.Cookies["password"] != null)
                {
                    string userName = Request.Cookies["userName"].Value;
                    string password = Request.Cookies["password"].Value;
                    if (UserDatabaseHelper.Instance.ValidateUser(userName, password))
                    {
                        user = UserDatabaseHelper.Instance.GetUserByUserName(userName);
                        if (UserDatabaseHelper.Instance.isLookedUser(user.UserName))
                        {
                            TempData["errorTitle"]   = "Locked User";
                            TempData["errorMessage"] = "Your account is locked! Please contact with our support";

                            return(RedirectToAction("Index", "Home"));
                        }
                        UserHelpers.SetCurrentUser(Session, user);
                    }
                    TempData["errorTitle"]   = "Require Signin";
                    TempData["errorMessage"] = "Ops.. It look like you are current is not signed in system! Please sign in first!";
                    return(RedirectToAction("Details", "Event", new { id = EventID }));
                }
            }
            Video newVideo = new Video();

            newVideo.EventPlaceID = LocationHelpers.Instance.GetEventPlacesID(EventID, LocationID);
            newVideo.StartTime    = DateTime.Now;
            newVideo.Privacy      = 1;
            newVideo.VideoLink    = VideoURL;
            if (EventDatabaseHelper.Instance.AddVideo(newVideo))
            {
                TempData["VideoAddError"] = null; // success
            }
            else
            {
                TempData["VideoAddError"] = "There is something wrong";
            }
            return(RedirectToAction("Details", "Event", new { id = EventID }));
        }
        public ActionResult VideoAdd(String VideoURL, long LocationID, long EventID)
        {
            User user = UserHelpers.GetCurrentUser(Session);
            if (user == null)
            {
                if (Request.Cookies["userName"] != null && Request.Cookies["password"] != null)
                {
                    string userName = Request.Cookies["userName"].Value;
                    string password = Request.Cookies["password"].Value;
                    if (UserDatabaseHelper.Instance.ValidateUser(userName, password))
                    {
                        user = UserDatabaseHelper.Instance.GetUserByUserName(userName);
                        if (UserDatabaseHelper.Instance.isLookedUser(user.UserName))
                        {
                            TempData["errorTitle"] = "Locked User";
                            TempData["errorMessage"] = "Your account is locked! Please contact with our support";

                            return RedirectToAction("Index", "Home");
                        }
                        UserHelpers.SetCurrentUser(Session, user);
                    }
                    TempData["errorTitle"] = "Require Signin";
                    TempData["errorMessage"] = "Ops.. It look like you are current is not signed in system! Please sign in first!";
                    return RedirectToAction("Details", "Event", new { id = EventID });
                }
            }
            Video newVideo = new Video();
            newVideo.EventPlaceID = LocationHelpers.Instance.GetEventPlacesID(EventID, LocationID);
            newVideo.StartTime = DateTime.Now;
            newVideo.Privacy = 1;
            newVideo.VideoLink = VideoURL;
            if (EventDatabaseHelper.Instance.AddVideo(newVideo))
            {
                TempData["VideoAddError"] = null; // success
            }
            else
            {
                TempData["VideoAddError"] = "There is something wrong";
            }
            return RedirectToAction("Details", "Event",new {id=EventID});

        }
        public async Task<ActionResult> IndexAsync(LiveStreamingModel liveModel, CancellationToken cancellationToken)
        {
            if (ModelState.IsValid)
            {
                HttpCookie newModel = new HttpCookie("liveModel");
                newModel.Value = new JavaScriptSerializer().Serialize(liveModel);
                newModel.Expires = DateTime.Now.AddHours(10);
                Response.Cookies.Add(newModel);
            }
            else 
            {
                if (Request.Cookies["liveModel"] != null)
                {
                    JavaScriptSerializer objJavascript = new JavaScriptSerializer();
                    liveModel = objJavascript.Deserialize<LiveStreamingModel>(Request.Cookies["liveModel"].Value);
                }
                else {
                    TempData["errorTitle"] = "Error";
                    TempData["errorMessage"] = "Something wrong! Please try again later!";
                    return RedirectToAction("Index", "Home", liveModel.eventID);
                }
            }
            
                var result = await new AuthorizationCodeMvcApp(this, new AppFlowMetadata()).
                AuthorizeAsync(cancellationToken);
                
                
                if (result.Credential != null)
                {
                    var youtubeService = new YouTubeService(new BaseClientService.Initializer()
                    {
                        HttpClientInitializer = result.Credential,
                        ApplicationName = Assembly.GetExecutingAssembly().GetName().Name
                    });
                    LiveBroadcastSnippet broadcastSnippet = new LiveBroadcastSnippet();
                    broadcastSnippet.Title = liveModel.Title;
                    broadcastSnippet.ScheduledStartTime = liveModel.StartTimeYoutube.CompareTo(DateTime.Now) < 0 ? (DateTime.Now) : liveModel.StartTimeYoutube;
                    broadcastSnippet.ScheduledEndTime = liveModel.EndTimeYoutube;
                    // Set the broadcast's privacy status to "private". See:
                    // https://developers.google.com/youtube/v3/live/docs/liveBroadcasts#status.privacyStatus
                    LiveBroadcastStatus status = new LiveBroadcastStatus();
                    if (liveModel.PrivacyYoutube == EventZoneConstants.publicEvent)
                    {
                        status.PrivacyStatus = "public";
                    }
                    else if (liveModel.PrivacyYoutube == EventZoneConstants.unlistedEvent)
                    {
                        status.PrivacyStatus = "unlisted";
                    }
                    else { 
                        status.PrivacyStatus= "private";
                    }
                    //Set LiveBroadcast
                    LiveBroadcast broadcast = new LiveBroadcast();
                    LiveBroadcast returnBroadcast = new LiveBroadcast();
                    broadcast.Kind = "youtube#liveBroadcast";
                    broadcast.Snippet = broadcastSnippet;
                    broadcast.Status = status;
                    LiveBroadcastsResource.InsertRequest liveBroadcastInsert = youtubeService.LiveBroadcasts.Insert(broadcast, "snippet,status");
                    try
                    {
                        returnBroadcast = liveBroadcastInsert.Execute();
                    }
                    catch (Exception ex){
                        TempData["ErrorCreateLiveMessage"] = "Your youtube account can not create live streaming";
                        result.Credential.RevokeTokenAsync(CancellationToken.None).Wait();
                        return RedirectToAction("Details", "Event", new { id = liveModel.eventID });
                    }
                    
                    //Set LiveStream Snippet
                    LiveStreamSnippet streamSnippet = new LiveStreamSnippet();
                    streamSnippet.Title = liveModel.Title + "Stream Title";
                    CdnSettings cdnSettings = new CdnSettings();
                    cdnSettings.Format = liveModel.Quality;
                    cdnSettings.IngestionType = "rtmp";

                    //Set LiveStream
                    LiveStream streamLive = new LiveStream();
                    streamLive.Kind = "youtube#liveStream";
                    streamLive.Snippet = streamSnippet;
                    streamLive.Cdn = cdnSettings;
                    LiveStream returnLiveStream = youtubeService.LiveStreams.Insert(streamLive, "snippet,cdn").Execute();
                    LiveBroadcastsResource.BindRequest liveBroadcastBind = youtubeService.LiveBroadcasts.Bind(returnBroadcast.Id, "id,contentDetails");
                    liveBroadcastBind.StreamId = returnLiveStream.Id;
                    try
                    {
                        returnBroadcast = liveBroadcastBind.Execute();
                    }
                    catch (Exception ex)
                    {
                        TempData["ErrorCreateLiveMessage"] = "Your youtube account can not create live streaming";
                        result.Credential.RevokeTokenAsync(CancellationToken.None).Wait();
                        return RedirectToAction("Details", "Event", new { id = liveModel.eventID });
                    }
                    
                    //Return Value
                    String streamName = returnLiveStream.Cdn.IngestionInfo.StreamName;
                    String primaryServerUrl = returnLiveStream.Cdn.IngestionInfo.IngestionAddress;
                    String backupServerUrl = returnLiveStream.Cdn.IngestionInfo.BackupIngestionAddress;
                    String youtubeUrl = "https://www.youtube.com/watch?v=" + returnBroadcast.Id;
                    
                    //youtubeReturnModel model = new youtubeReturnModel { streamName = streamName, primaryServerUrl = primaryServerUrl,backupServerUrl=backupServerUrl,youtubeUrl=youtubeUrl };
                    Video video = new Video {  EventPlaceID = liveModel.EventPlaceID,
                                               VideoLink = youtubeUrl,
                                               PrimaryServer = primaryServerUrl,
                                               StartTime = liveModel.StartTimeYoutube,
                                               Privacy = liveModel.PrivacyYoutube,
                                               EndTime = liveModel.EndTimeYoutube,
                                               BackupServer = backupServerUrl,
                                               StreamName= streamName};
                    EventDatabaseHelper.Instance.AddVideo(video);
                    HttpCookie newModel = new HttpCookie("liveModel");
                    newModel.Value = new JavaScriptSerializer().Serialize(liveModel);
                    newModel.Expires = DateTime.Now.AddHours(-1);
                    Response.Cookies.Add(newModel);
                    result.Credential.RevokeTokenAsync(CancellationToken.None).Wait();
                    TempData["ErrorCreateLiveMessage"] = "Success";
                    return RedirectToAction("Details", "Event", new { id = EventDatabaseHelper.Instance.GetEventPlaceByID(liveModel.EventPlaceID).EventID });
            }
            else
            {
                return new RedirectResult(result.RedirectUri);
            }
        }
Exemplo n.º 5
0
        public async Task <ActionResult> IndexAsync(LiveStreamingModel liveModel, CancellationToken cancellationToken)
        {
            if (!ModelState.IsValid)
            {
                JavaScriptSerializer objJavascript = new JavaScriptSerializer();
                liveModel = objJavascript.Deserialize <LiveStreamingModel>(Request.Cookies["liveModel"].Value);
            }
            else
            {
                if (liveModel.Quality != null)
                {
                    HttpCookie newModel = new HttpCookie("liveModel");
                    newModel.Value   = new JavaScriptSerializer().Serialize(liveModel);
                    newModel.Expires = DateTime.Now.AddHours(10);
                    Response.Cookies.Add(newModel);
                }
            }
            var result = await new AuthorizationCodeMvcApp(this, new AppFlowMetadata()).
                         AuthorizeAsync(cancellationToken);


            if (result.Credential != null)
            {
                var youtubeService = new YouTubeService(new BaseClientService.Initializer()
                {
                    HttpClientInitializer = result.Credential,
                    ApplicationName       = Assembly.GetExecutingAssembly().GetName().Name
                });
                LiveBroadcastSnippet broadcastSnippet = new LiveBroadcastSnippet();
                broadcastSnippet.Title = liveModel.Title;
                broadcastSnippet.ScheduledStartTime = liveModel.StartTimeYoutube.CompareTo(DateTime.Now) < 0 ? (DateTime.Now) : liveModel.StartTimeYoutube;
                broadcastSnippet.ScheduledEndTime   = liveModel.EndTimeYoutube;
                // Set the broadcast's privacy status to "private". See:
                // https://developers.google.com/youtube/v3/live/docs/liveBroadcasts#status.privacyStatus
                LiveBroadcastStatus status = new LiveBroadcastStatus();
                if (liveModel.PrivacyYoutube == EventZoneConstants.publicEvent)
                {
                    status.PrivacyStatus = "public";
                }
                else if (liveModel.PrivacyYoutube == EventZoneConstants.unlistedEvent)
                {
                    status.PrivacyStatus = "unlisted";
                }
                else
                {
                    status.PrivacyStatus = "private";
                }

                //Set LiveBroadcast
                LiveBroadcast broadcast       = new LiveBroadcast();
                LiveBroadcast returnBroadcast = new LiveBroadcast();
                broadcast.Kind    = "youtube#liveBroadcast";
                broadcast.Snippet = broadcastSnippet;
                broadcast.Status  = status;
                LiveBroadcastsResource.InsertRequest liveBroadcastInsert = youtubeService.LiveBroadcasts.Insert(broadcast, "snippet,status");
                try
                {
                    returnBroadcast = liveBroadcastInsert.Execute();
                }
                catch (Exception ex) {
                    TempData["errorTitle"]   = "Error";
                    TempData["errorMessage"] = ex.Message;
                    result.Credential.RevokeTokenAsync(CancellationToken.None).Wait();
                    return(RedirectToAction("Details", "Event", liveModel.eventID));
                }

                //Set LiveStream Snippet
                LiveStreamSnippet streamSnippet = new LiveStreamSnippet();
                streamSnippet.Title = liveModel.Title + "Stream Title";
                CdnSettings cdnSettings = new CdnSettings();
                cdnSettings.Format        = liveModel.Quality;
                cdnSettings.IngestionType = "rtmp";

                //Set LiveStream
                LiveStream streamLive = new LiveStream();
                streamLive.Kind    = "youtube#liveStream";
                streamLive.Snippet = streamSnippet;
                streamLive.Cdn     = cdnSettings;
                LiveStream returnLiveStream = youtubeService.LiveStreams.Insert(streamLive, "snippet,cdn").Execute();
                LiveBroadcastsResource.BindRequest liveBroadcastBind = youtubeService.LiveBroadcasts.Bind(returnBroadcast.Id, "id,contentDetails");
                liveBroadcastBind.StreamId = returnLiveStream.Id;
                try
                {
                    returnBroadcast = liveBroadcastBind.Execute();
                }
                catch (Exception ex)
                {
                    TempData["errorTitle"]   = "Error";
                    TempData["errorMessage"] = ex.Message;
                    result.Credential.RevokeTokenAsync(CancellationToken.None).Wait();
                    return(RedirectToAction("Details", "Event", liveModel.eventID));
                }

                //Return Value
                String streamName       = returnLiveStream.Cdn.IngestionInfo.StreamName;
                String primaryServerUrl = returnLiveStream.Cdn.IngestionInfo.IngestionAddress;
                String backupServerUrl  = returnLiveStream.Cdn.IngestionInfo.BackupIngestionAddress;
                String youtubeUrl       = "https://www.youtube.com/watch?v=" + returnBroadcast.Id;

                //youtubeReturnModel model = new youtubeReturnModel { streamName = streamName, primaryServerUrl = primaryServerUrl,backupServerUrl=backupServerUrl,youtubeUrl=youtubeUrl };
                Video video = new Video {
                    EventPlaceID  = liveModel.EventPlaceID,
                    VideoLink     = youtubeUrl,
                    PrimaryServer = primaryServerUrl,
                    StartTime     = liveModel.StartTimeYoutube,
                    Privacy       = liveModel.PrivacyYoutube,
                    EndTime       = liveModel.EndTimeYoutube,
                    BackupServer  = backupServerUrl,
                    StreamName    = streamName
                };
                EventDatabaseHelper.Instance.AddVideo(video);

                HttpCookie newEventID = new HttpCookie("CreateEventID");
                newEventID.Expires = DateTime.Now.AddDays(-1);
                Request.Cookies.Add(newEventID);
                HttpCookie newModel = new HttpCookie("liveModel");
                newModel.Value   = new JavaScriptSerializer().Serialize(liveModel);
                newModel.Expires = DateTime.Now.AddHours(-1);
                Response.Cookies.Add(newModel);
                result.Credential.RevokeTokenAsync(CancellationToken.None).Wait();
                return(RedirectToAction("Details", "Event", new { id = EventDatabaseHelper.Instance.GetEventPlaceByID(liveModel.EventPlaceID).EventID }));
            }
            else
            {
                return(new RedirectResult(result.RedirectUri));
            }
        }