예제 #1
0
        public void DisplayUnitsTest()
        {
            string       fileName = "displayUnitsTest.json";
            JSONExporter exporter = new JSONExporter(fileName, "myProcess.exe");

            exporter.Initialize();

            for (int i = 0; i < 20; i++)
            {
                exporter.CounterPayloadReceived("myProvider", TestHelpers.GenerateCounterPayload(false, "heapSize", (double)i, 0, "Heap Size", "MB"), false);
            }
            exporter.Stop();

            Assert.True(File.Exists(fileName));
            using (StreamReader r = new StreamReader(fileName))
            {
                string           json         = r.ReadToEnd();
                JSONCounterTrace counterTrace = JsonConvert.DeserializeObject <JSONCounterTrace>(json);
                Assert.Equal("myProcess.exe", counterTrace.targetProcess);
                Assert.Equal(20, counterTrace.events.Length);
                var i = 0;
                foreach (JSONCounterPayload payload in counterTrace.events)
                {
                    Assert.Equal("myProvider", payload.provider);
                    Assert.Equal("Heap Size (MB)", payload.name);
                    Assert.Equal(i, payload.value);
                    i += 1;
                }
            }
        }
예제 #2
0
        public void CounterTest()
        {
            string       fileName = "CounterTest.json";
            JSONExporter exporter = new JSONExporter(fileName, "myProcess.exe");

            exporter.Initialize();
            for (int i = 0; i < 10; i++)
            {
                exporter.CounterPayloadReceived("myProvider", TestHelpers.GenerateCounterPayload(false, "counterOne", 1.0, 1, "Counter One"), false);
            }
            exporter.Stop();

            Assert.True(File.Exists(fileName));
            using (StreamReader r = new StreamReader(fileName))
            {
                string           json         = r.ReadToEnd();
                JSONCounterTrace counterTrace = JsonConvert.DeserializeObject <JSONCounterTrace>(json);

                Assert.Equal("myProcess.exe", counterTrace.targetProcess);
                Assert.Equal(10, counterTrace.events.Length);
                foreach (JSONCounterPayload payload in counterTrace.events)
                {
                    Assert.Equal("myProvider", payload.provider);
                    Assert.Equal("Counter One", payload.name);
                    Assert.Equal("Metric", payload.counterType);
                    Assert.Equal(1.0, payload.value);
                }
            }
        }
예제 #3
0
        public void PercentilesTest()
        {
            string       fileName = "PercentilesTest.json";
            JSONExporter exporter = new JSONExporter(fileName, "myProcess.exe");

            exporter.Initialize();
            DateTime start = DateTime.Now;

            for (int i = 0; i < 10; i++)
            {
                exporter.CounterPayloadReceived(new PercentilePayload("myProvider", "counterOne", "Counter One", "", "f=abc,Percentile=50", 1, start + TimeSpan.FromSeconds(i)), false);
            }
            exporter.Stop();

            Assert.True(File.Exists(fileName));
            using (StreamReader r = new StreamReader(fileName))
            {
                string           json         = r.ReadToEnd();
                JSONCounterTrace counterTrace = JsonConvert.DeserializeObject <JSONCounterTrace>(json);

                Assert.Equal("myProcess.exe", counterTrace.targetProcess);
                Assert.Equal(10, counterTrace.events.Length);
                foreach (JSONCounterPayload payload in counterTrace.events)
                {
                    Assert.Equal("myProvider", payload.provider);
                    Assert.Equal("Counter One", payload.name);
                    Assert.Equal("Metric", payload.counterType);
                    Assert.Equal(1.0, payload.value);
                    Assert.Equal("f=abc,Percentile=50", payload.tags);
                }
            }
        }
예제 #4
0
        public void ValidJSONFormatTest()
        {
            // Test if the produced JSON is a valid format.
            // Regression test for https://github.com/dotnet/diagnostics/issues/1020

            string       fileName = "validJSONFormatTest.json";
            JSONExporter exporter = new JSONExporter(fileName, "myProcess.exe");

            exporter.Initialize();

            for (int i = 0; i < 20; i++)
            {
                exporter.CounterPayloadReceived("myProvider", TestHelpers.GenerateCounterPayload(false, "heapSize", 0, 0, "Heap Size", "MB"), false);
            }
            exporter.Stop();

            Assert.True(File.Exists(fileName));
            using (StreamReader r = new StreamReader(fileName))
            {
                string json = r.ReadToEnd();
                // first } from end of the last event payload
                // next ] from closing "Events" field
                // last } from closing the whole JSON
                Assert.EndsWith("0 }]}", json);
            }
        }
예제 #5
0
        static void Main(string[] args)
        {
            string[] keywords = { "game", "browser" };

            string[] fieldNames =
            {
                "Url",                "ScrapedDate",      "Name",              "Developer",        "IsTopDeveloper",   "DeveloperURL",  "PublicationDate",
                "Category",           "IsFree",           "Price",             "CoverImageUrl",    "Description",      "ReviewScore",   "ReviewTotal",
                "FiveStarsReviews",   "FourStarsReviews", "ThreeStarsReviews", "TwoStarsReviews",
                "OneStarReviewCount", "AppSize",          "Installs",          "CurrentVersion",   "MinimumOSVersion", "ContentRating",
                "HaveInAppPurchases", "InAppPriceRange",  "DeveloperEmail",    "DeveloperWebsite", "DeveloperPrivacyPolicy"
            };

            string outputFilePath = @"./result";

            IExporter exporter = null;

            // Export to CSV file.
            // NOTE: You can also implement your own Exporter class.
            // Please see IExporter and CSVExporter class for example.
            exporter = new CSVExporter(outputFilePath + ".csv", fieldNames);

            // Start crawling for the keywords with maximum 30 Apps result and download delay 1 second.
            PlayStoreScraper.Crawl(keywords, exporter, 30, 1000);


            // Same example with exporting to JSON file
            exporter = new JSONExporter(outputFilePath + ".json", fieldNames);
            PlayStoreScraper.Crawl(keywords, exporter, 30, 1000);


            // Same example with callback method
            PlayStoreScraper.Crawl(keywords, null, 30, 1000, appModel =>
            {
                Console.WriteLine("App Name: {0}, App URL: {1}", appModel.Name, appModel.Url);
            });
        }