Ejemplo n.º 1
0
        public async Task IncreaseInvisibilityAsync(ProvisioningQueueParentDto message, int invisibleForInSeconds)
        {
            _logger.LogInformation($"Queue: Increasing message invisibility for {message.MessageId} with description \"{message.Description}\" by {invisibleForInSeconds} seconds.");
            var messageAsJson = JsonSerializerUtil.Serialize(message);
            var updateReceipt = await _queueService.UpdateMessageAsync(message.MessageId, message.PopReceipt, messageAsJson, invisibleForInSeconds);
            message.PopReceipt = updateReceipt.PopReceipt;
            message.NextVisibleOn = updateReceipt.NextVisibleOn;
            _logger.LogInformation($"Queue: Message {message.MessageId} will be visible again at {updateReceipt.NextVisibleOn} (UTC)");

        }
Ejemplo n.º 2
0
        public static JsonResponse CreateErrorMessageResult(string requestId, string message, HttpStatusCode statusCode = HttpStatusCode.InternalServerError)
        {
            var content = JsonSerializerUtil.Serialize(new Common.Dto.ErrorResponse
            {
                Message   = message,
                RequestId = requestId
            });

            return(new JsonResponse {
                Content = content, StatusCode = statusCode
            });
        }
Ejemplo n.º 3
0
        public async Task<ProvisioningQueueParentDto> SendMessageAsync(ProvisioningQueueParentDto message, TimeSpan? visibilityTimeout = null, CancellationToken cancellationToken = default)
        {
            _logger.LogInformation($"Queue: Adding message: {message.Description}, having {message.Children.Count} children");
            var serializedMessage = JsonSerializerUtil.Serialize(message);
            var sendtMessage = await _queueService.SendMessageAsync(serializedMessage, visibilityTimeout, cancellationToken);

            message.MessageId = sendtMessage.MessageId;
            message.PopReceipt = sendtMessage.PopReceipt;
            message.NextVisibleOn = sendtMessage.NextVisibleOn;

            return message;

        }
Ejemplo n.º 4
0
        private RedisCache()
        {
            string cacheConfigString = AppContext.CacheConfigString;
            string appUri            = LocationHelper.Instance.GetAppUri(AppNameEnum.RedisSvc);

            cacheConfigString = (string.IsNullOrEmpty(cacheConfigString) ? appUri.Replace("http://", string.Empty).Trim(new char[] { '/' }) : cacheConfigString);
            ConfigurationOptions configurationOption = ConfigurationOptions.Parse(cacheConfigString);

            if (configurationOption.EndPoints.Count == 0)
            {
                configurationOption.EndPoints.Add(appUri);
            }
            this.redis = ConnectionMultiplexer.Connect(configurationOption, null);
            this.db    = this.redis.GetDatabase(-1, null);
            DebugUtil.CollectDebugInfo(JsonSerializerUtil.Serialize <ConfigurationOptions>(configurationOption));
        }
Ejemplo n.º 5
0
        public ICacheResult <T> Set <T>(string key, T value, int expiredTime = 3600)
        {
            CacheResult <T> cacheResult = new CacheResult <T>()
            {
                Success = false,
                Status  = Status.None
            };
            CacheResult <T> cacheResult1 = cacheResult;

            expiredTime = (expiredTime <= 0 ? 3600 : expiredTime);
            try
            {
                string str = JsonSerializerUtil.Serialize <T>(value);
                cacheResult1.Success = this.db.StringSet(KeyGen.AttachPrefixToKey(key), str, new TimeSpan?(new TimeSpan(0, 0, expiredTime)), 0, 0);
                cacheResult1.Status  = Status.Success;
            }
            catch (Exception exception)
            {
                cacheResult1.Exception = exception;
            }
            return(cacheResult1);
        }
        public async Task <AzureRoleAssignment> AddRoleAssignment(string resourceId, string roleDefinitionId, string principalId, string roleAssignmentId = null, CancellationToken cancellationToken = default)
        {
            try
            {
                if (String.IsNullOrWhiteSpace(roleAssignmentId))
                {
                    roleAssignmentId = Guid.NewGuid().ToString();
                }

                var addRoleUrl = $"https://management.azure.com{resourceId}/providers/Microsoft.Authorization/roleAssignments/{roleAssignmentId}?api-version=2015-07-01";

                var body     = new AzureRoleAssignmentRequestDto(roleDefinitionId, principalId);
                var bodyJson = new StringContent(JsonSerializerUtil.Serialize(body), Encoding.UTF8, "application/json");

                var result = await PerformRequest <AzureRoleAssignment>(addRoleUrl, HttpMethod.Put, bodyJson, true, cancellationToken : cancellationToken);

                return(result);
            }
            catch (Exception ex)
            {
                throw new Exception($"Add role assignment with id {roleAssignmentId} failed for resource {resourceId}. Role definition: {roleDefinitionId}, principalId: {principalId}", ex);
            }
        }
Ejemplo n.º 7
0
 public static string TagDictionaryToString(Dictionary <string, string> tags)
 {
     return(JsonSerializerUtil.Serialize(tags));
 }