Ejemplo n.º 1
0
        public void OpenFile(string fileName)
        {
            if (!System.IO.File.Exists(fileName))
            {
                return;
            }

            view.Clear();
            ShowStatus("Loading...");
            Mouse.OverrideCursor = Cursors.Wait;

            // Load on a background thread so we can keep the UI in sync
            Task.Factory.StartNew(() =>
            {
                try
                {
                    xstFile = new XstFile(view, fileName);
                    xstFile.ReadFolderTree();
                }
                catch (System.Exception ex)
                {
                    MessageBox.Show(ex.Message, "Error reading xst file");
                }
            })
            // When loading completes, update the UI using the UI thread
            .ContinueWith((task) =>
            {
                Application.Current.Dispatcher.Invoke(new Action(() =>
                {
                    ShowStatus(null);
                    Mouse.OverrideCursor = null;
                    Title = "Xst Reader - " + System.IO.Path.GetFileName(fileName);
                }));
            });
        }
Ejemplo n.º 2
0
        public void OpenFile(string fileName)
        {
            if (!System.IO.File.Exists(fileName))
            {
                return;
            }

            view.Clear();
            ShowStatus("Loading...");
            Mouse.OverrideCursor = Cursors.Wait;

            // Load on a background thread so we can keep the UI in sync
            Task.Factory.StartNew(() =>
            {
                try
                {
                    xstFile  = new XstFile(fileName);
                    var root = xstFile.ReadFolderTree();

                    //
                    // I refactorized this part:
                    //
                    // iterator with view.RootFolderViews.Add -> moved to view.UpdateFolderViews(root)
                    //

                    // We may be called on a background thread, so we need to dispatch this to the UI thread
                    Application.Current.Dispatcher.Invoke(new Action(() => view.UpdateFolderViews(root)));

                    //foreach (var f in root.Folders)
                    //{
                    //    // We may be called on a background thread, so we need to dispatch this to the UI thread
                    //    Application.Current.Dispatcher.Invoke(new Action(() =>
                    //    {
                    //        view.RootFolderViews.Add(new FolderView(f));
                    //    }));
                    //}
                }
                catch (System.Exception ex)
                {
                    MessageBox.Show(ex.ToString(), "Error reading xst file");
                }
            })
            // When loading completes, update the UI using the UI thread
            .ContinueWith((task) =>
            {
                Application.Current.Dispatcher.Invoke(new Action(() =>
                {
                    ShowStatus(null);
                    Mouse.OverrideCursor = null;
                    Title = "Xst Reader - " + System.IO.Path.GetFileName(fileName);
                }));
            });
        }
Ejemplo n.º 3
0
        private void btnOpen_Click(object sender, RoutedEventArgs e)
        {
            // Ask for a .ost or .pst file to open
            System.Windows.Forms.OpenFileDialog dialog = new System.Windows.Forms.OpenFileDialog();

            dialog.Filter           = "xst files (*.ost;*.pst)|*.ost;*.pst|All files (*.*)|*.*";
            dialog.FilterIndex      = 1;
            dialog.InitialDirectory = Properties.Settings.Default.LastFolder;
            if (dialog.InitialDirectory == "")
            {
                dialog.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
            }
            dialog.RestoreDirectory = true;

            if (dialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                Properties.Settings.Default.LastFolder = System.IO.Path.GetDirectoryName(dialog.FileName);
                Properties.Settings.Default.Save();

                view.Clear();
                txtStatus.Text       = "Loading...";
                Mouse.OverrideCursor = Cursors.Wait;

                // Load on a background thread so we can keep the UI in sync
                Task.Factory.StartNew(() =>
                {
                    try
                    {
                        xstFile = new XstFile(view, dialog.FileName);
                        xstFile.ReadFolderTree();
                    }
                    catch (System.Exception ex)
                    {
                        MessageBox.Show(ex.Message, "Error reading xst file");
                    }
                })
                // When loading completes, update the UI using the UI thread
                .ContinueWith((task) =>
                {
                    Application.Current.Dispatcher.Invoke(new Action(() =>
                    {
                        txtStatus.Text       = "";
                        Mouse.OverrideCursor = null;
                        Title = "Xst Reader - " + System.IO.Path.GetFileName(dialog.FileName);
                    }));
                });
            }
        }