예제 #1
0
 /// <summary>
 /// Sets the text asynchronous.
 /// </summary>
 /// <param name="text">The text.</param>
 /// <returns>Task.</returns>
 public async Task SetTextAsync(string text)
 {
     if (PreventMultiLineText)
     {
         text = CleanupCarriageReturns(text);
     }
     await clipboard.SetTextAsync(text);
 }
        private async void OpenInNavigationAppExecuted(string fromOrToPortal)
        {
            if (IsBusy)
            {
                return;
            }

            LoggingService.Trace("Executing MarkerAssignmentDialogViewModel.OpenInNavigationAppCommand");

            IsBusy = true;

            if (MarkerAssignment?.Portal == null)
            {
                return;
            }

            try
            {
                if (MarkerAssignment.Portal == null)
                {
                    return;
                }

                var    culture     = CultureInfo.GetCultureInfo("en-US");
                string coordinates = $"{MarkerAssignment.Portal.Lat},{MarkerAssignment.Portal.Lng}";

                double.TryParse(MarkerAssignment.Portal.Lat, NumberStyles.Float, culture, out var lat);
                double.TryParse(MarkerAssignment.Portal.Lng, NumberStyles.Float, culture, out var lng);

                Location location = new Location(lat, lng);

                if (coordinates.IsNullOrEmpty() is false)
                {
                    await _clipboard.SetTextAsync(coordinates);

                    if (_clipboard.HasText)
                    {
                        _userDialogs.Toast("Coordinates copied to clipboartd.");
                    }
                }

                await _map.OpenAsync(location);
            }
            catch (Exception e)
            {
                LoggingService.Error(e, "Error Executing MarkerAssignmentDialogViewModel.OpenInNavigationAppCommand");
            }
            finally
            {
                IsBusy = false;
            }
        }
예제 #3
0
 public Task SetTextAsync(string text) => _clipboard.SetTextAsync(text);
예제 #4
0
        private async void OpenInNavigationAppExecuted(string fromOrToPortal)
        {
            if (IsBusy)
            {
                return;
            }

            LoggingService.Trace("Executing LinkAssignmentDialogViewModel.OpenInNavigationAppCommand");

            IsBusy = true;

            if (LinkAssignment == null)
            {
                return;
            }

            try
            {
                var      culture = CultureInfo.GetCultureInfo("en-US");
                string   coordinates;
                Location location;

                switch (fromOrToPortal)
                {
                case "From":
                    if (LinkAssignment.FromPortal == null)
                    {
                        return;
                    }

                    coordinates = $"{LinkAssignment.FromPortal.Lat},{LinkAssignment.FromPortal.Lng}";

                    double.TryParse(LinkAssignment.FromPortal.Lat, NumberStyles.Float, culture, out var fromLat);
                    double.TryParse(LinkAssignment.FromPortal.Lng, NumberStyles.Float, culture, out var fromLng);

                    location = new Location(fromLat, fromLng);
                    break;

                case "To":
                    if (LinkAssignment.ToPortal == null)
                    {
                        return;
                    }

                    coordinates = $"{LinkAssignment.ToPortal.Lat},{LinkAssignment.ToPortal.Lng}";

                    double.TryParse(LinkAssignment.ToPortal.Lat, NumberStyles.Float, culture, out var toLat);
                    double.TryParse(LinkAssignment.ToPortal.Lng, NumberStyles.Float, culture, out var toLng);

                    location = new Location(toLat, toLng);
                    break;

                default:
                    throw new ArgumentOutOfRangeException(nameof(fromOrToPortal), fromOrToPortal,
                                                          "Incorrect value");
                }

                if (coordinates.IsNullOrEmpty() is false)
                {
                    await _clipboard.SetTextAsync(coordinates);

                    if (_clipboard.HasText)
                    {
                        _userDialogs.Toast("Coordinates copied to clipboartd.");
                    }
                }

                await _map.OpenAsync(location);
            }
            catch (Exception e)
            {
                LoggingService.Error(e, "Error Executing LinkAssignmentDialogViewModel.OpenInNavigationAppCommand");
            }
            finally
            {
                IsBusy = false;
            }
        }
예제 #5
0
 public Task SetTextAsync(string text, CancellationToken cancellation = default)
 {
     Check();
     return(clipboard.SetTextAsync(text, cancellation));
 }
        protected override async Task ExecuteAsync(CancellationToken stoppingToken)
        {
            Console.WriteLine();
            Console.WriteAscii("Token Generation Started...", Colorful.FigletFont.Default);
            Console.WriteLine();

            if (_hostOptions.Verbose)
            {
                Console.WriteLine($"{nameof(HttpServer)} is starting.");
            }

            var http        = new HttpListener();
            var redirectURI = string.Format("http://{0}:{1}/", "localhost", GetRandomUnusedPort());

            http.Prefixes.Add(redirectURI);
            http.Start();

            var authUrl = GetAuthorizationUrl(redirectURI);

            if (_hostOptions.Verbose)
            {
                Console.WriteLine($"Opening a browser window with Url: {authUrl}", Color.Blue);
            }

            var process = ConsoleHandler.OpenBrowser(authUrl);

            var context = await http.GetContextAsync();

            while (!stoppingToken.IsCancellationRequested)
            {
                if (_isCompleted)
                {
                    _applicationLifetime.StopApplication();
                    return;
                }

                if (_hostOptions.Verbose)
                {
                    Console.WriteLine($"{nameof(HttpServer)} is running");
                }

                if (context != null)
                {
                    var responseOutput = await ShowBrowserMessage(context);

                    responseOutput.Close();

                    if (context.Request.QueryString.Get("error") != null)
                    {
                        Console.WriteLine($"OAuth authorization error: {context.Request.QueryString.Get("error")}.", Color.Red);
                    }

                    if (context.Request.QueryString.Get("code") == null)
                    {
                        Console.WriteLine($"Malformed authorization response {context.Request.QueryString}", Color.Red);
                    }

                    // Authorization code the consumer must use to obtain the access and refresh tokens.
                    // The authorization code expires after 15 minutes.
                    var code = context.Request.QueryString.Get("code");
                    Console.WriteLine($"The authorization code will expire in 15 minutes: {code}", Color.Blue);

                    var auth = new AuthenticationClient();
                    await auth.WebServerAsync(
                        _config.ClientId,
                        _config.ClientSecret,
                        redirectURI,
                        code,
                        $"{_config.LoginUrl}{_config.OAuthUri}");

                    Console.WriteLineFormatted("Access_token = {0}", Color.Green, Color.Yellow, auth.AccessInfo.AccessToken);

                    Console.WriteLineFormatted("Refresh_token = {0}", Color.Green, Color.Yellow, auth.AccessInfo.RefreshToken);

                    await _clipboard.SetTextAsync(auth.AccessInfo.RefreshToken);

                    Console.WriteLine($"Refresh_token copied to the Clipboard", color: Color.Yellow);

                    _isCompleted = true;

                    http.Stop();
                    if (_hostOptions.Verbose)
                    {
                        Console.WriteLine($"{nameof(HttpServer)} is stopping.");
                    }
                }

                await Task.Delay(TimeSpan.FromSeconds(5), stoppingToken);

                Console.WriteLine();
                Console.Write("Thanks for using this cli tool");
            }
        }
예제 #7
0
 public Task SetTextAsync(string text)
 {
     return(clipboard.SetTextAsync(text));
 }