Exemple #1
0
        public void TestSetRequestedCapabilities()
        {
            string   ua     = "Mozilla/5.0 (Nintendo Switch; WebApplet) AppleWebKit/601.6 (KHTML, like Gecko) NF/4.0.0.5.9 NintendoBrowser/5.1.0.13341";
            WmClient client = WmClient.Create(serverProtocol, serverIP, serverPort, "");

            Assert.NotNull(client);
            client.SetRequestedStaticCapabilities(new string[] { "brand_name", "is_ios", "non_ex_cap" });
            client.SetRequestedVirtualCapabilities(new string[] { "brand_name", "is_ios", "non_ex_vcap" });

            JSONDeviceData d = client.LookupUserAgent(ua);

            Assert.NotNull(d);
            Assert.AreEqual(3, d.Capabilities.Count);
            client.SetRequestedStaticCapabilities(null);
            d = client.LookupUserAgent(ua);
            Assert.AreEqual(2, d.Capabilities.Count);
            client.SetRequestedVirtualCapabilities(null);
            // Resetting all requested caps arrays makes server return ALL available caps
            d = client.LookupUserAgent(ua);
            Assert.True(d.Capabilities.Count >= 40);

            bool exc = false;

            try
            {
                var cap = d.Capabilities["non_ex_cap"];
            }
            catch (Exception)
            {
                exc = true;
            }
            Assert.True(exc);
        }
Exemple #2
0
        public void TestLookupRequestWithEmptyBody()
        {
            WmClient client     = WmClient.Create(serverProtocol, serverIP, serverPort, "");
            bool     excCatched = false;

            try
            {
                Assert.NotNull(client);

                // Create request to pass
                Mock <HttpRequestBase> mockHttpRequest = new Mock <HttpRequestBase>();

                JSONDeviceData jsonData = client.LookupRequest(mockHttpRequest.Object);
            }
            catch (WmException e)
            {
                excCatched = true;
                Assert.NotNull(e.Message);
                Assert.True(e.Message.Length > 0);
                Assert.True(e.Message.Contains("Headers dictionary cannot be null"));
            }
            finally
            {
                client.DestroyConnection();
            }
            Assert.True(excCatched);
        }
Exemple #3
0
        public void TestLookupRequestWithSpecificCapsAndNoHeaders()
        {
            WmClient client = WmClient.Create(serverProtocol, serverIP, serverPort, "");

            try
            {
                string[] reqCaps = { "brand_name", "is_wireless_device", "pointing_method", "model_name" };
                Assert.NotNull(client);
                client.SetRequestedCapabilities(reqCaps);

                // Create request to pass
                Mock <HttpRequestBase> mockHttpRequest = new Mock <HttpRequestBase>();
                NameValueCollection    requestHeaders  = new NameValueCollection {
                };
                mockHttpRequest.SetupGet(x => x.Headers).Returns(requestHeaders);
                JSONDeviceData jsonData = client.LookupRequest(mockHttpRequest.Object);
                // From version 2.1.0 on, WURFL Microservice server returns "generic" device and not
                // an error in case of empty user-agent or headers.
                Assert.AreEqual("generic", jsonData.Capabilities["wurfl_id"]);
            }
            catch (WmException e)
            {
                Assert.NotNull(e.Message);
                Assert.True(e.Message.Length > 0);
            }
            finally
            {
                client.DestroyConnection();
            }
        }
Exemple #4
0
        public void TestLookupUseragentWithVcapOnly()
        {
            var ua = "Mozilla/5.0 (Nintendo Switch; WebApplet) AppleWebKit/601.6 (KHTML, like Gecko) NF/4.0.0.5.9 NintendoBrowser/5.1.0.13341";

            WmClient client = WmClient.Create(serverProtocol, serverIP, serverPort, "");

            try
            {
                string[] reqCaps = { "is_robot",                     "is_smartphone", "is_app", "complete_device_name", "advertised_device_os",
                                     "advertised_device_os_version", "form_factor",   "is_app_webview" };
                Assert.NotNull(client);
                client.SetRequestedCapabilities(reqCaps);

                JSONDeviceData jsonData = client.LookupUserAgent(ua);
                Assert.NotNull(jsonData);
                var did = jsonData.Capabilities;
                Assert.NotNull(did);
                Assert.AreEqual(9, did.Count);
                Assert.AreEqual("false", did["is_robot"]);
                Assert.AreEqual("false", did["is_smartphone"]);
                Assert.AreEqual("false", did["is_app"]);
                Assert.AreEqual("false", did["is_app_webview"]);
                Assert.AreEqual("Nintendo", did["advertised_device_os"]);
                Assert.AreEqual("Nintendo Switch", did["complete_device_name"]);
                Assert.AreEqual("nintendo_switch_ver1", did["wurfl_id"]);
            }
            finally
            {
                client.DestroyConnection();
            }
        }
Exemple #5
0
        public void TestLookupHeadersOK()
        {
            var ua = "Mozilla/5.0 (Nintendo Switch; WebApplet) AppleWebKit/601.6 (KHTML, like Gecko) NF/4.0.0.5.9 NintendoBrowser/5.1.0.13341";
            IDictionary <string, string> requestHeaders = new Dictionary <string, string>()
            {
                { "User-agent", ua },
                { "content-Type", "gzip, deflate" },
                { "Accept-Encoding", "application/json" }
            };


            WmClient client = WmClient.Create(serverProtocol, serverIP, serverPort, "");

            client.SetCacheSize(1000);
            try
            {
                Assert.NotNull(client);
                JSONDeviceData jsonData = client.LookupHeaders(requestHeaders);
                Assert.NotNull(jsonData);
                var did = jsonData.Capabilities;
                Assert.NotNull(did);
                Assert.True(did.Count >= 40);
                Assert.AreEqual("Smart-TV", did["form_factor"]);

                Assert.AreEqual("false", did["is_app"]);
                Assert.AreEqual("false", did["is_app_webview"]);
                Assert.AreEqual("Nintendo", did["advertised_device_os"]);
                Assert.AreEqual("Nintendo Switch", did["complete_device_name"]);
                Assert.AreEqual("nintendo_switch_ver1", did["wurfl_id"]);

                // Now set a cap filter
                string[] reqCaps = { "form_factor", "is_mobile", "is_app", "complete_device_name", "advertised_device_os", "brand_name" };
                client.SetRequestedCapabilities(reqCaps);
                jsonData = client.LookupHeaders(requestHeaders);
                did      = jsonData.Capabilities;
                Assert.NotNull(did);
                Assert.AreEqual(7, did.Count);

                // Now, lets try with mixed case headers
                requestHeaders = new Dictionary <string, string>()
                {
                    { "usEr-AgeNt", ua },
                    { "CoNtent-TYpe", "gzip, deflate" },
                    { "Accept-ENCoding", "application/json" }
                };

                jsonData = client.LookupHeaders(requestHeaders);
                did      = jsonData.Capabilities;
                Assert.NotNull(did);

                int[] cacheSizes = client.GetActualCacheSizes();
                // Cache has been hit even if header names have a different case
                Assert.AreEqual(1, cacheSizes[1]);
            }
            finally
            {
                client.DestroyConnection();
            }
        }
Exemple #6
0
        public WmClient CreateTestCachedClient(int csize)
        {
            WmClient client = WmClient.Create(serverProtocol, serverIP, serverPort, "");

            client.SetCacheSize(csize);
            Assert.NotNull(client);
            return(client);
        }
Exemple #7
0
        public void TestCreateWithEmptySchemeValue()
        {
            WmClient client = WmClient.Create(serverProtocol, serverIP, serverPort, "");

            Assert.NotNull(client);
            Assert.True(client.ImportantHeaders.Length > 0);
            Assert.True(client.VirtualCaps.Length > 0);
            Assert.True(client.StaticCaps.Length > 0);
        }
Exemple #8
0
        public void TestLookupRequestOK()
        {
            var ua = "Mozilla/5.0 (Nintendo Switch; WebApplet) AppleWebKit/601.6 (KHTML, like Gecko) NF/4.0.0.5.9 NintendoBrowser/5.1.0.13341";
            Mock <HttpRequestBase> mockHttpRequest = new Mock <HttpRequestBase>();
            NameValueCollection    requestHeaders  = new NameValueCollection
            {
                { "User-agent", ua },
                { "content-Type", "gzip, deflate" },
                { "Accept-Encoding", "application/json" }
            };

            mockHttpRequest.SetupGet(x => x.Headers).Returns(requestHeaders);

            WmClient client = WmClient.Create(serverProtocol, serverIP, serverPort, "");

            try
            {
                Assert.NotNull(client);
                JSONDeviceData jsonData = client.LookupRequest(mockHttpRequest.Object);
                Assert.NotNull(jsonData);
                var did = jsonData.Capabilities;
                Assert.NotNull(did);
                Assert.True(did.Count >= 40);
                Assert.AreEqual("Smart-TV", did["form_factor"]);

                Assert.AreEqual("false", did["is_app"]);
                Assert.AreEqual("false", did["is_app_webview"]);
                Assert.AreEqual("Nintendo", did["advertised_device_os"]);
                Assert.AreEqual("Nintendo Switch", did["complete_device_name"]);
                Assert.AreEqual("nintendo_switch_ver1", did["wurfl_id"]);

                // Now set a cap filter
                string[] reqCaps = { "form_factor", "is_mobile", "is_app", "complete_device_name", "advertised_device_os", "brand_name" };
                client.SetRequestedCapabilities(reqCaps);
                jsonData = client.LookupRequest(mockHttpRequest.Object);
                did      = jsonData.Capabilities;
                Assert.NotNull(did);
                Assert.AreEqual(7, did.Count);

                // Now, lets try with mixed case headers
                requestHeaders = new NameValueCollection
                {
                    { "usEr-AgeNt", ua },
                    { "CoNtent-TYpe", "gzip, deflate" },
                    { "Accept-ENCoding", "application/json" }
                };
                mockHttpRequest.SetupGet(x => x.Headers).Returns(requestHeaders);
                jsonData = client.LookupRequest(mockHttpRequest.Object);
                did      = jsonData.Capabilities;
                Assert.NotNull(did);
            }
            finally
            {
                client.DestroyConnection();
            }
        }
Exemple #9
0
        public void TestHasStaticCapability()
        {
            WmClient client = WmClient.Create(serverProtocol, serverIP, serverPort, "");

            Assert.NotNull(client);
            Assert.True(client.HasStaticCapability("brand_name"));
            Assert.True(client.HasStaticCapability("model_name"));
            Assert.True(client.HasStaticCapability("is_smarttv"));
            // this is a virtual capability, so it shouldn't be returned
            Assert.False(client.HasStaticCapability("is_app"));
        }
Exemple #10
0
        public void TestDestroyConnection()
        {
            WmClient client = WmClient.Create(serverProtocol, serverIP, serverPort, "");

            Assert.NotNull(client);


            Assert.NotNull(client.GetInfo());

            client.DestroyConnection();
            Assert.Throws <WmException>(() => client.GetInfo());
        }
Exemple #11
0
        public void TestHasVirtualCapability()
        {
            WmClient client = WmClient.Create(serverProtocol, serverIP, serverPort, "");

            Assert.NotNull(client);
            Assert.True(client.HasVirtualCapability("is_app"));
            Assert.True(client.HasVirtualCapability("is_smartphone"));
            Assert.True(client.HasVirtualCapability("form_factor"));
            Assert.True(client.HasVirtualCapability("is_app_webview"));
            // this is a static capability, so it shouldn't be returned
            Assert.False(client.HasVirtualCapability("brand_name"));
            Assert.False(client.HasVirtualCapability("is_wireless_device"));
        }
Exemple #12
0
        public void internalTestLookupUserAgent(WmClient client)
        {
            var ua       = "Mozilla/5.0 (Linux; Android 7.0; SAMSUNG SM-G950F Build/NRD90M) AppleWebKit/537.36 (KHTML, like Gecko) SamsungBrowser/5.2 Chrome/51.0.2704.106 Mobile Safari/537.36";
            var jsonData = client.LookupUserAgent(ua);

            Assert.NotNull(jsonData);
            var did = jsonData.Capabilities;

            Assert.NotNull(did);
            Assert.True(did.Count >= 40); // sum of caps, vcaps and 1 wurfl_id. 40 is the size of minimum capability set
            Assert.AreEqual(did["model_name"], "SM-G950F");
            Assert.AreEqual("false", did["is_app"]);
            Assert.AreEqual("false", did["is_app_webview"]);
        }
Exemple #13
0
        public void TestLookupUseragentNullUa()
        {
            WmClient conn = WmClient.Create(serverProtocol, serverIP, serverPort, "");

            try
            {
                JSONDeviceData device = conn.LookupUserAgent(null);
                Assert.NotNull(device);
                var did = device.Capabilities;
                Assert.NotNull(did);
                Assert.NotNull(device.Error);
                // From v 2.1.0 server returns a generic device when queried qith null/empty User-Agent
                Assert.AreEqual("generic", device.Capabilities["wurfl_id"]);
            }
            finally
            {
                conn.DestroyConnection();
            }
        }
Exemple #14
0
        public void TestLookupUseragentEmptyuUa()
        {
            WmClient conn = WmClient.Create(serverProtocol, serverIP, serverPort, "");

            try
            {
                JSONDeviceData device = conn.LookupUserAgent("");
                Assert.NotNull(device);
                var did = device.Capabilities;
                Assert.NotNull(did);
                Assert.NotNull(device.APIVersion);
                Assert.True(device.Error.Length == 0);
                Assert.AreEqual("generic", device.Capabilities["wurfl_id"]);
            }
            finally
            {
                conn.DestroyConnection();
            }
        }
Exemple #15
0
        public void TestCacheUsage()
        {
            WmClient           client = WmClient.Create(serverProtocol, serverIP, serverPort, "");
            HiPerformanceTimer timer  = new HiPerformanceTimer();
            var userAgentList         = TestData.CreateTestUserAgentList();

            try
            {
                timer.Start();
                foreach (var ua in userAgentList)
                {
                    client.LookupUserAgent(ua);
                }
                timer.Stop();
                // get the total detection time in nanoseconds
                var totalDetectionTime = timer.Duration(true);

                // now enable the cache and fill it
                client.SetCacheSize(10000);
                foreach (var ua in userAgentList)
                {
                    client.LookupUserAgent(ua);
                }

                // Now measure cache usage time
                timer.Start();
                foreach (var ua in userAgentList)
                {
                    client.LookupUserAgent(ua);
                }
                timer.Stop();
                var totalCacheUsageTime = timer.Duration(true);
                var avgDetectionTime    = (double)totalDetectionTime / (double)userAgentList.Length;
                var avgCacheTime        = (double)totalCacheUsageTime / (double)userAgentList.Length;
                // Test passes only if cache performance is at least one order of magnitude faster than detection
                Assert.True(avgDetectionTime > avgCacheTime * 10);
            }
            finally
            {
                client.DestroyConnection();
            }
        }
Exemple #16
0
        public void TestLookupHeadersWithoutHeders()
        {
            WmClient client = WmClient.Create(serverProtocol, serverIP, serverPort, "");

            try
            {
                Assert.NotNull(client);
                JSONDeviceData jsonData = client.LookupHeaders(null);
                Assert.NotNull(jsonData);
                Assert.AreEqual("generic", jsonData.Capabilities["wurfl_id"]);
            }
            catch (WmException e)
            {
                Assert.Fail(e.Message);
            }
            finally
            {
                client.DestroyConnection();
            }
        }
Exemple #17
0
        public void TestLookupUserAgent()
        {
            WmClient client = WmClient.Create(serverProtocol, serverIP, serverPort, "");

            try
            {
                var            ua     = "Mozilla/5.0 (Linux; Android 7.0; SAMSUNG SM-G950F Build/NRD90M) AppleWebKit/537.36 (KHTML, like Gecko) SamsungBrowser/5.2 Chrome/51.0.2704.106 Mobile Safari/537.36";
                JSONDeviceData device = client.LookupUserAgent(ua);
                Assert.NotNull(device);
                int dcount = device.Capabilities.Count;
                Assert.True(dcount >= 40); // sum of caps, vcaps and wurfl_id
                Assert.AreEqual(device.Capabilities["model_name"], "SM-G950F");
                Assert.AreEqual("false", device.Capabilities["is_app"]);
                Assert.AreEqual("false", device.Capabilities["is_app_webview"]);
            }
            finally
            {
                client.DestroyConnection();
            }
        }
Exemple #18
0
        public void TestLookupDeviceId()
        {
            WmClient client = WmClient.Create(serverProtocol, serverIP, serverPort, "");

            try
            {
                Assert.NotNull(client);
                JSONDeviceData jsonData = client.LookupDeviceID("nokia_generic_series40");
                Assert.NotNull(jsonData);
                var did = jsonData.Capabilities;
                Assert.NotNull(did);
                // num caps + num vcaps + wurfl id
                Assert.True(did.Count >= 40);
                Assert.AreEqual("false", did["is_android"]);
                Assert.AreEqual("128", did["resolution_width"]);
            }
            finally
            {
                client.DestroyConnection();
            }
        }
Exemple #19
0
        public void TestGetInfo()
        {
            WmClient client = WmClient.Create(serverProtocol, serverIP, serverPort, "");

            try
            {
                JSONInfoData jsonInfoData = client.GetInfo();
                Assert.NotNull(jsonInfoData);
                Assert.NotNull(jsonInfoData.Wm_version);
                Assert.True(jsonInfoData.Wm_version.Length >= 5);
                Console.WriteLine(string.Format("WM server version #{0} ", jsonInfoData.Wm_version));
                Assert.True(jsonInfoData.Wurfl_info.Length > 0);
                Assert.True(jsonInfoData.Important_headers.Length > 0);
                Assert.True(jsonInfoData.Static_caps.Length > 0);
                Assert.True(jsonInfoData.Virtual_caps.Length > 0);
            }
            finally
            {
                client.DestroyConnection();
            }
        }
Exemple #20
0
        public void TestLookupHeadersWithEmptyHeaders()
        {
            WmClient client = WmClient.Create(serverProtocol, serverIP, serverPort, "");

            try
            {
                Assert.NotNull(client);
                JSONDeviceData jsonData = client.LookupHeaders(new Dictionary <string, string>());
                Assert.NotNull(jsonData);
                Assert.AreEqual("generic", jsonData.Capabilities["wurfl_id"]);
            }
            catch (WmException e)
            {
                Assert.NotNull(e.Message);
                Assert.True(e.Message.Length > 0);
                Assert.True(e.Message.Contains("Headers dictionary cannot be null"));
            }
            finally
            {
                client.DestroyConnection();
            }
        }
Exemple #21
0
        public void TestLookupUserAgentWithSpecificCaps()
        {
            string[] reqCaps = { "brand_name", "model_name", "form_factor", "is_mobile", "is_android", "is_ios", "is_app" };

            WmClient client = WmClient.Create(serverProtocol, serverIP, serverPort, "");

            try
            {
                client.SetRequestedCapabilities(reqCaps);
                var            ua     = "Mozilla/5.0 (Nintendo Switch; WebApplet) AppleWebKit/601.6 (KHTML, like Gecko) NF/4.0.0.5.9 NintendoBrowser/5.1.0.13341";
                JSONDeviceData device = client.LookupUserAgent(ua);
                Assert.NotNull(device);
                Assert.NotNull(device.Capabilities);
                Assert.AreEqual("Nintendo", device.Capabilities["brand_name"]);
                Assert.AreEqual("Switch", device.Capabilities["model_name"]);
                Assert.AreEqual("true", device.Capabilities["is_mobile"]);
                Assert.AreEqual(8, device.Capabilities.Count);
            }
            finally
            {
                client.DestroyConnection();
            }
        }
Exemple #22
0
        public void TestLookupDeviceIdWithEmptyId()
        {
            WmClient client     = WmClient.Create(serverProtocol, serverIP, serverPort, "");
            bool     excCatched = false;

            try
            {
                Assert.NotNull(client);
                JSONDeviceData jsonData = client.LookupDeviceID("");
            }
            catch (WmException e)
            {
                excCatched = true;
                Assert.NotNull(e.Message);
                Assert.True(e.Message.Length > 0);
                Assert.True(e.Message.Contains("device is missing"));
            }
            finally
            {
                client.DestroyConnection();
            }
            Assert.True(excCatched);
        }
Exemple #23
0
        public void TestLookupDeviceIdWithSpecificCaps()
        {
            WmClient client = WmClient.Create(serverProtocol, serverIP, serverPort, "");

            try
            {
                String[] reqCaps  = { "brand_name", "is_smarttv" };
                String[] reqvCaps = { "is_app", "is_app_webview" };
                client.SetRequestedStaticCapabilities(reqCaps);
                client.SetRequestedVirtualCapabilities(reqvCaps);
                Assert.NotNull(client);
                JSONDeviceData jsonData = client.LookupDeviceID("generic_opera_mini_version1");
                Assert.NotNull(jsonData);
                var did = jsonData.Capabilities;
                Assert.NotNull(did);
                Assert.AreEqual("Opera", did["brand_name"]);
                Assert.AreEqual("false", did["is_app"]);
                Assert.AreEqual(5, did.Count);
            }
            finally
            {
                client.DestroyConnection();
            }
        }
        static void Main(string[] args)
        {
            try
            {
                // First we need to create a WM client instance, to connect to our WM server API at the specified host and port.
                // Last parameter is a prefix for path, most of the time we won't need it
                WmClient client = WmClient.Create("http", "localhost", "80", "");

                if (client != null)
                {
                    // enable cache: by setting the cache size we are also activating the caching option in WM client.
                    // In order to not use cache, you just to need to omit setCacheSize call
                    client.SetCacheSize(100000);

                    // We ask Wm server API for some Wm server info such as server API version and info about WURFL API and file used by WM server.
                    JSONInfoData info = client.GetInfo();
                    Console.WriteLine("Server info: \n");
                    Console.WriteLine("WURFL API version: " + info.Wurfl_api_version);
                    Console.WriteLine("WM server version: " + info.Wm_version);
                    Console.WriteLine("WURFL file info:" + info.Wurfl_info + '\n');

                    var requestedStaticCaps = new string[] {
                        "brand_name",
                        "model_name"
                    };
                    var requestedVirtualCapabilities = new string[] {
                        "is_smartphone",
                        "form_factor"
                    };
                    // set the capabilities we want to receive from WM server
                    client.SetRequestedStaticCapabilities(requestedStaticCaps);
                    client.SetRequestedVirtualCapabilities(requestedVirtualCapabilities);

                    //var ua = "UCWEB/2.0 (Java; U; MIDP-2.0; Nokia203/20.37) U2/1.0.0 UCBrowser/8.7.0.218 U2/1.0.0 Mobile";
                    //Console.WriteLine("Device lookup for user-agent: " + ua);
                    // Perform a device detection calling WM server API passing the user-agent
                    // JSONDeviceData device = client.LookupUserAgent(ua);

                    var headers = new Dictionary <String, String>();
                    headers.Add("Content-Type", "application/json");
                    headers.Add("Accept-Encoding", "gzip, deflate");
                    headers.Add("Accept-Language", "en");
                    headers.Add("Referer", "https://www.cram.com/flashcards/labor-and-delivery-questions-889210");
                    headers.Add("User-Agent", "Opera/9.80 (Android; Opera Mini/51.0.2254/184.121; U; en) Presto/2.12.423 Version/12.16");
                    headers.Add("X-Clacks-Overhead", "GNU ph");
                    headers.Add("X-Forwarded-For", "110.54.224.195, 82.145.210.235");
                    headers.Add("X-Operamini-Features", "advanced, camera, download, file_system, folding, httpping, pingback, routing, touch, viewport");
                    headers.Add("X-Operamini-Phone", "Android #");
                    headers.Add("X-Operamini-Phone-Ua", "Mozilla/5.0 (Linux; Android 8.1.0; SM-J610G Build/M1AJQ; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/69.0.3497.100 Mobile Safari/537.36");
                    headers.Add("Accept", "text/html, application/xml;q=0.9, application/xhtml+xml, image/png, image/webp, image/jpeg, image/gif, image/x-xbitmap, */*;q=0.1");
                    headers.Add("Device-Stock-Ua", "Mozilla/5.0 (Linux; Android 8.1.0; SM-J610G Build/M1AJQ; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/69.0.3497.100 Mobile Safari/537.36");
                    headers.Add("Forwarded", "for=\"110.54.224.195:36350\"");

                    // Perform a device detection calling WM server API passing the whole request headers
                    JSONDeviceData device = client.LookupHeaders(headers);

                    // Let's get the device capabilities and print some of them
                    Console.WriteLine("Detected device WURFL ID: " + device.Capabilities["wurfl_id"]);
                    Console.WriteLine("Detected device brand & model: " + device.Capabilities["brand_name"]
                                      + " " + device.Capabilities["model_name"]);
                    Console.WriteLine("Detected device form factor: " + device.Capabilities["form_factor"]);
                    if (device.Capabilities["is_smartphone"].Equals("true"))
                    {
                        Console.WriteLine("This is a smartphone");
                    }

                    // Now let's print all the device capabilities
                    DumpDevice(device);

                    // Get all the device manufacturers, and print the first twenty
                    int      limit       = 20;
                    String[] deviceMakes = client.GetAllDeviceMakes();
                    Console.WriteLine(String.Format("Print the first {0} Brand of {1}\n", limit, deviceMakes.Length));

                    // Sort the device manufacturer names
                    Array.Sort(deviceMakes);
                    for (int i = 0; i < limit; i++)
                    {
                        Console.WriteLine(String.Format(" - {0}\n", deviceMakes[i]));
                    }

                    // Now call the WM server to get all device model and marketing names produced by Apple
                    Console.WriteLine("Print all Model for the Apple Brand");
                    JSONModelMktName[] devNames = client.GetAllDevicesForMake("Apple");

                    // Sort ModelMktName objects by their model name (a specific comparer is used)
                    Array.Sort(devNames, new ByModelNameComparer());
                    foreach (JSONModelMktName modelMktName in devNames)
                    {
                        Console.WriteLine(" - {0} {1}\n", modelMktName.Model_Name, modelMktName.Marketing_Name);
                    }

                    // Now call the WM server to get all operative system names
                    Console.WriteLine("Print the list of OSes");
                    String[] oses = client.GetAllOSes();
                    // Sort and print all OS names
                    Array.Sort(oses);
                    foreach (String os in oses)
                    {
                        Console.WriteLine(String.Format(" - {0}\n", os));
                    }
                    // Let's call the WM server to get all version of the Android OS
                    Console.WriteLine("Print all versions for the Android OS");
                    String[] osVersions = client.GetAllVersionsForOS("Android");
                    // Sort all Android version numbers and print them.
                    Array.Sort(osVersions);
                    foreach (String ver in osVersions)
                    {
                        Console.WriteLine(" - {0}\n", ver);
                    }
                }
                else
                {
                    Console.WriteLine("WmClient instance is null");
                }
                // Deallocate all client resources. Any call on client method after this one will throw a WmException
                client.DestroyConnection();
            }
            catch (WmException e)
            {
                // problems such as network errors  or internal server problems
                Console.WriteLine(e.Message);
            }

            finally
            {
                Console.Write("Press a key...");
                Console.ReadKey();
            }
        }
Exemple #25
0
 public LookupUserAgent(WmClient client, int idx, String[] userAgents)
 {
     this.client      = client;
     this.threadIndex = idx;
     this.userAgents  = userAgents;
 }
Exemple #26
0
 public void TestCreateWithEmptyServerValues()
 {
     Assert.Throws <WmException>(() => WmClient.Create("", "", "", ""));
 }
Exemple #27
0
 public void TestCreateWithServerDown()
 {
     Assert.Throws <WmException>(() => WmClient.Create(serverProtocol, serverIP, "18080", ""));
 }
Exemple #28
0
 public void TestCreateWithWrongSchemeValue()
 {
     Assert.Throws <WmException>(() => WmClient.Create("smtp", serverIP, "18080", ""));
 }
Exemple #29
0
 public CrawlerService()
 {
     _httpClient = new WmClient();
 }
Exemple #30
0
 public void TestCreateWithoutHost()
 {
     Assert.Throws <WmException>(() => WmClient.Create(serverProtocol, "", serverPort, ""));
 }