示例#1
0
        private void logThreadMethod()
        {
            try
            {
                _context.Send(new SendOrPostCallback(delegate(object state)
                {
                    toolStripStatusLabel1.Visible = true;
                    toolStripStatusLabel1.Text    = _gc.Code;
                }), null);

                var req = new Utils.API.LiveV6.CreateFieldNoteAndPublishRequest();
                req.AccessToken       = _client.Token;
                req.CacheCode         = _gc.Code;
                req.EncryptLogText    = false;
                req.FavoriteThisCache = _addToFavorites;
                req.Note          = _logText;
                req.PromoteToLog  = true;
                req.WptLogTypeId  = _logType.ID;
                req.UTCDateLogged = _logDate.AddHours(12).ToUniversalTime();
                var resp = _client.Client.CreateFieldNoteAndPublish(req);
                if (resp.Status.StatusCode == 0)
                {
                    if (Utils.DataAccess.GetGeocache(_core.Geocaches, _gc.Code) != null)
                    {
                        //add log tot database
                        //if found, update cache as found
                        if (_logType.AsFound)
                        {
                            _gc.Found = true;
                        }
                        _core.Logs.Add(Utils.API.Convert.Log(_core, resp.Log));
                        _gc.ResetCachedLogData();
                    }

                    //log the trackables
                    if (_tbTrackingNumbers.Count > 0)
                    {
                        List <Utils.API.LiveV6.Trackable> tb = new List <Utils.API.LiveV6.Trackable>();
                        foreach (string t in _tbs14)
                        {
                            tb.Add((Utils.API.LiveV6.Trackable)_tbTrackingNumbers[t]);
                        }
                        logTrackables(tb, 14);

                        if (string.IsNullOrEmpty(_errormessage))
                        {
                            tb = new List <Utils.API.LiveV6.Trackable>();
                            foreach (string t in _tbs75)
                            {
                                tb.Add((Utils.API.LiveV6.Trackable)_tbTrackingNumbers[t]);
                            }
                            logTrackables(tb, 75);
                        }
                    }

                    //add the images to the logs
                    foreach (LogImage li in _logImages)
                    {
                        var uplReq = new Utils.API.LiveV6.UploadImageToGeocacheLogRequest();
                        uplReq.AccessToken               = _client.Token;
                        uplReq.LogGuid                   = resp.Log.Guid;
                        uplReq.ImageData                 = new Utils.API.LiveV6.UploadImageData();
                        uplReq.ImageData.FileCaption     = li.Caption;
                        uplReq.ImageData.FileDescription = li.Description;
                        uplReq.ImageData.FileName        = li.FileName;
                        uplReq.ImageData.base64ImageData = System.Convert.ToBase64String(System.IO.File.ReadAllBytes(li.imgFile.Path));
                        var resp2 = _client.Client.UploadImageToGeocacheLog(uplReq);
                        if (resp2.Status.StatusCode != 0)
                        {
                            _errormessage = resp.Status.StatusMessage;
                            break;
                        }
                    }

                    //check favorite
                    if (_addToFavorites)
                    {
                        //not critical
                        try
                        {
                            Framework.Interfaces.IPlugin p = Utils.PluginSupport.PluginByName(_core, "GlobalcachingApplication.Plugins.APIFavorites.EditFavorites");
                            if (p != null)
                            {
                                MethodInfo mi = p.GetType().GetMethod("AddToFavorites");
                                if (mi != null)
                                {
                                    mi.Invoke(p, new object[] { _gc.Code });
                                }
                            }
                        }
                        catch
                        {
                        }
                    }
                }
                else
                {
                    _errormessage = resp.Status.StatusMessage;
                }
            }
            catch (Exception e)
            {
                _errormessage = e.Message;
            }
        }
示例#2
0
        private void logThreadMethod()
        {
            try
            {
                _context.Send(new SendOrPostCallback(delegate(object state)
                {
                    toolStripStatusLabel1.Visible = true;
                    toolStripStatusLabel1.Text = _gc.Code;
                }), null);

                var req = new Utils.API.LiveV6.CreateFieldNoteAndPublishRequest();
                req.AccessToken = _client.Token;
                req.CacheCode = _gc.Code;
                req.EncryptLogText = false;
                req.FavoriteThisCache = _addToFavorites;
                req.Note = _logText;
                req.PromoteToLog = true;
                req.WptLogTypeId = _logType.ID;
                req.UTCDateLogged = _logDate.AddHours(12).ToUniversalTime();
                var resp = _client.Client.CreateFieldNoteAndPublish(req);
                if (resp.Status.StatusCode == 0)
                {
                    if (Utils.DataAccess.GetGeocache(_core.Geocaches, _gc.Code) != null)
                    {
                        //add log tot database
                        //if found, update cache as found
                        if (_logType.AsFound)
                        {
                            _gc.Found = true;
                        }
                        _core.Logs.Add(Utils.API.Convert.Log(_core, resp.Log));
                        _gc.ResetCachedLogData();
                    }

                    //log the trackables
                    if (_tbTrackingNumbers.Count > 0)
                    {
                        List<Utils.API.LiveV6.Trackable> tb = new List<Utils.API.LiveV6.Trackable>();
                        foreach (string t in _tbs14)
                        {
                            tb.Add((Utils.API.LiveV6.Trackable)_tbTrackingNumbers[t]);
                        }
                        logTrackables(tb, 14);

                        if (string.IsNullOrEmpty(_errormessage))
                        {
                            tb = new List<Utils.API.LiveV6.Trackable>();
                            foreach (string t in _tbs75)
                            {
                                tb.Add((Utils.API.LiveV6.Trackable)_tbTrackingNumbers[t]);
                            }
                            logTrackables(tb, 75);
                        }
                    }

                    //add the images to the logs
                    foreach (LogImage li in _logImages)
                    {
                        var uplReq = new Utils.API.LiveV6.UploadImageToGeocacheLogRequest();
                        uplReq.AccessToken = _client.Token;
                        uplReq.LogGuid = resp.Log.Guid;
                        uplReq.ImageData = new Utils.API.LiveV6.UploadImageData();
                        uplReq.ImageData.FileCaption = li.Caption;
                        uplReq.ImageData.FileDescription = li.Description;
                        uplReq.ImageData.FileName = li.FileName;
                        uplReq.ImageData.base64ImageData = System.Convert.ToBase64String(System.IO.File.ReadAllBytes(li.imgFile.Path));
                        var resp2 = _client.Client.UploadImageToGeocacheLog(uplReq);
                        if (resp2.Status.StatusCode != 0)
                        {
                            _errormessage = resp.Status.StatusMessage;
                            break;
                        }
                    }

                    //check favorite
                    if (_addToFavorites)
                    {
                        //not critical
                        try
                        {
                            Framework.Interfaces.IPlugin p = Utils.PluginSupport.PluginByName(_core, "GlobalcachingApplication.Plugins.APIFavorites.EditFavorites");
                            if (p != null)
                            {
                                MethodInfo mi = p.GetType().GetMethod("AddToFavorites");
                                if (mi != null)
                                {
                                    mi.Invoke(p, new object[] { _gc.Code });
                                }
                            }
                        }
                        catch
                        {
                        }

                    }

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