Ejemplo n.º 1
0
        public static async Task <FileStream> FolderCreateFileAsync(DirectoryInfo argBaseFolder, string argFileName)
        {
            // TODO Handle relative paths

            // Check for relative path
            if (!StoreFileUtility.IsRelativeFilePathValid(argFileName))
            {
                return(null);
            }

            // load the real file
            if (argBaseFolder != null)
            {
                try
                {
                    FileStream tt = File.Create(Path.Combine(argBaseFolder.FullName, argFileName));

                    return(tt);
                }
                catch (FileNotFoundException ex)
                {
                    await DataStore.CN.MajorStatusAdd(ex.Message + ex.FileName).ConfigureAwait(false);

                    // default to a standard file marker
                }
                catch (Exception ex)
                {
                    DataStore.CN.NotifyException(ex.Message + argFileName, ex);
                    throw;
                }
            }

            return(null);
        }
Ejemplo n.º 2
0
        public static FileStream FolderCreateFile(DirectoryInfo argBaseFolder, string argFileName)
        {
            // TODO Handle relative paths

            // Check for relative path
            if (!StoreFileUtility.IsRelativeFilePathValid(argFileName))
            {
                return(null);
            }

            // Load the real file
            if (argBaseFolder != null)
            {
                try
                {
                    FileStream tt = File.Create(Path.Combine(argBaseFolder.FullName, argFileName));

                    return(tt);
                }
                catch (FileNotFoundException ex)
                {
                    App.Current.Services.GetService <IErrorNotifications>().DataLogEntryAdd(ex.Message + ex.FileName);

                    // default to a standard file marker
                }
                catch (Exception ex)
                {
                    App.Current.Services.GetService <IErrorNotifications>().NotifyException(ex.Message + argFileName, ex);
                    throw;
                }
            }

            return(null);
        }
Ejemplo n.º 3
0
        public static FileInfoEx FolderGetFile(DirectoryInfo argBaseFolder, string argFileName)
        {
            Contract.Requires(argBaseFolder != null);

            // TODO Handle relative paths

            // Check for relative path
            if (!StoreFileUtility.IsRelativeFilePathValid(argFileName))
            {
                return(new FileInfoEx());
            }

            // load the real file
            DirectoryInfo realPath = new DirectoryInfo(Path.Combine(argBaseFolder.FullName, Path.GetDirectoryName(argFileName)));

            if (realPath != null)
            {
                try
                {
                    FileInfo[] t = realPath.GetFiles();

                    foreach (FileInfo item in t)
                    {
                        if (item.Name == Path.GetFileName(argFileName))
                        {
                            return(new FileInfoEx(item));
                        }
                    }
                }
                catch (FileNotFoundException ex)
                {
                    DataStore.CN.NotifyError(ex.Message + ex.FileName);

                    // default to a standard file marker
                }
                catch (DirectoryNotFoundException ex)
                {
                    DataStore.CN.NotifyError("Directory not found when deserialising the data.  Perahps the GPKG filenames are too long?" + ex.Message);

                    // default to a standard file marker
                }
                catch (Exception ex)
                {
                    DataStore.CN.NotifyException(ex.Message + argFileName, ex);
                    throw;
                }
            }

            return(new FileInfoEx());
        }
Ejemplo n.º 4
0
        /// <summary>
        /// get the StorageFile of the file.
        /// </summary>
        /// <param name="relativeFilePath">
        /// file path relative to the provider base folder.
        /// </param>
        /// <returns>
        /// StorageFile for the chosen file.
        /// </returns>
        public async static Task <FileInfoEx> GetStorageFileAsync(string relativeFilePath)
        {
            FileInfoEx resultFile = new FileInfoEx();

            // Validate the input
            if ((relativeFilePath is null) || (string.IsNullOrEmpty(relativeFilePath)))
            {
                return(resultFile);
            }

            // Check for relative path
            if (!StoreFileUtility.IsRelativeFilePathValid(relativeFilePath))
            {
                return(resultFile);
            }

            // load the real file
            DirectoryInfo tt = DataStore.AD.CurrentDataFolder;

            if (tt != null)
            {
                try
                {
                    if (Directory.Exists(Path.Combine(tt.FullName, Path.GetDirectoryName(relativeFilePath))))
                    {
                        FileInfo[] t = tt.GetFiles(relativeFilePath);

                        if (t.Length > 0)
                        {
                            resultFile.FInfo = t[0];
                        }
                    }
                    return(resultFile);
                }
                catch (FileNotFoundException ex)
                {
                    await DataStore.CN.MajorStatusAdd(ex.Message + ex.FileName).ConfigureAwait(false);

                    // default to a standard file marker
                }
                catch (Exception ex)
                {
                    DataStore.CN.NotifyException(ex.Message + relativeFilePath, ex);
                    throw;
                }
            }

            return(resultFile);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// get the StorageFile of the file.
        /// </summary>
        /// <param name="relativeFilePath">
        /// file path relative to the provider base folder.
        /// </param>
        /// <returns>
        /// StorageFile for the chosen file.
        /// </returns>
        /// TODO Check if same as MakeGetFile
        public static IFileInfoEx GetStorageFile(string relativeFilePath)
        {
            IFileInfoEx resultFile = new FileInfoEx(argRelativeFolder: Path.GetDirectoryName(relativeFilePath), argFileName: Path.GetFileName(relativeFilePath));

            // Validate the input
            if ((relativeFilePath is null) || (string.IsNullOrEmpty(relativeFilePath)))
            {
                return(resultFile);
            }

            // Check for relative path
            if (!StoreFileUtility.IsRelativeFilePathValid(relativeFilePath))
            {
                return(resultFile);
            }

            // Load the real file
            if (DataStore.Instance.AD.CurrentDataFolder.Valid)
            {
                try
                {
                    if (Directory.Exists(Path.Combine(DataStore.Instance.AD.CurrentDataFolder.Path, Path.GetDirectoryName(relativeFilePath))))
                    {
                        FileInfo[] t = DataStore.Instance.AD.CurrentDataFolder.Value.GetFiles(relativeFilePath);

                        if (t.Length > 0)
                        {
                            resultFile.FInfo = t[0];
                        }
                    }

                    return(resultFile);
                }
                catch (FileNotFoundException ex)
                {
                    App.Current.Services.GetService <IErrorNotifications>().DataLogEntryAdd(ex.Message + ex.FileName);

                    // default to a standard file marker
                }
                catch (Exception ex)
                {
                    App.Current.Services.GetService <IErrorNotifications>().NotifyException(ex.Message + relativeFilePath, ex);
                    throw;
                }
            }

            return(resultFile);
        }
Ejemplo n.º 6
0
        /// <summary>
        /// get the StorageFile of the file.
        /// </summary>
        /// <param name="argFileName">
        /// file path relative to the provider base folder.
        /// </param>
        /// <returns>
        /// StorageFile for the chosen file.
        /// </returns>
        public static async Task <bool> FolderFileExistsAsync(DirectoryInfo argBaseFolder, string argFileName)
        {
            // Check for relative path
            if (!StoreFileUtility.IsRelativeFilePathValid(argFileName))
            {
                return(false);
            }

            // load the real file
            if (argBaseFolder != null)
            {
                try
                {
                    FileInfo[] t = argBaseFolder.GetFiles();

                    foreach (FileInfo item in t)
                    {
                        if (item.Name == argFileName)
                        {
                            return(true);
                        }
                    }
                }
                catch (FileNotFoundException ex)
                {
                    await DataStore.CN.MajorStatusAdd(ex.Message + ex.FileName).ConfigureAwait(false);

                    // default to a standard file marker
                }
                catch (Exception ex)
                {
                    DataStore.CN.NotifyException(ex.Message + argFileName, ex);
                    throw;
                }
            }

            return(false);
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Get the StorageFile of the file.
        /// </summary>
        /// <param name="argBaseFolder">
        /// Base Folder to start checking
        /// </param>
        /// <param name="argFileName">
        /// file path relative to the provider base folder.
        /// </param>
        /// <returns>
        /// StorageFile for the chosen file.
        /// </returns>
        public static async Task <bool> FolderFileExistsAsync(DirectoryInfo argBaseFolder, string argFileName)
        {
            // Check for relative path
            if (!StoreFileUtility.IsRelativeFilePathValid(argFileName))
            {
                return(false);
            }

            // Load the real file
            if (argBaseFolder != null)
            {
                try
                {
                    FileInfo[] t = argBaseFolder.GetFiles();

                    foreach (FileInfo item in t)
                    {
                        if (item.Name == argFileName)
                        {
                            return(true);
                        }
                    }
                }
                catch (FileNotFoundException ex)
                {
                    App.Current.Services.GetService <IErrorNotifications>().DataLogEntryAdd(ex.Message + ex.FileName);

                    // default to a standard file marker
                }
                catch (Exception ex)
                {
                    App.Current.Services.GetService <IErrorNotifications>().NotifyException(ex.Message + argFileName, ex);
                    throw;
                }
            }

            return(false);
        }