public static async Task <string> SaveTextAsync(string text)
        {
            // フォルダ名、ファイル名を作成
            var SubFolderName = "GitUserData";
            var TextFileName  = "gitUser.txt";

            // ユーザーデータ保存フォルダー
            PCLStorage.IFolder localFolder = PCLStorage.FileSystem.Current.LocalStorage;

            // サブフォルダーを作成、または、取得する
            PCLStorage.IFolder subFolder
                = await localFolder.CreateFolderAsync(SubFolderName,
                                                      PCLStorage.CreationCollisionOption.OpenIfExists);

            // ファイルを作成、または、取得する
            PCLStorage.IFile file
                = await subFolder.CreateFileAsync(TextFileName,
                                                  PCLStorage.CreationCollisionOption.ReplaceExisting);

            // テキストをファイルに書き込む
            // ※冒頭に「using PCLStorage;」が必要
            await file.WriteAllTextAsync(text);

            return(file.Path);
        }
Ejemplo n.º 2
0
        protected override async void OnAppearing()
        {
            Grid grid = new Grid();

            grid.RowDefinitions.Add(new RowDefinition {
                Height = new GridLength(1, GridUnitType.Star)
            });
            grid.RowDefinitions.Add(new RowDefinition {
                Height = new GridLength(50)
            });
            grid.ColumnDefinitions.Add(new ColumnDefinition {
                Width = new GridLength(1, GridUnitType.Star)
            });
            grid.ColumnDefinitions.Add(new ColumnDefinition {
                Width = new GridLength(1, GridUnitType.Star)
            });

            actualImageFile = await FileSystem.Current.GetFileFromPathAsync(appImage.photoFileLocation);

            Stream stream = await actualImageFile.OpenAsync(PCLStorage.FileAccess.Read);

            var image = new Image();

            byte[] imageByte;
            using (MemoryStream ms = new MemoryStream())
            {
                stream.Position = 0;                // needed for WP (in iOS and Android it also works without it)!!
                stream.CopyTo(ms);                  // was empty without stream.Position = 0;
                imageByte = ms.ToArray();
            }
            image.Source = ImageSource.FromStream(() => new MemoryStream(imageByte));
            image.Aspect = Aspect.AspectFit;
            grid.Children.Add(image, 0, 0);
            Grid.SetColumnSpan(image, 2);

            Button removeButton = new Button();

            removeButton.Text = "Remove";
            grid.Children.Add(removeButton, 0, 1);
            removeButton.Clicked += (sender, e) => {
                File.Delete(appImage.photoThumbnailFileLocation);
                if (!string.IsNullOrEmpty(appImage.photoScaledFileLocation))
                {
                    File.Delete(appImage.photoScaledFileLocation);
                }
                actualImageFile.DeleteAsync();
                App.Database.DeleteJobImage(appImage);
                Ultis.Settings.DeleteImage = "Yes";
                Navigation.PopAsync();
            };
            Button backButton = new Button();

            backButton.Text     = "Back";
            backButton.Clicked += (object sender, EventArgs e) => {
                Navigation.PopAsync();
            };
            grid.Children.Add(backButton, 1, 1);

            Content = grid;
        }
Ejemplo n.º 3
0
        /// <summary>
        /// ユーザーデータをファイルに書き出す
        /// </summary>
        /// <param name="text">書き出す文字列</param>
        /// <returns></returns>
        static private async Task <string> SaveTextAsync(string text)
        {
            // ユーザーデータ保存フォルダー
            PCLStorage.IFolder localFolder = PCLStorage.FileSystem.Current.LocalStorage;

            // ファイルを作成、または、取得する
            PCLStorage.IFile file
                = await localFolder.CreateFileAsync(TextFileName,
                                                    PCLStorage.CreationCollisionOption.ReplaceExisting).ConfigureAwait(false);

            // テキストをファイルに書き込む
            await file.WriteAllTextAsync(text).ConfigureAwait(false);

            return(file.Path);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// ユーザーデータをファイルから読み取る
        /// </summary>
        /// <returns></returns>
        static private async Task <string> LoadTextAsync()
        {
            // ユーザーデータ保存フォルダー
            PCLStorage.IFolder localFolder = PCLStorage.FileSystem.Current.LocalStorage;

            ExistenceCheckResult res = await localFolder.CheckExistsAsync(TextFileName).ConfigureAwait(false);

            if (res == ExistenceCheckResult.NotFound)
            {
                return(null);
            }

            // ファイルを取得する
            PCLStorage.IFile file = await localFolder.GetFileAsync(TextFileName).ConfigureAwait(false);

            // テキストファイルを読み込む
            return(await file.ReadAllTextAsync().ConfigureAwait(false));
        }
        public static async Task <string> LoadTextAsync()
        {
            // フォルダ名、ファイル名を作成
            var SubFolderName = "GitUserData";
            var TextFileName  = "gitUser.txt";

            // ユーザーデータ保存フォルダー
            PCLStorage.IFolder localFolder = PCLStorage.FileSystem.Current.LocalStorage;

            // サブフォルダーを作成、または、取得する
            PCLStorage.IFolder subFolder
                = await localFolder.CreateFolderAsync(SubFolderName,
                                                      PCLStorage.CreationCollisionOption.OpenIfExists);

            // ファイルを取得する
            PCLStorage.IFile file = await subFolder.GetFileAsync(TextFileName);

            // テキストファイルを読み込む
            // ※ファイル冒頭に「using PCLStorage;」が必要
            return(await file.ReadAllTextAsync());
        }