/// <summary>
        /// Cache data locally
        /// </summary>
        /// <param name="content">object to be cached</param>
        /// <param name="filename">file name for cache</param>
        /// <returns></returns>
        public override async Task <bool> WriteToLocal(string filename, object content)
        {
            bool success = false;

            if (!string.IsNullOrEmpty(filename))
            {
                StorageFile File = await localFolder.CreateFileAsync(filename, CreationCollisionOption.ReplaceExisting);

                try
                {
                    string json = DataAccessUtil.SerializeObject(content);
                    using (var writer = new StreamWriter(File.Path, false))
                    {
                        await writer.WriteAsync(json);

                        success = true;
                    }
                }
                catch
                {
                    success = false;
                }
            }
            return(success);
        }
예제 #2
0
        public override async Task <bool> WriteToLocal(string filePath, object content)
        {
            var           documentPath  = NSFileManager.DefaultManager.GetUrls(NSSearchPathDirectory.DocumentDirectory, NSSearchPathDomain.User)[0].Path;
            var           fullFilePath  = Path.Combine(documentPath, filePath);
            var           contentString = DataAccessUtil.SerializeObject(content);
            NSFileManager fileManager   = NSFileManager.DefaultManager;
            await Task.Delay(1);

            try
            {
                File.WriteAllText(fullFilePath, contentString);
                return(true);
            }
            catch (Exception)
            {
                return(false);
            }
        }