Пример #1
0
        private void Application_DispatcherUnhandledException(object sender, System.Windows.Threading.DispatcherUnhandledExceptionEventArgs e)
        {
            StringBuilder exMessage = new StringBuilder();

            // Add info
            exMessage.Append(DateTime.Now);
            exMessage.Append(System.Environment.NewLine);
            exMessage.Append("Source: \n");
            exMessage.Append(e.Exception.Source);
            exMessage.Append("\nException message: \n");
            exMessage.Append(e.Exception.Message);
            exMessage.Append("\nStack trace: \n");
            exMessage.Append(e.Exception.StackTrace);
            // Log to file
            FileWorker filewriter = new FileWorker();

            filewriter.WriteToFile(@"C:\MultiTextEditorLog.txt", exMessage.ToString(), true);

            MessageBox.Show(@"Exception occurs during work with the application. Please, send C:\MultiTextEditorLog.txt log about the error to developer!");
        }
Пример #2
0
        private void Application_DispatcherUnhandledException(object sender, System.Windows.Threading.DispatcherUnhandledExceptionEventArgs e)
        {
            StringBuilder exMessage = new StringBuilder();

            // Add info
            exMessage.Append(DateTime.Now);
            exMessage.Append(System.Environment.NewLine);
            exMessage.Append("Source: \n");
            exMessage.Append(e.Exception.Source);
            exMessage.Append("\nException message: \n");
            exMessage.Append(e.Exception.Message);
            exMessage.Append("\nStack trace: \n");
            exMessage.Append(e.Exception.StackTrace);
            // Log to file
            FileWorker filewriter = new FileWorker();

            filewriter.WriteToFile(@"C:\MultiTextEditorLog.txt", exMessage.ToString(), true);

            MessageBox.Show(@"Exception occurs during work with the application. Please, send C:\MultiTextEditorLog.txt log about the error to developer!");
        }
        private void Save_Click(object sender, RoutedEventArgs e)
        {
            // Find path.
            String filePath = String.Empty;

            try
            {
                OpenFileDialog ofd = new OpenFileDialog();
                ofd.Filter = (string)App.Current.FindResource("FileDialogSettings");

                if (ofd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                {
                    if (ofd.CheckFileExists == true)
                    {
                        filePath = ofd.FileName;
                    }
                }
            }
            catch (OutOfMemoryException)
            {
                System.Windows.Forms.MessageBox.Show((string)App.Current.FindResource("ErrorOutMemory"));
            }
            catch (Exception)
            {
                System.Windows.Forms.MessageBox.Show((string)App.Current.FindResource("ErrorCantOpenDialog"));
            }

            // Write.
            FileWorker fw = new FileWorker();

            try
            {
                fw.WriteToFile(filePath, _data.ToString(), false);
            }
            catch (SimpleEditException ex)
            {
                System.Windows.Forms.MessageBox.Show(ex.Message);
            }
        }
        private void Save_Click(object sender, RoutedEventArgs e)
        {
            // Find path.
            String filePath = String.Empty;
            try
            {
                OpenFileDialog ofd = new OpenFileDialog();
                ofd.Filter = (string)App.Current.FindResource("FileDialogSettings");

                if (ofd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                {
                    if (ofd.CheckFileExists == true)
                    {
                        filePath = ofd.FileName;
                    }
                }
            }
            catch (OutOfMemoryException)
            {
                System.Windows.Forms.MessageBox.Show((string)App.Current.FindResource("ErrorOutMemory"));
            }
            catch (Exception)
            {
                System.Windows.Forms.MessageBox.Show((string)App.Current.FindResource("ErrorCantOpenDialog"));
            }

            // Write.
            FileWorker fw = new FileWorker();
            try
            {
                fw.WriteToFile(filePath, _data.ToString(), false);
            }
            catch (SimpleEditException ex)
            {
                System.Windows.Forms.MessageBox.Show(ex.Message);
            }
        }
        /// <summary>
        /// Method writes data to file.
        /// </summary>
        /// <param name="filePath">Path to the file.</param>
        /// <param name="data">Data to write.</param>
        private void _WriteDataToFile(String filePath, String data, Encoding format)
        {
            //check file info
            FileInfo fi = new FileInfo(filePath);

            FileWorker fw = new FileWorker();
            fw.WriteToFile(filePath, data, format);
        }
        /// <summary>
        /// Method reads data from file.
        /// </summary>
        /// <param name="filePath">Path to the file.</param>
        /// <returns></returns>
        private String _ReadDataFromFile(String filePath)
        {
            String Text = String.Empty;
            //check file info
            FileInfo fi = new FileInfo(filePath);

            if(fi.Exists == true)
            {

                    FileWorker fw = new FileWorker();
                    Text = fw.ReadFromFile(filePath);
            }
            return Text;
        }