Exemplo n.º 1
0
        // public static void RegisterRoutes(RouteCollection routes)
        // {
        //     routes.MapPageRoute("",
        //         "Category/{action}/{categoryName}",
        //         "~/categoriespage.aspx");
        // }
        // private string GetMacAddress()
        // {
        //     string macAddresses = string.Empty;
        //
        //     foreach (NetworkInterface nic in NetworkInterface.GetAllNetworkInterfaces())
        //     {
        //         if (nic.OperationalStatus == OperationalStatus.Up)
        //         {
        //             macAddresses += nic.GetPhysicalAddress().ToString();
        //             break;
        //         }
        //     }
        //     Console.WriteLine(macAddresses);
        //     return macAddresses;
        // }
        public static string GetLocalIPAddress()
        {
            var host = Dns.GetHostEntry(Dns.GetHostName());

            foreach (var ip in host.AddressList)
            {
                if (ip.AddressFamily == AddressFamily.InterNetwork)
                {
                    return(ip.ToString());
                }
            }
            throw new Exception("No network adapters with an IPv4 address in the system!");
        }
Exemplo n.º 2
0
        public void Should_measure_lookup_latency()
        {
            var stopWatch = Stopwatch.StartNew();

            DNS.GetHostEntry("google.com");
            stopWatch.Stop();

            Action assertion = () => collections.Should().HaveCount(1);

            assertion.ShouldPassIn(5.Seconds());
            var latency = collections.Single().Latency;

            Math.Abs(stopWatch.ElapsedMilliseconds - latency.TotalMilliseconds).Should().BeLessThan(1);
        }
Exemplo n.º 3
0
        public void Should_measure_lookups()
        {
            const int lookupsCount = 5;

            for (var i = 0; i < lookupsCount; i++)
            {
                DNS.GetHostEntry("google.com");
            }

            Action assertion = () => collections.Should().HaveCount(lookupsCount);

            assertion.ShouldPassIn(5.Seconds());
            collections.Any(info => info.IsFailed).Should().BeFalse();
        }
Exemplo n.º 4
0
        public Server(int port, IMPLEMENTATION implementor)
        {
            Debug.Assert(implementor != null);
            ExecutionPhaseChanged?.Invoke(this, new ExecutionPhaseEventArgs(ExecutionPhase.ReflectionStarted));
            var knownTypes = Utility.CollectKnownTypes(typeof(CONTRACT));

            serializer       = new(typeof(MethodSchema), knownTypes);
            methodDictionary = new MethodDictionary();
            CreateImplementingDynamicMethods(implementor);
            ExecutionPhaseChanged?.Invoke(this, new ExecutionPhaseEventArgs(ExecutionPhase.ReflectionComplete));
            this.implementor = implementor;
            this.port        = port;
            localIpAddress   = Dns.GetHostEntry(DefinitionSet.localHost).AddressList[0];
            listener         = new(localIpAddress, port);
            listeningThread  = new(ListenerThreadBody);
            protocolThread   = new(ProtocolThreadBody);
        } //Server
Exemplo n.º 5
0
        public void Should_measure_failed_lookups()
        {
            const int lookupsCount = 5;

            for (var i = 0; i < lookupsCount; i++)
            {
                try
                {
                    DNS.GetHostEntry("go23t2dst2ogle.c23t4vgwom");
                }
                catch
                {
                    // Ignore
                }
            }

            Action assertion = () => collections.Should().HaveCount(lookupsCount);

            assertion.ShouldPassIn(30.Seconds());
            collections.All(info => info.IsFailed).Should().BeTrue();
        }
Exemplo n.º 6
0
        static void Main(string[] args)
        {
            ToMainPage.AppendChild(HtmlNode.CreateNode("<h1>Forum</h1>"));
            forum = new Forum2.Forum("users.xml", "threads.xml");
            forum.ThreadManager.AddThread(new Forum2.Items.User(), new Forum2.Items.ThreadItems.Header("New forum, new threads", "First thread on forum redesign"));
            forum.ThreadManager.AddThread(new Forum2.Items.User(), new Forum2.Items.ThreadItems.Header("Testing thread enumerability", "yes test"));
            forum.ContentManager.AddContent("icon.png", "", Content.ContentTypes.IMGPNG);
            if (!forum.UserManager.Exists("MrDoritos"))
            {
                forum.UserManager.AddUser("MrDoritos", "coolguy");
            }
            var thread = forum.ThreadManager.GetThread(1);

            thread.AddComment(new Forum2.Items.ThreadItems.Comment("Yes", new Forum2.Items.User(), DateTime.Now, 1));
            while (true)
            {
                try
                {
                    Console.Write("Hostname: ");
                    server = new Server(new System.Net.IPEndPoint(Dns.GetHostAddresses(Console.ReadLine())[0], 80));
                    server.Start();
                    server.RequestRecieved += RequestRecieved;
                    break;
                }
                catch (Exception e)
                {
                    Console.WriteLine($"{e.Message}\r\n");
                }
            }
            Console.WriteLine("Server started");
            while (server.Connected)
            {
                forum.UserManager.Save(); Console.WriteLine("Saved Databases"); Task.Delay(600000).Wait();
            }
            Console.WriteLine("Server stopped\r\nPress any key to continue...");
            Console.ReadKey();
        }