async public void NewExcuseAysnc()
 {
     CurrentExcuse = new Excuse();
     excuseFile = null;
     OnPropertyChanged("CurrentExcuse");
     await UpdateFileDateAsync();
 }
        private StorageFile NewStorageFile(string fileNamePath)
        {
            StorageFile newStorageFile;
            if (!string.IsNullOrEmpty(fileNamePath))
            {
                newStorageFile = new StorageFile(fileNamePath);
                SetPath(fileNamePath);
            }
            else
            {
                newStorageFile = null;
            }

            return newStorageFile;
        }
 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");
     }
 }
        public async void OpenExcuseAsync()
        {
            StorageFile chosenFile = FileOpenPicker(storageFile: excuseFile);

            if (chosenFile != null)
            {
                excuseFile = chosenFile;
                await ReadExcuseAsync();
            }
            OnPropertyChanged("CurrentExcuse");
        }
 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);
     }
 }
 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);
     }
 }
        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;
        }
        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;
        }
        public async void SaveCurrentExcuseAsAsync()
        {
            StorageFile chosenFile = FileSavePicker(storageFile: excuseFile);

            if (chosenFile != null)
            {
                excuseFile = chosenFile;
                await WriteExcuseAsync();
            }       
        }
        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();
            }    
        }