Exemplo n.º 1
0
        public String UploadFile(String file)
        {
            OctoprintAPI api = new OctoprintAPI();

            api.serverAddress = OctoUploader.Properties.Settings.Default.ServerAddress;
            api.apiKey        = OctoUploader.Properties.Settings.Default.APIKey;

            if (!File.Exists(file))
            {
                return("");
            }

            bool   AutoStart = OctoUploader.Properties.Settings.Default.AutoStart;
            String result    = api.UploadFile(file, AutoStart, AutoStart);

            if (api.lastResultCode == System.Net.HttpStatusCode.Created)
            {
                tbi.ShowBalloonTip("Octoprint Uploader", Path.GetFileName(file) + " uploaded successfully.", BalloonIcon.Info);

                if (OctoUploader.Properties.Settings.Default.DeleteOnUpload)
                {
                    File.Delete(file);
                }
            }
            else
            {
                tbi.ShowBalloonTip("Octoprint Uploader", "Could not upload file. Check your settings and ensure that Octoprint isn't already printing.", BalloonIcon.Error);
            }

            return(result);
        }
Exemplo n.º 2
0
        public String UploadFile(String file)
        {
            var api = new OctoprintAPI
            {
                serverAddress = OctoUploader.Properties.Settings.Default.ServerAddress,
                apiKey        = OctoUploader.Properties.Settings.Default.APIKey
            };

            if (!File.Exists(file))
            {
                return("");
            }

            bool   AutoStart = OctoUploader.Properties.Settings.Default.AutoStart;
            String result    = api.UploadFile(file, AutoStart, AutoStart);

            if (api.lastResultCode == System.Net.HttpStatusCode.Created)
            {
                Log.Information("Successfully uploaded file to {Filename} to {Server}",
                                Path.GetFileName(file),
                                OctoUploader.Properties.Settings.Default.ServerAddress
                                );

                tbi.ShowBalloonTip("Octoprint Uploader", Path.GetFileName(file) + " uploaded successfully.", BalloonIcon.Info);

                if (OctoUploader.Properties.Settings.Default.DeleteOnUpload)
                {
                    File.Delete(file);
                }
            }
            else
            {
                Log.Debug("Failed while uploading file {Filename} to {Server} with {ResultCode}",
                          Path.GetFileName(file),
                          OctoUploader.Properties.Settings.Default.ServerAddress,
                          api.lastResultCode
                          );
                tbi.ShowBalloonTip("Octoprint Uploader", "Could not upload file. Check your settings and ensure that Octoprint isn't already printing.", BalloonIcon.Error);
            }

            return(result);
        }
Exemplo n.º 3
0
        public String UploadFile(String file)
        {
            OctoprintAPI api = new OctoprintAPI();

            api.serverAddress = OctoUploader.Properties.Settings.Default.ServerAddress;
            api.apiKey        = OctoUploader.Properties.Settings.Default.APIKey;

            if (!File.Exists(file))
            {
                return("");
            }

            bool   AutoStart = OctoUploader.Properties.Settings.Default.AutoStart;
            String result    = api.UploadFile(file, AutoStart, AutoStart);

            if (OctoUploader.Properties.Settings.Default.DeleteOnUpload == true && api.lastResultCode == System.Net.HttpStatusCode.Created)
            {
                File.Delete(file);
            }

            return(result);
        }
        private void checkButton_click(object sender, RoutedEventArgs e)
        {
            OctoprintAPI api = new OctoprintAPI();

            api.serverAddress = this.serverAddress.Text;
            api.apiKey        = this.apiKey.Text;

            String version = api.GetVersion();

            switch (api.lastResultCode)
            {
            case System.Net.HttpStatusCode.OK:
                lblWarning.Content = "Successfully connected.";
                break;

            case System.Net.HttpStatusCode.Unauthorized:
                lblWarning.Content = "Invalid API Code.";
                break;

            default:
                lblWarning.Content = "Could not connect.";
                break;
            }
        }