- 웹브라우저 쿠키와 비슷하게 실버라이트에서 사용하는 사용자 컴퓨터에 저장되는 임시 데이터 저장 공간

- 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; // 현재시간으로 재설정

        }

    }

}

 

 


















Posted by holland14
: