예제 #1
0
파일: Program.cs 프로젝트: Papuss/Week14A
        static void Main(string[] args)
        {
            IsolatedStorageFile userStore = IsolatedStorageFile.GetUserStoreForAssembly();

            IsolatedStorageFileStream userStream = new IsolatedStorageFileStream("Usersettings.set", FileMode.Create, userStore);

            StreamWriter userWriter = new StreamWriter(userStream);

            userWriter.WriteLine("User Prefs");
            userWriter.Close();

            string[] files = userStore.GetFileNames("UserSettings.set");
            if (files.Length == 0)
            {
                Console.WriteLine("File not exist bro, do something");
                Console.Read();
            }
            else
            {
                userStream = new IsolatedStorageFileStream("UserSettings.set", FileMode.Open, userStore);
                StreamReader userReader = new StreamReader(userStream);
                string       contents   = userReader.ReadToEnd();
                Console.WriteLine(contents);
                Console.Read();
            }
        }
        private void UpdateMediaItemsDownloadedStatus()
        {
            using (IsolatedStorageFile appDirectory = IsolatedStorageFile.GetUserStoreForApplication())
            {
                string searchpath = Path.Combine(Utils.LibraryDirPath(App.Engine.LoggedUser, ActiveLibrary), "*.*");
                IEnumerable <string> filenamesInLibraryDir   = appDirectory.GetFileNames(searchpath).Cast <string>();
                IEnumerable <string> filenamesOnDownloadList =
                    from downloads in App.Engine.LoggedUser.Downloads
                    where downloads.LibraryId == ActiveLibrary.ServerId
                    select downloads.LocalFilename;
                IEnumerable <string> downloadedFilenames = filenamesInLibraryDir.Except(filenamesOnDownloadList);

                foreach (MediaItemsListModelItem item in MediaItems)
                {
                    if (downloadedFilenames.Contains(Utils.FilenameToLocalFilename(item.FileName)))
                    {
                        item.ItemState = MediaItemState.Local;
                    }
                    else if (filenamesOnDownloadList.Contains(Utils.FilenameToLocalFilename(item.FileName)))
                    {
                        item.ItemState = MediaItemState.Downloading;
                    }
                }
            }
        }
예제 #3
0
        public static string GetDataTime()
        {
            string str;
            IsolatedStorageFile isf = IsolatedStorageFile.GetStore(IsolatedStorageScope.Assembly | IsolatedStorageScope.Domain | IsolatedStorageScope.User, (Type)null, (Type)null);

            if (isf.GetDirectoryNames(UIConstants.IsolatedStorageDirectoryName).Length == 0)
            {
                return(string.Empty);
            }
            if (isf.GetFileNames(UIConstants.IsolatedStorage).Length == 0)
            {
                return(string.Empty);
            }
            using (IsolatedStorageFileStream stream = new IsolatedStorageFileStream(UIConstants.IsolatedStorage, FileMode.OpenOrCreate, isf))
            {
                using (StreamReader reader = new StreamReader(stream))
                {
                    str = reader.ReadLine();
                }
            }
            if (!string.IsNullOrEmpty(str))
            {
                try
                {
                    str = EncodeHelper.DesDecrypt(str, UIConstants.IsolatedStorageEncryptKey);
                }
                catch
                {
                }
            }
            return(str);
        }
예제 #4
0
        static void Main(string[] args)
        {
            //Хранилище уровня компьютера (Assembly/ Machine)
            IsolatedStorageFile machineStorage = IsolatedStorageFile.GetMachineStoreForAssembly();
            //Хранилище уровня пользователя (Assembly/User)
            IsolatedStorageFile userStore = IsolatedStorageFile.GetUserStoreForAssembly();


            //Класс IsolatedStorageFileStream

            IsolatedStorageFileStream userStream = new IsolatedStorageFileStream("UserSettings.set", FileMode.Create, userStore);

            StreamWriter userWriter = new StreamWriter(userStream);

            userWriter.WriteLine("User Prefs");
            userWriter.Close();

            //чтение
            string[] files = userStore.GetFileNames("UserSettings.set");
            if (files.Length == 0)
            {
                Console.WriteLine("No data saved for this user");
            }
            else
            {
                userStream = new IsolatedStorageFileStream("UserSettings.set", FileMode.Open, userStore);
                StreamReader userReader = new StreamReader(userStream);
                string       contents   = userReader.ReadToEnd();
                Console.WriteLine(contents);
            }
        }
예제 #5
0
        private async void Button_Tap_1(object sender, System.Windows.Input.GestureEventArgs e)
        {
            List <KeyValue <int, GameData> > Database = new List <KeyValue <int, GameData> >();

            using (IsolatedStorageFile isoStore = IsolatedStorageFile.GetUserStoreForApplication())
            {
                await IsolatedStorageHelper.Save <List <KeyValue <int, GameData> > >(Database, "/GameLibrary/Database.xml");

                App.ViewModel.MainGameView.GamesList.Clear();

                if (isoStore.DirectoryExists("/GameImages/"))
                {
                    foreach (var file in isoStore.GetFileNames("/GameImages/"))
                    {
                        if (isoStore.FileExists("/GameImages/" + file))
                        {
                            isoStore.DeleteFile("/GameImages/" + file);
                        }
                    }

                    isoStore.DeleteDirectory("/GameImages/");
                }
            }

            clearCacheButton.IsEnabled = false;
        }
예제 #6
0
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            base.OnNavigatedTo(e);
            StackPanel grid = (LayoutRoot.FindName("PhotoViewer") as StackPanel);

            using (IsolatedStorageFile isStore = IsolatedStorageFile.GetUserStoreForApplication())
            {
                if (isStore.DirectoryExists("files"))
                {
                    string[] fileNames = isStore.GetFileNames("files/*.jpg");
                    foreach (string fileName in fileNames)
                    {
                        //                    TextBlock block = new TextBlock();
                        //                    block.Text = fileName;
                        //                    grid.Children.Add(block);

                        Button button = new Button();
                        button.Content = fileName;
                        button.VerticalContentAlignment = System.Windows.VerticalAlignment.Bottom;
                        ImageBrush  brush = new ImageBrush();
                        BitmapImage bi    = new BitmapImage();
                        bi.SetSource(isStore.OpenFile("files\\" + fileName, FileMode.Open, FileAccess.Read));
                        brush.ImageSource = bi;
                        brush.Stretch     = Stretch.Uniform;
                        button.Height     = 300;
                        button.Width      = 300;
                        button.Background = brush;

                        grid.Children.Add(button);
                    }
                }
            }
        }
예제 #7
0
        private static void handleRemovingIconFiles()
        {
            IsolatedStorageSettings settings   = IsolatedStorageSettings.ApplicationSettings;
            IsolatedStorageFile     isoStorage = IsolatedStorageFile.GetUserStoreForApplication();

            if (isoStorage.DirectoryExists(App.PODCAST_ICON_DIR))
            {
                if (settings.Contains(LSKEY_MUST_CLEAN_PODCAST_ICONS))
                {
                    return;
                }

                MessageBox.Show("The podcast logo handling has improved in this version of Podcatcher. We'll now remove all old logo files and fetch them again.", "Optimization notice",
                                MessageBoxButton.OK);

                foreach (var file in isoStorage.GetFileNames(Path.Combine(App.PODCAST_ICON_DIR, "*.*")))
                {
                    Debug.WriteLine("Deleting podcast logo: " + file);
                    isoStorage.DeleteFile(Path.Combine(App.PODCAST_ICON_DIR, file));
                }
            }

            settings[LSKEY_MUST_CLEAN_PODCAST_ICONS] = "done";
            settings.Save();
        }
예제 #8
0
 // helper function from: http://stackoverflow.com/questions/18422331/easy-way-to-recursively-delete-directories-in-isolatedstorage-on-wp7-8
 private void DeleteDirectoryRecursively(IsolatedStorageFile storageFile, String dirName)
 {
     try
     {
         String   pattern = dirName + @"\*";
         String[] files   = storageFile.GetFileNames(pattern);
         foreach (var fName in files)
         {
             storageFile.DeleteFile(Path.Combine(dirName, fName));
         }
         String[] dirs = storageFile.GetDirectoryNames(pattern);
         foreach (var dName in dirs)
         {
             DeleteDirectoryRecursively(storageFile, Path.Combine(dirName, dName));
         }
         if (storageFile.DirectoryExists(dirName))
         {
             storageFile.DeleteDirectory(dirName);
         }
     }
     catch (Exception e)
     {
         Debug.WriteLine("Unable to delete directory : " + dirName);
     }
 }
        private void LoadFileList(string path)
        {
            using (IsolatedStorageFile store = IsolatedStorageFile.GetUserStoreForApplication())
            {
                var fileItems = new List <FileItem>();

                string searchPattern = Path.Combine(path, "*");
                foreach (string directoryName in store.GetDirectoryNames(searchPattern))
                {
                    fileItems.Add(new FileItem()
                    {
                        Name = directoryName, Type = "directory"
                    });
                }

                foreach (string fileName in store.GetFileNames(searchPattern))
                {
                    fileItems.Add(new FileItem()
                    {
                        Name = fileName, Type = "file"
                    });
                }

                this.fileList.ItemsSource = fileItems;
            }
        }
예제 #10
0
        /// <summary>
        /// Specifies if the application has the settings saved in Isolated Storage.
        /// </summary>
        /// <returns>
        /// True is the repository configuration file exists in Isolated Storage.
        /// False if the file does not exist.
        /// </returns>
        public static bool HasSettings()
        {
            IsolatedStorageFile isFile = null;
            bool hasSettings           = false;

            try
            {
                isFile      = IsolatedStorageFile.GetUserStoreForAssembly();
                hasSettings = (isFile.GetFileNames(filename).Length > 0);
            }
            catch (IOException ioException)
            {
                Log.Exception(ioException);
            }
            finally
            {
                if (isFile != null)
                {
                    isFile.Dispose();
                    isFile.Close();
                }
            }

            return(hasSettings);
        }
예제 #11
0
        /// <summary>
        /// Saves the collection to the isolated storage.
        /// </summary>
        void SaveCollection()
        {
            // Saving a list to local storage can generate I/O errors.  They are intensionally trapped here and not passed on to the higher levels.  If a list can't
            // be saved to local storage then there is nothing a user can do about it anyway.  The feedback will be that the preferences are not saved.
            if (this.isInitialized)
            {
                try
                {
                    // This will store the list to the local storage associated with this assembly.
                    using (IsolatedStorageFile isolatedStorageFile = IsolatedStorageFile.GetUserStoreForAssembly())
                    {
                        // Prepare the local file stream for writing using the unique list name.  The file is truncated if it already exists, created if it doesn't.
                        String fileName = MruCollection <T> .filePrefix + Name + MruCollection <T> .fileSuffix;
                        IsolatedStorageFileStream isolatedStorageFileStream = new IsolatedStorageFileStream(
                            fileName,
                            isolatedStorageFile.GetFileNames(fileName).Length == 0 ? FileMode.Create : FileMode.Truncate,
                            FileAccess.Write,
                            isolatedStorageFile);

                        // This will save the collection to the local storage.
                        using (isolatedStorageFileStream)
                        {
                            XmlSerializer xmlSerializer = new XmlSerializer(typeof(ObservableCollection <T>));
                            xmlSerializer.Serialize(isolatedStorageFileStream, this);
                        }
                    }
                }
                catch (SecurityException) { }
            }
예제 #12
0
        static void Main(string[] args)
        {
            IsolatedStorageFile userStore = IsolatedStorageFile.GetUserStoreForAssembly();

            IsolatedStorageFileStream userStream = new IsolatedStorageFileStream("UserSettings.set", FileMode.Create, userStore);

            StreamWriter userWriter = new StreamWriter(userStream);

            userWriter.WriteLine("Kod Adi K.O.Z. A look at the 17-25 December 2013 corruption scandal in Turkey, from the viewpoint of the Erdogan government.");
            userWriter.Close();

            string[] files = userStore.GetFileNames("UserSettings.set");
            if (files.Length == 0)
            {
                Console.WriteLine("No files found!");
                Console.WriteLine("Press Enter to exit.");
                Console.ReadKey();
            }

            userStream = new IsolatedStorageFileStream("UserSettings.set", FileMode.Open, userStore);
            StreamReader userReader = new StreamReader(userStream);
            string       contents   = userReader.ReadToEnd();

            Console.WriteLine(contents);
            Console.WriteLine("Press Enter to exit.");
            Console.ReadKey();
        }
예제 #13
0
        private void ImportSavegamesCache(IsolatedStorageFile isf)
        {
            List <CartridgeSavegame> cSavegames = new List <CartridgeSavegame>();

            string[] gwsFiles = isf.GetFileNames(PathToSavegames + "/*.gws");
            if (gwsFiles != null)
            {
                // For each file, imports its metadata.
                foreach (string file in gwsFiles)
                {
                    try
                    {
                        cSavegames.Add(CartridgeSavegame.FromIsoStore(PathToSavegames + "/" + file, isf));
                    }
                    catch (Exception ex)
                    {
                        // Outputs the exception.
                        System.Diagnostics.Debug.WriteLine("CartridgeTag: WARNING: Exception during savegame import.");
                        DebugUtils.DumpException(ex);
                    }
                }
            }

            // Sets the savegame list.
            savegames = cSavegames;
            RaisePropertyChanged("Savegames");
        }
예제 #14
0
        public void GetFilesInSubdirs()
        {
            IsolatedStorageFile isf = IsolatedStorageFile.GetUserStoreForAssembly();
            string pattern          = Path.Combine("..", "*");

            isf.GetFileNames(pattern);
        }
        static void Main(string[] args)
        {
            // Exercise 4
            IsolatedStorageFile       userStore  = IsolatedStorageFile.GetUserStoreForAssembly();
            IsolatedStorageFileStream userStream = new IsolatedStorageFileStream("UserSettings.set", FileMode.Create, userStore);
            string contents = "";

            StreamWriter userWriter = new StreamWriter(userStream);

            userWriter.WriteLine("User Prefs");
            userWriter.Close();

            // Exercise 5
            string[] files = userStore.GetFileNames("UserSettings.set");
            if (files.Length == 0)
            {
                Console.WriteLine("No files were found.");
            }
            else
            {
                userStream = new IsolatedStorageFileStream("UserSettings.set", FileMode.Open, userStore);
                StreamReader userReader = new StreamReader(userStream);
                contents = userReader.ReadToEnd();
            }
            Console.Write("\n File content in isolated storage: ");
            Console.ForegroundColor = ConsoleColor.Green;
            Console.Write(contents);
            Console.ResetColor();
            Console.ReadLine();
        }
예제 #16
0
    public bool GetIsoStoreInfo()
    {
        // Get a User store with type evidence for the current Domain and the Assembly.
        IsolatedStorageFile isoFile = IsolatedStorageFile.GetStore(IsolatedStorageScope.User |
                                                                   IsolatedStorageScope.Assembly |
                                                                   IsolatedStorageScope.Domain,
                                                                   typeof(System.Security.Policy.Url),
                                                                   typeof(System.Security.Policy.Url));

        String[] dirNames  = isoFile.GetDirectoryNames("*");
        String[] fileNames = isoFile.GetFileNames("*");

        // List directories currently in this Isolated Storage.
        if (dirNames.Length > 0)
        {
            for (int i = 0; i < dirNames.Length; ++i)
            {
                Console.WriteLine("Directory Name: " + dirNames[i]);
            }
        }

        // List the files currently in this Isolated Storage.
        // The list represents all users who have personal preferences stored for this application.
        if (fileNames.Length > 0)
        {
            for (int i = 0; i < fileNames.Length; ++i)
            {
                Console.WriteLine("File Name: " + fileNames[i]);
            }
        }

        isoFile.Close();
        return(true);
    }
예제 #17
0
        static void Main()
        {
            // Создание изолированного хранилища уровня .Net сборки.
            IsolatedStorageFile userStorage = IsolatedStorageFile.GetUserStoreForAssembly();

            // Создание файлового потока с указанием: Имени файла, FileMode, объекта хранилища.
            IsolatedStorageFileStream userStream = new IsolatedStorageFileStream("UserSettings.set", FileMode.Create, userStorage);

            //   StreamWriter - запись данных в поток userStream.
            StreamWriter userWriter = new StreamWriter(userStream);

            userWriter.WriteLine("User Prefs");
            userWriter.Close();

            // Проверить, если файл существует.
            string[] files = userStorage.GetFileNames("UserSettings.set");

            if (files.Length == 0)
            {
                Console.WriteLine("No data saved for this user");
            }
            else
            {
                // Прочитать данные из потока.
                userStream = new IsolatedStorageFileStream("UserSettings.set", FileMode.Open, userStorage);

                StreamReader userReader = new StreamReader(userStream);
                string       contents   = userReader.ReadToEnd();
                Console.WriteLine(contents);
            }

            // Задержка.
            Console.ReadKey();
        }
예제 #18
0
        private void ImportSavegamesCache(IsolatedStorageFile isf)
        {
            List <CartridgeSavegame> cSavegames = new List <CartridgeSavegame>();

            string[] gwsFiles = isf.GetFileNames(PathToSavegames + "/*.gws");
            if (gwsFiles != null)
            {
                // For each file, imports its metadata.
                foreach (string file in gwsFiles)
                {
                    string path = PathToSavegames + "/" + file;
                    try
                    {
                        cSavegames.Add(CartridgeSavegame.FromIsoStore(path, isf));
                    }
                    catch (FileNotFoundException)
                    {
                        // No associated meta-data or the file does not exist.
                        // Let the store decide what to do.
                        App.Current.Model.CartridgeStore.OnUnknownSavegame(path);
                    }
                    catch (Exception ex)
                    {
                        // Outputs the exception.
                        System.Diagnostics.Debug.WriteLine("CartridgeTag: WARNING: Exception during savegame import.");
                        DebugUtils.DumpException(ex);
                    }
                }
            }

            // Sets the savegame list.
            _savegames.AddRange(cSavegames);
            RaisePropertyChanged("Savegames");
        }
예제 #19
0
        public virtual List <string> LoadPlugins()
        {
            List <string> pluginsFailedToLoad = new List <string>();

            plugins = new Dictionary <String, IPlugin>();
            using (IsolatedStorageFile store = IsolatedStorageFile.GetUserStoreForAssembly())
            {
                var serializer = new YamlSerializer();
                foreach (string file in store.GetFileNames("*.yml"))
                {
                    try
                    {
                        using (IsolatedStorageFileStream stream = new IsolatedStorageFileStream(file, FileMode.Open, FileAccess.Read, store))
                        {
                            Plugin plugin = (Plugin)serializer.Deserialize(stream, typeof(Plugin))[0];
                            plugins.Add(Path.GetFileNameWithoutExtension(file), plugin);
                        }
                    }
                    catch
                    {
                        pluginsFailedToLoad.Add(file);
                    }
                }
                store.Close();
            }
            return(pluginsFailedToLoad);
        }
예제 #20
0
        /// <summary>
        /// Load the collection from the isolated store.
        /// </summary>
        void LoadCollection()
        {
            // This will initialize the list from a persistent file.  As seeding the list will cause an update event to fire -- and this update event handler would
            // write the file -- it's important to block re-entrancy while the list is initialized.  A field -- isInitialized -- will prevent the trigger from
            // writing to the persistent storage until the field is set.  Also, since there are a lot of I/O operations, it's a good idea to catch all the
            // exceptions that might occur with the isolated storage and serialization.
            try
            {
                // This will load the contents of the collection from a file in the persistent storage (if it exists).
                using (IsolatedStorageFile isolatedStorageFile = IsolatedStorageFile.GetUserStoreForAssembly())
                {
                    String fileName = MruCollection <T> .filePrefix + Name + MruCollection <T> .fileSuffix;
                    if (isolatedStorageFile.GetFileNames(fileName).Length != 0)
                    {
                        using (IsolatedStorageFileStream stream = new IsolatedStorageFileStream(fileName, FileMode.Open, FileAccess.Read, isolatedStorageFile))
                        {
                            XmlSerializer            xmlSerializer = new XmlSerializer(typeof(ObservableCollection <T>));
                            ObservableCollection <T> clone         = xmlSerializer.Deserialize(stream) as ObservableCollection <T>;
                            for (Int32 index = 0; index < clone.Count; index++)
                            {
                                this.Insert(index, clone[index]);
                            }
                        }
                    }
                }
            }
            catch (SecurityException) { }
            catch (InvalidOperationException) { }
            catch (IsolatedStorageException) { }

            // At this point the list is initialized and the event triggers are used to save any changes to disk.
            this.isInitialized = true;
        }
예제 #21
0
 public string[] listFiles()
 {
     if (!isoStore.DirectoryExists("localusers"))
     {
         isoStore.CreateDirectory("localusers");
     }
     return(isoStore.GetFileNames("localusers\\*.xml"));
 }
 private void Page_Loaded(object sender, RoutedEventArgs e)
 {
     using (IsolatedStorageFile store = IsolatedStorageFile.GetUserStoreForApplication())
     {
         string[] people = store.GetFileNames("*.person");
         lstPeople.ItemsSource = people;
     }
 }
        /// <summary>
        /// Checks if the persistence service has the state with the specified
        /// id in its storage.
        /// </summary>
        /// <param name="id">The id of the state to look for.</param>
        /// <returns>true if the state is persisted in the storage; otherwise false.</returns>
        public override bool Contains(string id)
        {
            IsolatedStorageFile store = IsolatedStorageFile.GetStore(scope, null, null);

            string[] files = store.GetFileNames(GetFileName(id));

            return(files.Length == 1);
        }
        public ECollegeResponseCacheEntry Get(string cacheKey)
        {
            string dirPath = GetDirectoryForCacheKey(cacheKey);

            ECollegeResponseCacheEntry result = null;

            lock (dirPath)
            {
                if (storage.DirectoryExists(dirPath))
                {
                    string existingCacheFileName = storage.GetFileNames(GetFileGlobForCacheKey(cacheKey)).FirstOrDefault();

                    if (existingCacheFileName != null)
                    {
                        var existingCacheFilePath = string.Format("{0}\\{1}", dirPath, existingCacheFileName);

                        var expirationDate =
                            DateTime.FromFileTimeUtc(long.Parse(Path.GetFileNameWithoutExtension(existingCacheFileName)));

                        if (expirationDate >= DateTime.UtcNow)
                        {
                            using (var f = new IsolatedStorageFileStream(existingCacheFilePath, FileMode.Open, FileAccess.Read, storage))
                            {
                                using (var sr = new StreamReader(f))
                                {
                                    result          = new ECollegeResponseCacheEntry();
                                    result.CachedAt = DateTime.Now;
                                    result.Data     = sr.ReadToEnd();
                                }
                            }
                        }
                        else
                        {
                            storage.DeleteFile(existingCacheFilePath);
                            storage.DeleteDirectory(dirPath);
                        }
                    }
                    else
                    {
                        storage.DeleteDirectory(dirPath);
                    }
                }
            }

            return(result);
        }
예제 #25
0
        /// <summary>
        /// 列举所有保存了的story, 并且返回story名称.
        /// </summary>
        /// <returns>story列表, 没有.xml扩展名.</returns>
        internal static List <string> EnumerateStories()
        {
            IsolatedStorageFile userStore = IsolatedStorageFile.GetUserStoreForApplication();

            return((from f in userStore.GetFileNames()
                    where f.EndsWith(".xml")
                    select f.Substring(0, f.Length - 4)).ToList());
        }
예제 #26
0
 private void DeleteState(IsolatedStorageFile storage)
 {
     string[] files = storage.GetFileNames("ScreenManager\\*");
     foreach (string file in files)
     {
         storage.DeleteFile(Path.Combine("ScreenManger", file));
     }
 }
예제 #27
0
 private void SendStoredMessages()
 {
     lock (_sendLock)
     {
         try
         {
             using (IsolatedStorageFile isolatedStorage = GetIsolatedStorageScope())
             {
                 string   directoryName = "RaygunOfflineStorage";
                 string[] directories   = isolatedStorage.GetDirectoryNames("*");
                 if (FileExists(directories, directoryName))
                 {
                     string[] fileNames = isolatedStorage.GetFileNames(directoryName + "\\*.txt");
                     foreach (string name in fileNames)
                     {
                         IsolatedStorageFileStream isoFileStream = new IsolatedStorageFileStream(directoryName + "\\" + name, FileMode.Open, isolatedStorage);
                         using (StreamReader reader = new StreamReader(isoFileStream))
                         {
                             string text = reader.ReadToEnd();
                             try
                             {
                                 Send(text);
                             }
                             catch
                             {
                                 // If just one message fails to send, then don't delete the message, and don't attempt sending anymore until later.
                                 return;
                             }
                             System.Diagnostics.Debug.WriteLine("Sent " + name);
                         }
                         isolatedStorage.DeleteFile(directoryName + "\\" + name);
                     }
                     if (isolatedStorage.GetFileNames(directoryName + "\\*.txt").Length == 0)
                     {
                         System.Diagnostics.Debug.WriteLine("Successfully sent all pending messages");
                         isolatedStorage.DeleteDirectory(directoryName);
                     }
                 }
             }
         }
         catch (Exception ex)
         {
             System.Diagnostics.Debug.WriteLine(string.Format("Error sending stored messages to Raygun.io {0}", ex.Message));
         }
     }
 }
예제 #28
0
 public async Task <IEnumerable <string> > GetFileNamesAsync(string folderName = null, string fileNamePattern = null)
 {
     try {
         return(isoStore.GetFileNames((folderName ?? "") + Path.DirectorySeparatorChar + fileNamePattern ?? "*"));
     } catch (DirectoryNotFoundException) {
         return(new string[0]);
     }
 }
 /// <summary>
 /// Removes a directory and any files or subdirectories within it
 /// from the persistence store
 /// </summary>
 /// <param name="dirName"></param>
 /// <returns></returns>
 public void DeleteDirectory(string dirName)
 {
     foreach (var fileName in _isolatedStorage.GetFileNames(dirName + Path.DirectorySeparatorChar + "*"))
     {
         DeleteFile(Path.Combine(dirName, fileName));
     }
     _isolatedStorage.DeleteDirectory(dirName);
 }
예제 #30
0
        protected void LoadSaveSettings(bool bLoad)
        {
            IsolatedStorageFilePermission perm =
                new IsolatedStorageFilePermission(PermissionState.Unrestricted);

            perm.UsageAllowed = IsolatedStorageContainment.AssemblyIsolationByUser;
            if (!SecurityManager.IsGranted(perm))
            {
                MessageBox.Show("User settings won't be saved.", strProgName, MessageBoxButtons.OK,
                                MessageBoxIcon.Warning);
                return;
            }

            IsolatedStorageFileStream stream = null;

            try
            {
                IsolatedStorageFile storage =
                    IsolatedStorageFile.GetUserStoreForAssembly();
                if (bLoad)
                {
                    string[] astr = storage.GetFileNames(strConfig);
                    if (astr.Length > 0)
                    {
                        stream = new IsolatedStorageFileStream(strConfig, FileMode.Open,
                                                               FileAccess.Read, FileShare.Read, storage);

                        PropertyBag props = new PropertyBag(stream);
                        LoadSettings(props);
                    }
                    else
                    {
                        // default settings
                        mediaControl.AutoPlay = true;
                        mediaControl.ShowLogo = true;
                        mediaControl.PreferredVideoRenderer = MediaEngineServiceProvider.RecommendedRenderer;
                    }
                }
                else
                {
                    PropertyBag props = new PropertyBag();
                    SaveSettings(props);

                    stream = new IsolatedStorageFileStream(strConfig, FileMode.Create, FileAccess.Write, storage);
                    props.Save(stream);
                }
            }
            catch
            {
            }
            finally
            {
                if (stream != null)
                {
                    stream.Close();
                }
            }
        }