Ejemplo n.º 1
0
        /// <summary> Reads file as bytes asynchronous. </summary>
        /// <exception cref="ArgumentNullException"> Thrown when one or more required arguments are null. </exception>
        /// <exception cref="ArgumentOutOfRangeException"> Thrown when one or more arguments are outside
        ///     the required range. </exception>
        /// <exception cref="FileNotFoundException"> Thrown when the requested file is not present. </exception>
        /// <param name="filePath"> Full pathname of the file. </param>
        /// <param name="fileNotFoundCheck"> (Optional) The file not found check. </param>
        /// <returns> The file as bytes asynchronous. </returns>
        public async Task <byte[]> ReadFileAsBytesAsync(string filePath, FileNotFoundOption fileNotFoundCheck = FileNotFoundOption.DoNotCheck)
        {
            if (filePath == null)
            {
                throw new ArgumentNullException(nameof(filePath));
            }
            if (String.IsNullOrWhiteSpace(filePath))
            {
                throw new ArgumentOutOfRangeException(nameof(filePath));
            }

            bool fileExists = (fileNotFoundCheck == FileNotFoundOption.DoNotCheck) || FileExists(filePath);

            if ((!fileExists) && fileNotFoundCheck == FileNotFoundOption.ThrowException)
            {
                throw new FileNotFoundException("The specified file could not be found.", filePath);
            }

            byte[] result = (fileNotFoundCheck == FileNotFoundOption.ReturnEmpty) ? (new byte[] { }) : null;

            if (fileExists)
            {
                result = await Task.Run(() => File.ReadAllBytes(filePath));
            }

            return(result);
        }
Ejemplo n.º 2
0
 /// <summary> Reads file as bytes asynchronous. </summary>
 /// <param name="fileName"> Filename of the file. </param>
 /// <param name="appDataSubFolder"> Pathname of the application data sub folder. </param>
 /// <param name="fileNotFoundCheck"> (Optional) The file not found check. </param>
 /// <returns> The file as bytes asynchronous. </returns>
 public async Task <byte[]> ReadFileAsBytesAsync(string fileName, string appDataSubFolder, FileNotFoundOption fileNotFoundCheck = FileNotFoundOption.DoNotCheck)
 {
     return(await ReadFileAsBytesAsync(AppDataFilePath(fileName, appDataSubFolder), fileNotFoundCheck));
 }
Ejemplo n.º 3
0
 private void cancel_button_Click(object sender, RoutedEventArgs e)
 {
     Option = FileNotFoundOption.Cancel;
     Hide();
 }
Ejemplo n.º 4
0
 private void skip_button_Click(object sender, RoutedEventArgs e)
 {
     Option = FileNotFoundOption.Skip;
     Hide();
 }