Exemple #1
0
        private void _Initialize()
        {
            IsolatedStorageFile       filesystem = null;
            IsolatedStorageFileStream fs         = null;

            try
            {
                filesystem = IsolatedStorageFile.GetUserStoreForApplication();

                if (!filesystem.FileExists(CONTACTS_CACHE))
                {
                    _contacts = new List <PhoneContact>();
                }
                else
                {
                    fs = new IsolatedStorageFileStream(CONTACTS_CACHE, FileMode.Open, filesystem);

                    var serializer = new DataContractJsonSerializer(typeof(List <PhoneContact>));
                    _contacts = serializer.ReadObject(fs) as List <PhoneContact>;
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine("Cannot initialize contacts cache: " + ex.Message);
            }
            finally
            {
                if (filesystem != null)
                {
                    filesystem.Dispose();
                }

                if (fs != null)
                {
                    fs.Dispose();
                }
            }
        }
        private void _Initialize()
        {
            IsolatedStorageFile       filesystem = null;
            IsolatedStorageFileStream fs         = null;

            try
            {
                filesystem = IsolatedStorageFile.GetUserStoreForApplication();

                if (!filesystem.FileExists(MESSAGES_CACHE))
                {
                    _messages = new Dictionary <int, List <Message> >();
                }
                else
                {
                    fs = new IsolatedStorageFileStream(MESSAGES_CACHE, FileMode.Open, filesystem);

                    var serializer = new DataContractJsonSerializer(typeof(IDictionary <int, List <Message> >), _knownTypes);
                    _messages = serializer.ReadObject(fs) as IDictionary <int, List <Message> >;
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine("Cannot initialize messages cache: " + ex.Message);
            }
            finally
            {
                if (filesystem != null)
                {
                    filesystem.Dispose();
                }

                if (fs != null)
                {
                    fs.Dispose();
                }
            }
        }
Exemple #3
0
        private BitmapImage _LoadImage(string filename)
        {
            BitmapImage               image      = null;
            IsolatedStorageFile       filesystem = null;
            IsolatedStorageFileStream fs         = null;

            try
            {
                filesystem = IsolatedStorageFile.GetUserStoreForApplication();
                filename   = filename + ".jpg";
                if (filesystem.FileExists(filename))
                {
                    fs = new IsolatedStorageFileStream(filename, FileMode.Open, filesystem);

                    image = new BitmapImage();

                    image.SetSource(fs);
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine("_LoadImage error: " + ex.Message);
            }
            finally
            {
                if (filesystem != null)
                {
                    filesystem.Dispose();
                }

                if (fs != null)
                {
                    fs.Dispose();
                }
            }

            return(image);
        }
		public void FileExists ()
		{
			IsolatedStorageFile isf = IsolatedStorageFile.GetUserStoreForAssembly ();
			IsolatedStorageFileStream file_a = new IsolatedStorageFileStream ("file-a", FileMode.Create, isf);
			IsolatedStorageFileStream file_b = new IsolatedStorageFileStream ("file-b", FileMode.Create, isf);
			file_a.Close ();
			file_b.Close ();

			Assert.AreEqual (true, isf.FileExists ("file-a"), "#A0");
			Assert.AreEqual (true, isf.FileExists ("file-b"), "#A1");
			Assert.AreEqual (false, isf.FileExists (String.Empty), "#A2");
			Assert.AreEqual (false, isf.FileExists ("file-"), "#A3");
			Assert.AreEqual (false, isf.FileExists ("file-*"), "#A4");
			Assert.AreEqual (false, isf.FileExists ("../../file-a"), "#A5");

			isf.CreateDirectory ("subdir");
			Assert.AreEqual (false, isf.FileExists ("subdir"), "#B0");

			try {
				isf.FileExists (null);
				Assert.Fail ("#Exc1");
			} catch (ArgumentNullException) {
			}

			isf.Close ();
			try {
				isf.FileExists ("file-a");
				Assert.Fail ("#Exc2");
			} catch (InvalidOperationException) {
			}

			isf.Dispose ();
			try {
				isf.FileExists ("file-a");
				Assert.Fail ("#Exc3");
			} catch (ObjectDisposedException) {
			}
		}
Exemple #5
0
        /// <summary>
        /// Returns a Stream representing the full resolution image.
        /// </summary>
        /// <returns>Stream of the full resolution image.</returns>
        public Stream GetImage()
        {
            Stream imageFileStream = null;

            using (IsolatedStorageFile store = IsolatedStorageFile.GetUserStoreForApplication())
            {
                try
                {
                    imageFileStream = store.OpenFile(
                        ImageFileName,
                        FileMode.Open,
                        FileAccess.Read,
                        FileShare.Delete | FileShare.Read);
                    imageFileStream.Seek(0, SeekOrigin.Begin);
                }
                catch
                {
                }
                store.Dispose();
            }

            return(imageFileStream);
        }
Exemple #6
0
        public void StopRecordToTempFile(string tempFileKey)
        {
            //if (tempFileKey == this.tempFileKey)
            //{
            GetRecordedData();
            _microphone.Stop();

            isf.Dispose();
            if (tempFileStream != null)
            {
                tempFileStream.Close();
                tempFileStream.Dispose();
                tempFileStream = null;
            }
            this.tempFileKey = null;

            return;

#if DEBUG
            Debug.WriteLine("file stop fail");
#endif
            // }
        }
 public static void SaveIsoStorageData(String fileName, String fieData)
 {
     try
     {
         IsolatedStorageFile isoFile = IsolatedStorageFile.GetUserStoreForApplication();
         if (isoFile.FileExists(fileName))
         {
             isoFile.DeleteFile(fileName);
         }
         IsolatedStorageFileStream file = isoFile.CreateFile(fileName);
         if (!"".Equals(fieData))
         {
             Byte[] byteArray = Encoding.UTF8.GetBytes(fieData);
             file.Write(byteArray, 0, byteArray.Length);
         }
         file.Close();
         file.Dispose();
         isoFile.Dispose();
     }
     catch (Exception)
     {
     }
 }
Exemple #8
0
        public static Stream StreamFileFromIsoStore(string filename)
        {
            Stream stream;
            IsolatedStorageFile userStoreForApplication = IsolatedStorageFile.GetUserStoreForApplication();
            IsolatedStorageFile file2 = userStoreForApplication;

            try
            {
                stream = userStoreForApplication.OpenFile(filename, FileMode.Open, FileAccess.Read, FileShare.Read);
            }
            catch
            {
                stream = null;
            }
            finally
            {
                if (file2 != null)
                {
                    file2.Dispose();
                }
            }
            return(stream);
        }
Exemple #9
0
        private static bool _SaveJpeg(WriteableBitmap image, string filename)
        {
            IsolatedStorageFile       filesystem = null;
            IsolatedStorageFileStream fs         = null;
            bool result = false;

            try
            {
                filesystem = IsolatedStorageFile.GetUserStoreForApplication();

                if (!filesystem.FileExists(filename + ".jpg"))
                {
                    fs = new IsolatedStorageFileStream(filename + ".jpg", FileMode.CreateNew, filesystem);
                    image.SaveJpeg(fs, PICTURE_DIMENSION, PICTURE_DIMENSION, 0, 70);
                }

                result = true;
            }
            catch (Exception ex)
            {
                Debug.WriteLine("_SaveJpeg failed: " + ex.Message);
            }
            finally
            {
                if (filesystem != null)
                {
                    filesystem.Dispose();
                }

                if (fs != null)
                {
                    fs.Dispose();
                }
            }

            return(result);
        }
Exemple #10
0
        public void DirectoryExists()
        {
            IsolatedStorageFile isf = IsolatedStorageFile.GetUserStoreForApplication();

            Assert.Throws <NullReferenceException> (delegate {
                isf.DirectoryExists(null);
            }, "null");
            Assert.IsTrue(isf.DirectoryExists(String.Empty), "Empty");

            Assert.IsFalse(isf.DirectoryExists("does not exists"), "DirectoryExists(doesnotexists)");
            Assert.IsFalse(isf.DirectoryExists("dir-exist"), "DirectoryExists(dir-exist)");
            string[] dirs = isf.GetDirectoryNames();
            int      ndir = dirs.Length;

            try {
                isf.CreateDirectory("dir-exist");
                Assert.IsTrue(isf.DirectoryExists("dir-exist"), "DirectoryExists(dir-exist)");
                Assert.AreEqual(ndir + 1, isf.GetDirectoryNames().Length, "GetDirectoryNames");
                dirs = isf.GetDirectoryNames("dir-exist");
                Assert.AreEqual(1, dirs.Length, "Length");
                // make sure we're not leaking the full path to the directory
                Assert.AreEqual("dir-exist", dirs [0], "dir-exist");
            }
            finally {
                isf.DeleteDirectory("dir-exist");
                Assert.IsFalse(isf.DirectoryExists("dir-exist"), "Delete/Exists(dir-exist)");
                Assert.AreEqual(ndir, isf.GetDirectoryNames().Length, "Delete/GetDirectoryNames");
                dirs = isf.GetDirectoryNames("dir-exist");
                Assert.AreEqual(0, dirs.Length, "Delete/Length");
            }

            isf.Remove();
            Assert.Throws(delegate { isf.DirectoryExists("does not exists"); }, typeof(IsolatedStorageException), "Remove");

            isf.Dispose();
            Assert.Throws(delegate { isf.DirectoryExists("does not exists"); }, typeof(ObjectDisposedException), "Dispose");
        }
Exemple #11
0
        private async void encode(object sender, RoutedEventArgs e)
        {
            // player.Stop();
            LameWrapper lame = new LameWrapper();

            lame.InitialLame(44100, 44100, 2, 5);
            IsolatedStorageFile isf = IsolatedStorageFile.GetUserStoreForApplication();

            using (IsolatedStorageFileStream WorkStream = isf.CreateFile("encoded_mp3.mp3"))
            {
                using (PCMStream = isf.OpenFile("/decoded_pcm.pcm", FileMode.Open))
                {
                    int totalread = 0;
                    while (PCMStream.Position < PCMStream.Length)
                    {
                        byte[] rawbytes = new byte[65536];

                        int actualcount = PCMStream.Read(rawbytes, 0, 65536);
                        //  MessageBox.Show("read:" + actualcount);
                        totalread         += actualcount;
                        PCMStream.Position = totalread;
                        IBuffer PCMSampleBuffer = WindowsRuntimeBufferExtensions.AsBuffer(rawbytes, 0, rawbytes.Length);

                        CompressedMp3Content citem = await lame.EncodePcm2Mp3(PCMSampleBuffer);

                        //  MessageBox.Show(citem.Mp3Data.Length+"");
                        WorkStream.Write(citem.Mp3Data, 0, citem.Mp3Data.Length);
                        WorkStream.Flush();
                        statustb.Text = "position: " + PCMStream.Position + " total: " + PCMStream.Length;
                    }
                }
            }

            isf.Dispose();
            lame.CloseLame();
        }
Exemple #12
0
        public void DeleteFile()
        {
            IsolatedStorageFile isf = IsolatedStorageFile.GetUserStoreForApplication();

            Assert.Throws <ArgumentNullException> (delegate {
                isf.DeleteFile(null);
            }, "null");
            Assert.Throws <IsolatedStorageException> (delegate {
                isf.DeleteFile(String.Empty);
            }, "Empty");

            Assert.IsFalse(isf.FileExists("file-exist"), "Before/Exists(file-exist)");
            using (IsolatedStorageFileStream s = isf.CreateFile("file-exist")) {
                Assert.IsTrue(isf.FileExists("file-exist"), "After/Exists(file-exist)");
            }
            isf.DeleteFile("file-exist");
            Assert.IsFalse(isf.FileExists("file-exist"), "Delete/Exists(file-exist)");

            isf.Remove();
            Assert.Throws(delegate { isf.DeleteFile("does not exists"); }, typeof(IsolatedStorageException), "Remove");

            isf.Dispose();
            Assert.Throws(delegate { isf.DeleteFile("does not exists"); }, typeof(ObjectDisposedException), "Dispose");
        }
        private void ChangePassword_Click(object sender, RoutedEventArgs e)
        {
            IsolatedStorageFileStream savedPassword = storage.OpenFile("Files/password.txt", FileMode.Open, FileAccess.Read);
            StreamReader reader        = new StreamReader(savedPassword);
            string       olderPassword = reader.ReadLine();

            savedPassword.Close();
            try
            {
                savedPassword = storage.OpenFile("Files/fakepassword.txt", FileMode.Open, FileAccess.Read);
                reader        = new StreamReader(savedPassword);
                fakePassword  = reader.ReadLine();
            }
            catch { }
            reader.Dispose();
            savedPassword.Dispose();


            if (oldPassword.Password == olderPassword & newPassword.Password != "" & newPassword.Password != fakePassword)
            {
                StreamWriter writer = new StreamWriter(new IsolatedStorageFileStream("Files/password.txt", FileMode.Create, FileAccess.Write, storage));
                writer.WriteLine(newPassword.Password);
                writer.Dispose();
                MessageBox.Show("You successfully changed your password");
                storage.Dispose();
                NavigationService.GoBack();
            }
            else if (newPassword.Password == fakePassword)
            {
                MessageBox.Show("You cannot use your fake password as an original password");
            }
            else
            {
                MessageBox.Show("Old password wrong or New Password Box empty");
            }
        }
Exemple #14
0
        //method to remove a favourite
        private void remove_Click(object sender, EventArgs e)
        {
            IsolatedStorageFile file = IsolatedStorageFile.GetUserStoreForApplication();

            if (file.FileExists("state.txt"))// if favourite is present
            {
                //delete file
                file.DeleteFile("state.txt");
                file.Dispose();
                //set values to 0
                fvmintemp.Text = "0";
                fvmaxtemp.Text = "0";
                fvtemp.Text    = "0";
                fvwind.Text    = "0";
                //Display 'No Favourite' in city and country
                fvcity.Text    = "No Favourites";
                fvcountry.Text = "No Favourites";
            }
            else//user clicks remove button even if no favourite was present
            {
                MessageBox.Show("No Favourite has been added yet. Taking you to Add New page");
                NavigationService.Navigate(new Uri("/AddNew.xaml", UriKind.Relative));//Takes the user to AddNew page where he can add a new Favourite
            }
        }
		public void UsedSize ()
		{
			IsolatedStorageFile isf = IsolatedStorageFile.GetUserStoreForAssembly ();
			IsolatedStorageFileStream isfs = isf.CreateFile ("file");
			StreamWriter writer = new StreamWriter (isfs);
			writer.WriteLine ("hello mono");
			writer.Close ();

			Assert.AreEqual (true, isf.UsedSize > 0, "#A0");

			isf.Close ();
			try {
				Console.WriteLine (isf.UsedSize);
				Assert.Fail ("#Exc1");
			} catch (InvalidOperationException) {
			}

			isf.Dispose ();
			try {
				Console.WriteLine (isf.UsedSize);
				Assert.Fail ("#Exc2");
			} catch (ObjectDisposedException) {
			}
		}
 /// <summary>
 /// Performs application-defined tasks associated with freeing,
 /// releasing, or resetting unmanaged resources.
 /// </summary>
 public void Dispose()
 {
     _shpBinaryReader.Close();
     _isolatedStorageFile.Dispose();
 }
Exemple #17
0
        //
        public ViewModel LoadInfoFromXML()
        {
            //目的地データの読み込み。
            IsolatedStorageFile       isoFile = IsolatedStorageFile.GetUserStoreForApplication();
            IsolatedStorageFileStream strm    = new IsolatedStorageFileStream(DBFileName, FileMode.Open, FileAccess.Read, isoFile);
            XDocument xmlDoc = XDocument.Load(strm);

            strm.Dispose();
            isoFile.Dispose();

            var destinations = from destination in xmlDoc.Descendants("Destination")
                               orderby destination.Element("Name").Value
                               select destination;


            ViewModel    PushPinView = new ViewModel();
            PushPinModel pin;//=new PushPinModel();

            bool darkTheme = ((Visibility)Application.Current.Resources["PhoneDarkThemeVisibility"] == Visibility.Visible);

            foreach (var dest in destinations)
            {
                pin = new PushPinModel();
                // if (dest.Element("Latitude").Value == "NaN")
                //   pin.Location = new GeoCoordinate(34,140);
                //else
                if (dest.Element("Latitude").Value != "NaN")
                {
                    pin.Location   = new GeoCoordinate(Convert.ToDouble(dest.Element("Latitude").Value), Convert.ToDouble(dest.Element("Longitude").Value));
                    pin.Name       = dest.Element("Name").Value;
                    pin.IsEnabled  = Convert.ToBoolean(dest.Element("IsEnable").Value);
                    pin.Target     = Convert.ToBoolean(dest.Element("Target").Value);
                    pin.Selected   = Convert.ToBoolean(dest.Element("Selected").Value);
                    pin.Note       = dest.Element("Note").Value;
                    pin.Color      = new SolidColorBrush(Utility.GetColorFromHexString(dest.Element("Color").Value));
                    pin.Visibility = Utility.GetVisibilityFromString(dest.Element("Visibility").Value);
                    try
                    {
                        pin.CreateDate = DateTime.FromFileTime((long)Convert.ToDouble(dest.Element("CreateDate").Value));
                    }
                    catch
                    {
                        pin.CreateDate = DateTime.Parse(dest.Element("CreateDate").Value);
                    }
                    pin.Address  = (dest.Descendants("Address").Count() == 0) ? "" : dest.Element("Address").Value;
                    pin.PhoneNum = (dest.Descendants("PhoneNum").Count() == 0) ? "" : dest.Element("PhoneNum").Value;

                    if (darkTheme == true)//darkの時は白抜きの画像
                    {
                        pin.ArrowURI  = "/Icons/appbar.next.rest.png";
                        pin.CircleURI = "/Icons/appbar.basecircle.rest.png";
                    }
                    else
                    {
                        pin.ArrowURI  = "/Icons/appbar.next.rest.light.png";
                        pin.CircleURI = "/Icons/appbar.base.png";
                    }

                    //MessageBox.Show("l "+pin.Visibility.ToString());
                    PushPinView.PushPins.Add(pin);
                }
            }

            return(PushPinView);
        }
        public void CopyFile()
        {
            IsolatedStorageFile isf = IsolatedStorageFile.GetUserStoreForAssembly();

            if (isf.FileExists("file"))
            {
                isf.DeleteFile("file");
            }
            if (isf.FileExists("file-new"))
            {
                isf.DeleteFile("file-new");
            }

            isf.CreateFile("file").Close();
            isf.CopyFile("file", "file-new");
            Assert.AreEqual(true, isf.FileExists("file"), "#A0");
            Assert.AreEqual(true, isf.FileExists("file-new"), "#A1");

            // At this point 'file-exists' already exists.
            isf.CopyFile("file", "file-new", true);
            Assert.AreEqual(true, isf.FileExists("file"), "#B0");
            Assert.AreEqual(true, isf.FileExists("file-new"), "#B1");

            isf.CreateDirectory("subdir");
            isf.CreateFile("subdir/subfile").Close();
            isf.CopyFile("subdir/subfile", "subdir/subfile-new");
            Assert.AreEqual(true, isf.FileExists("subdir/subfile"), "#C0");
            Assert.AreEqual(true, isf.FileExists("subdir/subfile-new"), "#C1");

            try {
                isf.CopyFile("file", "file-new");
                Assert.Fail("#Exc0");
            } catch (IsolatedStorageException) {
            }

            // Using the same file name is failing for even when passing override=true.
            try {
                isf.CopyFile("file-new", "file-new", true);
                Assert.Fail("#Exc1");
            } catch (IsolatedStorageException) {
            }

            try {
                isf.CopyFile("file-new", "file-new", false);
                Assert.Fail("#Exc2");
            } catch (IsolatedStorageException) {
            }

            // Remove 'file-new' for cleaness purposes.
            isf.DeleteFile("file-new");

            try {
                isf.CopyFile("doesntexist", "file-new", false);
                Assert.Fail("#Exc3");
            } catch (FileNotFoundException) {
            }

            try {
                isf.CopyFile("doesnexist/doesntexist", "file-new", false);
                Assert.Fail("#Exc4");
            } catch (DirectoryNotFoundException) {
            }

            // I'd have expected a DirectoryNotFoundException here.
            try {
                isf.CopyFile("file", "doesntexist/doesntexist");
                Assert.Fail("#Exc5");
            } catch (IsolatedStorageException) {
            }

            // Out of storage dir
            try {
                isf.CopyFile("file", "../../file");
                Assert.Fail("#Exc6");
            } catch (IsolatedStorageException) {
            }

            try {
                isf.CopyFile("../file", "file-new");
                Assert.Fail("#Exc7");
            } catch (IsolatedStorageException) {
            }

            // We are creating a subdirectory and files within it, so remove it just in case.
            isf.Remove();

            isf.Close();
            isf.Dispose();
        }
        public void MoveDirectory()
        {
            IsolatedStorageFile isf = IsolatedStorageFile.GetUserStoreForAssembly();

            // Mare sure to remove them if they exist already
            if (isf.DirectoryExists("subdir"))
            {
                isf.DeleteDirectory("subdir");
            }
            if (isf.DirectoryExists("subdir-new"))
            {
                isf.DeleteDirectory("subdir-new");
            }

            isf.CreateDirectory("subdir");
            Assert.AreEqual(true, isf.DirectoryExists("subdir"), "#A0");

            isf.MoveDirectory("subdir", "subdir-new");
            Assert.AreEqual(false, isf.DirectoryExists("subdir"), "#A1");
            Assert.AreEqual(true, isf.DirectoryExists("subdir-new"), "#A2");

            try {
                isf.MoveDirectory(String.Empty, "subdir-new-new");
                Assert.Fail("#Exc1");
            } catch (ArgumentException) {
            }

            try {
                isf.MoveDirectory("  ", "subdir-new-new");
                Assert.Fail("#Exc2");
            } catch (ArgumentException) {
            }

            try {
                isf.MoveDirectory("doesntexist", "subdir-new-new");
                Assert.Fail("#Exc3");
            } catch (DirectoryNotFoundException) {
            }

            try {
                isf.MoveDirectory("doesnexist/doesntexist", "subdir-new-new");
                Assert.Fail("#Exc4");
            } catch (DirectoryNotFoundException) {
            }

            try {
                isf.MoveDirectory("subdir-new", "doesntexist/doesntexist");
                Assert.Fail("#Exc5");
            } catch (DirectoryNotFoundException) {
            }

            // Out of storage dir
            try {
                isf.MoveDirectory("subdir-new", "../../subdir-new");
                Assert.Fail("#Exc6");
            } catch (IsolatedStorageException) {
            }

            isf.Remove();
            isf.Close();
            isf.Dispose();
        }
        public void MoveFile()
        {
            IsolatedStorageFile isf = IsolatedStorageFile.GetUserStoreForAssembly();

            // Mare sure to remove them if they exist already
            if (isf.FileExists("file"))
            {
                isf.DeleteFile("file");
            }
            if (isf.FileExists("file-new"))
            {
                isf.DeleteFile("file-new");
            }
            if (isf.FileExists("subdir/subfile"))
            {
                isf.DeleteFile("subdir/subfile");
            }
            if (isf.FileExists("subdir/subfile-new"))
            {
                isf.DeleteFile("subdir/subfile-new");
            }

            isf.CreateFile("file").Close();
            Assert.AreEqual(true, isf.FileExists("file"), "#A0");

            // Same file
            isf.MoveFile("file", "file");
            Assert.AreEqual(true, isf.FileExists("file"), "#A0-1");

            isf.MoveFile("file", "file-new");
            Assert.AreEqual(false, isf.FileExists("file"), "#A1");
            Assert.AreEqual(true, isf.FileExists("file-new"), "#A2");

            isf.CreateDirectory("subdir");
            isf.CreateFile("subdir/subfile").Close();
            isf.MoveFile("subdir/subfile", "subdir/subfile-new");
            Assert.AreEqual(false, isf.FileExists("subdir/subfile"), "#B0");
            Assert.AreEqual(true, isf.FileExists("subdir/subfile-new"), "#B1");

            try {
                isf.MoveFile(String.Empty, "file-new-new");
                Assert.Fail("#Exc1");
            } catch (ArgumentException) {
            }

            try {
                isf.MoveFile("  ", "file-new-new");
                Assert.Fail("#Exc2");
            } catch (ArgumentException e) {
                Console.WriteLine(e);
            }

            try {
                isf.MoveFile("doesntexist", "file-new-new");
                Assert.Fail("#Exc3");
            } catch (FileNotFoundException) {
            }

            // CopyFile is throwing a DirectoryNotFoundException here.
            try {
                isf.MoveFile("doesnexist/doesntexist", "file-new-new");
                Assert.Fail("#Exc4");
            } catch (FileNotFoundException) {
            }

            // I'd have expected a DirectoryNotFoundException here.
            try {
                isf.MoveFile("file-new", "doesntexist/doesntexist");
                Assert.Fail("#Exc5");
            } catch (IsolatedStorageException) {
            }

            // Out of storage dir
            try {
                isf.MoveFile("file-new", "../../file-new");
                Assert.Fail("#Exc6");
            } catch (IsolatedStorageException) {
            }

            isf.Remove();
            isf.Close();
            isf.Dispose();
        }
Exemple #21
0
        /// <summary>
        /// Reads the specified file name.
        /// </summary>
        /// <param name="fileName">Name of the file.</param>
        /// <returns></returns>
        public static object Read(string fileName)
        {
            System.Diagnostics.Debug.WriteLine("IsolatedStoreageHelper Read " + fileName);
            object result = null;

            if (IsolatedStorageFile.IsEnabled)
            {
                lock (m_synch)
                {
                    IsolatedStorageFile isoStore = null;
                    try
                    {
                        isoStore = IsolatedStorageFile.GetUserStoreForApplication();

                        if (isoStore.FileExists(fileName))
                        {
                            byte[] buffer = null;
                            using (IsolatedStorageFileStream isoStream = new IsolatedStorageFileStream(fileName, FileMode.Open, FileAccess.Read, isoStore))
                            {
                                buffer = new byte[isoStream.Length];
                                if (isoStream.CanRead)
                                {
                                    isoStream.Read(buffer, 0, buffer.Length);
                                }
                                isoStream.Close();
                            }

                            if (buffer != null)
                            {
                                using (MemoryStream stream = new MemoryStream())
                                {
                                    var decompressedBuffer = UtilityHelper.DeflateUnCompress(buffer);

                                    stream.Write(decompressedBuffer, 0, decompressedBuffer.Length);
                                    stream.Position = 0;

                                    result = UtilityHelper.BinaryDeserialize(stream);
                                }
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        try
                        {
                            string[] fileNames = IsolatedStorageFile.GetUserStoreForApplication().GetFileNames();

                            StringBuilder sb = new StringBuilder();
                            sb.AppendLine(string.Format("IsolatedStoreageHelper Read {0}", fileName));
                            sb.AppendLine(string.Format("Used Size: {0}kb", Math.Round(Convert.ToDouble(IsolatedStorageFile.GetUserStoreForApplication().UsedSize) / 1024d, 2)));
                            if (fileNames != null)
                            {
                                foreach (var filePath in fileNames)
                                {
                                    IsolatedStorageFileStream isoStream = null;
                                    try
                                    {
                                        isoStream = IsolatedStorageFile.GetUserStoreForApplication().OpenFile(filePath, FileMode.Open, FileAccess.ReadWrite);
                                        sb.AppendLine(string.Format("{0}: {1}kb", filePath, Math.Round(Convert.ToDouble(isoStream.Length) / 1024d, 2)));
                                    }
                                    finally
                                    {
                                        if (isoStream != null)
                                        {
                                            isoStream.Dispose();
                                        }
                                    }
                                }
                            }
                            ComponentFactory.Logger.LogError(ex, sb.ToString(), null);
                        }
                        catch (Exception ex1)
                        {
                            ComponentFactory.Logger.LogError(ex1, "Delete IsolatedStorage File error on Read.", null);
                        }
                    }
                    finally
                    {
                        if (isoStore != null)
                        {
                            isoStore.Dispose();
                        }
                    }
                }
            }

            return(result);
        }
Exemple #22
0
        /// <summary>
        /// Writes the specified file name.
        /// </summary>
        /// <param name="fileName">Name of the file.</param>
        /// <param name="data">The data.</param>
        public static void Write(string fileName, object data)
        {
            System.Diagnostics.Debug.WriteLine("IsolatedStoreageHelper Write " + fileName);

            if (IsolatedStorageFile.IsEnabled)
            {
                lock (m_synch)
                {
                    IsolatedStorageFile isoStore = null;
                    try
                    {
                        using (MemoryStream stream = new MemoryStream())
                        {
                            UtilityHelper.BinarySerialize(data, stream);

                            stream.Position = 0;

                            isoStore = IsolatedStorageFile.GetUserStoreForApplication();


                            var buffer = new byte[stream.Length];
                            stream.Read(buffer, 0, buffer.Length);
                            var compressedBuffer = UtilityHelper.DeflateCompress(buffer);

                            using (IsolatedStorageFileStream isoStream = new IsolatedStorageFileStream(fileName, FileMode.OpenOrCreate, FileAccess.ReadWrite, isoStore))
                            {
                                if (isoStream.CanWrite)
                                {
                                    isoStream.Write(compressedBuffer, 0, compressedBuffer.Length);
                                }
                                isoStream.Close();
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        try
                        {
                            string[]      fileNames = IsolatedStorageFile.GetUserStoreForApplication().GetFileNames();
                            StringBuilder sb        = new StringBuilder();
                            sb.AppendLine(string.Format("IsolatedStoreageHelper Write {0}", fileName));
                            sb.AppendLine(string.Format("Used Size: {0}kb", Math.Round(Convert.ToDouble(IsolatedStorageFile.GetUserStoreForApplication().UsedSize) / 1024d, 2)));
                            sb.AppendLine("For Application:");
                            if (fileNames != null)
                            {
                                foreach (var filePath in fileNames)
                                {
                                    IsolatedStorageFileStream isoStream = null;
                                    try
                                    {
                                        isoStream = IsolatedStorageFile.GetUserStoreForApplication().OpenFile(filePath, FileMode.Open, FileAccess.ReadWrite);
                                        sb.AppendLine(string.Format("{0}: {1}kb", filePath, Math.Round(Convert.ToDouble(isoStream.Length) / 1024d, 2)));
                                    }
                                    finally
                                    {
                                        if (isoStream != null)
                                        {
                                            isoStream.Dispose();
                                        }
                                    }
                                }
                            }

                            fileNames = IsolatedStorageFile.GetUserStoreForSite().GetFileNames();
                            sb.AppendLine("For Site:");
                            if (fileNames != null)
                            {
                                foreach (var filePath in fileNames)
                                {
                                    IsolatedStorageFileStream isoStream = null;
                                    try
                                    {
                                        isoStream = IsolatedStorageFile.GetUserStoreForSite().OpenFile(filePath, FileMode.Open, FileAccess.ReadWrite);
                                        sb.AppendLine(string.Format("{0}: {1}kb", filePath, Math.Round(Convert.ToDouble(isoStream.Length) / 1024d, 2)));
                                    }
                                    finally
                                    {
                                        if (isoStream != null)
                                        {
                                            isoStream.Dispose();
                                        }
                                    }
                                }
                            }

                            ComponentFactory.Logger.LogError(ex, sb.ToString(), null);

                            if (ex is IsolatedStorageException && isoStore != null && ex.StackTrace.Contains("IsolatedStorageFile.Reserve"))
                            {
                                isoStore.Remove();
                            }
                            isoStore = IsolatedStorageFile.GetUserStoreForSite();
                            if (ex is IsolatedStorageException && isoStore != null && ex.StackTrace.Contains("IsolatedStorageFile.Reserve"))
                            {
                                isoStore.Remove();
                            }
                        }
                        catch (Exception ex1)
                        {
                            ComponentFactory.Logger.LogError(ex1, "IsolatedStoreageHelper Write failed.", null);
                        }
                    }
                    finally
                    {
                        if (isoStore != null)
                        {
                            isoStore.Dispose();
                        }
                    }
                }
            }
        }
        private void _GetResult(Stream result)
        {
            if (result == null)
            {
                _LoadNext();
            }
            else
            {
                try
                {
                    _isEnoughSpace = CacheHelpers.GetMoreSpace(result.Length);

                    if (_isEnoughSpace)
                    {
                        lock (guard)
                        {
                            IsolatedStorageFile       filesystem = null;
                            IsolatedStorageFileStream fs         = null;
                            try
                            {
                                filesystem = IsolatedStorageFile.GetUserStoreForApplication();
                                string filename = _currentFileName + ".jpg";

                                if (!filesystem.FileExists(filename))
                                {
                                    fs = new IsolatedStorageFileStream(filename, FileMode.Create, filesystem);
                                    // Save the image to Isolated Storage
                                    Int64  imgLen = (Int64)result.Length;
                                    byte[] b      = new byte[imgLen];
                                    result.Read(b, 0, b.Length);
                                    fs.Write(b, 0, b.Length);
                                    fs.Flush();
                                }

                                _numberOfLoaded++;
                            }
                            catch (Exception ex)
                            {
                                Debug.WriteLine("Save avatar in file system failed: " + ex.Message);
                            }
                            finally
                            {
                                if (filesystem != null)
                                {
                                    filesystem.Dispose();
                                }

                                if (fs != null)
                                {
                                    fs.Dispose();
                                }
                            }
                        }

                        _callback(_currentFriendId);

                        _LoadNext();
                    }
                }
                catch (Exception ex)
                {
                    Debug.WriteLine("Image loading failed." + ex.Message);

                    _LoadNext();
                }
            }
        }
 public void Dispose()
 {
     storage.Dispose();
 }
 public void Dispose()
 {
     __IsoStorage.Dispose();
 }
 /// <summary>
 /// Performs application-defined tasks associated with freeing, releasing,
 /// or resetting unmanaged resources.
 /// </summary>
 public void Dispose()
 {
     _dbfStream.Close();
     _isolatedStorageFile.Dispose();
 }
Exemple #27
0
        public ViewModel LoadInfoFromXML()
        {
            //目的地データの読み込み。
            IsolatedStorageFile       isoFile = IsolatedStorageFile.GetUserStoreForApplication();
            IsolatedStorageFileStream strm    = new IsolatedStorageFileStream(DBFileName, FileMode.Open, FileAccess.Read, isoFile);
            XDocument xmlDoc = XDocument.Load(strm);

            strm.Dispose();
            isoFile.Dispose();

            var books = from book in xmlDoc.Descendants("Book")
                        orderby book.Element("CreateDate").Value descending
                        select book;

            ViewModel BookView = new ViewModel();
            BookModel newBook;//=new PushPinModel();

            foreach (var book in books)
            {
                newBook = new BookModel();

                newBook.EAN       = book.Element("EAN").Value;
                newBook.Title     = book.Element("Title").Value;
                newBook.Authors   = book.Element("Authors").Value;
                newBook.Publisher = book.Element("Publisher").Value;
                newBook.Price     = book.Element("Price").Value;
                newBook.Currency  = book.Element("Currency").Value;
                try
                {
                    newBook.CreateDate = DateTime.Parse(book.Element("CreateDate").Value);
                }
                catch
                {
                    try
                    {
                        newBook.CreateDate = DateTime.FromFileTime((long)Convert.ToDouble(book.Element("CreateDate").Value));
                    }
                    catch
                    {
                        newBook.CreateDate = NullDate;
                    }
                }

                try
                {
                    newBook.StartReadDate = DateTime.Parse(book.Element("StartReadDate").Value);
                }
                catch
                {
                    try
                    {
                        newBook.StartReadDate = DateTime.FromFileTime((long)Convert.ToDouble(book.Element("StartReadDate").Value));
                    }
                    catch
                    {
                        newBook.StartReadDate = NullDate;
                    }
                }

                try
                {
                    newBook.FinishReadDate = DateTime.Parse(book.Element("FinishReadDate").Value);
                }
                catch
                {
                    try
                    {
                        newBook.FinishReadDate = DateTime.FromFileTime((long)Convert.ToDouble(book.Element("FinishDate").Value));
                    }
                    catch
                    {
                        newBook.FinishReadDate = NullDate;
                    }
                }

                try
                {
                    newBook.PurchaseDate = DateTime.Parse(book.Element("PurchaseDate").Value);
                }
                catch
                {
                    try
                    {
                        newBook.PurchaseDate = DateTime.FromFileTime((long)Convert.ToDouble(book.Element("PurchaseDate").Value));
                    }
                    catch
                    {
                        newBook.PurchaseDate = NullDate;
                    }
                }

                try
                {
                    newBook.PublishDate = DateTime.Parse(book.Element("PublishDate").Value);
                }
                catch
                {
                    try
                    {
                        newBook.PublishDate = DateTime.FromFileTime((long)Convert.ToDouble(book.Element("PublishDate").Value));
                    }
                    catch
                    {
                        newBook.PublishDate = NullDate;
                    }
                }

                try
                {
                    newBook.OpenDetailDate = DateTime.Parse(book.Element("OpenDetailDate").Value);
                }
                catch
                {
                    try
                    {
                        newBook.OpenDetailDate = DateTime.FromFileTime((long)Convert.ToDouble(book.Element("OpenDetailDate").Value));
                    }
                    catch
                    {
                        newBook.OpenDetailDate = NullDate;
                    }
                }

                newBook.Note          = book.Element("Note").Value;
                newBook.Rate          = Convert.ToDouble(book.Element("Star").Value);
                newBook.Status        = book.Element("Status").Value;
                newBook.ImageLocalUri = book.Element("ImageLocalUri").Value;
                newBook.Type          = book.Element("Type").Value;
                newBook.Language      = book.Element("Language").Value;
                newBook.ImageWebUri   = book.Element("ImageWebUri").Value;


                BookView.Books.Add(newBook);
            }


            return(BookView);
        }
Exemple #28
0
 protected override void Cleanup()
 {
     Clean();
     m_Store.Dispose();
     base.Cleanup();
 }
 public void Dispose()
 {
     machineStoreForApplication.Dispose();
 }
Exemple #30
0
        protected override void OnBackKeyPress(System.ComponentModel.CancelEventArgs e)
        {
            if (!e.Cancel && match.gameState != GamePageState.HAVETOEXIT)
            {
                if (match.gameState == GamePageState.LOST)
                {
                    e.Cancel = true;
                    GoBackGameOverStoryBoard.Begin();
                }
                else
                {
                    match.previousState = match.gameState;
                    match.gameState     = GamePageState.PAUSE;
                    PhoneApplicationService.Current.UserIdleDetectionMode = IdleDetectionMode.Enabled;
                    if (MessageBox.Show(Strings.MsgBoxExitText, Strings.MsgBoxExitCaption, MessageBoxButton.OKCancel) == MessageBoxResult.Cancel)
                    {
                        e.Cancel        = true;
                        match.gameState = match.previousState;
                        PhoneApplicationService.Current.UserIdleDetectionMode = IdleDetectionMode.Disabled;
                    }
                    else
                    {
                        inputManager             = null;
                        ((App)App.Current).match = null;
                        NavigationService.GoBack();
                    }
                }
            }
            else
            {
                IsolatedStorageFile storage = IsolatedStorageFile.GetUserStoreForApplication();
                //
                //
                //CODICE PER IL SALVATAGGIO O MENO DEI TEMPI ALL'USCITA
                //
                //
                //Il tempo è un record?
                if (scores.Length == 0 || scores.Length < Constants.NUMBER_OF_RECORDS_SAVED || new Score(match.matchTime, "").CompareTo(scores[scores.Length - 1]) < 0)
                {
                    //IMPORTANTE: LA RISCRITTURA DEL FILE PUO' LASCIARE ERRORI. ELIMINARLO E RISCRIVERLO
                    storage.DeleteFile("scores.xml");

                    //SCRIVO LA NUOVA LISTA DI MATCH.
                    using (IsolatedStorageFileStream stream = storage.OpenFile("scores.xml", FileMode.OpenOrCreate, FileAccess.Write))
                    {
                        XmlSerializer xml = new XmlSerializer(typeof(Score[]));

                        {
                            Score[] tmp = new Score[scores.Length + 1];
                            Array.Copy(scores, tmp, scores.Length);
                            string tmpName;

                            if (GameOverNameTextBox.Text.Trim() == "")
                            {
                                GameOverNameTextBox.Text = name;
                                tmpName = name;
                            }
                            else
                            {
                                tmpName = GameOverNameTextBox.Text.Trim();
                                IsolatedStorageSettings.ApplicationSettings["DefaultName"] = GameOverNameTextBox.Text.Trim();
                            }

                            tmp[scores.Length] = new Score(match.matchTime, tmpName);
                            scores             = tmp;
                            Array.Sort(scores);
                        }

                        //TRONCO LE PARTITE OLTRE IL LIMITE DI SALVATAGGI CONSENTITI.
                        if (scores.Length > Constants.NUMBER_OF_RECORDS_SAVED)
                        {
                            Score[] tmp = new Score[scores.Length - 1];
                            Array.Copy(scores, tmp, tmp.Length);
                            scores = tmp;
                        }

                        xml.Serialize(stream, scores);
                        stream.Close();
                        stream.Dispose();
                    }
                    storage.Dispose();
                }
                ((App)App.Current).match = null;
                NavigationService.GoBack();
            }
            base.OnBackKeyPress(e);
        }