Exemplo n.º 1
0
        private void GenerateHashBt_Click(object sender, RoutedEventArgs e)
        {
            //TODO: Move to model
            var hash =
                string.IsNullOrWhiteSpace(usersWindow.HasherPB.Password)
                ? string.Empty
                : Hasher.GetHash(usersWindow.HasherPB.Password);
            var cb = new TextCopy.Clipboard();

            cb.SetText(hash);
            usersWindow.ConfirmPU.IsOpen = true;
        }
Exemplo n.º 2
0
        private static void HandleInput(string cmd)
        {
            switch (cmd)
            {
            case "clear":
                Console.Clear();
                break;

            case "ip":
                Console.WriteLine(ip);
                break;

            case "players":
                if (GameManager.players.Count > 0)
                {
                    Console.WriteLine("Connected players:");
                    foreach (Player player in GameManager.players.Values)
                    {
                        Console.WriteLine($"{player.username}:{player.id}");
                    }
                }
                else
                {
                    Console.WriteLine("No players online");
                }
                break;

            case "getip":
                try
                {
                    TextCopy.Clipboard clipboard = new TextCopy.Clipboard();
                    clipboard.SetText(ip);
                    Console.WriteLine("Copied the ip to your clipboard");
                }
                catch (Exception e)
                {
                    Debug.LogError("Failed to copy ip to your clipboard: " + e.Message);
                }

                break;

            case "exit":
                running = false;
                break;

            default:
                Console.WriteLine("Command not found");
                break;
            }
        }
 public void CauseExceptionAndCopyToClipboard()
 {
     try
     {
         CallMethod1();
     }
     catch (Exception e)
     {
         var clipboard = new TextCopy.Clipboard();
         clipboard.SetText("An error occurred while running the test" + Environment.NewLine + Environment.NewLine + e);
         Console.WriteLine("Exception copied to clipboard");
         throw;
     }
 }
Exemplo n.º 4
0
        static async Task Main(string[] args)
        {
            using (var client = new HttpClient())
            {
                //var baseUrl = "https://sandbox-api-pay.line.me";
                var baseUrl       = "https://api-pay.line.me";
                var requestUrl    = "/v3/payments/request";
                var channelId     = "1653957456";
                var channelSecret = "c35bfea4d5ae857d9f1c15614c48e935";
                var nonce         = Guid.NewGuid().ToString();
                var product       = new PaymentRequest {
                    Amount   = 0.02,
                    Currency = "THB",
                    OrderId  = Guid.NewGuid().ToString(),
                    Packages = new Package[]
                    {
                        new Package
                        {
                            Id       = "1",
                            Amount   = 0.02,
                            Products = new Product[]
                            {
                                new Product
                                {
                                    Id       = "PENB001",
                                    Name     = "Pen Brown",
                                    ImageUrl = "https://droidsans.com/wp-content/uploads/2020/01/line4.jpg",
                                    Price    = 0.01,
                                    Quantity = 2
                                }
                            }
                        }
                    },
                    RedirectUrls = new RedirectUrl
                    {
                        ConfirmUrlType = "SERVER",
                        ConfirmUrl     = "https://linepaymentapi.herokuapp.com/api/payment/authorize",
                        CancelUrl      = "https://pay-store.line.com/order/payment/cancel"
                    }
                };

                var payload = JsonSerializer.Serialize(product, new JsonSerializerOptions
                {
                    PropertyNamingPolicy = JsonNamingPolicy.CamelCase,
                });
                var data     = channelSecret + requestUrl + payload + nonce;
                var hashHMAC = HashHMAC(channelSecret, data);

                client.DefaultRequestHeaders.Add("X-LINE-ChannelId", channelId);
                client.DefaultRequestHeaders.Add("X-LINE-Authorization-Nonce", nonce);
                client.DefaultRequestHeaders.Add("X-LINE-Authorization", Convert.ToBase64String(hashHMAC));

                var stringContent = new StringContent(payload, Encoding.UTF8, "application/json");
                var res           = await client.PostAsync(baseUrl + requestUrl, stringContent);

                var payment = JsonSerializer.Deserialize <PaymentResponse>(await res.Content.ReadAsStringAsync(), new JsonSerializerOptions
                {
                    PropertyNamingPolicy = JsonNamingPolicy.CamelCase,
                });
                var cb = new TextCopy.Clipboard();
                cb.SetText($"https://chart.apis.google.com/chart?cht=qr&chs=500x500&chl={payment.Info.PaymentUrl.App}");
                Console.WriteLine(payment.Info.PaymentUrl.App);
            }
        }
        /// <summary>
        /// Converts a file to a Base64 string and copies either the compressed or decompressed versions to the clipboard.
        /// </summary>
        /// <returns>Returns true if the console app should exit after this method completes.</returns>
        public static bool FileToBase64()
        {
            var exitApp  = false;
            var filePath = string.Empty;

            while (true)
            {
                ConsoleWriter.Info("Enter the full directory path and file name for the file you wish to convert to a Base64 string.");

                filePath = Console.ReadLine();

                if (string.IsNullOrWhiteSpace(filePath) || !File.Exists(filePath))
                {
                    ConsoleWriter.Error("File path was invalid.");
                    ConsoleWriter.Line();
                }
                else
                {
                    break;
                }
            }

            ConsoleWriter.Line();
            ConsoleWriter.Line();

            var bytes        = File.ReadAllBytes(filePath);
            var base64String = Convert.ToBase64String(bytes);

            ConsoleWriter.Success("File has been converted!");
            ConsoleWriter.Line();

            ConsoleWriter.Info("Press 'c' to copy the raw, decompressed Base64 string to clipboard.");
            ConsoleWriter.Info("Press 'v' to copy the compressed (deflated) Base64 string to clipboard.");
            ConsoleWriter.Info("Press 'Enter' to clear the current file and start over.");
            ConsoleWriter.Info("Press 'Escape' to exit.");

            // Prompt for the user's next action.
            while (true)
            {
                var key = Console.ReadKey();
                ConsoleWriter.Line();

                if (key.Key == ConsoleKey.C)
                {
                    var clipboard = new TextCopy.Clipboard();
                    clipboard.SetText(base64String);

                    ConsoleWriter.Line();
                    ConsoleWriter.Success("Decompressed Base64 file contents copied to clipboard.");
                }
                else if (key.Key == ConsoleKey.V)
                {
                    var compressedBytes        = Utilities.Compress(bytes);
                    var compressedBase64String = Convert.ToBase64String(compressedBytes);

                    var clipboard = new TextCopy.Clipboard();
                    clipboard.SetText(compressedBase64String);

                    ConsoleWriter.Line();
                    ConsoleWriter.Success("Compressed (deflated) Base64 file contents copied to clipboard.");
                }
                else if (key.Key == ConsoleKey.Enter)
                {
                    // Clear and repeat.
                    Console.Clear();
                    break;
                }
                else if (key.Key == ConsoleKey.Escape)
                {
                    exitApp = true;
                    break;
                }
                else
                {
                    ConsoleWriter.Warning("Unrecognized input.");
                }
            }

            return(exitApp);
        }