自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

Windows Phone開發(fā)(27):隔離存儲(chǔ)A

移動(dòng)開發(fā)
隔離存儲(chǔ)不是WP特有的,在Silverlight或WPF中也有,而且,更準(zhǔn)確地講,“獨(dú)立存儲(chǔ)”在.NET 2.0的時(shí)候已經(jīng)出現(xiàn),可能大家沒有注意到,不信?你可以在.NET類庫中找一下。

在很多資料或書籍上都翻譯為“獨(dú)立存儲(chǔ)”,不過,我想了一下,決定將IsolatedStorage翻譯為“隔離存儲(chǔ)”,我想這樣會(huì)更方便大家對(duì)這一概念的理解。
關(guān)于何為隔離存儲(chǔ),按照固有習(xí)慣,我不希望作太多理論上的解釋,一來理論化的東西容易把簡單的事情變得復(fù)雜化,二來,就算把理論知識(shí)說得有多***,相信大家都沒興趣看,就算你有興趣也會(huì)一頭霧水。

隔離存儲(chǔ)不是WP特有的,在Silverlight或WPF中也有,而且,更準(zhǔn)確地講,“獨(dú)立存儲(chǔ)”在.NET 2.0的時(shí)候已經(jīng)出現(xiàn),可能大家沒有注意到,不信?你可以在.NET類庫中找一下。

以前沒關(guān)注過也沒關(guān)系,隔離存儲(chǔ)其實(shí)是很簡單的,說白了就是Windows Phone上面的目錄和文件管理,在Windows平臺(tái)上,這些操作相信做過.NET開發(fā)的朋友們都肯定玩得很熟了。

Windows phone的目錄和文件管理方式與過去Windows CE或Windows Mobile是不同的,過去在這兩個(gè)OS上都是使用相對(duì)路徑,而其操作方法與PC系統(tǒng)相近;而WP則不同,盡管也是使用相對(duì)路徑,但操作方式和原理不同。

這就是我為什么要翻譯成“隔離存儲(chǔ)”了,這樣一來,大家從字面上就可以猜出它的特征了,每個(gè)應(yīng)用程序只能訪問其獨(dú)立的存儲(chǔ)空間,你不能去訪問其它應(yīng)用程序的目錄和結(jié)構(gòu),也不能訪問基礎(chǔ)操作系統(tǒng)的目錄和文件,這就大大提高了安全性。

好的,下面我們只需要一個(gè)簡單的示例,大家就會(huì)明白了。
示例允許你輸入一個(gè)目錄名稱,點(diǎn)擊“創(chuàng)建后”,將在隔離存儲(chǔ)中創(chuàng)建一個(gè)目錄,然后點(diǎn)擊第二個(gè)按鈕,可以檢測(cè)目錄是否存在,第三個(gè)按鈕用于刪除目錄。

  1. <phone:PhoneApplicationPage  
  2.     x:Class="IsoStorageSample1.MainPage" 
  3.     xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
  4.     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
  5.     xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone" 
  6.     xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone" 
  7.     xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
  8.     xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
  9.     mc:Ignorable="d" d:DesignWidth="480" d:DesignHeight="768" 
  10.     FontFamily="{StaticResource PhoneFontFamilyNormal}" 
  11.     FontSize="{StaticResource PhoneFontSizeNormal}" 
  12.     Foreground="{StaticResource PhoneForegroundBrush}" 
  13.     SupportedOrientations="Portrait" Orientation="Portrait" 
  14.     shell:SystemTray.IsVisible="True"
  15.     <!--LayoutRoot 是包含所有頁面內(nèi)容的根網(wǎng)格--> 
  16.     <Grid x:Name="LayoutRoot" Background="Transparent"
  17.         <Grid.RowDefinitions> 
  18.             <RowDefinition Height="Auto"/> 
  19.             <RowDefinition Height="*"/> 
  20.         </Grid.RowDefinitions> 
  21.         <!--TitlePanel 包含應(yīng)用程序的名稱和頁標(biāo)題--> 
  22.         <StackPanel x:Name="TitlePanel" Grid.Row="0" Margin="12,17,0,28"
  23.             <TextBlock x:Name="ApplicationTitle" Text="我的應(yīng)用程序" Style="{StaticResource PhoneTextNormalStyle}"/> 
  24.             <TextBlock x:Name="PageTitle" Text="隔離存儲(chǔ)" Margin="9,-7,0,0" Style="{StaticResource PhoneTextTitle1Style}"/> 
  25.         </StackPanel> 
  26.         <!--ContentPanel - 在此處放置其他內(nèi)容--> 
  27.         <Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0"
  28.             <TextBox Height="72" HorizontalAlignment="Left" Margin="12,25,0,0" Name="txtDirName" VerticalAlignment="Top" Width="289" /> 
  29.             <Button Content="創(chuàng)建" Height="72" HorizontalAlignment="Left" Margin="307,25,0,0" Name="btnCreate" VerticalAlignment="Top" Width="127" Click="btnCreate_Click" /> 
  30.             <Button Content="檢測(cè)目錄是否已存在" Height="72" HorizontalAlignment="Left" Margin="146,120,0,0" Name="btnCheck" VerticalAlignment="Top" Width="276" Click="btnCheck_Click" /> 
  31.             <Button Content="刪除目錄" Height="72" HorizontalAlignment="Left" Margin="0,283,0,0" Name="btnDel" VerticalAlignment="Top" Width="422" Click="btnDel_Click" /> 
  32.             <TextBlock Height="38" HorizontalAlignment="Left" Margin="9,138,0,0" Name="tbDisplay" VerticalAlignment="Top" Width="131" /> 
  33.         </Grid> 
  34.     </Grid> 
  35. </phone:PhoneApplicationPage>
  1. private void btnCreate_Click(object sender, RoutedEventArgs e) 
  2.     // 通過GetUserStoreForApplication靜態(tài)方法,可以返回一個(gè)IsolatedStorageFile實(shí)例。 
  3.     IsolatedStorageFile iso = IsolatedStorageFile.GetUserStoreForApplication(); 
  4.     try 
  5.     { 
  6.         if (iso.DirectoryExists(txtDirName.Text)) 
  7.         { 
  8.             return
  9.         } 
  10.         iso.CreateDirectory(this.txtDirName.Text); 
  11.     } 
  12.     catch 
  13.     { MessageBox.Show("Error !"); } 
  14. private void btnCheck_Click(object sender, RoutedEventArgs e) 
  15.     IsolatedStorageFile iso = IsolatedStorageFile.GetUserStoreForApplication(); 
  16.     bool exists = iso.DirectoryExists(txtDirName.Text); 
  17.     if (exists) 
  18.     { 
  19.         this.tbDisplay.Text="已存在"
  20.     } 
  21.     else 
  22.     { 
  23.         this.tbDisplay.Text = "不存在"
  24.     } 
  25. private void btnDel_Click(object sender, RoutedEventArgs e) 
  26.     IsolatedStorageFile iso = IsolatedStorageFile.GetUserStoreForApplication(); 
  27.     try 
  28.     { 
  29.         iso.DeleteDirectory(txtDirName.Text); 
  30.     } 
  31.     catch 
  32.     { 
  33.         MessageBox.Show("Error !"); 
  34.     } 

注意,要引入System.IO.IsolatedStorage命名空間。

責(zé)任編輯:閆佳明 來源: oschina
相關(guān)推薦

2013-04-19 16:05:52

Windows PhoWindows Pho

2013-04-19 16:14:36

Windows PhoWindows Pho

2014-12-22 14:21:57

Windows Pho隔離式存儲(chǔ)機(jī)制

2012-08-01 10:26:33

Windows Pho

2013-07-30 12:37:56

Windows PhoWindows Pho

2010-04-21 17:07:54

Windows Pho

2010-12-01 09:01:31

獨(dú)立存儲(chǔ)Windows Pho

2011-06-07 12:42:15

Windows Pho

2013-04-17 14:00:06

Windows PhoWindows Pho

2013-04-16 17:02:50

Windows Pho概論

2013-04-19 16:34:56

Windows PhoWindows Pho

2013-07-30 11:18:37

Windows PhoWindows Pho

2010-04-08 17:40:23

Windows Pho

2013-04-17 13:27:04

Windows PhoWindows Pho

2011-06-07 11:35:38

Windows Pho

2012-08-16 10:35:50

Windows Pho

2013-04-17 14:47:19

Windows PhoWindows Pho

2013-07-31 13:03:51

Windows PhoWindows Pho

2010-07-16 15:29:02

Windows Pho

2010-12-14 18:48:49

微軟
點(diǎn)贊
收藏

51CTO技術(shù)棧公眾號(hào)