コード例 #1
0
        async Task UpdateAllViews()
        {
            List <IFileObject> leftList  = FileOperator.GetDirContainsList(FileOperator.Side.Left).ToList();
            List <IFileObject> rightList = FileOperator.GetDirContainsList(FileOperator.Side.Right).ToList();

            while (true)
            {
                await Task.Delay(1000);

                //FileOperator.Side s = FileOperator.ActiveDirectory;
                List <IFileObject> leftNewList  = FileOperator.GetDirContainsList(FileOperator.Side.Left).ToList();
                List <IFileObject> rightNewList = FileOperator.GetDirContainsList(FileOperator.Side.Right).ToList();
                List <String>      drives       = FileOperator.GetAllLogicalDrives().ToList();
                if (!CompareSortedFileLists(leftList, leftNewList) || !CompareSortedFileLists(rightList, rightNewList) || drives.Count != (rootComboBoxL.ItemsSource.Cast <string>().Count()))
                {
                    //lock (synclock)
                    {
                        await Task.Run(() => UpdateView(FileOperator.Side.Left, leftNewList, false));

                        await Task.Run(() => UpdateView(FileOperator.Side.Right, rightNewList, false));
                    }
                    leftList  = leftNewList;
                    rightList = rightNewList;
                }
            }
        }
コード例 #2
0
        private void UpdateView(FileOperator.Side _s, IEnumerable <IFileObject> _files = null, bool isMakeActive = true)
        {
            ListBox   someView         = null;
            ComboBox  someRootComboBox = null;
            TextBlock somePathRow      = null;
            Grid      someStatusStr    = null;
            ComboBox  someSortComboBox = null;

            if (_s == FileOperator.Side.Left)
            {
                Dispatcher.Invoke(() => someView         = leftView);
                Dispatcher.Invoke(() => someRootComboBox = rootComboBoxL);
                Dispatcher.Invoke(() => somePathRow      = pathRowL);
                Dispatcher.Invoke(() => someStatusStr    = StatusStrL);
                Dispatcher.Invoke(() => someSortComboBox = leftSortChooseBox);
            }
            else if (_s == FileOperator.Side.Right)
            {
                Dispatcher.Invoke(() => someView         = rightView);
                Dispatcher.Invoke(() => someRootComboBox = rootComboBoxR);
                Dispatcher.Invoke(() => somePathRow      = pathRowR);
                Dispatcher.Invoke(() => someStatusStr    = StatusStrR);
                Dispatcher.Invoke(() => someSortComboBox = rightSortChooseBox);
            }
            lock (synclock)
            {
                Dispatcher.Invoke(() => someView.ItemsSource = null);
                List <IFileObject> listOfContFiles = null;
                try
                {
                    listOfContFiles = (_files == null) ? FileOperator.GetDirContainsList(_s).ToList() : _files.ToList();
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Files list can not be get", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                    return;
                }
                try
                {
                    Dispatcher.Invoke(() => someView.ItemsSource = FileOperator.SetActionForSort(listOfContFiles, someSortComboBox.SelectedIndex));
                }
                catch (Exception ex)
                {
                    MessageBox.Show($"Cannot sort items: {ex.Message}. Show unsorted list", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                    Dispatcher.Invoke(() => someView.ItemsSource = listOfContFiles);
                }
                List <String> drives       = FileOperator.GetAllLogicalDrives().ToList();
                String        logicalDrive = File_Containers.FileDualContainer.ChooseContainer(_s).StoredDirectory.Info.LogicalDrive;
                try
                {
                    Dispatcher.Invoke(() => someRootComboBox.ItemsSource = drives);
                }
                catch (Exception ex)
                {
                    MessageBox.Show("This disk is not availbale. Chack other disk", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                    return;
                }
                Dispatcher.Invoke(() => someRootComboBox.SelectedItem = drives.Find((item) => logicalDrive.Equals(item)));
                Dispatcher.Invoke(() => somePathRow.Text          = File_Containers.FileDualContainer.ChooseContainer(_s).StoredDirectory.Info.ShortName);
                Dispatcher.Invoke(() => someStatusStr.DataContext = File_Containers.FileDualContainer.ChooseContainer(_s).StoredDirectory.Info);
                if (isMakeActive)
                {
                    MakeDirActive(_s);
                }
            }
        }