Esempio n. 1
0
        public async Task HandleAsync(TransactionEvent redeemEventMessage, CancellationToken token)
        {
            if (redeemEventMessage.Transaction.Action == TransactionActionType.CashOut)
            {
                await _queueProvider.InsertMessageAsync(
                    new RedeemTransactionMessage(redeemEventMessage.Transaction.Id), token);
            }

            if (redeemEventMessage.Transaction.Action == TransactionActionType.SoldDocument)
            {
                var message = new DocumentPurchasedMessage(redeemEventMessage.Transaction.Id);

                await _queueProvider.InsertMessageAsync(message, token);
            }
        }
        public Task HandleAsync(DocumentCreatedEvent eventMessage, CancellationToken token)
        {
            var doc = new DocumentSearchDto
            {
                UniversityId   = eventMessage.Document.University.Id,
                UniversityName = eventMessage.Document.University.Name,
                Country        = eventMessage.Document.University.Country.ToUpperInvariant(),
                Course         = eventMessage.Document.Course.Id.ToUpperInvariant(),
                DateTime       = eventMessage.Document.TimeStamp.UpdateTime,
                ItemId         = eventMessage.Document.Id,
                Name           = eventMessage.Document.Name,
                Type           = eventMessage.Document.DocumentType.GetValueOrDefault()
            };

            return(_queueProvider.InsertMessageAsync(new DocumentSearchMessage(doc, true), token));
        }
        private async Task GenerateEmailAsync(User user, CancellationToken token)
        {
            TempData[EmailTempDictionaryKey] = user.Email;
            var code = await _userManager.GeneratePasswordResetTokenAsync(user);

            code = UrlEncoder.Default.Encode(code);
            var link    = Url.Link(Controllers.ForgotPasswordController.ResetPasswordRouteName, new { user.Id, code });
            var message = new ResetPasswordEmail(user.Email, link, CultureInfo.CurrentUICulture);
            await _queueProvider.InsertMessageAsync(message, token);
        }
Esempio n. 4
0
        public async Task <ActionResult> DownloadAsync(long id, [FromServices] ICommandBus commandBus,
                                                       [FromServices] IBlobProvider blobProvider2, CancellationToken token)
        {
            var user   = _userManager.GetLongUserId(User);
            var query  = new DocumentById(id, user);
            var tItem  = _queryBus.QueryAsync(query, token);
            var tFiles = _blobProvider.FilesInDirectoryAsync("file-", id.ToString(), token);

            await Task.WhenAll(tItem, tFiles);

            var item = tItem.Result;

            if (item == null)
            {
                return(NotFound());
            }
            if (item.Document.DocumentType == DocumentType.Video)
            {
                return(Unauthorized());
            }
            if (!item.IsPurchased)
            {
                return(Unauthorized());
            }

            var files = tFiles.Result;
            var uri   = files.First();
            var file  = uri.Segments.Last();

            Task followTask = Task.CompletedTask;

            //blob.core.windows.net/spitball-files/files/6160/file-82925b5c-e3ba-4f88-962c-db3244eaf2b2-advanced-linux-programming.pdf
            if (item.Document.User.Id != user)
            {
                var command = new DownloadDocumentCommand(item.Document.Id, user);
                //var command = new FollowUserCommand(item.Document.User.Id, user);
                followTask = commandBus.DispatchAsync(command, token);
            }
            var messageTask = _queueProvider.InsertMessageAsync(new UpdateDocumentNumberOfDownloads(id), token);

            await Task.WhenAll(followTask, messageTask);

            var nameToDownload = item.Document.Title;
            var extension      = Path.GetExtension(file);
            var url            = blobProvider2.GenerateDownloadLink(uri, TimeSpan.FromMinutes(30), nameToDownload + extension);

            return(Redirect(url.AbsoluteUri));
        }
Esempio n. 5
0
        public async Task <ActionResult <DocumentPreviewResponse> > GetAsync(long id,
                                                                             [FromServices] IQueueProvider queueProvider,
                                                                             [FromServices] ICrawlerResolver crawlerResolver,
                                                                             [FromServices] IIndex <DocumentType, IDocumentGenerator> generatorIndex,
                                                                             [FromServices] IUrlBuilder urlBuilder,
                                                                             CancellationToken token)
        {
            long?userId = null;

            if (User.Identity.IsAuthenticated)
            {
                userId = _userManager.GetLongUserId(User);
            }

            var query = new DocumentById(id, userId);
            var model = await _queryBus.QueryAsync(query, token);

            if (model == null)
            {
                return(NotFound());
            }

            model.Document.User.Image = urlBuilder.BuildUserImageEndpoint(model.Document.User.Id, model.Document.User.Image);
            if (model.Tutor != null)
            {
                model.Tutor.Image =
                    urlBuilder.BuildUserImageEndpoint(model.Tutor.UserId, model.Tutor.Image);
            }

            var tQueue   = queueProvider.InsertMessageAsync(new UpdateDocumentNumberOfViews(id), token);
            var textTask = Task;

            if (crawlerResolver.Crawler != null)
            {
                textTask = _blobProvider.DownloadTextAsync("text.txt", query.Id.ToString(), token);
            }

            var files = await generatorIndex[model.Document.DocumentType].GeneratePreviewAsync(model, userId.GetValueOrDefault(-1), token);
            await System.Threading.Tasks.Task.WhenAll(tQueue, textTask);

            model.Document.Url = Url.DocumentUrl(model.Document.Course, model.Document.Id, model.Document.Title);
            return(new DocumentPreviewResponse(model, files, textTask.Result));
        }
Esempio n. 6
0
        private async Task GenerateEmailAsync(User user, ReturnUrlRequest?returnUrl, CancellationToken token)
        {
            var code = await _userManager.GenerateEmailConfirmationTokenAsync(user);

            code = UrlEncoder.Default.Encode(code);
            var url = returnUrl?.Url;

            if (!Url.IsLocalUrl(url))
            {
                url = null;
            }
            TempData[EmailTime] = DateTime.UtcNow.ToString(CultureInfo.InvariantCulture);

            var link = Url.Link("ConfirmEmail", new { user.Id, code, returnUrl = url, referral = TempData[HomeController.Referral] });

            TempData[Email] = user.Email;
            var message = new RegistrationEmail(user.Email, HtmlEncoder.Default.Encode(link), CultureInfo.CurrentUICulture);
            await _queueProvider.InsertMessageAsync(message, token);
        }
Esempio n. 7
0
 public async Task HandleAsync(UseCouponEvent eventMessage, CancellationToken token)
 {
     var message = new CouponActionEmail(eventMessage.UserCoupon.User.Id, eventMessage.UserCoupon.User.PhoneNumber, eventMessage.UserCoupon.User.Email,
                                         eventMessage.UserCoupon.Coupon.Code, eventMessage.UserCoupon.Tutor?.User.Name, CouponAction.Use.ToString());
     await _queueProvider.InsertMessageAsync(message, token);
 }
Esempio n. 8
0
 public async Task HandleAsync(LeadEvent eventMessage, CancellationToken token)
 {
     var message = new RequestTutorMessage(eventMessage.Lead.Id);
     await _queueProvider.InsertMessageAsync(message, token);
 }
Esempio n. 9
0
 public async Task HandleAsync(SessionParticipantDisconnectEvent disconnectMessage, CancellationToken token)
 {
     var message = new SessionDisconnectMessage(disconnectMessage.SessionDisconnect.Id);
     await _serviceBusProvider.InsertMessageAsync(message, TimeSpan.FromMinutes(TimeToDisconnectInMinutes), token);
 }
Esempio n. 10
0
 protected Task SendEmail(BaseEmail obj, CancellationToken token)
 {
     return(_serviceBusProvider.InsertMessageAsync(obj, token));
 }