コード例 #1
0
ファイル: Program.cs プロジェクト: Tuely/PerformanceTest
        static int Main(string[] args)
        {
            if (args.Length < 5 || args.Length > 7)
            {
                return(PrintSyntax());
            }

            int  k    = 0;
            bool init = false;

            if (args[k] == "--init")
            {
                if (args.Length != 7)
                {
                    return(PrintSyntax());
                }
                init = true;
                k++;
            }
            else
            {
                if (args.Length != 5)
                {
                    return(PrintSyntax());
                }
            }

            string executable            = args[k++];
            string arguments             = args[k++];
            string benchmarkContainerUri = ExperimentDefinition.LocalDiskContainerUri;
            string benchmarkDirectory    = args[k++];
            string category  = args[k++];
            string extension = args[k++];

            int    repetitions    = 1;
            double referenceValue = 1.0;

            if (init)
            {
                repetitions = int.Parse(args[k++], CultureInfo.InvariantCulture);
            }

            TimeSpan             timeout    = TimeSpan.FromHours(1);
            ExperimentDefinition definition = ExperimentDefinition.Create(executable, benchmarkContainerUri, benchmarkDirectory, extension, arguments, timeout, TimeSpan.FromSeconds(0), Measurement.Domain.Default.Name, category: category);
            string version = GetVersion(executable);

            if (init)
            {
                Print(String.Format("Initializing environment..."));
            }
            else
            {
                Print(String.Format("Measuring performance of {0} {1}...\n", executable, version));
            }

            IDomainResolver domainResolver = new DomainResolver(new[] { Measurement.Domain.Default });

            if (init)
            {
                var reference             = new ReferenceExperiment(definition, repetitions, referenceValue);
                ExperimentManager manager = LocalExperimentManager.NewExperiments("measure", reference, domainResolver);
            }
            else
            {
                ExperimentManager manager = LocalExperimentManager.OpenExperiments("measure", domainResolver);
                Run(manager, definition).Wait();
            }

            return(0);
        }
コード例 #2
0
 internal ResolutionIterator(DomainResolver resolver, DnsClient.DNS.QTYPE question, Caching.AddressCache addressCache)
     : base(resolver, question, addressCache)
 {
     NestingLevel = 0;
 }
コード例 #3
0
 // sub iterators: Address / CName
 protected ResolutionIterator(DomainResolver resolver, DnsClient.DNS.QTYPE question, Caching.AddressCache addressCache, int nestingLevel)
     : base(resolver, question, addressCache)
 {
     this.NestingLevel = nestingLevel;
 }
コード例 #4
0
 internal ResolutionIterator(DomainResolver resolver, DnsClient.DNS.QTYPE question, Caching.AddressCache addressCache)
     : base(resolver, question, addressCache)
 {
     NestingLevel = 0;
 }
コード例 #5
0
 // sub iterators: Address / CName
 protected ResolutionIterator(DomainResolver resolver, DnsClient.DNS.QTYPE question, Caching.AddressCache addressCache, int nestingLevel)
     : base(resolver, question, addressCache)
 {
     this.NestingLevel = nestingLevel;
 }
コード例 #6
0
        static void Main(string[] args)
        {
            try
            {
                File.Delete(filename);

                bool interactive = false;

                NameServer selected = null;
                while (true)
                {
                    if (File.Exists(filename))
                    {
                        using (DnsUdpClient client = new DnsUdpClient())
                        {
                            client.Client.SetSocketOption(System.Net.Sockets.SocketOptionLevel.Socket, System.Net.Sockets.SocketOptionName.ReceiveTimeout, 1000);

                            client.LogMessageCreated += new LogMessageEventHandler(OnLogMessage);
                            ResolutionIterator iterator = DeSerializeObject <ResolutionIterator>(filename);

                            iterator.Resolver.Connect(client);
                            if (iterator.MoveNext(selected))
                            {
                                Console.WriteLine();

                                ResolutionResult result = iterator.Current;

                                //Console.WriteLine("Response from {0} - chosen from {1} authorities", result.Authorities.Selected.Name, result.Authorities.ZoneName);
                                //foreach (NameServer ns in result.Authorities)
                                //{
                                //  Console.WriteLine("  {0}", ns);
                                //}

                                Console.WriteLine("Took {0}ms:", result.Duration.TotalMilliseconds);
                                RenderResponse(result.Response);

                                if (interactive)
                                {
                                    selected = null;
                                    if (result.NextAuthorities != null)
                                    {
                                        Console.WriteLine();
                                        Console.WriteLine("Next authorities:");
                                        int i = 1;
                                        foreach (NameServer ns in result.NextAuthorities)
                                        {
                                            Console.WriteLine("  ({0}) {1}", i, ns.ToString());
                                            i++;
                                        }

                                        while (true)
                                        {
                                            Console.Write("Select next authority or ENTER for random: ");
                                            int    s;
                                            string choice = Console.ReadLine();
                                            if (!String.IsNullOrEmpty(choice))
                                            {
                                                if (int.TryParse(choice, out s))
                                                {
                                                    if (s >= 1 && s <= result.NextAuthorities.Count)
                                                    {
                                                        selected = result.NextAuthorities[s - 1];
                                                        break;
                                                    }
                                                }
                                            }
                                            else
                                            {
                                                break;
                                            }
                                        }
                                    }
                                }

                                SerializeObject <ResolutionIterator>(filename, iterator);
                                Console.WriteLine("====================================");
                            }
                            else
                            {
                                Console.WriteLine("finished.");
                                File.Delete(filename);
                            }
                        }
                    }
                    else
                    {
                        DnsDomain domain = null;
                        QTYPE     question;

                        try
                        {
                            Console.Write("enter name: ");
                            domain = DnsDomain.Parse(Console.ReadLine().Trim());
                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine(ex.Message);
                            goto next;
                        }

                        try
                        {
                            Console.Write("enter question: ");
                            question = (QTYPE)Enum.Parse(typeof(QTYPE), Console.ReadLine().Trim(), true);
                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine(ex.Message);
                            goto next;
                        }

                        Console.WriteLine("OK: {0} IN {1}", domain, question.ToString());

                        DomainResolver     resolver = new DomainResolver(Options.Default, domain);
                        ResolutionIterator iterator = resolver.GetIterator(question);
                        iterator.LogMessageCreated += new LogMessageEventHandler(OnLogMessage);

                        SerializeObject <ResolutionIterator>(filename, iterator);
                    }

next:
                    Console.WriteLine();
                    Console.WriteLine("type 'q' to quit, ENTER to continue.");
                    ConsoleKeyInfo ck = Console.ReadKey();
                    if (ck.KeyChar == 'q')
                    {
                        break;
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
            }
        }
コード例 #7
0
        /// <inheritdoc cref="IUrlGenerator.GeDefaulttUrl"/>
        public string GetDefaultUrl()
        {
            var domain = DomainResolver.GetDomain();

            return($"{domain}/Nui/ViewModule.aspx");
        }
        // GET: /<controller>/
        public async Task <IActionResult> Index()
        {
            List <TodoItem>      itemList = new List <TodoItem>();
            AuthenticationResult result;

            try
            {
                // Because we signed-in already in the WebApp, the userObjectId is know

                using (var domainResolver = new DomainResolver(HttpContext, _azureAdOptions, _azureAdB2COptions))
                {
                    ViewBag.isB2cUser = domainResolver.isB2cUser;
                    result            = await domainResolver.getAccessTokenAsync();
                }

                // Retrieve the user's To Do List.
                HttpClient         client  = new HttpClient();
                HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Get, _azureAdOptions.TodoListBaseAddress + "/api/todolist");
                request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", result.AccessToken);
                HttpResponseMessage response = await client.SendAsync(request);

                // Return the To Do List in the view.
                if (response.IsSuccessStatusCode)
                {
                    List <Dictionary <String, String> > responseElements = new List <Dictionary <String, String> >();
                    JsonSerializerSettings settings = new JsonSerializerSettings();
                    String responseString           = await response.Content.ReadAsStringAsync();

                    responseElements = JsonConvert.DeserializeObject <List <Dictionary <String, String> > >(responseString, settings);
                    foreach (Dictionary <String, String> responseElement in responseElements)
                    {
                        TodoItem newItem = new TodoItem();
                        newItem.Title = responseElement["title"];
                        newItem.Owner = responseElement["owner"];
                        itemList.Add(newItem);
                    }

                    return(View(itemList));
                }

                //
                // If the call failed with access denied, then drop the current access token from the cache,
                //     and show the user an error indicating they might need to sign-in again.
                //
                if (response.StatusCode == System.Net.HttpStatusCode.Unauthorized)
                {
                    return(Unauthorized());
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.InnerException);
                if (HttpContext.Request.Query["reauth"] == "True")
                {
                    //
                    // Send an OpenID Connect sign-in request to get a new set of tokens.
                    // If the user still has a valid session with Azure AD, they will not be prompted for their credentials.
                    // The OpenID Connect middleware will return to this controller after the sign-in response has been handled.
                    //
                    return(new ChallengeResult(OpenIdConnectDefaults.AuthenticationScheme));
                }
                //
                // The user needs to re-authorize.  Show them a message to that effect.
                //
                TodoItem newItem = new TodoItem();
                newItem.Title = "(Sign-in required to view to do list.)";
                itemList.Add(newItem);
                ViewBag.ErrorMessage = "AuthorizationRequired";
                return(View(itemList));
            }
            //
            // If the call failed for any other reason, show the user an error.
            //
            return(View("Error"));
        }
        public async Task <ActionResult> Index(string item)
        {
            if (ModelState.IsValid)
            {
                //
                // Retrieve the user's tenantID and access token since they are parameters used to call the To Do service.
                //

                List <TodoItem> itemList = new List <TodoItem>();
                try
                {
                    AuthenticationResult result = null;
                    using (var domainResolver = new DomainResolver(HttpContext, _azureAdOptions, _azureAdB2COptions))
                    {
                        ViewBag.isB2cUser = domainResolver.isB2cUser;
                        result            = await domainResolver.getAccessTokenAsync();
                    }

                    // Forms encode todo item, to POST to the todo list web api.
                    HttpContent content = new StringContent(JsonConvert.SerializeObject(new { Title = item }), System.Text.Encoding.UTF8, "application/json");

                    //
                    // Add the item to user's To Do List.
                    //
                    HttpClient         client  = new HttpClient();
                    HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Post, _azureAdOptions.TodoListBaseAddress + "/api/todolist");
                    request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", result.AccessToken);
                    request.Content = content;
                    HttpResponseMessage response = await client.SendAsync(request);

                    //
                    // Return the To Do List in the view.
                    //
                    if (response.IsSuccessStatusCode)
                    {
                        return(RedirectToAction("Index"));
                    }

                    //
                    // If the call failed with access denied, then drop the current access token from the cache,
                    //     and show the user an error indicating they might need to sign-in again.
                    //
                    if (response.StatusCode == System.Net.HttpStatusCode.Unauthorized)
                    {
                        return(Unauthorized());
                    }
                }
                catch (Exception)
                {
                    //
                    // The user needs to re-authorize.  Show them a message to that effect.
                    //
                    TodoItem newItem = new TodoItem();
                    newItem.Title = "(No items in list)";
                    itemList.Add(newItem);
                    ViewBag.ErrorMessage = "AuthorizationRequired";
                    return(View(itemList));
                }
                //
                // If the call failed for any other reason, show the user an error.
                //
                return(View("Error"));
            }
            return(View("Error"));
        }
コード例 #10
0
 internal ResolutionIteratorBase(DomainResolver resolver, DnsClient.DNS.QTYPE question, Caching.AddressCache addressCache)
 {
     _Resolver    = resolver;
     _Question    = question;
     AddressCache = addressCache;
 }