Ejemplo n.º 1
0
 internal PublishingTask(PublishBot publishBot, PostingManager postingManager, AdminBot adminBot)
 {
     this.posts       = postingManager;
     this.publishBot  = publishBot;
     this.adminBot    = adminBot;
     this.publishTask = this.periodicPublishingTask(new TimeSpan(0, 0, 0, IntervalCheckPublishSeconds, 0), this.cancelTaskSource.Token);
 }
Ejemplo n.º 2
0
 internal ModerationCheckTask(PostingManager posts, FeedbackManager feedbackManager, ModerateBot moderateBot)
 {
     this.posts               = posts;
     this.feedbackManager     = feedbackManager;
     this.moderateBot         = moderateBot;
     this.moderationCheckTask = this.periodicModerationCheckTask(new TimeSpan(0, 0, 0, intervalModerationCheckSeconds, 0), this.cancelTaskSource.Token);
 }
Ejemplo n.º 3
0
 internal void initData()
 {
     if (Utilities.Runningintestmode)
     {
         Roomname        = "c/1457606766";
         Roomname_daily  = "c/1151058807";
         Roomname_weekly = "c/1233617142";
     }
     logger.Info("Lade Autor-Manager");
     this.authors = new AuthorManager();
     logger.Info("Lade Posting-Manager");
     this.posts = new PostingManager();
     logger.Info("Lade Statistik-Manager");
     this.statistics = new DRaumStatistics();
     logger.Info("Lade Feedback-Manager");
     this.feedbackManager = new FeedbackManager();
     if (!this.loadDataFromFiles())
     {
         this.startupinfo = "!!! Server ist ohne Daten gestartet !!!";
         logger.Info("Lade Autor-Manager neu");
         this.authors = new AuthorManager();
         logger.Info("Lade Posting-Manager neu");
         this.posts = new PostingManager();
         logger.Info("Lade Statistik-Manager neu");
         this.statistics = new DRaumStatistics();
         logger.Info("Lade Feedback-Manager neu");
         this.feedbackManager = new FeedbackManager();
     }
     else
     {
         this.startupinfo = "Server ist gestartet";
     }
     this.textBuilder  = new PostingTextBuilder(this.posts, this.authors);
     this.startupinfo += "\r\nMaximale Autorenzahl:" + AuthorManager.Maxmanagedusers;
 }
Ejemplo n.º 4
0
        public void checkMassPostings()
        {
            AuthorManager.Maxmanagedusers = int.MaxValue;
            Utilities.Runningintestmode   = true;
            AuthorManager  authors  = new AuthorManager();
            PostingManager postings = new PostingManager();

            NLog.LogManager.DisableLogging();

            for (int i = 0; i < 5000; i++)
            {
                authors.getCoolDownTimer(10000 + i, "autor_" + i, Author.InteractionCooldownTimer.Default);
            }

            int authorid = 10000;

            for (int monat = 1; monat <= 6; monat++)
            {
                for (int tag = 1; tag <= 30; tag++)
                {
                    for (int postcount = 0; postcount < 200; postcount++)
                    {
                        postings.addPosting("Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt " +
                                            "ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo " +
                                            "dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit " +
                                            "amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor " +
                                            "invidunt ut labor" + postcount + ":" + tag + ":" + monat, authorid);
                        authorid++;
                        if (authorid > 14999)
                        {
                            authorid = 10000;
                        }
                    }
                }
            }

            DateTime     before     = DateTime.Now;
            FileStream   backupfile = File.Create("testposts.json");
            StreamWriter sr         = new StreamWriter(backupfile);

            sr.Write(JsonConvert.SerializeObject(postings, Formatting.Indented));
            sr.Close();
            TimeSpan durationToStore = DateTime.Now - before;

            Console.Out.WriteLine("Speichern dauerte " + durationToStore.TotalSeconds + " Sekunden.");

            before = DateTime.Now;
            FileStream   inputFilestream = File.OpenRead("testposts.json");
            StreamReader sreader         = new StreamReader(inputFilestream);
            string       jsonstring      = sreader.ReadToEnd();

            sreader.Close();
            postings        = JsonConvert.DeserializeObject <PostingManager>(jsonstring);
            durationToStore = DateTime.Now - before;

            Console.Out.WriteLine("Laden dauerte " + durationToStore.TotalSeconds + " Sekunden.");

            Assert.IsTrue(true);
        }
Ejemplo n.º 5
0
 internal VoteAndFlagTask(PostingManager postingManager, PublishBot publishBot, DRaumStatistics statistics, AdminBot adminBot)
 {
     this.statistics      = statistics;
     this.adminBot        = adminBot;
     this.publishBot      = publishBot;
     this.posts           = postingManager;
     this.voteAndFlagTask = this.periodicVoteAndFlagTask(new TimeSpan(0, 0, intervalVoteAndFlagCountMinutes, 0, 0), this.cancelTaskSource.Token);
 }
Ejemplo n.º 6
0
 internal StatisticCollectionTask(AuthorManager authors, DRaumStatistics statistics, PostingManager posts, AdminBot adminBot)
 {
     this.authors    = authors;
     this.posts      = posts;
     this.statistics = statistics;
     this.adminBot   = adminBot;
     this.statisticCollectionTask = this.periodicStatisticCollectionTask(new TimeSpan(0, 0, intervalStatisticCollectionMinutes, 0, 0), this.cancelTaskSource.Token);
 }
Ejemplo n.º 7
0
        public void postDoubleVoteDenyTest()
        {
            PostingManager pmgr = new PostingManager();
            AuthorManager  amgr = new AuthorManager();

            Utilities.Runningintestmode = false;
            amgr.setPostMode(10, "user1");
            amgr.setPostMode(20, "user2");
            pmgr.addPosting("testpost", 10);
            KeyValuePair <long, string> kvp = pmgr.getNextPostToCheck();
            long postingId = kvp.Key;

            pmgr.acceptPost(postingId, PostingPublishManager.PublishHourType.Normal);
            Assert.IsFalse(pmgr.isAuthor(postingId, 20));
            Assert.IsTrue(amgr.canUserVote(postingId, 20, "hans"));
            amgr.vote(postingId, 20);
            pmgr.upvote(postingId, 5);
            Assert.IsFalse(!pmgr.isAuthor(postingId, 20) && amgr.canUserVote(postingId, 20, "hans"));
            Assert.IsFalse(!pmgr.isAuthor(postingId, 10) && amgr.canUserVote(postingId, 10, "hans"));
        }
Ejemplo n.º 8
0
        internal PublishBot(TelegramBotClient telegramPublishBot, PostingManager posts, PostingTextBuilder textBuilder,
                            Func <ITelegramBotClient, Update, CancellationToken, Task> updateHandler,
                            Func <ITelegramBotClient, Exception, CancellationToken, Task> errorHandler)
        {
            this.draumChatId        = long.Parse(ConfigurationManager.AppSettings["mainRoomID"]);
            this.draumDailyChatId   = long.Parse(ConfigurationManager.AppSettings["dailyRoomID"]);
            this.draumWeeklyChatId  = long.Parse(ConfigurationManager.AppSettings["weeklyRoomID"]);
            this.telegramPublishBot = telegramPublishBot;
            this.textBuilder        = textBuilder;
            this.posts = posts;

            var receiverOptions = new ReceiverOptions();

            receiverOptions.AllowedUpdates      = new Telegram.Bot.Types.Enums.UpdateType[] { Telegram.Bot.Types.Enums.UpdateType.CallbackQuery };
            receiverOptions.ThrowPendingUpdates = true;
            this.telegramPublishBot.StartReceiving(
                updateHandler,
                errorHandler,
                receiverOptions,
                cancellationToken: cts.Token);
        }
Ejemplo n.º 9
0
    // called second
    void OnSceneLoaded(Scene scene, LoadSceneMode mode)
    {
        if (allCharacters == null)
        {
            allCharacters = new Dictionary <string, Character>();
        }

        if (!allCharacters.ContainsKey(currentCharacterName))
        {
            Character character = new Character(currentCharacterName);
            allCharacters.Add(currentCharacterName, character);
        }

        if (scene.name == "PhoneUIDemo")
        {
            dialogueManager   = GameObject.Find("DialogueManager").GetComponent <DialogueManager>();
            interactUIManager = GameObject.Find("InteractUIManager").GetComponent <InteractUIManager>();
            sfxManager        = GameObject.Find("SFXManager").GetComponent <SFXManager>();

            dialogueManager.setDialogue(allCharacters[currentCharacterName].getDialogue());
            interactUIManager.setCharacter(allCharacters[currentCharacterName]);
            interactUIManager.setCharacterPortrait(CharacterExpression.Default);
            interactUIManager.setBackgroundImage();
            startGreetingDialogue();
        }

        else if (scene.name == "PostDemo")
        {
            postingManager = GameObject.Find("PostingManager").GetComponent <PostingManager>();

            postingManager.setPostImages(allCharacters[currentCharacterName].getPostImages());
            postingManager.startPostingMinigame();
        }

        else if (scene.name == "Match3Game")
        {
            boardManager = GameObject.Find("BoardManager").GetComponent <Board>();
            boardManager.setVals(allCharacters[currentCharacterName]);
        }
    }
Ejemplo n.º 10
0
        internal InputBot(AuthorManager authors, DRaumStatistics statistics, TelegramBotClient telegramInputBot,
                          PostingManager posts, FeedbackManager feedbackManager,
                          Func <ITelegramBotClient, Update, CancellationToken, Task> updateHandler,
                          Func <ITelegramBotClient, Exception, CancellationToken, Task> errorHandler)
        {
            this.authors          = authors;
            this.statistics       = statistics;
            this.telegramInputBot = telegramInputBot;
            this.posts            = posts;
            this.feedbackManager  = feedbackManager;

            var receiverOptions = new ReceiverOptions();

            receiverOptions.AllowedUpdates = new Telegram.Bot.Types.Enums.UpdateType[] {
                Telegram.Bot.Types.Enums.UpdateType.CallbackQuery,
                Telegram.Bot.Types.Enums.UpdateType.Message
            };
            receiverOptions.ThrowPendingUpdates = true;
            this.telegramInputBot.StartReceiving(
                updateHandler,
                errorHandler,
                receiverOptions,
                cancellationToken: cts.Token);
        }
Ejemplo n.º 11
0
        public void topPostingFilterTest()
        {
            PostingManager  pmgr     = new PostingManager();
            DRaumStatistics drs      = new DRaumStatistics();
            const int       numposts = 20;

            for (int i = 0; i < numposts; i++)
            {
                // ein paar posts anlegen
                pmgr.addPosting("Bla bla bla", 10 + i * 10);
            }

            int count = 0;
            KeyValuePair <long, string> pair;

            do
            {
                pair = pmgr.getNextPostToCheck();
                if (pair.Key != -1)
                {
                    count++;
                    string res = pmgr.acceptPost(pair.Key, PostingPublishManager.PublishHourType.Normal);
                    Assert.IsTrue(res.StartsWith("Veröffentlichung"));
                    pmgr.testPublishing(pair.Key, DateTime.Now.AddHours(-24));
                    for (int i = 0; i < count * 3; i++)
                    {
                        if (count > numposts / 2)
                        {
                            pmgr.downvote(pair.Key, 200 + i);
                        }
                        else
                        {
                            pmgr.upvote(pair.Key, 200 + i);
                        }
                    }
                }
            } while (pair.Key != -1);

            Assert.AreEqual(numposts, count);
            IEnumerable <long> list = pmgr.getDailyTopPostsFromYesterday();
            bool found10            = false;
            bool found09            = false;
            bool found08            = false;

            foreach (long postingId in list)
            {
                if (postingId == 10)
                {
                    found10 = true;
                }
                if (postingId == 9)
                {
                    found09 = true;
                }
                if (postingId == 8)
                {
                    found08 = true;
                }
            }

            Assert.IsTrue(found10 && found09 && found08);
        }
Ejemplo n.º 12
0
 internal PostingTextBuilder(PostingManager postingManager, AuthorManager authorManager)
 {
     this.posts   = postingManager;
     this.authors = authorManager;
 }
Ejemplo n.º 13
0
        // == Persistency
        private bool loadDataFromFiles()
        {
            // Suche im Backup-Ordner nach dem neuesten Satz backupdateien
            string        dateprefix = "";
            DirectoryInfo di         = new DirectoryInfo(BackupFolder);

            if (di.Exists)
            {
                FileInfo[] filelist = di.GetFiles();
                Array.Sort(filelist, new FileDateComparer());
                // Ist nun aufsteigend sortiert
                int  lastindex  = filelist.Length - 1;
                bool validFound = false;
                while (!validFound && lastindex >= 0)
                {
                    // Es müssen vier gleiche Dateien vorhanden sein
                    if (filelist[lastindex].Name.Substring(0, 18).Equals(filelist[lastindex - 1].Name.Substring(0, 18)) &&
                        filelist[lastindex].Name.Substring(0, 18).Equals(filelist[lastindex - 2].Name.Substring(0, 18)) &&
                        filelist[lastindex].Name.Substring(0, 18).Equals(filelist[lastindex - 3].Name.Substring(0, 18)))
                    {
                        validFound = true;
                        dateprefix = filelist[lastindex].Name.Substring(0, filelist[lastindex].Name.IndexOf(FilePrefix, StringComparison.Ordinal));
                        logger.Info("Lade die Daten aus diesen Dateien: " + filelist[lastindex].Name);
                        if (lastindex != filelist.Length - 1)
                        {
                            logger.Warn("Dies waren nicht die letzten Dateien im Verzeichnis: " + filelist[lastindex].Name);
                        }
                    }
                    lastindex--;
                }
                if (!validFound)
                {
                    return(false);
                }
            }

            FileStream inputFilestream = null;

            try
            {
                logger.Info("Lese Autoren-Daten aus dem Dateisystem");
                inputFilestream = File.OpenRead(BackupFolder + Path.DirectorySeparatorChar + dateprefix + FilePrefix + "authors.json");
                StreamReader sr         = new StreamReader(inputFilestream);
                string       jsonstring = sr.ReadToEnd();
                sr.Close();
                this.authors = JsonConvert.DeserializeObject <AuthorManager>(jsonstring);
                logger.Info("Lese Post-Daten aus dem Dateisystem");
                inputFilestream = File.OpenRead(BackupFolder + Path.DirectorySeparatorChar + dateprefix + FilePrefix + "posts.json");
                sr         = new StreamReader(inputFilestream);
                jsonstring = sr.ReadToEnd();
                sr.Close();
                this.posts = JsonConvert.DeserializeObject <PostingManager>(jsonstring);
                logger.Info("Lese Statistik-Daten aus dem Dateisystem");
                inputFilestream = File.OpenRead(BackupFolder + Path.DirectorySeparatorChar + dateprefix + FilePrefix + "statistic.json");
                sr         = new StreamReader(inputFilestream);
                jsonstring = sr.ReadToEnd();
                sr.Close();
                this.statistics = JsonConvert.DeserializeObject <DRaumStatistics>(jsonstring);
                logger.Info("Lese Feedback-Daten aus dem Dateisystem");
                inputFilestream = File.OpenRead(BackupFolder + Path.DirectorySeparatorChar + dateprefix + FilePrefix + "feedback.json");
                sr         = new StreamReader(inputFilestream);
                jsonstring = sr.ReadToEnd();
                sr.Close();
                this.feedbackManager = JsonConvert.DeserializeObject <FeedbackManager>(jsonstring);
                if (this.authors == null || this.posts == null || this.statistics == null || this.feedbackManager == null)
                {
                    logger.Error("Beim Deserialisieren wurde eine Klasse als NULL deserialisiert!");
                    return(false);
                }
                this.posts.transferFromInCheckToToCheck();
                return(true);
            }
            catch (Exception e)
            {
                logger.Error(e, "Fehler beim Laden der Daten, es wird bei 0 begonnen");
            }
            finally
            {
                inputFilestream?.Close();
            }
            return(false);
        }