コード例 #1
0
        public EditCopypasta(Copypasta copypasta)
        {
            InitializeComponent();

            //? Translation

            if (Titles.Language == "EN")
            {
                FavouriteCheckbox.Content = Titles.Favourite_EN;
                DeleteCopypasta.Content   = Titles.Delete_EN;
                MaterialDesignThemes.Wpf.HintAssist.SetHint(TitleBox, Titles.Title_EN);
                MaterialDesignThemes.Wpf.HintAssist.SetHint(ContentBox, Titles.Content_EN);
                MaterialDesignThemes.Wpf.HintAssist.SetHint(DateAddedPicker, Titles.DateAdded_EN);
                MaterialDesignThemes.Wpf.HintAssist.SetHint(ChannelFromBox, Titles.ChannelFrom_EN);
            }
            else
            {
                FavouriteCheckbox.Content = Titles.Favourite;
                DeleteCopypasta.Content   = Titles.Delete;
                MaterialDesignThemes.Wpf.HintAssist.SetHint(TitleBox, Titles.Title);
                MaterialDesignThemes.Wpf.HintAssist.SetHint(ContentBox, Titles.Content);
                MaterialDesignThemes.Wpf.HintAssist.SetHint(DateAddedPicker, Titles.DateAdded);
                MaterialDesignThemes.Wpf.HintAssist.SetHint(ChannelFromBox, Titles.ChannelFrom);
            }

            //? End translation

            Copypasta = copypasta;

            TitleBox.Text                = Copypasta.Title;
            ContentBox.Text              = Copypasta.Content;
            FavouriteCheckbox.IsChecked  = Copypasta.IsFavourite;
            DateAddedPicker.SelectedDate = Copypasta.DateAdded;
            ChannelFromBox.Text          = Copypasta.ChannelFrom;
        }
コード例 #2
0
        public CopypastaBlock(Copypasta copypasta)
        {
            InitializeComponent();

            //? How is this ever null?

            if (copypasta != null)
            {
                Copypasta         = copypasta;
                ContentBlock.Text = Copypasta.Content;
                DateBlock.Text    = Copypasta.DateAdded.ToString("dd.MM.y H:mm");

                if (string.IsNullOrEmpty(Copypasta.Title))
                {
                    TitleBlock.Text = Titles.Language == "EN" ? Titles.Pasta_NoTitle_EN : Titles.Pasta_NoTitle;
                }
                else
                {
                    TitleBlock.Text = Copypasta.Title;
                }

                if (Copypasta.IsFavourite)
                {
                    FavouriteIcon.IsEnabled  = true;
                    FavouriteIcon.Kind       = MaterialDesignThemes.Wpf.PackIconKind.Star;
                    FavouriteIcon.Foreground = Brushes.Gold;
                }
                else
                {
                    FavouriteIcon.IsEnabled  = true;
                    FavouriteIcon.Kind       = MaterialDesignThemes.Wpf.PackIconKind.StarOutline;
                    FavouriteIcon.Foreground = Brushes.Black;
                }
            }
        }
コード例 #3
0
        private void SaveButton_Click(object sender, RoutedEventArgs e)
        {
            if (ContentBox.Text == "")
            {
                if (Titles.Language == "EN")
                {
                    MessageBox.Show(Titles.ContentEmptyError_EN, Titles.ErrorTitle_EN, MessageBoxButton.OK, MessageBoxImage.Error);
                }
                else
                {
                    MessageBox.Show(Titles.ContentEmptyError, Titles.ErrorTitle, MessageBoxButton.OK, MessageBoxImage.Error);
                }

                return;
            }

            var pasta = new Copypasta
            {
                Title       = TitleBox.Text,
                Content     = ContentBox.Text,
                DateAdded   = DateTime.Now,
                IsFavourite = FavouriteCheckbox.IsChecked.Value,
                ChannelFrom = ""
            };

            DatabaseOperations.AddToDatabase(pasta);
        }
コード例 #4
0
        public static void DeleteCopypasta(Copypasta copypasta)
        {
            // Delete the given copypasta from the database

            using (var db = new CopypastaContext())
            {
                var pasta = (from c in db.Copypastas where c.Id == copypasta.Id select c).SingleOrDefault();

                db.Copypastas.Remove(pasta);
                db.SaveChanges();
            }
        }
コード例 #5
0
        public static void AddToDatabase(Copypasta copypasta)
        {
            //First check if this pasta is already there (title doesn't matter because it isn't key anyway, it can appear multiple times)

            using (var db = new CopypastaContext())
            {
                var query = from c in db.Copypastas where c.Content.Contains(copypasta.Content) select c;
                if (query.Any())
                {
                    //this copypasta has already been added
                    return;
                }

                db.Copypastas.Add(copypasta);
                db.SaveChanges();
            }
        }
コード例 #6
0
        // Updates a given Copypasta - we assume the Id stays the same and other parameters can be chagned
        public static void UpdateCopypasta(Copypasta newPasta)
        {
            using (var db = new CopypastaContext())
            {
                var result = (from c in db.Copypastas where c.Id == newPasta.Id select c).SingleOrDefault();
                if (result != null)
                {
                    result.Title       = newPasta.Title;
                    result.Content     = newPasta.Content;
                    result.DateAdded   = newPasta.DateAdded;
                    result.IsFavourite = newPasta.IsFavourite;
                    result.ChannelFrom = newPasta.ChannelFrom;

                    db.SaveChanges();
                }
            }
        }
コード例 #7
0
        //Once _allMessages reaches MaxCapacity messages, evaluate and clear it
        private void EvaluateAllMessages()
        {
            _logger.Log(_logId++, $"Evaluating {_allMessages.Count} messages", DateTime.Now);

            for (int i = 0; i < _allMessages.Count; i++)
            {
                int currentCount   = 0;
                var currentMessage = _allMessages[i];

                for (int j = i + 1; j < _allMessages.Count; j++)
                {
                    if (_allMessages[j].Contains(currentMessage))
                    {
                        currentCount++;
                        _allMessages.RemoveAt(j);
                        j--;
                    }
                }

                if (currentCount >= MinCount)
                {
                    //check if the message is not blacklisted
                    //! important note - only messages *exactly the same* as the blacklisted will not get added
                    //! this means that a message having other content than just these blacklisted (emotes?), or a combination of blacklisted keywords, will get added

                    if (Blacklist.BlacklistedMessages.Contains(currentMessage))
                    {
                        continue;
                    }

                    var pasta = new Copypasta()
                    {
                        Content   = currentMessage,
                        DateAdded = DateTime.Now
                    };

                    _copypastas.Add(pasta);
                }
            }

            _allMessages.Clear();
        }