Пример #1
0
        static void Main(string[] args)
        {
            // set logger factory
            var properties = new Common.Logging.Configuration.NameValueCollection();

            properties["level"]        = "TRACE";
            properties["showLogName"]  = "true";
            properties["showDateTime"] = "true";
            LogManager.Adapter         = new ConsoleOutLoggerFactoryAdapter(properties);

            //ClientConnect();

            //ServerListen();

            //var t = new Test();
            //t.Chunking().Wait();
            //log.Debug("--- RUN Can_Start_And_Stop");
            //t.Can_Start_And_Stop().Wait();
            //log.Debug("--- RUN Swarm_Gets_Bootstrap_Peers");
            //t.Swarm_Gets_Bootstrap_Peers().Wait();
            //Console.WriteLine("finished");
            //Console.ReadKey();

            var test = new PeerTalk.SwarmTest();

            test.Connect_Disconnect().Wait();
        }
Пример #2
0
        private static void InitializeCommonLogging()
        {
            var properties = new Common.Logging.Configuration.NameValueCollection();

            properties["configType"] = "INLINE";
            LogManager.Adapter       = new Log4NetLoggerFactoryAdapter(properties);
        }
Пример #3
0
        private static void ConnectUsingLdClient()
        {
            var props = new Common.Logging.Configuration.NameValueCollection
            {
                { "level", "warn" }
            };

            LogManager.Adapter = new ConsoleOutLoggerFactoryAdapter(props);

            var ldConfig = LaunchDarkly.Client.Configuration
                           .Default(TestSdkKey)
                           //.WithIsStreamingEnabled(false)//;
                           .WithUri("http://sudawsm:49345/")
                           .WithStreamUri("http://sudawsm:49345/")
                           .WithEventsUri("http://sudawsm:49345/");

            LdClient client = new LdClient(ldConfig);
            User     user   = User.WithKey("Default");

            for (int i = 0; i < 100; i++)
            {
                var value = client.BoolVariation(TestFeatureFlag, user, false);
                Log("got value {0}", value);
                Log(
                    value
                        ? "Showing feature for user {0}, iteration: {1}"
                        : "Not showing feature for user {0}, iteration: {1}", user.Key, i);
                client.Flush();
                Task.Delay(TimeSpan.FromMilliseconds(5000)).Wait();
            }
            Log("Finished, press any key to continue");
            Console.ReadKey();
        }
Пример #4
0
        static void Main(string[] args)
        {
            var props = new Common.Logging.Configuration.NameValueCollection
            {
                { "level", "Debug" }
            };

            LogManager.Adapter = new ConsoleOutLoggerFactoryAdapter(props);

            Configuration ldConfig = LaunchDarkly.Client.Configuration
                                     // TODO: Enter your LaunchDarkly SDK key here
                                     .Default("YOUR_SDK_KEY");

            LdClient client = new LdClient(ldConfig);
            User     user   = User.WithKey("*****@*****.**")
                              .AndFirstName("Bob")
                              .AndLastName("Loblaw")
                              .AndCustomAttribute("groups", "beta_testers");

            // TODO: Enter the key for your feature flag key here
            var value = client.BoolVariation("YOUR_FEATURE_FLAG_KEY", user, false);

            if (value)
            {
                Console.WriteLine("Showing feature for user " + user.Key);
            }
            else
            {
                Console.WriteLine("Not showing feature for user " + user.Key);
            }
            client.Flush();

            Console.WriteLine("Press any key to exit");
            Console.ReadKey();
        }
Пример #5
0
        static void Main(string[] args)
        {
            Console.WriteLine("Multicast DNS spike");

            // set logger factory
            var properties = new Common.Logging.Configuration.NameValueCollection
            {
                ["level"]        = "TRACE",
                ["showLogName"]  = "true",
                ["showDateTime"] = "true"
            };

            LogManager.Adapter = new ConsoleOutLoggerFactoryAdapter(properties);

            var mdns = new MulticastService
            {
                NetworkInterfaceDiscoveryInterval = TimeSpan.FromSeconds(1),
            };

            foreach (var a in MulticastService.GetIPAddresses())
            {
                Console.WriteLine($"IP address {a}");
            }

            mdns.QueryReceived += (s, e) =>
            {
                var names = e.Message.Questions
                            .Select(q => q.Name + " " + q.Type);
                Console.WriteLine($"got a query for {String.Join(", ", names)}");
            };
            mdns.AnswerReceived += (s, e) =>
            {
                var names = e.Message.Answers
                            .Select(q => q.Name + " " + q.Type)
                            .Distinct();
                Console.WriteLine($"got answer for {String.Join(", ", names)}");
            };
            mdns.NetworkInterfaceDiscovered += (s, e) =>
            {
                foreach (var nic in e.NetworkInterfaces)
                {
                    Console.WriteLine($"discovered NIC '{nic.Name}'");
                }
            };

            var sd = new ServiceDiscovery(mdns);

            sd.Advertise(new ServiceProfile("x1", "_xservice._tcp", 5011));
            sd.Advertise(new ServiceProfile("x2", "_xservice._tcp", 666));
            var z1 = new ServiceProfile("z1", "_zservice.udp", 5012);

            z1.AddProperty("foo", "bar");
            sd.Advertise(z1);

            mdns.Start();
            Console.ReadKey();
        }
Пример #6
0
        private static void SetupLogging()
        {
            var props = new Common.Logging.Configuration.NameValueCollection
            {
                { "configType", "FILE" },
                { "configFile", "./nlog.config" }
            };

            LogManager.Adapter = new Common.Logging.NLog.NLogLoggerFactoryAdapter(props);
        }
Пример #7
0
        /// <summary>
        /// Starts the schedular.
        /// </summary>
        /// <returns>IScheduler.</returns>
        public static IScheduler StartSchedular()
        {
            var properties = new Common.Logging.Configuration.NameValueCollection {
                { "configType", "FILE" }, { "configFile", "~/NLog.config" }
            };

            Common.Logging.LogManager.Adapter = new NLogLoggerFactoryAdapter(properties);
            var scheduler = StdSchedulerFactory.GetDefaultScheduler();

            scheduler.Start();
            return(scheduler);
        }
Пример #8
0
        public static void AssemblyInitialize(TestContext context)
        {
            // set logger factory
            var properties = new Common.Logging.Configuration.NameValueCollection
            {
                ["level"]          = "TRACE",
                ["showLogName"]    = "true",
                ["showDateTime"]   = "true",
                ["dateTimeFormat"] = "HH:mm:ss.fff"
            };

            LogManager.Adapter = new ConsoleOutLoggerFactoryAdapter(properties);
        }
Пример #9
0
        static void Main(string[] args)
        {
            // set logger factory
            var properties = new Common.Logging.Configuration.NameValueCollection();

            properties["level"]          = "DEBUG";
            properties["showLogName"]    = "true";
            properties["showDateTime"]   = "true";
            properties["dateTimeFormat"] = "HH:mm:ss.fff";
            LogManager.Adapter           = new ConsoleOutLoggerFactoryAdapter(properties);

            var test = new BitswapApiTest();

            test.GetsBlock_OnConnect().Wait();
        }
Пример #10
0
        static Program()
        {
            //Setup logging.
            //Must be done (just once!) before any loggers are instantiated
            var props = new Common.Logging.Configuration.NameValueCollection
            {
                { "configType", "FILE" },
                { "configFile", "./nlog.config" }
            };

            LogManager.Adapter = new Common.Logging.NLog.NLogLoggerFactoryAdapter(props);

            //Create logger instance
            log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
        }
Пример #11
0
        /// <summary>
        /// Initializes a new instance of the <see cref="NLog"/> class.
        /// </summary>
        /// <param name="logger"><see cref="ILogger"/></param>
        /// <param name="stopWatch">Performance stopwatch</param>
        public NLog(ILogger logger, IStopWatch stopWatch)
        {
            _logger   = logger;
            StopWatch = stopWatch;
            if (!Configuration.CommonLogEnabled())
            {
                return;
            }

            var props = new Common.Logging.Configuration.NameValueCollection
            {
                { "ConfigType", "INLINE" },
            };

            Common.Logging.LogManager.Adapter = new Common.Logging.NLog.NLogLoggerFactoryAdapter(props);
        }
Пример #12
0
        /// <summary>
        /// Initializes a new instance of the <see cref="MultiFactoryLoggerFactoryAdapter"/> class.
        /// </summary>
        public MultiLoggerFactoryAdapter(Common.Logging.Configuration.NameValueCollection properties)
        {
            LoggerFactoryAdapters = new List <ILoggerFactoryAdapter>();

            foreach (var factoryAdapter in properties.Where(e => e.Key.EndsWith(".factoryAdapter")))
            {
                string adapterName = factoryAdapter.Key.Substring(0, factoryAdapter.Key.Length - 15);
                string adapterType = factoryAdapter.Value;

                var adapterConfig = new Common.Logging.Configuration.NameValueCollection();
                foreach (var entry in properties.Where(e1 => e1.Key.StartsWith(adapterName + ".")))
                {
                    adapterConfig.Add(entry.Key.Substring(adapterName.Length + 1), entry.Value);
                }

                var adapter = (ILoggerFactoryAdapter)Activator.CreateInstance(Type.GetType(adapterType), adapterConfig);
                LoggerFactoryAdapters.Add(adapter);
            }
        }
Пример #13
0
        public static int Main(string[] args)
        {
            var startTime = DateTime.Now;

            // Need to setup common.logging early.
            debugging = args.Any(s => s == "--debug");
            tracing   = args.Any(s => s == "--trace");
            var properties = new Common.Logging.Configuration.NameValueCollection();

            properties["level"]          = tracing ? "TRACE" : (debugging ? "DEBUG" : "OFF");
            properties["showLogName"]    = "true";
            properties["showDateTime"]   = "true";
            properties["dateTimeFormat"] = "HH:mm:ss.fff";
            LogManager.Adapter           = new ConsoleOutLoggerFactoryAdapter(properties);

            try
            {
                CommandLineApplication.Execute <Program>(args);
            }
            catch (Exception e)
            {
                for (; e != null; e = e.InnerException)
                {
                    Console.Error.WriteLine(e.Message);
                    if (debugging || tracing)
                    {
                        Console.WriteLine();
                        Console.WriteLine(e.StackTrace);
                    }
                }
                return(1);
            }

            var took = DateTime.Now - startTime;

            //Console.Write($"Took {took.TotalSeconds} seconds.");

            return(0);
        }
Пример #14
0
        static void Main(string[] args)
        {
            var props = new Common.Logging.Configuration.NameValueCollection
            {
                { "level", "Debug" }
            };

            LogManager.Adapter = new ConsoleOutLoggerFactoryAdapter(props);

            Configuration ldConfigGood = LaunchDarkly.Client.Configuration.Default("SDK_KEY")
                                         .WithBaseUri("BASE_URI")
                                         .WithStreamUri("STREAM_URI")
                                         .WithEventsUri("EVENTS_URI");

            Configuration ldConfigBad = LaunchDarkly.Client.Configuration.Default("SDK_KEY")

                                        LdClient client = new LdClient(ldConfig);
            User user = User.Builder("*****@*****.**")
                        .FirstName("Bob")
                        .LastName("Loblaw")
                        .Custom("groups", "beta_testers")
                        .Build();

            // TODO: Enter the key for your feature flag key here
            var value = client.BoolVariation("YOUR_FEATURE_FLAG_KEY", user, false);

            if (value)
            {
                Console.WriteLine("Showing feature for user " + user.Key);
            }
            else
            {
                Console.WriteLine("Not showing feature for user " + user.Key);
            }
            client.Flush();

            Console.WriteLine("Press any key to exit");
            Console.ReadKey();
        }
 /// <summary>
 /// 適配器構造處理(適配器自定義屬性讀取)
 /// </summary>
 /// <param name="properties">屬性</param>
 public NLogLoggerFactoryAdapter(Common.Logging.Configuration.NameValueCollection properties)
     : base(properties)
 {
 }
        public void ThreadedRequestsGetProcessed()
        {
            // oh well, this test doesn't fail if it does, because there's no assertions or exceptions (or anything) in threads
            // but log and debug should show anomalies (and todo I should assert on them)

            var properties = new Common.Logging.Configuration.NameValueCollection
            {
                ["showDateTime"] = "true"
            };

            LogManager.Adapter = new Common.Logging.Simple.ConsoleOutLoggerFactoryAdapter(properties);

            ThreadStart ts = () =>
            {
                lock (this)
                {
                    Thread.CurrentThread.Name = "test thread " + (_threadId++).ToString();
                }

                ILog log = LogManager.GetLogger <PechkinSynchronizedTests>();
                log.Trace("T:" + Thread.CurrentThread.Name + " Thread started");

                string html = GetResourceString("PechkinTests.Resources.page.html");

                log.Trace("T:" + Thread.CurrentThread.Name + " Got resource string");

                SynchronizedPechkin c = ProduceTestObject(new GlobalConfig());
                //SimplePechkin c = new SimplePechkin(new GlobalConfig());

                log.Trace("T:" + Thread.CurrentThread.Name + " Created converter, starting conversion");

                byte[] ret = c.Convert(html);

                log.Trace("T:" + Thread.CurrentThread.Name + " Converted everything, " + c.ProgressString);

                Assert.NotNull(ret);
            };

            Thread t  = new Thread(ts);
            Thread t2 = new Thread(ts);

            t.Start();
            Thread.Sleep(1000);
            t2.Start();

            GC.Collect();

            Thread.Sleep(6000);

            GC.Collect();

            Thread.Sleep(60000);

            /*
             * t = new Thread(ts);
             * t2 = new Thread(ts);
             *
             * t.Start();
             * Thread.Sleep(1000);
             * t2.Start();
             *
             * GC.Collect();
             *
             * Thread.Sleep(6000);
             *
             * GC.Collect();
             */

            TestEnd();
        }