public void AddChatMessageToDb(List <ChatMessageJsonClass.Comment> comments, long streamId)
        {
            using (var context = new ChatDataContext()) {
                _logger.Info("Saving chat...");
                foreach (var comment in comments)
                {
                    context.Chats.Add(new Chat {
                        messageId     = comment._id,
                        streamId      = streamId,
                        body          = comment.message.body,
                        userId        = comment.commenter._id,
                        userName      = comment.commenter.name,
                        sentAt        = comment.created_at,
                        offsetSeconds = comment.content_offset_seconds,
                        userBadges    = comment.message.userBadges,
                        userColour    = comment.message.user_color,
                        mod           = comment.message.userBadges?.Contains("moderator") ?? false,
                        subscriber    = comment.message.userBadges?.Contains("subscriber") ?? false,
                        turbo         = comment.message.userBadges?.Contains("turbo") ?? false,
                        emotes        = comment.message.formattedEmoticons
                    });
                }

                context.SaveChanges();
            }
        }
 private void RemoveStreamChatFromDb(long streamId)
 {
     using (var context = new ChatDataContext()) {
         var existingChat = context.Chats.Where(item => item.streamId == streamId);
         context.RemoveRange(existingChat);
         context.SaveChanges();
     }
 }
Пример #3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="MessageBox"/> class.
        /// </summary>
        /// <param name="Msgbox_typename">The msgbox_typename.</param>
        /// <param name="content">The content.</param>
        /// <param name="btnleft_content">The btnleft_content.</param>
        /// <param name="btnright_content">The btnright_content.</param>
        /// <param name="isUsedForForward">if set to <c>true</c> [is used for forward].</param>
        public MessageBox(string Msgbox_typename, string content, string btnleft_content, string btnright_content, bool isUsedForForward)
        {
            btnleft_Content  = btnleft_content;
            btnright_Content = btnright_content;
            IsUsedForForward = isUsedForForward;
            InitializeComponent();
            this.DataContext        = ChatDataContext.GetInstance();
            ForwardError.Visibility = System.Windows.Visibility.Hidden;
            ForwardError.Content    = "";
            if (Msgbox_typename == "close")
            {
                this.DialogResult = true;
                this.Close();
            }
            if (IsUsedForForward)
            {
                growFwd.Height     = GridLength.Auto;
                btn_left.IsEnabled = false;
            }
            else
            {
                growFwd.Height = new GridLength(0);
            }

            if (IsUsedForForward)
            {
                if (Msgbox_typename.Contains("Cancel"))
                {
                    lblTitle.Content   = Msgbox_typename;
                    btn_left.IsEnabled = true;
                }
                else
                {
                    lblTitle.Content = Msgbox_typename;
                }
            }
            else
            {
                lblTitle.Content = Msgbox_typename + " - Agent Interaction Desktop";
            }

            txtblockContent.Text = content;
            if (!string.IsNullOrEmpty(btnleft_content))
            {
                btn_left.Content = btnleft_content;
            }
            else
            {
                btn_left.Visibility = System.Windows.Visibility.Hidden;
            }
            btn_right.Content        = btnright_content;
            ShadowEffect.ShadowDepth = 0;
            ShadowEffect.Opacity     = 0.5;
            ShadowEffect.Softness    = 0.5;
            ShadowEffect.Color       = (Color)ColorConverter.ConvertFromString("#003660");
        }
Пример #4
0
        public void AddLiveStreamChatToDb(List <Chat> chats, long streamId)
        {
            using (var context = new ChatDataContext()) {
                _logger.Info("Saving live chat...");
                for (int i = 0; i < chats.Count; i++)
                {
                    context.Chats.Add(chats[i]);
                }

                context.SaveChanges();
            }
        }
Пример #5
0
        public string getChatLogic(long streamId)
        {
            List <Databases.Chat.Models.Chat> streamChat;

            using (var context = new ChatDataContext()) {
                streamChat = context.Chats.Where(item => item.streamId == streamId).ToList();
            }

            Directory.CreateDirectory(GlobalConfig.GetGlobalConfig("contentRootPath") + "tmp");
            string path = GlobalConfig.GetGlobalConfig("contentRootPath") + $"tmp/{streamId}.txt";

            File.WriteAllText(path, JsonConvert.SerializeObject(streamChat));

            return($"/tmp/{streamId}.txt");
        }
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            ImageSource imgSource = null;

            if (value.ToString().ToLower().Contains("email"))
            {
                imgSource = new BitmapImage(new Uri(ChatDataContext.GetInstance().Imagepath + "\\Email\\Email.png", UriKind.Relative));
            }
            else if (value.ToString().ToLower().Contains("chat"))
            {
                imgSource = new BitmapImage(new Uri(ChatDataContext.GetInstance().Imagepath + "\\Chat\\Chat.png", UriKind.Relative));
            }
            else
            {
                imgSource = null;
            }
            return(imgSource);
        }
Пример #7
0
        // removes any in-progress live stream downloads since the last run from the database
        public Task RemoveLeftOverLiveStreamDownloads()
        {
            List <Stream> streams;

            Console.WriteLine("Checking for dead streams...");
            using (var mainDataContext = new MainDataContext()) {
                streams = mainDataContext.Streams.Where(stream => stream.vodId != 0 && stream.downloading).ToList();
                mainDataContext.RemoveRange(streams);

                if (streams.Count > 0)
                {
                    using (var chatDataContext = new ChatDataContext()) {
                        chatDataContext.RemoveRange(chatDataContext.Chats.Where(chat => streams.Select(stream => stream.streamId).Contains(chat.streamId)));
                        chatDataContext.SaveChanges();
                    }
                }

                mainDataContext.SaveChanges();
            }


            Console.WriteLine("Done!");
            return(Task.CompletedTask);
        }
Пример #8
0
 public UserRepository(ChatDataContext context) : base(context)
 {
     _context = context;
 }
Пример #9
0
 public ChatHub(ChatDataContext context)
 {
     _context = context;
 }
 public ChatController(ChatDataContext context)
 {
     _context = context;
 }
Пример #11
0
 public MessageRepository(ChatDataContext context) : base(context)
 {
     _context = context;
 }
Пример #12
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
            });
        }
Пример #13
0
 public BaseRepository(ChatDataContext context)
 {
     _context = context;
 }