Пример #1
0
        public async Task SetCurrentAsync(StorageFolder newCurrent)
        {
            IReadOnlyList <StorageFolder> newFamily = new List <StorageFolder>();
            int newIndex = -1;

            if (newCurrent != null)
            {
                await FileErrorHelper.RunMethodAsync(async delegate(String path)
                {
                    var parent = await newCurrent.GetParentAsync();
                    if (parent != null)
                    {
                        await FileErrorHelper.RunMethodAsync(async delegate(String parent_path)
                        {
                            var curName = newCurrent.Name;
                            newFamily   = await parent.GetFoldersAsync();
                            for (int i = 0; i < newFamily.Count; ++i)
                            {
                                if (newFamily[i].Name == curName)
                                {
                                    newIndex = i;
                                    break;
                                }
                            }
                        }, parent.Path);
                    }
                }, newCurrent.Path);
            }

            lock (_mutex)
            {
                _currentIndex = newIndex;
                _family       = newFamily;
            }
        }
Пример #2
0
 private async Task OpenFolderPathAndReloadView(String path)
 {
     await FileErrorHelper.RunMethodAsync(async delegate(String p) {
         var folder = await StorageFolder.GetFolderFromPathAsync(p);
         await UpdateFromFolder(folder);
     }, path);
 }
Пример #3
0
 protected async override void OnNavigatedTo(NavigationEventArgs e)
 {
     if (e != null)
     {
         var args = e.Parameter as IActivatedEventArgs;
         if (args != null)
         {
             if (args.Kind == ActivationKind.CommandLineLaunch)
             {
                 string folderPath = "";
                 var    clArgs     = args as CommandLineActivatedEventArgs;
                 var    op         = clArgs.Operation;
                 if (op != null)
                 {
                     folderPath = op.Arguments;
                 }
                 if (folderPath.Length > 0)
                 {
                     await OpenFolderPathAndReloadView(folderPath);
                 }
             }
             else if (args.Kind == ActivationKind.File)
             {
                 var fileArgs = args as FileActivatedEventArgs;
                 var file     = fileArgs.Files[0] as StorageFile;
                 await FileErrorHelper.RunMethodAsync(async delegate(String p)
                 {
                     var parent = await file.GetParentAsync();
                     await UpdateFromFolder(parent);
                 }, file.Path);
             }
         }
     }
     base.OnNavigatedTo(e);
 }
Пример #4
0
 public static async Task RunMethodAsync(Func <String, Task> fn, String path)
 {
     try
     {
         await fn(path);
     }
     catch (System.IO.FileNotFoundException)
     {
         await FileErrorHelper.RaiseNotFoundDialog(path);
     }
     catch (UnauthorizedAccessException)
     {
         await FileErrorHelper.RaisePermissionsDialog(path);
     }
 }
Пример #5
0
        public static async Task <List <StorageFolder> > GetSubfolders(StorageFolder parent)
        {
            List <StorageFolder> subfolders = new List <StorageFolder>();

            if (parent == null)
            {
                return(subfolders);
            }
            await FileErrorHelper.RunMethodAsync(async delegate(String path)
            {
                var clock                 = new WallClockMeasurement();
                var folderOptions         = new QueryOptions(CommonFolderQuery.DefaultQuery);
                folderOptions.FolderDepth = FolderDepth.Deep;
                var folderQuery           = parent.CreateFolderQueryWithOptions(folderOptions);
                var unsortedFolders       = await folderQuery.GetFoldersAsync();
                subfolders                = unsortedFolders.OrderBy(f => f.Path).ToList();
                clock.Report(0, "Querying " + subfolders.Count() + " subfolders of " + parent.Path);
            }, parent.Path);

            return(subfolders);
        }