示例#1
0
        public static async Task Process()
        {
            try
            {
                config = GetConfig();
                TripSpanCache.LocateSameDay = config.locate_same_day;
                var filePaths      = Directory.EnumerateFiles(config.path, "*.jpg", SearchOption.AllDirectories);
                var copyPhotosTask = Task.Run(() => CopyPhotosTask());
                // var copyPhotosWithoutGPSTask = Task.Run(() => CopyPhotosWithoutGPSTask());

                foreach (var filePath in filePaths)
                {
                    try
                    {
                        var meta = ReadMeta(filePath);
                        if (meta != null)
                        {
                            await GenerateAddress(meta).ConfigureAwait(false);

                            if (meta.HasLocation)
                            {
                                GenerateNewFilePath(meta);
                                TripSpanCache.ExpandDuration(meta);
                                photoQueueWithGPS.Enqueue(meta);
                            }
                            else
                            {
                                photoQueueWithoutGPS.Enqueue(meta);
                            }
                        }
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine(string.Format("Error 2: {0}", e.Message));
                    }
                }

                inProgress = false;
                Task.WaitAll(copyPhotosTask);

                //photoWithGPSInProgress = false;
                //Task.WaitAll(copyPhotosWithoutGPSTask);
                CopyPhotosWithoutGPS();

                // Save metadata as log
                SaveMetadata();
            }
            catch (Exception e)
            {
                Console.WriteLine(string.Format("Error: {0}", e.Message));
                // throw;
            }
        }
示例#2
0
        private static void CopyPhotosWithoutGPS()
        {
            while (photoQueueWithoutGPS.Count > 0)
            {
                PhotoMetadata meta;
                if (photoQueueWithoutGPS.TryDequeue(out meta))
                {
                    GoogleAddressInfo address;
                    if (TripSpanCache.TryGetAddress(meta, out address))
                    {
                        meta.Address = address;
                    }

                    GenerateNewFilePath(meta);
                    CopyPhoto(meta);
                }
            }
        }
示例#3
0
        private static void CopyPhotosWithoutGPSTask()
        {
            while (photoWithGPSInProgress)
            {
                PhotoMetadata meta;
                if (photoQueueWithoutGPS.TryPeek(out meta))
                {
                    GoogleAddressInfo address;
                    if (TripSpanCache.TryGetAddress(meta, out address))
                    {
                        meta.Address = address;
                        GenerateNewFilePath(meta);
                        CopyPhoto(meta);
                        photoQueueWithoutGPS.TryDequeue(out meta);
                    }
                }

                Task.Delay(500);
            }
        }