Example #1
0
 public override bool Action(string action)
 {
     bool result = base.Action(action);
     if (result && action == ACTION_SHOW)
     {
         if (Utils.API.GeocachingLiveV6.CheckAPIAccessAvailable(Core, true))
         {
             using (var client = new Utils.API.GeocachingLiveV6(Core, true))
             {
                 var res = client.Client.GetCacheIdsFavoritedByUser(client.Token);
                 if (res.Status.StatusCode == 0)
                 {
                     //res.CacheCodes
                 }
                 var resp2 = client.Client.GetCachesFavoritedByUser(client.Token);
                 if (resp2.Status.StatusCode == 0)
                 {
                     //resp2.
                 }
                 //client.Client.AddFavoritePointToCache(client.Token, "");
                 //client.Client.RemoveFavoritePointFromCache
             }
         }
     }
     return result;
 }
Example #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;
 }
Example #3
0
        public override bool Action(string action)
        {
            bool result = base.Action(action);
            if (result && action == ACTION_SHOW)
            {
                if (Utils.API.GeocachingLiveV6.CheckAPIAccessAvailable(Core, true))
                {
                    using (var client = new Utils.API.GeocachingLiveV6(Core, false))
                    {
                        var res = client.Client.GetPocketQueryList(client.Token);
                        if (res.Status.StatusCode == 0)
                        {
                            //res.CacheCodes
                            Guid g = res.PocketQueryList[0].GUID;
                            //g = Guid.Parse("c42cf092-28e8-4781-b62e-0de0e3e1a11d");

                            var resp2 = client.Client.GetPocketQueryData(client.Token, g, 0, 10, true);
                            if (resp2.Status.StatusCode == 0)
                            {
                                //resp2.
                            }
                        }
                    }
                }
            }
            return result;
        }
Example #4
0
        public override bool Action(string action)
        {
            bool result = base.Action(action);

            if (result && action == ACTION_IMPORT)
            {
                try
                {
                    using (var client = new Utils.API.GeocachingLiveV6(Core))
                        using (var wc = new System.Net.WebClient())
                        {
                            var resp = client.Client.GetGeocacheDataTypes(client.Token, true, true, true);
                            if (resp.Status.StatusCode == 0)
                            {
                                string defaultPath = Path.Combine(new string[] { _basePath, "Default", "attributes" });
                                if (!Directory.Exists(defaultPath))
                                {
                                    Directory.CreateDirectory(defaultPath);
                                }
                                foreach (var attr in resp.AttributeTypes)
                                {
                                    wc.DownloadFile(attr.YesIconName, Path.Combine(defaultPath, string.Format("{0}.gif", attr.ID)));
                                    wc.DownloadFile(attr.NoIconName, Path.Combine(defaultPath, string.Format("_{0}.gif", attr.ID)));
                                }

                                defaultPath = Path.Combine(new string[] { _basePath, "Default", "cachetypes" });
                                if (!Directory.Exists(defaultPath))
                                {
                                    Directory.CreateDirectory(defaultPath);
                                }

                                string smallPath = Path.Combine(new string[] { _basePath, "Small", "cachetypes" });
                                if (!Directory.Exists(smallPath))
                                {
                                    Directory.CreateDirectory(smallPath);
                                }
                                foreach (var gt in resp.GeocacheTypes)
                                {
                                    string fn = string.Format("{0}.gif", gt.GeocacheTypeId);
                                    wc.DownloadFile(gt.ImageURL, Path.Combine(defaultPath, fn));
                                }

                                defaultPath = Path.Combine(new string[] { _basePath, "Default", "logtypes" });
                                if (!Directory.Exists(defaultPath))
                                {
                                    Directory.CreateDirectory(defaultPath);
                                }
                                foreach (var gt in resp.WptLogTypes)
                                {
                                    wc.DownloadFile(gt.ImageURL, Path.Combine(defaultPath, string.Format("{0}.gif", gt.WptLogTypeId)));
                                }
                            }
                        }
                }
                catch
                {
                }
            }
            return(result);
        }
Example #5
0
        public OfflineLogForm(Utils.BasePlugin.Plugin plugin, Framework.Interfaces.ICore core, Utils.API.GeocachingLiveV6 client) :
            this()
        {
            _core   = core;
            _client = client;
            _plugin = plugin;

            this.Text           = Utils.LanguageSupport.Instance.GetTranslation(STR_TITLE);
            this.groupBox1.Text = Utils.LanguageSupport.Instance.GetTranslation(STR_ADDGEOCACHES);
            this.label5.Text    = Utils.LanguageSupport.Instance.GetTranslation(STR_CODE);
            this.button6.Text   = Utils.LanguageSupport.Instance.GetTranslation(STR_ADD);
            this.button7.Text   = Utils.LanguageSupport.Instance.GetTranslation(STR_ADDALLSELECTED);
            this.groupBox2.Text = Utils.LanguageSupport.Instance.GetTranslation(STR_OFFLINELOGS);
            this.label1.Text    = Utils.LanguageSupport.Instance.GetTranslation(STR_GEOCACHES);
            this.label2.Text    = Utils.LanguageSupport.Instance.GetTranslation(STR_LOGTYPE);
            this.label3.Text    = Utils.LanguageSupport.Instance.GetTranslation(STR_LOGDATE);
            this.label4.Text    = Utils.LanguageSupport.Instance.GetTranslation(STR_LOGTEXT);
            this.button1.Text   = Utils.LanguageSupport.Instance.GetTranslation(STR_LOGSELECTED);
            this.button2.Text   = Utils.LanguageSupport.Instance.GetTranslation(STR_LOGALL);
            this.button8.Text   = Utils.LanguageSupport.Instance.GetTranslation(STR_OK);
            this.groupBox3.Text = Utils.LanguageSupport.Instance.GetTranslation(STR_LOGONLINE);

            int[] ids = new int[] { 2, 3, 4, 7, 45 };
            comboBoxLogType1.SetLogTypes(core, (from Framework.Data.LogType l in core.LogTypes join a in ids on l.ID equals a select l).ToList());

            if (core.ActiveGeocache != null)
            {
                textBox2.Text = core.ActiveGeocache.Code;
            }
            button7.Enabled = Utils.DataAccess.GetSelectedGeocaches(core.Geocaches).Count > 0;

            loadOfflineLogs();
        }
Example #6
0
        public override bool Action(string action)
        {
            bool result = base.Action(action);

            if (result && action == ACTION_SHOW)
            {
                if (Utils.API.GeocachingLiveV6.CheckAPIAccessAvailable(Core, true))
                {
                    using (var client = new Utils.API.GeocachingLiveV6(Core, false))
                    {
                        var res = client.Client.GetPocketQueryList(client.Token);
                        if (res.Status.StatusCode == 0)
                        {
                            //res.CacheCodes
                            Guid g = res.PocketQueryList[0].GUID;
                            //g = Guid.Parse("c42cf092-28e8-4781-b62e-0de0e3e1a11d");

                            var resp2 = client.Client.GetPocketQueryData(client.Token, g, 0, 10, true);
                            if (resp2.Status.StatusCode == 0)
                            {
                                //resp2.
                            }
                        }
                    }
                }
            }
            return(result);
        }
Example #7
0
        public OfflineLogForm(Utils.BasePlugin.Plugin plugin, Framework.Interfaces.ICore core, Utils.API.GeocachingLiveV6 client) :
            this()
        {
            _core = core;
            _client = client;
            _plugin = plugin;

            this.Text = Utils.LanguageSupport.Instance.GetTranslation(STR_TITLE);
            this.groupBox1.Text = Utils.LanguageSupport.Instance.GetTranslation(STR_ADDGEOCACHES);
            this.label5.Text = Utils.LanguageSupport.Instance.GetTranslation(STR_CODE);
            this.button6.Text = Utils.LanguageSupport.Instance.GetTranslation(STR_ADD);
            this.button7.Text = Utils.LanguageSupport.Instance.GetTranslation(STR_ADDALLSELECTED);
            this.groupBox2.Text = Utils.LanguageSupport.Instance.GetTranslation(STR_OFFLINELOGS);
            this.label1.Text = Utils.LanguageSupport.Instance.GetTranslation(STR_GEOCACHES);
            this.label2.Text = Utils.LanguageSupport.Instance.GetTranslation(STR_LOGTYPE);
            this.label3.Text = Utils.LanguageSupport.Instance.GetTranslation(STR_LOGDATE);
            this.label4.Text = Utils.LanguageSupport.Instance.GetTranslation(STR_LOGTEXT);
            this.button1.Text = Utils.LanguageSupport.Instance.GetTranslation(STR_LOGSELECTED);
            this.button2.Text = Utils.LanguageSupport.Instance.GetTranslation(STR_LOGALL);
            this.button8.Text = Utils.LanguageSupport.Instance.GetTranslation(STR_OK);
            this.groupBox3.Text = Utils.LanguageSupport.Instance.GetTranslation(STR_LOGONLINE);

            int[] ids = new int[] { 2, 3, 4, 7, 45 };
            comboBoxLogType1.SetLogTypes(core, (from Framework.Data.LogType l in core.LogTypes join a in ids on l.ID equals a select l).ToList());

            if (core.ActiveGeocache != null)
            {
                textBox2.Text = core.ActiveGeocache.Code;
            }
            button7.Enabled = Utils.DataAccess.GetSelectedGeocaches(core.Geocaches).Count > 0;

            loadOfflineLogs();
        }
Example #8
0
        private bool getBookmarkList(Guid guid)
        {
            bool result = false;

            Cursor = Cursors.WaitCursor;
            try
            {
                using (Utils.API.GeocachingLiveV6 api = new Utils.API.GeocachingLiveV6(_core))
                {
                    var req = new Utils.API.LiveV6.GetBookmarkListByGuidRequest();
                    req.AccessToken      = api.Token;
                    req.BookmarkListGuid = guid;
                    var resp = api.Client.GetBookmarkListByGuid(req);
                    if (resp.Status.StatusCode == 0)
                    {
                        _gcCodes = (from c in resp.BookmarkList select c.CacheCode).ToList();
                        result   = true;
                    }
                    else
                    {
                        MessageBox.Show(resp.Status.StatusMessage, Utils.LanguageSupport.Instance.GetTranslation(STR_ERROR));
                    }
                }
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message, Utils.LanguageSupport.Instance.GetTranslation(STR_ERROR));
            }
            Cursor = Cursors.Default;

            return(result);
        }
Example #9
0
        public override bool Action(string action)
        {
            bool result = base.Action(action);

            if (result && action == ACTION_SHOW)
            {
                if (Utils.API.GeocachingLiveV6.CheckAPIAccessAvailable(Core, true))
                {
                    using (var client = new Utils.API.GeocachingLiveV6(Core, true))
                    {
                        var res = client.Client.GetCacheIdsFavoritedByUser(client.Token);
                        if (res.Status.StatusCode == 0)
                        {
                            //res.CacheCodes
                        }
                        var resp2 = client.Client.GetCachesFavoritedByUser(client.Token);
                        if (resp2.Status.StatusCode == 0)
                        {
                            //resp2.
                        }
                        //client.Client.AddFavoritePointToCache(client.Token, "");
                        //client.Client.RemoveFavoritePointFromCache
                    }
                }
            }
            return(result);
        }
Example #10
0
        public override bool Action(string action)
        {
            bool result = base.Action(action);

            if (result && action == ACTION_SHOW)
            {
                if (Utils.API.GeocachingLiveV6.CheckAPIAccessAvailable(Core, true))
                {
                    using (var client = new Utils.API.GeocachingLiveV6(Core))
                    {
                        StringBuilder sb  = new StringBuilder();
                        var           res = client.Client.GetAttributeTypesData(client.Token);
                        if (res.Status.StatusCode == 0)
                        {
                            foreach (var at in res.AttributeTypes)
                            {
                                sb.AppendLine(string.Format("htAttributes[{0}] = \"{1}\";", at.ID, at.IconName));
                            }
                        }
                        string fill = sb.ToString();
                    }
                }
            }
            return(result);
        }
Example #11
0
 private void logThreadMethod()
 {
     try
     {
         using (Utils.API.GeocachingLiveV6 api = new Utils.API.GeocachingLiveV6(_core))
         {
             var req = new Utils.API.LiveV6.CreateTrackableLogRequest();
             req.AccessToken   = api.Token;
             req.Note          = _logText;
             req.LogType       = _logType.ID;
             req.UTCDateLogged = _visitDate.AddHours(12).ToUniversalTime();
             bool getOwnedDone = false;
             foreach (string tb in _tbs)
             {
                 if (tb.StartsWith("TB"))
                 {
                     if (_tbTrackingNumbers[tb] as string == null)
                     {
                         if (!getOwnedDone)
                         {
                             getOwnedTrackables();
                         }
                     }
                     req.TrackingNumber = _tbTrackingNumbers[tb] as string;
                 }
                 else
                 {
                     req.TrackingNumber = tb;
                 }
                 req.CacheCode = _gcCode;
                 var resp = api.Client.CreateTrackableLog(req);
                 if (resp.Status.StatusCode == 0)
                 {
                     _context.Send(new SendOrPostCallback(delegate(object state)
                     {
                         checkedListBox1.SetItemChecked(checkedListBox1.Items.IndexOf(tb), false);
                         toolStripProgressBar1.Value++;
                     }), null);
                 }
                 else
                 {
                     _errormessage = resp.Status.StatusMessage;
                 }
                 if (_stopAfterEachLog || _cancelled)
                 {
                     break;
                 }
                 else
                 {
                     Thread.Sleep(2000);
                 }
             }
         }
     }
     catch (Exception e)
     {
         _errormessage = e.Message;
     }
 }
Example #12
0
        public override bool Action(string action)
        {
            bool result = base.Action(action);
            if (result && action == ACTION_IMPORT)
            {
                try
                {
                    using (var client = new Utils.API.GeocachingLiveV6(Core))
                    using (var wc = new System.Net.WebClient())
                    {
                        var resp = client.Client.GetGeocacheDataTypes(client.Token, true, true, true);
                        if (resp.Status.StatusCode == 0)
                        {
                            string defaultPath = Path.Combine(new string[] { _basePath, "Default", "attributes" });
                            if (!Directory.Exists(defaultPath))
                            {
                                Directory.CreateDirectory(defaultPath);
                            }
                            foreach (var attr in resp.AttributeTypes)
                            {
                                //wc.DownloadFile(attr.YesIconName, Path.Combine(defaultPath, string.Format("{0}.gif", attr.ID)));
                                //wc.DownloadFile(attr.NoIconName, Path.Combine(defaultPath, string.Format("_{0}.gif", attr.ID)));
                            }

                            defaultPath = Path.Combine(new string[] { _basePath, "Default", "cachetypes" });
                            if (!Directory.Exists(defaultPath))
                            {
                                Directory.CreateDirectory(defaultPath);
                            }

                            string smallPath = Path.Combine(new string[] { _basePath, "Small", "cachetypes" });
                            if (!Directory.Exists(smallPath))
                            {
                                Directory.CreateDirectory(smallPath);
                            }
                            foreach (var gt in resp.GeocacheTypes)
                            {
                                string fn = string.Format("{0}.gif", gt.GeocacheTypeId);
                                //wc.DownloadFile(gt.ImageURL, Path.Combine(defaultPath, fn));
                            }

                            defaultPath = Path.Combine(new string[] { _basePath, "Default", "logtypes" });
                            if (!Directory.Exists(defaultPath))
                            {
                                Directory.CreateDirectory(defaultPath);
                            }
                            foreach (var gt in resp.WptLogTypes)
                            {
                                wc.DownloadFile(gt.ImageURL, Path.Combine(defaultPath, string.Format("{0}.gif", gt.WptLogTypeId)));
                            }
                        }
                    }
                }
                catch
                {
                }
            }
            return result;
        }
Example #13
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;
                }
            }
        }
        private void button4_Click(object sender, EventArgs e)
        {
            WaypointListItem wpi = listBox1.SelectedItem as WaypointListItem;

            Framework.Data.Location ll = Utils.Conversion.StringToLocation(textBox8.Text);
            if (Core.ActiveGeocache != null && wpi != null && wpi.WP.ID <= 0)
            {
                if (Utils.API.GeocachingLiveV6.CheckAPIAccessAvailable(Core, true))
                {
                    try
                    {
                        Utils.API.LiveV6.SaveUserWaypointResponse resp = null;
                        Cursor = Cursors.WaitCursor;
                        try
                        {
                            using (Utils.API.GeocachingLiveV6 api = new Utils.API.GeocachingLiveV6(Core))
                            {
                                var req = new Utils.API.LiveV6.SaveUserWaypointRequest();
                                req.AccessToken = api.Token;
                                req.CacheCode   = Core.ActiveGeocache.Code;
                                req.Description = textBox2.Text;
                                req.Latitude    = ll.Lat;
                                req.Longitude   = ll.Lon;
                                resp            = api.Client.SaveUserWaypoint(req);
                            }
                        }
                        finally
                        {
                            Cursor = Cursors.Default;
                        }
                        if (resp != null)
                        {
                            if (resp.Status.StatusCode == 0)
                            {
                                Framework.Data.UserWaypoint wp = Utils.API.Convert.UserWaypoint(Core, resp.NewWaypoint);
                                wp.Saved = false;
                                wpi.WP   = wp;
                                Core.UserWaypoints.Add(wp);
                            }
                            else
                            {
                                MessageBox.Show(resp.Status.StatusMessage ?? "", Utils.LanguageSupport.Instance.GetTranslation(STR_ERROR));
                            }
                        }
                        else
                        {
                            MessageBox.Show(Utils.LanguageSupport.Instance.GetTranslation(STR_FAILED), Utils.LanguageSupport.Instance.GetTranslation(STR_ERROR));
                        }
                    }
                    catch
                    {
                        MessageBox.Show(Utils.LanguageSupport.Instance.GetTranslation(STR_FAILED), Utils.LanguageSupport.Instance.GetTranslation(STR_ERROR));
                    }
                }
            }
        }
Example #15
0
 public GeocacheLogForm(Framework.Interfaces.ICore core, Utils.API.GeocachingLiveV6 client, Framework.Data.Geocache gc, CGeoGeocacheVisitsLogForm.GeocacheVisitsItem data)
     : this(core, client, gc)
 {
     if (data.LogType.ID > 0)
     {
         comboBoxLogType1.SelectedItem = data.LogType;
         dateTimePicker1.Value         = data.LogDate;
         textBox1.Text = data.Comment;
     }
 }
Example #16
0
 private void getOwnedTrackables()
 {
     try
     {
         using (Utils.API.GeocachingLiveV6 api = new Utils.API.GeocachingLiveV6(_core, _useTestSite))
         {
             var req = new Utils.API.LiveV6.GetTrackablesByUserRequest();
             req.AccessToken        = api.Token;
             req.MaxPerPage         = 10;
             req.StartIndex         = 0;
             req.TrackableLogsCount = 0;
             var resp = api.Client.GetUsersTrackables(req);
             while (resp.Status.StatusCode == 0 && resp.Trackables != null)
             {
                 _context.Send(new SendOrPostCallback(delegate(object state)
                 {
                     foreach (Utils.API.LiveV6.Trackable tb in resp.Trackables)
                     {
                         if (!tb.Archived && tb.CurrentOwner.UserName == _core.GeocachingComAccount.AccountName)
                         {
                             if (!imageList1.Images.ContainsKey(tb.IconUrl))
                             {
                                 Image img = LoadImage(tb.IconUrl);
                                 if (img != null)
                                 {
                                     imageList1.Images.Add(tb.IconUrl, img);
                                 }
                             }
                             ListViewItem lv = new ListViewItem(new string[] { "", tb.Code, tb.Name ?? "" }, tb.IconUrl);
                             lv.Tag          = tb;
                             listView1.Items.Add(lv);
                         }
                     }
                 }), null);
                 if (resp.Trackables.Count() < req.MaxPerPage)
                 {
                     break;
                 }
                 else
                 {
                     req.StartIndex += req.MaxPerPage;
                     Thread.Sleep(2000);
                     resp = api.Client.GetUsersTrackables(req);
                 }
             }
             if (resp.Status.StatusCode != 0)
             {
                 _errormessage = resp.Status.StatusMessage;
             }
         }
     }
     catch
     {
     }
 }
Example #17
0
 public GeocacheLogForm(Framework.Interfaces.ICore core, Utils.API.GeocachingLiveV6 client, Framework.Data.Geocache gc, OfflineLogForm.OfflineLogInfo data)
     : this(core, client, gc)
 {
     if (data.LogType.ID > 0)
     {
         comboBoxLogType1.SelectedItem = data.LogType;
         dateTimePicker1.Value         = data.LogDate;
         textBox1.Text      = data.LogText;
         textBoxGC.ReadOnly = true;
     }
 }
        private void button3_Click(object sender, EventArgs e)
        {
            WaypointListItem wpi = listBox1.SelectedItem as WaypointListItem;

            if (wpi != null)
            {
                if (wpi.WP.ID <= 0)
                {
                    listBox1.Items.Remove(wpi);
                    button1.Enabled = true;
                }
                else
                {
                    if (Utils.API.GeocachingLiveV6.CheckAPIAccessAvailable(Core, true))
                    {
                        try
                        {
                            Utils.API.LiveV6.StatusResponse resp = null;
                            Cursor = Cursors.WaitCursor;
                            try
                            {
                                using (Utils.API.GeocachingLiveV6 api = new Utils.API.GeocachingLiveV6(Core))
                                {
                                    resp = api.Client.DeleteUserWaypoint(api.Token, wpi.WP.ID);
                                }
                            }
                            finally
                            {
                                Cursor = Cursors.Default;
                            }
                            if (resp != null)
                            {
                                if (resp.StatusCode == 0)
                                {
                                    Core.UserWaypoints.Remove(wpi.WP);
                                }
                                else
                                {
                                    MessageBox.Show(resp.StatusMessage ?? "", Utils.LanguageSupport.Instance.GetTranslation(STR_ERROR));
                                }
                            }
                            else
                            {
                                MessageBox.Show(Utils.LanguageSupport.Instance.GetTranslation(STR_FAILED), Utils.LanguageSupport.Instance.GetTranslation(STR_ERROR));
                            }
                        }
                        catch
                        {
                            MessageBox.Show(Utils.LanguageSupport.Instance.GetTranslation(STR_FAILED), Utils.LanguageSupport.Instance.GetTranslation(STR_ERROR));
                        }
                    }
                }
            }
        }
Example #19
0
        public override bool Action(string action)
        {
            bool result = base.Action(action);

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

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

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

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

                                if (resp.Logs.Count() >= req.MaxPerPage)
                                {
                                    req.StartIndex = logs.Count;
                                    if (!progress.UpdateProgress("Importing logs", "Importing logs...", logs.Count + req.MaxPerPage, logs.Count))
                                    {
                                        break;
                                    }
                                    resp = api.Client.GetUsersGeocacheLogs(req);
                                }
                                else
                                {
                                    break;
                                }
                            }
                            if (resp.Status.StatusCode != 0)
                            {
                                //_errormessage = resp.Status.StatusMessage;
                            }
                        }
                    }
                }
                catch
                {
                }
            }
            return result;
        }
Example #21
0
        public override bool Action(string action)
        {
            bool result = base.Action(action);

            if (result && action == ACTION_SHOW)
            {
                if (Utils.API.GeocachingLiveV6.CheckAPIAccessAvailable(Core, false))
                {
                    StringBuilder sb = new StringBuilder();
                    try
                    {
                        using (var api = new Utils.API.GeocachingLiveV6(Core))
                        {
                            var resp = api.Client.GetAPILimits(api.Token);
                            sb.AppendLine("CacheLimits: ");
                            foreach (var cl in resp.Limits.CacheLimits)
                            {
                                sb.AppendLine(string.Format("CacheLimit: {0}, InMinutes: {1}", cl.CacheLimit, cl.InMinutes));
                            }
                            sb.AppendLine("LightCacheLimits: ");
                            foreach (var cl in resp.Limits.LiteCacheLimits)
                            {
                                sb.AppendLine(string.Format("LiteCacheLimits: {0}, InMinutes: {1}", cl.CacheLimit, cl.InMinutes));
                            }
                            sb.AppendLine(string.Format("EnforceCacheLimits: {0}", resp.Limits.EnforceCacheLimits));
                            sb.AppendLine(string.Format("EnforceLiteCacheLimits: {0}", resp.Limits.EnforceLiteCacheLimits));
                            sb.AppendLine(string.Format("EnforceMethodLimits: {0}", resp.Limits.EnforceMethodLimits));
                            sb.AppendLine(string.Format("ForMembershipType: {0}", resp.Limits.ForMembershipType));
                            sb.AppendLine(string.Format("MaxCallsbyIPIn1Minute: {0}", resp.Limits.MaxCallsbyIPIn1Minute));
                            sb.AppendLine(string.Format("RestrictbyIP: {0}", resp.Limits.RestrictbyIP));
                            sb.AppendLine(string.Format("ValidateIPCounts: {0}", resp.Limits.ValidateIPCounts));
                            sb.AppendLine("MethodLimits: ");
                            foreach (var cl in resp.Limits.MethodLimits)
                            {
                                sb.AppendLine(string.Format("MethodName: {0}, MaxCalls: {1}, InMinutes: {2}, PartnerMethod = {3}", cl.MethodName, cl.MaxCalls, cl.InMinutes, cl.PartnerMethod));
                            }
                        }
                    }
                    catch
                    {
                        sb.AppendLine();
                        sb.AppendLine("ERROR");
                    }
                    using (APIInfoForm dlg = new APIInfoForm())
                    {
                        dlg.textBox1.Text = sb.ToString();
                        dlg.ShowDialog();
                    }
                }
            }
            return(result);
        }
Example #22
0
 private void getAllTrackableLogsThreadMethod()
 {
     try
     {
         using (Utils.ProgressBlock progr = new Utils.ProgressBlock(_plugin as Utils.BasePlugin.Plugin, STR_GETTINGLOGS, STR_GETTINGLOGS, 30, 0, true))
         {
             using (var api = new Utils.API.GeocachingLiveV6(_core, _useTestSite))
             {
                 int maxPageSize = 30;
                 while (true)
                 {
                     var resp = api.Client.GetTrackableLogsByTBCode(api.Token, _activeTb.Code, _activeTbLogs.Count, maxPageSize);
                     if (resp.Status.StatusCode == 0)
                     {
                         if (resp.TrackableLogs != null)
                         {
                             _activeTbLogs.AddRange(resp.TrackableLogs);
                             if (resp.TrackableLogs.Count() < maxPageSize)
                             {
                                 break;
                             }
                             else
                             {
                                 if (!progr.UpdateProgress(STR_GETTINGLOGS, STR_GETTINGLOGS, _activeTbLogs.Count + maxPageSize, _activeTbLogs.Count))
                                 {
                                     break;
                                 }
                                 else
                                 {
                                     Thread.Sleep(2000);
                                 }
                             }
                         }
                         else
                         {
                             break;
                         }
                     }
                     else
                     {
                         _errormessage = resp.Status.StatusMessage;
                         break;
                     }
                 }
             }
         }
     }
     catch
     {
     }
 }
Example #23
0
 public override bool Action(string action)
 {
     bool result = base.Action(action);
     if (result && action == ACTION_SHOW)
     {
         if (Utils.API.GeocachingLiveV6.CheckAPIAccessAvailable(Core, false))
         {
             StringBuilder sb = new StringBuilder();
             try
             {
                 using (var api = new Utils.API.GeocachingLiveV6(Core))
                 {
                     var resp = api.Client.GetAPILimits(api.Token);
                     sb.AppendLine("CacheLimits: ");
                     foreach(var cl in resp.Limits.CacheLimits)
                     {
                         sb.AppendLine(string.Format("CacheLimit: {0}, InMinutes: {1}", cl.CacheLimit, cl.InMinutes));
                     }
                     sb.AppendLine("LightCacheLimits: ");
                     foreach (var cl in resp.Limits.LiteCacheLimits)
                     {
                         sb.AppendLine(string.Format("LiteCacheLimits: {0}, InMinutes: {1}", cl.CacheLimit, cl.InMinutes));
                     }
                     sb.AppendLine(string.Format("EnforceCacheLimits: {0}", resp.Limits.EnforceCacheLimits));
                     sb.AppendLine(string.Format("EnforceLiteCacheLimits: {0}", resp.Limits.EnforceLiteCacheLimits));
                     sb.AppendLine(string.Format("EnforceMethodLimits: {0}", resp.Limits.EnforceMethodLimits));
                     sb.AppendLine(string.Format("ForMembershipType: {0}", resp.Limits.ForMembershipType));
                     sb.AppendLine(string.Format("MaxCallsbyIPIn1Minute: {0}", resp.Limits.MaxCallsbyIPIn1Minute));
                     sb.AppendLine(string.Format("RestrictbyIP: {0}", resp.Limits.RestrictbyIP));
                     sb.AppendLine(string.Format("ValidateIPCounts: {0}", resp.Limits.ValidateIPCounts));
                     sb.AppendLine("MethodLimits: ");
                     foreach (var cl in resp.Limits.MethodLimits)
                     {
                         sb.AppendLine(string.Format("MethodName: {0}, MaxCalls: {1}, InMinutes: {2}, PartnerMethod = {3}", cl.MethodName, cl.MaxCalls, cl.InMinutes, cl.PartnerMethod));
                     }
                 }
             }
             catch
             {
                 sb.AppendLine();
                 sb.AppendLine("ERROR");
             }
             using (APIInfoForm dlg = new APIInfoForm())
             {
                 dlg.textBox1.Text = sb.ToString();
                 dlg.ShowDialog();
             }
         }
     }
     return result;
 }
Example #24
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();
        }
Example #25
0
        public GeocacheBatchLogForm(Utils.BasePlugin.Plugin plugin, Framework.Interfaces.ICore core, Utils.API.GeocachingLiveV6 client, bool addSelected)
        {
            InitializeComponent();

            this.Text                      = Utils.LanguageSupport.Instance.GetTranslation(STR_TITLE);
            this.label1.Text               = Utils.LanguageSupport.Instance.GetTranslation(STR_GEOCACHECODE);
            this.buttonAdd.Text            = Utils.LanguageSupport.Instance.GetTranslation(STR_ADD);
            this.listView1.Columns[0].Text = Utils.LanguageSupport.Instance.GetTranslation(STR_CODE);
            this.listView1.Columns[1].Text = Utils.LanguageSupport.Instance.GetTranslation(STR_NAME);
            this.checkBox1.Text            = Utils.LanguageSupport.Instance.GetTranslation(STR_STOPATLOG);
            this.label3.Text               = Utils.LanguageSupport.Instance.GetTranslation(STR_STARTFOUNDCNT);
            this.label5.Text               = Utils.LanguageSupport.Instance.GetTranslation(STR_LOGTYPE);
            this.label8.Text               = Utils.LanguageSupport.Instance.GetTranslation(STR_DATE);
            this.label9.Text               = Utils.LanguageSupport.Instance.GetTranslation(STR_LOGTEXT);
            this.buttonSubmit.Text         = Utils.LanguageSupport.Instance.GetTranslation(STR_SUBMIT);
            this.button6.Text              = string.Format("{0} >>", Utils.LanguageSupport.Instance.GetTranslation(STR_TRACKABLES));
            this.button9.Text              = Utils.LanguageSupport.Instance.GetTranslation(STR_SELECTALL);
            this.button8.Text              = Utils.LanguageSupport.Instance.GetTranslation(STR_CLEARTALL);

            _context = SynchronizationContext.Current;
            if (_context == null)
            {
                _context = new SynchronizationContext();
            }

            _core   = core;
            _client = client;
            _plugin = plugin;
            int[] ids = new int[] { 2 };
            comboBoxLogType1.SetLogTypes(core, (from Framework.Data.LogType l in core.LogTypes join a in ids on l.ID equals a select l).ToList());
            comboBoxLogType1.SelectedIndex = 0;

            ids = new int[] { 75 };
            comboBoxLogType2.SetLogTypes(core, (from Framework.Data.LogType l in core.LogTypes join a in ids on l.ID equals a select l).ToList());
            comboBoxLogType2.SelectedIndex = 0;

            if (addSelected)
            {
                listView1.BeginUpdate();
                List <Framework.Data.Geocache> gcList = Utils.DataAccess.GetSelectedGeocaches(core.Geocaches);
                foreach (Framework.Data.Geocache gc in gcList)
                {
                    addGeocacheToList(gc);
                }
                listView1.EndUpdate();
            }
            numericUpDown1.Value = Utils.DataAccess.GetFoundGeocaches(core.Geocaches, core.Logs, core.GeocachingComAccount).Count + 1;
            checkSubmitButton();
        }
Example #26
0
 private void button1_Click(object sender, EventArgs e)
 {
     this.Cursor = Cursors.WaitCursor;
     try
     {
         using (Utils.API.GeocachingLiveV6 api = new Utils.API.GeocachingLiveV6(_core, _useTestSite))
         {
             Utils.API.LiveV6.GetTrackableResponse resp;
             if (textBox1.Text.ToUpper().StartsWith("TB"))
             {
                 resp = api.Client.GetTrackablesByTBCode(api.Token, textBox1.Text.ToUpper(), 0);
             }
             else
             {
                 resp = api.Client.GetTrackablesByTrackingNumber(api.Token, textBox1.Text.ToUpper(), 0);
             }
             if (resp.Status.StatusCode == 0)
             {
                 if (resp.Trackables.Count() > 0)
                 {
                     Utils.API.LiveV6.Trackable tb = resp.Trackables[0];
                     if (!tb.Archived && tb.CurrentOwner.UserName == _core.GeocachingComAccount.AccountName)
                     {
                         if (!imageList1.Images.ContainsKey(tb.IconUrl))
                         {
                             Image img = LoadImage(tb.IconUrl);
                             if (img != null)
                             {
                                 imageList1.Images.Add(tb.IconUrl, img);
                             }
                         }
                         ListViewItem lv = new ListViewItem(new string[] { "", tb.Code, tb.Name ?? "" }, tb.IconUrl);
                         lv.Tag = tb;
                         listView1.Items.Add(lv);
                     }
                 }
             }
             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;
 }
Example #27
0
        public override bool Action(string action)
        {
            bool result = base.Action(action);

            if (result && action == ACTION_SETTINGS)
            {
                using (System.Windows.Forms.FolderBrowserDialog dlg = new System.Windows.Forms.FolderBrowserDialog())
                {
                    if (dlg.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                    {
                        ClearActions();
                        PluginSettings.Instance.UserScriptsFolder = dlg.SelectedPath;
                        Core.CSScriptsPath = PluginSettings.Instance.UserScriptsFolder;
                        LoadFolder(PluginSettings.Instance.UserScriptsFolder);
                        InitFileSystemWatcher();
                    }
                }
            }
            else if (result && action == ACTION_REFRESH)
            {
                ClearActions();
                LoadFolder(PluginSettings.Instance.UserScriptsFolder);
            }
            else
            {
                try
                {
                    if (!_allAssembliesLoaded)
                    {
                        using (Utils.API.GeocachingLiveV6 client = new Utils.API.GeocachingLiveV6(Core))
                        {
                            //to load assembly
                        }
                        string s = System.Web.HttpUtility.HtmlEncode("hallo");
                        s = "";
                        _allAssembliesLoaded = true;
                    }
                    AsmHelper scriptAsm = new AsmHelper(CSScript.Load(_availableScripts[action].ToString()));
                    result = (bool)scriptAsm.Invoke("Script.Run", new object[] { this, Core });
                }
                catch (Exception e)
                {
                    System.Windows.Forms.MessageBox.Show(e.Message, "Error");
                }
            }
            return(result);
        }
Example #28
0
        public GeocacheLogForm(Framework.Interfaces.ICore core, Utils.API.GeocachingLiveV6 client, Framework.Data.Geocache gc)
        {
            InitializeComponent();

            this.Text                         = Utils.LanguageSupport.Instance.GetTranslation(STR_TITLE);
            this.label4.Text                  = Utils.LanguageSupport.Instance.GetTranslation(STR_GEOCACHECODE);
            this.buttonSelect.Text            = Utils.LanguageSupport.Instance.GetTranslation(STR_SELECT);
            this.label1.Text                  = Utils.LanguageSupport.Instance.GetTranslation(STR_LOGTYPE);
            this.label2.Text                  = Utils.LanguageSupport.Instance.GetTranslation(STR_DATE);
            this.label3.Text                  = Utils.LanguageSupport.Instance.GetTranslation(STR_LOGTEXT);
            this.buttonSubmit.Text            = Utils.LanguageSupport.Instance.GetTranslation(STR_SUBMIT);
            this.button1.Text                 = string.Format("{0} >>", Utils.LanguageSupport.Instance.GetTranslation(STR_TRACKABLES));
            this.button2.Text                 = Utils.LanguageSupport.Instance.GetTranslation(STR_SELECTALL);
            this.button5.Text                 = Utils.LanguageSupport.Instance.GetTranslation(STR_SELECTALL);
            this.button3.Text                 = Utils.LanguageSupport.Instance.GetTranslation(STR_CLEARTALL);
            this.button4.Text                 = Utils.LanguageSupport.Instance.GetTranslation(STR_CLEARTALL);
            this.button6.Text                 = Utils.LanguageSupport.Instance.GetTranslation(STR_ADD);
            this.removeToolStripMenuItem.Text = Utils.LanguageSupport.Instance.GetTranslation(STR_REMOVE);
            this.checkBox1.Text               = Utils.LanguageSupport.Instance.GetTranslation(STR_ADDTOFAVORITES);

            _context = SynchronizationContext.Current;
            if (_context == null)
            {
                _context = new SynchronizationContext();
            }

            _core      = core;
            _client    = client;
            _gc        = gc;
            AskForNext = true;
            int[] ids = new int[] { 2, 3, 4, 7, 45, 9, 10 };
            comboBoxLogType1.SetLogTypes(core, (from Framework.Data.LogType l in core.LogTypes join a in ids on l.ID equals a select l).ToList());

            ids = new int[] { 14 };
            comboBoxLogType2.SetLogTypes(core, (from Framework.Data.LogType l in core.LogTypes join a in ids on l.ID equals a select l).ToList());
            comboBoxLogType2.SelectedIndex = 0;

            ids = new int[] { 75 };
            comboBoxLogType3.SetLogTypes(core, (from Framework.Data.LogType l in core.LogTypes join a in ids on l.ID equals a select l).ToList());
            comboBoxLogType3.SelectedIndex = 0;

            updateGCInfo();
        }
Example #29
0
 private void getOwnedTrackables()
 {
     _tbTrackingNumbers.Clear();
     try
     {
         using (Utils.API.GeocachingLiveV6 api = new Utils.API.GeocachingLiveV6(_core))
         {
             var req = new Utils.API.LiveV6.GetTrackablesByUserRequest();
             req.AccessToken        = api.Token;
             req.MaxPerPage         = 10;
             req.StartIndex         = 0;
             req.TrackableLogsCount = 0;
             var resp = api.Client.GetUsersTrackables(req);
             while (resp.Status.StatusCode == 0)
             {
                 if (resp.Trackables != null)
                 {
                     foreach (Utils.API.LiveV6.Trackable tb in resp.Trackables)
                     {
                         _tbTrackingNumbers.Add(tb.Code, tb.TrackingCode);
                     }
                     if (resp.Trackables.Count() < req.MaxPerPage)
                     {
                         break;
                     }
                     else
                     {
                         req.StartIndex += req.MaxPerPage;
                         resp            = api.Client.GetUsersTrackables(req);
                     }
                 }
                 else
                 {
                     break;
                 }
             }
         }
     }
     catch
     {
     }
 }
Example #30
0
        private void button2_Click(object sender, EventArgs e)
        {
            try
            {
                using (var client = new Utils.API.GeocachingLiveV6(_core))
                {
                    string token = textBox1.Text.Trim();

                    var resp = client.Client.GetYourUserProfile(new Utils.API.LiveV6.GetYourUserProfileRequest()
                    {
                        AccessToken = token,
                        DeviceInfo = new Utils.API.LiveV6.DeviceData()
                        {
                            DeviceName = "GlobalcachingApplication",
                            DeviceUniqueId = "internal",
                            ApplicationSoftwareVersion = "V1.0.0.0"
                        }
                    });
                    if (resp.Status.StatusCode == 0)
                    {
                        _core.GeocachingComAccount.APIToken = token;
                        _core.GeocachingComAccount.AccountName = resp.Profile.User.UserName;
                        _core.GeocachingComAccount.MemberType = resp.Profile.User.MemberType.MemberTypeName;
                        _core.GeocachingComAccount.MemberTypeId = (int)resp.Profile.User.MemberType.MemberTypeId;
                        if (resp.Profile.User.HomeCoordinates != null)
                        {
                            _core.HomeLocation.SetLocation(resp.Profile.User.HomeCoordinates.Latitude, resp.Profile.User.HomeCoordinates.Longitude);
                        }
                        Close();
                    }
                    else
                    {
                        MessageBox.Show(resp.Status.StatusMessage, Utils.LanguageSupport.Instance.GetTranslation(STR_ERROR));
                    }
                }
            }
            catch(Exception ex)
            {
                MessageBox.Show(ex.Message, Utils.LanguageSupport.Instance.GetTranslation(STR_ERROR));
            }
        }
Example #31
0
        private void button2_Click(object sender, EventArgs e)
        {
            try
            {
                using (var client = new Utils.API.GeocachingLiveV6(_core))
                {
                    string token = textBox1.Text.Trim();

                    var resp = client.Client.GetYourUserProfile(new Utils.API.LiveV6.GetYourUserProfileRequest()
                    {
                        AccessToken = token,
                        DeviceInfo  = new Utils.API.LiveV6.DeviceData()
                        {
                            DeviceName                 = "GlobalcachingApplication",
                            DeviceUniqueId             = "internal",
                            ApplicationSoftwareVersion = "V1.0.0.0"
                        }
                    });
                    if (resp.Status.StatusCode == 0)
                    {
                        _core.GeocachingComAccount.APIToken     = token;
                        _core.GeocachingComAccount.AccountName  = resp.Profile.User.UserName;
                        _core.GeocachingComAccount.MemberType   = resp.Profile.User.MemberType.MemberTypeName;
                        _core.GeocachingComAccount.MemberTypeId = (int)resp.Profile.User.MemberType.MemberTypeId;
                        if (resp.Profile.User.HomeCoordinates != null)
                        {
                            _core.HomeLocation.SetLocation(resp.Profile.User.HomeCoordinates.Latitude, resp.Profile.User.HomeCoordinates.Longitude);
                        }
                        Close();
                    }
                    else
                    {
                        MessageBox.Show(resp.Status.StatusMessage, Utils.LanguageSupport.Instance.GetTranslation(STR_ERROR));
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, Utils.LanguageSupport.Instance.GetTranslation(STR_ERROR));
            }
        }
        public CGeoGeocacheVisitsLogForm(Utils.BasePlugin.Plugin plugin, Framework.Interfaces.ICore core, Utils.API.GeocachingLiveV6 client)
        {
            InitializeComponent();

            _core   = core;
            _client = client;
            _plugin = plugin;

            this.Text                      = Utils.LanguageSupport.Instance.GetTranslation(STR_TITLE);
            this.groupBox1.Text            = Utils.LanguageSupport.Instance.GetTranslation(STR_LOADFROMDEVICE);
            this.groupBox2.Text            = Utils.LanguageSupport.Instance.GetTranslation(STR_GEOCACHEINFO);
            this.button1.Text              = Utils.LanguageSupport.Instance.GetTranslation(STR_SELECTFILE);
            this.button3.Text              = Utils.LanguageSupport.Instance.GetTranslation(STR_IMPORTMISSING);
            this.button4.Text              = Utils.LanguageSupport.Instance.GetTranslation(STR_LOGSELECTED);
            this.button6.Text              = Utils.LanguageSupport.Instance.GetTranslation(STR_BATCHLOGSELECTED);
            this.button5.Text              = Utils.LanguageSupport.Instance.GetTranslation(STR_SELECTALL);
            this.listView1.Columns[0].Text = Utils.LanguageSupport.Instance.GetTranslation(STR_PERESENT);
            this.listView1.Columns[1].Text = Utils.LanguageSupport.Instance.GetTranslation(STR_CODE);
            this.listView1.Columns[2].Text = Utils.LanguageSupport.Instance.GetTranslation(STR_DATE);
            this.listView1.Columns[3].Text = Utils.LanguageSupport.Instance.GetTranslation(STR_LOGTYPE);
            this.listView1.Columns[4].Text = Utils.LanguageSupport.Instance.GetTranslation(STR_COMMENT);
        }
        public GarminGeocacheVisitsLogForm(Utils.BasePlugin.Plugin plugin, Framework.Interfaces.ICore core, Utils.API.GeocachingLiveV6 client)
        {
            InitializeComponent();

            _core = core;
            _client = client;
            _plugin = plugin;

            this.Text = Utils.LanguageSupport.Instance.GetTranslation(STR_TITLE);
            this.groupBox1.Text = Utils.LanguageSupport.Instance.GetTranslation(STR_LOADFROMDEVICE);
            this.groupBox2.Text = Utils.LanguageSupport.Instance.GetTranslation(STR_GEOCACHEINFO);
            this.button1.Text = Utils.LanguageSupport.Instance.GetTranslation(STR_SELECTFILE);
            this.button3.Text = Utils.LanguageSupport.Instance.GetTranslation(STR_IMPORTMISSING);
            this.button4.Text = Utils.LanguageSupport.Instance.GetTranslation(STR_LOGSELECTED);
            this.button6.Text = Utils.LanguageSupport.Instance.GetTranslation(STR_BATCHLOGSELECTED);
            this.button5.Text = Utils.LanguageSupport.Instance.GetTranslation(STR_SELECTALL);
            this.listView1.Columns[0].Text = Utils.LanguageSupport.Instance.GetTranslation(STR_PERESENT);
            this.listView1.Columns[1].Text = Utils.LanguageSupport.Instance.GetTranslation(STR_CODE);
            this.listView1.Columns[2].Text = Utils.LanguageSupport.Instance.GetTranslation(STR_DATE);
            this.listView1.Columns[3].Text = Utils.LanguageSupport.Instance.GetTranslation(STR_LOGTYPE);
            this.listView1.Columns[4].Text = Utils.LanguageSupport.Instance.GetTranslation(STR_COMMENT);
        }
Example #34
0
        public override bool Action(string action)
        {
            bool result = base.Action(action);

            if (result && action == ACTION_SHOW)
            {
                if (Utils.API.GeocachingLiveV6.CheckAPIAccessAvailable(Core, true))
                {
                    using (var client = new Utils.API.GeocachingLiveV6(Core, true))
                    {
                        var res = client.Client.GetUserWaypoints(client.Token, "GC2CHT2");
                        if (res.Status.StatusCode == 0)
                        {
                        }
                        ///*
                        var req = new Utils.API.LiveV6.SaveUserWaypointRequest();
                        req.AccessToken = client.Token;
                        req.CacheCode   = "GC2CHT2";
                        req.Description = "Coordinate Override";
                        var ll = Utils.Conversion.StringToLocation("N 52° 14.431 E 005° 56.159");
                        req.Latitude  = ll.Lat;
                        req.Longitude = ll.Lon;
                        var res2 = client.Client.SaveUserWaypoint(req);

                        if (res2.Status.StatusCode == 0)
                        {
                        }

                        res = client.Client.GetUserWaypoints(client.Token, "GC2CHT2");
                        if (res.Status.StatusCode == 0)
                        {
                        }
                        //* */
                    }
                }
            }
            return(result);
        }
 public override bool Action(string action)
 {
     bool result = base.Action(action);
     if (result && action == ACTION_SHOW)
     {
         try
         {
             using (var api = new Utils.API.GeocachingLiveV6(Core))
             {
                 var req = new Utils.API.LiveV6.GetAnotherUsersProfileRequest();
                 req.AccessToken = api.Token;
                 req.UserID = 164977;
                 req.ProfileOptions = new Utils.API.LiveV6.UserProfileOptions();
                 req.ProfileOptions.PublicProfileData = true;
                 var p = api.Client.GetAnotherUsersProfile(req);
             }
         }
         catch(Exception e)
         {
         }
     }
     return result;
 }
Example #36
0
        public override bool Action(string action)
        {
            bool result = base.Action(action);
            if (result && action == ACTION_SHOW)
            {
                if (Utils.API.GeocachingLiveV6.CheckAPIAccessAvailable(Core, true))
                {
                    using (var client = new Utils.API.GeocachingLiveV6(Core, true))
                    {
                        var res = client.Client.GetUserWaypoints(client.Token, "GC2CHT2");
                        if (res.Status.StatusCode == 0)
                        {
                        }
                        ///*
                        var req = new Utils.API.LiveV6.SaveUserWaypointRequest();
                        req.AccessToken = client.Token;
                        req.CacheCode = "GC2CHT2";
                        req.Description = "Coordinate Override";
                        var ll = Utils.Conversion.StringToLocation("N 52° 14.431 E 005° 56.159");
                        req.Latitude = ll.Lat;
                        req.Longitude = ll.Lon;
                        var res2 = client.Client.SaveUserWaypoint(req);

                        if (res2.Status.StatusCode == 0)
                        {
                        }

                        res = client.Client.GetUserWaypoints(client.Token, "GC2CHT2");
                        if (res.Status.StatusCode == 0)
                        {
                        }
                         //* */
                    }
                }
            }
            return result;
        }
Example #37
0
 public override bool Action(string action)
 {
     bool result = base.Action(action);
     if (result && action == ACTION_SHOW)
     {
         if (Utils.API.GeocachingLiveV6.CheckAPIAccessAvailable(Core, true))
         {
             using (var client = new Utils.API.GeocachingLiveV6(Core))
             {
                 StringBuilder sb = new StringBuilder();
                 var res = client.Client.GetAttributeTypesData(client.Token);
                 if (res.Status.StatusCode == 0)
                 {
                     foreach (var at in res.AttributeTypes)
                     {
                         sb.AppendLine(string.Format("htAttributes[{0}] = \"{1}\";", at.ID, at.IconName));
                     }
                 }
                 string fill = sb.ToString();
             }
         }
     }
     return result;
 }
Example #38
0
        public override bool Action(string action)
        {
            bool result = base.Action(action);

            if (result && action == ACTION_SHOW)
            {
                try
                {
                    using (var api = new Utils.API.GeocachingLiveV6(Core))
                    {
                        var req = new Utils.API.LiveV6.GetAnotherUsersProfileRequest();
                        req.AccessToken    = api.Token;
                        req.UserID         = 164977;
                        req.ProfileOptions = new Utils.API.LiveV6.UserProfileOptions();
                        req.ProfileOptions.PublicProfileData = true;
                        var p = api.Client.GetAnotherUsersProfile(req);
                    }
                }
                catch (Exception e)
                {
                }
            }
            return(result);
        }
Example #39
0
        private void GetAllTrackableDataThreadMethod()
        {
            try
            {
                using (Utils.ProgressBlock progr = new Utils.ProgressBlock(this.OwnerPlugin as Utils.BasePlugin.Plugin, "Get trackable data...", "Fetching data from geocaching.com...", _tbList.Count, 0, true))
                {
                    bool cancel = false;
                    using (var api = new Utils.API.GeocachingLiveV6(Core))
                    {
                        for (int i = 0; i < _tbList.Count; i++)
                        {
                            if (_tbList[i].ToUpper().StartsWith("TB"))
                            {
                                Core.DebugLog(Framework.Data.DebugLogLevel.Info, OwnerPlugin, null, string.Format("{0} - GetTrackablesByTBCode - ", DateTime.Now.ToString("HH:mm:ss.fff")));
                                var resp = api.Client.GetTrackablesByTBCode(api.Token, _tbList[i].ToUpper(), 0);
                                if (resp.Status.StatusCode == 0)
                                {
                                    if (resp.Trackables != null)
                                    {
                                        foreach (var t in resp.Trackables)
                                        {
                                            TrackableItem trk = GetTrackableItemFromLiveAPI(t);
                                            AddTrackableToDatabase(trk);

                                            Core.DebugLog(Framework.Data.DebugLogLevel.Info, OwnerPlugin, null, string.Format("{0} - GetTrackableTravelList - ", DateTime.Now.ToString("HH:mm:ss.fff")));
                                            var resp2 = api.Client.GetTrackableTravelList(api.Token, trk.Code);
                                            if (resp2.Status.StatusCode == 0)
                                            {
                                                if (resp2.TrackableTravels != null)
                                                {
                                                    List<TravelItem> travelList = new List<TravelItem>();
                                                    foreach (var tt in resp2.TrackableTravels)
                                                    {
                                                        if (tt.Latitude != null && tt.Longitude != null)
                                                        {
                                                            TravelItem ti = new TravelItem();
                                                            ti.TrackableCode = trk.Code;
                                                            if (tt.CacheID != null)
                                                            {
                                                                ti.GeocacheCode = Utils.Conversion.GetCacheCodeFromCacheID((int)tt.CacheID);
                                                            }
                                                            else
                                                            {
                                                                ti.GeocacheCode = "";
                                                            }
                                                            ti.DateLogged = tt.DateLogged;
                                                            ti.Lat = (double)tt.Latitude;
                                                            ti.Lon = (double)tt.Longitude;
                                                            travelList.Add(ti);
                                                        }
                                                    }
                                                    AddTravelListToDatabase(trk.Code, travelList);
                                                }

                                                //get all logs
                                                List<LogItem> logs = new List<LogItem>();
                                                int maxPageSize = 30;
                                                while (true)
                                                {
                                                    Core.DebugLog(Framework.Data.DebugLogLevel.Info, OwnerPlugin, null, string.Format("{0} - GetTrackableLogsByTBCode - ", DateTime.Now.ToString("HH:mm:ss.fff")));
                                                    var resp3 = api.Client.GetTrackableLogsByTBCode(api.Token, trk.Code, logs.Count, maxPageSize);
                                                    if (resp3.Status.StatusCode == 0)
                                                    {
                                                        if (resp3.TrackableLogs != null)
                                                        {
                                                            foreach (var tl in resp3.TrackableLogs)
                                                            {
                                                                LogItem li = new LogItem();
                                                                li.TrackableCode = trk.Code;
                                                                if (tl.CacheID != null)
                                                                {
                                                                    li.GeocacheCode = Utils.Conversion.GetCacheCodeFromCacheID((int)tl.CacheID);
                                                                }
                                                                else
                                                                {
                                                                    li.GeocacheCode = "";
                                                                }
                                                                li.LogCode = tl.Code;
                                                                li.ID = tl.ID;
                                                                li.IsArchived = tl.IsArchived;
                                                                li.LoggedBy = tl.LoggedBy==null?"":tl.LoggedBy.UserName;
                                                                li.LogGuid = tl.LogGuid.ToString();
                                                                li.LogIsEncoded = tl.LogIsEncoded;
                                                                li.LogText = tl.LogText;
                                                                li.WptLogTypeId = tl.LogType == null ? -1 : (int)tl.LogType.WptLogTypeId;
                                                                li.Url = tl.Url;
                                                                li.UTCCreateDate = tl.UTCCreateDate;
                                                                li.VisitDate = tl.VisitDate;
                                                                logs.Add(li);
                                                            }
                                                            if (resp3.TrackableLogs.Count() < maxPageSize)
                                                            {
                                                                break;
                                                            }
                                                            Thread.Sleep(2000 + PluginSettings.Instance.TimeBetweenTrackableUpdates);
                                                        }
                                                        else
                                                        {
                                                            break;
                                                        }
                                                    }
                                                    else
                                                    {
                                                        _errormessage = resp3.Status.StatusMessage;
                                                        break;
                                                    }
                                                }
                                                if (string.IsNullOrEmpty(_errormessage))
                                                {
                                                    AddLogListToDatabase(trk.Code, logs);
                                                }
                                            }
                                            else
                                            {
                                                _errormessage = resp2.Status.StatusMessage;
                                                break;
                                            }
                                            if (!progr.UpdateProgress("Get trackable data...", "Fetching data from geocaching.com...", _tbList.Count, i))
                                            {
                                                cancel = true;
                                                break;
                                            }
                                        }
                                    }
                                }
                                else
                                {
                                    _errormessage = resp.Status.StatusMessage;
                                }
                            }
                            if (cancel || !string.IsNullOrEmpty(_errormessage))
                            {
                                break;
                            }
                            if (PluginSettings.Instance.TimeBetweenTrackableUpdates > 0)
                            {
                                System.Threading.Thread.Sleep(PluginSettings.Instance.TimeBetweenTrackableUpdates);
                            }
                        }
                    }
                }
            }
            catch
            {
            }
        }
Example #40
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);
 }
Example #41
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);
 }
Example #42
0
 public async override Task<bool> ActionAsync(string action)
 {
     bool result = base.Action(action);
     if (result && action == ACTION_IMPORT)
     {
         try
         {
             //get from goundspeak
             if (Utils.API.GeocachingLiveV6.CheckAPIAccessAvailable(Core, true))
             {
                 using (Utils.API.GeocachingLiveV6 client = new Utils.API.GeocachingLiveV6(Core, false))
                 {
                     Utils.API.LiveV6.PQData[] pqData = getAvailablePocketQueries(client);
                     if (pqData!=null)
                     {
                         using (SelectPQForm dlg = new SelectPQForm(pqData, getProcessedPq()))
                         {
                             if (dlg.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                             {
                                 _pqs = dlg.SelectedPQs;
                                 _client = client;
                                 await PerformImport();
                             }
                         }
                     }
                 }
             }
         }
         catch(Exception e)
         {
             System.Windows.Forms.MessageBox.Show(e.Message, Utils.LanguageSupport.Instance.GetTranslation(STR_ERROR), System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error);
         }
     }
     return result;
 }
Example #43
0
        private bool getBookmarkList(Guid guid)
        {
            bool result = false;

            Cursor = Cursors.WaitCursor;
            try
            {
                using (Utils.API.GeocachingLiveV6 api = new Utils.API.GeocachingLiveV6(_core))
                {
                    var req = new Utils.API.LiveV6.GetBookmarkListByGuidRequest();
                    req.AccessToken = api.Token;
                    req.BookmarkListGuid = guid;
                    var resp = api.Client.GetBookmarkListByGuid(req);
                    if (resp.Status.StatusCode == 0)
                    {
                        _gcCodes = (from c in resp.BookmarkList select c.CacheCode).ToList();
                        result = true;
                    }
                    else
                    {
                        MessageBox.Show(resp.Status.StatusMessage, Utils.LanguageSupport.Instance.GetTranslation(STR_ERROR));
                    }
                }
            }
            catch(Exception e)
            {
                MessageBox.Show(e.Message, Utils.LanguageSupport.Instance.GetTranslation(STR_ERROR));
            }
            Cursor = Cursors.Default;

            return result;
        }
Example #44
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;
                }
            }
        }
Example #45
0
        public GeocacheBatchLogForm(Utils.BasePlugin.Plugin plugin, Framework.Interfaces.ICore core, Utils.API.GeocachingLiveV6 client, bool addSelected)
        {
            InitializeComponent();

            this.Text = Utils.LanguageSupport.Instance.GetTranslation(STR_TITLE);
            this.label1.Text = Utils.LanguageSupport.Instance.GetTranslation(STR_GEOCACHECODE);
            this.buttonAdd.Text = Utils.LanguageSupport.Instance.GetTranslation(STR_ADD);
            this.listView1.Columns[0].Text = Utils.LanguageSupport.Instance.GetTranslation(STR_CODE);
            this.listView1.Columns[1].Text = Utils.LanguageSupport.Instance.GetTranslation(STR_NAME);
            this.checkBox1.Text = Utils.LanguageSupport.Instance.GetTranslation(STR_STOPATLOG);
            this.label3.Text = Utils.LanguageSupport.Instance.GetTranslation(STR_STARTFOUNDCNT);
            this.label5.Text = Utils.LanguageSupport.Instance.GetTranslation(STR_LOGTYPE);
            this.label8.Text = Utils.LanguageSupport.Instance.GetTranslation(STR_DATE);
            this.label9.Text = Utils.LanguageSupport.Instance.GetTranslation(STR_LOGTEXT);
            this.buttonSubmit.Text = Utils.LanguageSupport.Instance.GetTranslation(STR_SUBMIT);
            this.button6.Text = string.Format("{0} >>", Utils.LanguageSupport.Instance.GetTranslation(STR_TRACKABLES));
            this.button9.Text = Utils.LanguageSupport.Instance.GetTranslation(STR_SELECTALL);
            this.button8.Text = Utils.LanguageSupport.Instance.GetTranslation(STR_CLEARTALL);

            _context = SynchronizationContext.Current;
            if (_context == null)
            {
                _context = new SynchronizationContext();
            }

            _core = core;
            _client = client;
            _plugin = plugin;
            int[] ids = new int[] { 2 };
            comboBoxLogType1.SetLogTypes(core, (from Framework.Data.LogType l in core.LogTypes join a in ids on l.ID equals a select l).ToList());
            comboBoxLogType1.SelectedIndex = 0;

            ids = new int[] { 75 };
            comboBoxLogType2.SetLogTypes(core, (from Framework.Data.LogType l in core.LogTypes join a in ids on l.ID equals a select l).ToList());
            comboBoxLogType2.SelectedIndex = 0;

            if (addSelected)
            {
                listView1.BeginUpdate();
                List<Framework.Data.Geocache> gcList = Utils.DataAccess.GetSelectedGeocaches(core.Geocaches);
                foreach (Framework.Data.Geocache gc in gcList)
                {
                    addGeocacheToList(gc);
                }
                listView1.EndUpdate();
            }
            numericUpDown1.Value = Utils.DataAccess.GetFoundGeocaches(core.Geocaches, core.Logs, core.GeocachingComAccount).Count + 1;
            checkSubmitButton();
        }
Example #46
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;
 }
Example #47
0
 private void getOwnedTrackables()
 {
     _tbTrackingNumbers.Clear();
     try
     {
         using (Utils.API.GeocachingLiveV6 api = new Utils.API.GeocachingLiveV6(_core))
         {
             var req = new Utils.API.LiveV6.GetTrackablesByUserRequest();
             req.AccessToken = api.Token;
             req.MaxPerPage = 10;
             req.StartIndex = 0;
             req.TrackableLogsCount = 0;
             var resp = api.Client.GetUsersTrackables(req);
             while (resp.Status.StatusCode == 0)
             {
                 if (resp.Trackables != null)
                 {
                     foreach (Utils.API.LiveV6.Trackable tb in resp.Trackables)
                     {
                         _tbTrackingNumbers.Add(tb.Code, tb.TrackingCode);
                     }
                     if (resp.Trackables.Count() < req.MaxPerPage)
                     {
                         break;
                     }
                     else
                     {
                         req.StartIndex += req.MaxPerPage;
                         resp = api.Client.GetUsersTrackables(req);
                     }
                 }
                 else
                 {
                     break;
                 }
             }
         }
     }
     catch
     {
     }
 }
Example #48
0
 private void logThreadMethod()
 {
     try
     {
         using (Utils.API.GeocachingLiveV6 api = new Utils.API.GeocachingLiveV6(_core))
         {
             var req = new Utils.API.LiveV6.CreateTrackableLogRequest();
             req.AccessToken = api.Token;
             req.Note = _logText;
             req.LogType = _logType.ID;
             req.UTCDateLogged = _visitDate.AddHours(12).ToUniversalTime();
             bool getOwnedDone = false;
             foreach (string tb in _tbs)
             {
                 if (tb.StartsWith("TB"))
                 {
                     if (_tbTrackingNumbers[tb] as string == null)
                     {
                         if (!getOwnedDone)
                         {
                             getOwnedTrackables();
                         }
                     }
                     req.TrackingNumber = _tbTrackingNumbers[tb] as string;
                 }
                 else
                 {
                     req.TrackingNumber = tb;
                 }
                 req.CacheCode = _gcCode;
                 var resp = api.Client.CreateTrackableLog(req);
                 if (resp.Status.StatusCode == 0)
                 {
                     _context.Send(new SendOrPostCallback(delegate(object state)
                     {
                         checkedListBox1.SetItemChecked(checkedListBox1.Items.IndexOf(tb), false);
                         toolStripProgressBar1.Value++;
                     }), null);
                 }
                 else
                 {
                     _errormessage = resp.Status.StatusMessage;
                 }
                 if (_stopAfterEachLog || _cancelled)
                 {
                     break;
                 }
                 else
                 {
                     Thread.Sleep(2000);
                 }
             }
         }
     }
     catch (Exception e)
     {
         _errormessage = e.Message;
     }
     _actionReady.Set();
 }
Example #49
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;
            }
        }
Example #50
0
        public override bool Action(string action)
        {
            bool result = base.Action(action);
            if (result)
            {
                try
                {
                    //get from goundspeak
                    if (Utils.API.GeocachingLiveV6.CheckAPIAccessAvailable(Core, false))
                    {
#if DEBUG
                        //using (var client = new Utils.API.GeocachingLiveV6(Core, true))
                        using (var client = new Utils.API.GeocachingLiveV6(Core))
#else
                        using (var client = new Utils.API.GeocachingLiveV6(Core))
#endif
                        {
                            if (action == ACTION_SINGLE)
                            {
                                using (GeocacheLogForm dlg = new GeocacheLogForm(Core, client, Core.ActiveGeocache))
                                {
                                    dlg.ShowDialog();
                                }
                            }
                            else if (action == ACTION_BATCH)
                            {
                                using (GeocacheBatchLogForm dlg = new GeocacheBatchLogForm(this, Core, client))
                                {
                                    dlg.ShowDialog();
                                }
                            }
                            else if (action == ACTION_GARMINVISIT)
                            {
                                using (GarminGeocacheVisitsLogForm dlg = new GarminGeocacheVisitsLogForm(this, Core, client))
                                {
                                    dlg.ShowDialog();
                                }
                            }
                            else if (action == ACTION_CGEOVISIT)
                            {
                                using (CGeoGeocacheVisitsLogForm dlg = new CGeoGeocacheVisitsLogForm(this, Core, client))
                                {
                                    dlg.ShowDialog();
                                }
                            }
                            else if (action == ACTION_OFFLINE)
                            {
                                using (OfflineLogForm dlg = new OfflineLogForm(this, Core, client))
                                {
                                    dlg.ShowDialog();
                                }
                            }
                        }
                    }
                }
                catch
                {
                    System.Windows.Forms.MessageBox.Show(Utils.LanguageSupport.Instance.GetTranslation(STR_UNABLEACCESSAPI), Utils.LanguageSupport.Instance.GetTranslation(STR_ERROR), System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error);
                }
            }
            return result;
        }
Example #51
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;

                        while (_gcList.Count > 0)
                        {
                            if (PluginSettings.Instance.AdditionalDelayBetweenImageImport > 0)
                            {
                                Thread.Sleep(PluginSettings.Instance.AdditionalDelayBetweenImageImport);
                            }
                            var resp = client.Client.GetImagesForGeocache(client.Token, _gcList[0].Code);
                            if (resp.Status.StatusCode == 0)
                            {
                                if (resp.Images != null)
                                {
                                    List <string> ids = new List <string>();
                                    foreach (var img in resp.Images)
                                    {
                                        if (img.Url.IndexOf("/cache/log/") < 0)
                                        {
                                            Framework.Data.GeocacheImage gcImg = Utils.API.Convert.GeocacheImage(Core, img, _gcList[0].Code);
                                            AddGeocacheImage(gcImg);
                                            ids.Add(gcImg.ID);
                                        }
                                    }
                                    List <Framework.Data.GeocacheImage> allImages = Utils.DataAccess.GetGeocacheImages(Core.GeocacheImages, _gcList[0].Code);
                                    foreach (Framework.Data.GeocacheImage gim in allImages)
                                    {
                                        if (!ids.Contains(gim.ID))
                                        {
                                            Core.GeocacheImages.Remove(gim);
                                        }
                                    }
                                }

                                if (PluginSettings.Instance.DeselectGeocacheAfterUpdate)
                                {
                                    _gcList[0].Selected = false;
                                }

                                index++;
                                if (!progress.UpdateProgress(STR_UPDATINGGEOCACHES, STR_UPDATINGGEOCACHE, totalcount, index))
                                {
                                    break;
                                }
                                _gcList.RemoveAt(0);

                                if (_gcList.Count > 0)
                                {
                                    Thread.Sleep(3000);
                                }
                            }
                            else
                            {
                                _errormessage = resp.Status.StatusMessage;
                                break;
                            }
                        }
                    }
                }
            }
            catch (Exception e)
            {
                _errormessage = e.Message;
            }
        }
 private void button4_Click(object sender, EventArgs e)
 {
     WaypointListItem wpi = listBox1.SelectedItem as WaypointListItem;
     Framework.Data.Location ll = Utils.Conversion.StringToLocation(textBox8.Text);
     if (Core.ActiveGeocache!=null && wpi != null && wpi.WP.ID <= 0)
     {
         if (Utils.API.GeocachingLiveV6.CheckAPIAccessAvailable(Core, true))
         {
             try
             {
                 Utils.API.LiveV6.SaveUserWaypointResponse resp = null;
                 Cursor = Cursors.WaitCursor;
                 try
                 {
                     using (Utils.API.GeocachingLiveV6 api = new Utils.API.GeocachingLiveV6(Core))
                     {
                         var req = new Utils.API.LiveV6.SaveUserWaypointRequest();
                         req.AccessToken = api.Token;
                         req.CacheCode = Core.ActiveGeocache.Code;
                         req.Description = textBox2.Text;
                         req.Latitude = ll.Lat;
                         req.Longitude = ll.Lon;
                         resp = api.Client.SaveUserWaypoint(req);
                     }
                 }
                 finally
                 {
                     Cursor = Cursors.Default;
                 }
                 if (resp != null)
                 {
                     if (resp.Status.StatusCode == 0)
                     {
                         Framework.Data.UserWaypoint wp = Utils.API.Convert.UserWaypoint(Core, resp.NewWaypoint);
                         wp.Saved = false;
                         wpi.WP = wp;
                         Core.UserWaypoints.Add(wp);
                     }
                     else
                     {
                         MessageBox.Show(resp.Status.StatusMessage ?? "", Utils.LanguageSupport.Instance.GetTranslation(STR_ERROR));
                     }
                 }
                 else
                 {
                     MessageBox.Show(Utils.LanguageSupport.Instance.GetTranslation(STR_FAILED), Utils.LanguageSupport.Instance.GetTranslation(STR_ERROR));
                 }
             }
             catch
             {
                 MessageBox.Show(Utils.LanguageSupport.Instance.GetTranslation(STR_FAILED), Utils.LanguageSupport.Instance.GetTranslation(STR_ERROR));
             }
         }
     }
 }
Example #53
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);
            }
        }
Example #54
0
 public override bool Action(string action)
 {
     bool result = base.Action(action);
     if (result && action == ACTION_SETTINGS)
     {
         using (System.Windows.Forms.FolderBrowserDialog dlg = new System.Windows.Forms.FolderBrowserDialog())
         {
             if (dlg.ShowDialog()== System.Windows.Forms.DialogResult.OK)
             {
                 ClearActions();
                 PluginSettings.Instance.UserScriptsFolder = dlg.SelectedPath;
                 Core.CSScriptsPath = PluginSettings.Instance.UserScriptsFolder;
                 LoadFolder(PluginSettings.Instance.UserScriptsFolder);
                 InitFileSystemWatcher();
             }
         }
     }
     else if (result && action == ACTION_REFRESH)
     {
         ClearActions();
         LoadFolder(PluginSettings.Instance.UserScriptsFolder);
     }
     else
     {
         try
         {
             if (!_allAssembliesLoaded)
             {
                 using (Utils.API.GeocachingLiveV6 client = new Utils.API.GeocachingLiveV6(Core))
                 {
                     //to load assembly
                 }
                 string s = System.Web.HttpUtility.HtmlEncode("hallo");
                 s = "";
                 _allAssembliesLoaded = true;
             }
             AsmHelper scriptAsm = new AsmHelper(CSScript.Load(_availableScripts[action].ToString()));
             result = (bool)scriptAsm.Invoke("Script.Run", new object[] { this, Core });
         }
         catch (Exception e)
         {
             System.Windows.Forms.MessageBox.Show(e.Message, "Error");
         }
     }
     return result;
 }
Example #55
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;
                        bool cancel = false;

                        while (_gcList.Count > 0 && !cancel)
                        {
                            int logCount = 0;
                            int maxPerPage = 30;
                            bool done = false;

                            if (PluginSettings.Instance.UpdateLogsMaxLogCount > 0 && PluginSettings.Instance.UpdateLogsMaxLogCount < 30)
                            {
                                maxPerPage = PluginSettings.Instance.UpdateLogsMaxLogCount;
                            }
                            List<string> ids = new List<string>();
                            
                            Thread.Sleep(PluginSettings.Instance.AdditionalDelayBetweenLogImport);
                            var resp = client.Client.GetGeocacheLogsByCacheCode(client.Token, _gcList[0].Code, logCount, maxPerPage);
                            while (resp.Status.StatusCode == 0 && resp.Logs != null && resp.Logs.Count() > 0 && !done)
                            {
                                foreach (var lg in resp.Logs)
                                {
                                    if (!lg.IsArchived)
                                    {
                                        Framework.Data.Log gcLog = Utils.API.Convert.Log(Core, lg);
                                        AddLog(gcLog);
                                        if (PluginSettings.Instance.UpdateLogsMaxLogCount == 0)
                                        {
                                            ids.Add(gcLog.ID);
                                        }
                                    }
                                }

                                logCount += resp.Logs.Count();
                                if (PluginSettings.Instance.UpdateLogsMaxLogCount > 0)
                                {
                                    int left = PluginSettings.Instance.UpdateLogsMaxLogCount - logCount;
                                    if (left < maxPerPage)
                                    {
                                        maxPerPage = left;
                                    }
                                }
                                if (maxPerPage > 0)
                                {
                                    Thread.Sleep(3000 + PluginSettings.Instance.AdditionalDelayBetweenLogImport);
                                    resp = client.Client.GetGeocacheLogsByCacheCode(client.Token, _gcList[0].Code, logCount, maxPerPage);
                                }
                                else
                                {
                                    done = true;
                                }
                            }
                            if (resp.Status.StatusCode != 0)
                            {
                                _errormessage = resp.Status.StatusMessage;
                                break;
                            }
                            else
                            {
                                if (PluginSettings.Instance.DeselectGeocacheAfterUpdate)
                                {
                                    _gcList[0].Selected = false;
                                }
                                if (PluginSettings.Instance.UpdateLogsMaxLogCount == 0)
                                {
                                    List<Framework.Data.Log> allLogs = Utils.DataAccess.GetLogs(Core.Logs, _gcList[0].Code);
                                    foreach (Framework.Data.Log gim in allLogs)
                                    {
                                        if (!ids.Contains(gim.ID))
                                        {
                                            Core.Logs.Remove(gim);
                                        }
                                    }
                                }
                            }

                            index++;
                            if (!progress.UpdateProgress(STR_UPDATINGGEOCACHES, STR_UPDATINGGEOCACHE, totalcount, index))
                            {
                                break;
                            }
                            _gcList.RemoveAt(0);
                        }
                    }
                }
            }
            catch (Exception e)
            {
                _errormessage = e.Message;
            }
        }
Example #56
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;
                }
            }
        }
Example #57
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;
                        bool cancel = false;

                        while (_gcList.Count > 0 && !cancel)
                        {
                            int  logCount   = 0;
                            int  maxPerPage = 30;
                            bool done       = false;

                            if (PluginSettings.Instance.UpdateLogsMaxLogCount > 0 && PluginSettings.Instance.UpdateLogsMaxLogCount < 30)
                            {
                                maxPerPage = PluginSettings.Instance.UpdateLogsMaxLogCount;
                            }
                            List <string> ids = new List <string>();

                            Thread.Sleep(PluginSettings.Instance.AdditionalDelayBetweenLogImport);
                            var resp = client.Client.GetGeocacheLogsByCacheCode(client.Token, _gcList[0].Code, logCount, maxPerPage);
                            while (resp.Status.StatusCode == 0 && resp.Logs != null && resp.Logs.Count() > 0 && !done)
                            {
                                foreach (var lg in resp.Logs)
                                {
                                    if (!lg.IsArchived)
                                    {
                                        Framework.Data.Log gcLog = Utils.API.Convert.Log(Core, lg);
                                        AddLog(gcLog);
                                        if (PluginSettings.Instance.UpdateLogsMaxLogCount == 0)
                                        {
                                            ids.Add(gcLog.ID);
                                        }
                                    }
                                }

                                logCount += resp.Logs.Count();
                                if (PluginSettings.Instance.UpdateLogsMaxLogCount > 0)
                                {
                                    int left = PluginSettings.Instance.UpdateLogsMaxLogCount - logCount;
                                    if (left < maxPerPage)
                                    {
                                        maxPerPage = left;
                                    }
                                }
                                if (maxPerPage > 0)
                                {
                                    Thread.Sleep(3000 + PluginSettings.Instance.AdditionalDelayBetweenLogImport);
                                    resp = client.Client.GetGeocacheLogsByCacheCode(client.Token, _gcList[0].Code, logCount, maxPerPage);
                                }
                                else
                                {
                                    done = true;
                                }
                            }
                            if (resp.Status.StatusCode != 0)
                            {
                                _errormessage = resp.Status.StatusMessage;
                                break;
                            }
                            else
                            {
                                if (PluginSettings.Instance.DeselectGeocacheAfterUpdate)
                                {
                                    _gcList[0].Selected = false;
                                }
                                if (PluginSettings.Instance.UpdateLogsMaxLogCount == 0)
                                {
                                    List <Framework.Data.Log> allLogs = Utils.DataAccess.GetLogs(Core.Logs, _gcList[0].Code);
                                    foreach (Framework.Data.Log gim in allLogs)
                                    {
                                        if (!ids.Contains(gim.ID))
                                        {
                                            Core.Logs.Remove(gim);
                                        }
                                    }
                                }
                            }

                            index++;
                            if (!progress.UpdateProgress(STR_UPDATINGGEOCACHES, STR_UPDATINGGEOCACHE, totalcount, index))
                            {
                                break;
                            }
                            _gcList.RemoveAt(0);
                        }
                    }
                }
            }
            catch (Exception e)
            {
                _errormessage = e.Message;
            }
        }
Example #58
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;

                        while (_gcList.Count > 0)
                        {
                            if (PluginSettings.Instance.AdditionalDelayBetweenImageImport > 0)
                            {
                                Thread.Sleep(PluginSettings.Instance.AdditionalDelayBetweenImageImport);
                            }
                            var resp = client.Client.GetImagesForGeocache(client.Token, _gcList[0].Code);
                            if (resp.Status.StatusCode == 0)
                            {
                                if (resp.Images != null)
                                {
                                    List<string> ids = new List<string>();
                                    foreach (var img in resp.Images)
                                    {
                                        if (img.Url.IndexOf("/cache/log/") < 0)
                                        {
                                            Framework.Data.GeocacheImage gcImg = Utils.API.Convert.GeocacheImage(Core, img, _gcList[0].Code);
                                            AddGeocacheImage(gcImg);
                                            ids.Add(gcImg.ID);
                                        }
                                    }
                                    List<Framework.Data.GeocacheImage> allImages = Utils.DataAccess.GetGeocacheImages(Core.GeocacheImages, _gcList[0].Code);
                                    foreach (Framework.Data.GeocacheImage gim in allImages)
                                    {
                                        if (!ids.Contains(gim.ID))
                                        {
                                            Core.GeocacheImages.Remove(gim);
                                        }
                                    }
                                }

                                if (PluginSettings.Instance.DeselectGeocacheAfterUpdate)
                                {
                                    _gcList[0].Selected = false;
                                }

                                index++;
                                if (!progress.UpdateProgress(STR_UPDATINGGEOCACHES, STR_UPDATINGGEOCACHE, totalcount, index))
                                {
                                    break;
                                }
                                _gcList.RemoveAt(0);

                                if (_gcList.Count > 0)
                                {
                                    Thread.Sleep(3000);
                                }
                            }
                            else
                            {
                                _errormessage = resp.Status.StatusMessage;
                                break;
                            }
                        }
                    }
                }
            }
            catch (Exception e)
            {
                _errormessage = e.Message;
            }
        }
Example #59
0
        public override bool Action(string action)
        {
            bool result = base.Action(action);

            if (result)
            {
                try
                {
                    //get from goundspeak
                    if (Utils.API.GeocachingLiveV6.CheckAPIAccessAvailable(Core, false))
                    {
#if DEBUG
                        //using (var client = new Utils.API.GeocachingLiveV6(Core, true))
                        using (var client = new Utils.API.GeocachingLiveV6(Core))
#else
                        using (var client = new Utils.API.GeocachingLiveV6(Core))
#endif
                        {
                            if (action == ACTION_SINGLE)
                            {
                                using (GeocacheLogForm dlg = new GeocacheLogForm(Core, client, Core.ActiveGeocache))
                                {
                                    dlg.ShowDialog();
                                }
                            }
                            else if (action == ACTION_BATCH)
                            {
                                using (GeocacheBatchLogForm dlg = new GeocacheBatchLogForm(this, Core, client))
                                {
                                    dlg.ShowDialog();
                                }
                            }
                            else if (action == ACTION_GARMINVISIT)
                            {
                                using (GarminGeocacheVisitsLogForm dlg = new GarminGeocacheVisitsLogForm(this, Core, client))
                                {
                                    dlg.ShowDialog();
                                }
                            }
                            else if (action == ACTION_CGEOVISIT)
                            {
                                using (CGeoGeocacheVisitsLogForm dlg = new CGeoGeocacheVisitsLogForm(this, Core, client))
                                {
                                    dlg.ShowDialog();
                                }
                            }
                            else if (action == ACTION_OFFLINE)
                            {
                                using (OfflineLogForm dlg = new OfflineLogForm(this, Core, client))
                                {
                                    dlg.ShowDialog();
                                }
                            }
                        }
                    }
                }
                catch
                {
                    System.Windows.Forms.MessageBox.Show(Utils.LanguageSupport.Instance.GetTranslation(STR_UNABLEACCESSAPI), Utils.LanguageSupport.Instance.GetTranslation(STR_ERROR), System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error);
                }
            }
            return(result);
        }
 private void button3_Click(object sender, EventArgs e)
 {
     WaypointListItem wpi = listBox1.SelectedItem as WaypointListItem;
     if (wpi != null)
     {
         if (wpi.WP.ID <= 0)
         {
             listBox1.Items.Remove(wpi);
             button1.Enabled = true;
         }
         else
         {
             if (Utils.API.GeocachingLiveV6.CheckAPIAccessAvailable(Core, true))
             {
                 try
                 {
                     Utils.API.LiveV6.StatusResponse resp = null;
                     Cursor = Cursors.WaitCursor;
                     try
                     {
                         using (Utils.API.GeocachingLiveV6 api = new Utils.API.GeocachingLiveV6(Core))
                         {
                             resp = api.Client.DeleteUserWaypoint(api.Token, wpi.WP.ID);
                         }
                     }
                     finally
                     {
                         Cursor = Cursors.Default;
                     }
                     if (resp != null)
                     {
                         if (resp.StatusCode == 0)
                         {
                             Core.UserWaypoints.Remove(wpi.WP);
                         }
                         else
                         {
                             MessageBox.Show(resp.StatusMessage ?? "", Utils.LanguageSupport.Instance.GetTranslation(STR_ERROR));
                         }
                     }
                     else
                     {
                         MessageBox.Show(Utils.LanguageSupport.Instance.GetTranslation(STR_FAILED), Utils.LanguageSupport.Instance.GetTranslation(STR_ERROR));
                     }
                 }
                 catch
                 {
                     MessageBox.Show(Utils.LanguageSupport.Instance.GetTranslation(STR_FAILED), Utils.LanguageSupport.Instance.GetTranslation(STR_ERROR));
                 }
             }
         }
     }
 }