/// <summary>
        /// Reading Values from the Storage...
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="Key"></param>
        /// <returns></returns>
        public async Task <Set1> Get_Value <T>(String filename)
        {
            IFolder rootFolder = FileSystem.Current.LocalStorage;
            IFolder folder     = await rootFolder.CreateFolderAsync("Set1",
                                                                    CreationCollisionOption.OpenIfExists);

            ExistenceCheckResult isFileExisting = await folder.CheckExistsAsync(filename);

            if (!isFileExisting.ToString().Equals("NotFound"))
            {
                try
                {
                    IFile file = await folder.CreateFileAsync(filename,
                                                              CreationCollisionOption.OpenIfExists);

                    String languageString = await file.ReadAllTextAsync();

                    XmlSerializer oXmlSerializer = new XmlSerializer(typeof(T));
                    return((Set1)oXmlSerializer.Deserialize(new StringReader(languageString)));
                }
                catch (Exception ex)
                {
                    var message = ex.Message;
                    return(default(Set1));
                }
            }

            return(default(Set1));
        }
Exemple #2
0
        public async Task PCLStorageSample()
        {
            IFolder rootFolder = FileSystem.Current.LocalStorage;
            IFolder folder     = await rootFolder.CreateFolderAsync("MySubFolder",
                                                                    CreationCollisionOption.OpenIfExists);

            IFile file = await folder.CreateFileAsync("answer.txt",
                                                      CreationCollisionOption.ReplaceExisting);

            await file.WriteAllTextAsync("42");

            ExistenceCheckResult re = await folder.CheckExistsAsync("answer.txt");

            if (re == ExistenceCheckResult.FileExists)
            {
                Debug.WriteLine("Folder exists" + re.ToString());
            }
            else
            {
                Debug.WriteLine("Folder missing");
            }
        }
        /// <summary>
        /// Delete any value from the Storage...
        /// </summary>
        /// <param name="Key"></param>
        public async void Delete_Value(String filename)
        {
            IFolder rootFolder = FileSystem.Current.LocalStorage;
            IFolder folder     = await rootFolder.CreateFolderAsync("Set1",
                                                                    CreationCollisionOption.OpenIfExists);

            ExistenceCheckResult isFileExisting = await folder.CheckExistsAsync(filename);

            if (!isFileExisting.ToString().Equals("NotFound"))
            {
                try
                {
                    IFile file = await folder.CreateFileAsync(filename,
                                                              CreationCollisionOption.OpenIfExists);

                    await file.DeleteAsync();
                }
                catch (Exception ex)
                {
                    var message = ex.Message;
                }
            }
        }