void MainPage_Loaded(object sender, RoutedEventArgs e)
        {
            // Load isolated storage file
            _isofile = IsolatedStorageFile.GetUserStoreForApplication();

            // Display isolated storage file info
            RefreshAvailableSize();

            // Load isolated storage treeview ViewModel
            _isoroot = LoadIsoRoot();

            // Display treeview
            tvIsolatedStorage.ItemsSource = new ObservableCollection <IsoFile> {
                _isoroot
            };

            // Retrieve last login date from IsolatedStorageSettings
            if (IsolatedStorageSettings.ApplicationSettings.Contains("lastLogin"))
            {
                var date = IsolatedStorageSettings.ApplicationSettings["lastLogin"].ToString();
                tbAppInfo.Text = "Last time this application ran was: " + date;
            }
            else
            {
                tbAppInfo.Text = "Last time this application ran is not known.";
            }
            // Save login time in IsolatedStorageSettings
            IsolatedStorageSettings.ApplicationSettings["lastLogin"] = DateTime.Now;

            // Update operation panel
            UpdateOperationPanel();
        }
 // Helper method: get parent directory
 IsoDirectory GetParentDir(IsoDirectory root, IsoFile child)
 {
     if (string.IsNullOrEmpty(child.FilePath))
     {
         return(null);
     }
     else
     {
         string[]     dirs = child.FilePath.Split('/');
         IsoDirectory cur  = root;
         for (int i = 1; i < dirs.Length - 1; i++)
         {
             IsoDirectory next = cur.Children.FirstOrDefault(dir => dir.FileName == dirs[i]) as IsoDirectory;
             if (next != null)
             {
                 cur = next;
             }
             else
             {
                 return(null);
             }
         }
         return(cur);
     }
 }
        // Load isolated storage view model
        IsoDirectory LoadIsoRoot()
        {
            var root = new IsoDirectory("Root", null);

            AddFileToDirectory(root, _isofile);
            return(root);
        }
        // Add dir/file recursively
        void AddFileToDirectory(IsoDirectory dir, IsolatedStorageFile isf)
        {
            string[] childrendir, childrenfile;
            if (string.IsNullOrEmpty(dir.FilePath))
            {
                childrendir  = isf.GetDirectoryNames();
                childrenfile = isf.GetFileNames();
            }
            else
            {
                childrendir  = isf.GetDirectoryNames(dir.FilePath + "/");
                childrenfile = isf.GetFileNames(dir.FilePath + "/");
            }

            // Add directory entity
            foreach (var dirname in childrendir)
            {
                var childdir = new IsoDirectory(dirname, dir.FilePath + "/" + dirname);
                AddFileToDirectory(childdir, isf);
                dir.Children.Add(childdir);
            }

            // Add file entity
            foreach (var filename in childrenfile)
            {
                dir.Children.Add(new IsoFile(filename, dir.FilePath + "/" + filename));
            }
        }
Example #5
0
        void MainPage_Loaded(object sender, RoutedEventArgs e)
        {
            // 加载独立存储器文件
            _isofile = IsolatedStorageFile.GetUserStoreForApplication();

            // 显示独立存储器文件信息
            RefreshAvailableSize();

            // 加载独立存储器树目录查看模型
            _isoroot = LoadIsoRoot();

            // 显示树目录
            tvIsolatedStorage.ItemsSource = new ObservableCollection <IsoFile> {
                _isoroot
            };

            // 从IsolatedStorageSettings取得上次登陆时间
            if (IsolatedStorageSettings.ApplicationSettings.Contains("lastLogin"))
            {
                var date = IsolatedStorageSettings.ApplicationSettings["lastLogin"].ToString();
                tbAppInfo.Text = "上次本应用程序运行时间为: " + date;
            }
            else
            {
                tbAppInfo.Text = "没有上次本应用程序运行时间。";
            }
            // 保存登陆时间到IsolatedStorageSettings
            IsolatedStorageSettings.ApplicationSettings["lastLogin"] = DateTime.Now;

            // 更新操作面板
            UpdateOperationPanel();
        }
Example #6
0
        void MainPage_Loaded(object sender, RoutedEventArgs e)
        {
            // 加载独立存储器文件
            _isofile = IsolatedStorageFile.GetUserStoreForApplication();

            // 显示独立存储器文件信息
            RefreshAvailableSize();

            // 加载独立存储器树目录查看模型
            _isoroot = LoadIsoRoot();

            // 显示树目录
            tvIsolatedStorage.ItemsSource = new ObservableCollection<IsoFile> { _isoroot };

            // 从IsolatedStorageSettings取得上次登陆时间
            if (IsolatedStorageSettings.ApplicationSettings.Contains("lastLogin"))
            {
                var date = IsolatedStorageSettings.ApplicationSettings["lastLogin"].ToString();
                tbAppInfo.Text = "上次本应用程序运行时间为: "+date;
            }
            else
                tbAppInfo.Text = "没有上次本应用程序运行时间。";
            // 保存登陆时间到IsolatedStorageSettings
            IsolatedStorageSettings.ApplicationSettings["lastLogin"] = DateTime.Now;

            // 更新操作面板
            UpdateOperationPanel();
        }
Example #7
0
 // 加载独立存储器查看模型
 IsoDirectory LoadIsoRoot()
 {
     var root = new IsoDirectory("Root", null);
     AddFileToDirectory(root, _isofile);
     return root;
 }
Example #8
0
 // Helper 方法: 取得父目录
 IsoDirectory GetParentDir(IsoDirectory root, IsoFile child)
 {
     if (string.IsNullOrEmpty(child.FilePath))
         return null;
     else
     {
         string[] dirs = child.FilePath.Split('/');
         IsoDirectory cur = root;
         for (int i = 1; i < dirs.Length - 1; i++)
         {
             IsoDirectory next = cur.Children.FirstOrDefault(dir => dir.FileName == dirs[i]) as IsoDirectory;
             if (next != null)
                 cur = next;
             else
                 return null;
         }
         return cur;
     }
 }
Example #9
0
        // 用递归方法增加目录/文件
        void AddFileToDirectory(IsoDirectory dir, IsolatedStorageFile isf)
        {
            string[] childrendir, childrenfile;
            if (string.IsNullOrEmpty(dir.FilePath))
            {
                childrendir = isf.GetDirectoryNames();
                childrenfile = isf.GetFileNames();
            }
            else
            {
                childrendir = isf.GetDirectoryNames(dir.FilePath + "/");
                childrenfile = isf.GetFileNames(dir.FilePath + "/");
            }

            // 增加目录实体
            foreach (var dirname in childrendir)
            {
                var childdir = new IsoDirectory(dirname, dir.FilePath + "/" + dirname);
                AddFileToDirectory(childdir, isf);
                dir.Children.Add(childdir);
            }

            // 增加文件实体
            foreach (var filename in childrenfile)
            {
                dir.Children.Add(new IsoFile(filename, dir.FilePath + "/" + filename));
            }
        }