예제 #1
0
 public GeoBackgroundTask(AppSettings appSettings, ISelectorStorage selectorStorage,
                          IGeoLocationWrite geoLocationWrite, IMemoryCache memoryCache,
                          IWebLogger logger, IGeoReverseLookup geoReverseLookup)
 {
     _appSettings      = appSettings;
     _iStorage         = selectorStorage.Get(SelectorStorage.StorageServices.SubPath);
     _thumbnailStorage = selectorStorage.Get(SelectorStorage.StorageServices.Thumbnail);
     _readMeta         = new ReadMeta(_iStorage);
     _geoLocationWrite = geoLocationWrite;
     _logger           = logger;
     _geoIndexGpx      = new GeoIndexGpx(_appSettings, _iStorage, memoryCache);
     _geoReverseLookup = geoReverseLookup;
 }
예제 #2
0
        /// <summary>
        /// Command line importer to Database and update disk
        /// </summary>
        /// <param name="args">arguments provided by command line app</param>
        /// <returns>Void Task</returns>
        public async Task CommandLineAsync(string[] args)
        {
            _appSettings.Verbose = ArgsHelper.NeedVerbose(args);

            // Download ExifTool
            await _exifToolDownload.DownloadExifTool(_appSettings.IsWindows);

            // Geo cities1000 download
            await _geoFileDownload.Download();

            _appSettings.ApplicationType = AppSettings.StarskyAppType.Geo;

            if (new ArgsHelper().NeedHelp(args) ||
                (new ArgsHelper(_appSettings).GetPathFormArgs(args, false).Length <= 1 &&
                 ArgsHelper.GetSubPathFormArgs(args).Length <= 1 &&
                 new ArgsHelper(_appSettings).GetRelativeValue(args) == null))
            {
                new ArgsHelper(_appSettings, _console).NeedHelpShowDialog();
                return;
            }

            // Using both options
            string inputPath;

            // -s = if subPath || -p is path
            if (ArgsHelper.IsSubPathOrPath(args))
            {
                inputPath = _appSettings.DatabasePathToFilePath(
                    ArgsHelper.GetSubPathFormArgs(args)
                    );
            }
            else
            {
                inputPath = new ArgsHelper(_appSettings).GetPathFormArgs(args, false);
            }

            // overwrite subPath with relative days
            // use -g or --SubPathRelative to use it.
            // envs are not supported
            var getSubPathRelative = new ArgsHelper(_appSettings).GetRelativeValue(args);

            if (getSubPathRelative != null)
            {
                var dateTime = DateTime.Now.AddDays(( double )getSubPathRelative);
                inputPath = _appSettings.DatabasePathToFilePath(
                    new StructureService(_iStorage, _appSettings.Structure)
                    .ParseSubfolders(dateTime), false);
            }

            // used in this session to find the files back
            _appSettings.StorageFolder = inputPath;

            if (inputPath == null || _iStorage.IsFolderOrFile("/") == FolderOrFileModel.FolderOrFileTypeList.Deleted)
            {
                _console.WriteLine(
                    $"Folder location is not found \nPlease try the `-h` command to get help \nDid search for: {inputPath}");
                return;
            }

            // use relative to StorageFolder
            var listOfFiles = _iStorage.GetAllFilesInDirectory("/")
                              .Where(ExtensionRolesHelper.IsExtensionSyncSupported).ToList();

            var fileIndexList = _readMeta.ReadExifAndXmpFromFileAddFilePathHash(listOfFiles);

            var toMetaFilesUpdate = new List <FileIndexItem>();

            if (new ArgsHelper().GetIndexMode(args))
            {
                _console.WriteLine($"CameraTimeZone: {_appSettings.CameraTimeZone}");
                _console.WriteLine($"Folder: {inputPath}");

                toMetaFilesUpdate = new GeoIndexGpx(_appSettings,
                                                    _iStorage).LoopFolder(fileIndexList);

                _console.Write("¬");
                await _geoLocationWrite.LoopFolderAsync(toMetaFilesUpdate, false);

                _console.Write("(gps added)");
            }

            fileIndexList = _geoReverseLookup.LoopFolderLookup(fileIndexList,
                                                               ArgsHelper.GetAll(args));
            if (fileIndexList.Count >= 1)
            {
                _console.Write("~ Add city, state and country info ~");

                await _geoLocationWrite.LoopFolderAsync(fileIndexList, true);
            }

            _console.Write("^\n");
            _console.Write("~ Rename thumbnails ~");

            // Loop though all options
            fileIndexList.AddRange(toMetaFilesUpdate);

            // update thumbs to avoid unnecessary re-generation
            foreach (var item in fileIndexList.GroupBy(i => i.FilePath).
                     Select(g => g.First())
                     .ToList())
            {
                var newThumb = (await new FileHash(_iStorage).GetHashCodeAsync(item.FilePath)).Key;
                if (item.FileHash == newThumb)
                {
                    continue;
                }
                new ThumbnailFileMoveAllSizes(_thumbnailStorage).FileMove(
                    item.FileHash, newThumb);
                if (_appSettings.IsVerbose())
                {
                    _console.WriteLine("thumb+ `" + item.FileHash + "`" + newThumb);
                }
            }

            // dont updated in the database
        }