コード例 #1
0
        public async void UpdateRecentProjectList()
        {
            StorageFile myFile;
            string      token   = "";
            var         mruList = StorageApplicationPermissions.MostRecentlyUsedList;
            //mruList.Clear();

            AccessListEntryView entries = mruList.Entries;

            if (entries.Count() > 0)
            {
                foreach (AccessListEntry entry in entries)
                {
                    token = entry.Token;
                    try
                    {
                        myFile = await mruList.GetFileAsync(token);

                        ProjectsList.Add(new RecentProject()
                        {
                            FileName = myFile.Name, FileToken = token
                        });
                    }
                    catch (FileNotFoundException)
                    {
                        mruList.Remove(token);
                    }
                }
            }
        }
コード例 #2
0
        private void ShowListButton_Click(object sender, RoutedEventArgs e)
        {
            StorageFile file = rootPage.sampleFile;

            if (file != null)
            {
                if (MRURadioButton.IsChecked.Value)
                {
                    AccessListEntryView entries = StorageApplicationPermissions.MostRecentlyUsedList.Entries;
                    if (entries.Count > 0)
                    {
                        StringBuilder outputText = new StringBuilder("The MRU list contains the following item(s):");
                        foreach (AccessListEntry entry in entries)
                        {
                            outputText.AppendLine();
                            outputText.Append(entry.Metadata); // Application previously chose to store file.Name in this field
                        }

                        rootPage.NotifyUser(outputText.ToString(), NotifyType.StatusMessage);
                    }
                    else
                    {
                        rootPage.NotifyUser("The MRU list is empty, please select 'Most Recently Used' list and click 'Add to List' to add a file to the MRU list.", NotifyType.ErrorMessage);
                    }
                }
                else if (FALRadioButton.IsChecked.Value)
                {
                    AccessListEntryView entries = StorageApplicationPermissions.FutureAccessList.Entries;
                    if (entries.Count > 0)
                    {
                        StringBuilder outputText = new StringBuilder("The FAL list contains the following item(s):");
                        foreach (AccessListEntry entry in entries)
                        {
                            outputText.AppendLine();
                            outputText.Append(entry.Metadata); // Application previously chose to store file.Name in this field
                        }

                        rootPage.NotifyUser(outputText.ToString(), NotifyType.StatusMessage);
                    }
                    else
                    {
                        rootPage.NotifyUser("The FAL list is empty, please select 'Future Access List' list and click 'Add to List' to add a file to the FAL list.", NotifyType.ErrorMessage);
                    }
                }
            }
            else
            {
                rootPage.NotifyUserFileNotExist();
            }
        }
コード例 #3
0
ファイル: MainPage.xaml.cs プロジェクト: ayamadori/EmlReader
        private void DeleteItem_Click(object sender, RoutedEventArgs e)
        {
            // https://stackoverflow.com/questions/34445579/how-to-get-listview-item-content-on-righttapped-event-of-an-universal-windows-ap
            AccessListEntry entry = (AccessListEntry)((FrameworkElement)e.OriginalSource).DataContext;
            string          token = entry.Token;

            // Remove from MRU
            // https://docs.microsoft.com/en-us/windows/uwp/files/how-to-track-recently-used-files-and-folders
            var mru = StorageApplicationPermissions.MostRecentlyUsedList;

            mru.Remove(token);
            MruList.ItemsSource = null;
            mruView             = StorageApplicationPermissions.MostRecentlyUsedList.Entries;
            MruList.ItemsSource = mruView;
        }
コード例 #4
0
ファイル: MainPage.xaml.cs プロジェクト: ayamadori/EmlReader
        private async void MruList_Tapped(object sender, Windows.UI.Xaml.Input.TappedRoutedEventArgs e)
        {
            if ((sender as ListView).SelectedItem == null)
            {
                return;
            }
            AccessListEntry entry = (AccessListEntry)(sender as ListView).SelectedItem;
            string          token = entry.Token;

            try
            {
                StorageFile file = await StorageApplicationPermissions.MostRecentlyUsedList.GetItemAsync(token) as StorageFile;

                if (file != null)
                {
                    Frame rootFrame = Window.Current.Content as Frame;
                    rootFrame.Navigate(typeof(MailPage), file);

                    // Add to MRU
                    // https://docs.microsoft.com/en-us/windows/uwp/files/how-to-track-recently-used-files-and-folders
                    var    mru      = StorageApplicationPermissions.MostRecentlyUsedList;
                    string mruToken = mru.Add(file, file.Name);
                    MruList.ItemsSource = null;
                    mruView             = StorageApplicationPermissions.MostRecentlyUsedList.Entries;
                    MruList.ItemsSource = mruView;
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.ToString());

                ContentDialog dlg = new ContentDialog()
                {
                    Title = $"\"{entry.Metadata}\" is not available", Content = "Selected file may be moved/renamed/deleted.", CloseButtonText = "OK"
                };
                _ = dlg.ShowAsync();

                // Remove from MRU
                // https://docs.microsoft.com/en-us/windows/uwp/files/how-to-track-recently-used-files-and-folders
                var mru = StorageApplicationPermissions.MostRecentlyUsedList;
                mru.Remove(token);
                MruList.ItemsSource = null;
                mruView             = StorageApplicationPermissions.MostRecentlyUsedList.Entries;
                MruList.ItemsSource = mruView;
            }
        }
コード例 #5
0
        async internal void checkMRU()
        {
            AccessListEntryView entries    = StorageApplicationPermissions.MostRecentlyUsedList.Entries;
            StringBuilder       outputText = new StringBuilder("The MRU list contains the following items:\n\n");

            foreach (AccessListEntry entry in entries)
            {
                try
                {
                    StorageFile storageFile = await StorageApplicationPermissions.MostRecentlyUsedList.GetFileAsync(entry.Token);

                    outputText.Append(storageFile.DisplayName + "\n");
                }
                catch { }
            }
            this.txtContent.Text += outputText.ToString();
        }
コード例 #6
0
ファイル: MainPage.xaml.cs プロジェクト: ayamadori/EmlReader
        private async void OpenWindowButton_Click(object sender, RoutedEventArgs e)
        {
            // https://stackoverflow.com/questions/34445579/how-to-get-listview-item-content-on-righttapped-event-of-an-universal-windows-ap
            AccessListEntry entry = (AccessListEntry)((FrameworkElement)e.OriginalSource).DataContext;
            string          token = entry.Token;

            try
            {
                StorageFile file = await StorageApplicationPermissions.MostRecentlyUsedList.GetItemAsync(token) as StorageFile;

                if (file != null)
                {
                    // Open file on this app
                    var options = new LauncherOptions();
                    options.TargetApplicationPackageFamilyName = Package.Current.Id.FamilyName;
                    await Launcher.LaunchFileAsync(file, options);

                    // Add to MRU
                    // https://docs.microsoft.com/en-us/windows/uwp/files/how-to-track-recently-used-files-and-folders
                    var    mru      = StorageApplicationPermissions.MostRecentlyUsedList;
                    string mruToken = mru.Add(file, file.Name);
                    MruList.ItemsSource = null;
                    mruView             = StorageApplicationPermissions.MostRecentlyUsedList.Entries;
                    MruList.ItemsSource = mruView;
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.ToString());

                ContentDialog dlg = new ContentDialog()
                {
                    Title = $"\"{entry.Metadata}\" is not available", Content = "Selected file may be moved/renamed/deleted.", CloseButtonText = "OK"
                };
                _ = dlg.ShowAsync();

                // Remove from MRU
                // https://docs.microsoft.com/en-us/windows/uwp/files/how-to-track-recently-used-files-and-folders
                var mru = StorageApplicationPermissions.MostRecentlyUsedList;
                mru.Remove(token);
                MruList.ItemsSource = null;
                mruView             = StorageApplicationPermissions.MostRecentlyUsedList.Entries;
                MruList.ItemsSource = mruView;
            }
        }
コード例 #7
0
        private void ShowListButton_Click(object sender, RoutedEventArgs e)
        {
            rootPage.ResetScenarioOutput(OutputTextBlock);
            StorageFile file = rootPage.sampleFile;

            if (file != null)
            {
                if (MRURadioButton.IsChecked.Value)
                {
                    AccessListEntryView entries = StorageApplicationPermissions.MostRecentlyUsedList.Entries;
                    if (entries.Count > 0)
                    {
                        StringBuilder outputText = new StringBuilder("The MRU list contains the following item(s):" + Environment.NewLine + Environment.NewLine);
                        foreach (AccessListEntry entry in entries)
                        {
                            outputText.AppendLine(entry.Metadata); // Application previously chose to store file.Name in this field
                        }

                        OutputTextBlock.Text = outputText.ToString();
                    }
                    else
                    {
                        OutputTextBlock.Text = "The MRU list is empty, please select 'Most Recently Used' list and click 'Add to List' to add a file to the MRU list.";
                    }
                }
                else if (FALRadioButton.IsChecked.Value)
                {
                    AccessListEntryView entries = StorageApplicationPermissions.FutureAccessList.Entries;
                    if (entries.Count > 0)
                    {
                        StringBuilder outputText = new StringBuilder("The FAL list contains the following item(s):" + Environment.NewLine + Environment.NewLine);
                        foreach (AccessListEntry entry in entries)
                        {
                            outputText.AppendLine(entry.Metadata); // Application previously chose to store file.Name in this field
                        }

                        OutputTextBlock.Text = outputText.ToString();
                    }
                    else
                    {
                        OutputTextBlock.Text = "The FAL list is empty, please select 'Future Access List' list and click 'Add to List' to add a file to the FAL list.";
                    }
                }
            }
        }
コード例 #8
0
ファイル: PageMain.xaml.cs プロジェクト: mpalka/Libra
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            base.OnNavigatedTo(e);
            // Remove ads if purchased
            if (App.licenseInformation.ProductLicenses["removedAds"].IsActive)
            {
                RemoveAds();
            }
            // Show most recent files
            mruFiles = new ObservableCollection <RecentFile>();
            AccessListEntryView mruEntries = null;

            if ((bool)App.AppSettings[App.SHOW_RECENT_FILES])
            {
                mruEntries = StorageApplicationPermissions.MostRecentlyUsedList.Entries;
            }
            // If no recent file
            if (mruEntries == null || mruEntries.Count == 0)
            {
                this.recentFileTitle.Text = "No Recent File.";
                this.OpenNew.Content      = "Open a File...";
                AppEventSource.Log.Debug("MainPage: No recent file found.");
            }
            else
            {
                // Show a list of recent used file
                for (int i = 0; i < mruEntries.Count; i++)
                {
                    AccessListEntry entry = mruEntries[i];
                    RecentFile      file  = new RecentFile(entry.Token);
                    string[]        split = entry.Metadata.Split(new string[] { MRU_DELIMITER }, 2, StringSplitOptions.RemoveEmptyEntries);
                    file.Filename       = split[0];
                    file.LastAccessTime = Convert.ToDateTime(split[1]);
                    file.Identifier     = PREFIX_RECENT_FILE + i.ToString();
                    mruFiles.Add(file);
                    if (i == 10)
                    {
                        break;
                    }
                }
                this.RecentFileList.DataContext = mruFiles;
                AppEventSource.Log.Debug("MainPage: Recent files added.");
            }
        }
コード例 #9
0
ファイル: TokenDemo.xaml.cs プロジェクト: webabcd/Windows10
        private async void btnGetMostRecentlyUsedList_Click(object sender, RoutedEventArgs e)
        {
            AccessListEntryView entries = StorageApplicationPermissions.MostRecentlyUsedList.Entries;

            if (entries.Count > 0)
            {
                // 通过 token 值,从“最近访问列表”中获取文件对象
                AccessListEntry entry       = entries[0];
                StorageFile     storageFile = await StorageApplicationPermissions.MostRecentlyUsedList.GetFileAsync(entry.Token);

                string textContent = await FileIO.ReadTextAsync(storageFile);

                lblMsg.Text = "MostRecentlyUsedList 的第一个文件的文本内容:" + textContent;
            }
            else
            {
                lblMsg.Text = "最近访问列表中无数据";
            }
        }
コード例 #10
0
        public async void getRecentFiles()
        {
            AccessListEntryView entries = StorageApplicationPermissions.MostRecentlyUsedList.Entries;

            //存放得到的recent歌曲
            songs = new ObservableCollection <Song>();
            if (entries.Count > 0)
            {
                songs.Clear();
                foreach (AccessListEntry entry in entries)
                {
                    StorageFile file = await StorageApplicationPermissions.MostRecentlyUsedList.GetFileAsync(entry.Token);

                    Song s = await file.ToSong();

                    songs.Add(s);
                }
            }
        }
コード例 #11
0
        public static List <string> GetTokenList(DataType type)
        {
            AccessListEntryView entries = getEntryFromType(type);
            List <string>       resultList;

            if (type == DataType.Latest)
            {
                resultList = entries.OrderByDescending(entry => entry.Metadata)
                             .Select(entry => entry.Token)
                             .ToList();
            }
            else
            {
                resultList = entries.Where(entry => entry.Metadata == type.ToString())
                             .Select(entry => entry.Token)
                             .ToList();
            }

            return(resultList);
        }
コード例 #12
0
        public static void RemoveAll(DataType type)
        {
            AccessListEntryView entries = getEntryFromType(type);

            if (type == DataType.Latest)
            {
                foreach (AccessListEntry entry in entries)
                {
                    StorageApplicationPermissions.MostRecentlyUsedList.Remove(entry.Token);
                }
            }
            else
            {
                AccessListEntry[] filterList = entries.Where(entry => entry.Metadata == type.ToString()).ToArray();
                foreach (AccessListEntry entry in filterList)
                {
                    StorageApplicationPermissions.FutureAccessList.Remove(entry.Token);
                }
            }
        }
コード例 #13
0
        async public Task init(int numToLoad)
        {
            page.LoadingTxt.Visibility = Windows.UI.Xaml.Visibility.Visible;
            //Create the collection
            NotepadItem item;

            //Iterate through MRU list
            AccessListEntryView entries = StorageApplicationPermissions.MostRecentlyUsedList.Entries;

            ItemCount = 0;
            foreach (AccessListEntry entry in entries)
            {
                try
                {
                    item = new NotepadItem();

                    StorageFile storageFile = await StorageApplicationPermissions.MostRecentlyUsedList.GetFileAsync(entry.Token);

                    item.Title = storageFile.DisplayName;
                    item.Token = entry.Token;

                    if (ItemCount < numToLoad && item.Title != "")
                    {
                        Collection.Add(item);
                        ItemCount++;
                    }

                    //item.FileName = storageFile.Path;
                    IRandomAccessStream txtStream = await storageFile.OpenAsync(FileAccessMode.Read);

                    IInputStream readStream = txtStream.GetInputStreamAt(0);

                    DataReader reader         = new DataReader(readStream);
                    uint       numBytesLoaded = await reader.LoadAsync((uint)txtStream.Size);

                    if (numBytesLoaded > 25)
                    {
                        numBytesLoaded = 25;
                    }
                    item.FileName = reader.ReadString(numBytesLoaded) + "...";
                }
                catch
                {
                    //int i = 0;
                }
            }
            page.LoadingTxt.Visibility = Windows.UI.Xaml.Visibility.Collapsed;
            page.RefreshGridView();

            //iterate through each of them again to reset the list
            ItemCount = 0;
            AccessListEntryView entries2 = StorageApplicationPermissions.MostRecentlyUsedList.Entries;

            foreach (AccessListEntry entry in entries2)
            {
                try
                {
                    if (ItemCount < numToLoad)
                    {
                        ItemCount++; //need to do this to keep the count the same
                    }
                    StorageFile storageFile = await StorageApplicationPermissions.MostRecentlyUsedList.GetFileAsync(entry.Token);
                }
                catch { }
            }
        }
コード例 #14
0
ファイル: MainPage.xaml.cs プロジェクト: ayamadori/EmlReader
 public MainPage()
 {
     this.InitializeComponent();
     mruView = StorageApplicationPermissions.MostRecentlyUsedList.Entries;
 }