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

                            if (!progress.UpdateProgress(STR_IMPORTINGCACHES, STR_IMPORTINGCACHES, max, max - gcList.Count))
                            {
                                break;
                            }
                        }
                    }
                }
                catch (Exception e)
                {
                    _errormessage = e.Message;
                }
            }
        }
Exemple #2
0
        private void button3_Click(object sender, EventArgs e)
        {
            SiteInfo si = comboBox1.SelectedItem as SiteInfo;

            if (si != null)
            {
                _token        = "";
                _tokenSecret  = "";
                textBox3.Text = Utils.LanguageSupport.Instance.GetTranslation(STR_NO);
                using (KeyRequestForm dlg = new KeyRequestForm(si))
                {
                    dlg.ShowDialog();
                    _tokenSecret = dlg.TokenSecret;
                    _token       = dlg.Token;
                    bool isAuthorized = (!string.IsNullOrEmpty(_tokenSecret) && !string.IsNullOrEmpty(_tokenSecret));
                    textBox3.Text = isAuthorized ? Utils.LanguageSupport.Instance.GetTranslation(STR_YES) : Utils.LanguageSupport.Instance.GetTranslation(STR_NO);
                    if (isAuthorized)
                    {
                        string uuid     = "";
                        string username = "";
                        if (OKAPIService.GetAuthorizedUser(si, _token, _tokenSecret, out username, out uuid))
                        {
                            textBox1.Text = username;
                            textBox2.Text = uuid;
                        }
                    }
                }
            }
        }
Exemple #3
0
        protected override void ImportMethod()
        {
            //for now, we just use the active site
            //howver, in the future it is better to automatically switcg according geocode prefix
            //at this moment, the user is responsible for selecting the geocaches and the active site
            try
            {
                //first get a list of geocache codes
                using (Utils.ProgressBlock progress = new Utils.ProgressBlock(this, STR_UPDATINGGEOCACHES, STR_UPDATINGGEOCACHES, _gcList.Count, 0, true))
                {
                    int gcupdatecount = 1;
                    int max           = _gcList.Count;
                    while (_gcList.Count > 0)
                    {
                        List <string> lcs = (from Framework.Data.Geocache g in _gcList select g.Code).Take(gcupdatecount).ToList();
                        _gcList.RemoveRange(0, lcs.Count);
                        List <OKAPIService.Geocache> caches = OKAPIService.GetGeocaches(SiteManager.Instance.ActiveSite, lcs);
                        Import.AddGeocaches(Core, caches);

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

                        if (!progress.UpdateProgress(STR_IMPORTINGCACHES, STR_IMPORTINGCACHES, max, max - _gcList.Count))
                        {
                            break;
                        }
                    }
                }
            }
            catch (Exception e)
            {
                _errormessage = e.Message;
            }
        }
Exemple #5
0
        private void button1_Click(object sender, EventArgs e)
        {
            SiteInfo si = comboBox1.SelectedItem as SiteInfo;

            if (si != null)
            {
                textBox2.Text = "";
                Cursor        = Cursors.WaitCursor;
                try
                {
                    string username = textBox1.Text;
                    string userid   = OKAPIService.GetUserID(si, ref username);
                    textBox1.Text = username;
                    textBox2.Text = userid;
                }
                catch
                {
                }
                Cursor = Cursors.Default;
            }
        }
Exemple #6
0
        public static Framework.Data.Geocache Geocache(Framework.Interfaces.ICore core, OKAPIService.Geocache gc)
        {
            Framework.Data.Geocache result = null;
            if (gc != null)
            {
                Framework.Data.Geocache tmp = Utils.DataAccess.GetGeocache(core.Geocaches, gc.code);
                result = new Framework.Data.Geocache();
                if (tmp != null)
                {
                    result.UpdateFrom(tmp, null);
                }
                result.DataFromDate = DateTime.Now;
                result.Code         = gc.code;
                result.ID           = gc.code;
                result.Archived     = gc.status == "Archived";
                result.Available    = gc.status == "Available";

                List <int> attris = new List <int>();
                foreach (string at in gc.attr_acodes)
                {
                    int code = OKAPIService.MapAttributeACodeToAttributeID(at);
                    if (code > 0)
                    {
                        attris.Add(code);
                    }
                }
                result.AttributeIds = attris;

                // 'none', 'nano', 'micro', 'small', 'regular', 'large', 'xlarge', 'other'
                // we chose to map the containers
                if (gc.size2 == "none")
                {
                    result.Container = Utils.DataAccess.GetGeocacheContainer(core.GeocacheContainers, 5);
                }
                else if (gc.size2 == "micro" || gc.size2 == "nano")
                {
                    result.Container = Utils.DataAccess.GetGeocacheContainer(core.GeocacheContainers, 2);
                }
                else if (gc.size2 == "small")
                {
                    result.Container = Utils.DataAccess.GetGeocacheContainer(core.GeocacheContainers, 8);
                }
                else if (gc.size2 == "regular")
                {
                    result.Container = Utils.DataAccess.GetGeocacheContainer(core.GeocacheContainers, 3);
                }
                else if (gc.size2 == "large" || gc.size2 == "xlarge")
                {
                    result.Container = Utils.DataAccess.GetGeocacheContainer(core.GeocacheContainers, 4);
                }
                else
                {
                    result.Container = Utils.DataAccess.GetGeocacheContainer(core.GeocacheContainers, 6);
                }
                result.Country      = gc.country ?? "";
                result.Difficulty   = gc.difficulty;
                result.EncodedHints = gc.hint2;
                result.Found        = gc.is_found;
                if (gc.type.ToLower().Contains("traditional"))
                {
                    result.GeocacheType = Utils.DataAccess.GetGeocacheType(core.GeocacheTypes, 96001);
                }
                else if (gc.type.ToLower().Contains("multi"))
                {
                    result.GeocacheType = Utils.DataAccess.GetGeocacheType(core.GeocacheTypes, 96002);
                }
                else if (gc.type.ToLower().Contains("quiz") || gc.type.ToLower().Contains("puzzle"))
                {
                    result.GeocacheType = Utils.DataAccess.GetGeocacheType(core.GeocacheTypes, 96008);
                }
                else if (gc.type.ToLower().Contains("virtual"))
                {
                    result.GeocacheType = Utils.DataAccess.GetGeocacheType(core.GeocacheTypes, 96003);
                }
                else if (gc.type.ToLower().Contains("event"))
                {
                    result.GeocacheType = Utils.DataAccess.GetGeocacheType(core.GeocacheTypes, 96004);
                }
                else if (gc.type.ToLower().Contains("webcam"))
                {
                    result.GeocacheType = Utils.DataAccess.GetGeocacheType(core.GeocacheTypes, 96006);
                }
                else if (gc.type.ToLower().Contains("location") || gc.type.Contains("moving"))
                {
                    result.GeocacheType = Utils.DataAccess.GetGeocacheType(core.GeocacheTypes, 96007);
                }
                else
                {
                    result.GeocacheType = Utils.DataAccess.GetGeocacheType(core.GeocacheTypes, 96005);
                }
                result.Lat                    = Utils.Conversion.StringToDouble(gc.location.Substring(0, gc.location.IndexOf('|')));
                result.Lon                    = Utils.Conversion.StringToDouble(gc.location.Substring(gc.location.IndexOf('|') + 1));
                result.LongDescription        = gc.description;
                result.LongDescriptionInHtml  = true;
                result.Name                   = gc.name;
                result.Owner                  = gc.owner.username;
                result.OwnerId                = gc.owner.uuid;
                result.PlacedBy               = gc.owner.username;
                result.PublishedTime          = DateTime.Parse(gc.date_hidden);
                result.ShortDescription       = "";
                result.ShortDescriptionInHtml = true;
                result.State                  = gc.state ?? "";
                result.Terrain                = gc.terrain;
                result.Url                    = gc.url ?? "";

                Calculus.SetDistanceAndAngleGeocacheFromLocation(result, core.CenterLocation);
            }
            return(result);
        }
Exemple #7
0
        protected override void ImportMethod()
        {
            bool cancelled = false;

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

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

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

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

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

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

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

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