public async Task <BloodRequest> GetAsync(Guid id)
        {
            var db     = _connectionMultiplexer.GetDatabase();
            var result = await db.JsonGetAsync <BloodRequest>(RedisConstants.GetBloodRequestPersistenceKey(id));

            return(result);
        }
Ejemplo n.º 2
0
        public override async Task OnDisconnectedAsync(Exception exception)
        {
            var spoolerId = GetSpoolerId();
            var db        = _redis.GetDatabase();
            await db.HashDeleteAsync(RedisConstants.ConnectedClients, spoolerId);

            await db.HashSetAsync(RedisConstants.SpoolerDetails(spoolerId), "last-disconnected", DateTime.UtcNow.ToString("o", CultureInfo.InvariantCulture));

            await base.OnDisconnectedAsync(exception);
        }
Ejemplo n.º 3
0
        public async Task SpoolPendingJobs()
        {
            var spoolerId = GetSpoolerId();

            _logger.LogInformation("Spooler {SpoolerId} is requesting to spool its pending jobs.", spoolerId);

            _printJobProcessor.QueuePendingJobs(spoolerId);
            var db = _redis.GetDatabase();
            await db.HashSetAsync(RedisConstants.SpoolerDetails(spoolerId), "last-job-spooled", DateTime.UtcNow.ToString("o", CultureInfo.InvariantCulture));
        }
Ejemplo n.º 4
0
        public override async Task OnConnectedAsync()
        {
            await base.OnConnectedAsync();

            var spoolerId = GetSpoolerId();
            var db        = _redis.GetDatabase();
            await db.HashSetAsync(RedisConstants.ConnectedClients, spoolerId, Context.ConnectionId);

            await db.HashSetAsync(RedisConstants.SpoolerDetails(spoolerId), "last-connected", DateTime.UtcNow.ToString("o", CultureInfo.InvariantCulture));
        }
Ejemplo n.º 5
0
 public async Task Hello(string version)
 {
     var spoolerId = GetSpoolerId();
     var db        = _redis.GetDatabase();
     var entries   = new HashEntry[]
     {
         new HashEntry("last-hello-received", DateTime.UtcNow.ToString("o", CultureInfo.InvariantCulture)),
         new HashEntry("print-spooler-app-version", version)
     };
     await db.HashSetAsync(RedisConstants.SpoolerDetails(spoolerId), entries);
 }
        public async Task <bool> UpdateRequestStatus(Guid id, OpenIdKey openIdKey, DetailedStatusList status)
        {
            var db = _connectionMultiplexer.GetDatabase();
            await db.JsonSetAsync(RedisConstants.GetBloodRequestPersistenceKey(id), JsonSerializer.Serialize(status, _jsonSerializerOptions), ".Status");

            var path = status switch
            {
                DetailedStatusList.Assigned => ".AssignedBy",
                DetailedStatusList.Cancelled => ".CancelledBy",
                _ => ".ActionBy",
            };
            var result = await db.JsonSetAsync(RedisConstants.GetBloodRequestPersistenceKey(id), JsonSerializer.Serialize(openIdKey.GetPersistenceKey(), _jsonSerializerOptions), path);

            return(result.IsSuccess);
        }
Ejemplo n.º 7
0
            public override async Task <ActionResult> HandleAsync(Command request, CancellationToken cancellationToken)
            {
                var projectId = User.GetProjectId();

                if (!await _db.Spoolers.AnyAsync(x => x.Zone.ProjectId == projectId && x.Id == request.SpoolerId))
                {
                    return(NotFound());
                }

                var db         = _redis.GetDatabase();
                var subscriber = _redis.GetSubscriber();
                var key        = RedisConstants.InstalledPrinters(request.SpoolerId);
                var multi      = db.CreateTransaction();

                _ = multi.KeyDeleteAsync(key, CommandFlags.FireAndForget);
                _ = multi.SetAddAsync(key, request.PrinterNames.Select(x => (RedisValue)x).ToArray(), CommandFlags.FireAndForget);
                await multi.ExecuteAsync();

                await subscriber.PublishAsync(RedisConstants.Channels.InstalledPrintersRefreshed(request.SpoolerId), string.Empty);

                return(Ok());
            }
Ejemplo n.º 8
0
        public static async Task GetPrintersAsync(Spooler spooler, IDatabase db)
        {
            var batch = db.CreateBatch();

            var isOnlineTask = batch.HashExistsAsync(RedisConstants.ConnectedClients, spooler.Id);
            var detailsTask  = batch.HashGetAllAsync(RedisConstants.SpoolerDetails(spooler.Id));
            var printersTask = batch.SetMembersAsync(RedisConstants.InstalledPrinters(spooler.Id));

            batch.Execute();

            var isOnline = await isOnlineTask;
            var details  = (await detailsTask).ToStringDictionary();
            var printers = await printersTask;

            spooler.IsOnline               = isOnline;
            spooler.LastConnected          = GetDateTimeOrNull(details.GetValueOrDefault("last-connected"));
            spooler.LastDisconnected       = GetDateTimeOrNull(details.GetValueOrDefault("last-disconnected"));
            spooler.LastHelloReceived      = GetDateTimeOrNull(details.GetValueOrDefault("last-hello-received"));
            spooler.LastHeartbeatReceived  = GetDateTimeOrNull(details.GetValueOrDefault("last-heartbeat-received"));
            spooler.LastJobSpooled         = GetDateTimeOrNull(details.GetValueOrDefault("last-job-spooled"));
            spooler.PrintSpoolerAppVersion = details.GetValueOrDefault("print-spooler-app-version");

            spooler.Printers = printers.Select(x => (string)x).ToArray();
        }
Ejemplo n.º 9
0
 public async Task Heartbeat()
 {
     var spoolerId = GetSpoolerId();
     var db        = _redis.GetDatabase();
     await db.HashSetAsync(RedisConstants.SpoolerDetails(spoolerId), "last-heartbeat-received", DateTime.UtcNow.ToString("o", CultureInfo.InvariantCulture));
 }
Ejemplo n.º 10
0
        public async Task <List <BloodRequestSearchRecordDto> > GetSearchResultsFromDbAsync(string searchString)
        {
            var          requests     = new List <BloodRequestSearchRecordDto>();
            SearchResult?searchResult = null;

            try
            {
                searchResult = await _redisSearchClient.SearchAsync(new Query(searchString) { WithPayloads = true });

                _logger.LogInformation("search result: {info}", searchResult);
            }
            catch (Exception ex)
            {
                _logger.LogError(ex, "Redis Search for Blood Requests");
            }

            if (searchResult == null)
            {
                return(requests);
            }

            var db     = _connectionMultiplexer.GetDatabase();
            var result = await db.JsonMultiGetAsync <BloodRequest>(searchResult.Documents.Select(q => new RedisKey(RedisConstants.GetBloodRequestPersistenceKey(q.Id))).ToArray());

            var filteredResult = result.Where(q => q.Status is DetailedStatusList.Open or DetailedStatusList.Assigned)
                                 .Select(q => new BloodRequestSearchRecordDto()
            {
                Status          = q.Status.GetDescription(),
                RequestId       = q.Id,
                PatientName     = q.PatientName,
                Reason          = q.Reason,
                BloodGroup      = q.BloodGroup.GetDescription(),
                DonationType    = q.DonationType.GetDescription(),
                Priority        = q.Priority.GetDescription(),
                QuantityInUnits = q.QuantityInUnits
            });

            requests.AddRange(filteredResult);
            return(requests);
        }
Ejemplo n.º 11
0
        public Task <RedisResponse> ExecuteAsync(string command, params object[] args)
        {
            var request = ComposeRequest(RedisConstants.SerializeCommandName(command), Serialize(args));

            return(_channel.ExecuteRedisCommand(request));
        }