/// <summary>
        /// Initializes a new instance of the <see cref="RollbarDeploysManager"/> class.
        /// </summary>
        /// <param name="writeAccessToken">The write access token.</param>
        /// <param name="readAccessToken">The read access token.</param>
        public RollbarDeploysManager(string writeAccessToken, string readAccessToken)
        {
            Assumption.AssertFalse(
                string.IsNullOrWhiteSpace(writeAccessToken) && string.IsNullOrWhiteSpace(readAccessToken),
                nameof(writeAccessToken) + "and" + nameof(readAccessToken)
                );

            this._writeAccessToken = writeAccessToken;
            this._readAccessToken  = readAccessToken;
        }
        /// <summary>
        /// Packages as rollbar data.
        /// </summary>
        /// <returns>Rollbar Data DTO or null (if packaging is not applicable in some cases).</returns>
        public virtual Data PackageAsRollbarData()
        {
            this._rollbarData = this.ProduceRollbarData();

            // a packaging strategy decorator is never expected to have its own valid instance of this._rollbarData:
            Assumption.AssertFalse(
                this.GetType().IsSubclassOf(typeof(RollbarPackageDecoratorBase)) &&
                (this._rollbarData != null),
                nameof(this._rollbarData)
                );

            return(this._rollbarData);
        }
Example #3
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;
        }
Example #4
0
        /// <summary>
        /// Initializes the specified configuration.
        /// </summary>
        /// <param name="config">The configuration.</param>
        /// <exception cref="RollbarException">
        /// Exception while initializing the internal services!
        /// </exception>
        public void Init(IRollbarInfrastructureConfig config)
        {
            Assumption.AssertNotNull(config, nameof(config));
            Assumption.AssertNotNull(RollbarInfrastructure.Instance, nameof(RollbarInfrastructure.Instance));
            Assumption.AssertFalse(RollbarInfrastructure.Instance.IsInitialized, nameof(RollbarInfrastructure.Instance.IsInitialized));

            lock (this._syncLock)
            {
                if (this.IsInitialized)
                {
                    string msg = $"{typeof(RollbarInfrastructure).Name} can not be initialized more than once!";
                    traceSource.TraceInformation(msg);
                    throw new RollbarException(
                              InternalRollbarError.InfrastructureError,
                              msg
                              );
                }

                // now, since the basic infrastructure seems to be good and initialized,
                // let's initialize all the dependent services of the infrastructure:
                try
                {
                    this._config = config;
                    this.ValidateConfiguration();
                    this._config.Reconfigured += _config_Reconfigured;
                    this._lazyQueueController.Value.Init(config);
                    this._lazyTelemetryCollector.Value.Init(config.RollbarTelemetryOptions);
                    _ = this._lazyConnectivityMonitor.Value;
                    //Assumption.AssertTrue(RollbarInfrastructure.Instance.IsInitialized, nameof(RollbarInfrastructure.Instance.IsInitialized));
                }
                catch (Exception ex)
                {
                    throw new RollbarException(
                              InternalRollbarError.InfrastructureError,
                              "Exception while initializing the internal services!",
                              ex
                              );
                }
            }
        }
Example #5
0
 public void Release()
 {
     Assumption.AssertFalse(this._isReleased, nameof(this._isReleased));
     this._isReleased = true;
 }