コード例 #1
0
        public async Task Cannot_revoke_only_owner_grant()
        {
            var capture   = new PlaintextKeyCapture("rosebud", "rosebud");
            var service   = new TempKeyFileService();
            var publicKey = CryptoTestHarness.GenerateKeyFile(_output, capture, service);

            capture.Reset();

            var revoke = new RevokeRole(Constants.DefaultOwnerRole, publicKey, publicKey);

            revoke.Sign(service, capture);
            Assert.True(revoke.Verify(), "revocation did not verify");

            using var fixture = new LogStoreFixture();

            var @default = LogEntryFactory.CreateNamespaceEntry(Constants.DefaultNamespace, default);
            await fixture.Store.AddEntryAsync(@default);

            var ontology = new MemoryOntologyLog(new OntologyEvents(), publicKey);

            Assert.Single(ontology.Roles[Constants.DefaultNamespace]);

            await fixture.Store.AddEntryAsync(LogEntryFactory.CreateEntry(revoke));

            await Assert.ThrowsAsync <CannotRemoveSingleOwnerException>(() => ontology.MaterializeAsync(fixture.Store));
        }
        public void ArchiveFilesExistWhenLoggingMultipleEntriesWithRollingFlatFileTraceListener()
        {
            if (Directory.Exists("RFFLogFiles"))
            {
                Directory.Delete("RFFLogFiles", true);
            }

            LogWriterFactory factory = new LogWriterFactory((e) => this.ConfigurationSource.GetSection("loggingConfiguration99"));

            this.writer = factory.Create();

            for (int i = 0; i < 18; i++)
            {
                LogEntry entry = LogEntryFactory.GetLogEntry("RFFRoleOnSize", this.GetTwoKBMessage());

                this.writer.Write(entry);
            }

            this.writer.Dispose();

            Assert.AreEqual(5, Directory.GetFiles(".\\RFFLogFiles", "Log3*.log", SearchOption.TopDirectoryOnly).Length);

            Assert.IsTrue(File.Exists(Path.Combine("RFFLogFiles", String.Format("log3.{0}.14.log", DateTime.Now.Year))));
            Assert.IsTrue(File.Exists(Path.Combine("RFFLogFiles", String.Format("log3.{0}.15.log", DateTime.Now.Year))));
            Assert.IsTrue(File.Exists(Path.Combine("RFFLogFiles", String.Format("log3.{0}.16.log", DateTime.Now.Year))));
            Assert.IsTrue(File.Exists(Path.Combine("RFFLogFiles", String.Format("log3.{0}.17.log", DateTime.Now.Year))));
        }
コード例 #3
0
        public void EntryIsWrittenWhenLoggingUsingEventLog()
        {
            const string ListenerName  = "Event Log Listener";
            const string FormatterName = "Text Formatter";
            const string Template      = "My template";

            configurationStart.WithOptions
            .LogToCategoryNamed(CategoryName)
            .WithOptions
            .SetAsDefaultCategory()
            .ToSourceLevels(SourceLevels.All)
            .SendTo
            .EventLog(ListenerName)
            .WithTraceOptions(TraceOptions.None)
            .FormatWith(new FormatterBuilder()
                        .TextFormatterNamed(FormatterName)
                        .UsingTemplate(Template));

            this.SetConfigurationSource();

            LogWriterFactory factory = new LogWriterFactory((e) => this.ConfigurationSource.GetSection(e));

            this.writer = factory.Create();
            Logger.SetLogWriter(this.writer);

            LogEntry logEntry = LogEntryFactory.GetLogEntry();

            this.writer.Write(logEntry);

            Assert.IsTrue(this.CheckForEntryInEventlog(Template));
        }
        public void CustomListenerIsInvokedWhenConfigured()
        {
            const string ListenerName  = "Custom Listener";
            const string FormatterName = "Text Formatter";
            const string Template      = "My template";

            configurationStart.LogToCategoryNamed(CategoryName)
            .WithOptions
            .DoNotAutoFlushEntries()
            .SetAsDefaultCategory()
            .ToSourceLevels(SourceLevels.All)
            .SendTo
            .Custom(ListenerName, typeof(MyCustomTraceListener))
            .WithTraceOptions(TraceOptions.DateTime)
            .Filter(SourceLevels.Verbose)
            .FormatWith(new FormatterBuilder()
                        .TextFormatterNamed(FormatterName)
                        .UsingTemplate(Template));

            this.SetConfigurationSource();

            LogWriterFactory factory = new LogWriterFactory((e) => this.ConfigurationSource.GetSection(e));

            this.writer = factory.Create();
            Logger.SetLogWriter(this.writer);
            LogEntry entry = LogEntryFactory.GetLogEntry();

            entry.Categories.Add(LoggingFixtureBase.CategoryName);

            this.writer.Write(entry);

            Assert.IsTrue(MyCustomTraceListener.Wrote);
        }
コード例 #5
0
 private void SetupMatchService(Action <RtSession> onStartRtSession)
 {
     _matchService.SubscribeToOnMatchNotFound(() =>
     {
         OnLogEntryReceived(LogEntryFactory.CreateMatchNotFoundLogEntry());
     });
     _matchService.SubscribeToOnMatchFound(rtSession =>
     {
         _sessionListDict.Add(rtSession.MatchId, rtSession);
         _sessionGui.MatchMakingGui.AddRealTimeSessionKey(rtSession.MatchId);
         OnLogEntryReceived(LogEntryFactory.CreateMatchFoundLogEntry(rtSession));
     });
     _sessionGui.MatchMakingGui.Initialize(
         rtSessionKey =>
     {
         if (!_sessionListDict.ContainsKey(rtSessionKey))
         {
             return;
         }
         onStartRtSession(_sessionListDict[rtSessionKey]);
         _sessionGui.RealTimeControlGui.SetActive(true);
     },
         (skill, shortCode) =>
     {
         _matchService.FindMatch(skill, shortCode);
         OnLogEntryReceived(LogEntryFactory.CreateMatchMakingRequestLogEntry(skill, shortCode));
     });
 }
コード例 #6
0
        public void WhenCategoryFilterIsChanged()
        {
            string fileName = "trace.log";

            File.Delete(fileName);

            LogWriterFactory factory = new LogWriterFactory((e) => this.ConfigurationSource.GetSection("loggingConfiguration72"));

            this.writer = factory.Create();
            Logger.SetLogWriter(this.writer);

            var entry = LogEntryFactory.GetLogEntry();

            entry.Severity = System.Diagnostics.TraceEventType.Critical;
            entry.Categories.Clear();
            entry.Categories.Add("General");

            this.writer.Write(entry);

            FileInfo info = new FileInfo(fileName);

            Assert.IsTrue(info.Exists);
            long originalLength = info.Length;

            this.ReplaceCategoryFilter("General");

            this.writer.Write(entry);

            info = new FileInfo(fileName);

            Assert.IsTrue(info.Length == originalLength);
        }
コード例 #7
0
        public void EntryIsLoggedWhenLoggingLevelIsChanged()
        {
            string fileName = "trace.log";

            File.Delete(fileName);

            LogWriterFactory factory = new LogWriterFactory((e) => this.ConfigurationSource.GetSection("loggingConfiguration72"));

            this.writer = factory.Create();
            Logger.SetLogWriter(this.writer);

            var entry = LogEntryFactory.GetLogEntry();

            entry.Severity = System.Diagnostics.TraceEventType.Verbose;
            entry.Categories.Clear();
            entry.Categories.Add("General");

            this.writer.Write(entry);

            FileInfo info = new FileInfo(fileName);

            Assert.IsFalse(info.Exists);

            this.SetSourceLevel("General", SourceLevels.Critical);

            entry.Severity = TraceEventType.Critical;

            this.writer.Write(entry);

            info = new FileInfo(fileName);

            Assert.IsTrue(info.Exists);
            Assert.IsTrue(info.Length > 0);
        }
コード例 #8
0
        public void EntryIsWrittenWhenLoggingUsingBinaryLogFormatter()
        {
            const string BinaryFileName = "trace.log";

            File.Delete(BinaryFileName);

            LogWriterFactory factory = new LogWriterFactory((e) => this.ConfigurationSource.GetSection("loggingConfiguration102"));

            this.writer = factory.Create();

            LogEntry entry = LogEntryFactory.GetLogEntry();

            entry.Categories.Clear();
            entry.Categories.Add("General");

            if (writer.ShouldLog(entry))
            {
                this.writer.Write(entry);
            }

            Assert.IsTrue(File.Exists(BinaryFileName));

            FileInfo fileInfo = new FileInfo(BinaryFileName);

            Assert.IsTrue(fileInfo.Length > 0);

            LogEntry deserializedEntry = LogFileReader.GetEntry(BinaryFileName);

            Assert.AreEqual(entry.Message, deserializedEntry.Message);
            Assert.AreEqual(entry.Priority, deserializedEntry.Priority);
            Assert.AreEqual(entry.Severity, deserializedEntry.Severity);
        }
コード例 #9
0
        private void SendPongpacket(int pingRequestId, long pingTime)
        {
            SendPacket((int)OpCode.Pong, _settings.Protocol,
                       PacketDataFactory.GetTimestampPong(pingRequestId, pingTime));

            OnLogEntry(LogEntryFactory.CreatePongSentEntryLog(pingRequestId, (int)OpCode.Pong));
        }
        public void EntryIsWrittenWhenLoggingWithXmlFile()
        {
            const string FilePath     = "sample.xml";
            const string ListenerName = "Xml File Listener";

            File.Delete(FilePath);

            configurationStart.LogToCategoryNamed(CategoryName)
            .WithOptions
            .SetAsDefaultCategory()
            .ToSourceLevels(SourceLevels.All)
            .SendTo
            .XmlFile(ListenerName)
            .ToFile(FilePath)
            .WithTraceOptions(TraceOptions.None);

            this.SetConfigurationSource();

            LogWriterFactory factory = new LogWriterFactory((e) => this.ConfigurationSource.GetSection(e));

            this.writer = factory.Create();
            Logger.SetLogWriter(this.writer);

            LogEntry entry = LogEntryFactory.GetLogEntry();

            entry.Categories.Add(CategoryName);

            writer.Write(entry);

            FileInfo info = new FileInfo(FilePath);

            Assert.IsTrue(info.Exists);
            Assert.IsTrue(info.Length > 0);
        }
コード例 #11
0
        public void EntryIsWrittenWhenEventLogTraceListenerMin()
        {
            bool entrymade = false;

            LogWriterFactory factory = new LogWriterFactory((e) => this.ConfigurationSource.GetSection("loggingConfiguration68"));

            this.writer = factory.Create();
            Logger.SetLogWriter(this.writer);

            var entry = LogEntryFactory.GetLogEntry();

            this.writer.Write(entry);

            EventLog events = new EventLog()
            {
                Log    = "Application",
                Source = "Enterprise Library Logging"
            };

            foreach (EventLogEntry elogentry in events.Entries)
            {
                if (elogentry.Message.Contains("Message: Sample Message."))
                {
                    entrymade = true;
                    break;
                }
            }

            if (entrymade == false)
            {
                Assert.Fail("Eventlog message not logged");
            }
        }
コード例 #12
0
        void ILog.Write(LogLevel logLevel, string message)
        {
            var now      = _dateTimeProvider.Now;
            var logEntry = LogEntryFactory.Create(_name, now, message, logLevel);

            _logWriter.Write(logEntry);
        }
コード例 #13
0
        public void Create_CreateFactoryWithName_ReturnsEntryWithTitleSetToLoggerName()
        {
            var factory = new LogEntryFactory("Any name");

            var result = factory.Create(TraceEventType.Error, "Any message");

            Assert.AreEqual("Any name", result.Title);
        }
コード例 #14
0
        public void Create_SendInObject_ReturnsEntryWithCorrectMessage()
        {
            var factory = new LogEntryFactory("Any name");

            var result = factory.Create(TraceEventType.Error, 1);

            Assert.AreEqual("1", result.Message);
        }
コード例 #15
0
        public void Create_SendInSeverity_ReturnsEntryWithCorrectSeverity()
        {
            var factory = new LogEntryFactory("Any name");

            var result = factory.Create(TraceEventType.Error, "Any message");

            Assert.AreEqual(TraceEventType.Error, result.Severity);
        }
コード例 #16
0
 private void OnFindMatch(int skill, string shortCode)
 {
     _matchService.FindMatch(skill, shortCode, (err) => // on match making Error
     {
         OnLogEntryReceived(LogEntryFactory.CreateMatchMakingErrorLogEntry(err));
     });
     OnLogEntryReceived(LogEntryFactory.CreateMatchMakingRequestLogEntry(skill, shortCode));
 }
コード例 #17
0
 internal void Write(Log log, LogLevel logLevel, string message)
 {
     if (_multipeLog != null)
     {
         var logEntry = LogEntryFactory.Create(log.LoggedName, _dateTimeProvider.Now, message, logLevel);
         _multipeLog.Write(logEntry);
     }
 }
コード例 #18
0
        private void WriteOutResults(PingTestResults r)
        {
            var e = LogEntryFactory.CreateQosTestResultsLogEntry(r);

            foreach (var l in _pingTestResultsListeners)
            {
                l(e);
            }
        }
コード例 #19
0
        public void ShouldNotLogWhenDeniedCategory()
        {
            LogEntry entry = LogEntryFactory.GetLogEntry();

            entry.Categories.Clear();
            entry.Categories.Add("Denied");

            Assert.IsFalse(writer.ShouldLog(entry));
        }
コード例 #20
0
 internal void Write(Log log, LogLevel logLevel, string format, params object[] args)
 {
     if (_multipeLog != null)
     {
         var message  = string.Format(format, args);
         var logEntry = LogEntryFactory.Create(log.LoggedName, _dateTimeProvider.Now, message, logLevel);
         _multipeLog.Write(logEntry);
     }
 }
コード例 #21
0
 /**
  * <summary>Leave the Real Time Session</summary>
  */
 public void LeaveSession()
 {
     if (!_rtConnected)
     {
         return;
     }
     _rtConnected = false;
     _gameSparksRtUnity.Disconnect();
     OnLogEntry(LogEntryFactory.CreateLeaveSessionLogEntry());
 }
コード例 #22
0
        /**
         * <summary>Send Unstructured Packet</summary>
         * <param name="opCode">OpCode to send the packet on</param>
         */
        public void SendUnstructuredDataPacket(int opCode)
        {
            if (!_rtConnected)
            {
                return;
            }
            var r = GetNextRequestId();

            SendPacket(opCode, _settings.Protocol, PacketDataFactory.GetUnstructuredData(r));
            OnLogEntry(LogEntryFactory.CreateBlankSentLogEntry(r, opCode));
        }
コード例 #23
0
        /**
         * <summary>Send Ping</summary>
         * <remark>This ping is intented to measure the latency and
         * round trip of the active clients in the real time session.
         * This is not a reflection of the client / server connection.</remark>
         */
        public void SendPing()
        {
            if (!_rtConnected)
            {
                return;
            }
            var r = GetNextRequestId();

            SendPacket((int)OpCode.Ping, _settings.Protocol, PacketDataFactory.GetTimestampPing(r));
            OnLogEntry(LogEntryFactory.CreatePingSentEntryLog(r, (int)OpCode.Ping));
        }
コード例 #24
0
        public void EntryIsWrittenWhenMinMSMQTraceListener()
        {
            LogWriterFactory factory = new LogWriterFactory((e) => this.ConfigurationSource.GetSection("loggingConfiguration57"));

            this.writer = factory.Create();
            Logger.SetLogWriter(this.writer);

            var entry = LogEntryFactory.GetLogEntry();

            this.writer.Write(entry);
        }
コード例 #25
0
        public void EntryIsWrittenWhenUnprocessedCategoryEventLog()
        {
            var entry = LogEntryFactory.GetLogEntry();

            LogWriterFactory factory = new LogWriterFactory((e) => this.ConfigurationSource.GetSection("loggingConfiguration92"));

            this.writer = factory.Create();
            Logger.SetLogWriter(this.writer);
            this.writer.Write(entry);

            Assert.IsTrue(this.CheckForEntryInEventlog("Message: Sample Message."));
        }
コード例 #26
0
        public void EntryIsWrittenWhenSpecialCategoriesCriticalEventLogMax()
        {
            LogWriterFactory factory = new LogWriterFactory((e) => this.ConfigurationSource.GetSection("loggingConfiguration76"));

            this.writer = factory.Create();
            Logger.SetLogWriter(this.writer);
            var entry = LogEntryFactory.GetLogEntry();

            this.writer.Write(entry);

            Assert.IsTrue(this.CheckForEntryInEventlog("Message: Sample Message."));
        }
コード例 #27
0
        public void CustomFormatterIsInvoked()
        {
            var listener =
                this.writer.TraceSources.Values.SelectMany(x => x.Listeners).OfType <MyCustomTraceListener>().Single();

            var customFormatter = listener.Formatter as CustomFormatter;

            Assert.IsFalse(customFormatter.FormattedInvoked);

            this.writer.Write(LogEntryFactory.GetLogEntry());

            Assert.IsTrue(customFormatter.FormattedInvoked);
        }
コード例 #28
0
 private void InitializeMatchServiceSubscriptions()
 {
     _matchService.SubscribeToOnMatchNotFound(() =>
     {
         OnLogEntryReceived(LogEntryFactory.CreateMatchNotFoundLogEntry());
     });
     _matchService.SubscribeToOnMatchFound(rtSession =>
     {
         _sessionListDict.Add(rtSession.MatchId, rtSession);
         _sessionGui.MatchMakingGui.AddRealTimeSessionKey(rtSession.MatchId);
         OnLogEntryReceived(LogEntryFactory.CreateMatchFoundLogEntry(rtSession));
     });
 }
コード例 #29
0
        public void EntryIsWrittenWhenMinXMLTraceListener()
        {
            this.LoadConfig("loggingConfiguration50");

            var entry = LogEntryFactory.GetLogEntry();

            this.writer.Write(entry);

            FileInfo info = new FileInfo(XmlFilePath);

            Assert.IsTrue(info.Exists);
            Assert.IsTrue(info.Length > 0);
        }
コード例 #30
0
        public void ShouldOnlyLogWhenAllowedCategoryInCategories()
        {
            LogEntry entry = LogEntryFactory.GetLogEntry();

            entry.Categories.Clear();
            entry.Categories.Add("RFFBehavIncrTimeStampEmpty");

            Assert.IsFalse(Logger.ShouldLog(entry));

            entry.Categories.Add("General");

            Assert.IsTrue(Logger.ShouldLog(entry));
        }