Пример #1
0
        protected override void ImportMethod()
        {
            using (Utils.ProgressBlock blockprogress = new Utils.ProgressBlock(this, STR_IMPORTINGCACHES, STR_IMPORTINGCACHES, 1, 0))
            {
                try
                {
                    //first get a list of geocache codes
                    List <string> gcList = OKAPIService.GetGeocachesWithinRadius(SiteManager.Instance.ActiveSite, _centerLoc, _radiusKm, _filter);
                    using (Utils.ProgressBlock progress = new Utils.ProgressBlock(this, STR_IMPORTINGCACHES, STR_IMPORTINGCACHES, gcList.Count, 0, true))
                    {
                        int gcupdatecount = 1;
                        int max           = gcList.Count;
                        while (gcList.Count > 0)
                        {
                            List <string> lcs = gcList.Take(gcupdatecount).ToList();
                            gcList.RemoveRange(0, lcs.Count);
                            List <OKAPIService.Geocache> caches = OKAPIService.GetGeocaches(SiteManager.Instance.ActiveSite, lcs);
                            Import.AddGeocaches(Core, caches);

                            if (!progress.UpdateProgress(STR_IMPORTINGCACHES, STR_IMPORTINGCACHES, max, max - gcList.Count))
                            {
                                break;
                            }
                        }
                    }
                }
                catch (Exception e)
                {
                    _errormessage = e.Message;
                }
            }
        }
Пример #2
0
        protected override void ImportMethod()
        {
            //for now, we just use the active site
            //howver, in the future it is better to automatically switcg according geocode prefix
            //at this moment, the user is responsible for selecting the geocaches and the active site
            try
            {
                //first get a list of geocache codes
                using (Utils.ProgressBlock progress = new Utils.ProgressBlock(this, STR_UPDATINGGEOCACHES, STR_UPDATINGGEOCACHES, _gcList.Count, 0, true))
                {
                    int gcupdatecount = 1;
                    int max           = _gcList.Count;
                    while (_gcList.Count > 0)
                    {
                        List <string> lcs = (from Framework.Data.Geocache g in _gcList select g.Code).Take(gcupdatecount).ToList();
                        _gcList.RemoveRange(0, lcs.Count);
                        List <OKAPIService.Geocache> caches = OKAPIService.GetGeocaches(SiteManager.Instance.ActiveSite, lcs);
                        Import.AddGeocaches(Core, caches);

                        if (!progress.UpdateProgress(STR_UPDATINGGEOCACHES, STR_UPDATINGGEOCACHES, max, max - _gcList.Count))
                        {
                            break;
                        }
                    }
                }
            }
            catch (Exception e)
            {
                _errormessage = e.Message;
            }
        }
Пример #3
0
        protected override void ImportMethod()
        {
            try
            {
                using (Utils.ProgressBlock progress = new Utils.ProgressBlock(this, STR_IMPORTINGCACHES, STR_IMPORTINGCACHES, _gcList.Count, 0, true))
                {
                    int gcupdatecount = 1;
                    int max           = _gcList.Count;
                    while (_gcList.Count > 0)
                    {
                        List <string> lcs = _gcList.Take(gcupdatecount).ToList();
                        _gcList.RemoveRange(0, lcs.Count);
                        List <OKAPIService.Geocache> caches = OKAPIService.GetGeocaches(SiteManager.Instance.ActiveSite, lcs);
                        Import.AddGeocaches(Core, caches);

                        if (!progress.UpdateProgress(STR_IMPORTINGCACHES, STR_IMPORTINGCACHES, max, max - _gcList.Count))
                        {
                            break;
                        }
                    }
                }
            }
            catch (Exception e)
            {
                _errormessage = e.Message;
            }
        }
Пример #4
0
        protected override void ImportMethod()
        {
            bool cancelled = false;

            using (Utils.ProgressBlock blockprogress = new Utils.ProgressBlock(this, STR_IMPORTINGMYF, STR_IMPORTINGMYF, 1, 0))
            {
                try
                {
                    int stepSize = 100;
                    List <OKAPIService.Log> logs = new List <OKAPIService.Log>();

                    using (Utils.ProgressBlock progress = new Utils.ProgressBlock(this, STR_IMPORTINGMYF, STR_IMPORTINGLOGS, 100, 0, true))
                    {
                        List <OKAPIService.Log> pageLogs = OKAPIService.GetLogsOfUserID(SiteManager.Instance.ActiveSite, SiteManager.Instance.ActiveSite.UserID, stepSize, 0);

                        while (pageLogs.Count() > 0)
                        {
                            logs.AddRange(pageLogs);
                            if (!progress.UpdateProgress(STR_IMPORTINGMYF, STR_IMPORTINGLOGS, logs.Count + stepSize, logs.Count))
                            {
                                cancelled = true;
                                break;
                            }
                            else if (pageLogs.Count() < stepSize)
                            {
                                break;
                            }
                            pageLogs = OKAPIService.GetLogsOfUserID(SiteManager.Instance.ActiveSite, SiteManager.Instance.ActiveSite.UserID, stepSize, logs.Count);
                        }
                    }

                    if (!cancelled)
                    {
                        //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.cache_code) != null select a.cache_code).ToList();
                        foreach (string s in gcList)
                        {
                            Utils.DataAccess.GetGeocache(Core.Geocaches, s).Found = true;
                            var ls = (from a in logs where a.cache_code == s select a).ToList();
                            foreach (var l in ls)
                            {
                                AddLog(Convert.Log(Core, l, SiteManager.Instance.ActiveSite.Username, SiteManager.Instance.ActiveSite.UserID));
                            }
                        }

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

                            while (gcList.Count > 0)
                            {
                                List <string> lcs = gcList.Take(gcupdatecount).ToList();
                                gcList.RemoveRange(0, lcs.Count);
                                List <OKAPIService.Geocache> caches = OKAPIService.GetGeocaches(SiteManager.Instance.ActiveSite, lcs);
                                Import.AddGeocaches(Core, caches);

                                foreach (var g in caches)
                                {
                                    var ls = (from a in logs where a.cache_code == g.code select a).ToList();
                                    foreach (var l in ls)
                                    {
                                        AddLog(Convert.Log(Core, l, SiteManager.Instance.ActiveSite.Username, SiteManager.Instance.ActiveSite.UserID));
                                    }
                                }

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