Ejemplo n.º 1
0
        public static async Task LoadDeviceAsync()
        {
            foreach (DriveInfo Drive in DriveInfo.GetDrives().Where((Drives) => Drives.DriveType == DriveType.Fixed || Drives.DriveType == DriveType.Removable || Drives.DriveType == DriveType.Network)
                     .Where((NewItem) => DriveList.All((Item) => Item.Folder.Path != NewItem.RootDirectory.FullName)))
            {
                try
                {
                    StorageFolder DriveFolder = await StorageFolder.GetFolderFromPathAsync(Drive.RootDirectory.FullName);

                    DriveList.Add(await DriveRelatedData.CreateAsync(DriveFolder, Drive.DriveType).ConfigureAwait(true));
                }
                catch (Exception ex)
                {
                    LogTracer.Log(ex, $"Hide the device \"{Drive.RootDirectory.FullName}\" for error");
                }
            }

            switch (PortalDeviceWatcher.Status)
            {
            case DeviceWatcherStatus.Created:
            case DeviceWatcherStatus.Aborted:
            case DeviceWatcherStatus.Stopped:
            {
                PortalDeviceWatcher.Start();
                break;
            }
            }

            NetworkDriveCheckTimer.Start();
        }
Ejemplo n.º 2
0
        public static async Task LoadDeviceAsync()
        {
            if (Interlocked.Exchange(ref LoadDriveLockResource, 1) == 0)
            {
                try
                {
                    if (!IsDriveLoaded)
                    {
                        IsDriveLoaded = true;

                        foreach (DriveInfo Drive in DriveInfo.GetDrives().Where((Drives) => Drives.DriveType == DriveType.Fixed || Drives.DriveType == DriveType.Removable || Drives.DriveType == DriveType.Network)
                                 .Where((NewItem) => DriveList.All((Item) => Item.Folder.Path != NewItem.RootDirectory.FullName)))
                        {
                            try
                            {
                                StorageFolder DriveFolder = await StorageFolder.GetFolderFromPathAsync(Drive.RootDirectory.FullName);

                                DriveList.Add(await DriveRelatedData.CreateAsync(DriveFolder, Drive.DriveType));
                            }
                            catch (Exception ex)
                            {
                                LogTracer.Log(ex, $"Hide the device \"{Drive.RootDirectory.FullName}\" for error");
                            }
                        }

                        switch (PortalDeviceWatcher.Status)
                        {
                        case DeviceWatcherStatus.Created:
                        case DeviceWatcherStatus.Aborted:
                        case DeviceWatcherStatus.Stopped:
                        {
                            PortalDeviceWatcher.Start();
                            break;
                        }
                        }

                        NetworkDriveCheckTimer.Start();
                    }
                }
                finally
                {
                    _ = Interlocked.Exchange(ref LoadDriveLockResource, 0);
                }
            }
        }
Ejemplo n.º 3
0
        private static async void PortalDeviceWatcher_Added(DeviceWatcher sender, DeviceInformation args)
        {
            try
            {
                StorageFolder DeviceFolder = StorageDevice.FromId(args.Id);

                if (DriveList.All((Device) => (string.IsNullOrEmpty(Device.Path) || string.IsNullOrEmpty(DeviceFolder.Path)) ? !Device.Name.Equals(DeviceFolder.Name, StringComparison.OrdinalIgnoreCase) : !Device.Path.Equals(DeviceFolder.Path, StringComparison.OrdinalIgnoreCase)))
                {
                    await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, async() =>
                    {
                        DriveList.Add(await DriveDataBase.CreateAsync(DeviceFolder, DriveType.Removable));
                    });
                }
            }
            catch (Exception ex)
            {
                LogTracer.Log(ex, $"Error happened when add device to HardDeviceList");
            }
        }
Ejemplo n.º 4
0
        private static async void PortalDeviceWatcher_Added(DeviceWatcher sender, DeviceInformation args)
        {
            try
            {
                StorageFolder DeviceFolder = StorageDevice.FromId(args.Id);

                if (DriveList.All((Device) => (string.IsNullOrEmpty(Device.Folder.Path) || string.IsNullOrEmpty(DeviceFolder.Path)) ? Device.Folder.Name != DeviceFolder.Name : Device.Folder.Path != DeviceFolder.Path))
                {
                    await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, async() =>
                    {
                        DriveList.Add(await DriveRelatedData.CreateAsync(DeviceFolder, DriveType.Removable).ConfigureAwait(true));
                    });
                }
            }
            catch (Exception ex)
            {
                LogTracer.Log(ex, $"Error happened when add device to HardDeviceList");
            }
        }
Ejemplo n.º 5
0
        public static async Task LoadDriveAsync(bool IsRefresh = false)
        {
            if (Interlocked.Exchange(ref LoadDriveLockResource, 1) == 0)
            {
                try
                {
                    if (!IsDriveLoaded || IsRefresh)
                    {
                        IsDriveLoaded = true;

                        foreach (DriveInfo Drive in DriveInfo.GetDrives().Where((Drives) => Drives.DriveType == DriveType.Fixed || Drives.DriveType == DriveType.Removable || Drives.DriveType == DriveType.Network)
                                 .Where((NewItem) => DriveList.All((Item) => !Item.Path.Equals(NewItem.RootDirectory.FullName, StringComparison.OrdinalIgnoreCase))))
                        {
                            try
                            {
                                StorageFolder Folder = await StorageFolder.GetFolderFromPathAsync(Drive.RootDirectory.FullName);

                                if (DriveList.All((Item) => (string.IsNullOrEmpty(Item.Path) || string.IsNullOrEmpty(Folder.Path)) ? !Item.Name.Equals(Folder.Name, StringComparison.OrdinalIgnoreCase) : !Item.Path.Equals(Folder.Path, StringComparison.OrdinalIgnoreCase)))
                                {
                                    DriveList.Add(await DriveDataBase.CreateAsync(Folder, Drive.DriveType));
                                }
                            }
                            catch (Exception ex)
                            {
                                LogTracer.Log(ex, $"Hide the device \"{Drive.RootDirectory.FullName}\" for error");
                            }
                        }

                        foreach (DeviceInformation Drive in await DeviceInformation.FindAllAsync(StorageDevice.GetDeviceSelector()))
                        {
                            try
                            {
                                StorageFolder Folder = StorageDevice.FromId(Drive.Id);

                                if (DriveList.All((Item) => (string.IsNullOrEmpty(Item.Path) || string.IsNullOrEmpty(Folder.Path)) ? !Item.Name.Equals(Folder.Name, StringComparison.OrdinalIgnoreCase) : !Item.Path.Equals(Folder.Path, StringComparison.OrdinalIgnoreCase)))
                                {
                                    DriveList.Add(await DriveDataBase.CreateAsync(Folder, DriveType.Removable));
                                }
                            }
                            catch (Exception ex)
                            {
                                LogTracer.Log(ex, $"Hide the device for error");
                            }
                        }

                        foreach (StorageFolder Folder in await GetWslDriveAsync())
                        {
                            try
                            {
                                if (DriveList.All((Item) => (string.IsNullOrEmpty(Item.Path) || string.IsNullOrEmpty(Folder.Path)) ? !Item.Name.Equals(Folder.Name, StringComparison.OrdinalIgnoreCase) : !Item.Path.Equals(Folder.Path, StringComparison.OrdinalIgnoreCase)))
                                {
                                    DriveList.Add(await DriveDataBase.CreateAsync(Folder, DriveType.Network));
                                }
                            }
                            catch (Exception ex)
                            {
                                LogTracer.Log(ex, $"Hide the device \"{Folder.Name}\" for error");
                            }
                        }

                        switch (PortalDeviceWatcher.Status)
                        {
                        case DeviceWatcherStatus.Created:
                        case DeviceWatcherStatus.Aborted:
                        case DeviceWatcherStatus.Stopped:
                        {
                            PortalDeviceWatcher.Start();
                            break;
                        }
                        }

                        if (!NetworkDriveCheckTimer.IsEnabled)
                        {
                            NetworkDriveCheckTimer.Start();
                        }
                    }
                }
                catch (Exception ex)
                {
                    LogTracer.Log(ex, $"An exception was threw in {nameof(LoadDriveAsync)}");
                }
                finally
                {
                    _ = Interlocked.Exchange(ref LoadDriveLockResource, 0);
                }
            }
        }