/// <exception cref="IngestionException"/>
        public async Task ExecuteCallAsync(IServiceCall call)
        {
            if (call.CancellationToken.IsCancellationRequested)
            {
                return;
            }
            var baseUrl = string.IsNullOrEmpty(_baseLogUrl) ? DefaultBaseUrl : _baseLogUrl;

            MobileCenterLog.Verbose(MobileCenterLog.LogTag, $"Calling {baseUrl + ApiVersion}...");

            // Create request headers.
            var requestHeaders = CreateHeaders(call.AppSecret, call.InstallId);

            MobileCenterLog.Verbose(MobileCenterLog.LogTag, "Headers: " +
                                    $"{AppSecret}={GetRedactedAppSecret(call.AppSecret)}, " +
                                    $"{InstallId}={call.InstallId}");

            // Create request content.
            var requestContent = CreateLogsContent(call.Logs);

            MobileCenterLog.Verbose(MobileCenterLog.LogTag, requestContent);

            // Send request.
            await _httpNetwork.SendAsync(baseUrl + ApiVersion, HttpMethod.Post, requestHeaders, requestContent, call.CancellationToken).ConfigureAwait(false);
        }
Esempio n. 2
0
        public static void Log(string tag, string message, Exception exception = null, MobileCenterLogType type = MobileCenterLogType.Warn)
        {
            switch (type)
            {
            case MobileCenterLogType.Info:
                MobileCenterLog.Info(tag, message, exception);
                break;

            case MobileCenterLogType.Warn:
                MobileCenterLog.Warn(tag, message, exception);
                break;

            case MobileCenterLogType.Error:
                MobileCenterLog.Error(tag, message, exception);
                break;

            case MobileCenterLogType.Assert:
                MobileCenterLog.Assert(tag, message, exception);
                break;

            case MobileCenterLogType.Verbose:
                MobileCenterLog.Verbose(tag, message, exception);
                break;

            case MobileCenterLogType.Debug:
                MobileCenterLog.Debug(tag, message, exception);
                break;

            default:
                throw new Exception("MobileCenterLogType Does Not Exist");
            }
        }
        internal HttpRequestMessage CreateRequest(string appSecret, Guid installId, string requestContent)
        {
            var baseUrl = string.IsNullOrEmpty(_baseLogUrl) ? DefaultBaseUrl : _baseLogUrl;

            // Create HTTP transport objects
            var request = new HttpRequestMessage
            {
                Method     = HttpMethod.Post,
                RequestUri = new Uri(baseUrl + ApiVersion)
            };

            MobileCenterLog.Verbose(MobileCenterLog.LogTag, $"Calling {request.RequestUri}...");

            // Set Headers
            request.Headers.Add(AppSecret, appSecret);
            request.Headers.Add(InstallId, installId.ToString());

            // Log headers
            var headers = $"Headers: Content-Type={ContentTypeValue}, " +
                          $"{AppSecret}={GetRedactedAppSecret(appSecret)}, " +
                          $"{InstallId}={installId}";

            MobileCenterLog.Verbose(MobileCenterLog.LogTag, headers);

            // Request content
            MobileCenterLog.Verbose(MobileCenterLog.LogTag, requestContent);
            request.Content = new StringContent(requestContent, System.Text.Encoding.UTF8);
            request.Content.Headers.ContentType = System.Net.Http.Headers.MediaTypeHeaderValue.Parse(ContentTypeValue);

            return(request);
        }
Esempio n. 4
0
        /// <exception cref="IngestionException"/>
        public async Task <string> SendAsync(string uri, HttpMethod method, IDictionary <string, string> headers, string jsonContent, CancellationToken cancellationToken)
        {
            using (var request = CreateRequest(uri, method, headers, jsonContent))
                using (var response = await SendRequestAsync(request, cancellationToken).ConfigureAwait(false))
                {
                    if (response == null)
                    {
                        throw new IngestionException("Null response received");
                    }
                    var    responseContent = "(null)";
                    string contentType     = null;
                    if (response.Content != null)
                    {
                        responseContent = await response.Content.ReadAsStringAsync().ConfigureAwait(false);

                        if (response.Content.Headers.TryGetValues("Content-Type", out var contentTypeHeaders))
                        {
                            contentType = contentTypeHeaders.FirstOrDefault();
                        }
                    }
                    string logPayload;
                    if (contentType == null || contentType.StartsWith("text/") || contentType.StartsWith("application/"))
                    {
                        logPayload = responseContent;
                    }
                    else
                    {
                        logPayload = "<binary>";
                    }
                    MobileCenterLog.Verbose(MobileCenterLog.LogTag, $"HTTP response status={(int)response.StatusCode} ({response.StatusCode}) payload={logPayload}");
                    if (response.StatusCode != HttpStatusCode.OK)
                    {
                        throw new HttpIngestionException($"Operation returned an invalid status code '{response.StatusCode}'")
                              {
                                  Method          = request.Method.ToString(),
                                  RequestUri      = request.RequestUri,
                                  StatusCode      = (int)response.StatusCode,
                                  RequestContent  = jsonContent,
                                  ResponseContent = responseContent
                              };
                    }
                    return(responseContent);
                }
        }
Esempio n. 5
0
        public override bool FinishedLaunching(UIApplication application, NSDictionary launchOptions)
        {
            // Override point for customization after application launch.
            // If not required for your application you can safely delete this method

            MobileCenter.LogLevel = LogLevel.Verbose;
            MobileCenter.SetLogUrl("https://in-integration.dev.avalanch.es");
            MobileCenter.Start("b889c4f2-9ac2-4e2e-ae16-dae54f2c5899", typeof(Analytics), typeof(Crashes));
            try
            {
                ThrowAnException();
            }
            catch (Exception e)
            {
                MobileCenterLog.Verbose("THETAG", "THEMESSAGE", e);
            }

            Analytics.Enabled = true;
            System.Diagnostics.Debug.WriteLine("ANALYTICS: " + Analytics.Enabled.ToString());
            return(true);
        }
        /// <exception cref="IngestionException"/>
        public async Task ExecuteCallAsync(IServiceCall call)
        {
            if (call.CancellationToken.IsCancellationRequested)
            {
                return;
            }
            var requestContent = CreateLogsContent(call.Logs);

            using (var request = CreateRequest(call.AppSecret, call.InstallId, requestContent))
                using (var response = await _httpNetwork.SendAsync(request, call.CancellationToken).ConfigureAwait(false))
                {
                    if (response == null)
                    {
                        throw new IngestionException("Null response received");
                    }
                    var responseContent = "(null)";
                    if (response.Content != null)
                    {
                        responseContent = await response.Content.ReadAsStringAsync().ConfigureAwait(false);
                    }
                    MobileCenterLog.Verbose(MobileCenterLog.LogTag, $"HTTP response status={(int)response.StatusCode} ({response.StatusCode}) payload={responseContent}");
                    if (call.CancellationToken.IsCancellationRequested)
                    {
                        return;
                    }
                    if (response.StatusCode != HttpStatusCode.OK)
                    {
                        var ex = new HttpIngestionException($"Operation returned an invalid status code '{response.StatusCode}'")
                        {
                            Method          = request.Method,
                            RequestUri      = request.RequestUri,
                            StatusCode      = response.StatusCode,
                            RequestContent  = requestContent,
                            ResponseContent = responseContent
                        };
                        throw ex;
                    }
                }
        }
Esempio n. 7
0
        public static void Log(Exception exception, MobileCenterLogType type = MobileCenterLogType.Warn)
        {
            var exceptionType = exception.GetType().ToString();
            var message       = exception.Message;

            System.Diagnostics.Debug.WriteLine(exceptionType);
            System.Diagnostics.Debug.WriteLine($"Error: {message}");

            switch (type)
            {
            case MobileCenterLogType.Info:
                MobileCenterLog.Info(exceptionType, message, exception);
                break;

            case MobileCenterLogType.Warn:
                MobileCenterLog.Warn(exceptionType, message, exception);
                break;

            case MobileCenterLogType.Error:
                MobileCenterLog.Error(exceptionType, message, exception);
                break;

            case MobileCenterLogType.Assert:
                MobileCenterLog.Assert(exceptionType, message, exception);
                break;

            case MobileCenterLogType.Verbose:
                MobileCenterLog.Verbose(exceptionType, message, exception);
                break;

            case MobileCenterLogType.Debug:
                MobileCenterLog.Debug(exceptionType, message, exception);
                break;

            default:
                throw new Exception("MobileCenterLogType Does Not Exist");
            }
        }
Esempio n. 8
0
        public override bool FinishedLaunching(UIApplication application, NSDictionary launchOptions)
        {
            // Override point for customization after application launch.
            // If not required for your application you can safely delete this method

            MobileCenter.LogLevel = LogLevel.Verbose;

            MobileCenter.SetServerUrl("http://in-integration.dev.avalanch.es:8081");
            MobileCenter.Start("e7eb534d-58b7-461b-a888-ec250c983e08", typeof(Analytics), typeof(Crashes));

            try
            {
                ThrowAnException();
            }
            catch (Exception e)
            {
                MobileCenterLog.Verbose("THETAG", "THEMESSAGE", e);
            }

            Analytics.Enabled = true;
            System.Diagnostics.Debug.WriteLine("ANALYTICS: " + Analytics.Enabled.ToString());
            return(true);
        }
        public override bool FinishedLaunching(UIApplication application, NSDictionary launchOptions)
        {
            // Override point for customization after application launch.
            // If not required for your application you can safely delete this method

            MobileCenter.LogLevel = LogLevel.Verbose;
            MobileCenter.SetLogUrl("https://in-integration.dev.avalanch.es");
            Distribute.SetInstallUrl("http://install.asgard-int.trafficmanager.net");
            Distribute.SetApiUrl("https://asgard-int.trafficmanager.net/api/v0.1");
            Distribute.DontCheckForUpdatesInDebug();
            MobileCenter.Start("b889c4f2-9ac2-4e2e-ae16-dae54f2c5899", typeof(Analytics), typeof(Crashes), typeof(Distribute));
            try
            {
                ThrowAnException();
            }
            catch (Exception e)
            {
                MobileCenterLog.Verbose("THETAG", "THEMESSAGE", e);
            }

            Analytics.SetEnabledAsync(true);
            System.Diagnostics.Debug.WriteLine("ANALYTICS: " + Analytics.IsEnabledAsync().Result);
            return(true);
        }