Esempio n. 1
0
 private Framework.Data.Geocache getGeocache(string code)
 {
     Cursor = Cursors.WaitCursor;
     Framework.Data.Geocache result = null;
     try
     {
         Utils.API.LiveV6.SearchForGeocachesRequest req = new Utils.API.LiveV6.SearchForGeocachesRequest();
         req.IsLite               = _core.GeocachingComAccount.MemberTypeId == 1;
         req.AccessToken          = _client.Token;
         req.CacheCode            = new Utils.API.LiveV6.CacheCodeFilter();
         req.CacheCode.CacheCodes = new string[] { code };
         req.MaxPerPage           = 1;
         req.GeocacheLogCount     = 5;
         var resp = _client.Client.SearchForGeocaches(req);
         if (resp.Status.StatusCode == 0 && resp.Geocaches != null)
         {
             Utils.API.Import.AddGeocaches(_core, resp.Geocaches);
         }
         else
         {
             System.Windows.Forms.MessageBox.Show(resp.Status.StatusMessage, Utils.LanguageSupport.Instance.GetTranslation(Utils.LanguageSupport.Instance.GetTranslation(STR_ERROR)), System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error);
         }
     }
     catch
     {
     }
     Cursor = Cursors.Default;
     return(result);
 }
Esempio n. 2
0
 private void buttonCheck_Click(object sender, EventArgs e)
 {
     this.linkLabel1.Text = "";
     this.Cursor          = Cursors.WaitCursor;
     try
     {
         using (Utils.API.GeocachingLiveV6 api = new Utils.API.GeocachingLiveV6(_core))
         {
             var req = new Utils.API.LiveV6.SearchForGeocachesRequest();
             req.AccessToken          = api.Token;
             req.CacheCode            = new Utils.API.LiveV6.CacheCodeFilter();
             req.CacheCode.CacheCodes = new string[] { textBox3.Text.ToUpper().Trim() };
             req.IsLite           = true;
             req.MaxPerPage       = 1;
             req.GeocacheLogCount = 0;
             var resp = api.Client.SearchForGeocaches(req);
             if (resp.Status.StatusCode == 0)
             {
                 if (resp.Geocaches != null && resp.Geocaches.Count() > 0)
                 {
                     linkLabel1.Text = string.Format("{0}, {1}", resp.Geocaches[0].Code, resp.Geocaches[0].Name);
                     linkLabel1.Links.Add(0, resp.Geocaches[0].Code.Length, resp.Geocaches[0].Url);
                 }
             }
             else
             {
                 System.Windows.Forms.MessageBox.Show(resp.Status.StatusMessage, Utils.LanguageSupport.Instance.GetTranslation(Utils.LanguageSupport.Instance.GetTranslation(STR_ERROR)), System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error);
             }
         }
     }
     catch
     {
     }
     this.Cursor = Cursors.Default;
 }
Esempio n. 3
0
        protected override void ImportMethod()
        {
            int max = _gcList.Count;
            int gcupdatecount = 50;
            int index = 0;
            TimeSpan interval = new TimeSpan(0, 0, 0, 2, 100);
            DateTime prevCall = DateTime.MinValue;
            bool dodelay = (_gcList.Count > 30);
            using (Utils.ProgressBlock progress = new Utils.ProgressBlock(this, STR_IMPORTING, STR_IMPORTING, max, 0, true))
            {
                try
                {
                    using (Utils.API.GeocachingLiveV6 client = new Utils.API.GeocachingLiveV6(Core, string.IsNullOrEmpty(Core.GeocachingComAccount.APIToken)))
                    {
                        while (_gcList.Count > 0)
                        {
                            if (dodelay)
                            {
                                TimeSpan ts = DateTime.Now - prevCall;
                                if (ts < interval)
                                {
                                    Thread.Sleep(interval - ts);
                                }
                            }

                            Utils.API.LiveV6.SearchForGeocachesRequest req = new Utils.API.LiveV6.SearchForGeocachesRequest();
                            req.IsLite = Core.GeocachingComAccount.MemberTypeId == 1;
                            req.AccessToken = client.Token;
                            req.CacheCode = new Utils.API.LiveV6.CacheCodeFilter();
                            req.CacheCode.CacheCodes = _gcList.Take(gcupdatecount).ToArray();
                            req.MaxPerPage = gcupdatecount;
                            req.GeocacheLogCount = 5;
                            index += req.CacheCode.CacheCodes.Length;
                            _gcList.RemoveRange(0, req.CacheCode.CacheCodes.Length);
                            prevCall = DateTime.Now;
                            var resp = client.Client.SearchForGeocaches(req);
                            if (resp.Status.StatusCode == 0 && resp.Geocaches != null)
                            {
                                Utils.API.Import.AddGeocaches(Core, resp.Geocaches);
                            }
                            else
                            {
                                _errormessage = resp.Status.StatusMessage;
                                break;
                            }
                            if (!progress.UpdateProgress(STR_IMPORTING, STR_IMPORTING, max, index))
                            {
                                break;
                            }
                        }
                    }
                }
                catch(Exception e)
                {
                    _errormessage = e.Message;
                }
            }
        }
Esempio n. 4
0
 private void buttonAdd_Click(object sender, EventArgs e)
 {
     Framework.Data.Geocache gc = null;
     if (textBox1.Text.Length > 0)
     {
         gc = Utils.DataAccess.GetGeocache(_core.Geocaches, textBox1.Text.ToUpper());
         if (gc == null)
         {
             //not in our system, try geocaching.com
             if (textBox1.Text.ToUpper().StartsWith("GC"))
             {
                 Cursor = Cursors.WaitCursor;
                 try
                 {
                     var req = new Utils.API.LiveV6.SearchForGeocachesRequest();
                     req.AccessToken = _client.Token;
                     req.CacheCode   = new Utils.API.LiveV6.CacheCodeFilter()
                     {
                         CacheCodes = new string[] { textBox1.Text.ToUpper() }
                     };
                     req.IsLite           = _core.GeocachingComAccount.MemberTypeId == 1;
                     req.MaxPerPage       = 1;
                     req.GeocacheLogCount = 0;
                     var resp = _client.Client.SearchForGeocaches(req);
                     if (resp.Status.StatusCode == 0)
                     {
                         if (resp.Geocaches != null && resp.Geocaches.Length > 0)
                         {
                             gc = Utils.API.Convert.Geocache(_core, resp.Geocaches[0]);
                         }
                     }
                     else
                     {
                         if (!string.IsNullOrEmpty(resp.Status.StatusMessage))
                         {
                             MessageBox.Show(resp.Status.StatusMessage, Utils.LanguageSupport.Instance.GetTranslation(Utils.LanguageSupport.Instance.GetTranslation(STR_ERROR)), MessageBoxButtons.OK, MessageBoxIcon.Error);
                         }
                     }
                 }
                 catch
                 {
                     System.Windows.Forms.MessageBox.Show(Utils.LanguageSupport.Instance.GetTranslation(STR_FAILUNKNOWN), Utils.LanguageSupport.Instance.GetTranslation(STR_ERROR), System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error);
                 }
                 Cursor = Cursors.Default;
             }
         }
         if (gc != null)
         {
             addGeocacheToList(gc);
             checkSubmitButton();
         }
     }
 }
Esempio n. 5
0
        private void importGeocachesThreadMethod()
        {
            int max           = _gcList.Count;
            int gcupdatecount = 20;
            int index         = 0;

            using (Utils.ProgressBlock progress = new Utils.ProgressBlock(OwnerPlugin, STR_IMPORTING, STR_IMPORTING, max, 0, true))
            {
                try
                {
                    using (Utils.API.GeocachingLiveV6 client = new Utils.API.GeocachingLiveV6(Core, string.IsNullOrEmpty(Core.GeocachingComAccount.APIToken)))
                    {
                        while (_gcList.Count > 0)
                        {
                            Utils.API.LiveV6.SearchForGeocachesRequest req = new Utils.API.LiveV6.SearchForGeocachesRequest();
                            req.IsLite               = Core.GeocachingComAccount.MemberTypeId == 1;
                            req.AccessToken          = client.Token;
                            req.CacheCode            = new Utils.API.LiveV6.CacheCodeFilter();
                            req.CacheCode.CacheCodes = _gcList.Take(gcupdatecount).ToArray();
                            req.MaxPerPage           = gcupdatecount;
                            req.GeocacheLogCount     = 5;
                            index += req.CacheCode.CacheCodes.Length;
                            _gcList.RemoveRange(0, req.CacheCode.CacheCodes.Length);
                            var resp = client.Client.SearchForGeocaches(req);
                            if (resp.Status.StatusCode == 0 && resp.Geocaches != null)
                            {
                                Utils.API.Import.AddGeocaches(Core, resp.Geocaches);
                            }
                            else
                            {
                                _errormessage = resp.Status.StatusMessage;
                                break;
                            }
                            if (!progress.UpdateProgress(STR_IMPORTING, STR_IMPORTING, max, index))
                            {
                                break;
                            }

                            if (_gcList.Count > 0)
                            {
                                Thread.Sleep(3000);
                            }
                        }
                    }
                }
                catch
                {
                }
            }
            _actionReady.Set();
        }
        private void getGeocachesThreadMethod()
        {
            try
            {
                using (Utils.ProgressBlock progress = new Utils.ProgressBlock(_plugin, STR_IMPORTING, STR_IMPORTING, _geocacheCodes.Count, 0, true))
                {
                    int totalcount    = _geocacheCodes.Count;
                    int index         = 0;
                    int gcupdatecount = 20;
                    while (_geocacheCodes.Count > 0)
                    {
                        Utils.API.LiveV6.SearchForGeocachesRequest req = new Utils.API.LiveV6.SearchForGeocachesRequest();
                        req.IsLite               = _core.GeocachingComAccount.MemberTypeId == 1;
                        req.AccessToken          = _client.Token;
                        req.CacheCode            = new Utils.API.LiveV6.CacheCodeFilter();
                        req.CacheCode.CacheCodes = (from a in _geocacheCodes select a).Take(gcupdatecount).ToArray();
                        req.MaxPerPage           = gcupdatecount;
                        req.GeocacheLogCount     = 5;
                        index += req.CacheCode.CacheCodes.Length;
                        _geocacheCodes.RemoveRange(0, req.CacheCode.CacheCodes.Length);
                        var resp = _client.Client.SearchForGeocaches(req);
                        if (resp.Status.StatusCode == 0 && resp.Geocaches != null)
                        {
                            Utils.API.Import.AddGeocaches(_core, resp.Geocaches);
                        }
                        else
                        {
                            _errormessage = resp.Status.StatusMessage;
                            break;
                        }

                        if (!progress.UpdateProgress(STR_IMPORTING, STR_IMPORTING, totalcount, index))
                        {
                            break;
                        }

                        if (_geocacheCodes.Count > 0)
                        {
                            Thread.Sleep(3000);
                        }
                    }
                }
            }
            catch
            {
            }
        }
Esempio n. 7
0
 private Framework.Data.Geocache getGeocache(string code)
 {
     Cursor = Cursors.WaitCursor;
     Framework.Data.Geocache result = null;
     try
     {
         Utils.API.LiveV6.SearchForGeocachesRequest req = new Utils.API.LiveV6.SearchForGeocachesRequest();
         req.IsLite = _core.GeocachingComAccount.MemberTypeId == 1;
         req.AccessToken = _client.Token;
         req.CacheCode = new Utils.API.LiveV6.CacheCodeFilter();
         req.CacheCode.CacheCodes = new string[] { code };
         req.MaxPerPage = 1;
         req.GeocacheLogCount = 5;
         var resp = _client.Client.SearchForGeocaches(req);
         if (resp.Status.StatusCode == 0 && resp.Geocaches != null)
         {
             Utils.API.Import.AddGeocaches(_core, resp.Geocaches);
         }
         else
         {
             System.Windows.Forms.MessageBox.Show(resp.Status.StatusMessage, Utils.LanguageSupport.Instance.GetTranslation(Utils.LanguageSupport.Instance.GetTranslation(STR_ERROR)), System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error);
         }
     }
     catch
     {
     }
     Cursor = Cursors.Default;
     return result;
 }
Esempio n. 8
0
 public async override Task<bool> ActionAsync(string action)
 {
     bool result = base.Action(action);
     if (result)
     {
         if (Utils.API.GeocachingLiveV6.CheckAPIAccessAvailable(Core, false))
         {
             using (GetGeocachesForm dlg = new GetGeocachesForm(this, Core))
             {
                 if (dlg.ShowDialog() == DialogResult.OK && dlg.SearchForGeocachesRequestProperties!=null)
                 {
                     req = dlg.SearchForGeocachesRequestProperties;
                     max = dlg.Max;
                     _apiLimit = -1;
                     _errormessage = null;
                     await PerformImport();
                     if (!string.IsNullOrEmpty(_errormessage))
                     {
                         MessageBox.Show(_errormessage, Utils.LanguageSupport.Instance.GetTranslation(Utils.LanguageSupport.Instance.GetTranslation(STR_ERROR)), MessageBoxButtons.OK, MessageBoxIcon.Error);
                     }
                     if (_apiLimit >= 0)
                     {
                         Utils.Dialogs.LiveAPICachesLeftForm.ShowMessage(_apiLimit, _apiLeft);
                     }
                 }
             }
         }
     }
     return result;
 }
Esempio n. 9
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;
                }
            }
        }
Esempio n. 10
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;
                }
            }
        }
Esempio n. 11
0
        protected override void ImportMethod()
        {
            using (Utils.ProgressBlock progress = new Utils.ProgressBlock(this, STR_IMPORT, STR_IMPORTINGCACHES, 1, 0, true))
            {
                using (Utils.API.GeocachingLiveV6 api = new Utils.API.GeocachingLiveV6(Core))
                {
                    try
                    {
                        var respC = api.Client.GetCacheIdsFavoritedByUser(api.Token);
                        if (respC.Status.StatusCode == 0)
                        {
                            Favorites.Instance(Core).Reset(respC.CacheCodes);
                            List<string> gcList = (from s in respC.CacheCodes where Utils.DataAccess.GetGeocache(Core.Geocaches, s) == null select s).ToList();

                            if (gcList.Count > 0)
                            {
                                if (progress.UpdateProgress(STR_IMPORT, STR_IMPORTINGCACHES, gcList.Count, 0))
                                {
                                    int index = 0;
                                    int max = gcList.Count;
                                    int gcupdatecount;
                                    TimeSpan interval = new TimeSpan(0, 0, 0, 2, 100);
                                    DateTime prevCall = DateTime.MinValue;
                                    bool dodelay;

                                    gcupdatecount = 20;
                                    dodelay = (gcList.Count > 30);

                                    while (gcList.Count > 0)
                                    {
                                        if (dodelay)
                                        {
                                            TimeSpan ts = DateTime.Now - prevCall;
                                            if (ts < interval)
                                            {
                                                System.Threading.Thread.Sleep(interval - ts);
                                            }
                                        }

                                        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);
                                        prevCall = DateTime.Now;
                                        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_IMPORT, STR_IMPORTINGCACHES, max, max - gcList.Count))
                                            {
                                                break;
                                            }

                                        }
                                        else
                                        {
                                            _errormessage = resp.Status.StatusMessage;
                                            break;
                                        }
                                    }
                                }
                            }
                        }
                        else
                        {
                            _errormessage = respC.Status.StatusMessage;
                        }
                    }
                    catch(Exception e)
                    {
                        _errormessage = e.Message;
                    }
                }
            }

        }
Esempio n. 12
0
 private void buttonAdd_Click(object sender, EventArgs e)
 {
     Framework.Data.Geocache gc = null;
     if (textBox1.Text.Length > 0)
     {
         gc = Utils.DataAccess.GetGeocache(_core.Geocaches, textBox1.Text.ToUpper());
         if (gc == null)
         {
             //not in our system, try geocaching.com
             if (textBox1.Text.ToUpper().StartsWith("GC"))
             {
                 Cursor = Cursors.WaitCursor;
                 try
                 {
                     var req = new Utils.API.LiveV6.SearchForGeocachesRequest();
                     req.AccessToken = _client.Token;
                     req.CacheCode = new Utils.API.LiveV6.CacheCodeFilter() { CacheCodes = new string[] { textBox1.Text.ToUpper() } };
                     req.IsLite = _core.GeocachingComAccount.MemberTypeId == 1;
                     req.MaxPerPage = 1;
                     req.GeocacheLogCount = 0;
                     var resp = _client.Client.SearchForGeocaches(req);
                     if (resp.Status.StatusCode == 0)
                     {
                         if (resp.Geocaches != null && resp.Geocaches.Length > 0)
                         {
                             gc = Utils.API.Convert.Geocache(_core, resp.Geocaches[0]);
                         }
                     }
                     else
                     {
                         if (!string.IsNullOrEmpty(resp.Status.StatusMessage))
                         {
                             MessageBox.Show(resp.Status.StatusMessage, Utils.LanguageSupport.Instance.GetTranslation(Utils.LanguageSupport.Instance.GetTranslation(STR_ERROR)), MessageBoxButtons.OK, MessageBoxIcon.Error);
                         }
                     }
                 }
                 catch
                 {
                     System.Windows.Forms.MessageBox.Show(Utils.LanguageSupport.Instance.GetTranslation(STR_FAILUNKNOWN), Utils.LanguageSupport.Instance.GetTranslation(STR_ERROR), System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error);
                 }
                 Cursor = Cursors.Default;
             }
         }
         if (gc != null)
         {
             addGeocacheToList(gc);
             checkSubmitButton();
         }
     }
 }
Esempio n. 13
0
 private void getCopiedSelectionGeocacheInbackgroundMethod()
 {
     try
     {
         int max = _importGeocaches.Count;
         using (Utils.ProgressBlock prog = new Utils.ProgressBlock(OwnerPlugin as Utils.BasePlugin.Plugin, STR_COPYSELECTION, STR_RETRIEVING, max, 0, true))
         {
             using (Utils.API.GeocachingLiveV6 client = new Utils.API.GeocachingLiveV6(Core, string.IsNullOrEmpty(Core.GeocachingComAccount.APIToken)))
             {
                 var req = new Utils.API.LiveV6.SearchForGeocachesRequest();
                 req.AccessToken = client.Token;
                 while (_importGeocaches.Count > 0)
                 {
                     req.CacheCode = new Utils.API.LiveV6.CacheCodeFilter();
                     req.CacheCode.CacheCodes = (from gc in _importGeocaches select gc).Take(10).ToArray();
                     req.GeocacheLogCount = 5;
                     req.IsLite = Core.GeocachingComAccount.MemberTypeId == 1;
                     req.MaxPerPage = req.CacheCode.CacheCodes.Length;
                     var resp = client.Client.SearchForGeocaches(req);
                     if (resp.Status.StatusCode == 0 && resp.Geocaches != null)
                     {
                         _importGeocaches.RemoveRange(0, req.CacheCode.CacheCodes.Length);
                         Utils.API.Import.AddGeocaches(Core, resp.Geocaches);
                     }
                     else
                     {
                         break;
                     }
                     if (!prog.UpdateProgress(STR_COPYSELECTION, STR_RETRIEVING, max, max - _importGeocaches.Count))
                     {
                         break;
                     }
                 }
             }
         }
     }
     catch
     {
     }
     _context.Send(new SendOrPostCallback(delegate(object state)
     {
         _frameworkUpdater.Dispose();
         _frameworkUpdater = null;
     }), null);
 }
Esempio n. 14
0
 protected override void ImportMethod()
 {
     try
     {
         using (Utils.ProgressBlock progress = new Utils.ProgressBlock(this, STR_UPDATINGGEOCACHES, STR_UPDATINGGEOCACHE, _gcList.Count, 0, true))
         {
             int totalcount = _gcList.Count;
             using (Utils.API.GeocachingLiveV6 client = new Utils.API.GeocachingLiveV6(Core, string.IsNullOrEmpty(Core.GeocachingComAccount.APIToken)))
             {
                 int index = 0;
                 int gcupdatecount;
                 TimeSpan interval = new TimeSpan(0, 0, 0, 2, 100);
                 DateTime prevCall = DateTime.MinValue;
                 bool dodelay;
                 if (_updateStatusOnly)
                 {
                     gcupdatecount = 109;
                     dodelay = (_gcList.Count / gcupdatecount > 30);
                 }
                 else
                 {
                     gcupdatecount = 30;
                     dodelay = (_gcList.Count > 30);
                 }
                 while (_gcList.Count > 0)
                 {
                     if (dodelay)
                     {
                         TimeSpan ts = DateTime.Now - prevCall;
                         if (ts < interval)
                         {
                             Thread.Sleep(interval - ts);
                         }
                     }
                     if (_updateStatusOnly)
                     {
                         var req = new Utils.API.LiveV6.GetGeocacheStatusRequest();
                         req.AccessToken = client.Token;
                         req.CacheCodes = (from a in _gcList select a.Code).Take(gcupdatecount).ToArray();
                         _gcList.RemoveRange(0, req.CacheCodes.Length);
                         index += req.CacheCodes.Length;
                         prevCall = DateTime.Now;
                         var resp = client.Client.GetGeocacheStatus(req);
                         if (resp.Status.StatusCode == 0 && resp.GeocacheStatuses != null)
                         {
                             foreach (var gs in resp.GeocacheStatuses)
                             {
                                 Framework.Data.Geocache gc = Utils.DataAccess.GetGeocache(Core.Geocaches, gs.CacheCode);
                                 if (gc != null)
                                 {
                                     gc.DataFromDate = DateTime.Now;
                                     gc.Archived = gs.Archived;
                                     gc.Available = gs.Available;
                                     gc.Name = gs.CacheName;
                                     gc.Title = gs.CacheName;
                                     gc.MemberOnly = gs.Premium;
                                     if (Properties.Settings.Default.DeselectGeocacheAfterUpdate)
                                     {
                                         gc.Selected = false;
                                     }
                                 }
                             }
                         }
                         else
                         {
                             if (resp.Status.StatusCode != 0)
                             {
                                 _errormessage = resp.Status.StatusMessage;
                             }
                             break;
                         }
                     }
                     else
                     {
                         Utils.API.LiveV6.SearchForGeocachesRequest req = new Utils.API.LiveV6.SearchForGeocachesRequest();
                         req.IsLite = Core.GeocachingComAccount.MemberTypeId == 1;
                         req.AccessToken = client.Token;
                         req.CacheCode = new Utils.API.LiveV6.CacheCodeFilter();
                         req.CacheCode.CacheCodes = (from a in _gcList select a.Code).Take(gcupdatecount).ToArray();
                         req.MaxPerPage = gcupdatecount;
                         req.GeocacheLogCount = 5;
                         index += req.CacheCode.CacheCodes.Length;
                         _gcList.RemoveRange(0, req.CacheCode.CacheCodes.Length);
                         prevCall = DateTime.Now;
                         var resp = client.Client.SearchForGeocaches(req);
                         if (resp.Status.StatusCode == 0 && resp.Geocaches != null)
                         {
                             Utils.API.Import.AddGeocaches(Core, resp.Geocaches);
                             if (Properties.Settings.Default.DeselectGeocacheAfterUpdate)
                             {
                                 foreach (var g in resp.Geocaches)
                                 {
                                     Framework.Data.Geocache gc = Utils.DataAccess.GetGeocache(Core.Geocaches, g.Code);
                                     if (gc != null)
                                     {
                                         gc.Selected = false;
                                     }
                                 }
                             }
                         }
                         else
                         {
                             _errormessage = resp.Status.StatusMessage;
                             break;
                         }
                     }
                     if (!progress.UpdateProgress(STR_UPDATINGGEOCACHES, STR_UPDATINGGEOCACHE, totalcount, index))
                     {
                         break;
                     }
                 }
             }
         }
     }
     catch(Exception e)
     {
         _errormessage = e.Message;
     }
 }
Esempio n. 15
0
        protected override void ImportMethod()
        {
            try
            {
                using (Utils.ProgressBlock progress = new Utils.ProgressBlock(this, STR_UPDATINGGEOCACHES, STR_UPDATINGGEOCACHE, _gcList.Count, 0, true))
                {
                    int totalcount = _gcList.Count;
                    using (Utils.API.GeocachingLiveV6 client = new Utils.API.GeocachingLiveV6(Core, string.IsNullOrEmpty(Core.GeocachingComAccount.APIToken)))
                    {
                        int index = 0;
                        int gcupdatecount;
                        if (_updateStatusOnly)
                        {
                            gcupdatecount = 109;
                        }
                        else
                        {
                            gcupdatecount = 20;
                        }
                        while (_gcList.Count > 0)
                        {
                            if (_updateStatusOnly)
                            {
                                var req = new Utils.API.LiveV6.GetGeocacheStatusRequest();
                                req.AccessToken = client.Token;
                                req.CacheCodes  = (from a in _gcList select a.Code).Take(gcupdatecount).ToArray();
                                _gcList.RemoveRange(0, req.CacheCodes.Length);
                                index += req.CacheCodes.Length;
                                var resp = client.Client.GetGeocacheStatus(req);
                                if (resp.Status.StatusCode == 0 && resp.GeocacheStatuses != null)
                                {
                                    foreach (var gs in resp.GeocacheStatuses)
                                    {
                                        Framework.Data.Geocache gc = Utils.DataAccess.GetGeocache(Core.Geocaches, gs.CacheCode);
                                        if (gc != null)
                                        {
                                            gc.DataFromDate = DateTime.Now;
                                            gc.Archived     = gs.Archived;
                                            gc.Available    = gs.Available;
                                            gc.Name         = gs.CacheName;
                                            gc.Title        = gs.CacheName;
                                            gc.MemberOnly   = gs.Premium;
                                            if (PluginSettings.Instance.DeselectGeocacheAfterUpdate)
                                            {
                                                gc.Selected = false;
                                            }
                                        }
                                    }
                                }
                                else
                                {
                                    if (resp.Status.StatusCode != 0)
                                    {
                                        _errormessage = resp.Status.StatusMessage;
                                    }
                                    break;
                                }
                            }
                            else
                            {
                                Utils.API.LiveV6.SearchForGeocachesRequest req = new Utils.API.LiveV6.SearchForGeocachesRequest();
                                req.IsLite               = Core.GeocachingComAccount.MemberTypeId == 1;
                                req.AccessToken          = client.Token;
                                req.CacheCode            = new Utils.API.LiveV6.CacheCodeFilter();
                                req.CacheCode.CacheCodes = (from a in _gcList select a.Code).Take(gcupdatecount).ToArray();
                                req.MaxPerPage           = gcupdatecount;
                                req.GeocacheLogCount     = 5;
                                index += req.CacheCode.CacheCodes.Length;
                                _gcList.RemoveRange(0, req.CacheCode.CacheCodes.Length);
                                var resp = client.Client.SearchForGeocaches(req);
                                if (resp.Status.StatusCode == 0 && resp.Geocaches != null)
                                {
                                    Utils.API.Import.AddGeocaches(Core, resp.Geocaches);
                                    if (PluginSettings.Instance.DeselectGeocacheAfterUpdate)
                                    {
                                        foreach (var g in resp.Geocaches)
                                        {
                                            Framework.Data.Geocache gc = Utils.DataAccess.GetGeocache(Core.Geocaches, g.Code);
                                            if (gc != null)
                                            {
                                                gc.Selected = false;
                                            }
                                        }
                                    }
                                }
                                else
                                {
                                    _errormessage = resp.Status.StatusMessage;
                                    break;
                                }
                            }
                            if (!progress.UpdateProgress(STR_UPDATINGGEOCACHES, STR_UPDATINGGEOCACHE, totalcount, index))
                            {
                                break;
                            }

                            if (_gcList.Count > 0)
                            {
                                Thread.Sleep(3000);
                            }
                        }
                    }
                }
            }
            catch (Exception e)
            {
                _errormessage = e.Message;
            }
        }
Esempio n. 16
0
        protected override void ImportMethod()
        {
            using (Utils.ProgressBlock progress = new Utils.ProgressBlock(this, STR_IMPORT, STR_IMPORTINGCACHES, 1, 0, true))
            {
                using (Utils.API.GeocachingLiveV6 api = new Utils.API.GeocachingLiveV6(Core))
                {
                    try
                    {
                        var respC = api.Client.GetCacheIdsFavoritedByUser(api.Token);
                        if (respC.Status.StatusCode == 0)
                        {
                            Favorites.Instance(Core).Reset(respC.CacheCodes);
                            List <string> gcList = (from s in respC.CacheCodes where Utils.DataAccess.GetGeocache(Core.Geocaches, s) == null select s).ToList();

                            if (gcList.Count > 0)
                            {
                                if (progress.UpdateProgress(STR_IMPORT, STR_IMPORTINGCACHES, gcList.Count, 0))
                                {
                                    int      index = 0;
                                    int      max   = gcList.Count;
                                    int      gcupdatecount;
                                    TimeSpan interval = new TimeSpan(0, 0, 0, 2, 100);
                                    DateTime prevCall = DateTime.MinValue;
                                    bool     dodelay;

                                    gcupdatecount = 20;
                                    dodelay       = (gcList.Count > 30);

                                    while (gcList.Count > 0)
                                    {
                                        if (dodelay)
                                        {
                                            TimeSpan ts = DateTime.Now - prevCall;
                                            if (ts < interval)
                                            {
                                                System.Threading.Thread.Sleep(interval - ts);
                                            }
                                        }

                                        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);
                                        prevCall = DateTime.Now;
                                        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_IMPORT, STR_IMPORTINGCACHES, max, max - gcList.Count))
                                            {
                                                break;
                                            }
                                        }
                                        else
                                        {
                                            _errormessage = resp.Status.StatusMessage;
                                            break;
                                        }
                                    }
                                }
                            }
                        }
                        else
                        {
                            _errormessage = respC.Status.StatusMessage;
                        }
                    }
                    catch (Exception e)
                    {
                        _errormessage = e.Message;
                    }
                }
            }
        }
Esempio n. 17
0
        private void buttonImport_Click(object sender, EventArgs e)
        {
            PluginSettings.Instance.UseMetric = this.radioButtonKm.Checked;
            PluginSettings.Instance.MaxLogs = (int)this.numericUpDownLogCount.Value;
            PluginSettings.Instance.MaxPerRequest = (int)this.numericUpDownMaxPerPage.Value;
            PluginSettings.Instance.TotalMaximum = (int)this.numericUpDownMaximum.Value;

            SavePresets();

            SearchForGeocachesRequestProperties = new Utils.API.LiveV6.SearchForGeocachesRequest();
            SearchForGeocachesRequestProperties.IsLite = _core.GeocachingComAccount.MemberTypeId==1;
            Max = (int)numericUpDownMaximum.Value;
            SearchForGeocachesRequestProperties.MaxPerPage = (int)Math.Min(numericUpDownMaximum.Value, numericUpDownMaxPerPage.Value);
            if (textBoxLocation.Text != "")
            {
                double dist = (double)numericUpDownRadius.Value * 1000.0;
                if (radioButtonMiles.Checked) dist *= 1.6214;
                Framework.Data.Location l = Utils.Conversion.StringToLocation(textBoxLocation.Text);

                SearchForGeocachesRequestProperties.PointRadius = new Utils.API.LiveV6.PointRadiusFilter();
                SearchForGeocachesRequestProperties.PointRadius.DistanceInMeters = (long)dist;
                SearchForGeocachesRequestProperties.PointRadius.Point = new Utils.API.LiveV6.LatLngPoint();
                SearchForGeocachesRequestProperties.PointRadius.Point.Latitude = l.Lat;
                SearchForGeocachesRequestProperties.PointRadius.Point.Longitude = l.Lon;
            }
            if (textBoxCodes.Text != "")
            {
                string[] parts = textBoxCodes.Text.Split(new char[] { ',', ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries);
                SearchForGeocachesRequestProperties.CacheCode = new Utils.API.LiveV6.CacheCodeFilter();
                SearchForGeocachesRequestProperties.CacheCode.CacheCodes = (from s in parts select s.ToUpper()).ToArray();
            }
            SearchForGeocachesRequestProperties.GeocacheLogCount = (int)numericUpDownLogCount.Value;
            if (_core.GeocachingComAccount.MemberTypeId > 1)
            {
                SearchForGeocachesRequestProperties.FavoritePoints = new Utils.API.LiveV6.FavoritePointsFilter();
                SearchForGeocachesRequestProperties.FavoritePoints.MinFavoritePoints = (int)numericUpDownMinFav.Value;
                SearchForGeocachesRequestProperties.FavoritePoints.MaxFavoritePoints = (int)numericUpDownMaxFav.Value;
                SearchForGeocachesRequestProperties.Difficulty = new Utils.API.LiveV6.DifficultyFilter();
                SearchForGeocachesRequestProperties.Difficulty.MinDifficulty = (double)numericUpDownMinDif.Value;
                SearchForGeocachesRequestProperties.Difficulty.MaxDifficulty = (double)numericUpDownMaxDif.Value;
                SearchForGeocachesRequestProperties.Terrain = new Utils.API.LiveV6.TerrainFilter();
                SearchForGeocachesRequestProperties.Terrain.MinTerrain = (double)numericUpDownMinTer.Value;
                SearchForGeocachesRequestProperties.Terrain.MaxTerrain = (double)numericUpDownMaxTer.Value;

                if (checkBoxArchived.CheckState != CheckState.Indeterminate ||
                    checkBoxAvailable.CheckState != CheckState.Indeterminate ||
                    checkBoxPremium.CheckState != CheckState.Indeterminate)
                {
                    SearchForGeocachesRequestProperties.GeocacheExclusions = new Utils.API.LiveV6.GeocacheExclusionsFilter();
                    if (checkBoxArchived.CheckState != CheckState.Indeterminate)
                    {
                        SearchForGeocachesRequestProperties.GeocacheExclusions.Archived = (checkBoxArchived.CheckState != CheckState.Checked);
                    }
                    if (checkBoxAvailable.CheckState != CheckState.Indeterminate)
                    {
                        SearchForGeocachesRequestProperties.GeocacheExclusions.Available = (checkBoxAvailable.CheckState != CheckState.Checked);
                    }
                    if (checkBoxPremium.CheckState != CheckState.Indeterminate)
                    {
                        SearchForGeocachesRequestProperties.GeocacheExclusions.Premium = (checkBoxPremium.CheckState != CheckState.Checked);
                    }
                }
            }
            if (textBoxName.Text != "")
            {
                SearchForGeocachesRequestProperties.GeocacheName = new Utils.API.LiveV6.GeocacheNameFilter();
                SearchForGeocachesRequestProperties.GeocacheName.GeocacheName = textBoxName.Text;
            }
            if (_core.GeocachingComAccount.MemberTypeId > 1)
            {
                long[] gcTypeIds = (from ListViewItem s in listViewGeocacheType.Items where s.Checked select (long)Utils.DataAccess.GetGeocacheType(_core.GeocacheTypes, s.SubItems[0].Text).ID).ToArray();
                if (gcTypeIds.Length < listViewGeocacheType.Items.Count)
                {
                    SearchForGeocachesRequestProperties.GeocacheType = new Utils.API.LiveV6.GeocacheTypeFilter();
                    SearchForGeocachesRequestProperties.GeocacheType.GeocacheTypeIds = gcTypeIds;
                }
                long[] cntTypeIds = (from ListViewItem s in listViewContainer.Items where s.Checked select (long)Utils.DataAccess.GetGeocacheContainer(_core.GeocacheContainers, s.SubItems[0].Text).ID).ToArray();
                if (cntTypeIds.Length < listViewContainer.Items.Count)
                {
                    SearchForGeocachesRequestProperties.GeocacheContainerSize = new Utils.API.LiveV6.GeocacheContainerSizeFilter();
                    SearchForGeocachesRequestProperties.GeocacheContainerSize.GeocacheContainerSizeIds = cntTypeIds;
                }
                if (textBoxNotFound.Text != "")
                {
                    SearchForGeocachesRequestProperties.NotFoundByUsers = new Utils.API.LiveV6.NotFoundByUsersFilter();
                    string[] parts = textBoxNotFound.Text.Split(new char[] { ',', '\t' }, StringSplitOptions.RemoveEmptyEntries);
                    SearchForGeocachesRequestProperties.NotFoundByUsers.UserNames = (from s in parts select s.Trim()).ToArray();
                }
                if (textBoxNotHidden.Text != "")
                {
                    SearchForGeocachesRequestProperties.NotHiddenByUsers = new Utils.API.LiveV6.NotHiddenByUsersFilter();
                    string[] parts = textBoxNotHidden.Text.Split(new char[] { ',', '\t' }, StringSplitOptions.RemoveEmptyEntries);
                    SearchForGeocachesRequestProperties.NotHiddenByUsers.UserNames = (from s in parts select s.Trim()).ToArray();
                }
            }
            if (textBoxHiddenBy.Text != "")
            {
                SearchForGeocachesRequestProperties.HiddenByUsers = new Utils.API.LiveV6.HiddenByUsersFilter();
                string[] parts = textBoxHiddenBy.Text.Split(new char[] { ',', '\t' }, StringSplitOptions.RemoveEmptyEntries);
                SearchForGeocachesRequestProperties.HiddenByUsers.UserNames = (from s in parts select s.Trim()).ToArray();
            }
            if (_core.GeocachingComAccount.MemberTypeId > 1)
            {
                //SearchForGeocachesRequestProperties.TrackableCount = new Utils.API.LiveV6.TrackableCountFilter();
                //SearchForGeocachesRequestProperties.TrackableCount.MinTrackables = (int)numericUpDownTrackMin.Value;
                //SearchForGeocachesRequestProperties.TrackableCount.MaxTrackables = (int)numericUpDownTrackMax.Value;
                SearchForGeocachesRequestProperties.TrackableLogCount = 0;
                if (checkBox1.Checked)
                {
                    SearchForGeocachesRequestProperties.CachePublishedDate = new Utils.API.LiveV6.CachePublishedDateFilter();
                    SearchForGeocachesRequestProperties.CachePublishedDate.Range = new Utils.API.LiveV6.DateRange();
                    SearchForGeocachesRequestProperties.CachePublishedDate.Range.StartDate = dateTimePicker1.Value < dateTimePicker2.Value ? dateTimePicker1.Value : dateTimePicker2.Value;
                    SearchForGeocachesRequestProperties.CachePublishedDate.Range.EndDate = dateTimePicker2.Value > dateTimePicker1.Value ? dateTimePicker2.Value : dateTimePicker1.Value;
                }
            }
        }
        private void getGeocachesThreadMethod()
        {
            try
            {
                using (Utils.ProgressBlock progress = new Utils.ProgressBlock(_plugin, STR_IMPORTING, STR_IMPORTING, _geocacheCodes.Count, 0, true))
                {
                    int totalcount = _geocacheCodes.Count;
                    int index = 0;
                    int gcupdatecount = 20;
                    while (_geocacheCodes.Count > 0)
                    {
                        Utils.API.LiveV6.SearchForGeocachesRequest req = new Utils.API.LiveV6.SearchForGeocachesRequest();
                        req.IsLite = _core.GeocachingComAccount.MemberTypeId == 1;
                        req.AccessToken = _client.Token;
                        req.CacheCode = new Utils.API.LiveV6.CacheCodeFilter();
                        req.CacheCode.CacheCodes = (from a in _geocacheCodes select a).Take(gcupdatecount).ToArray();
                        req.MaxPerPage = gcupdatecount;
                        req.GeocacheLogCount = 5;
                        index += req.CacheCode.CacheCodes.Length;
                        _geocacheCodes.RemoveRange(0, req.CacheCode.CacheCodes.Length);
                        var resp = _client.Client.SearchForGeocaches(req);
                        if (resp.Status.StatusCode == 0 && resp.Geocaches != null)
                        {
                            Utils.API.Import.AddGeocaches(_core, resp.Geocaches);
                        }
                        else
                        {
                            _errormessage = resp.Status.StatusMessage;
                            break;
                        }

                        if (!progress.UpdateProgress(STR_IMPORTING, STR_IMPORTING, totalcount, index))
                        {
                            break;
                        }

                        if (_geocacheCodes.Count > 0)
                        {
                            Thread.Sleep(3000);
                        }
                    }
                }
            }
            catch
            {
            }
        }
Esempio n. 19
0
        protected override void ImportMethod()
        {
            List <Utils.API.LiveV6.CacheNote> missingGeocaches = new List <Utils.API.LiveV6.CacheNote>();
            string errMessage = "";

            try
            {
                using (Utils.ProgressBlock progress = new Utils.ProgressBlock(this, STR_IMPORTING, STR_IMPORTING, 1, 0))
                {
                    //clear all notes
                    foreach (Framework.Data.Geocache gc in Core.Geocaches)
                    {
                        gc.PersonaleNote = "";
                    }

                    using (Utils.API.GeocachingLiveV6 client = new Utils.API.GeocachingLiveV6(Core, string.IsNullOrEmpty(Core.GeocachingComAccount.APIToken)))
                    {
                        int maxPerRequest = 30;
                        int startIndex    = 0;
                        var resp          = client.Client.GetUsersCacheNotes(client.Token, startIndex, maxPerRequest);
                        while (resp.Status.StatusCode == 0)
                        {
                            foreach (var n in resp.CacheNotes)
                            {
                                Framework.Data.Geocache gc = Utils.DataAccess.GetGeocache(Core.Geocaches, n.CacheCode);
                                if (gc != null)
                                {
                                    string s = n.Note ?? "";
                                    s = s.Replace("\r", "");
                                    s = s.Replace("\n", "\r\n");
                                    gc.PersonaleNote = s;
                                }
                                else
                                {
                                    missingGeocaches.Add(n);
                                }
                            }
                            if (resp.CacheNotes.Count() >= maxPerRequest)
                            {
                                startIndex += resp.CacheNotes.Count();
                                Thread.Sleep(2100);
                                resp = client.Client.GetUsersCacheNotes(client.Token, startIndex, maxPerRequest);
                            }
                            else
                            {
                                break;
                            }
                        }
                        if (resp.Status.StatusCode != 0)
                        {
                            if (!string.IsNullOrEmpty(resp.Status.StatusMessage))
                            {
                                errMessage = resp.Status.StatusMessage;
                            }
                        }
                    }
                }
                if (string.IsNullOrEmpty(errMessage) && missingGeocaches.Count > 0)
                {
                    List <string> gcList = (from a in missingGeocaches select a.CacheCode).ToList();
                    if (System.Windows.Forms.MessageBox.Show(string.Format("{0} {1}", missingGeocaches.Count, Utils.LanguageSupport.Instance.GetTranslation(Utils.LanguageSupport.Instance.GetTranslation(STR_IMPORTGEOCACHES))), Utils.LanguageSupport.Instance.GetTranslation(Utils.LanguageSupport.Instance.GetTranslation(STR_QUESTIONGEOCACHES)), System.Windows.Forms.MessageBoxButtons.YesNo, System.Windows.Forms.MessageBoxIcon.Question) == System.Windows.Forms.DialogResult.Yes)
                    {
                        using (Utils.ProgressBlock progress = new Utils.ProgressBlock(this, STR_IMPORTINGGEOCACHES, STR_IMPORTINGGEOCACHES, gcList.Count, 0, true))
                        {
                            int totalcount = gcList.Count;
                            using (Utils.API.GeocachingLiveV6 client = new Utils.API.GeocachingLiveV6(Core, string.IsNullOrEmpty(Core.GeocachingComAccount.APIToken)))
                            {
                                int      index = 0;
                                int      gcupdatecount;
                                TimeSpan interval = new TimeSpan(0, 0, 0, 2, 100);
                                DateTime prevCall = DateTime.MinValue;
                                bool     dodelay;
                                gcupdatecount = 50;
                                dodelay       = (gcList.Count > 30);
                                while (gcList.Count > 0)
                                {
                                    if (dodelay)
                                    {
                                        TimeSpan ts = DateTime.Now - prevCall;
                                        if (ts < interval)
                                        {
                                            Thread.Sleep(interval - ts);
                                        }
                                    }
                                    Utils.API.LiveV6.SearchForGeocachesRequest req = new Utils.API.LiveV6.SearchForGeocachesRequest();
                                    req.IsLite               = Core.GeocachingComAccount.MemberTypeId == 1;
                                    req.AccessToken          = client.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     = 5;
                                    index += req.CacheCode.CacheCodes.Length;
                                    gcList.RemoveRange(0, req.CacheCode.CacheCodes.Length);
                                    prevCall = DateTime.Now;
                                    var resp = client.Client.SearchForGeocaches(req);
                                    if (resp.Status.StatusCode == 0 && resp.Geocaches != null)
                                    {
                                        Utils.API.Import.AddGeocaches(Core, resp.Geocaches);
                                    }
                                    else
                                    {
                                        errMessage = resp.Status.StatusMessage;
                                        break;
                                    }
                                    if (!progress.UpdateProgress(STR_IMPORTINGGEOCACHES, STR_IMPORTINGGEOCACHES, totalcount, index))
                                    {
                                        break;
                                    }
                                }
                            }
                        }
                        foreach (var n in missingGeocaches)
                        {
                            Framework.Data.Geocache gc = Utils.DataAccess.GetGeocache(Core.Geocaches, n.CacheCode);
                            if (gc != null)
                            {
                                string s = n.Note ?? "";
                                s = s.Replace("\r", "");
                                s = s.Replace("\n", "\r\n");
                                gc.PersonaleNote = s;
                            }
                        }
                    }
                }
            }
            catch (Exception e)
            {
                errMessage = e.Message;
            }
            if (!string.IsNullOrEmpty(errMessage))
            {
                System.Windows.Forms.MessageBox.Show(errMessage, Utils.LanguageSupport.Instance.GetTranslation(Utils.LanguageSupport.Instance.GetTranslation(STR_ERROR)), System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error);
            }
        }
Esempio n. 20
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;
                }
            }
        }
Esempio n. 21
0
        private void getGeocachesThreadMethod()
        {
            try
            {
                using (Utils.ProgressBlock progress = new Utils.ProgressBlock(_plugin, STR_IMPORTING, STR_IMPORTING, _geocacheCodes.Count, 0, true))
                {
                    int totalcount = _geocacheCodes.Count;
                    int index = 0;
                    int gcupdatecount;
                    TimeSpan interval = new TimeSpan(0, 0, 0, 2, 100);
                    DateTime prevCall = DateTime.MinValue;
                    bool dodelay;
                    gcupdatecount = 50;
                    dodelay = (_geocacheCodes.Count > 30);
                    while (_geocacheCodes.Count > 0)
                    {
                        if (dodelay)
                        {
                            TimeSpan ts = DateTime.Now - prevCall;
                            if (ts < interval)
                            {
                                Thread.Sleep(interval - ts);
                            }
                        }
                        Utils.API.LiveV6.SearchForGeocachesRequest req = new Utils.API.LiveV6.SearchForGeocachesRequest();
                        req.IsLite = _core.GeocachingComAccount.MemberTypeId == 1;
                        req.AccessToken = _client.Token;
                        req.CacheCode = new Utils.API.LiveV6.CacheCodeFilter();
                        req.CacheCode.CacheCodes = (from a in _geocacheCodes select a).Take(gcupdatecount).ToArray();
                        req.MaxPerPage = gcupdatecount;
                        req.GeocacheLogCount = 5;
                        index += req.CacheCode.CacheCodes.Length;
                        _geocacheCodes.RemoveRange(0, req.CacheCode.CacheCodes.Length);
                        prevCall = DateTime.Now;
                        var resp = _client.Client.SearchForGeocaches(req);
                        if (resp.Status.StatusCode == 0 && resp.Geocaches != null)
                        {
                            Utils.API.Import.AddGeocaches(_core, resp.Geocaches);
                        }
                        else
                        {
                            _errormessage = resp.Status.StatusMessage;
                            break;
                        }

                        if (!progress.UpdateProgress(STR_IMPORTING, STR_IMPORTING, totalcount, index))
                        {
                            break;
                        }
                    }
                }
            }
            catch
            {
            }
            _actionReady.Set();
        }
Esempio n. 22
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;
                }
            }
        }
Esempio n. 23
0
 private void updateThreadMethod()
 {
     try
     {
         using (Utils.ProgressBlock progress = new Utils.ProgressBlock(ActionBuilderForm.ActionBuilderFormInstance.OwnerPlugin as Utils.BasePlugin.Plugin, STR_UPDATINGGEOCACHES, STR_UPDATINGGEOCACHE, _gcList.Count, 0, true))
         {
             int totalcount = _gcList.Count;
             using (Utils.API.GeocachingLiveV6 client = new Utils.API.GeocachingLiveV6(Core, string.IsNullOrEmpty(Core.GeocachingComAccount.APIToken)))
             {
                 int index = 0;
                 int gcupdatecount;
                 TimeSpan interval = new TimeSpan(0, 0, 0, 2, 100);
                 DateTime prevCall = DateTime.MinValue;
                 bool dodelay;
                 gcupdatecount = 50;
                 dodelay = (_gcList.Count > 30);
                 while (_gcList.Count > 0)
                 {
                     if (dodelay)
                     {
                         TimeSpan ts = DateTime.Now - prevCall;
                         if (ts < interval)
                         {
                             Thread.Sleep(interval - ts);
                         }
                     }
                     Utils.API.LiveV6.SearchForGeocachesRequest req = new Utils.API.LiveV6.SearchForGeocachesRequest();
                     req.IsLite = Core.GeocachingComAccount.MemberTypeId == 1;
                     req.AccessToken = client.Token;
                     req.CacheCode = new Utils.API.LiveV6.CacheCodeFilter();
                     req.CacheCode.CacheCodes = (from a in _gcList select a.Code).Take(gcupdatecount).ToArray();
                     req.MaxPerPage = gcupdatecount;
                     req.GeocacheLogCount = 5;
                     index += req.CacheCode.CacheCodes.Length;
                     _gcList.RemoveRange(0, req.CacheCode.CacheCodes.Length);
                     prevCall = DateTime.Now;
                     var resp = client.Client.SearchForGeocaches(req);
                     if (resp.Status.StatusCode == 0 && resp.Geocaches != null)
                     {
                         Utils.API.Import.AddGeocaches(Core, resp.Geocaches);
                     }
                     else if (resp.Status.StatusCode != 0)
                     {
                         _errormessage = resp.Status.StatusMessage;
                         break;
                     }
                     if (!progress.UpdateProgress(STR_UPDATINGGEOCACHES, STR_UPDATINGGEOCACHE, totalcount, index))
                     {
                         break;
                     }
                 }
             }
         }
     }
     catch (Exception e)
     {
         _errormessage = e.Message;
     }
     _actionDone.Set();
 }
Esempio n. 24
0
 private void getGeocacheInbackgroundMethod()
 {
     Utils.API.LiveV6.Geocache[] gcList = null;
     try
     {
         using (Utils.API.GeocachingLiveV6 client = new Utils.API.GeocachingLiveV6(Core, string.IsNullOrEmpty(Core.GeocachingComAccount.APIToken)))
         {
             var req = new Utils.API.LiveV6.SearchForGeocachesRequest();
             req.AccessToken = client.Token;
             req.CacheCode = new Utils.API.LiveV6.CacheCodeFilter();
             req.CacheCode.CacheCodes = new string[] { _codeToGetWithLiveAPI };
             req.GeocacheLogCount = 5;
             req.IsLite = Core.GeocachingComAccount.MemberTypeId == 1;
             req.MaxPerPage = 1;
             var resp = client.Client.SearchForGeocaches(req);
             if (resp.Status.StatusCode == 0 && resp.Geocaches != null)
             {
                 gcList = resp.Geocaches;
             }
         }
     }
     catch
     {
     }
     _context.Post(new SendOrPostCallback(delegate(object state)
     {
         Framework.Data.Geocache activeGC = null;
         if (gcList != null)
         {
             using (Utils.FrameworkDataUpdater dupd = new Utils.FrameworkDataUpdater(Core))
             {
                 List<Framework.Data.Geocache> lst = Utils.API.Import.AddGeocaches(Core, gcList);
                 if (lst != null && lst.Count > 0)
                 {
                     activeGC = lst[lst.Count - 1];
                 }
             }
         }
         toolStripStatusLabelGettingGeocache.Visible = false;
         Core.ActiveGeocache = activeGC;
         if (activeGC != null)
         {
             if (linkLabelUnavailableCache.Visible)
             {
                 if (linkLabelUnavailableCache.Text.IndexOf(activeGC.Code) >= 0)
                 {
                     linkLabelUnavailableCache.Visible = false;
                 }
             }
         }
     }), null);
 }
Esempio n. 25
0
 private void buttonCheck_Click(object sender, EventArgs e)
 {
     this.linkLabel1.Text = "";
     this.Cursor = Cursors.WaitCursor;
     try
     {
         using (Utils.API.GeocachingLiveV6 api = new Utils.API.GeocachingLiveV6(_core))
         {
             var req = new Utils.API.LiveV6.SearchForGeocachesRequest();
             req.AccessToken = api.Token;
             req.CacheCode = new Utils.API.LiveV6.CacheCodeFilter();
             req.CacheCode.CacheCodes = new string[] { textBox3.Text.ToUpper().Trim() };
             req.IsLite = true;
             req.MaxPerPage = 1;
             req.GeocacheLogCount = 0;
             var resp = api.Client.SearchForGeocaches(req);
             if (resp.Status.StatusCode == 0)
             {
                 if (resp.Geocaches != null && resp.Geocaches.Count() > 0)
                 {
                     linkLabel1.Text = string.Format("{0}, {1}", resp.Geocaches[0].Code, resp.Geocaches[0].Name);
                     linkLabel1.Links.Add(0, resp.Geocaches[0].Code.Length, resp.Geocaches[0].Url);
                 }
             }
             else
             {
                 System.Windows.Forms.MessageBox.Show(resp.Status.StatusMessage, Utils.LanguageSupport.Instance.GetTranslation(Utils.LanguageSupport.Instance.GetTranslation(STR_ERROR)), System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error);
             }
         }                
     }
     catch
     {
     }
     this.Cursor = Cursors.Default;
 }
Esempio n. 26
0
        protected override void ImportMethod()
        {
            List<Utils.API.LiveV6.CacheNote> missingGeocaches = new List<Utils.API.LiveV6.CacheNote>();
            string errMessage = "";
            try
            {
                using (Utils.ProgressBlock progress = new Utils.ProgressBlock(this, STR_IMPORTING, STR_IMPORTING, 1, 0))
                {
                    //clear all notes
                    foreach (Framework.Data.Geocache gc in Core.Geocaches)
                    {
                        gc.PersonaleNote = "";
                    }

                    using (Utils.API.GeocachingLiveV6 client = new Utils.API.GeocachingLiveV6(Core, string.IsNullOrEmpty(Core.GeocachingComAccount.APIToken)))
                    {
                        int maxPerRequest = 100;
                        int startIndex = 0;
                        var resp = client.Client.GetUsersCacheNotes(client.Token, startIndex, maxPerRequest);
                        while (resp.Status.StatusCode == 0)
                        {
                            foreach (var n in resp.CacheNotes)
                            {
                                Framework.Data.Geocache gc = Utils.DataAccess.GetGeocache(Core.Geocaches, n.CacheCode);
                                if (gc != null)
                                {
                                    string s = n.Note ?? "";
                                    s = s.Replace("\r", "");
                                    s = s.Replace("\n", "\r\n");
                                    gc.PersonaleNote = s;
                                }
                                else
                                {
                                    missingGeocaches.Add(n);
                                }
                            }
                            if (resp.CacheNotes.Count() >= maxPerRequest)
                            {
                                startIndex += resp.CacheNotes.Count();
                                resp = client.Client.GetUsersCacheNotes(client.Token, startIndex, maxPerRequest);
                            }
                            else
                            {
                                break;
                            }
                        }
                        if (resp.Status.StatusCode != 0)
                        {
                            if (!string.IsNullOrEmpty(resp.Status.StatusMessage))
                            {
                                errMessage = resp.Status.StatusMessage;
                            }
                        }
                    }
                }
                if (string.IsNullOrEmpty(errMessage) && missingGeocaches.Count > 0)
                {
                    List<string> gcList = (from a in missingGeocaches select a.CacheCode).ToList();
                    if (System.Windows.Forms.MessageBox.Show(string.Format("{0} {1}", missingGeocaches.Count, Utils.LanguageSupport.Instance.GetTranslation(Utils.LanguageSupport.Instance.GetTranslation(STR_IMPORTGEOCACHES))), Utils.LanguageSupport.Instance.GetTranslation(Utils.LanguageSupport.Instance.GetTranslation(STR_QUESTIONGEOCACHES)), System.Windows.Forms.MessageBoxButtons.YesNo, System.Windows.Forms.MessageBoxIcon.Question) == System.Windows.Forms.DialogResult.Yes)
                    {
                        using (Utils.ProgressBlock progress = new Utils.ProgressBlock(this, STR_IMPORTINGGEOCACHES, STR_IMPORTINGGEOCACHES, gcList.Count, 0, true))
                        {
                            int totalcount = gcList.Count;
                            using (Utils.API.GeocachingLiveV6 client = new Utils.API.GeocachingLiveV6(Core, string.IsNullOrEmpty(Core.GeocachingComAccount.APIToken)))
                            {
                                int index = 0;
                                int gcupdatecount;
                                TimeSpan interval = new TimeSpan(0, 0, 0, 2, 100);
                                DateTime prevCall = DateTime.MinValue;
                                bool dodelay;
                                gcupdatecount = 50;
                                dodelay = (gcList.Count > 30);
                                while (gcList.Count > 0)
                                {
                                    if (dodelay)
                                    {
                                        TimeSpan ts = DateTime.Now - prevCall;
                                        if (ts < interval)
                                        {
                                            Thread.Sleep(interval - ts);
                                        }
                                    }
                                    Utils.API.LiveV6.SearchForGeocachesRequest req = new Utils.API.LiveV6.SearchForGeocachesRequest();
                                    req.IsLite = Core.GeocachingComAccount.MemberTypeId == 1;
                                    req.AccessToken = client.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 = 5;
                                    index += req.CacheCode.CacheCodes.Length;
                                    gcList.RemoveRange(0, req.CacheCode.CacheCodes.Length);
                                    prevCall = DateTime.Now;
                                    var resp = client.Client.SearchForGeocaches(req);
                                    if (resp.Status.StatusCode == 0 && resp.Geocaches != null)
                                    {
                                        Utils.API.Import.AddGeocaches(Core, resp.Geocaches);
                                    }
                                    else
                                    {
                                        errMessage = resp.Status.StatusMessage;
                                        break;
                                    }                                    
                                    if (!progress.UpdateProgress(STR_IMPORTINGGEOCACHES, STR_IMPORTINGGEOCACHES, totalcount, index))
                                    {
                                        break;
                                    }
                                }
                            }
                        }
                        foreach (var n in missingGeocaches)
                        {
                            Framework.Data.Geocache gc = Utils.DataAccess.GetGeocache(Core.Geocaches, n.CacheCode);
                            if (gc != null)
                            {
                                string s = n.Note ?? "";
                                s = s.Replace("\r", "");
                                s = s.Replace("\n", "\r\n");
                                gc.PersonaleNote = s;
                            }
                        }
                    }
                }
            }
            catch (Exception e)
            {
                errMessage = e.Message;
            }
            if (!string.IsNullOrEmpty(errMessage))
            {
                System.Windows.Forms.MessageBox.Show(errMessage, Utils.LanguageSupport.Instance.GetTranslation(Utils.LanguageSupport.Instance.GetTranslation(STR_ERROR)), System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error);
            }
        }
Esempio n. 27
0
        private void importGeocachesThreadMethod()
        {
            int max = _gcList.Count;
            int gcupdatecount = 20;
            int index = 0;
            using (Utils.ProgressBlock progress = new Utils.ProgressBlock(OwnerPlugin, STR_IMPORTING, STR_IMPORTING, max, 0, true))
            {
                try
                {
                    using (Utils.API.GeocachingLiveV6 client = new Utils.API.GeocachingLiveV6(Core, string.IsNullOrEmpty(Core.GeocachingComAccount.APIToken)))
                    {
                        while (_gcList.Count > 0)
                        {
                            Utils.API.LiveV6.SearchForGeocachesRequest req = new Utils.API.LiveV6.SearchForGeocachesRequest();
                            req.IsLite = Core.GeocachingComAccount.MemberTypeId == 1;
                            req.AccessToken = client.Token;
                            req.CacheCode = new Utils.API.LiveV6.CacheCodeFilter();
                            req.CacheCode.CacheCodes = _gcList.Take(gcupdatecount).ToArray();
                            req.MaxPerPage = gcupdatecount;
                            req.GeocacheLogCount = 5;
                            index += req.CacheCode.CacheCodes.Length;
                            _gcList.RemoveRange(0, req.CacheCode.CacheCodes.Length);
                            var resp = client.Client.SearchForGeocaches(req);
                            if (resp.Status.StatusCode == 0 && resp.Geocaches != null)
                            {
                                Utils.API.Import.AddGeocaches(Core, resp.Geocaches);
                            }
                            else
                            {
                                _errormessage = resp.Status.StatusMessage;
                                break;
                            }
                            if (!progress.UpdateProgress(STR_IMPORTING, STR_IMPORTING, max, index))
                            {
                                break;
                            }

                            if (_gcList.Count > 0)
                            {
                                Thread.Sleep(3000);
                            }
                        }
                    }
                }
                catch
                {
                }
            }
            _actionReady.Set();
        }