示例#1
0
        public void LoadCollection()
        {
            try
            {
                using (var reader = new StreamReader(filename))
                {
                    var serializer = new XmlSerializer(typeof(EditCollection));
                    edcoll = (EditCollection)serializer.Deserialize(reader);
                }
            }
            catch (InvalidOperationException ex) //invalid operation is what happens when the xml can't be parsed into the objects correctly
            {
                Log.Logger.Error($"{_constants.LoadCollection} {ex.Message}\n { ex.StackTrace}");

                var caption = PluginResources.EditSettingsErrorCaption;
                var message = string.Format(PluginResources.EditSettingsXmlErrorMessage, Path.GetFileName(filename));
                MessageBox.Show(new MtWindowWrapper(GetHandle()), message, caption, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                throw new Exception(message);
            }
            catch (Exception exp) //catch-all for any other kind of error...passes up a general message with the error description
            {
                Log.Logger.Error($"{_constants.LoadCollection} {exp.Message}\n { exp.StackTrace}");

                var caption = PluginResources.EditSettingsErrorCaption;
                var message = PluginResources.EditSettingsGenericErrorMessage + " " + exp.Message;
                MessageBox.Show(new MtWindowWrapper(GetHandle()), message, caption, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                throw new Exception(message); //throwing exception aborts the segment lookup
            }
        }
        private string BrowseEditFile()
        {
            //Note: The current thread culture will not affect the language of message boxes and other dialogs
            //there seem to be some tricky workarounds out there involving win32 API hooks...but that might be a bit much
            //for now the message boxes and other system dialogs will be in language set for Windows, no matter the language set for Studio (i.e. the language of the current thread);
            //another option could be to make a custom message box as a form, but custom file dialogs could be a pain
            //FUTURE: consider possibly making the plugin localized to the system settings and not the current thread set by Studio

            if (openFile.ShowDialog() == DialogResult.OK)
            {
                try //a simple way to check for the proper xml format is to try and deserialize it
                {
                    using (System.IO.StreamReader reader = new System.IO.StreamReader(openFile.FileName))
                    {
                        XmlSerializer  serializer = new XmlSerializer(typeof(EditCollection));
                        EditCollection edcoll     = (EditCollection)serializer.Deserialize(reader);
                        edcoll = null;
                        return(openFile.FileName);
                    }
                }
                catch (InvalidOperationException) //invalid operation is what happens when the xml can't be parsed into the objects correctly
                {
                    string caption = MtProviderConfDialogResources.lookupFileStructureCheckErrorCaption;
                    string message = string.Format(MtProviderConfDialogResources.lookupFileStructureCheckXmlProblemErrorMessage, System.IO.Path.GetFileName(openFile.FileName));
                    MessageBox.Show(this, message, caption, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    return(null);
                }
                catch (Exception exp) //catch-all for any other kind of error...passes up a general message with the error description
                {
                    string caption = MtProviderConfDialogResources.lookupFileStructureCheckErrorCaption;
                    string message = MtProviderConfDialogResources.lookupFileStructureCheckGenericErrorMessage + " " + exp.Message;
                    MessageBox.Show(this, message, caption, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    return(null);
                }
            }
            else
            {
                return(null);
            }
        }