示例#1
0
        private void Execute(ISender client, GetDrives command)
        {
            DriveInfo[] driveInfos;
            try
            {
                driveInfos = DriveInfo.GetDrives().Where(d => d.IsReady).ToArray();
            }
            catch (IOException)
            {
                client.Send(new SetStatusFileManager {
                    Message = "GetDrives I/O error", SetLastDirectorySeen = false
                });
                return;
            }
            catch (UnauthorizedAccessException)
            {
                client.Send(new SetStatusFileManager {
                    Message = "GetDrives No permission", SetLastDirectorySeen = false
                });
                return;
            }

            if (driveInfos.Length == 0)
            {
                client.Send(new SetStatusFileManager {
                    Message = "GetDrives No drives", SetLastDirectorySeen = false
                });
                return;
            }

            Drive[] drives = new Drive[driveInfos.Length];
            for (int i = 0; i < drives.Length; i++)
            {
                try
                {
                    var displayName = !string.IsNullOrEmpty(driveInfos[i].VolumeLabel)
                        ? string.Format("{0} ({1}) [{2}, {3}]", driveInfos[i].RootDirectory.FullName,
                                        driveInfos[i].VolumeLabel,
                                        driveInfos[i].DriveType.ToFriendlyString(), driveInfos[i].DriveFormat)
                        : string.Format("{0} [{1}, {2}]", driveInfos[i].RootDirectory.FullName,
                                        driveInfos[i].DriveType.ToFriendlyString(), driveInfos[i].DriveFormat);

                    drives[i] = new Drive
                    {
                        DisplayName = displayName, RootDirectory = driveInfos[i].RootDirectory.FullName
                    };
                }
                catch (Exception)
                {
                }
            }

            client.Send(new GetDrivesResponse {
                Drives = drives
            });
        }
        public static void getDrives(GetDrives command, ClientMosaique client)
        {
            DriveInfo[] drives;
            try
            {
                drives = DriveInfo.GetDrives().Where(d => d.IsReady).ToArray();
            }
            catch (IOException)
            {
                new SetStatusFileManager("GetDrives I/O error", false).Execute(client);
                return;
            }
            catch (UnauthorizedAccessException)
            {
                new SetStatusFileManager("GetDrives No permission", false).Execute(client);
                return;
            }

            if (drives.Length == 0)
            {
                new SetStatusFileManager("GetDrives No drives", false).Execute(client);
                return;
            }

            string[] displayName   = new string[drives.Length];
            string[] rootDirectory = new string[drives.Length];
            for (int i = 0; i < drives.Length; i++)
            {
                string volumeLabel = null;
                try
                {
                    volumeLabel = drives[i].VolumeLabel;
                }
                catch
                {
                }

                if (string.IsNullOrEmpty(volumeLabel))
                {
                    displayName[i] = string.Format("{0} [{1}, {2}]", drives[i].RootDirectory.FullName,
                                                   DriveTypeName(drives[i].DriveType), drives[i].DriveFormat);
                }
                else
                {
                    displayName[i] = string.Format("{0} ({1}) [{2}, {3}]", drives[i].RootDirectory.FullName, volumeLabel,
                                                   DriveTypeName(drives[i].DriveType), drives[i].DriveFormat);
                }
                rootDirectory[i] = drives[i].RootDirectory.FullName;
            }

            new GetDrivesResponse(displayName, rootDirectory).Execute(client);
        }
示例#3
0
        public MemoryPage()
        {
            InitializeComponent();
            _driveinfo = GetDrives.GetDrivesMethod();

            if (_driveinfo.Length == 0)
            {
                _drivesAmount = 0;
            }
            else
            {
                _drivesAmount = _driveinfo.Length;
                _currentDrive = 1;

                MainFrame.Content = new DrivePage(_driveinfo, _currentDrive);
            }
        }
示例#4
0
        private void InitTree()
        {
            GetDrives?.Invoke(this, EventArgs.Empty);
            foreach (var drive in Drives)
            {
                try//картинки на диски
                {
                    _treeNode = new TreeNode();
                    _treeNode = treeView1.Nodes.Add(drive.Key);

                    switch (drive.Value)
                    {
                    case "DriveType.Fixed":
                    case "DriveType.Network":
                        _treeNode.ImageIndex         = 1;
                        _treeNode.SelectedImageIndex = 1;
                        break;

                    case "DriveType.Removable":
                    case "DriveType.CDRom":
                        _treeNode.ImageIndex         = 0;
                        _treeNode.SelectedImageIndex = 0;
                        break;
                    }
                    GetPaths?.Invoke(drive.Key);
                    foreach (var item in DirectoriesNames)
                    {
                        TreeNode node = new TreeNode(item)
                        {
                            ImageIndex         = 2,
                            SelectedImageIndex = 2
                        };
                        _treeNode.Nodes.Add(node);
                    }
                }
                catch { }
            }
        }
示例#5
0
        /// <summary>
        /// Gets the specified request.
        /// </summary>
        /// <param name="request">The request.</param>
        /// <returns>System.Object.</returns>
        public object Get(GetDrives request)
        {
            var result = GetDrives().ToList();

            return(ToOptimizedSerializedResultUsingCache(result));
        }
示例#6
0
        /// <summary>
        /// Gets the specified request.
        /// </summary>
        /// <param name="request">The request.</param>
        /// <returns>System.Object.</returns>
        public object Get(GetDrives request)
        {
            var result = GetDrives().ToList();

            return(ToOptimizedResult(result));
        }