격리 저장소(Isolated Storage) - 실습 : 마지막 방문시간 출력하기
.NET프로그래밍/Silverlight 3.0 2009. 12. 15. 13:26 |- 웹브라우저 쿠키와 비슷하게 실버라이트에서 사용하는 사용자 컴퓨터에 저장되는 임시 데이터 저장 공간
- 1~50MB 정도의 공간을 사용 가능
- 사용자의 허락하에 50MB 사용 가능
- 실버라이트 응용 프로그램의 간단한 상태 관리를 위해서 주로 사용
- 실버라이트에서는 '세션', '쿠키'를 사용할 수 없다.
[MainPage.xaml]
<UserControl x:Class="RiaIsolatedStorage.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="400">
<Grid x:Name="LayoutRoot" Background="White">
<StackPanel Orientation="Horizontal">
<TextBlock Text="마지막 방문 시간 : " />
<TextBlock x:Name="lblLastVisit" />
</StackPanel>
<StackPanel>
<Button x:Name="btnAddSpace" Content="저장 공간 늘리기" />
</StackPanel>
</Grid>
</UserControl>
[MainPage.xaml.cs]
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.IO.IsolatedStorage;
namespace RiaIsolatedStorage
{
public partial class MainPage : UserControl
{
public MainPage()
{
InitializeComponent();
this.Loaded += new RoutedEventHandler(MainPage_Loaded);
btnAddSpace.Click += new RoutedEventHandler(btnAddSpace_Click);
}
void btnAddSpace_Click(object sender, RoutedEventArgs e)
{
// 저장 공간 늘리기
IsolatedStorageFile isf = IsolatedStorageFile.GetUserStoreForApplication(); // 현재 공간 가져오기
MessageBox.Show("현재 : " + isf.AvailableFreeSpace.ToString()); // 현재값 출력
long newSize = isf.AvailableFreeSpace + 1048576;
isf.IncreaseQuotaTo(newSize);
}
void MainPage_Loaded(object sender, RoutedEventArgs e)
{
// 마지막 방문 정보가 격리 저장소에 들어있으면 출력, 새롭게 등록
IsolatedStorageSettings iss = IsolatedStorageSettings.ApplicationSettings;
if (iss.Contains("keyLast"))
{
lblLastVisit.Text = iss["keyLast"].ToString(); // 이전에 기록된 값 출력
SetLastVisit(iss);
}
else
{
SetLastVisit(iss); // 처음 방문 또는 이전 방문 정보가 제거되었다면...
}
}
private static void SetLastVisit(IsolatedStorageSettings iss)
{
iss["keyLast"] = DateTime.Now; // 현재시간으로 재설정
}
}
}
'.NET프로그래밍 > Silverlight 3.0' 카테고리의 다른 글
실습 : 방명록 (0) | 2009.12.16 |
---|---|
Open File Dialog 컨트롤 (0) | 2009.12.15 |
ChildWindow로 모달 팝업 구현 (0) | 2009.12.15 |
Popup 컨트롤 - 컨트롤과 코드 기반으로 팝업 출력 (0) | 2009.12.15 |
Microsoft의 무료 실버라이트 배포 공간 (0) | 2009.12.15 |