示例#1
0
        public async Task <bool> Send()
        {
            if (String.IsNullOrWhiteSpace(Message))
            {
                return(false);
            }

            var json = new FeedbackJson()
            {
                Subject  = "-- Toggl Mobile Feedback",
                IsMobile = true,
            };

            var sb = new StringBuilder();

            sb.AppendLine();
            sb.AppendLine(Message);
            sb.AppendLine();
            sb.AppendLine("――――");
            sb.AppendLine();

            AppendMood(sb);
            AppendTimeInfo(sb);
            await AppendTimeEntryStats(sb).ConfigureAwait(false);

            var client   = ServiceContainer.Resolve <ITogglClient> ();
            var logStore = ServiceContainer.Resolve <LogStore> ();

            try {
                json.Message        = sb.ToString();
                json.AttachmentData = await logStore.Compress().ConfigureAwait(false);

                if (json.AttachmentData != null)
                {
                    json.AttachmentName = "log.gz";
                }

                await client.CreateFeedback(json).ConfigureAwait(false);
            } catch (Exception ex) {
                var log = ServiceContainer.Resolve <ILogger> ();
                if (ex.IsNetworkFailure())
                {
                    log.Info(Tag, ex, "Failed to send feedback.");
                }
                else
                {
                    log.Warning(Tag, ex, "Failed to send feedback.");
                }
                return(false);
            }

            return(true);
        }
示例#2
0
        public async Task CreateFeedback (FeedbackJson jsonObject)
        {
            var url = new Uri (v8Url, "feedback");

            jsonObject.AppVersion = String.Format ("{0}/{1}", Platform.AppIdentifier, Platform.AppVersion);
            jsonObject.Timestamp = Time.Now;

            var json = JsonConvert.SerializeObject (jsonObject);
            var httpReq = SetupRequest (new HttpRequestMessage () {
                Method = HttpMethod.Post,
                RequestUri = url,
                Content = new StringContent (json, Encoding.UTF8, "application/json"),
            });
            await SendAsync (httpReq).ConfigureAwait (false);
        }