Пример #1
0
        public void EventHandling()
        {
            LogsCollection logsCollection = new LogsCollection();
            bool           isCalled       = false;

            logsCollection.OnAdd += (entry) => { isCalled = !isCalled; };

            logsCollection.Add(new Entry("smth"));
            Assert.IsTrue(isCalled);
            logsCollection.Add(new Entry("smth2"));
            Assert.IsFalse(isCalled);
            logsCollection.Add(new Entry("smth3"));
            Assert.IsTrue(isCalled);

            LogsCollection logsCollection2 = new LogsCollection();

            logsCollection.OnAdd += (entry) =>
            {
                logsCollection2.Add(new Entry(entry.Text, entry.Time, entry.Level));
            };

            logsCollection.Add(new Entry
                               (
                                   "test2.0",
                                   new DateTime(1992, 6, 12, 12, 0, 0),
                                   EntryLevel.System)
                               );

            Entry expected = new Entry("test2.0", new DateTime(1992, 6, 12, 12, 0, 0), EntryLevel.System);

            Assert.AreEqual(expected, logsCollection2.LastAdded());
        }
Пример #2
0
        public void LogsCollectionIsCollection()
        {
            LogsCollection logsCollection = new LogsCollection();

            logsCollection.Add(new Entry("log1"));
            logsCollection.Add(new Entry("log2", new DateTime(2019, 6, 7, 5, 0, 32)));

            Assert.AreEqual(2, logsCollection.Count());
        }
Пример #3
0
        public void EnumerationCollection()
        {
            LogsCollection logsCollection = new LogsCollection();

            logsCollection.Add(new Entry("log..."));
            logsCollection.Add(new Entry("log.."));
            logsCollection.Add(new Entry("log."));
            logsCollection.Add(new Entry("log"));

            Assert.AreEqual("log...", logsCollection[0].Text);
            Assert.AreEqual("log..", logsCollection[1].Text);
            Assert.AreEqual("log.", logsCollection[2].Text);
            Assert.AreEqual("log", logsCollection[3].Text);
        }
Пример #4
0
        public void LogsCollectionCountOfContains()
        {
            LogsCollection logsCollection = new LogsCollection();

            for (int i = 0; i < 10; ++i)
            {
                logsCollection.Add(new Entry("log" + i.ToString()));
                if (i % 2 == 0)
                {
                    logsCollection.Add(new Entry("Log" + i.ToString() + ".2"));
                    logsCollection.Add(new Entry("lo" + i.ToString() + "g"));
                }
            }

            Assert.AreEqual(20, logsCollection.Count());
            Assert.AreEqual(15, logsCollection.CountOfContains("log"));
            Assert.AreEqual(10, logsCollection.CountOfContains("log", true));
        }
        public override void ViewAppeared()
        {
            base.ViewAppeared();

            _token ??= _messenger.Subscribe <NotificationMessage>(msg =>
            {
                LogsCollection.Add(new LogLine($"{DateTime.Now:T}: {msg.Message}", msg.Data));
                RaisePropertyChanged(() => LogsCollection);
            });
        }
Пример #6
0
        public void LastLog()
        {
            LogsCollection logsCollection = new LogsCollection();
            Entry          log1           = new Entry("smth", new DateTime(2203, 1, 1, 1, 1, 1));
            Entry          log2           = new Entry("smth2");

            logsCollection.Add(log1);
            for (int i = 0; i < 10; ++i)
            {
                logsCollection.Add(new Entry("smth for " + i.ToString()));
            }
            logsCollection.Add(log2);

            Entry lastLog1 = logsCollection.LastByTime();
            Entry lastLog2 = logsCollection.LastAdded();

            Assert.AreEqual(log1, lastLog1);
            Assert.AreEqual(log2, lastLog2);
        }
Пример #7
0
        public void LogsByEntryLevel()
        {
            LogsCollection logsCollection = new LogsCollection();
            List <string>  results        = new List <string>
            {
                "ban smwh",
                "add smth",
                "delete smth"
            };

            logsCollection.Add(new Entry(results[0], EntryLevel.Admin));
            logsCollection.Add(new Entry(results[1], EntryLevel.Admin));
            logsCollection.Add(new Entry(results[2], EntryLevel.Admin));
            logsCollection.Add(new Entry("try ban", EntryLevel.User));
            logsCollection.Add(new Entry("try add", EntryLevel.Undefined));
            logsCollection.Add(new Entry("try delete", EntryLevel.Server));

            List <Entry> entries = logsCollection.GetLogsByLevel(EntryLevel.Admin).ToList();

            Assert.AreEqual(3, entries.Count());
            Assert.AreEqual(results[0], entries[0].Text);
            Assert.AreEqual(EntryLevel.Admin, entries[0].Level);
            Assert.AreEqual(results[1], entries[1].Text);
            Assert.AreEqual(EntryLevel.Admin, entries[1].Level);
            Assert.AreEqual(results[2], entries[2].Text);
            Assert.AreEqual(EntryLevel.Admin, entries[2].Level);
        }
Пример #8
0
        public LogsCollection GetActionLogByReffID(string InternalID)
        {
            LogsCollection logss = null;

            if (!this.IsReady)
            {
                base.CurDBEngine = new DatabaseEngine(this.DBType, this.Conn);
                if (this.IsReady = base.CurDBEngine.Connect())
                {
                    this.CurSQLFactory = new SQLFactory(this.DBType);
                }
            }
            if (this.IsReady)
            {
                DatabaseParameters parameters = new DatabaseParameters();
                parameters.Add(new DatabaseParameter(this.DataStructure.Tables.LogActions.ReffID.ActualFieldName, InternalID));
                this.CurSQLFactory.SelectCommand(parameters, this.DataStructure.Tables.LogActions.ActualTableName);
                DataTable table = base.CurDBEngine.SelectQuery(this.CurSQLFactory.SQL);
                if (table != null)
                {
                    logss = new LogsCollection();
                    DataRow[] rowArray = table.Select("", this.DataStructure.Tables.LogActions.LogDateTime.ActualFieldName);
                    foreach (DataRow row in rowArray)
                    {
                        ActionLogItem item = new ActionLogItem {
                            ReffID            = row[this.DataStructure.Tables.LogActions.ReffID.ActualFieldName].ToString(),
                            LogDate           = Convert.ToDateTime(row[this.DataStructure.Tables.LogActions.LogDateTime.ActualFieldName]),
                            LoggedBy          = new ApplicationUser(row[this.DataStructure.Tables.LogActions.LogBy.ActualFieldName].ToString()),
                            ActionDescription = row[this.DataStructure.Tables.LogActions.Description.ActualFieldName].ToString()
                        };
                        logss.Add(item);
                    }
                    return(logss);
                }
                this.ErrMsg = "[LogManager.GetActionLogByReffID] : Failed at this.CurDBEngine.SelectQuery('" + this.CurSQLFactory.SQL + "') : " + base.CurDBEngine.ErrorMessage;
            }
            return(logss);
        }