Beispiel #1
0
        public static void DisplayError(string message)
        {
            // Include information for sharing this Error, since Errors are something I'll want to know about and fix but don't want to throw an Exception and hard-stop the application
            const string ERROR_HEADER_OFFLINE = "An error has occurred.  Please post the following information to www.reddit.com/r/ChroniCalc:\r\n\r\n";
            const string ERROR_HEADER_ONLINE  = "An error has occurred.  Would you like to copy the error details link to your clipboard to send it to the developer?\r\n";

            DialogResult   dialogResult;
            string         pasteUrl;
            PasteBinClient client = new PasteBinClient(PasteBinClient.PBType.Error);

            // Post the error to Pastebin and provide the user a link to send instead of asking them to do screenshots
            // Setup the data for the Pastebin  //TODO enhance to include the Build data if it exists?
            var entry = new PasteBinEntry
            {
                Title      = "ChroniCalc Error",
                Text       = message,
                Expiration = PasteBinExpiration.OneMonth,
                Private    = false
            };

            try
            {
                // Call through the Pastebin API to get the URL
                pasteUrl = client.Paste(entry, false);

                // Display the message to the user and give them a chance to copy the Pastebin URL containing the call stack
                dialogResult = MessageBox.Show(string.Concat(ERROR_HEADER_ONLINE, Environment.NewLine, message, Environment.NewLine, pasteUrl), "ChroniCalc Error", MessageBoxButtons.YesNo);

                switch (dialogResult)
                {
                case DialogResult.Yes:
                    Clipboard.SetText(pasteUrl);
                    break;

                default:
                    break;
                }
            }
            catch (Exception)
            {
                // If an exception was returned from Pastebin, it's likely the user is not connected to the internet or Pastebin is down, so just show the message to them instead
                MessageBox.Show(string.Concat(ERROR_HEADER_OFFLINE, message), "ChroniCalc Error");
            }
        }
        public EChroniCalcException(string message)
        {
            DialogResult   dialogResult;
            string         pasteUrl;
            PasteBinClient client = new PasteBinClient(PasteBinClient.PBType.Error);

            // Post the error to Pastebin and provide the user a link to send instead of asking them to do screenshots
            // Setup the data for the Pastebin  //TODO enhance to include the Build data if it exists?
            var entry = new PasteBinEntry
            {
                Title      = "ChroniCalc Exception",
                Text       = message,
                Expiration = PasteBinExpiration.OneMonth,
                Private    = false
            };

            try
            {
                // Call through the Pastebin API to get the URL
                pasteUrl = client.Paste(entry, false);

                // Display the message to the user and give them a chance to copy the Pastebin URL containing the call stack
                dialogResult = MessageBox.Show(string.Concat(ERROR_HEADER_ONLINE, Environment.NewLine, message, Environment.NewLine, pasteUrl), "ChroniCalc Exception", MessageBoxButtons.YesNo);

                switch (dialogResult)
                {
                case DialogResult.Yes:
                    Clipboard.SetText(pasteUrl);
                    break;

                default:
                    break;
                }
            }
            catch (Exception)
            {
                // If an exception was returned from Pastebin, it's likely the user is not connected to the internet or Pastebin is down, so just show the message to them instead
                MessageBox.Show(string.Concat(ERROR_HEADER_OFFLINE, message), "ChroniCalc Exception");
            }
        }
Beispiel #3
0
        private void BtnPastebinLoad_Click(object sender, EventArgs e)
        {
            // Decipher the content of the Pastebin URL into a Build
            PasteBinClient pasteBinClient;
            string         pastebinExtract;

            // Ensure there was an attempt to put a Build URL into the Load textbox before trying to load a build
            if (txtPastebinLoad.Text == string.Empty)
            {
                MessageBox.Show("Please enter a Build URL.", "Load Build");
                return;
            }

            //Prompt for save/if user really wants to load, overwriting current build
            if (!(this.ParentForm as BuildShareForm).ParentForm.SaveBuildShouldContinue())
            {
                return;
            }

            pasteBinClient = new PasteBinClient(PasteBinClient.PBType.BuildShare);
            try
            {
                pastebinExtract = pasteBinClient.Extract(txtPastebinLoad.Text);

                (this.ParentForm as BuildShareForm).ParentForm.OpenBuild(pastebinExtract, true);
            }
            catch (System.Net.WebException)
            {
                MessageBox.Show("Unable to reach Pastebin.  Invalid URL or this function is not currently available.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            catch (Exception ex)
            {
                // Throw an exception that the pastebin build either failed to be retrieved or failed to open; as such, we have to throw an exception because it's possible
                //  a true exception stemmed from the above OpenBuild() call and we don't want to lose that information by instead just showing a generic Alerts.DisplayError message and allowing the program to continue
                throw new EChroniCalcException("PastebinLoad:  Unable to retrieve and open the build from Pastebin" + Environment.NewLine + ex.ToString());
            }

            // Close the Form now that the build has been loaded and opened
            this.ParentForm.Close();
        }
Beispiel #4
0
        private void BtnPastebinShare_Click(object sender, EventArgs e)
        {
            // Generate a Pastebin URL of the current Build for the user to share
            string        buildAsText;
            string        pasteUrl;
            XmlSerializer serializer;
            var           client = new PasteBinClient(PasteBinClient.PBType.BuildShare);

            // Optional; will publish as a guest if not logged in; could enable this to see how many pastes people are using but
            //   this exposes username/password since it's on Github
            //client.Login(userName, password); //this'll set User Key

            serializer = new XmlSerializer((this.ParentForm as BuildShareForm).ParentForm.build.GetType());

            try
            {
                // Save the build to a string format
                using (StringWriter writer = new StringWriter())
                {
                    serializer.Serialize(writer, (this.ParentForm as BuildShareForm).ParentForm.build);
                    buildAsText = writer.ToString();
                }
            }
            catch (Exception ex)
            {
                // Display error that the build could not be serialized to be shared via Pastebin
                Alerts.DisplayError("PastebinShare:  Unable to serialize the build to be shared with Pastebin." + Environment.NewLine + ex.ToString());
                return;
            }

            // Setup the data for the Pastebin
            var entry = new PasteBinEntry
            {
                Title      = "ChroniCalc Build Share",
                Text       = buildAsText,
                Expiration = PasteBinExpiration.Never,
                Private    = false,
                Format     = "xml"
            };

            try
            {
                // Call through the Pastebin API to get the URL
                pasteUrl = client.Paste(entry);

                // Show the Pastebin URL in the textbox
                txtPastebinShare.Text = pasteUrl;
            }
            catch (System.Net.WebException)
            {
                MessageBox.Show("Unable to reach Pastebin.  This function is not currently available.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            catch (PasteBinApiException ex)
            {
                MessageBox.Show("Unable to retrieve Build URL from Pastebin.  This function is not currently available." + Environment.NewLine + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            catch (Exception ex)
            {
                // Something else happened and we're not sure what, so provide error details to the user to pass along to me
                throw new EChroniCalcException("PasteBinShare: Unable to reach Pastebin." + Environment.NewLine + ex.Message);
            }
        }