Esempio n. 1
0
        public async Task <IActionResult> SendPhotoToUsersAsync([FromForm] FileToUsersModel model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            UserCheckResultDto        userCheckResult;
            List <UserCheckResultDto> userCheckResults = new List <UserCheckResultDto>();

            string path = await SaveFileAsync(model.File);

            ISocialProvider provider   = _serviceAccessor(model.Provider);
            FileToUserDto   fileToUser = new FileToUserDto
            {
                Name       = model.File.FileName,
                SenderName = model.SenderName,
                Subject    = model.Subject,
                Caption    = model.Caption ?? "",
                Path       = path,
                Priority   = model.Priority
            };

            using (IEnumerator <string> enumer = model.Logins.GetEnumerator())
            {
                if (enumer.MoveNext())
                {
                    if (string.IsNullOrEmpty(parentIds[model.Provider]) ||
                        JobStorage.Current.GetMonitoringApi().JobDetails(parentIds[model.Provider]) == null)
                    {
                        userCheckResult = await provider.UserCheck(enumer.Current);

                        userCheckResults.Add(userCheckResult);
                        if (userCheckResult.IsValid)
                        {
                            fileToUser.Login          = enumer.Current;
                            parentIds[model.Provider] = BackgroundJob.Enqueue(() => provider.SendPhotoToUserAsync(fileToUser));
                        }
                        if (!enumer.MoveNext())
                        {
                            return(Ok(JsonConvert.SerializeObject(userCheckResults)));
                        }
                    }

                    do
                    {
                        userCheckResult = await provider.UserCheck(enumer.Current);

                        userCheckResults.Add(userCheckResult);
                        if (userCheckResult.IsValid)
                        {
                            fileToUser.Login          = enumer.Current;
                            parentIds[model.Provider] = BackgroundJob.ContinueWith(parentIds[model.Provider], () => provider.SendPhotoToUserAsync(fileToUser));
                        }
                    } while (enumer.MoveNext());
                }
            }

            return(Ok(JsonConvert.SerializeObject(userCheckResults)));
        }
Esempio n. 2
0
        public async Task SendPhotoToUserAsync(FileToUserDto model)
        {
            var userId = await GetUserIdAsync(model.Login);

            await SendFile(userId, model.Path, MessageBuilder(model.SenderName, model.Subject, model.Caption), model.MimeType, model.Name);

            Thread.Sleep(DileyTime);
        }
Esempio n. 3
0
        public async Task SendPhotoToUserAsync(FileToUserDto model)
        {
            TLUser user = await GetUserAsync(model.Login);

            TLAbsInputFile fileResult = await UpLoadFileAsync(model.Path, model.Name);

            await client.SendUploadedPhoto(new TLInputPeerUser()
            {
                UserId = user.Id
            }, fileResult, MessageBuilder(model.SenderName, model.Subject, model.Caption));

            Thread.Sleep(DileyTime);
        }
Esempio n. 4
0
        public async Task SendFileToUserAsync(FileToUserDto model)
        {
            if (!IsValidEmail(model.Login))
            {
                throw new ArgumentException("Login is not a valid email: " + model.Login);
            }
            if (string.IsNullOrEmpty(model.Path))
            {
                throw new ArgumentException("Path can't be empty");
            }
            if (!File.Exists(model.Path))
            {
                throw new ArgumentException("Could not find file " + model.Path);
            }

            BodyBuilder bodyBuilder = new BodyBuilder
            {
                TextBody = model.Caption
            };

            bodyBuilder.Attachments.Add(model.Path);

            MimeMessage message = new MimeMessage
            {
                Subject = model.Subject,
                Body    = bodyBuilder.ToMessageBody()
            };

            message.To.Add(new MailboxAddress("User", model.Login));
            message.From.Add(new MailboxAddress(model.SenderName, _emailConfigurations.Email));


            using (SmtpClient emailClient = new SmtpClient())
            {
                emailClient.Connect(_emailConfigurations.SmtpServer, _emailConfigurations.SmtpPort, true);
                emailClient.Authenticate(_emailConfigurations.UserName, _emailConfigurations.Password);
                emailClient.Send(message);
                emailClient.Disconnect(true);
            }
            Thread.Sleep(DileyTime);
        }
Esempio n. 5
0
        public async Task SendFileToUserAsync(FileToUserDto model)
        {
            TLUser user = await GetUserAsync(model.Login);

            TLAbsInputFile fileResult = await UpLoadFileAsync(model.Path, model.Name);

            await client.SendUploadedDocument(
                new TLInputPeerUser()
            {
                UserId = user.Id
            },
                fileResult,
                MessageBuilder(model.SenderName, model.Subject, model.Caption),
                model.MimeType,
                new TLVector <TLAbsDocumentAttribute>()
            {
                new TLDocumentAttributeFilename
                {
                    FileName = model.Name
                }
            });

            Thread.Sleep(DileyTime);
        }