예제 #1
0
        public static List <Core.Data.GeocacheImage> ImportGeocacheImages(Core.Storage.Database db, LiveV6.ImageData[] wps, string GeocacheCode)
        {
            List <Core.Data.GeocacheImage> result  = new List <Core.Data.GeocacheImage>();
            List <Core.Data.GeocacheImage> curImgs = Utils.DataAccess.GetGeocacheImages(db, GeocacheCode);

            if (wps != null)
            {
                foreach (var lg in wps)
                {
                    Core.Data.GeocacheImage g = ImportGeocacheImage(db, lg, GeocacheCode);
                    if (g != null)
                    {
                        result.Add(g);
                        if (curImgs.Contains(g))
                        {
                            curImgs.Remove(g);
                        }
                    }
                }
            }
            foreach (var g in curImgs)
            {
                g.DeleteRecord();
                db.GeocacheImageCollection.Remove(g);
            }
            return(result);
        }
예제 #2
0
        public static Core.Data.GeocacheImage ImportGeocacheImage(Core.Storage.Database db, LiveV6.ImageData img, string GeocacheCode)
        {
            Core.Data.GeocacheImage result = null;
            if (img != null)
            {
                result = db.GeocacheImageCollection.GetGeocacheImage(img.ImageGuid.ToString());

                Core.Data.IGeocacheImageData wpd;
                if (result == null)
                {
                    wpd    = new Core.Data.GeocacheImageData();
                    wpd.ID = img.ImageGuid.ToString();
                }
                else
                {
                    wpd = result;
                }

                wpd.DataFromDate = DateTime.Now;
                wpd.GeocacheCode = GeocacheCode;
                wpd.Name         = img.Name;
                wpd.Url          = img.Url;
                wpd.ThumbUrl     = img.ThumbUrl;
                wpd.MobileUrl    = img.MobileUrl;
                wpd.Description  = img.Description;

                if (wpd is Core.Data.GeocacheImageData)
                {
                    if (Utils.DataAccess.AddGeocacheImage(db, wpd as Core.Data.GeocacheImageData))
                    {
                        result = db.GeocacheImageCollection.GetGeocacheImage(img.ImageGuid.ToString());
                    }
                }
            }
            return(result);
        }
예제 #3
0
        public static Core.Data.GeocacheImage AddGeocacheImage(Core.Storage.Database db, OKAPIService.GeocacheImage img, string GeocacheCode)
        {
            Core.Data.GeocacheImage result = null;
            if (img != null)
            {
                result = db.GeocacheImageCollection.GetGeocacheImage(img.uuid);

                Core.Data.IGeocacheImageData wpd;
                if (result == null)
                {
                    wpd    = new Core.Data.GeocacheImageData();
                    wpd.ID = img.uuid;
                }
                else
                {
                    wpd = result;
                }

                wpd.DataFromDate = DateTime.Now;
                wpd.GeocacheCode = GeocacheCode;
                wpd.Name         = img.caption;
                wpd.Url          = img.url;
                wpd.ThumbUrl     = img.thumb_url;
                wpd.MobileUrl    = img.thumb_url;
                wpd.Description  = "";

                if (wpd is Core.Data.GeocacheImageData)
                {
                    if (Utils.DataAccess.AddGeocacheImage(db, wpd as Core.Data.GeocacheImageData))
                    {
                        result = db.GeocacheImageCollection.GetGeocacheImage(img.uuid);
                    }
                }
            }
            return(result);
        }
예제 #4
0
파일: Export.cs 프로젝트: pheijmans-zz/GAPP
        public async Task CreateImageFolder(List <Core.Data.Geocache> gcList, string folder, bool download, bool NotDescrOnly, bool clearBeforeCopy)
        {
            if (download)
            {
                await OfflineImagesManager.Instance.DownloadImagesAsync(gcList, true);
            }
            await Task.Run(() =>
            {
                try
                {
                    DateTime nextUpdate = DateTime.Now.AddSeconds(1);
                    using (Utils.ProgressBlock progress = new Utils.ProgressBlock("CreatingOfflineImageFolder", "CreatingOfflineImageFolder", gcList.Count, 0, true))
                    {
                        if (!Directory.Exists(folder))
                        {
                            Directory.CreateDirectory(folder);
                        }
                        string imgFolder = Path.Combine(folder, "GeocachePhotos");
                        if (!Directory.Exists(imgFolder))
                        {
                            Directory.CreateDirectory(imgFolder);
                        }
                        if (clearBeforeCopy)
                        {
                            string[] fls = Directory.GetFiles(imgFolder);
                            if (fls != null)
                            {
                                foreach (string f in fls)
                                {
                                    File.Delete(f);
                                }
                            }
                            fls = Directory.GetDirectories(imgFolder);
                            if (fls != null)
                            {
                                foreach (string f in fls)
                                {
                                    Directory.Delete(f, true);
                                }
                            }
                        }
                        int index = 0;
                        foreach (Core.Data.Geocache gc in gcList)
                        {
                            int imgIndex       = 1;
                            string cacheFolder = "";
                            List <string> urls = Utils.DataAccess.GetImagesOfGeocache(gc.Database, gc.Code, NotDescrOnly);
                            Dictionary <string, string> oimgs      = OfflineImagesManager.Instance.GetImages(gc);
                            List <Core.Data.GeocacheImage> imgList = Utils.DataAccess.GetGeocacheImages(gc.Database, gc.Code);
                            foreach (var kp in oimgs)
                            {
                                if (urls.Contains(kp.Key))
                                {
                                    if (string.IsNullOrEmpty(cacheFolder))
                                    {
                                        cacheFolder = Path.Combine(imgFolder, gc.Code[gc.Code.Length - 1].ToString());
                                        if (!Directory.Exists(cacheFolder))
                                        {
                                            Directory.CreateDirectory(cacheFolder);
                                        }
                                        cacheFolder = Path.Combine(cacheFolder, gc.Code[gc.Code.Length - 2].ToString());
                                        if (!Directory.Exists(cacheFolder))
                                        {
                                            Directory.CreateDirectory(cacheFolder);
                                        }
                                        cacheFolder = Path.Combine(cacheFolder, gc.Code);
                                        if (!Directory.Exists(cacheFolder))
                                        {
                                            Directory.CreateDirectory(cacheFolder);
                                        }
                                    }
                                    string imgname = imgIndex.ToString();
                                    if (imgList != null)
                                    {
                                        Core.Data.GeocacheImage img = (from a in imgList where a.Url == kp.Key select a).FirstOrDefault();
                                        if (img != null)
                                        {
                                            imgname = string.Format("{1}{0}", imgIndex, getValidNameForFile(img.Name));
                                        }
                                    }
                                    string dst = Path.Combine(cacheFolder, string.Format("{0}{1}", imgname, Path.GetExtension(kp.Value)));
                                    if (!File.Exists(dst))
                                    {
                                        File.Copy(kp.Value, dst);
                                    }
                                }
                                imgIndex++;
                            }

                            index++;
                            if (DateTime.Now >= nextUpdate)
                            {
                                if (!progress.Update("CreatingOfflineImageFolder", gcList.Count, index))
                                {
                                    break;
                                }
                                nextUpdate = DateTime.Now.AddSeconds(1);
                            }
                        }
                    }
                }
                catch (Exception e)
                {
                    Core.ApplicationData.Instance.Logger.AddLog(this, e);
                }
            });
        }
예제 #5
0
        public static void ImportGeocacheImages(Core.Storage.Database db, List <Core.Data.Geocache> gcList)
        {
            try
            {
                using (Utils.ProgressBlock progress = new Utils.ProgressBlock("UpdatingGeocaches", "UpdatingGeocache", gcList.Count, 0, true))
                {
                    int totalcount = gcList.Count;
                    using (LiveAPI.GeocachingLiveV6 client = new LiveAPI.GeocachingLiveV6())
                    {
                        int index = 0;
                        while (gcList.Count > 0)
                        {
                            if (index > 0)
                            {
                                Thread.Sleep(Core.Settings.Default.LiveAPIDelayGetImagesForGeocache);
                            }
                            var resp = client.Client.GetImagesForGeocache(client.Token, gcList[0].Code);
                            if (resp.Status.StatusCode == 0)
                            {
                                if (resp.Images != null)
                                {
                                    List <string> ids = new List <string>();
                                    foreach (var img in resp.Images)
                                    {
                                        if (img.Url.IndexOf("/cache/log/") < 0)
                                        {
                                            Core.Data.GeocacheImage gcImg = ImportGeocacheImage(db, img, gcList[0].Code);
                                            if (gcImg != null)
                                            {
                                                ids.Add(gcImg.ID);
                                            }
                                        }
                                    }
                                    List <Core.Data.GeocacheImage> allImages = Utils.DataAccess.GetGeocacheImages(db, gcList[0].Code);
                                    foreach (Core.Data.GeocacheImage gim in allImages)
                                    {
                                        if (!ids.Contains(gim.ID))
                                        {
                                            gim.DeleteRecord();
                                            db.GeocacheImageCollection.Remove(gim);
                                        }
                                    }
                                }

                                if (Core.Settings.Default.LiveAPIDeselectAfterUpdate)
                                {
                                    gcList[0].Selected = false;
                                }

                                index++;
                                if (!progress.Update("UpdatingGeocache", totalcount, index))
                                {
                                    break;
                                }
                                gcList.RemoveAt(0);
                            }
                            else
                            {
                                Core.ApplicationData.Instance.Logger.AddLog(new Import(), Core.Logger.Level.Error, resp.Status.StatusMessage);
                                break;
                            }
                        }
                    }
                }
            }
            catch (Exception e)
            {
                Core.ApplicationData.Instance.Logger.AddLog(new Import(), e);
            }
        }