コード例 #1
0
 private void listView_ItemSelectionChanged(object sender, ListViewItemSelectionChangedEventArgs e)
 {
     if (listView.SelectedItems.Count > 1)
     {
         List <string> dataSourceList = new List <string>();
         foreach (ListViewItem item in listView.SelectedItems)
         {
             if (!DataSourceUtil.IsFolderType(item.SubItems[1].Text))
             {
                 // ReSharper disable LocalizableElement
                 dataSourceList.Add(string.Format("\"{0}\"", GetItemPath(item)));
             }
             // ReSharper restore LocalizableElement
         }
         sourcePathTextBox.Text = string.Join(@" ", dataSourceList.ToArray());
     }
     else if (listView.SelectedItems.Count > 0)
     {
         sourcePathTextBox.Text = GetItemPath(listView.SelectedItems[0]);
     }
     else
     {
         sourcePathTextBox.Text = string.Empty;
     }
 }
コード例 #2
0
        private SourceInfo getSourceInfo(DirectoryInfo dirInfo)
        {
            string     type       = DataSourceUtil.GetSourceType(dirInfo);
            SourceInfo sourceInfo = new SourceInfo(new MsDataFilePath(dirInfo.FullName))
            {
                type         = type,
                imageIndex   = (DataSourceUtil.IsFolderType(type) ? ImageIndex.Folder : ImageIndex.MassSpecFile),
                name         = dirInfo.Name,
                dateModified = GetSafeDateModified(dirInfo)
            };

            if (listView.View != View.Details ||
                (sourceTypeComboBox.SelectedIndex > 0 &&
                 sourceTypeComboBox.SelectedItem.ToString() != sourceInfo.type))
            {
                return(sourceInfo);
            }

            if (sourceInfo.isFolder)
            {
                return(sourceInfo);
            }
            if (!sourceInfo.isUnknown)
            {
                sourceInfo.size = 0;
                foreach (FileInfo fileInfo in dirInfo.GetFiles())
                {
                    sourceInfo.size += (UInt64)fileInfo.Length;
                }
                return(sourceInfo);
            }
            return(null);
        }
コード例 #3
0
        private void listView_ItemActivate(object sender, EventArgs e)
        {
            if (listView.SelectedItems.Count == 0)
            {
                return;
            }

            ListViewItem item = listView.SelectedItems[0];

            if (DataSourceUtil.IsFolderType(item.SubItems[1].Text))
            {
                OpenFolderItem(item);
            }
            else
            {
                DataSources  = new[] { ((SourceInfo)item.Tag).MsDataFileUri, };
                DialogResult = DialogResult.OK;
                Close();
            }
        }
コード例 #4
0
        public void Open()
        {
            List <MsDataFileUri> dataSourceList = new List <MsDataFileUri>();

            foreach (ListViewItem item in listView.SelectedItems)
            {
                if (!DataSourceUtil.IsFolderType(item.SubItems[1].Text))
                {
                    dataSourceList.Add(((SourceInfo)item.Tag).MsDataFileUri);
                }
            }
            if (dataSourceList.Count > 0)
            {
                DataSources        = dataSourceList.ToArray();
                _abortPopulateList = true;
                DialogResult       = DialogResult.OK;
                return;
            }

            // No files selected: see if there is a folder selected that we
            // should navigate to
            foreach (ListViewItem item in listView.SelectedItems)
            {
                if (DataSourceUtil.IsFolderType(item.SubItems[1].Text))
                {
                    OpenFolderItem(item);
                    return;
                }
            }

            try
            {
                // perhaps the user has typed an entire filename into the text box - or just garbage
                var  fileOrDirName = sourcePathTextBox.Text;
                bool exists;
                bool triedAddingDirectory = false;
                while (!(exists = ((File.Exists(fileOrDirName) || Directory.Exists(fileOrDirName)))))
                {
                    if (triedAddingDirectory)
                    {
                        break;
                    }
                    MsDataFilePath currentDirectoryPath = CurrentDirectory as MsDataFilePath;
                    if (null == currentDirectoryPath)
                    {
                        break;
                    }
                    fileOrDirName        = Path.Combine(currentDirectoryPath.FilePath, fileOrDirName);
                    triedAddingDirectory = true;
                }

                if (exists)
                {
                    if (DataSourceUtil.IsDataSource(fileOrDirName))
                    {
                        DataSources  = new[] { MsDataFileUri.Parse(fileOrDirName) };
                        DialogResult = DialogResult.OK;
                        return;
                    }
                    else if (Directory.Exists(fileOrDirName))
                    {
                        OpenFolder(new MsDataFilePath(fileOrDirName));
                        return;
                    }
                }
            }
// ReSharper disable once EmptyGeneralCatchClause
            catch {} // guard against user typed-in-garbage

            // No files or folders selected: Show an error message.
            MessageDlg.Show(this, Resources.OpenDataSourceDialog_Open_Please_select_one_or_more_data_sources);
        }
コード例 #5
0
        private void populateListViewFromDirectory(MsDataFileUri directory)
        {
            _abortPopulateList = false;
            listView.Cursor    = Cursors.Default;
            _waitingForData    = false;
            listView.Items.Clear();

            var listSourceInfo = new List <SourceInfo>();

            if (null == directory || directory is MsDataFilePath && string.IsNullOrEmpty(((MsDataFilePath)directory).FilePath))
            {
                foreach (DriveInfo driveInfo in DriveInfo.GetDrives())
                {
                    string     label      = string.Empty;
                    string     sublabel   = driveInfo.Name;
                    ImageIndex imageIndex = ImageIndex.Folder;
                    _driveReadiness[sublabel] = false;
                    try
                    {
                        switch (driveInfo.DriveType)
                        {
                        case DriveType.Fixed:
                            imageIndex = ImageIndex.LocalDrive;
                            label      = Resources.OpenDataSourceDialog_populateListViewFromDirectory_Local_Drive;
                            if (driveInfo.VolumeLabel.Length > 0)
                            {
                                label = driveInfo.VolumeLabel;
                            }
                            break;

                        case DriveType.CDRom:
                            imageIndex = ImageIndex.OpticalDrive;
                            label      = Resources.OpenDataSourceDialog_populateListViewFromDirectory_Optical_Drive;
                            if (driveInfo.IsReady && driveInfo.VolumeLabel.Length > 0)
                            {
                                label = driveInfo.VolumeLabel;
                            }
                            break;

                        case DriveType.Removable:
                            imageIndex = ImageIndex.OpticalDrive;
                            label      = Resources.OpenDataSourceDialog_populateListViewFromDirectory_Removable_Drive;
                            if (driveInfo.IsReady && driveInfo.VolumeLabel.Length > 0)
                            {
                                label = driveInfo.VolumeLabel;
                            }
                            break;

                        case DriveType.Network:
                            label = Resources.OpenDataSourceDialog_populateListViewFromDirectory_Network_Share;
                            break;
                        }
                        _driveReadiness[sublabel] = IsDriveReady(driveInfo);
                    }
                    catch (Exception)
                    {
                        label += string.Format(@" ({0})", Resources.OpenDataSourceDialog_populateListViewFromDirectory_access_failure);
                    }

                    string name = driveInfo.Name;
                    if (label != string.Empty)
                    {
                        name = string.Format(@"{0} ({1})", label, name);
                    }

                    listSourceInfo.Add(new SourceInfo(new MsDataFilePath(driveInfo.RootDirectory.FullName))
                    {
                        type         = DataSourceUtil.FOLDER_TYPE,
                        imageIndex   = imageIndex,
                        name         = name,
                        dateModified = GetDriveModifiedTime(driveInfo)
                    });
                }
            }
            else if (directory is RemoteUrl)
            {
                RemoteUrl remoteUrl = directory as RemoteUrl;
                if (string.IsNullOrEmpty(remoteUrl.ServerUrl))
                {
                    foreach (var remoteAccount in _remoteAccounts)
                    {
                        listSourceInfo.Add(new SourceInfo(remoteAccount.GetRootUrl())
                        {
                            name       = remoteAccount.GetKey(),
                            type       = DataSourceUtil.FOLDER_TYPE,
                            imageIndex = ImageIndex.MyNetworkPlaces,
                        });
                    }
                }
                else
                {
                    RemoteAccount remoteAccount = GetRemoteAccount(remoteUrl);
                    if (RemoteSession == null || !Equals(remoteAccount, RemoteSession.Account))
                    {
                        RemoteSession = RemoteSession.CreateSession(remoteAccount);
                    }
                    RemoteServerException exception;
                    bool isComplete = _remoteSession.AsyncFetchContents(remoteUrl, out exception);
                    foreach (var item in _remoteSession.ListContents(remoteUrl))
                    {
                        var imageIndex = DataSourceUtil.IsFolderType(item.Type)
                            ? ImageIndex.Folder
                            : ImageIndex.MassSpecFile;
                        listSourceInfo.Add(new SourceInfo(item.MsDataFileUri)
                        {
                            name         = item.Label,
                            type         = item.Type,
                            imageIndex   = imageIndex,
                            dateModified = item.LastModified,
                            size         = item.FileSize
                        });
                    }
                    if (null != exception)
                    {
                        if (MultiButtonMsgDlg.Show(this, exception.Message, Resources.OpenDataSourceDialog_populateListViewFromDirectory_Retry) != DialogResult.Cancel)
                        {
                            RemoteSession.RetryFetchContents(remoteUrl);
                            isComplete = false;
                        }
                    }
                    if (!isComplete)
                    {
                        listView.Cursor = Cursors.WaitCursor;
                        _waitingForData = true;
                    }
                }
            }
            else if (directory is MsDataFilePath)
            {
                MsDataFilePath msDataFilePath = (MsDataFilePath)directory;
                DirectoryInfo  dirInfo        = new DirectoryInfo(msDataFilePath.FilePath);

                try
                {
                    // subitems: Name, Type, Spectra, Size, Date Modified
                    var arraySubDirInfo = dirInfo.GetDirectories();
                    Array.Sort(arraySubDirInfo, (d1, d2) => string.Compare(d1.Name, d2.Name, StringComparison.CurrentCultureIgnoreCase));
                    var arrayFileInfo = dirInfo.GetFiles();
                    Array.Sort(arrayFileInfo, (f1, f2) => string.Compare(f1.Name, f2.Name, StringComparison.CurrentCultureIgnoreCase));

                    // Calculate information about the files, allowing the user to cancel
                    foreach (var info in arraySubDirInfo)
                    {
                        listSourceInfo.Add(getSourceInfo(info));
                        Application.DoEvents();
                        if (_abortPopulateList)
                        {
                            //MessageBox.Show( "abort" );
                            break;
                        }
                    }

                    if (!_abortPopulateList)
                    {
                        foreach (var info in arrayFileInfo)
                        {
                            listSourceInfo.Add(getSourceInfo(info));
                            Application.DoEvents();
                            if (_abortPopulateList)
                            {
                                //MessageBox.Show( "abort" );
                                break;
                            }
                        }
                    }
                }
                catch (Exception x)
                {
                    var message = TextUtil.LineSeparate(
                        Resources.OpenDataSourceDialog_populateListViewFromDirectory_An_error_occurred_attempting_to_retrieve_the_contents_of_this_directory,
                        x.Message);
                    // Might throw access violation.
                    MessageDlg.ShowWithException(this, message, x);
                    return;
                }
            }

            // Populate the list
            var items = new List <ListViewItem>();

            foreach (var sourceInfo in listSourceInfo)
            {
                if (sourceInfo != null &&
                    (sourceTypeComboBox.SelectedIndex == 0 ||
                     sourceTypeComboBox.SelectedItem.ToString() == sourceInfo.type ||
                     // Always show folders
                     sourceInfo.isFolder))
                {
                    ListViewItem item = new ListViewItem(sourceInfo.ToArray(), (int)sourceInfo.imageIndex)
                    {
                        Tag = sourceInfo,
                    };
                    item.SubItems[2].Tag = sourceInfo.size;
                    item.SubItems[3].Tag = sourceInfo.dateModified;

                    items.Add(item);
                }
            }
            listView.Items.AddRange(items.ToArray());
        }