コード例 #1
0
 async public void NewExcuseAysnc()
 {
     CurrentExcuse = new Excuse();
     excuseFile = null;
     OnPropertyChanged("CurrentExcuse");
     await UpdateFileDateAsync();
 }
コード例 #2
0
        private StorageFile NewStorageFile(string fileNamePath)
        {
            StorageFile newStorageFile;
            if (!string.IsNullOrEmpty(fileNamePath))
            {
                newStorageFile = new StorageFile(fileNamePath);
                SetPath(fileNamePath);
            }
            else
            {
                newStorageFile = null;
            }

            return newStorageFile;
        }
コード例 #3
0
 public async void OpenRandomExcuseAsync()
 {
     IReadOnlyList<StorageFile> files = await excuseFolder.GetFilesAsync();
     if (files.Count() > 0)
     {
         excuseFile = files[random.Next(0, files.Count())];
         await ReadExcuseAsync();
         OnPropertyChanged("CurrentExcuse");
     }
 }
コード例 #4
0
        public async void OpenExcuseAsync()
        {
            StorageFile chosenFile = FileOpenPicker(storageFile: excuseFile);

            if (chosenFile != null)
            {
                excuseFile = chosenFile;
                await ReadExcuseAsync();
            }
            OnPropertyChanged("CurrentExcuse");
        }
コード例 #5
0
 private string SetCurrentFileName(StorageFile storageFile = null)
 {
     if (storageFile == null || string.IsNullOrEmpty(storageFile.Path))
     {
         if (!string.IsNullOrWhiteSpace(CurrentExcuse.Description))
         {
             return CurrentExcuse.Description + ".xml";
         }
         else
         {
             return "";
         }
     }
     else
     {
         return Path.GetFileName(storageFile.Path);
     }
 }
コード例 #6
0
 private string SetCurrentDirectory(StorageFolder storageFolder = null, StorageFile storageFile = null)
 {
     if (storageFile == null || string.IsNullOrEmpty(storageFile.Path))
     {
         if (storageFolder == null || string.IsNullOrEmpty(storageFolder.Path))
         {
             return initialDirectory;
         }
         else
         {
             return storageFolder.Path;
         }
     }
     else
     {
         return Path.GetDirectoryName(storageFile.Path);
     }
 }
コード例 #7
0
        private StorageFile FileSavePicker(StorageFolder storageFolder = null, StorageFile storageFile = null)
        {
            string directory = SetCurrentDirectory(storageFolder, storageFile);
            string fileName = SetCurrentFileName(storageFile);

            SaveFileDialog saveDialog = new SaveFileDialog()
            {
                Title = "Save File",
                Filter = FILTER,
                FileName = fileName,
                InitialDirectory = directory,
                CheckPathExists = true,
                CheckFileExists = false
            };

            if (saveDialog.ShowDialog() == true)
            {
                storageFile = new StorageFile(saveDialog.FileName);
                return storageFile;
            }
            return null;
        }
コード例 #8
0
        private StorageFile FileOpenPicker(StorageFolder storageFolder = null, StorageFile storageFile = null)
        {
            string directory = SetCurrentDirectory(storageFolder, storageFile);
            string fileName = SetCurrentFileName(storageFile);

            OpenFileDialog openDialog = new OpenFileDialog()
            {
                Title = "Open File",
                Filter = FILTER,
                FileName = fileName,
                InitialDirectory = directory,
                Multiselect = false,
                CheckPathExists = true,
                CheckFileExists = true
            };

            if (openDialog.ShowDialog() == true)
            {
                storageFile = new StorageFile(openDialog.FileName);
                return storageFile;
            }
            return null;
        }
コード例 #9
0
        public async void SaveCurrentExcuseAsAsync()
        {
            StorageFile chosenFile = FileSavePicker(storageFile: excuseFile);

            if (chosenFile != null)
            {
                excuseFile = chosenFile;
                await WriteExcuseAsync();
            }       
        }
コード例 #10
0
        public async void SaveCurrentExcuseAsync()
        {
            if (CurrentExcuse == null)
            {
                WinForms.MessageBox.Show("No excuse loaded.");
                return;
            }
            if (string.IsNullOrEmpty(CurrentExcuse.Description))
            {
                if (excuseFile != null)
                {
                    WinForms.MessageBox.Show(string.Format("Current excuse {0} does not have a description.", excuseFile.Name));
                }
                else
                {
                    WinForms.MessageBox.Show("Current excuse does not have any data entered.");
                }
                
                return;
            }
            // Check was in example, but prevents saving over an existing file
            //if (excuseFile == null)
            //{
                excuseFile = await excuseFolder.CreateFileAsync(CurrentExcuse.Description + ".xml",
                                                                CreateCollisionOption.ReplaceExisting);
            //}

            if (excuseFile != null)
            {
                await WriteExcuseAsync();
            }    
        }