/// <summary> /// Constructs <see cref="Switch"/> instances for the current /// `system.diagnostics/switches` configuration. /// </summary> /// <param name="configurationSection"></param> /// <returns></returns> private static IDictionary <string, Switch> InstantiateSwitches( SystemDiagnosticsConfigurationSection configurationSection) { var switches = new Dictionary <string, Switch>(StringComparer.OrdinalIgnoreCase); if (configurationSection.Switches != null) { foreach (SwitchElement switchElement in configurationSection.Switches) { // multiple rules dictate switch type var @switch = default(Switch); if (bool.TryParse(switchElement.Value, out bool boolValue)) { // if value is a `bool`, use `BooleanSwitch` @switch = new BooleanSwitch(switchElement.Name, "", switchElement.Value); } else if (Enum.TryParse(switchElement.Value, out TraceLevel traceLevel)) { // if value is a `TraceLevel`, use `TraceSwitch` @switch = new TraceSwitch(switchElement.Name, "", switchElement.Value); } else { throw new Exception( $"Unsupported Value '{switchElement.Value}' for Switch '{switchElement.Name}'."); } switches.Add(switchElement.Name, @switch); } } return(switches); }
static WorkflowTrace() { runtime.Switch = new SourceSwitch("System.Workflow.Runtime", SourceLevels.Off.ToString()); tracking = new TraceSource("System.Workflow.Runtime.Tracking"); tracking.Switch = new SourceSwitch("System.Workflow.Runtime.Tracking", SourceLevels.Off.ToString()); host = new TraceSource("System.Workflow.Runtime.Hosting"); host.Switch = new SourceSwitch("System.Workflow.Runtime.Hosting", SourceLevels.Off.ToString()); BooleanSwitch switch2 = new BooleanSwitch("System.Workflow LogToFile", "Log traces to file"); if (switch2.Enabled) { TextWriterTraceListener listener = new TextWriterTraceListener("WorkflowTrace.log"); Trace.Listeners.Add(listener); runtime.Listeners.Add(listener); host.Listeners.Add(listener); } BooleanSwitch switch3 = new BooleanSwitch("System.Workflow LogToTraceListeners", "Trace to listeners in Trace.Listeners", "0"); if (switch3.Enabled) { foreach (TraceListener listener2 in Trace.Listeners) { if (!(listener2 is DefaultTraceListener)) { runtime.Listeners.Add(listener2); tracking.Listeners.Add(listener2); host.Listeners.Add(listener2); } } } }
public DocumentsTrace(string switchName) { #if DEBUG string name = SafeSecurityHelper.GetAssemblyPartialName(Assembly.GetCallingAssembly()); _switch = new BooleanSwitch(switchName, "[" + name + "]"); #endif }
public void Constructor1() { var swtch = new BooleanSwitch(Name, ""); Assert.False(swtch.Enabled); // assert that a null name doesn't throw. swtch = new BooleanSwitch(null, null); }
protected override void Initialize(RequestContext requestContext) { base.Initialize(requestContext); BypassMobileId = ConfigurationManager.AppSettings["BypassMobileId"] == "1"; _MIDLogSwitch = new BooleanSwitch("MIDLog", "MID Prozess loggen"); if (_MIDLogSwitch.Enabled) { var today = DateTime.Now; _MIDLogOpId = 10000000000 * today.Year + 100000000 * today.Month + 1000000 * today.Day + 10000 * today.Hour + 100 * today.Minute + today.Second; _MIDLogSeqId = 0; } var certDir = Server.MapPath("~/Certificates"); try { _TokenSigningCertificate2 = new X509Certificate2( Path.Combine(certDir, ConfigurationManager.AppSettings["TokenSigningCertificate"]), ConfigurationManager.AppSettings["TokenSigningCertificatePassword"]); } catch (Exception ex) { } }
public override void OnApplyTemplate() { if (_carsPanel != null) { _carsPanel.MouseEnter -= CarsPanel_MouseEnter; } if (_carsPanel != null) { _sessionsPanel.MouseEnter -= SessionsPanel_MouseEnter; } if (_trackNameText != null) { _trackNameText.MouseEnter -= TrackNameText_MouseEnter; } if (_clientsText != null) { _clientsText.MouseEnter -= ClientsText_MouseEnter; } base.OnApplyTemplate(); _passwordIcon = (FrameworkElement)GetTemplateChild(@"PasswordIcon"); _bookedIcon = (FrameworkElement)GetTemplateChild(@"BookedForPlayerIcon"); _friendsIcon = (FrameworkElement)GetTemplateChild(@"FriendsIcon"); _hasErrorsGroup = (BooleanSwitch)GetTemplateChild(@"HasErrorsGroup"); _errorMessageGroup = (BbCodeBlock)GetTemplateChild(@"ErrorMessageGroup"); _pingText = (TextBlock)GetTemplateChild(@"PingText"); _clientsText = (TextBlock)GetTemplateChild(@"DisplayClientsText"); _timeLeftText = (TextBlock)GetTemplateChild(@"TimeLeftText"); _countryFlagImage = (Image)GetTemplateChild(@"CountryFlagImage"); _nameText = (TextBlock)GetTemplateChild(@"DisplayNameText"); _trackNameText = (TextBlock)GetTemplateChild(@"TrackNameText"); _countryName = (TextBlock)GetTemplateChild(@"CountryName"); _sessionsPanel = (Panel)GetTemplateChild(@"SessionsPanel"); _carsPanel = (Panel)GetTemplateChild(@"CarsPanel"); Update(Server); if (_carsPanel != null) { _carsPanel.MouseEnter += CarsPanel_MouseEnter; } if (_sessionsPanel != null) { _sessionsPanel.MouseEnter += SessionsPanel_MouseEnter; } if (_trackNameText != null) { _trackNameText.MouseEnter += TrackNameText_MouseEnter; } if (_clientsText != null) { _clientsText.MouseEnter += ClientsText_MouseEnter; } }
public static void Write(BooleanSwitch bs, string msg) { #if TRACE Trace.WriteLine(bs.DisplayName + ": " + Thread.CurrentThread.Name + ": " + msg); #elif BRUNET_NUNIT System.Console.WriteLine(msg); #endif }
public void Constructor1() { var swtch = new BooleanSwitch(Name, ""); Assert.False(swtch.Enabled); // assert that a null name doesn't throw. swtch = new BooleanSwitch(null, null); }
public void Enabled() { var swtch = new BooleanSwitch(Name, ""); swtch.Enabled = true; Assert.True(swtch.Enabled); swtch.Enabled = false; Assert.False(swtch.Enabled); }
public void Enabled() { var swtch = new BooleanSwitch(Name, ""); swtch.Enabled = true; Assert.True(swtch.Enabled); swtch.Enabled = false; Assert.False(swtch.Enabled); }
public void Constructor2() { var swtch = new BooleanSwitch(Name, "", "True"); Assert.True(swtch.Enabled); swtch = new BooleanSwitch(Name, "", "false"); Assert.False(swtch.Enabled); swtch = new BooleanSwitch(Name, "", "BAD_VALUE"); Assert.Throws<FormatException>(() => swtch.Enabled); }
public void SutIsSpecimenBuilder() { // Arrange // Act var sut = new BooleanSwitch(); // Assert Assert.IsAssignableFrom <ISpecimenBuilder>(sut); }
static AppWatch() { Logger = LogManager.GetCurrentClassLogger(); UseEnvironmentSwitch = new BooleanSwitch("UseEnvironmentWatch", "AppWatch uses Environment.TickCount instead of own Stopwatch"); Watch = Stopwatch.StartNew(); Created = DateTime.UtcNow; Logger.Info($"App watch was created and started at(UTC): {Created}"); }
public void CreateAnonymousWillReturnTrueOnFirstCall() { // Arrange BooleanSwitch sut = new BooleanSwitch(); // Act bool result = sut.CreateAnonymous(); // Assert Assert.True(result, "CreateAnonymous called an uneven number of times"); }
public void SutIsSpecimenBuilder() { // Fixture setup // Exercise system var sut = new BooleanSwitch(); // Verify outcome Assert.IsAssignableFrom <ISpecimenBuilder>(sut); // Teardown }
public void CreateWithNullContainerDoesNotThrow() { // Arrange var sut = new BooleanSwitch(); // Act var dummyRequest = new object(); sut.Create(dummyRequest, null); // Assert (no exception indicates success) }
public void Constructor2() { var swtch = new BooleanSwitch(Name, "", "True"); Assert.True(swtch.Enabled); swtch = new BooleanSwitch(Name, "", "false"); Assert.False(swtch.Enabled); swtch = new BooleanSwitch(Name, "", "BAD_VALUE"); Assert.Throws <FormatException>(() => swtch.Enabled); }
public void CreateAnonymousWillReturnTrueOnFirstCall() { // Fixture setup BooleanSwitch sut = new BooleanSwitch(); // Exercise system bool result = sut.CreateAnonymous(); // Verify outcome Assert.True(result, "CreateAnonymous called an uneven number of times"); // Teardown }
public void CreateWithNullContainerDoesNotThrow() { // Fixture setup var sut = new BooleanSwitch(); // Exercise system var dummyRequest = new object(); sut.Create(dummyRequest, null); // Verify outcome (no exception indicates success) // Teardown }
public static void Log(string statement) { logSwitch = new BooleanSwitch(LOG_SWITCH, LOG_SWITCH); if (logSwitch.Enabled) { Trace.Flush(); var logStatement = string.Format("{0}{1}{2}{1}", DateTime.Now, Environment.NewLine, statement); Trace.WriteLine(logStatement); Trace.Close(); } }
public void CreateWithNullRequestWillReturnCorrectResult() { // Arrange var sut = new BooleanSwitch(); // Act var dummyContainer = new DelegatingSpecimenContext(); var result = sut.Create(null, dummyContainer); // Assert Assert.Equal(new NoSpecimen(), result); }
public void CreateWithNullRequestWillReturnCorrectResult() { // Fixture setup var sut = new BooleanSwitch(); // Exercise system var dummyContainer = new DelegatingSpecimenContext(); var result = sut.Create(null, dummyContainer); // Verify outcome Assert.Equal(new NoSpecimen(), result); // Teardown }
public static bool IsEnabled(string category) { bool enable; if (!enabled.TryGetValue(category, out enable)) { enable = new BooleanSwitch(category, string.Empty).Enabled; enabled.Add(category, enable); } return(enable); }
public void CreateAnonymousWillReturnFalseOnSecondCall() { // Arrange BooleanSwitch sut = new BooleanSwitch(); sut.CreateAnonymous(); // Act bool result = sut.CreateAnonymous(); // Assert Assert.False(result, "CreateAnonymous called an even number of times"); }
public void CreateWithBooleanRequestWillReturnCorrectResultOnFirstCall() { // Arrange var booleanRequest = typeof(bool); var sut = new BooleanSwitch(); // Act var dummyContainer = new DelegatingSpecimenContext(); var result = sut.Create(booleanRequest, dummyContainer); // Assert Assert.True((bool)result); }
/// <summary> /// TraceListenerを追加する /// </summary> /// <param name="Listener"></param> public static void AddLogListener(TraceListener Listener) { Initialize(); // If asked, we'll initialize with a process specific file name. BooleanSwitch tsUniqueLog = new BooleanSwitch("UniqueLog", "Generate separate log for each process instance"); if (tsUniqueLog.Enabled) { System.Diagnostics.Trace.Listeners.Add(Listener); System.Diagnostics.Trace.AutoFlush = true; } }
public void Create_A_Message_For_Switch_And_Positional_Differently() { // arrange var param = new BooleanSwitch(new Parser("a"), 'h', "help", o => { }); var pos = new Positional(new Parser("a"), (o, strings) => { }); var ex0 = new MissingRequiredParameterException(param, new object()); var ex1 = new MissingRequiredParameterException(pos, new object()); // act // assert ex0.Message.Should().NotBe(ex1.Message); }
static void Main0() { Trace.Listeners.RemoveAt(0); bs = new BooleanSwitch("DISwitch", "DataImport switch"); Trace.Listeners.Add(new TextWriterTraceListener( new FileStream(@"F:\D.log", FileMode.OpenOrCreate))); //Create a fileSystem Watcher object used to monitor //the specified directory FileSystemWatcher fsw = new FileSystemWatcher { //extension to monitor for Path = @"F:\temp", Filter = "*.xml", //No need to go into subdirs IncludeSubdirectories = false, }; //Add the handler to manage the raised event //when a new file is created fsw.Created += new FileSystemEventHandler(OnFileChanged); //Enable the object to raise the event fsw.EnableRaisingEvents = true; try { //Call the waitforchanged method in an infinite loop //When the event is raised the OnfileCreated will be contacted WaitForChangedResult res; while (true) { res = fsw.WaitForChanged(WatcherChangeTypes.Created); Trace.WriteLineIf(bs.Enabled, DateTime.Now + " - Found: " + res.Name + " file"); } } catch (Exception e) { Trace.WriteLineIf(bs.Enabled, DateTime.Now + " - An exception occured while waiting for file:"); Trace.Indent(); Trace.WriteLineIf(bs.Enabled, DateTime.Now + " - " + e.ToString()); Trace.Unindent(); } finally { fsw.EnableRaisingEvents = false; Trace.WriteLineIf(bs.Enabled, DateTime.Now + " - Directory monitoring stopped"); Trace.Close(); } }
public void CreateWithBooleanRequestWillReturnCorrectResultOnFirstCall() { // Fixture setup var booleanRequest = typeof(bool); var sut = new BooleanSwitch(); // Exercise system var dummyContainer = new DelegatingSpecimenContext(); var result = sut.Create(booleanRequest, dummyContainer); // Verify outcome Assert.True((bool)result); // Teardown }
public void CreateWithNonBooleanRequestWillReturnCorrectResult() { // Arrange var nonBooleanRequest = new object(); var sut = new BooleanSwitch(); // Act var dummyContainer = new DelegatingSpecimenContext(); var result = sut.Create(nonBooleanRequest, dummyContainer); // Assert var expectedResult = new NoSpecimen(); Assert.Equal(expectedResult, result); }
public void Return_EmptyString_If_Not_Required() { // arrange var param = new BooleanSwitch(new Parser("a"), 'b', "bee", o => { }) { IsRequired = false }; var vm = new ParameterViewModel(param, Theme.Default); // act // assert vm.RequiredText.Should().Be(""); }
public void CreateWillReturnFalseOnSecondCall() { // Fixture setup BooleanSwitch sut = new BooleanSwitch(); sut.Create(); // Exercise system bool result = sut.Create(); // Verify outcome Assert.False(result, "CreateAnonymous called an even number of times"); // Teardown }
public void Return_A_Check_Mark_If_Required() { // arrange var param = new BooleanSwitch(new Parser("a"), 'b', "bee", o => { }) { IsRequired = true }; var vm = new ParameterViewModel(param, Theme.Default); // act // assert vm.RequiredText.Should().Be("✓"); }
static int Test1 () { TraceSwitch testSwitch1 = new TraceSwitch ("testSwitch1", null); if (testSwitch1.Level != TraceLevel.Verbose) return 1; TraceSwitch testSwitch2 = new TraceSwitch ("testSwitch2", null); if (testSwitch2.Level != TraceLevel.Off) return 2; TraceSwitch testSwitch3 = new TraceSwitch ("testSwitch3", null); if (testSwitch3.Level != TraceLevel.Warning) return 3; TraceSwitch testSwitch4 = new TraceSwitch ("testSwitch4", null); if (testSwitch4.Level != TraceLevel.Info) return 4; TraceSwitch testSwitch5 = new TraceSwitch ("testSwitch5", null); if (testSwitch5.Level != TraceLevel.Verbose) return 5; TraceSwitch testSwitch6 = new TraceSwitch ("testSwitch6", null); if (testSwitch6.Level != TraceLevel.Off) return 6; #if NET_2_0 TraceSwitch testSwitch7 = new TraceSwitch ("testSwitch7", null); if (testSwitch7.Level != TraceLevel.Info) return 7; TraceSwitch testSwitch8 = new TraceSwitch ("testSwitch8", null); if (testSwitch8.Level != TraceLevel.Warning) return 8; #endif TraceSwitch testSwitch9 = new TraceSwitch ("testSwitch9", null); if (testSwitch9.Level != TraceLevel.Off) return 9; BooleanSwitch boolSwitch1 = new BooleanSwitch ("boolSwitch1", null); if (boolSwitch1.Enabled) return 10; BooleanSwitch boolSwitch2 = new BooleanSwitch ("boolSwitch2", null); if (!boolSwitch2.Enabled) return 11; BooleanSwitch boolSwitch3 = new BooleanSwitch ("boolSwitch3", null); if (!boolSwitch3.Enabled) return 12; BooleanSwitch boolSwitch4 = new BooleanSwitch ("boolSwitch4", null); if (boolSwitch4.Enabled) return 13; #if NET_2_0 BooleanSwitch boolSwitch5 = new BooleanSwitch ("boolSwitch5", null); if (!boolSwitch5.Enabled) return 14; BooleanSwitch boolSwitch6 = new BooleanSwitch ("boolSwitch6", null); if (boolSwitch6.Enabled) return 15; SourceSwitch sourceSwitch1 = new SourceSwitch ("sourceSwitch1"); if ((sourceSwitch1.Level & SourceLevels.Critical) == 0) return 16; SourceSwitch sourceSwitch2 = new SourceSwitch ("sourceSwitch2"); if ((sourceSwitch2.Level & SourceLevels.Warning) == 0) return 17; if ((sourceSwitch2.Level & SourceLevels.Error) == 0) return 18; SourceSwitch sourceSwitch3 = new SourceSwitch ("sourceSwitch3"); if (sourceSwitch3.Level != SourceLevels.Off) return 19; #endif return 0; }
static int Test6 () { BooleanSwitch boolSwitch1 = new BooleanSwitch ("boolSwitch1", null); #if NET_2_0 if (boolSwitch1.Enabled) return 1; BooleanSwitch boolSwitch8 = new BooleanSwitch ("boolSwitch8", null); try { Assert.Fail ("#1:" + boolSwitch8.Enabled); } catch (ConfigurationErrorsException ex) { // The config value for Switch 'boolSwitch8' was invalid Assert.AreEqual (typeof (ConfigurationErrorsException), ex.GetType (), "#2"); Assert.IsNotNull (ex.InnerException, "#3"); Assert.IsNotNull (ex.Message, "#4"); Assert.IsTrue (ex.Message.IndexOf ("'boolSwitch8'") != -1, "#5"); // Input string was not in a correct format FormatException fe = ex.InnerException as FormatException; Assert.IsNotNull (fe, "#6"); Assert.IsNotNull (fe.Message, "#7"); } #else try { Assert.Fail ("#1:" + boolSwitch1.Enabled); } catch (ConfigurationException ex) { // Error in trace switch 'boolSwitch8': The value of a // switch must be integral Assert.AreEqual (typeof (ConfigurationException), ex.GetType (), "#2"); Assert.IsNull (ex.InnerException, "#3"); Assert.IsNotNull (ex.Message, "#4"); Assert.IsTrue (ex.Message.IndexOf ("'boolSwitch8'") != -1, "#5"); } #endif return 0; }