Beispiel #1
0
        public override bool Action(string action)
        {
            bool result = base.Action(action);

            if (result && action == ACTION_SHOW)
            {
                try
                {
                    var logs = new List <Utils.API.LiveV6.GeocacheLog>();

                    using (var api = new Utils.API.GeocachingLiveV6(Core))
                    {
                        using (Utils.ProgressBlock progress = new Utils.ProgressBlock(this, "Importing logs", "Importing logs...", 100, 0, true))
                        {
                            var req = new Utils.API.LiveV6.GetUsersGeocacheLogsRequest();
                            req.AccessToken     = api.Token;
                            req.Username        = "******";
                            req.ExcludeArchived = true;
                            req.MaxPerPage      = 30;
                            req.StartIndex      = 0;
                            req.LogTypes        = (from a in Core.LogTypes where a.AsFound select(long) a.ID).ToArray();
                            var resp = api.Client.GetUsersGeocacheLogs(req);
                            while (resp.Status.StatusCode == 0)
                            {
                                logs.AddRange(resp.Logs);

                                if (resp.Logs.Count() >= req.MaxPerPage)
                                {
                                    req.StartIndex = logs.Count;
                                    if (!progress.UpdateProgress("Importing logs", "Importing logs...", logs.Count + req.MaxPerPage, logs.Count))
                                    {
                                        break;
                                    }
                                    resp = api.Client.GetUsersGeocacheLogs(req);
                                }
                                else
                                {
                                    break;
                                }
                            }
                            if (resp.Status.StatusCode != 0)
                            {
                                //_errormessage = resp.Status.StatusMessage;
                            }
                        }
                    }
                }
                catch
                {
                }
            }
            return(result);
        }
Beispiel #2
0
        public override bool Action(string action)
        {
            bool result = base.Action(action);
            if (result && action == ACTION_SHOW)
            {
                try
                {
                    var logs = new List<Utils.API.LiveV6.GeocacheLog>();

                    using (var api = new Utils.API.GeocachingLiveV6(Core))
                    {
                        using (Utils.ProgressBlock progress = new Utils.ProgressBlock(this, "Importing logs", "Importing logs...", 100, 0, true))
                        {
                            var req = new Utils.API.LiveV6.GetUsersGeocacheLogsRequest();
                            req.AccessToken = api.Token;
                            req.Username = "******";
                            req.ExcludeArchived = true;
                            req.MaxPerPage = 100;
                            req.StartIndex = 0;
                            req.LogTypes = (from a in Core.LogTypes where a.AsFound select (long)a.ID).ToArray();
                            var resp = api.Client.GetUsersGeocacheLogs(req);
                            while (resp.Status.StatusCode == 0)
                            {
                                logs.AddRange(resp.Logs);

                                if (resp.Logs.Count() >= req.MaxPerPage)
                                {
                                    req.StartIndex = logs.Count;
                                    if (!progress.UpdateProgress("Importing logs", "Importing logs...", logs.Count + req.MaxPerPage, logs.Count))
                                    {
                                        break;
                                    }
                                    resp = api.Client.GetUsersGeocacheLogs(req);
                                }
                                else
                                {
                                    break;
                                }
                            }
                            if (resp.Status.StatusCode != 0)
                            {
                                //_errormessage = resp.Status.StatusMessage;
                            }
                        }
                    }
                }
                catch
                {
                }
            }
            return result;
        }
Beispiel #3
0
        protected override void ImportMethod()
        {
            bool cancelled = false;
            using (Utils.ProgressBlock blockprogress = new Utils.ProgressBlock(this, STR_IMPORTINGMYF, STR_IMPORTINGMYF, _users.Count, 0))
            {
                try
                {
                    using (var api = new Utils.API.GeocachingLiveV6(Core))
                    {
                        foreach (string usr in _users)
                        {
                            var logs = new List<Utils.API.LiveV6.GeocacheLog>();
                            int page = 0;
                            using (Utils.ProgressBlock progress = new Utils.ProgressBlock(this, STR_IMPORTINGMYF, STR_IMPORTINGLOGS, 100, 0, true))
                            {
                                var req = new Utils.API.LiveV6.GetUsersGeocacheLogsRequest();
                                req.AccessToken = api.Token;
                                req.ExcludeArchived = true;
                                req.Username = usr;
                                req.MaxPerPage = 30;
                                req.StartIndex = 0;
                                if (PluginSettings.Instance.BetweenDates)
                                {
                                    req.Range = new Utils.API.LiveV6.DateRange();
                                    req.Range.StartDate = _fromDate < _toDate? _fromDate:_toDate;
                                    req.Range.EndDate = _toDate > _fromDate ? _toDate : _fromDate;
                                }
                                req.LogTypes = _logTypes.ToArray();
                                //req.LogTypes = new long[] { 2 };
                                var resp = api.Client.GetUsersGeocacheLogs(req);
                                while (resp.Status.StatusCode == 0)
                                {
                                    logs.AddRange(resp.Logs);

                                    //if (resp.Logs.Count() >= req.MaxPerPage)
                                    if (resp.Logs.Count() > 0)
                                    {
                                        page++;
                                        //req.StartIndex = logs.Count;
                                        req.StartIndex = page * req.MaxPerPage;
                                        if (!progress.UpdateProgress(STR_IMPORTINGMYF, STR_IMPORTINGLOGS, logs.Count + req.MaxPerPage, logs.Count))
                                        {
                                            cancelled = true;
                                            break;
                                        }
                                        System.Threading.Thread.Sleep(2100);
                                        resp = api.Client.GetUsersGeocacheLogs(req);
                                    }
                                    else
                                    {
                                        break;
                                    }
                                }
                                if (resp.Status.StatusCode != 0)
                                {
                                    _errormessage = resp.Status.StatusMessage;
                                }
                            }

                            if (!cancelled)
                            {
                                foreach (var l in logs)
                                {
                                    AddLog(Utils.API.Convert.Log(Core, l));
                                }
                            }

                            //ok, we have the logs
                            //get the geocaches
                            if (PluginSettings.Instance.ImportMissingCaches && !cancelled && string.IsNullOrEmpty(_errormessage))
                            {
                                List<string> gcList = (from a in logs where a.CacheCode!=null && Utils.DataAccess.GetGeocache(Core.Geocaches, a.CacheCode) == null select a.CacheCode).ToList();
                                int maxToGet = gcList.Count;
                                using (Utils.ProgressBlock progress = new Utils.ProgressBlock(this, STR_IMPORTINGMYF, STR_IMPORTINGCACHES, maxToGet, 0, true))
                                {
                                    int index = 0;
                                    int gcupdatecount = 20;

                                    while (gcList.Count > 0)
                                    {
                                        Utils.API.LiveV6.SearchForGeocachesRequest req = new Utils.API.LiveV6.SearchForGeocachesRequest();
                                        req.IsLite = Core.GeocachingComAccount.MemberTypeId == 1;
                                        req.AccessToken = api.Token;
                                        req.CacheCode = new Utils.API.LiveV6.CacheCodeFilter();
                                        req.CacheCode.CacheCodes = (from a in gcList select a).Take(gcupdatecount).ToArray();
                                        req.MaxPerPage = gcupdatecount;
                                        req.GeocacheLogCount = 0;
                                        index += req.CacheCode.CacheCodes.Length;
                                        gcList.RemoveRange(0, req.CacheCode.CacheCodes.Length);
                                        var resp = api.Client.SearchForGeocaches(req);
                                        if (resp.Status.StatusCode == 0 && resp.Geocaches != null)
                                        {
                                            if (resp.CacheLimits != null)
                                            {
                                                _apiLimit = resp.CacheLimits.MaxCacheCount;
                                                _apiLeft = resp.CacheLimits.CachesLeft;
                                            }
                                            Utils.API.Import.AddGeocaches(Core, resp.Geocaches);

                                            if (!progress.UpdateProgress(STR_IMPORTINGMYF, STR_IMPORTINGCACHES, maxToGet, maxToGet - gcList.Count))
                                            {
                                                cancelled = true;
                                                break;
                                            }
                                            if (gcList.Count > 0)
                                            {
                                                Thread.Sleep(3000);
                                            }

                                        }
                                        else
                                        {
                                            _errormessage = resp.Status.StatusMessage;
                                            break;
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
                catch (Exception e)
                {
                    _errormessage = e.Message;
                }
            }
        }
Beispiel #4
0
        protected override void ImportMethod()
        {
            bool cancelled = false;
            using (Utils.ProgressBlock blockprogress = new Utils.ProgressBlock(this, STR_IMPORTINGMYF, STR_IMPORTINGMYF, 1, 0))
            {
                try
                {
                    var logs = new List<Utils.API.LiveV6.GeocacheLog>();

                    using (var api = new Utils.API.GeocachingLiveV6(Core))
                    {
                        using (Utils.ProgressBlock progress = new Utils.ProgressBlock(this, STR_IMPORTINGMYF, STR_IMPORTINGLOGS, 100, 0, true))
                        {
                            var req = new Utils.API.LiveV6.GetUsersGeocacheLogsRequest();
                            req.AccessToken = api.Token;
                            req.ExcludeArchived = false;
                            req.MaxPerPage = 30;
                            req.StartIndex = 0;
                            req.LogTypes = (from a in Core.LogTypes where a.AsFound select (long)a.ID).ToArray();
                            var resp = api.Client.GetUsersGeocacheLogs(req);
                            while (resp.Status.StatusCode == 0)
                            {
                                //logs.AddRange(resp.Logs);
                                //if (resp.Logs.Count() >= req.MaxPerPage)
                                if (resp.Logs.Count() > 0)
                                {
                                    logs.AddRange(resp.Logs);
                                    req.StartIndex = logs.Count;
                                    if (!progress.UpdateProgress(STR_IMPORTINGMYF, STR_IMPORTINGLOGS, logs.Count + req.MaxPerPage, logs.Count))
                                    {
                                        cancelled = true;
                                        break;
                                    }
                                    Thread.Sleep(4000);
                                    resp = api.Client.GetUsersGeocacheLogs(req);
                                }
                                else
                                {
                                    break;
                                }
                            }
                            if (resp.Status.StatusCode != 0)
                            {
                                _errormessage = resp.Status.StatusMessage;
                            }
                        }

                        //ok, we have the logs
                        //get the geocaches
                        if (!cancelled && string.IsNullOrEmpty(_errormessage))
                        {
                            //we download the geocaches that are not present. But for the ones we have, we need to add the log and mark it as found
                            List<string> gcList = (from a in logs where Utils.DataAccess.GetGeocache(Core.Geocaches, a.CacheCode) != null select a.CacheCode).ToList();
                            foreach (string s in gcList)
                            {
                                Utils.DataAccess.GetGeocache(Core.Geocaches, s).Found = true;
                                var ls = (from a in logs where a.CacheCode == s && !a.IsArchived select a).ToList();
                                foreach (var l in ls)
                                {
                                    AddLog(Utils.API.Convert.Log(Core, l));
                                }
                            }

                            gcList = (from a in logs where Utils.DataAccess.GetGeocache(Core.Geocaches, a.CacheCode) == null && !a.IsArchived select a.CacheCode).ToList();
                            using (Utils.ProgressBlock progress = new Utils.ProgressBlock(this, STR_IMPORTINGMYF, STR_IMPORTINGCACHES, gcList.Count, 0, true))
                            {
                                int index = 0;
                                int gcupdatecount = 20;

                                while (gcList.Count > 0)
                                {
                                    Utils.API.LiveV6.SearchForGeocachesRequest req = new Utils.API.LiveV6.SearchForGeocachesRequest();
                                    req.IsLite = Core.GeocachingComAccount.MemberTypeId == 1;
                                    req.AccessToken = api.Token;
                                    req.CacheCode = new Utils.API.LiveV6.CacheCodeFilter();
                                    req.CacheCode.CacheCodes = (from a in gcList select a).Take(gcupdatecount).ToArray();
                                    req.MaxPerPage = gcupdatecount;
                                    req.GeocacheLogCount = 0;
                                    index += req.CacheCode.CacheCodes.Length;
                                    gcList.RemoveRange(0, req.CacheCode.CacheCodes.Length);
                                    var resp = api.Client.SearchForGeocaches(req);
                                    if (resp.Status.StatusCode == 0 && resp.Geocaches != null)
                                    {
                                        if (resp.CacheLimits != null)
                                        {
                                            _apiLimit = resp.CacheLimits.MaxCacheCount;
                                            _apiLeft = resp.CacheLimits.CachesLeft;
                                        }
                                        Utils.API.Import.AddGeocaches(Core, resp.Geocaches);

                                        foreach (var g in resp.Geocaches)
                                        {
                                            var ls = (from a in logs where a.CacheCode == g.Code && !a.IsArchived select a).ToList();
                                            foreach (var l in ls)
                                            {
                                                AddLog(Utils.API.Convert.Log(Core, l));
                                            }
                                        }

                                        if (!progress.UpdateProgress(STR_IMPORTINGMYF, STR_IMPORTINGCACHES, logs.Count, logs.Count - gcList.Count))
                                        {
                                            cancelled = true;
                                            break;
                                        }

                                        if (gcList.Count > 0)
                                        {
                                            Thread.Sleep(3000);
                                        }
                                    }
                                    else
                                    {
                                        _errormessage = resp.Status.StatusMessage;
                                        break;
                                    }
                                }
                            }
                        }
                    }
                }
                catch (Exception e)
                {
                    _errormessage = e.Message;
                }
            }
        }
Beispiel #5
0
        protected override void ImportMethod()
        {
            bool cancelled = false;

            using (Utils.ProgressBlock blockprogress = new Utils.ProgressBlock(this, STR_IMPORTINGMYF, STR_IMPORTINGMYF, _users.Count, 0))
            {
                try
                {
                    using (var api = new Utils.API.GeocachingLiveV6(Core))
                    {
                        foreach (string usr in _users)
                        {
                            var logs = new List <Utils.API.LiveV6.GeocacheLog>();
                            int page = 0;
                            using (Utils.ProgressBlock progress = new Utils.ProgressBlock(this, STR_IMPORTINGMYF, STR_IMPORTINGLOGS, 100, 0, true))
                            {
                                var req = new Utils.API.LiveV6.GetUsersGeocacheLogsRequest();
                                req.AccessToken     = api.Token;
                                req.ExcludeArchived = true;
                                req.Username        = usr;
                                req.MaxPerPage      = 30;
                                req.StartIndex      = 0;
                                if (PluginSettings.Instance.BetweenDates)
                                {
                                    req.Range           = new Utils.API.LiveV6.DateRange();
                                    req.Range.StartDate = _fromDate < _toDate? _fromDate:_toDate;
                                    req.Range.EndDate   = _toDate > _fromDate ? _toDate : _fromDate;
                                }
                                req.LogTypes = _logTypes.ToArray();
                                //req.LogTypes = new long[] { 2 };
                                var resp = api.Client.GetUsersGeocacheLogs(req);
                                while (resp.Status.StatusCode == 0)
                                {
                                    logs.AddRange(resp.Logs);

                                    //if (resp.Logs.Count() >= req.MaxPerPage)
                                    if (resp.Logs.Count() > 0)
                                    {
                                        page++;
                                        //req.StartIndex = logs.Count;
                                        req.StartIndex = page * req.MaxPerPage;
                                        if (!progress.UpdateProgress(STR_IMPORTINGMYF, STR_IMPORTINGLOGS, logs.Count + req.MaxPerPage, logs.Count))
                                        {
                                            cancelled = true;
                                            break;
                                        }
                                        System.Threading.Thread.Sleep(2100);
                                        resp = api.Client.GetUsersGeocacheLogs(req);
                                    }
                                    else
                                    {
                                        break;
                                    }
                                }
                                if (resp.Status.StatusCode != 0)
                                {
                                    _errormessage = resp.Status.StatusMessage;
                                }
                            }

                            if (!cancelled)
                            {
                                foreach (var l in logs)
                                {
                                    AddLog(Utils.API.Convert.Log(Core, l));
                                }
                            }

                            //ok, we have the logs
                            //get the geocaches
                            if (PluginSettings.Instance.ImportMissingCaches && !cancelled && string.IsNullOrEmpty(_errormessage))
                            {
                                List <string> gcList   = (from a in logs where a.CacheCode != null && Utils.DataAccess.GetGeocache(Core.Geocaches, a.CacheCode) == null select a.CacheCode).ToList();
                                int           maxToGet = gcList.Count;
                                using (Utils.ProgressBlock progress = new Utils.ProgressBlock(this, STR_IMPORTINGMYF, STR_IMPORTINGCACHES, maxToGet, 0, true))
                                {
                                    int index         = 0;
                                    int gcupdatecount = 20;

                                    while (gcList.Count > 0)
                                    {
                                        Utils.API.LiveV6.SearchForGeocachesRequest req = new Utils.API.LiveV6.SearchForGeocachesRequest();
                                        req.IsLite               = Core.GeocachingComAccount.MemberTypeId == 1;
                                        req.AccessToken          = api.Token;
                                        req.CacheCode            = new Utils.API.LiveV6.CacheCodeFilter();
                                        req.CacheCode.CacheCodes = (from a in gcList select a).Take(gcupdatecount).ToArray();
                                        req.MaxPerPage           = gcupdatecount;
                                        req.GeocacheLogCount     = 0;
                                        index += req.CacheCode.CacheCodes.Length;
                                        gcList.RemoveRange(0, req.CacheCode.CacheCodes.Length);
                                        var resp = api.Client.SearchForGeocaches(req);
                                        if (resp.Status.StatusCode == 0 && resp.Geocaches != null)
                                        {
                                            if (resp.CacheLimits != null)
                                            {
                                                _apiLimit = resp.CacheLimits.MaxCacheCount;
                                                _apiLeft  = resp.CacheLimits.CachesLeft;
                                            }
                                            Utils.API.Import.AddGeocaches(Core, resp.Geocaches);

                                            if (!progress.UpdateProgress(STR_IMPORTINGMYF, STR_IMPORTINGCACHES, maxToGet, maxToGet - gcList.Count))
                                            {
                                                cancelled = true;
                                                break;
                                            }
                                            if (gcList.Count > 0)
                                            {
                                                Thread.Sleep(3000);
                                            }
                                        }
                                        else
                                        {
                                            _errormessage = resp.Status.StatusMessage;
                                            break;
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
                catch (Exception e)
                {
                    _errormessage = e.Message;
                }
            }
        }
Beispiel #6
0
        private void getImagesThreadMethod()
        {
            try
            {
                using (Utils.ProgressBlock blockprogress = new Utils.ProgressBlock(OwnerPlugin as Utils.BasePlugin.Plugin, STR_IMPORTINGMYF, STR_IMPORTINGMYF, 1, 0))
                {
                    try
                    {
                        Utils.DBCon dbcon = initDatabase();

                        var logs = new List<Utils.API.LiveV6.GeocacheLog>();

                        using (System.Net.WebClient wc = new System.Net.WebClient())
                        using (var api = new Utils.API.GeocachingLiveV6(Core))
                        {
                            using (Utils.ProgressBlock progress = new Utils.ProgressBlock(OwnerPlugin as Utils.BasePlugin.Plugin, STR_IMPORTINGMYF, STR_IMPORTINGLOGS, 100, 0, true))
                            {
                                var req = new Utils.API.LiveV6.GetUsersGeocacheLogsRequest();
                                req.AccessToken = api.Token;
                                req.ExcludeArchived = false;
                                req.MaxPerPage = 50;
                                req.StartIndex = 0;
                                req.LogTypes = (from a in Core.LogTypes select (long)a.ID).ToArray();
                                var resp = api.Client.GetUsersGeocacheLogs(req);
                                while (resp.Status.StatusCode == 0)
                                {
                                    logs.AddRange(resp.Logs);
                                    foreach (var log in resp.Logs)
                                    {
                                        if (log.Images != null && !log.IsArchived)
                                        {
                                            foreach (var li in log.Images)
                                            {
                                                string imgGuid = li.ImageGuid.ToString("N");
                                                ImageInfo ii = (from a in _imageInfoList where a.ImageGuid==imgGuid select a).FirstOrDefault();
                                                if (ii == null)
                                                {
                                                    ii = new ImageInfo();
                                                    ii.Description = li.Description;
                                                    ii.ImageGuid = imgGuid;
                                                    ii.MobileUrl = li.MobileUrl ?? "";
                                                    ii.Name = li.Name ?? "";
                                                    ii.ThumbUrl = li.ThumbUrl;
                                                    ii.Url = li.Url;
                                                    ii.LogCacheCode = log.CacheCode;
                                                    ii.LogCode = log.Code;
                                                    ii.LogUrl = log.Url;
                                                    ii.LogVisitDate = log.VisitDate;

                                                    ii.ThumbFile = Path.Combine(_thumbFolder, Path.GetFileName(li.ThumbUrl));
                                                    ii.ImgFile = Path.Combine(_imgFolder, Path.GetFileName(li.Url));

                                                    _imageInfoList.Add(ii);

                                                    dbcon.ExecuteNonQuery(string.Format("insert into gallery (ImageGuid, ThumbUrl, Description, Name, MobileUrl, Url, LogCacheCode, LogCode, LogUrl, LogVisitDate, ThumbFile, ImgFile) values ('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}','{10}','{11}')", ii.ImageGuid.Replace("'", "''"), ii.ThumbUrl.Replace("'", "''"), ii.Description.Replace("'", "''"), ii.Name.Replace("'", "''"), ii.MobileUrl.Replace("'", "''"), ii.Url.Replace("'", "''"), ii.LogCacheCode.Replace("'", "''"), ii.LogCode.Replace("'", "''"), ii.LogUrl.Replace("'", "''"), ii.LogVisitDate.ToString("s").Replace("'", "''"), ii.ThumbFile.Replace("'", "''"), ii.ImgFile.Replace("'", "''")));
                                                }
                                                //check if local file(s) exist(s)
                                                //not fail on img download!
                                                try
                                                {
                                                    if (!File.Exists(ii.ThumbFile))
                                                    {
                                                        wc.DownloadFile(li.ThumbUrl, ii.ThumbFile);
                                                    }
                                                    if (!File.Exists(ii.ImgFile))
                                                    {
                                                        wc.DownloadFile(li.Url, ii.ImgFile);
                                                    }
                                                }
                                                catch
                                                {
                                                }
                                            }
                                        }
                                    }

                                    if (resp.Logs.Count() >= req.MaxPerPage)
                                    {
                                        req.StartIndex = logs.Count;
                                        if (!progress.UpdateProgress(STR_IMPORTINGMYF, STR_IMPORTINGLOGS, logs.Count + req.MaxPerPage, logs.Count))
                                        {
                                            break;
                                        }
                                        Thread.Sleep(1500);
                                        resp = api.Client.GetUsersGeocacheLogs(req);
                                    }
                                    else
                                    {
                                        break;
                                    }
                                }
                                if (resp.Status.StatusCode != 0)
                                {
                                    _errormessage = resp.Status.StatusMessage;
                                }
                            }

                        }
                        if (dbcon != null)
                        {
                            dbcon.Dispose();
                            dbcon = null;
                        }
                    }
                    catch (Exception e)
                    {
                        _errormessage = e.Message;
                    }
                }
            }
            catch
            {
            }
            _actionReady.Set();
        }
Beispiel #7
0
        protected override void ImportMethod()
        {
            bool cancelled = false;

            using (Utils.ProgressBlock blockprogress = new Utils.ProgressBlock(this, STR_IMPORTINGMYF, STR_IMPORTINGMYF, 1, 0))
            {
                try
                {
                    var logs = new List <Utils.API.LiveV6.GeocacheLog>();

                    using (var api = new Utils.API.GeocachingLiveV6(Core))
                    {
                        using (Utils.ProgressBlock progress = new Utils.ProgressBlock(this, STR_IMPORTINGMYF, STR_IMPORTINGLOGS, 100, 0, true))
                        {
                            var req = new Utils.API.LiveV6.GetUsersGeocacheLogsRequest();
                            req.AccessToken     = api.Token;
                            req.ExcludeArchived = false;
                            req.MaxPerPage      = 30;
                            req.StartIndex      = 0;
                            req.LogTypes        = (from a in Core.LogTypes where a.AsFound select(long) a.ID).ToArray();
                            var resp = api.Client.GetUsersGeocacheLogs(req);
                            while (resp.Status.StatusCode == 0)
                            {
                                //logs.AddRange(resp.Logs);
                                //if (resp.Logs.Count() >= req.MaxPerPage)
                                if (resp.Logs.Count() > 0)
                                {
                                    logs.AddRange(resp.Logs);
                                    req.StartIndex = logs.Count;
                                    if (!progress.UpdateProgress(STR_IMPORTINGMYF, STR_IMPORTINGLOGS, logs.Count + req.MaxPerPage, logs.Count))
                                    {
                                        cancelled = true;
                                        break;
                                    }
                                    Thread.Sleep(4000);
                                    resp = api.Client.GetUsersGeocacheLogs(req);
                                }
                                else
                                {
                                    break;
                                }
                            }
                            if (resp.Status.StatusCode != 0)
                            {
                                _errormessage = resp.Status.StatusMessage;
                            }
                        }

                        //ok, we have the logs
                        //get the geocaches
                        if (!cancelled && string.IsNullOrEmpty(_errormessage))
                        {
                            //we download the geocaches that are not present. But for the ones we have, we need to add the log and mark it as found
                            List <string> gcList = (from a in logs where Utils.DataAccess.GetGeocache(Core.Geocaches, a.CacheCode) != null select a.CacheCode).ToList();
                            foreach (string s in gcList)
                            {
                                Utils.DataAccess.GetGeocache(Core.Geocaches, s).Found = true;
                                var ls = (from a in logs where a.CacheCode == s && !a.IsArchived select a).ToList();
                                foreach (var l in ls)
                                {
                                    AddLog(Utils.API.Convert.Log(Core, l));
                                }
                            }

                            gcList = (from a in logs where Utils.DataAccess.GetGeocache(Core.Geocaches, a.CacheCode) == null && !a.IsArchived select a.CacheCode).ToList();
                            using (Utils.ProgressBlock progress = new Utils.ProgressBlock(this, STR_IMPORTINGMYF, STR_IMPORTINGCACHES, gcList.Count, 0, true))
                            {
                                int index         = 0;
                                int gcupdatecount = 20;

                                while (gcList.Count > 0)
                                {
                                    Utils.API.LiveV6.SearchForGeocachesRequest req = new Utils.API.LiveV6.SearchForGeocachesRequest();
                                    req.IsLite               = Core.GeocachingComAccount.MemberTypeId == 1;
                                    req.AccessToken          = api.Token;
                                    req.CacheCode            = new Utils.API.LiveV6.CacheCodeFilter();
                                    req.CacheCode.CacheCodes = (from a in gcList select a).Take(gcupdatecount).ToArray();
                                    req.MaxPerPage           = gcupdatecount;
                                    req.GeocacheLogCount     = 0;
                                    index += req.CacheCode.CacheCodes.Length;
                                    gcList.RemoveRange(0, req.CacheCode.CacheCodes.Length);
                                    var resp = api.Client.SearchForGeocaches(req);
                                    if (resp.Status.StatusCode == 0 && resp.Geocaches != null)
                                    {
                                        if (resp.CacheLimits != null)
                                        {
                                            _apiLimit = resp.CacheLimits.MaxCacheCount;
                                            _apiLeft  = resp.CacheLimits.CachesLeft;
                                        }
                                        Utils.API.Import.AddGeocaches(Core, resp.Geocaches);

                                        foreach (var g in resp.Geocaches)
                                        {
                                            var ls = (from a in logs where a.CacheCode == g.Code && !a.IsArchived select a).ToList();
                                            foreach (var l in ls)
                                            {
                                                AddLog(Utils.API.Convert.Log(Core, l));
                                            }
                                        }

                                        if (!progress.UpdateProgress(STR_IMPORTINGMYF, STR_IMPORTINGCACHES, logs.Count, logs.Count - gcList.Count))
                                        {
                                            cancelled = true;
                                            break;
                                        }

                                        if (gcList.Count > 0)
                                        {
                                            Thread.Sleep(3000);
                                        }
                                    }
                                    else
                                    {
                                        _errormessage = resp.Status.StatusMessage;
                                        break;
                                    }
                                }
                            }
                        }
                    }
                }
                catch (Exception e)
                {
                    _errormessage = e.Message;
                }
            }
        }
Beispiel #8
0
        private void getImagesThreadMethod()
        {
            try
            {
                using (Utils.ProgressBlock blockprogress = new Utils.ProgressBlock(OwnerPlugin as Utils.BasePlugin.Plugin, STR_IMPORTINGMYF, STR_IMPORTINGMYF, 1, 0))
                {
                    try
                    {
                        Utils.DBCon dbcon = initDatabase();

                        var logs = new List <Utils.API.LiveV6.GeocacheLog>();

                        using (System.Net.WebClient wc = new System.Net.WebClient())
                            using (var api = new Utils.API.GeocachingLiveV6(Core))
                            {
                                using (Utils.ProgressBlock progress = new Utils.ProgressBlock(OwnerPlugin as Utils.BasePlugin.Plugin, STR_IMPORTINGMYF, STR_IMPORTINGLOGS, 100, 0, true))
                                {
                                    var req = new Utils.API.LiveV6.GetUsersGeocacheLogsRequest();
                                    req.AccessToken     = api.Token;
                                    req.ExcludeArchived = false;
                                    req.MaxPerPage      = 50;
                                    req.StartIndex      = 0;
                                    req.LogTypes        = (from a in Core.LogTypes select(long) a.ID).ToArray();
                                    var resp = api.Client.GetUsersGeocacheLogs(req);
                                    while (resp.Status.StatusCode == 0)
                                    {
                                        logs.AddRange(resp.Logs);
                                        foreach (var log in resp.Logs)
                                        {
                                            if (log.Images != null && !log.IsArchived)
                                            {
                                                foreach (var li in log.Images)
                                                {
                                                    string    imgGuid = li.ImageGuid.ToString("N");
                                                    ImageInfo ii      = (from a in _imageInfoList where a.ImageGuid == imgGuid select a).FirstOrDefault();
                                                    if (ii == null)
                                                    {
                                                        ii              = new ImageInfo();
                                                        ii.Description  = li.Description;
                                                        ii.ImageGuid    = imgGuid;
                                                        ii.MobileUrl    = li.MobileUrl ?? "";
                                                        ii.Name         = li.Name ?? "";
                                                        ii.ThumbUrl     = li.ThumbUrl;
                                                        ii.Url          = li.Url;
                                                        ii.LogCacheCode = log.CacheCode;
                                                        ii.LogCode      = log.Code;
                                                        ii.LogUrl       = log.Url;
                                                        ii.LogVisitDate = log.VisitDate;

                                                        ii.ThumbFile = Path.Combine(_thumbFolder, Path.GetFileName(li.ThumbUrl));
                                                        ii.ImgFile   = Path.Combine(_imgFolder, Path.GetFileName(li.Url));

                                                        _imageInfoList.Add(ii);

                                                        dbcon.ExecuteNonQuery(string.Format("insert into gallery (ImageGuid, ThumbUrl, Description, Name, MobileUrl, Url, LogCacheCode, LogCode, LogUrl, LogVisitDate, ThumbFile, ImgFile) values ('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}','{10}','{11}')", ii.ImageGuid.Replace("'", "''"), ii.ThumbUrl.Replace("'", "''"), ii.Description.Replace("'", "''"), ii.Name.Replace("'", "''"), ii.MobileUrl.Replace("'", "''"), ii.Url.Replace("'", "''"), ii.LogCacheCode.Replace("'", "''"), ii.LogCode.Replace("'", "''"), ii.LogUrl.Replace("'", "''"), ii.LogVisitDate.ToString("s").Replace("'", "''"), ii.ThumbFile.Replace("'", "''"), ii.ImgFile.Replace("'", "''")));
                                                    }
                                                    //check if local file(s) exist(s)
                                                    //not fail on img download!
                                                    try
                                                    {
                                                        if (!File.Exists(ii.ThumbFile))
                                                        {
                                                            wc.DownloadFile(li.ThumbUrl, ii.ThumbFile);
                                                        }
                                                        if (!File.Exists(ii.ImgFile))
                                                        {
                                                            wc.DownloadFile(li.Url, ii.ImgFile);
                                                        }
                                                    }
                                                    catch
                                                    {
                                                    }
                                                }
                                            }
                                        }

                                        if (resp.Logs.Count() >= req.MaxPerPage)
                                        {
                                            req.StartIndex = logs.Count;
                                            if (!progress.UpdateProgress(STR_IMPORTINGMYF, STR_IMPORTINGLOGS, logs.Count + req.MaxPerPage, logs.Count))
                                            {
                                                break;
                                            }
                                            Thread.Sleep(1500);
                                            resp = api.Client.GetUsersGeocacheLogs(req);
                                        }
                                        else
                                        {
                                            break;
                                        }
                                    }
                                    if (resp.Status.StatusCode != 0)
                                    {
                                        _errormessage = resp.Status.StatusMessage;
                                    }
                                }
                            }
                        if (dbcon != null)
                        {
                            dbcon.Dispose();
                            dbcon = null;
                        }
                    }
                    catch (Exception e)
                    {
                        _errormessage = e.Message;
                    }
                }
            }
            catch
            {
            }
            _actionReady.Set();
        }