示例#1
0
        // May throw exception. Returned path may not exist.
        private string GetFileFullPath(string nameBase, ExportCommand cmd, int n)
        {
            var fileName = nameBase + n.ToString().PadLeft(2, '0') + cmd.Extension;

            return(Path.Combine(ExportDirectory(cmd).RemoveIllegalPathChars(),
                                fileName.RemoveIllegalFileNameChars()));
        }
示例#2
0
        private Status Export(string nameBase, ExportCommand c, int i)
        {
            try
            {
                var fileName = GetFileFullPath(nameBase, c, i);

                // Although the file name has been checked to have no conflict, if the user choose
                // to export multiple files to the same folder, the file names can still collide.
                var newName = File.Exists(fileName)
                    ? GenerateFileName(nameBase + i.ToString().PadLeft(2, '0'), c)
                    : fileName;

                File.WriteAllText(newName,
                                  Providers.Types.GetExportText(c.ProviderType, route, navaids, airports));
                return(new Status(newName, true, "", false));
            }
            catch (Exception ex)
            {
                LoggerInstance.Log(ex);
                var mayBePermissionIssue = ex is UnauthorizedAccessException ||
                                           ex is SecurityException;

                return(new Status(c.CustomDirectory, false, ex.Message, mayBePermissionIssue));
            }
        }
示例#3
0
 public bool Equals(ExportCommand other)
 {
     return(ProviderType == other.ProviderType &&
            Directory == other.Directory &&
            Extension == other.Extension &&
            Enabled == other.Enabled);
 }
示例#4
0
 private bool FileExist(string nameBase, ExportCommand cmd, int n)
 {
     return(DefaultIfThrows(() =>
     {
         var filePath = GetFileFullPath(nameBase, cmd, n);
         return File.Exists(filePath);
     }, false));
 }
示例#5
0
 /// Returned path may be null or not exist.
 private string ExportDirectory(ExportCommand c) =>
 Providers.Types.ExportDirectory(c.DefaultSimulator, c, options());
示例#6
0
 private static string GenerateFileName(string nameBase, ExportCommand c)
 {
     return(FileNameGenerator.Generate(c.CustomDirectory.RemoveIllegalPathChars(),
                                       nameBase, c.Extension, n => "_" + n.ToString(), 1));
 }
示例#7
0
        private static bool FileExist(string nameBase, ExportCommand cmd, int n)
        {
            var filePath = GetFileFullPath(nameBase, cmd, n);

            return(File.Exists(filePath));
        }