Beispiel #1
0
        public async Task <string> Paste(PasteBinEntry entry)
        {
            if (entry == null)
            {
                throw new ArgumentNullException(nameof(entry));
            }
            if (string.IsNullOrEmpty(entry.Text))
            {
                throw new ArgumentException("The paste text must be set", nameof(entry));
            }

            IList <KeyValuePair <string, string> > content = new List <KeyValuePair <string, string> >
            {
                new KeyValuePair <string, string>(ApiParameters.DevKey, Config.PastebinApiKey),
                new KeyValuePair <string, string>(ApiParameters.Option, "paste"),
                new KeyValuePair <string, string>(ApiParameters.PasteCode, entry.Text)
            };

            SetIfNotEmpty(content, ApiParameters.PasteName, entry.Title);
            SetIfNotEmpty(content, ApiParameters.PasteFormat, entry.Format);
            SetIfNotEmpty(content, ApiParameters.PastePrivate, entry.Private ? "1" : "0");
            SetIfNotEmpty(content, ApiParameters.PasteExpireDate, FormatExpireDate(entry.Expiration));
            SetIfNotEmpty(content, ApiParameters.UserKey, _apiUserKey);

            FormUrlEncodedContent request = new FormUrlEncodedContent(content);

            HttpResponseMessage responce = await HttpClient.PostAsync(ApiPostUrl, request);

            return(await ParseResponce(responce));
        }
Beispiel #2
0
        public async Task<string> Paste(PasteBinEntry entry)
        {
            if (entry == null)
                throw new ArgumentNullException(nameof(entry));
            if (string.IsNullOrEmpty(entry.Text))
                throw new ArgumentException("The paste text must be set", nameof(entry));

            IList<KeyValuePair<string, string>> content = new List<KeyValuePair<string, string>>
            {
                new KeyValuePair<string, string>(ApiParameters.DevKey, Config.PastebinApiKey),
                new KeyValuePair<string, string>(ApiParameters.Option, "paste"),
                new KeyValuePair<string, string>(ApiParameters.PasteCode, entry.Text)
            };

            SetIfNotEmpty(content, ApiParameters.PasteName, entry.Title);
            SetIfNotEmpty(content, ApiParameters.PasteFormat, entry.Format);
            SetIfNotEmpty(content, ApiParameters.PastePrivate, entry.Private ? "1" : "0");
            SetIfNotEmpty(content, ApiParameters.PasteExpireDate, FormatExpireDate(entry.Expiration));
            SetIfNotEmpty(content, ApiParameters.UserKey, _apiUserKey);

            FormUrlEncodedContent request = new FormUrlEncodedContent(content);

            HttpResponseMessage responce = await HttpClient.PostAsync(ApiPostUrl, request);
            return await ParseResponce(responce);
        }
        private string UploadToPasteBin(string title, string text, PasteBinExpiration expiration, bool isPrivate, string format)
        {
            var client = new PasteBinClient(Strings.PasteBin.DevKey);

            try
            {
                client.Login(Strings.PasteBin.Username, Strings.PasteBin.Password);
            }
            catch (Exception ex)
            {
                Logger.Error(ex);
            }

            var entry = new PasteBinEntry
            {
                Title      = title,
                Text       = text,
                Expiration = expiration,
                Private    = isPrivate,
                Format     = format
            };

            try
            {
                return(client.Paste(entry));
            }
            catch (Exception ex)
            {
                Logger.Error(ex);
                MsgBox.Error(StringLoader.GetText("exception_log_file_failed"));
            }
            finally
            {
                client.Logout();
            }

            return(null);
        }
Beispiel #4
0
        //generate error report button
        private void button1_Click(object sender, EventArgs e)
        {
            //generate report button
            if (loglabel.Text == "(Logging is not enabled)")
            {
                MessageBox.Show("Cannot proceed, logging needs to be enabled!",
                                "LS2008 Toolkit",
                                MessageBoxButtons.OK,
                                MessageBoxIcon.Error);
                return;
            }

            if (Tmod.Text == "")
            {
                MessageBox.Show("Cannot proceed, mod name is empty!",
                                "LS2008 Toolkit",
                                MessageBoxButtons.OK,
                                MessageBoxIcon.Error);
                return;
            }

            if (Tuser.Text == "")
            {
                MessageBox.Show("Cannot proceed, Discord nickname is empty!",
                                "LS2008 Toolkit",
                                MessageBoxButtons.OK,
                                MessageBoxIcon.Error);
                return;
            }

            if (Tproblem.Text == "")
            {
                MessageBox.Show("Cannot proceed, problem overview is empty!",
                                "LS2008 Toolkit",
                                MessageBoxButtons.OK,
                                MessageBoxIcon.Error);
                return;
            }

            //creating the text output for pastebin and the file output
            string logoutput, modLink, fileOutput, fileName = "";

            logoutput = "";

            if (Tlink.Text == "")
            {
                modLink = "";
            }
            else
            {
                modLink = "\r\nLink to the mod: " + Tlink.Text;
            }
            try
            {
                logoutput = System.IO.File.ReadAllText(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "/FarmingSimulator2008/output.log");
            }
            catch (Exception exc)
            {
                MessageBox.Show("Cannot proceed with sending the error report as an error happened during reading the output.log.. Maybe you haven't run the game since this has been enabled?\nPossible solution: Open the game, wait until the problem happens and close it.\n\n" + exc.Message,
                                "LS2008 Toolkit",
                                MessageBoxButtons.OK,
                                MessageBoxIcon.Error);
            }

            fileName   = "LS2008 Error Report - " + Tuser.Text;
            fileOutput = "Error report by: " + Tuser.Text + "\r\nProblem with: " + Tmod.Text + modLink + "\r\nProblem overview: " + Tproblem.Text + "\r\n\r\n--------------------------\r\n     GAME LOG OUTPUT     \r\n--------------------------\r\n" + logoutput;

            DialogResult question = MessageBox.Show("Do you want to send the log to pastebin or to save it to a file?\n\nSelect Yes for PasteBin, No for local file and cancel to cancel sending a error report.",
                                                    "LS2008 Toolkit",
                                                    MessageBoxButtons.YesNoCancel,
                                                    MessageBoxIcon.Question);

            if (question == DialogResult.Yes)
            {
                var client = new PasteBinClient("axbfYcaOMTKf4ZjTmow_zxi6n5-Bg2Mv");
                client.Login("LSToolkit", "<redacted>");

                var entry = new PasteBinEntry
                {
                    Title      = fileName,
                    Text       = fileOutput,
                    Expiration = PasteBinExpiration.Never,
                    Private    = false
                };

                string pasteUrl = client.Paste(entry);

                try
                {
                    System.Diagnostics.Process.Start(pasteUrl);
                }
                catch (Exception exc)
                {
                    MessageBox.Show("An error happened during opening the pastebin log.. \n\n" + exc.Message,
                                    "LS2008 Toolkit",
                                    MessageBoxButtons.OK,
                                    MessageBoxIcon.Error);
                }
            }
            else if (question == DialogResult.No)
            {
                SaveFileDialog saveFile = new SaveFileDialog()
                {
                    AddExtension     = true,
                    FileName         = fileName,
                    InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Desktop),
                    RestoreDirectory = true,
                    OverwritePrompt  = true,
                    Title            = "Select a folder to save the log",
                    Filter           = "Log files|*.log",
                    DefaultExt       = "log"
                };

                if (saveFile.ShowDialog() == DialogResult.OK)
                {
                    StreamWriter writer = new StreamWriter(saveFile.OpenFile());
                    writer.WriteLine(fileOutput);
                    writer.Dispose();
                    writer.Close();
                }
            }
            else
            {
                //user clicked the cancel button, canceling the operation
                return;
            }
        }