Exemple #1
0
        private void _listViewAddMenuItem_Click(object sender, RoutedEventArgs e)
        {
            var dialog = new System.Windows.Forms.OpenFileDialog();

            dialog.Multiselect      = true;
            dialog.RestoreDirectory = true;

            if (dialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                var filePaths = new HashSet <string>(dialog.FileNames);

                Task.Run(() =>
                {
                    if (_shareAddIsRunning)
                    {
                        return;
                    }
                    _shareAddIsRunning = true;

                    Thread.CurrentThread.IsBackground = true;

                    try
                    {
                        foreach (var informaiton in _amoebaManager.ShareInformation)
                        {
                            filePaths.Remove((string)informaiton["Path"]);
                        }

                        this.Dispatcher.Invoke(DispatcherPriority.Background, new Action(() =>
                        {
                            if (filePaths.Count == 1)
                            {
                                var window   = new UploadWindow(filePaths.First(), true, _amoebaManager);
                                window.Owner = _mainWindow;
                                window.ShowDialog();
                            }
                            else if (filePaths.Count > 1)
                            {
                                var window   = new UploadListWindow(filePaths, true, _amoebaManager);
                                window.Owner = _mainWindow;
                                window.ShowDialog();
                            }
                        }));
                    }
                    finally
                    {
                        _shareAddIsRunning = false;
                    }
                });
            }
        }
        private void _listView_PreviewDrop(object sender, DragEventArgs e)
        {
            if (!e.Data.GetDataPresent(DataFormats.FileDrop)) return;
            var result = ((string[])e.Data.GetData(DataFormats.FileDrop)).ToList();

            ThreadPool.QueueUserWorkItem((object wstate) =>
            {
                if (_shareAddIsRunning) return;
                _shareAddIsRunning = true;

                Thread.CurrentThread.IsBackground = true;

                try
                {
                    var filePaths = new HashSet<string>();

                    foreach (var item in result)
                    {
                        if (File.Exists(item)) filePaths.Add(item);
                        else if (Directory.Exists(item)) filePaths.UnionWith(Directory.GetFiles(item, "*", SearchOption.AllDirectories));
                    }

                    foreach (var informaiton in _amoebaManager.ShareInformation)
                    {
                        filePaths.Remove((string)informaiton["Path"]);
                    }

                    this.Dispatcher.Invoke(DispatcherPriority.Background, new Action(() =>
                    {
                        if (filePaths.Count == 1)
                        {
                            UploadWindow window = new UploadWindow(filePaths.First(), true, _amoebaManager);
                            window.Owner = _mainWindow;
                            window.ShowDialog();
                        }
                        else if (filePaths.Count > 1)
                        {
                            UploadListWindow window = new UploadListWindow(filePaths, true, _amoebaManager);
                            window.Owner = _mainWindow;
                            window.ShowDialog();
                        }
                    }));
                }
                finally
                {
                    _shareAddIsRunning = false;
                }
            });
        }
Exemple #3
0
        private void _listView_PreviewDrop(object sender, DragEventArgs e)
        {
            if (!e.Data.GetDataPresent(DataFormats.FileDrop))
            {
                return;
            }
            var result = ((string[])e.Data.GetData(DataFormats.FileDrop)).ToList();

            Task.Run(() =>
            {
                if (_shareAddIsRunning)
                {
                    return;
                }
                _shareAddIsRunning = true;

                Thread.CurrentThread.IsBackground = true;

                try
                {
                    var filePaths = new HashSet <string>();

                    foreach (var item in result)
                    {
                        if (File.Exists(item))
                        {
                            filePaths.Add(item);
                        }
                        else if (Directory.Exists(item))
                        {
                            filePaths.UnionWith(Directory.GetFiles(item, "*", SearchOption.AllDirectories));
                        }
                    }

                    foreach (var informaiton in _amoebaManager.ShareInformation)
                    {
                        filePaths.Remove((string)informaiton["Path"]);
                    }

                    this.Dispatcher.Invoke(DispatcherPriority.Background, new Action(() =>
                    {
                        if (filePaths.Count == 1)
                        {
                            var window   = new UploadWindow(filePaths.First(), true, _amoebaManager);
                            window.Owner = _mainWindow;
                            window.ShowDialog();
                        }
                        else if (filePaths.Count > 1)
                        {
                            var window   = new UploadListWindow(filePaths, true, _amoebaManager);
                            window.Owner = _mainWindow;
                            window.ShowDialog();
                        }
                    }));
                }
                finally
                {
                    _shareAddIsRunning = false;
                }
            });
        }
        private void _listViewAddMenuItem_Click(object sender, RoutedEventArgs e)
        {
            System.Windows.Forms.OpenFileDialog dialog = new System.Windows.Forms.OpenFileDialog();
            dialog.Multiselect = true;
            dialog.RestoreDirectory = true;

            if (dialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                var filePaths = new HashSet<string>(dialog.FileNames);

                ThreadPool.QueueUserWorkItem((object wstate) =>
                {
                    if (_shareAddIsRunning) return;
                    _shareAddIsRunning = true;

                    Thread.CurrentThread.IsBackground = true;

                    try
                    {
                        foreach (var informaiton in _amoebaManager.ShareInformation)
                        {
                            filePaths.Remove((string)informaiton["Path"]);
                        }

                        this.Dispatcher.Invoke(DispatcherPriority.Background, new Action(() =>
                        {
                            if (filePaths.Count == 1)
                            {
                                UploadWindow window = new UploadWindow(filePaths.First(), true, _amoebaManager);
                                window.Owner = _mainWindow;
                                window.ShowDialog();
                            }
                            else if (filePaths.Count > 1)
                            {
                                UploadListWindow window = new UploadListWindow(filePaths, true, _amoebaManager);
                                window.Owner = _mainWindow;
                                window.ShowDialog();
                            }
                        }));
                    }
                    finally
                    {
                        _shareAddIsRunning = false;
                    }
                });
            }
        }