示例#1
0
        private void WorkerListFilesProgressChanged(object sender, ProgressChangedEventArgs e)
        {
            var worker = (BackgroundWorker)sender;

            Progress.Maximum = 100;
            Progress.Value   = e.ProgressPercentage;
            if (e.UserState == null)
            {
                return;
            }
            if (e.UserState is string)
            {
                CurrentAction.Text = (string)e.UserState;
            }
            else if (e.UserState is MetroTile)
            {
                var tile = (MetroTile)e.UserState;
                FileTooltip.SetToolTip(tile, tile.Text);
                tile.Click += LeftTile_Click;
                LeftPanel.Controls.Add(tile);
                tile.Refresh();
            }
            else if (e.UserState is MetroMessageBoxProperties)
            {
                var props = (MetroMessageBoxProperties)e.UserState;
                try
                {
                    if (MetroMessageBox.Show(this, props.Message, props.Title, props.Buttons, props.Icon) == DialogResult.Cancel)
                    {
                        worker.CancelAsync();
                    }
                }
                catch (Exception ex)
                {
                    _log.Error(ex);
                    worker.CancelAsync();
                }
            }
        }
示例#2
0
        private void LoadLocalContents(string localPath)
        {
            DisablePanels();
            try
            {
                CurrentAction.Text    = Resources.ReadLocalDir;
                ProgressPanel.Visible = true;

                var currentDirectory = new DirectoryInfo(localPath);
                var files            = currentDirectory.GetFiles();
                var folders          = currentDirectory.GetDirectories();

                RightTiles.Controls.Clear();

                if (Directory.Exists(localPath))
                {
                    LocalPath.Text = localPath;
                    if (localPath.Length > 2)
                    {
                        // parent Tile
                        var parentDirectory = localPath.LastIndexOf("\\") == 0 ? "\\" : localPath.Substring(0, localPath.LastIndexOf("\\"));
                        var tile            = new MetroTile
                        {
                            Text   = "..",
                            Width  = _metroTileSize,
                            Height = _metroTileSize,
                            Tag    = parentDirectory,
                            Style  = MetroColorStyle.Green
                        };
                        tile.Click += RightTile_Click;
                        RightTiles.Controls.Add(tile);
                    }


                    Progress.Maximum = folders.Length;
                    var counter = 0;
                    foreach (var folder in folders.OrderBy(fld => fld.Name))
                    {
                        var tile = new MetroTile
                        {
                            Text = folder.Name, Width = _metroTileSize, Height = _metroTileSize, Style = MetroColorStyle.Yellow,
                            Tag  = folder
                        };
                        tile.Click += RightTile_Click;
                        FileTooltip.SetToolTip(tile, folder.Name);
                        RightTiles.Controls.Add(tile);
                        Progress.Value = counter;
                        counter++;
                        Application.DoEvents();
                    }
                    Progress.Maximum = folders.Length;
                    counter          = 0;
                    foreach (var fileInfo in files.OrderBy(fld => fld.Name))
                    {
                        if (!fileInfo.Name.Contains('.') && _connection.Settings.FileTypesToCopy != (int)ProgramSettings.FileTypes.AllFiles)
                        {
                            continue;
                        }

                        var tile = new MetroTile
                        {
                            Text = fileInfo.Name, Width = _metroTileSize, Height = _metroTileSize,
                            Tag  = fileInfo
                        };
                        tile.Click += RightTile_Click;
                        FileTooltip.SetToolTip(tile, fileInfo.Name);
                        TryGetThumb(tile, fileInfo);
                        RightTiles.Controls.Add(tile);
                        Progress.Value = counter;
                        counter++;
                        Application.DoEvents();
                    }
                }
                ResizeTiles(RightTiles);
                ProgressPanel.Visible = false;
            }
            catch (Exception ex)
            {
                _log.Error(ex);
                MetroMessageBox.Show(this, "That path seems to be terribly wrong.");
            }
            EnablePanels();
        }