Exemple #1
0
        /// <summary>
        /// Gets the deployment asynchronous.
        /// </summary>
        /// <param name="readAccessToken">The read access token.</param>
        /// <param name="deploymentID">The deployment identifier.</param>
        /// <returns></returns>
        public async Task <DeployResponse> GetDeploymentAsync(string readAccessToken, string deploymentID)
        {
            Assumption.AssertNotNullOrWhiteSpace(readAccessToken, nameof(readAccessToken));
            Assumption.AssertNotNullOrWhiteSpace(deploymentID, nameof(deploymentID));

            using (var httpClient = this.BuildWebClient())
            {
                var uri = new Uri(
                    this.Config.EndPoint
                    + RollbarClient.deployApiPath + deploymentID + @"/"
                    + $"?access_token={readAccessToken}"
                    );

                var httpResponse = await httpClient.GetAsync(uri);

                DeployResponse response = null;
                if (httpResponse.IsSuccessStatusCode)
                {
                    string reply = await httpResponse.Content.ReadAsStringAsync();

                    response = JsonConvert.DeserializeObject <DeployResponse>(reply);
                }
                else
                {
                    httpResponse.EnsureSuccessStatusCode();
                }

                return(response);
            }
        }
Exemple #2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="RollbarConfig"/> class.
        /// </summary>
        /// <param name="accessToken">The access token.</param>
        public RollbarConfig(string accessToken)
        {
            Assumption.AssertNotNullOrWhiteSpace(accessToken, nameof(accessToken));

            this.AccessToken = accessToken;

            // let's set some default values:
            this.Environment         = "production";
            this.Enabled             = true;
            this.MaxReportsPerMinute = 60;
            this.ReportingQueueDepth = 20;
            this.LogLevel            = ErrorLevel.Debug;
            this.ScrubFields         = new[]
            {
                "passwd",
                "password",
                "secret",
                "confirm_password",
                "password_confirmation",
            };
            this.EndPoint     = "https://api.rollbar.com/api/1/";
            this.ProxyAddress = null;
            this.CheckIgnore  = null;
            this.Transform    = null;
            this.Truncate     = null;
            this.Server       = null;
            this.Person       = null;
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="RollbarConfig"/> class.
        /// </summary>
        /// <param name="accessToken">The access token.</param>
        public RollbarConfig(string accessToken)
        {
            Assumption.AssertNotNullOrWhiteSpace(accessToken, nameof(accessToken));

            this.SetDefaults();
            this.AccessToken = accessToken;
        }
Exemple #4
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Body"/> class.
        /// </summary>
        /// <param name="crashReport">The crash report.</param>
        public Body(string crashReport)
        {
            Assumption.AssertNotNullOrWhiteSpace(crashReport, nameof(crashReport));

            this.CrashReport = new CrashReport(crashReport);
            Validate();
        }
Exemple #5
0
        /// <summary>
        /// Gets the deployments asynchronous.
        /// </summary>
        /// <param name="readAccessToken">The read access token.</param>
        /// <param name="pageNumber">The page number.</param>
        /// <returns></returns>
        public async Task <DeploysPageResponse> GetDeploymentsAsync(string readAccessToken, int pageNumber = 1)
        {
            Assumption.AssertNotNullOrWhiteSpace(readAccessToken, nameof(readAccessToken));

            var uri = new Uri(
                this._config.EndPoint
                + RollbarDeployClient.deploysQueryApiPath
                + $"?access_token={readAccessToken}&page={pageNumber}"
                );

            var httpClient   = ProvideHttpClient();
            var httpResponse = await httpClient.GetAsync(uri);

            DeploysPageResponse response = null;

            if (httpResponse.IsSuccessStatusCode)
            {
                string reply = await httpResponse.Content.ReadAsStringAsync();

                response = JsonConvert.DeserializeObject <DeploysPageResponse>(reply);
            }
            else
            {
                httpResponse.EnsureSuccessStatusCode();
            }

            this.Release(httpClient);

            return(response);
        }
Exemple #6
0
        /// <summary>
        /// Validates this instance.
        /// </summary>
        public override void Validate()
        {
            Assumption.AssertNotNullOrWhiteSpace(this.AccessToken, nameof(this.AccessToken));
            Assumption.AssertNotNull(this.Data, nameof(this.Data));

            this.Data.Validate();
        }
Exemple #7
0
        private static ExtendableDtoMetadata Build(Type extendableDtoType)
        {
            Assumption.AssertNotNull(extendableDtoType, nameof(extendableDtoType));

            ExtendableDtoMetadata result = new ExtendableDtoMetadata();

            result.ExtendableDtoType = extendableDtoType;

            List <Type> reservedPropertiesNestedTypes = new List <Type>();
            Type        extendableDtoHierarchyType    = extendableDtoType;

            while (extendableDtoHierarchyType != null)
            {
                Type reservedPropertiesNestedType = ReflectionUtility.GetNestedTypeByName(
                    extendableDtoHierarchyType,
                    ExtendableDtoBase.reservedPropertiesNestedTypeName,
                    BindingFlags.Public | BindingFlags.Static
                    );
                if (reservedPropertiesNestedType != null)
                {
                    reservedPropertiesNestedTypes.Add(reservedPropertiesNestedType);
                }
                if (extendableDtoHierarchyType.BaseType == typeof(ExtendableDtoBase))
                {
                    break;
                }
                if (extendableDtoHierarchyType.BaseType != null)
                {
                    extendableDtoHierarchyType = extendableDtoHierarchyType.BaseType;
                }
            }

            List <FieldInfo> reservedAttributes = new List <FieldInfo>();

            foreach (Type reservedPropertiesNestedType in reservedPropertiesNestedTypes)
            {
                reservedAttributes.AddRange(
                    ReflectionUtility.GetAllPublicStaticFields(reservedPropertiesNestedType)
                    );
            }

            Dictionary <string, PropertyInfo> reservedPropertyInfoByName =
                new Dictionary <string, PropertyInfo>(reservedAttributes.Count);

            result.ReservedPropertyInfoByReservedKey = reservedPropertyInfoByName;

            foreach (var reservedAttribue in reservedAttributes)
            {
                var property =
                    extendableDtoType.GetProperty(reservedAttribue.Name, BindingFlags.Public | BindingFlags.Instance | BindingFlags.FlattenHierarchy);
                Assumption.AssertNotNull(property, nameof(property));

                string reservedKey = ReflectionUtility.GetStaticFieldValue <string>(reservedAttribue);
                Assumption.AssertNotNullOrWhiteSpace(reservedKey, nameof(reservedKey));

                reservedPropertyInfoByName.Add(reservedKey, property);
            }

            return(result);
        }
Exemple #8
0
        /// <summary>
        /// Creates the Json object.
        /// </summary>
        /// <param name="jsonData">The json data.</param>
        /// <returns>JObject.</returns>
        public static JObject CreateJsonObject(string jsonData)
        {
            Assumption.AssertNotNullOrWhiteSpace(jsonData, nameof(jsonData));

            JObject json = JObject.Parse(jsonData);

            return(json);
        }
        /// <summary>
        /// post as json as an asynchronous operation.
        /// </summary>
        /// <param name="accessToken">The access token.</param>
        /// <param name="jsonContent">Content of the json.</param>
        /// <param name="cancellationToken">The cancellation token.</param>
        /// <returns>Task&lt;RollbarResponse&gt;.</returns>
        private async Task <RollbarResponse> PostAsJsonAsync(
            string accessToken,
            StringContent jsonContent,
            CancellationToken cancellationToken
            )
        {
            Assumption.AssertNotNullOrWhiteSpace(accessToken, nameof(accessToken));
            Assumption.AssertNotNull(jsonContent, nameof(jsonContent));

            // build an HTTP request:
            HttpRequestMessage request           = new HttpRequestMessage(HttpMethod.Post, this._payloadPostUri);
            const string       accessTokenHeader = "X-Rollbar-Access-Token";

            request.Headers.Add(accessTokenHeader, accessToken);
            request.Content = jsonContent;

            // send the request:
            HttpResponseMessage postResponse = null;
            RollbarResponse     response     = null;

            try
            {
                postResponse = await this._httpClient.SendAsync(request, cancellationToken);

                if (postResponse.IsSuccessStatusCode)
                {
                    string reply =
                        await postResponse.Content.ReadAsStringAsync();

                    response =
                        JsonConvert.DeserializeObject <RollbarResponse>(reply);
                    response.RollbarRateLimit =
                        new RollbarRateLimit(postResponse.Headers);
                    response.HttpDetails =
                        $"Response: {postResponse}"
                        + Environment.NewLine
                        + $"Request: {postResponse.RequestMessage}"
                        + Environment.NewLine
                    ;
                }
                else
                {
                    postResponse.EnsureSuccessStatusCode();
                }
            }
            catch (System.Exception ex)
            {
                ExceptionDispatchInfo.Capture(ex).Throw();  // we are waiting outside of this method...
            }
            finally
            {
                postResponse?.Dispose();
            }

            return(response);
        }
Exemple #10
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Data"/> class.
        /// </summary>
        /// <param name="environment">The environment.</param>
        /// <param name="body">The body.</param>
        public Data(string environment, Body body)
        {
            Assumption.AssertNotNullOrWhiteSpace(environment, nameof(environment));
            Assumption.AssertNotNull(body, nameof(body));

            Environment = environment;
            Body        = body;
            Timestamp   = (long)DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1)).TotalSeconds;
            Platform    = DefaultPlatform;
            Language    = DefaultLanguage;
        }
Exemple #11
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Payload" /> class.
        /// </summary>
        /// <param name="accessToken">The access token.</param>
        /// <param name="data">The data.</param>
        public Payload(
            string accessToken,
            Data data
            )
        {
            Assumption.AssertNotNullOrWhiteSpace(accessToken, nameof(accessToken));
            Assumption.AssertNotNull(data, nameof(data));

            AccessToken = accessToken;
            Data        = data;
        }
        /// <summary>
        /// Gets the deployments page asynchronously.
        /// </summary>
        /// <param name="environment">The environment.</param>
        /// <param name="pageNumber">The page number.</param>
        /// <returns></returns>
        public async Task <IDeploymentDetails[]> GetDeploymentsPageAsync(string environment, int pageNumber)
        {
            Assumption.AssertNotNullOrWhiteSpace(this._readAccessToken, nameof(this._readAccessToken));

            var           config        = new RollbarConfig(this._readAccessToken);
            RollbarClient rollbarClient = new RollbarClient(config);

            var result = await rollbarClient.GetDeploymentsAsync(this._readAccessToken, pageNumber);

            return(result.DeploysPage.Deploys);
        }
Exemple #13
0
        /// <summary>
        /// post as json as an asynchronous operation.
        /// </summary>
        /// <param name="destinationUri">The destination URI.</param>
        /// <param name="accessToken">The access token.</param>
        /// <param name="jsonContent">Content of the json.</param>
        /// <returns>Task&lt;RollbarResponse&gt;.</returns>
        public async Task <RollbarResponse> PostAsJsonAsync(string destinationUri, string accessToken, string jsonContent)
        {
            Assumption.AssertNotNullOrWhiteSpace(destinationUri, nameof(destinationUri));
            Assumption.AssertNotNullOrWhiteSpace(accessToken, nameof(accessToken));
            Assumption.AssertNotNullOrWhiteSpace(jsonContent, nameof(jsonContent));

            return(await PostAsJsonAsync(
                       new Uri(destinationUri),
                       accessToken,
                       new StringContent(jsonContent)
                       ));
        }
        /// <summary>
        /// Gets the deployment asynchronously.
        /// </summary>
        /// <param name="deploymentID">The deployment identifier.</param>
        /// <returns></returns>
        public async Task <IDeploymentDetails> GetDeploymentAsync(string deploymentID)
        {
            Assumption.AssertNotNullOrWhiteSpace(deploymentID, nameof(deploymentID));
            Assumption.AssertNotNullOrWhiteSpace(this._readAccessToken, nameof(this._readAccessToken));

            var           config        = new RollbarConfig(this._readAccessToken);
            RollbarClient rollbarClient = new RollbarClient(config);

            var result = await rollbarClient.GetDeploymentAsync(this._readAccessToken, deploymentID);

            return(result.Deploy);
        }
        /// <summary>
        /// Gets the deployments page asynchronously.
        /// </summary>
        /// <param name="environment">The environment.</param>
        /// <param name="pageNumber">The page number.</param>
        /// <returns></returns>
        public async Task <IDeploymentDetails[]?> GetDeploymentsPageAsync(string environment, int pageNumber)
        {
            Assumption.AssertNotNullOrWhiteSpace(this._readAccessToken, nameof(this._readAccessToken));

            var config = new RollbarLoggerConfig(this._readAccessToken);

            using HttpClient httpClient = new();
            RollbarDeployClient rollbarClient = new(config, httpClient);
            var result = await rollbarClient.GetDeploymentsAsync(this._readAccessToken, pageNumber).ConfigureAwait(false);

            return(result?.DeploysPage?.Deploys);
        }
        /// <summary>
        /// Registers the deployment asynchronously.
        /// </summary>
        /// <param name="deployment">The deployment.</param>
        /// <returns></returns>
        public async Task RegisterAsync(IDeployment deployment)
        {
            Assumption.AssertNotNullOrWhiteSpace(this._writeAccessToken, nameof(this._writeAccessToken));

            RollbarDestinationOptions destinationOptions = new(this._writeAccessToken, deployment.Environment);
            var config = new RollbarLoggerConfig();

            config.RollbarDestinationOptions.Reconfigure(destinationOptions);

            using HttpClient httpClient = new();
            RollbarDeployClient rollbarClient = new(config, httpClient);
            await rollbarClient.PostAsync(deployment);
        }
Exemple #17
0
        /// <summary>
        /// Initializes a new instance of the <see cref="RollbarLoggerProvider" /> class.
        /// </summary>
        /// <param name="configuration">The configuration.</param>
        /// <param name="options">The options.</param>
        /// <param name="httpContextAccessor">The HTTP context accessor.</param>
        public RollbarLoggerProvider(
            IConfiguration configuration
            , IOptions <NetPlatformExtensions.RollbarOptions> options
            , IHttpContextAccessor httpContextAccessor
            )
            : base(configuration, options)
        {
            Assumption.AssertNotNull(configuration, nameof(configuration));
            Assumption.AssertNotNull(options, nameof(options));
            Assumption.AssertNotNull(this._rollbarConfig, nameof(this._rollbarConfig));
            Assumption.AssertNotNullOrWhiteSpace(this._rollbarConfig.AccessToken, nameof(this._rollbarConfig.AccessToken));

            this._httpContextAccessor = httpContextAccessor;
        }
        /// <summary>
        /// Registers the deployment asynchronously.
        /// </summary>
        /// <param name="deployment">The deployment.</param>
        /// <returns></returns>
        public async Task RegisterAsync(IDeployment deployment)
        {
            Assumption.AssertNotNullOrWhiteSpace(this._writeAccessToken, nameof(this._writeAccessToken));

            var config =
                new RollbarConfig(this._writeAccessToken)
            {
                Environment = deployment.Environment,
            };

            using HttpClient httpClient = new HttpClient();
            RollbarDeployClient rollbarClient = new RollbarDeployClient(config, httpClient);
            await rollbarClient.PostAsync(deployment);
        }
Exemple #19
0
        /// <summary>
        /// Validates this instance.
        /// </summary>
        public override void Validate()
        {
            Assumption.AssertNotNullOrWhiteSpace(this.Environment, nameof(this.Environment));
            Assumption.AssertNotNull(this.Body, nameof(this.Body));

            this.Body.Validate();

            this.Server?.Validate();
            this.Request?.Validate();
            this.Person?.Validate();
            this.Client?.Validate();

            base.Validate();
        }
Exemple #20
0
        /// <summary>
        /// Posts the specified deployment asynchronously.
        /// </summary>
        /// <param name="deployment">The deployment.</param>
        /// <returns></returns>
        public async Task PostAsync(IDeployment deployment)
        {
            Assumption.AssertNotNull(this._config, nameof(this._config));
            Assumption.AssertNotNullOrWhiteSpace(this._config.AccessToken, nameof(this._config.AccessToken));
            Assumption.AssertFalse(string.IsNullOrWhiteSpace(deployment.Environment) && string.IsNullOrWhiteSpace(this._config.Environment), nameof(deployment.Environment));
            Assumption.AssertNotNullOrWhiteSpace(deployment.Revision, nameof(deployment.Revision));

            Assumption.AssertLessThan(
                deployment.Environment.Length, 256,
                nameof(deployment.Environment.Length)
                );
            Assumption.AssertTrue(
                deployment.LocalUsername == null || deployment.LocalUsername.Length < 256,
                nameof(deployment.LocalUsername)
                );
            Assumption.AssertTrue(
                deployment.Comment == null || StringUtility.CalculateExactEncodingBytes(deployment.Comment, Encoding.UTF8) <= (62 * 1024),
                nameof(deployment.Comment)
                );

            var uri = new Uri(this._config.EndPoint + RollbarDeployClient.deployApiPath);

            var parameters = new Dictionary <string, string> {
                { "access_token", this._config.AccessToken },
                { "environment", (!string.IsNullOrWhiteSpace(deployment.Environment)) ? deployment.Environment : this._config.Environment },
                { "revision", deployment.Revision },
                { "rollbar_username", deployment.RollbarUsername },
                { "local_username", deployment.LocalUsername },
                { "comment", deployment.Comment },
            };

            var httpContent = new FormUrlEncodedContent(parameters);

            var httpClient   = ProvideHttpClient();
            var postResponse = await httpClient.PostAsync(uri, httpContent);

            if (postResponse.IsSuccessStatusCode)
            {
                string reply = await postResponse.Content.ReadAsStringAsync();
            }
            else
            {
                postResponse.EnsureSuccessStatusCode();
            }

            this.Release(httpClient);

            return;
        }
        /// <summary>
        /// Post as json as an asynchronous operation.
        /// </summary>
        /// <param name="accessToken">The access token.</param>
        /// <param name="jsonContent">Content of the json.</param>
        /// <param name="cancellationToken">
        /// The cancellation token that can be used by other objects or threads to receive notice of cancellation.
        /// </param>
        /// <returns>A Task&lt;RollbarResponse&gt; representing the asynchronous operation.</returns>
        public async Task <RollbarResponse?> PostAsJsonAsync(
            string accessToken,
            string jsonContent,
            CancellationToken?cancellationToken = null
            )
        {
            Assumption.AssertNotNullOrWhiteSpace(accessToken, nameof(accessToken));
            Assumption.AssertNotNullOrWhiteSpace(jsonContent, nameof(jsonContent));

            return(await PostAsJsonAsync(
                       accessToken,
                       new StringContent(jsonContent),
                       cancellationToken
                       ));
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="RollbarConfig"/> class.
        /// </summary>
        /// <param name="accessToken">The access token.</param>
        public RollbarConfig(string accessToken)
        {
            Assumption.AssertNotNullOrWhiteSpace(accessToken, nameof(accessToken));

            this.SetDefaults();

            if (!string.IsNullOrWhiteSpace(accessToken))
            {
                this.AccessToken = accessToken;
            }
            else
            {
                // initialize based on application configuration file (if any):
                NetStandard.RollbarConfigUtility.Load(this);
            }
        }
Exemple #23
0
        /// <summary>
        /// Initializes a new instance of the <see cref="RollbarLoggerProvider" /> class.
        /// </summary>
        /// <param name="configuration">The configuration.</param>
        /// <param name="options">The options.</param>
        /// <param name="httpContextAccessor">The HTTP context accessor.</param>
        public RollbarLoggerProvider(
            IConfiguration configuration
            , IOptions <RollbarOptions> options
            , IHttpContextAccessor httpContextAccessor
            )
        {
            Assumption.AssertNotNull(configuration, nameof(configuration));
            Assumption.AssertNotNull(options, nameof(options));

            this._rollbarOptions      = options.Value;
            this._rollbarConfig       = RollbarConfigurationUtil.DeduceRollbarConfig(configuration);
            this._httpContextAccessor = httpContextAccessor;

            Assumption.AssertNotNull(this._rollbarConfig, nameof(this._rollbarConfig));
            Assumption.AssertNotNullOrWhiteSpace(this._rollbarConfig.AccessToken, nameof(this._rollbarConfig.AccessToken));
        }
Exemple #24
0
        /// <summary>
        /// Posts as json.
        /// </summary>
        /// <param name="accessToken">The access token.</param>
        /// <param name="jsonContent">Content of the json.</param>
        /// <returns>System.Nullable&lt;RollbarResponse&gt;.</returns>
        /// <exception cref="System.Net.Http.HttpRequestException">
        /// Preliminary ConnectivityMonitor detected offline status!
        /// </exception>
        public RollbarResponse?PostAsJson(
            string?accessToken,
            string?jsonContent
            )
        {
            Assumption.AssertNotNullOrWhiteSpace(accessToken, nameof(accessToken));
            Assumption.AssertNotNullOrWhiteSpace(jsonContent, nameof(jsonContent));

            if (string.IsNullOrWhiteSpace(accessToken))
            {
                return(null);
            }

            // first, let's run quick Internet availability check
            // to minimize potential timeout of the following JSON POST call:
            if (RollbarConnectivityMonitor.Instance != null &&
                !RollbarConnectivityMonitor.Instance.IsConnectivityOn
                )
            {
                throw new HttpRequestException("Preliminary ConnectivityMonitor detected offline status!");
            }

            using CancellationTokenSource cancellationTokenSource = new();
            var task = this.PostAsJsonAsync(accessToken !, jsonContent !, cancellationTokenSource.Token);

            try
            {
                if (!task.Wait(this._expectedPostToApiTimeout))
                {
                    cancellationTokenSource.Cancel(true);
                }
                return(task.Result);
            }
            catch (System.Exception ex)
            {
                RollbarErrorUtility.Report(
                    null,
                    jsonContent,
                    InternalRollbarError.PayloadPostError,
                    "While PostAsJson((string destinationUri, string accessToken, string jsonContent)...",
                    ex,
                    null
                    );
                return(null);
            }
        }
Exemple #25
0
        /// <summary>
        /// Validates this instance.
        /// </summary>
        public override void Validate()
        {
            Assumption.AssertNotNullOrWhiteSpace(this.Id, nameof(this.Id));
            Assumption.AssertLessThanOrEqual(this.Id.Length, Person.maxIdChars, nameof(this.Id));

            if (this.UserName != null)
            {
                Assumption.AssertLessThanOrEqual(this.UserName.Length, Person.maxUsernameChars, nameof(this.UserName));
            }

            if (this.Email != null)
            {
                Assumption.AssertLessThanOrEqual(this.Email.Length, Person.maxEmailChars, nameof(this.Email));
            }

            base.Validate();
        }
Exemple #26
0
        /// <summary>
        /// post as json as an asynchronous operation.
        /// </summary>
        /// <param name="destinationUri">The destination URI.</param>
        /// <param name="accessToken">The access token.</param>
        /// <param name="jsonContent">Content of the json.</param>
        /// <returns>Task&lt;RollbarResponse&gt;.</returns>
        private async Task <RollbarResponse> PostAsJsonAsync(Uri destinationUri, string accessToken, StringContent jsonContent)
        {
            Assumption.AssertNotNull(destinationUri, nameof(destinationUri));
            Assumption.AssertNotNullOrWhiteSpace(accessToken, nameof(accessToken));
            Assumption.AssertNotNull(jsonContent, nameof(jsonContent));

            // build an HTTP request:
            HttpRequestMessage request           = new HttpRequestMessage(HttpMethod.Post, this._payloadPostUri);
            const string       accessTokenHeader = "X-Rollbar-Access-Token";

            request.Headers.Add(accessTokenHeader, accessToken);
            request.Content = jsonContent;

            // send the request:
            var postResponse = await this._httpClient.SendAsync(request);

            RollbarResponse response = null;

            if (postResponse.IsSuccessStatusCode)
            {
                string reply =
                    await postResponse.Content.ReadAsStringAsync();

                response =
                    JsonConvert.DeserializeObject <RollbarResponse>(reply);
                response.RollbarRateLimit =
                    new RollbarRateLimit(postResponse.Headers);
                response.HttpDetails =
                    $"Response: {postResponse}"
                    + Environment.NewLine
                    + $"Request: {postResponse.RequestMessage}"
                    + Environment.NewLine
                ;
            }
            else
            {
                postResponse.EnsureSuccessStatusCode();
            }

            postResponse.Dispose();

            return(response);
        }
Exemple #27
0
        /// <summary>
        /// Posts as json.
        /// </summary>
        /// <param name="destinationUri">The destination URI.</param>
        /// <param name="accessToken">The access token.</param>
        /// <param name="jsonContent">Content of the json.</param>
        /// <returns>RollbarResponse.</returns>
        public RollbarResponse PostAsJson(string destinationUri, string accessToken, string jsonContent)
        {
            Assumption.AssertNotNullOrWhiteSpace(destinationUri, nameof(destinationUri));
            Assumption.AssertNotNullOrWhiteSpace(accessToken, nameof(accessToken));
            Assumption.AssertNotNullOrWhiteSpace(jsonContent, nameof(jsonContent));

            // first, let's run quick Internet availability check
            // to minimize potential timeout of the following JSON POST call:
            if (!ConnectivityMonitor.Instance.IsConnectivityOn)
            {
                throw new HttpRequestException("Preliminary ConnectivityMonitor detected offline status!");
            }

            var task = this.PostAsJsonAsync(destinationUri, accessToken, jsonContent);

            //task.Wait(expectedPostToApiTimeout);
            task.Wait();

            return(task.Result);
        }
Exemple #28
0
        private static ExtendableDtoMetadata Build(Type extendableDtoType)
        {
            ExtendableDtoMetadata result = new ExtendableDtoMetadata();

            result.ExtendableDtoType = extendableDtoType;

            Type reservedPropertiesNestedType = ReflectionUtil.GetNestedTypeByName(
                extendableDtoType,
                ExtendableDtoBase.reservedPropertiesNestedTypeName,
                BindingFlags.Public | BindingFlags.Static
                );

            Assumption.AssertNotNull(reservedPropertiesNestedType, nameof(reservedPropertiesNestedType));

            var reservedAttributes =
                ReflectionUtil.GetAllPublicStaticFields(reservedPropertiesNestedType);

            Dictionary <string, PropertyInfo> reservedPropertyInfoByName =
                new Dictionary <string, PropertyInfo>(reservedAttributes.Length);

            result.ReservedPropertyInfoByReservedKey = reservedPropertyInfoByName;

            foreach (var reservedAttribue in reservedAttributes)
            {
                var property =
                    extendableDtoType.GetProperty(reservedAttribue.Name, BindingFlags.Public | BindingFlags.Instance);
                Assumption.AssertNotNull(property, nameof(property));

                string reservedKey = ReflectionUtil.GetStaticFieldValue <string>(reservedAttribue);
                Assumption.AssertNotNullOrWhiteSpace(reservedKey, nameof(reservedKey));

                reservedPropertyInfoByName.Add(reservedKey, property);
            }

            return(result);
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="AccessTokenQueuesMetadata"/> class.
        /// </summary>
        /// <param name="accessToken">The access token.</param>
        public AccessTokenQueuesMetadata(string accessToken)
        {
            Assumption.AssertNotNullOrWhiteSpace(accessToken, nameof(accessToken));

            this.AccessToken = accessToken;
        }
Exemple #30
0
 /// <summary>
 /// Validates this instance.
 /// </summary>
 public override void Validate()
 {
     Assumption.AssertNotNullOrWhiteSpace(this.Body, nameof(this.Body));
 }