コード例 #1
0
        private void UpdateCredentialsClick(object sender, RoutedEventArgs e)
        {
            var credWindow = new CredentialWindow();

            credWindow.ShowDialog();
        }
コード例 #2
0
        private void UploadClip(string file)
        {
            Dispatcher.Invoke(() => StatusText = "Preparing to upload...");
            if (!CredentialManager.Instance.IsSet)
            {
                Dispatcher.Invoke(() =>
                {
                    var credWindow = new CredentialWindow();
                    credWindow.ShowDialog();
                });
            }

            string username = CredentialManager.Instance.Username;
            string password = CredentialManager.Instance.Password;
            string encoded  = System.Convert.ToBase64String(System.Text.Encoding.GetEncoding("ISO-8859-1").GetBytes(username + ":" + password));

            string url    = "https://api.streamable.com/upload";
            var    client = new RestClient(url);

            client.Timeout = -1;
            var request = new RestRequest(Method.POST);

            request.AddHeader("Authorization", $"Basic {encoded}");
            request.AddFile("file", file);
            string requestBody = "{\"title\": \"" + Path.GetFileNameWithoutExtension(file) + "\"}";

            request.AddParameter("title", Path.GetFileNameWithoutExtension(file));
            Dispatcher.Invoke(() => StatusText = "Uploading");
            IRestResponse response           = client.Execute(request);
            var           streamableResponse = Newtonsoft.Json.JsonConvert.DeserializeObject <StreamableResponse>(response.Content);

            if (!string.IsNullOrEmpty(streamableResponse?.shortcode))
            {
                string link = $"https://streamable.com/{streamableResponse.shortcode}";
                Dispatcher.Invoke(() =>
                {
                    StatusText = $"Done. Link copied to clipboard: {link}";
                    Progress   = 100;
                });

                Dispatcher.Invoke(() => { Clipboard.SetText(link); });
            }
            else
            {
                string errorMessage;
                if (response.StatusCode == 0)
                {
                    errorMessage = "Error - Check Streamable credentials";
                }
                else
                {
                    errorMessage = $"Error - HTTP {response.StatusCode}";
                }

                Dispatcher.Invoke(() =>
                {
                    StatusText = errorMessage;
                    Progress   = 100;
                });
            }

            Console.WriteLine(response.Content);
        }