Ejemplo n.º 1
0
        public static bool Authorize(Framework.Interfaces.ICore core, bool syncAll)
        {
            bool result = false;

            try
            {
                if (core.RetrieveAPIKey(Framework.Data.APIKey.GeocachingLive))
                {
                    using (GeocachingLiveV6 client = new GeocachingLiveV6(core))
                    {
                        var resp = client.Client.GetYourUserProfile(new LiveV6.GetYourUserProfileRequest()
                        {
                            AccessToken = client.Token,
                            DeviceInfo  = new LiveV6.DeviceData()
                            {
                                DeviceName                 = "GlobalcachingApplication",
                                DeviceUniqueId             = "internal",
                                ApplicationSoftwareVersion = "V1.0.0.0"
                            }
                        });
                        if (resp.Status.StatusCode == 0)
                        {
                            result = true;
                            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 (syncAll)
                            {
                                if (resp.Profile.User.HomeCoordinates != null)
                                {
                                    core.HomeLocation.SetLocation(resp.Profile.User.HomeCoordinates.Latitude, resp.Profile.User.HomeCoordinates.Longitude);
                                }
                            }
                        }
                        else
                        {
                        }
                    }
                }
            }
            catch
            {
            }
            return(result);
        }
Ejemplo n.º 2
0
    private void threadMethod()
    {
        try
        {
            bool cancel = false;
            using (ProgressBlock progress = new ProgressBlock(_plugin, "Bijwerken van status en nieuwe geocaches", "Download gegevens van globalcaching.eu", 1, 0, true))
            {
                using (System.Net.WebClient wc = new System.Net.WebClient())
                {
                    string doc = wc.DownloadString("http://www.globalcaching.eu/Service/GeocacheCodes.aspx?country=Netherlands");
                    if (doc != null)
                    {
                        List<string> gcList = new List<string>();

                        string[] lines = doc.Replace("\r", "").Split(new char[] { '\n' });
                        progress.UpdateProgress("Bijwerken van status en nieuwe geocaches", "Bijwerken van de status...", lines.Length, 0);
                        Geocache gc;
                        char[] sep = new char[] { ',' };
                        string[] parts;
                        foreach (string s in lines)
                        {
                            parts = s.Split(sep);
                            if (parts.Length > 2)
                            {
                                gc = DataAccess.GetGeocache(_core.Geocaches, parts[0]);
                                if (gc != null)
                                {
                                    gc.Archived = parts[1] != "0";
                                    gc.Available = parts[2] != "0";
                                }
                                else if (parts[1] == "0") //add only none archived
                                {
                                    gcList.Add(parts[0]);
                                }
                            }
                        }

                        if (gcList.Count == 0)
                        {
                            System.Windows.Forms.MessageBox.Show("Er zijn geen nieuwe geocaches gevonden", "Bericht", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Information);
                        }
                        else
                        {
                            if (System.Windows.Forms.MessageBox.Show(string.Format("Er zijn {0} nieuwe geocaches gevonden\r\nDeze downloaden?", gcList.Count), "Bericht", System.Windows.Forms.MessageBoxButtons.YesNo, System.Windows.Forms.MessageBoxIcon.Information) == System.Windows.Forms.DialogResult.Yes)
                            {
                                progress.UpdateProgress("Bijwerken van status en nieuwe geocaches", "Importeren van geocaches...", gcList.Count, 0);

                                using (GeocachingLiveV6 client = new GeocachingLiveV6(_core, string.IsNullOrEmpty(_core.GeocachingComAccount.APIToken)))
                                {
                                    int index = 0;
                                    int total = gcList.Count;
                                    int gcupdatecount;
                                    TimeSpan interval = new TimeSpan(0, 0, 0, 2, 100);
                                    DateTime prevCall = DateTime.MinValue;
                                    bool dodelay;
                                    gcupdatecount = 30;
                                    dodelay = (gcList.Count > 30);
                                    while (gcList.Count > 0)
                                    {
                                        if (dodelay)
                                        {
                                            TimeSpan ts = DateTime.Now - prevCall;
                                            if (ts < interval)
                                            {
                                                Thread.Sleep(interval - ts);
                                            }
                                        }
                                        GlobalcachingApplication.Utils.API.LiveV6.SearchForGeocachesRequest req = new GlobalcachingApplication.Utils.API.LiveV6.SearchForGeocachesRequest();
                                        req.IsLite = false;
                                        req.AccessToken = client.Token;
                                        req.CacheCode = new GlobalcachingApplication.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)
                                        {
                                            Import.AddGeocaches(_core, resp.Geocaches);
                                        }
                                        else
                                        {
                                            _errormessage = resp.Status.StatusMessage;
                                            break;
                                        }
                                        if (!progress.UpdateProgress("Bijwerken van status en nieuwe geocaches", "Importeren van geocaches...", total, index))
                                        {
                                            break;
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
        catch(Exception e)
        {
            _errormessage = e.Message;
        }
        _actionReady.Set();
    }
Ejemplo n.º 3
0
 public static bool Authorize(Framework.Interfaces.ICore core, bool syncAll)
 {
     bool result = false;
     try
     {
         if (core.RetrieveAPIKey(Framework.Data.APIKey.GeocachingLive))
         {
             using (GeocachingLiveV6 client = new GeocachingLiveV6(core))
             {
                 LiveV6.GetUserProfileResponse resp = client.Client.GetYourUserProfile(new LiveV6.GetYourUserProfileRequest()
                 {
                     AccessToken = client.Token,
                     DeviceInfo = new LiveV6.DeviceData()
                     {
                         DeviceName = "GlobalcachingApplication",
                         DeviceUniqueId = "internal",
                         ApplicationSoftwareVersion = "V1.0.0.0"
                     }
                 });
                 if (resp.Status.StatusCode == 0)
                 {
                     result = true;
                     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 (syncAll)
                     {
                         if (resp.Profile.User.HomeCoordinates != null)
                         {
                             core.HomeLocation.SetLocation(resp.Profile.User.HomeCoordinates.Latitude, resp.Profile.User.HomeCoordinates.Longitude);
                         }
                     }
                 }
                 else
                 {
                 }
             }
         }
     }
     catch
     {
     }
     return result;
 }