Ejemplo n.º 1
0
        public Task QuartzDeleteJobLogic(QuartzExecuteJob.QuartzExecuteJobRequest requestBody)
        {
            MethodInfo methodInfo = typeof(QuartzSchedulers).GetMethod(requestBody.scheduler);

            if (methodInfo is not null)
            {
                var        schedulerFactory = new StdSchedulerFactory();
                IScheduler scheduler        = schedulerFactory.GetScheduler().Result;

                var splitJobName = requestBody.name.Split(".");
                return(JobHelpers.CancelJob(splitJobName[1], splitJobName[0], (NameValueCollection)methodInfo.Invoke(this, null)));
            }
            else
            {
                return(Task.FromException(new SchedulerException("Scheduler does not exist.")));
            }
        }
Ejemplo n.º 2
0
        public DeleteStreamReturn DeleteSingleStreamLogic(long streamId)
        {
            using (var context = new MainDataContext()) {
                var stream = context.Streams.FirstOrDefault(item => item.streamId == streamId);
                if (stream == null)
                {
                    stream = context.Streams.FirstOrDefault(item => item.vodId == streamId); // add live stream delete capabilities
                }

                if (stream != null)
                {
                    if (stream.downloadJobId != null)
                    {
                        var splitJobKey = stream.downloadJobId.Split(".");
                        try {
                            JobHelpers.CancelJob(splitJobKey[1], splitJobKey[0], QuartzSchedulers.PrimaryScheduler(), true);
                        } catch (MissingJobException e) {
                            _logger.Info(e.Message);
                        }
                    }

                    if (stream.vodId != 0)
                    {
                        try {
                            CleanUpStreamFiles(GlobalConfig.GetGlobalConfig("contentRootPath"), stream.vodId, stream.streamerId);
                        } catch (DirectoryNotFoundException) {
                            CleanUpStreamFiles(GlobalConfig.GetGlobalConfig("contentRootPath"), stream.streamId, stream.streamerId);
                        }
                    }
                    else
                    {
                        CleanUpStreamFiles(GlobalConfig.GetGlobalConfig("contentRootPath"), stream.streamId, stream.streamerId);
                    }

                    context.Remove(stream);

                    if (stream.chatDownloadJobId != null)
                    {
                        var splitJobKey = stream.chatDownloadJobId.Split(".");
                        try {
                            JobHelpers.CancelJob(splitJobKey[1], splitJobKey[0], QuartzSchedulers.PrimaryScheduler(), true);
                        } catch (MissingJobException e) {
                            _logger.Info(e.Message);
                        }
                    }

                    using (var chatContext = new ChatDataContext()) {
                        chatContext.Chats.RemoveRange(chatContext.Chats.Where(item => item.streamId == streamId));
                        chatContext.SaveChanges();
                    }
                }

                context.SaveChanges();
            }

            TwitchApiHelpers twitchApiHelpers = new TwitchApiHelpers();
            var request =
                twitchApiHelpers.TwitchRequest("https://api.twitch.tv/helix/videos?id=" + streamId, Method.GET);

            if (request.StatusCode == HttpStatusCode.OK)
            {
                return(new DeleteStreamReturn {
                    isStillAvailable = true
                });
            }

            return(new DeleteStreamReturn {
                isStillAvailable = false
            });
        }
Ejemplo n.º 3
0
        public static void SetDownloadToFinished(long streamId, bool isLive)
        {
            Logger _logger = new NLog.LogFactory().GetCurrentClassLogger();

            using (var context = new MainDataContext()) {
                Stream dbStream;

                dbStream = context.Streams.FirstOrDefault(item => item.streamId == streamId);

                string streamFile = GlobalConfig.GetGlobalConfig("contentRootPath") + dbStream.location + dbStream.fileName;
                dbStream.size        = new FileInfo(streamFile).Length;
                dbStream.downloading = false;

                NotificationHub.Current.Clients.All.SendAsync($"{streamId}-completed",
                                                              dbStream);

                if (isLive)
                {
                    _logger.Info("Stopping live chat download...");
                    if (dbStream.chatDownloadJobId.Contains("."))
                    {
                        var splitJobKey = dbStream.chatDownloadJobId.Split(".");
                        JobHelpers.CancelJob(splitJobKey[1], splitJobKey[0], QuartzSchedulers.PrimaryScheduler());
                    }
                    else
                    {
                        JobHelpers.CancelJob(dbStream.chatDownloadJobId, null,
                                             QuartzSchedulers.PrimaryScheduler());
                    }

                    dbStream.chatDownloading = false;
                    dbStream.duration        = getStreamDuration(streamFile);
                    GenerateThumbnailDuration(streamId);
                }
                else
                {
                    _logger.Info("Stopping VOD chat download.");
                }

                context.SaveChanges();

                // make another background job for this
                string checkVideoThumbnailsEnabled = GlobalConfig.GetGlobalConfig("generateVideoThumbnails");

                if (checkVideoThumbnailsEnabled != null && checkVideoThumbnailsEnabled == "True")
                {
                    _logger.Info("Queueing video thumbnail creation job...");
                    IJobDetail job = JobBuilder.Create <GenerateVideoThumbnailJob>()
                                     .WithIdentity("GenerateVideoThumbnail" + streamId)
                                     .UsingJobData("streamId", streamId)
                                     .UsingJobData("streamFile", streamFile)
                                     .Build();

                    var        schedulerFactory = new StdSchedulerFactory(QuartzSchedulers.PrimaryScheduler());
                    IScheduler scheduler        = schedulerFactory.GetScheduler().Result;
                    scheduler.Start();

                    ISimpleTrigger trigger = (ISimpleTrigger)TriggerBuilder.Create()
                                             .WithIdentity("GenerateVideoThumbnail" + streamId)
                                             .StartNow()
                                             .Build();

                    scheduler.ScheduleJob(job, trigger);
                    //BackgroundJob.Enqueue(() => GenerateVideoThumbnail(streamId, streamFile));
                }
            }
        }