Наследование: TextWriterTraceListener
Пример #1
0
 public static void AddDelimitedListTL()
 {
     //RemoveAllTraceListeners();
     Trace.AutoFlush = true;
     System.Diagnostics.DelimitedListTraceListener tListener = new System.Diagnostics.DelimitedListTraceListener("DLTrace.txt");
     System.Diagnostics.Trace.Listeners.Add(tListener);
 }
Пример #2
0
        public void Test02()
        {
            string msg1, msg2;
            string fileName = string.Format("{0}_4.txt", this.GetType().Name);
            CommonUtilities.DeleteFile(fileName);

            try
            {
                FileStream stream = new FileStream(fileName, FileMode.Create, FileAccess.Write);
                StreamWriter writer = new StreamWriter(stream);

                _delimitedListener = new DelimitedListTraceListener(writer);
                Assert.True(_delimitedListener.Delimiter == ";");
                Assert.True(_delimitedListener.Name == "");
                Assert.True(_delimitedListener.Writer == writer);

                msg1 = "Msg1";
                _delimitedListener.WriteLine(msg1);
                _delimitedListener.Delimiter = ",";
                msg2 = "Msg2";
                _delimitedListener.WriteLine(msg2);
                _delimitedListener.Flush();
                _delimitedListener.Dispose();

                Assert.True(_delimitedListener.Delimiter == ",");
                Assert.True(CommonUtilities.TestListenerContent(new Type[] { typeof(DelimitedListTraceListener) }, new string[] { fileName }, msg1));
                Assert.True(CommonUtilities.TestListenerContent(new Type[] { typeof(DelimitedListTraceListener) }, new string[] { fileName }, msg2));
            }
            finally
            {
                CommonUtilities.DeleteFile(fileName);
            }
        }
		public void TraceEvent1 ()
		{
			StringWriter sw = new StringWriter ();
			DelimitedListTraceListener x = new DelimitedListTraceListener (sw);
			x.TraceEvent (null, null, TraceEventType.Error, 4, null);
			x.Close ();
			Assert.AreEqual (sample2, sw.ToString ().Replace ("\r\n", "\n"));
		}
		public void WriteLine1 ()
		{
			StringWriter sw = new StringWriter ();
			DelimitedListTraceListener x = new DelimitedListTraceListener (sw);
			x.WriteLine ("sample");
			x.Close ();
			Assert.AreEqual (sample1, sw.ToString ().Replace ("\r\n", "\n"));
		}
		public void TraceEvent2 ()
		{
			StringWriter sw = new StringWriter ();
			DelimitedListTraceListener x = new DelimitedListTraceListener (sw);
			x.TraceEvent (null, "bulldog", TraceEventType.Error, 5);
			x.TraceEvent (null, "bulldog", TraceEventType.Error, 3, "test event arg:{0}", "arg1");
			x.Close ();
			Assert.AreEqual (sample3, sw.ToString ().Replace ("\r\n", "\n"));
		}
Пример #6
0
        protected override void ProcessRecord()
        {

            if (ParameterSetName == "On")
            {
                var existingListener = Trace.Listeners[LISTENERNAME];
                if (existingListener != null)
                {
                    existingListener.Flush();
                    existingListener.Close();
                    Trace.Listeners.Remove(existingListener);
                }

                if (!string.IsNullOrEmpty(LogFile))
                {
                    if (!System.IO.Path.IsPathRooted(LogFile))
                    {
                        LogFile = System.IO.Path.Combine(SessionState.Path.CurrentFileSystemLocation.Path, LogFile);
                    }
                    if (!string.IsNullOrEmpty(Delimiter))
                    {
                        DelimitedListTraceListener delimitedListener = new DelimitedListTraceListener(LogFile);
                        delimitedListener.Delimiter = Delimiter;
                        delimitedListener.TraceOutputOptions = TraceOptions.DateTime;
                        delimitedListener.Name = LISTENERNAME;
                        Trace.Listeners.Add(delimitedListener);
                        Core.Diagnostics.Log.LogLevel = Level;
                    }
                    else
                    {
                        TextWriterTraceListener listener = new TextWriterTraceListener(LogFile);
                        listener.Name = LISTENERNAME;
                        Trace.Listeners.Add(listener);
                        Core.Diagnostics.Log.LogLevel = Level;
                    }
                }
                else
                {
                    ConsoleTraceListener consoleListener = new ConsoleTraceListener(false);
                    consoleListener.Name = LISTENERNAME;
                    Trace.Listeners.Add(consoleListener);
                    Core.Diagnostics.Log.LogLevel = Level;
                }
                Trace.AutoFlush = AutoFlush;
                Trace.IndentSize = IndentSize;
            }
            else
            {
                try
                {
                    Trace.Flush();
                    Trace.Listeners[LISTENERNAME].Close();
                    Trace.Listeners.Remove(LISTENERNAME);
                }
                catch (Exception) { }
            }
        }
        public PerformanceTests()
        {
            if (_listener == null)
            {
                _listener = new DelimitedListTraceListener(@"PerformanceTests.csv");
            }

            Trace.Listeners.Clear();
            Trace.Listeners.Add(_listener);
            Trace.AutoFlush = true;
        }
Пример #8
0
        private static void Main(string[] args)
        {
            //Set managers
            ManagerBase2.SetTraceLog(generaltracelog);

            //GET THE ASSEMBLY'S DIRECTORY
            string file  = System.Reflection.Assembly.GetExecutingAssembly().Location;
            string fname = Path.GetFileNameWithoutExtension(file);

            //TRACELOG
            Trace.AutoFlush  = true;
            Trace.IndentSize = 4;
            if (System.Diagnostics.Trace.Listeners.Count <= 1 && (System.Diagnostics.Trace.Listeners["Default"] == null ||
                                                                  System.Diagnostics.Trace.Listeners["Default"].GetType() == typeof(System.Diagnostics.DefaultTraceListener)))
            {
                DelimitedListTraceListener del = new System.Diagnostics.DelimitedListTraceListener((fname + ".log.csv"), "text");
                del.Delimiter = ",";
                System.Diagnostics.Trace.Listeners.Add(del);
            }

            Trace.WriteLine("#############################################################################");
            Trace.WriteLine(string.Format("Saga Authtentication Server starting on: {0}", DateTime.Now));
            Trace.WriteLine(string.Format("OS Information: {0}", Environment.OSVersion));
            Trace.WriteLine(string.Format("Number of Processors: {0}", Environment.ProcessorCount));
            Trace.WriteLine(string.Format("CLR Version: {0}", Environment.Version));
            Trace.WriteLine(string.Format("Working set: {0}", Environment.WorkingSet));
            Trace.WriteLine(string.Format("OS Bit Version: {0} Bit", IntPtr.Size * 8));
            Trace.WriteLine("#############################################################################");

            AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);

            FirstRunConfiguration();
            HostContext.Current.Initialize();
            HostContext.Current.BeforeQuerySettings();
            HostContext.Current.AfterQuerySettings();
            HostContext.Current.Load();
            HostContext.Current.Loaded();
        }
		public void Fail1 ()
		{
			StringWriter sw = new StringWriter ();
			DelimitedListTraceListener x = new DelimitedListTraceListener (sw);
			TraceEventCache cc = new TraceEventCache ();
			x.Fail ("error summary", "error details");
			x.Close ();
			Assert.AreEqual (sample7, sw.ToString ().Replace ("\r\n", "\n"));
		}
		public void TraceTransfer1 ()
		{
			StringWriter sw = new StringWriter ();
			DelimitedListTraceListener x = new DelimitedListTraceListener (sw);
			x.TraceTransfer (null, "my name is \"tricky\"", 0, "hoge;hoge", Guid.Empty);
			x.Close ();
			Assert.AreEqual (sample6, sw.ToString ().Replace ("\r\n", "\n"));
		}
		public void TraceDataWithCache2 ()
		{
			StringWriter sw = new StringWriter ();
			DelimitedListTraceListener x = new DelimitedListTraceListener (sw);
			TraceEventCache cc = new TraceEventCache ();
			x.TraceData (cc, null, TraceEventType.Error, 7, "XYZ");
			x.TraceData (cc, null, TraceEventType.Error, 7, "ABC", "DEF", 123);
			x.Close ();
			Assert.AreEqual (sample5, sw.ToString ().Replace ("\r\n", "\n"));
		}
Пример #12
0
        private static void Main(string[] args)
        {
            //Set managers
            ManagerBase2.SetTraceLog(generaltracelog);
            CoreService.SetTraceLog(generaltracelog);

            //GET THE ASSEMBLY'S DIRECTORY
            string file  = System.Reflection.Assembly.GetExecutingAssembly().Location;
            string fname = Path.GetFileNameWithoutExtension(file);

            //TRACELOG
            Trace.AutoFlush  = true;
            Trace.IndentSize = 4;
            if (System.Diagnostics.Trace.Listeners.Count <= 1 && (System.Diagnostics.Trace.Listeners["Default"] == null ||
                                                                  System.Diagnostics.Trace.Listeners["Default"].GetType() == typeof(System.Diagnostics.DefaultTraceListener)))
            {
                DelimitedListTraceListener del = new System.Diagnostics.DelimitedListTraceListener((fname + ".log.csv"), "text");
                del.Delimiter = ",";
                System.Diagnostics.Trace.Listeners.Add(del);
            }

            Trace.WriteLine("#############################################################################");
            Trace.WriteLine(string.Format("Saga Map Server starting on: {0}", DateTime.Now));
            Trace.WriteLine(string.Format("OS Information: {0}", Environment.OSVersion));
            Trace.WriteLine(string.Format("Number of Processors: {0}", Environment.ProcessorCount));
            Trace.WriteLine(string.Format("CLR Version: {0}", Environment.Version));
            Trace.WriteLine(string.Format("Working set: {0}", Environment.WorkingSet));
            Trace.WriteLine(string.Format("OS Bit Version: {0} Bit", IntPtr.Size * 8));
            Trace.WriteLine("#############################################################################");

            AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);

            //Do initial configuration
            FirstRunConfiguration();

            _ConsoleCommands               = ManagerBase2.ProvideManager <ConsoleCommands>("Saga.Manager.ConsoleSettings");
            _NetworkService                = ManagerBase2.ProvideManager <NetworkService>("Saga.Manager.NetworkSettings");
            _WorldTasks                    = ManagerBase2.ProvideManager <WorldTasks>("Saga.Manager.WorldTasks");
            _Database                      = ManagerBase2.ProvideManager <Database>("Saga.Manager.Database");
            _Quests                        = ManagerBase2.ProvideManager <Saga.Managers.Quests>("Saga.Manager.Quest");
            _ScriptCompiler                = ManagerBase2.ProvideManager <ScriptCompiler>("Saga.Manager.Scripting");
            _EventManager                  = FactoryBase.ProvideManager <EventManager>("Saga.Factory.Events");
            _Additions                     = FactoryBase.ProvideManager <Additions>("Saga.Factory.Addition");
            _Portals                       = FactoryBase.ProvideManager <Portals>("Saga.Factory.Portals");
            _Spells                        = FactoryBase.ProvideManager <Saga.Factory.Spells>("Saga.Factory.Spells");
            _StatusByLevel                 = FactoryBase.ProvideManager <Saga.Factory.StatusByLevel>("Saga.Factory.StatusByLevel");
            _Warps                         = FactoryBase.ProvideManager <Warps>("Saga.Factory.Warps");
            _Zones                         = FactoryBase.ProvideManager <Zones>("Saga.Factory.Zones");
            _ItemFactory                   = FactoryBase.ProvideManager <ItemsFactory>("Saga.Factory.Items");
            _Weaponary                     = FactoryBase.ProvideManager <Weaponary>("Saga.Factory.Weaponary");
            _SpawnTemplates                = FactoryBase.ProvideManager <SpawnTemplate>("Saga.Factory.SpawnTemplate");
            _SpawnWorldObjects             = FactoryBase.ProvideManager <SpawnWorldObjects>("Saga.Factory.SpawnWorldObjects");
            _SpawnMultiWorldObjectSettings = FactoryBase.ProvideManager <SpawnMultiWorldObjects>("Saga.Factory.SpawnMultiWorldObjects");
            _CharacterConfiguration        = FactoryBase.ProvideManager <CharacterConfiguration>("Saga.Factory.CharacterConfiguration");
            _ItemDrops                     = FactoryBase.ProvideManager <ItemsDrops>("Saga.Factory.ItemDrops");

            try
            {
                ManagerCollection section = (ManagerCollection)ConfigurationManager.GetSection("Saga.Managers");
                if (section != null)
                {
                    foreach (SingletonManagerElement element in section)
                    {
                        ManagerBase2 managerBase = ManagerBase2.ProvideManagerFromTypeString <ManagerBase2>(element.Type);
                        _CustomManagers.Add(element.Name, managerBase);
                    }
                }
            }
            catch (Exception e)
            {
                HostContext.Current.AddUnhandeldException(e);
            }
            finally
            {
                HostContext.Current.Initialize();
                HostContext.Current.BeforeQuerySettings();
                HostContext.Current.AfterQuerySettings();
                HostContext.Current.Load();
                HostContext.Current.Loaded();
            }

            Console.ReadLine();
        }
Пример #13
0
        private static void Main(string[] args)
        {
            reader             = new ConsoleReader();
            reader.Title       = "Gateway server, type help for commands";
            reader.Initialize += new EventHandler(reader_Initialize);
            reader.Register(new ConsoleCommandHandler(Version));
            reader.Register(new ConsoleCommandHandler(CrcValidationCheck));
            reader.Register(new ConsoleCommandHandler(CheckHost));
            reader.Register(new ConsoleCommandHandler(Shutdown));
            reader.Clear(null);

            AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);

            //SagaConfigurationManager.read();
            string file  = System.Reflection.Assembly.GetExecutingAssembly().Location;
            string fname = Path.GetFileNameWithoutExtension(file);

            //TRACELOG
            Trace.AutoFlush  = true;
            Trace.IndentSize = 4;
            if (System.Diagnostics.Trace.Listeners.Count <= 1 && (System.Diagnostics.Trace.Listeners["Default"] == null ||
                                                                  System.Diagnostics.Trace.Listeners["Default"].GetType() == typeof(System.Diagnostics.DefaultTraceListener)))
            {
                DelimitedListTraceListener del = new System.Diagnostics.DelimitedListTraceListener((fname + ".log.csv"), "text");
                del.Delimiter = ",";
                System.Diagnostics.Trace.Listeners.Add(del);
            }

            Trace.WriteLine("#############################################################################");
            Trace.WriteLine(string.Format("Saga Gateway Server starting on: {0}", DateTime.Now));
            Trace.WriteLine(string.Format("OS Information: {0}", Environment.OSVersion));
            Trace.WriteLine(string.Format("Number of Processors: {0}", Environment.ProcessorCount));
            Trace.WriteLine(string.Format("CLR Version: {0}", Environment.Version));
            Trace.WriteLine(string.Format("Working set: {0}", Environment.WorkingSet));
            Trace.WriteLine(string.Format("OS Bit Version: {0} Bit", IntPtr.Size * 8));
            Trace.WriteLine("#############################################################################");

            System.Configuration.Configuration b =
                ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);

            if (CheckConfigExists() == false)
            {
                Console.WriteLine("First time run-configuration");
                char key;

ConfigureGatewayNetwork:
                Console.WriteLine("Do you wan to configure the gateway-network settings? Y/N");
                key = Console.ReadKey(true).KeyChar;
                if (key == 'y')
                {
                    Console.WriteLine("What ip should the gateway server listen to?");
                    while (!IPAddress.TryParse(Console.ReadLine(), out gatewayip))
                    {
                        Console.WriteLine("Incorrect value please use an ipv4 adress, recommended 0.0.0.0");
                    }

                    Console.WriteLine("What port should the gateway server listen to?");
                    while (!int.TryParse(Console.ReadLine(), out gatewayport))
                    {
                        Console.WriteLine("Incorrect value please use an number between 1024–49151, recommended 64000");
                    }
                }
                else if (key != 'n')
                {
                    goto ConfigureGatewayNetwork;
                }

ConfigureAuthenticationNetwork:
                Console.WriteLine("Do you wan to configure the authentication-network settings? Y/N");
                key = Console.ReadKey(true).KeyChar;
                if (key == 'y')
                {
                    Console.WriteLine("What is the ip of the authentication server");
                    while (!IPAddress.TryParse(Console.ReadLine(), out authenticationip))
                    {
                        Console.WriteLine("Incorrect value please use an ipv4 adress, recommended 0.0.0.0");
                    }

                    Console.WriteLine("On what port is the authentication server listening");
                    while (!int.TryParse(Console.ReadLine(), out authenticationport))
                    {
                        Console.WriteLine("Incorrect value please use an number between 1024–49151, recommended 64000");
                    }
                }
                else if (key != 'n')
                {
                    goto ConfigureAuthenticationNetwork;
                }

ConfigureGUID:
                Console.WriteLine("Do you wan to configure the gateway-guid settings? Y/N");
                key = Console.ReadKey(true).KeyChar;
                if (key == 'y')
                {
                    Console.WriteLine("What is the crc key");
                    byte[] ncrckey;
                    while (!Conversions.TryParse(Console.ReadLine(), out ncrckey) || crckey.Length != 20)
                    {
                        Console.WriteLine("Crc key key must be 20 hex digit string, recommended: A928CDC9DBE8751B3BC99EB65AE07E0C849CE739");
                    }

                    Console.WriteLine("What is the guid key");
                    byte[] nguidkey;
                    while (!Conversions.TryParse(Console.ReadLine(), out nguidkey) || guidkey.Length != 20)
                    {
                        Console.WriteLine("Guid key key must be 20 hex digit string, recommended: ED90AA25AE906FB36308C8523A4737A7E7B1FC6F");
                    }

                    crckey  = Conversions.ByteToHexString(ncrckey);
                    guidkey = Conversions.ByteToHexString(nguidkey);
                }
                else if (key != 'n')
                {
                    goto ConfigureGUID;
                }

                NetworkSettings       networkSettings = new NetworkSettings();
                NetworkFileCollection collection      = networkSettings.Connections;
                collection["public"]    = new NetworkElement("public", gatewayip.ToString(), gatewayport);
                collection["internal"]  = new NetworkElement("internal", authenticationip.ToString(), authenticationport);
                networkSettings.Crckey  = crckey;
                networkSettings.Guidkey = guidkey;
                b.Sections.Remove("Saga.NetworkSettings");
                b.Sections.Add("Saga.NetworkSettings", networkSettings);
                b.Save();
                ConfigurationManager.RefreshSection("Saga.NetworkSettings");

                Console.WriteLine("Everything configured");
            }
            else
            {
                Console.WriteLine("Configuration file exists");
            }

            // Try to establish connection to authentication-server [Daniel4rt]
            LoginClient client;

            for (int i = 0; i < 3; i++)
            {
                if (NetworkManager.TryGetLoginClient(out client))
                {
                    client.ExchangeIpAdress(IPAddress.Loopback);
                    break;
                }
                else
                {
                    Console.WriteLine("Test connection failed retrying in 3 seconds");
                    Thread.Sleep(3000);
                }
            }
            if (NetworkManager.TryGetLoginClient(out client))
            {
                Console.WriteLine("Connection to authentication-server created");
            }
            else
            {
                Console.WriteLine("Can't connect to authentication, try again manually with the command 'host -connect'");
            }

            reader.Start();
        }
        static async Task Proc()
        {
            using (var logStrm = new System.IO.StreamWriter(@".\trace.log", false)
            {
                AutoFlush = true
            })
                using (var loggerA = new System.Diagnostics.DelimitedListTraceListener(logStrm))
                    using (var loggerB = new System.Diagnostics.ConsoleTraceListener())
                    {
                        System.Diagnostics.Trace.Listeners.Add(loggerA);
                        System.Diagnostics.Trace.Listeners.Add(loggerB);

                        Trace.WriteLine("------------------------------");
                        Trace.WriteLine(" Environment");
                        Trace.WriteLine("------------------------------");
                        Trace.WriteLine(string.Format("Environment.OSVersion: {0}", Environment.OSVersion));
                        Trace.WriteLine(string.Format("Environment.Is64BitOperatingSystem: {0}", Environment.Is64BitOperatingSystem));
                        Trace.WriteLine(string.Format("Environment.Is64BitProcess: {0}", Environment.Is64BitProcess));
                        Console.WriteLine();

                        Trace.WriteLine("------------------------------");
                        Trace.WriteLine(" Tests: IE");
                        Trace.WriteLine("------------------------------");

                        var targetUrl = new Uri("http://nicovideo.jp");
                        var valueKey  = null as string;

                        try
                        {
                            //Win32Api.IEGetProtectedModeCookie
                            string lpszCookieData;
                            var    hResult = Win32Api.GetCookiesFromProtectedModeIE(out lpszCookieData, targetUrl, valueKey);
                            Trace.WriteLine(lpszCookieData != null
                        ? string.Format("Win32Api.GetCookieFromProtectedModeIE success: 0x{0}", hResult.ToString("x8"))
                        : string.Format("Win32Api.GetCookieFromProtectedModeIE error: 0x{0}", hResult.ToString("x8")));
                        }
                        catch (Exception e) { Trace.WriteLine(e); }
                        finally { Trace.WriteLine(string.Empty); }
                        try
                        {
                            //Win32Api.IEGetProtectedModeCookie (No Flags)
                            string lpszCookieData;
                            var    hResult = Win32Api.GetCookiesFromProtectedModeIE(out lpszCookieData, targetUrl, valueKey, 0);
                            Trace.WriteLine(lpszCookieData != null
                        ? string.Format("Win32Api.GetCookieFromProtectedModeIE(no flags) success: 0x{0}", hResult.ToString("x8"))
                        : string.Format("Win32Api.GetCookieFromProtectedModeIE(no flags) error: 0x{0}", hResult.ToString("x8")));
                        }
                        catch (Exception e) { Trace.WriteLine(e); }
                        finally { Trace.WriteLine(string.Empty); }
                        try
                        {
                            //IEPMCookieImporter.InternalGetCookiesWinApiOnProxy
                            if (Environment.OSVersion.Platform == PlatformID.Win32NT)
                            {
                                var cookieHeader = IEPMCookieImporter.InternalGetCookiesWinApiOnProxy(targetUrl, valueKey);
                                Trace.WriteLine(cookieHeader != null
                            ? string.Format("IEPMCookieImporter.InternalGetCookiesWinApiOnProxy success")
                            : string.Format("IEPMCookieImporter.InternalGetCookiesWinApiOnProxy error"));
                            }
                        }
                        catch (Exception e) { Trace.WriteLine(e); }
                        finally { Trace.WriteLine(string.Empty); }
                        try
                        {
                            //IEEPMCookieImporter
                            if (Environment.OSVersion.Platform == PlatformID.Win32NT)
                            {
                                var importer = new IEImporterFactory().GetIEEPMCookieImporter();
                                var res      = await importer.GetCookiesAsync(targetUrl);

                                Trace.WriteLine(res.Status == CookieImportState.Success && res.Cookies.Count > 0
                            ? string.Format("IEEPMCookieImporter success")
                            : string.Format("IEEPMCookieImporter error"));
                            }
                        }
                        catch (Exception e) { Trace.WriteLine(e); }
                        finally { Trace.WriteLine(string.Empty); }
                        Console.WriteLine();

                        Trace.WriteLine("------------------------------");
                        Trace.WriteLine(" Tests: CookieGetters");
                        Trace.WriteLine("------------------------------");
                        try
                        {
                            var getters = await CookieGetters.Default.GetInstancesAsync(false);

                            Trace.WriteLine(string.Format("Browser.Length: {0}", getters.Length));
                            for (var i = 0; i < getters.Length; i++)
                            {
                                try
                                {
                                    Trace.WriteLine(string.Format("{0:00}: {1}", i, getters[i].SourceInfo.BrowserName));
                                    Trace.Indent();
                                    var res = await getters[i].GetCookiesAsync(targetUrl);
                                    Trace.WriteLine(string.Format("Status: {0}", res.Status));
                                    Trace.WriteLine(string.Format("Cookies.Count: {0}",
                                                                  res.Status == CookieImportState.Success ? res.Cookies.Count.ToString() : "None"));
                                    Trace.Unindent();
                                }
                                catch (Exception e) { Trace.WriteLine(e); }
                            }
                        }
                        catch (Exception e) { Trace.WriteLine(e); }
                    }
        }
Пример #15
0
        private static void Main(string[] args)
        {
            //Set managers
            ManagerBase2.SetTraceLog(generaltracelog);

            //GET THE ASSEMBLY'S DIRECTORY
            string file = System.Reflection.Assembly.GetExecutingAssembly().Location;
            string fname = Path.GetFileNameWithoutExtension(file);

            //TRACELOG
            Trace.AutoFlush = true;
            Trace.IndentSize = 4;
            if (System.Diagnostics.Trace.Listeners.Count <= 1 && (System.Diagnostics.Trace.Listeners["Default"] == null ||
                System.Diagnostics.Trace.Listeners["Default"].GetType() == typeof(System.Diagnostics.DefaultTraceListener)))
            {
                DelimitedListTraceListener del = new System.Diagnostics.DelimitedListTraceListener((fname + ".log.csv"), "text");
                del.Delimiter = ",";
                System.Diagnostics.Trace.Listeners.Add(del);
            }

            Trace.WriteLine("#############################################################################");
            Trace.WriteLine(string.Format("Saga Authtentication Server starting on: {0}", DateTime.Now));
            Trace.WriteLine(string.Format("OS Information: {0}", Environment.OSVersion));
            Trace.WriteLine(string.Format("Number of Processors: {0}", Environment.ProcessorCount));
            Trace.WriteLine(string.Format("CLR Version: {0}", Environment.Version));
            Trace.WriteLine(string.Format("Working set: {0}", Environment.WorkingSet));
            Trace.WriteLine(string.Format("OS Bit Version: {0} Bit", IntPtr.Size * 8));
            Trace.WriteLine("#############################################################################");

            AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);

            FirstRunConfiguration();
            HostContext.Current.Initialize();
            HostContext.Current.BeforeQuerySettings();
            HostContext.Current.AfterQuerySettings();
            HostContext.Current.Load();
            HostContext.Current.Loaded();
        }
Пример #16
0
        private static void Main(string[] args)
        {
            reader = new ConsoleReader();
            reader.Title = "Gateway server, type help for commands";
            reader.Initialize += new EventHandler(reader_Initialize);
            reader.Register(new ConsoleCommandHandler(Version));
            reader.Register(new ConsoleCommandHandler(CrcValidationCheck));
            reader.Register(new ConsoleCommandHandler(CheckHost));
            reader.Register(new ConsoleCommandHandler(Shutdown));
            reader.Clear(null);

            AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);

            //SagaConfigurationManager.read();
            string file = System.Reflection.Assembly.GetExecutingAssembly().Location;
            string fname = Path.GetFileNameWithoutExtension(file);

            //TRACELOG
            Trace.AutoFlush = true;
            Trace.IndentSize = 4;
            if (System.Diagnostics.Trace.Listeners.Count <= 1 && (System.Diagnostics.Trace.Listeners["Default"] == null ||
                System.Diagnostics.Trace.Listeners["Default"].GetType() == typeof(System.Diagnostics.DefaultTraceListener)))
            {
                DelimitedListTraceListener del = new System.Diagnostics.DelimitedListTraceListener((fname + ".log.csv"), "text");
                del.Delimiter = ",";
                System.Diagnostics.Trace.Listeners.Add(del);
            }

            Trace.WriteLine("#############################################################################");
            Trace.WriteLine(string.Format("Saga Gateway Server starting on: {0}", DateTime.Now));
            Trace.WriteLine(string.Format("OS Information: {0}", Environment.OSVersion));
            Trace.WriteLine(string.Format("Number of Processors: {0}", Environment.ProcessorCount));
            Trace.WriteLine(string.Format("CLR Version: {0}", Environment.Version));
            Trace.WriteLine(string.Format("Working set: {0}", Environment.WorkingSet));
            Trace.WriteLine(string.Format("OS Bit Version: {0} Bit", IntPtr.Size * 8));
            Trace.WriteLine("#############################################################################");

            System.Configuration.Configuration b =
                ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);

            if (CheckConfigExists() == false)
            {
                Console.WriteLine("First time run-configuration");
                char key;

            ConfigureGatewayNetwork:
                Console.WriteLine("Do you wan to configure the gateway-network settings? Y/N");
                key = Console.ReadKey(true).KeyChar;
                if (key == 'y')
                {
                    Console.WriteLine("What ip should the gateway server listen to?");
                    while (!IPAddress.TryParse(Console.ReadLine(), out gatewayip))
                    {
                        Console.WriteLine("Incorrect value please use an ipv4 adress, recommended 0.0.0.0");
                    }

                    Console.WriteLine("What port should the gateway server listen to?");
                    while (!int.TryParse(Console.ReadLine(), out gatewayport))
                    {
                        Console.WriteLine("Incorrect value please use an number between 1024–49151, recommended 64000");
                    }
                }
                else if (key != 'n') goto ConfigureGatewayNetwork;

            ConfigureAuthenticationNetwork:
                Console.WriteLine("Do you wan to configure the authentication-network settings? Y/N");
                key = Console.ReadKey(true).KeyChar;
                if (key == 'y')
                {
                    Console.WriteLine("What is the ip of the authentication server");
                    while (!IPAddress.TryParse(Console.ReadLine(), out authenticationip))
                    {
                        Console.WriteLine("Incorrect value please use an ipv4 adress, recommended 0.0.0.0");
                    }

                    Console.WriteLine("On what port is the authentication server listening");
                    while (!int.TryParse(Console.ReadLine(), out authenticationport))
                    {
                        Console.WriteLine("Incorrect value please use an number between 1024–49151, recommended 64000");
                    }
                }
                else if (key != 'n') goto ConfigureAuthenticationNetwork;

            ConfigureGUID:
                Console.WriteLine("Do you wan to configure the gateway-guid settings? Y/N");
                key = Console.ReadKey(true).KeyChar;
                if (key == 'y')
                {
                    Console.WriteLine("What is the crc key");
                    byte[] ncrckey;
                    while (!Conversions.TryParse(Console.ReadLine(), out ncrckey) || crckey.Length != 20)
                    {
                        Console.WriteLine("Crc key key must be 20 hex digit string, recommended: A928CDC9DBE8751B3BC99EB65AE07E0C849CE739");
                    }

                    Console.WriteLine("What is the guid key");
                    byte[] nguidkey;
                    while (!Conversions.TryParse(Console.ReadLine(), out nguidkey) || guidkey.Length != 20)
                    {
                        Console.WriteLine("Guid key key must be 20 hex digit string, recommended: ED90AA25AE906FB36308C8523A4737A7E7B1FC6F");
                    }

                    crckey = Conversions.ByteToHexString(ncrckey);
                    guidkey = Conversions.ByteToHexString(nguidkey);
                }
                else if (key != 'n') goto ConfigureGUID;

                NetworkSettings networkSettings = new NetworkSettings();
                NetworkFileCollection collection = networkSettings.Connections;
                collection["public"] = new NetworkElement("public", gatewayip.ToString(), gatewayport);
                collection["internal"] = new NetworkElement("internal", authenticationip.ToString(), authenticationport);
                networkSettings.Crckey = crckey;
                networkSettings.Guidkey = guidkey;
                b.Sections.Remove("Saga.NetworkSettings");
                b.Sections.Add("Saga.NetworkSettings", networkSettings);
                b.Save();
                ConfigurationManager.RefreshSection("Saga.NetworkSettings");

                Console.WriteLine("Everything configured");
                LoginClient client;
                for (int i = 0; i < 3; i++)
                {
                    if (NetworkManager.TryGetLoginClient(out client))
                    {
                        Console.WriteLine("Test connection created");
                        client.Close();
                        break;
                    }
                    else
                    {
                        Thread.Sleep(3000);
                        Console.WriteLine("Test connection failed retrying in 3 secconds");
                    }
                }
            }
            else
            {
                LoginClient client;
                Console.WriteLine("Configuration file exists");
                Console.WriteLine("Trying to connect to authentication-server...");
                if (NetworkManager.TryGetLoginClient(out client))
                {
                    client.ExchangeIpAdress(IPAddress.Loopback);
                    Console.WriteLine("Connection to authentication-server is create");
                }
                else
                {
                    switch (NetworkManager.LastError)
                    {
                        case NetworkManager.NetworkError.InvalidHost:
                        Console.WriteLine("Host is invalid");
                        break;

                    case NetworkManager.NetworkError.Refused:
                        Console.WriteLine("Target machine activly refused the connection");
                        break;

                    case NetworkManager.NetworkError.Unknown:
                        Console.WriteLine("Unknown exception occured");
                        break;

                    case NetworkManager.NetworkError.Unreachable:
                        Console.WriteLine("Target machin is unreachable");
                        break;
                    }
                }
            }

            reader.Start();
        }
        public void RunTest()
        {
            DelimitedListTraceListener delimitedWriter;
            string fileName, msg1, msg2, msg3, format, source;
            TraceEventCache eventCache;
            TraceEventType severity;
            int id;
            object[] args, data;
            FileStream stream;
            StreamWriter writer;

            try
            {
                //Scenario 1: TraceEvent (TraceEventCache eventCache, string source, TraceEventType severity, int id, string format, params object[] args)
                fileName = string.Format("{0}_1.xml", this.GetType().Name);
                CommonUtilities.DeleteFile(fileName);
                stream = new FileStream(fileName, FileMode.Create, FileAccess.Write);
                writer = new StreamWriter(stream);
                delimitedWriter = new DelimitedListTraceListener(writer);

                eventCache = null;
                source = "Co1971";
                severity = TraceEventType.Information;
                id = 1000;
                format = "This is an object of type string:{0} and this is of type int: {1}";
                args = new Object[] { "Hello", 6 };
                msg1 = string.Format(format, args);
                delimitedWriter.TraceEvent(eventCache, source, severity, id, format, args);
                delimitedWriter.Dispose();

                Assert.True(CommonUtilities.TestListenerContent(new Type[] { typeof(DelimitedListTraceListener) }, new string[] { fileName }, source));
                Assert.True(CommonUtilities.TestListenerContent(new Type[] { typeof(DelimitedListTraceListener) }, new string[] { fileName }, severity.ToString()));
                Assert.True(CommonUtilities.TestListenerContent(new Type[] { typeof(DelimitedListTraceListener) }, new string[] { fileName }, id.ToString()));
                Assert.True(CommonUtilities.TestListenerContent(new Type[] { typeof(DelimitedListTraceListener) }, new string[] { fileName }, msg1));

                CommonUtilities.DeleteFile(fileName);

                //Scenario 2: TraceEvent(TraceEventCache eventCache, string source, TraceEventType severity, int id, string message)

                fileName = string.Format("{0}_2.xml", this.GetType().Name);
                CommonUtilities.DeleteFile(fileName);
                stream = new FileStream(fileName, FileMode.Create, FileAccess.Write);
                writer = new StreamWriter(stream);
                delimitedWriter = new DelimitedListTraceListener(writer);

                eventCache = null;
                source = "Co1971";
                severity = TraceEventType.Information;
                id = 1000;
                msg1 = "Hello World";
                delimitedWriter.TraceEvent(eventCache, source, severity, id, msg1);
                delimitedWriter.Dispose();

                Assert.True(CommonUtilities.TestListenerContent(new Type[] { typeof(DelimitedListTraceListener) }, new string[] { fileName }, source));
                Assert.True(CommonUtilities.TestListenerContent(new Type[] { typeof(DelimitedListTraceListener) }, new string[] { fileName }, severity.ToString()));
                Assert.True(CommonUtilities.TestListenerContent(new Type[] { typeof(DelimitedListTraceListener) }, new string[] { fileName }, id.ToString()));
                Assert.True(CommonUtilities.TestListenerContent(new Type[] { typeof(DelimitedListTraceListener) }, new string[] { fileName }, msg1));
                CommonUtilities.DeleteFile(fileName);

                //Scenario 3: TraceData(TraceEventCache eventCache, string source, TraceEventType severity, int id, object data)

                fileName = string.Format("{0}_3.xml", this.GetType().Name);
                CommonUtilities.DeleteFile(fileName);
                stream = new FileStream(fileName, FileMode.Create, FileAccess.Write);
                writer = new StreamWriter(stream);
                delimitedWriter = new DelimitedListTraceListener(writer);
                object data1;
                eventCache = null;
                source = "Co1971";
                severity = TraceEventType.Information;
                id = 1000;
                data1 = Decimal.MaxValue;
                delimitedWriter.TraceData(eventCache, source, severity, id, data1);
                delimitedWriter.Dispose();

                Assert.True(CommonUtilities.TestListenerContent(new Type[] { typeof(DelimitedListTraceListener) }, new string[] { fileName }, source));
                Assert.True(CommonUtilities.TestListenerContent(new Type[] { typeof(DelimitedListTraceListener) }, new string[] { fileName }, severity.ToString()));
                Assert.True(CommonUtilities.TestListenerContent(new Type[] { typeof(DelimitedListTraceListener) }, new string[] { fileName }, id.ToString()));
                Assert.True(CommonUtilities.TestListenerContent(new Type[] { typeof(DelimitedListTraceListener) }, new string[] { fileName }, data1.ToString()));
                CommonUtilities.DeleteFile(fileName);

                //Scenario 4: TraceData(TraceEventCache eventCache, string source, TraceEventType severity, int id, params object[] data)

                fileName = string.Format("{0}_4.xml", this.GetType().Name);
                CommonUtilities.DeleteFile(fileName);
                stream = new FileStream(fileName, FileMode.Create, FileAccess.Write);
                writer = new StreamWriter(stream);
                delimitedWriter = new DelimitedListTraceListener(writer);

                eventCache = null;
                source = "Co1971";
                severity = TraceEventType.Information;
                id = 1000;
                data = new Object[] { Decimal.MaxValue, Int64.MinValue, Int32.MaxValue, "Hello" };
                msg1 = string.Format("{0}{1}{2}{3}", data);
                delimitedWriter.TraceData(eventCache, source, severity, id, data);
                delimitedWriter.Dispose();


                Assert.True(CommonUtilities.TestListenerContent(new Type[] { typeof(DelimitedListTraceListener) }, new string[] { fileName }, source));
                Assert.True(CommonUtilities.TestListenerContent(new Type[] { typeof(DelimitedListTraceListener) }, new string[] { fileName }, severity.ToString()));
                Assert.True(CommonUtilities.TestListenerContent(new Type[] { typeof(DelimitedListTraceListener) }, new string[] { fileName }, id.ToString()));
                Assert.True(CommonUtilities.TestListenerContent(new Type[] { typeof(DelimitedListTraceListener) }, new string[] { fileName }, data[0].ToString()));
                Assert.True(CommonUtilities.TestListenerContent(new Type[] { typeof(DelimitedListTraceListener) }, new string[] { fileName }, data[1].ToString()));
                Assert.True(CommonUtilities.TestListenerContent(new Type[] { typeof(DelimitedListTraceListener) }, new string[] { fileName }, data[2].ToString()));
                Assert.True(CommonUtilities.TestListenerContent(new Type[] { typeof(DelimitedListTraceListener) }, new string[] { fileName }, data[3].ToString()));
                CommonUtilities.DeleteFile(fileName);

                //Scenario 5: Write(string message)

                fileName = string.Format("{0}_5.xml", this.GetType().Name);
                CommonUtilities.DeleteFile(fileName);
                stream = new FileStream(fileName, FileMode.Create, FileAccess.Write);
                writer = new StreamWriter(stream);
                delimitedWriter = new DelimitedListTraceListener(writer);

                msg1 = "Hello World";
                delimitedWriter.Write(msg1);
                delimitedWriter.Dispose();
                Assert.True(CommonUtilities.TestListenerContent(new Type[] { typeof(DelimitedListTraceListener) }, new string[] { fileName }, msg1));
                CommonUtilities.DeleteFile(fileName);

                //Scenario 6: WriteLine(string message)
                fileName = string.Format("{0}_6.xml", this.GetType().Name);
                CommonUtilities.DeleteFile(fileName);
                stream = new FileStream(fileName, FileMode.Create, FileAccess.Write);
                writer = new StreamWriter(stream);
                delimitedWriter = new DelimitedListTraceListener(writer);

                msg1 = "Hello World";
                delimitedWriter.WriteLine(msg1);
                delimitedWriter.Dispose();

                Assert.True(CommonUtilities.TestListenerContent(new Type[] { typeof(DelimitedListTraceListener) }, new string[] { fileName }, msg1));
                CommonUtilities.DeleteFile(fileName);

                //Scenario 7: some TraceListener methods that are not overridden
                fileName = string.Format("{0}_7.xml", this.GetType().Name);
                CommonUtilities.DeleteFile(fileName);
                stream = new FileStream(fileName, FileMode.Create, FileAccess.Write);
                writer = new StreamWriter(stream);
                delimitedWriter = new DelimitedListTraceListener(writer);
                msg1 = "Msg1";
                msg2 = "Msg2";
                delimitedWriter.Fail(msg1, msg2);
                msg3 = "Hello World";
                delimitedWriter.Fail(msg3);
                delimitedWriter.Dispose();

                Assert.True(CommonUtilities.TestListenerContent(new Type[] { typeof(DelimitedListTraceListener) }, new string[] { fileName }, msg1));
                Assert.True(CommonUtilities.TestListenerContent(new Type[] { typeof(DelimitedListTraceListener) }, new string[] { fileName }, msg2));
                Assert.True(CommonUtilities.TestListenerContent(new Type[] { typeof(DelimitedListTraceListener) }, new string[] { fileName }, msg1));
                CommonUtilities.DeleteFile(fileName);

                //Scenario 8: some TraceListener properties that are not overridden
                fileName = string.Format("{0}_8.xml", this.GetType().Name);
                CommonUtilities.DeleteFile(fileName);
                stream = new FileStream(fileName, FileMode.Create, FileAccess.Write);
                writer = new StreamWriter(stream);
                delimitedWriter = new DelimitedListTraceListener(writer);

                Assert.True(delimitedWriter.Filter == null);
                Assert.True(delimitedWriter.IndentLevel == 0);
                Assert.True(delimitedWriter.IndentSize == 4);
                Assert.True(delimitedWriter.Name == string.Empty);
                Assert.True(delimitedWriter.TraceOutputOptions == TraceOptions.None);
                delimitedWriter.Dispose();
                CommonUtilities.DeleteFile(fileName);
            }
            finally
            {
                for (int i = 1; i <= 8; i++)
                {
                    fileName = string.Format("{0}_{1}.xml", this.GetType().Name, i);
                    CommonUtilities.DeleteFile(fileName);
                }
            }
        }
Пример #18
0
        private static void Main(string[] args)
        {
            //Set managers
            ManagerBase2.SetTraceLog(generaltracelog);
            CoreService.SetTraceLog(generaltracelog);

            //GET THE ASSEMBLY'S DIRECTORY
            string file = System.Reflection.Assembly.GetExecutingAssembly().Location;
            string fname = Path.GetFileNameWithoutExtension(file);

            //TRACELOG
            Trace.AutoFlush = true;
            Trace.IndentSize = 4;
            if (System.Diagnostics.Trace.Listeners.Count <= 1 && (System.Diagnostics.Trace.Listeners["Default"] == null ||
                System.Diagnostics.Trace.Listeners["Default"].GetType() == typeof(System.Diagnostics.DefaultTraceListener)))
            {
                DelimitedListTraceListener del = new System.Diagnostics.DelimitedListTraceListener((fname + ".log.csv"), "text");
                del.Delimiter = ",";
                System.Diagnostics.Trace.Listeners.Add(del);
            }

            Trace.WriteLine("#############################################################################");
            Trace.WriteLine(string.Format("Saga Map Server starting on: {0}", DateTime.Now));
            Trace.WriteLine(string.Format("OS Information: {0}", Environment.OSVersion));
            Trace.WriteLine(string.Format("Number of Processors: {0}", Environment.ProcessorCount));
            Trace.WriteLine(string.Format("CLR Version: {0}", Environment.Version));
            Trace.WriteLine(string.Format("Working set: {0}", Environment.WorkingSet));
            Trace.WriteLine(string.Format("OS Bit Version: {0} Bit", IntPtr.Size * 8));
            Trace.WriteLine("#############################################################################");

            AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);

            //Do initial configuration
            FirstRunConfiguration();

            _ConsoleCommands = ManagerBase2.ProvideManager<ConsoleCommands>("Saga.Manager.ConsoleSettings");
            _NetworkService = ManagerBase2.ProvideManager<NetworkService>("Saga.Manager.NetworkSettings");
            _WorldTasks = ManagerBase2.ProvideManager<WorldTasks>("Saga.Manager.WorldTasks");
            _Database = ManagerBase2.ProvideManager<Database>("Saga.Manager.Database");
            _Quests = ManagerBase2.ProvideManager<Saga.Managers.Quests>("Saga.Manager.Quest");
            _ScriptCompiler = ManagerBase2.ProvideManager<ScriptCompiler>("Saga.Manager.Scripting");
            _EventManager = FactoryBase.ProvideManager<EventManager>("Saga.Factory.Events");
            _Additions = FactoryBase.ProvideManager<Additions>("Saga.Factory.Addition");
            _Portals = FactoryBase.ProvideManager<Portals>("Saga.Factory.Portals");
            _Spells = FactoryBase.ProvideManager<Saga.Factory.Spells>("Saga.Factory.Spells");
            _StatusByLevel = FactoryBase.ProvideManager<Saga.Factory.StatusByLevel>("Saga.Factory.StatusByLevel");
            _Warps = FactoryBase.ProvideManager<Warps>("Saga.Factory.Warps");
            _Zones = FactoryBase.ProvideManager<Zones>("Saga.Factory.Zones");
            _ItemFactory = FactoryBase.ProvideManager<ItemsFactory>("Saga.Factory.Items");
            _Weaponary = FactoryBase.ProvideManager<Weaponary>("Saga.Factory.Weaponary");
            _SpawnTemplates = FactoryBase.ProvideManager<SpawnTemplate>("Saga.Factory.SpawnTemplate");
            _SpawnWorldObjects = FactoryBase.ProvideManager<SpawnWorldObjects>("Saga.Factory.SpawnWorldObjects");
            _SpawnMultiWorldObjectSettings = FactoryBase.ProvideManager<SpawnMultiWorldObjects>("Saga.Factory.SpawnMultiWorldObjects");
            _CharacterConfiguration = FactoryBase.ProvideManager<CharacterConfiguration>("Saga.Factory.CharacterConfiguration");
            _ItemDrops = FactoryBase.ProvideManager<ItemsDrops>("Saga.Factory.ItemDrops");

            try
            {
                ManagerCollection section = (ManagerCollection)ConfigurationManager.GetSection("Saga.Managers");
                if (section != null)
                {
                    foreach (SingletonManagerElement element in section)
                    {
                        ManagerBase2 managerBase = ManagerBase2.ProvideManagerFromTypeString<ManagerBase2>(element.Type);
                        _CustomManagers.Add(element.Name, managerBase);
                    }
                }
            }
            catch (Exception e)
            {
                HostContext.Current.AddUnhandeldException(e);
            }
            finally
            {
                HostContext.Current.Initialize();
                HostContext.Current.BeforeQuerySettings();
                HostContext.Current.AfterQuerySettings();
                HostContext.Current.Load();
                HostContext.Current.Loaded();
            }

            Console.ReadLine();
        }
Пример #19
0
        public void Test05()
        {
            string fileName = string.Format("{0}_8.txt", this.GetType().Name);
            try
            {
                CommonUtilities.DeleteFile(fileName);
                FileStream stream = new FileStream(fileName, FileMode.Create, FileAccess.Write);
                _delimitedListener = new DelimitedListTraceListener(stream);
                Assert.True(_delimitedListener.Delimiter == ";");
                Assert.True(_delimitedListener.Name == "");

                _delimitedListener.Delimiter = "";
                _delimitedListener.Dispose();
            }
            catch (ArgumentException)
            {
                _delimitedListener.Dispose();
            }
            finally
            {
                CommonUtilities.DeleteFile(fileName);
            }
        }
Пример #20
0
 /// <summary>
 /// Derived method to initialize trace listener to write trace data separated by a delimiter
 /// </summary>
 /// <param name="traceSource">Trace source that holds a set of handlers</param>
 /// <param name="filterLevels">The level of trace message filtered by trace listener</param>
 /// <param name="traceOptions">Trace data options that has to be written in the trace output</param>
 /// <param name="traceListener">Trace listener object associated with the trace source</param>
 public override void InitListener(out TraceListener traceListener)
 {
     traceListener = new DelimitedListTraceListener(this.GetStreamWriter());
 }
		public void TraceDataWithCache1 ()
		{
			StringWriter sw = new StringWriter ();
			DelimitedListTraceListener x = new DelimitedListTraceListener (sw);
			Trace.CorrelationManager.StartLogicalOperation ("op1"); // ... irrelevant?
			TraceEventCache cc = new TraceEventCache ();
			x.TraceData (cc, null, TraceEventType.Error, 2);
			x.TraceData (cc, null, TraceEventType.Error, 3);
			Trace.CorrelationManager.StopLogicalOperation ();
			x.Close ();
			Assert.AreEqual (sample4, sw.ToString ().Replace ("\r\n", "\n"));
		}
        static async Task Proc()
        {
            using (var logStrm = new System.IO.StreamWriter(@".\trace.log", false) { AutoFlush = true })
            using (var loggerA = new System.Diagnostics.DelimitedListTraceListener(logStrm))
            using (var loggerB = new System.Diagnostics.ConsoleTraceListener())
            {
                System.Diagnostics.Trace.Listeners.Add(loggerA);
                System.Diagnostics.Trace.Listeners.Add(loggerB);

                Trace.WriteLine("------------------------------");
                Trace.WriteLine(" Environment");
                Trace.WriteLine("------------------------------");
                Trace.WriteLine(string.Format("Environment.OSVersion: {0}", Environment.OSVersion));
                Trace.WriteLine(string.Format("Environment.Is64BitOperatingSystem: {0}", Environment.Is64BitOperatingSystem));
                Trace.WriteLine(string.Format("Environment.Is64BitProcess: {0}", Environment.Is64BitProcess));
                Console.WriteLine();

                Trace.WriteLine("------------------------------");
                Trace.WriteLine(" Tests: IE");
                Trace.WriteLine("------------------------------");

                var targetUrl = new Uri("http://nicovideo.jp");
                var valueKey = null as string;

                try
                {
                    //Win32Api.IEGetProtectedModeCookie
                    string lpszCookieData;
                    var hResult = Win32Api.GetCookiesFromProtectedModeIE(out lpszCookieData, targetUrl, valueKey);
                    Trace.WriteLine(lpszCookieData != null
                        ? string.Format("Win32Api.GetCookieFromProtectedModeIE success: 0x{0}", hResult.ToString("x8"))
                        : string.Format("Win32Api.GetCookieFromProtectedModeIE error: 0x{0}", hResult.ToString("x8")));
                }
                catch (Exception e) { Trace.WriteLine(e); }
                finally { Trace.WriteLine(string.Empty); }
                try
                {
                    //Win32Api.IEGetProtectedModeCookie (No Flags)
                    string lpszCookieData;
                    var hResult = Win32Api.GetCookiesFromProtectedModeIE(out lpszCookieData, targetUrl, valueKey, 0);
                    Trace.WriteLine(lpszCookieData != null
                        ? string.Format("Win32Api.GetCookieFromProtectedModeIE(no flags) success: 0x{0}", hResult.ToString("x8"))
                        : string.Format("Win32Api.GetCookieFromProtectedModeIE(no flags) error: 0x{0}", hResult.ToString("x8")));
                }
                catch (Exception e) { Trace.WriteLine(e); }
                finally { Trace.WriteLine(string.Empty); }
                try
                {
                    //IEPMCookieImporter.InternalGetCookiesWinApiOnProxy
                    if (Environment.OSVersion.Platform == PlatformID.Win32NT)
                    {
                        var cookieHeader = IEPMCookieImporter.InternalGetCookiesWinApiOnProxy(targetUrl, valueKey);
                        Trace.WriteLine(cookieHeader != null
                            ? string.Format("IEPMCookieImporter.InternalGetCookiesWinApiOnProxy success")
                            : string.Format("IEPMCookieImporter.InternalGetCookiesWinApiOnProxy error"));
                    }
                }
                catch (Exception e) { Trace.WriteLine(e); }
                finally { Trace.WriteLine(string.Empty); }
                try
                {
                    //IEEPMCookieImporter
                    if (Environment.OSVersion.Platform == PlatformID.Win32NT)
                    {
                        var importer = new IEImporterFactory().GetIEEPMCookieImporter();
                        var res = await importer.GetCookiesAsync(targetUrl);
                        Trace.WriteLine(res.Status == CookieImportState.Success && res.Cookies.Count > 0
                            ? string.Format("IEEPMCookieImporter success")
                            : string.Format("IEEPMCookieImporter error"));
                    }
                }
                catch (Exception e) { Trace.WriteLine(e); }
                finally { Trace.WriteLine(string.Empty); }
                Console.WriteLine();

                Trace.WriteLine("------------------------------");
                Trace.WriteLine(" Tests: CookieGetters");
                Trace.WriteLine("------------------------------");
                try
                {
                    var getters = await CookieGetters.Default.GetInstancesAsync(false);
                    Trace.WriteLine(string.Format("Browser.Length: {0}", getters.Length));
                    for (var i = 0; i < getters.Length; i++)
                        try
                        {
                            Trace.WriteLine(string.Format("{0:00}: {1}", i, getters[i].SourceInfo.BrowserName));
                            Trace.Indent();
                            var res = await getters[i].GetCookiesAsync(targetUrl);
                            Trace.WriteLine(string.Format("Status: {0}", res.Status));
                            Trace.WriteLine(string.Format("Cookies.Count: {0}",
                                res.Status == CookieImportState.Success ? res.Cookies.Count.ToString() : "None"));
                            Trace.Unindent();
                        }
                        catch (Exception e) { Trace.WriteLine(e); }
                }
                catch (Exception e) { Trace.WriteLine(e); }
            }
        }