Mega Code Archive

 
Categories / Silverlight / Data
 

Creating a file quota bar associated with the users isolated storage area

<UserControl x:Class='SilverlightApplication3.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:DesignWidth='640'      d:DesignHeight='480'>     <Canvas x:Name="LayoutRoot" Background="White">         <Rectangle x:Name="maximumRectangle" Width="1" Height="20" Fill="#FFFFFFFF" Stroke="#FF000000" Canvas.Left="1" Canvas.Top="5" RadiusX="5" RadiusY="5"/>         <Rectangle x:Name="currentRectangle" Width="1" Height="20" Stroke="#FF000000" Canvas.Left="1" Canvas.Top="5" RadiusX="5" RadiusY="5" StrokeThickness="0">             <Rectangle.Fill>                 <LinearGradientBrush EndPoint="0.5,1.35" StartPoint="0.5,-0.3">                     <GradientStop Color="#FF54CDEA" Offset="0"/>                     <GradientStop Color="#FF017328" Offset="0.5"/>                     <GradientStop Color="#FF54CDEA" Offset="1"/>                 </LinearGradientBrush>             </Rectangle.Fill>         </Rectangle>     </Canvas> </UserControl> //File: Page.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; using System.Text; namespace SilverlightApplication3 {     public partial class MainPage : UserControl     {         public MainPage()         {             InitializeComponent();             using (IsolatedStorageFile isoFile =  IsolatedStorageFile.GetUserStoreForApplication())             {                 if (isoFile.FileExists("binaryFile1"))                     isoFile.DeleteFile("binaryFile1");                                      Random random = new Random();                 int size = random.Next(Convert.ToInt32(isoFile.Quota)-1);                 string randomString = CreateRandomString(size);                 IsolatedStorageFileStream fileStream = isoFile.CreateFile("binaryFile1");                 byte[] bytes = System.Text.Encoding.Unicode.GetBytes(randomString);                 fileStream.Write(bytes, 0, randomString.Length);                 fileStream.Close();                 double usedSpace = isoFile.Quota - isoFile.AvailableFreeSpace;                         maximumRectangle.Width = (isoFile.Quota / 10024) * 2;                                  currentRectangle.Width = (usedSpace / 10024) * 2;                                  }         }         private string CreateRandomString(int size)         {             StringBuilder builder = new StringBuilder();             Random random = new Random();                          char c;             for (int i = 0; i < size; i++)             {                 c = Convert.ToChar(Convert.ToInt32(Math.Floor(26 * random.NextDouble() + 65)));                 builder.Append(c);             }             return builder.ToString();         }     } }