コード例 #1
0
        private string UploadImageToS3(Stream memoryStream, string filePrefix = "img")
        {
            string         bucketName   = _appSettingService.GetAppSettingData("gallery_s3_bucket_name");
            string         keyName      = $"{filePrefix}_{CommonUtility.GetNewID()}.png";
            RegionEndpoint bucketRegion = RegionEndpoint.APSouth1;
            string         _accessKey   = _appSettingService.GetAppSettingData("aws_s3_access_key");
            string         _secretKey   = _appSettingService.GetAppSettingData("aws_s3_secret_key");
            IAmazonS3      s3Client;


            _logger.Debug($"{bucketName}:::{_accessKey}:::{_secretKey}");
            try
            {
                var credentials = new BasicAWSCredentials(_accessKey, _secretKey);
                s3Client = new AmazonS3Client(credentials, bucketRegion);


                S3CannedACL permissions = S3CannedACL.NoACL;
                var         putObject   = new PutObjectRequest
                {
                    BucketName  = bucketName,
                    Key         = keyName,
                    InputStream = memoryStream,
                    ContentType = "image/png",
                    CannedACL   = permissions
                };

                //setting content length for streamed input
                putObject.Metadata.Add("Content-Length", memoryStream.Length.ToString());
                var putResponse = s3Client.PutObjectAsync(putObject).GetAwaiter().GetResult();

                if (putResponse.HttpStatusCode == HttpStatusCode.OK)
                {
                    return($"/{keyName}");
                }
                else
                {
                    throw new Exception($"Error while upload image to s3 HttpStatusCode: {putResponse.HttpStatusCode }");
                }
            }
            catch (AmazonS3Exception e)
            {
                _logger.Error($"AmazonS3Exception : {e.Message}", e);
                throw;
            }
        }
コード例 #2
0
        public bool SendEmail(string email, string emailTemplate, string subject, OTPType otpType, string securityToken)
        {
            var otpData = CreateOTPData(otpType, securityToken);

            otpData[CommonConst.CommonField.EMAIL] = email;

            if (_dbService.Write(CommonConst.Collection.OTPs, otpData))
            {
                List <string> to = new List <string>()
                {
                    email
                };
                var fromEmail = _appSettingService.GetAppSettingData(CommonConst.CommonField.FROM_EMAIL_ID);
                return(_emailService.Send(to, fromEmail, null, emailTemplate, subject, otpData));
            }
            else
            {
                return(false);
            }
        }
コード例 #3
0
 public FileKeyValueFileStorage(IEncryption encryption, IAppSettingService appSettingService, ILogger logger)
 {
     _logger            = logger;
     _encryption        = encryption;
     _appSettingService = appSettingService;
     _storageBasePath   = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "ZNxtApp", appSettingService.GetAppSettingData("DataBaseName"));
 }
コード例 #4
0
        public JObject Send()
        {
            var model = _httpContextProxy.GetRequestBody <NotifyModel>();

            if (model == null)
            {
                return(_responseBuilder.BadRequest());
            }
            var to      = model.To.Split(';').ToList();
            var message = model.Message;

            if (model.Type == "SMS")
            {
                JObject dataresponse = new JObject();
                foreach (var res in _smsService.Send(to, message))
                {
                    dataresponse[res.Key] = res.Value;
                }
                return(_responseBuilder.Success(dataresponse));
            }
            else
            {
                if (_emailService.Send(to, _appSettingService.GetAppSettingData(CommonConst.CommonField.FROM_EMAIL_ID), model.CC.Split(';').ToList(), message, model.Subject))
                {
                    return(_responseBuilder.Success());
                }
                else
                {
                    return(_responseBuilder.ServerError());
                }
            }
        }
コード例 #5
0
        public bool Send(List <string> toEmail, string fromEmail, List <string> CC, string emailBody, string subject)
        {
            JObject emailData = new JObject();

            emailData[CommonConst.CommonField.DISPLAY_ID] = CommonUtility.GetNewID();
            emailData[CommonConst.CommonField.FROM]       = fromEmail;
            emailData[CommonConst.CommonField.SUBJECT]    = subject;
            emailData[CommonConst.CommonField.TO]         = new JArray();
            foreach (var email in toEmail)
            {
                (emailData[CommonConst.CommonField.TO] as JArray).Add(email);
            }
            emailData[CommonConst.CommonField.CC] = new JArray();
            if (CC != null)
            {
                foreach (var email in CC)
                {
                    (emailData[CommonConst.CommonField.CC] as JArray).Add(email);
                }
            }
            emailData[CommonConst.CommonField.BODY]   = emailBody;
            emailData[CommonConst.CommonField.STATUS] = EmailStatus.Queue.ToString();

            if (_dbService.Write(CommonConst.Collection.EMAIL_QUEUE, emailData))
            {
                Dictionary <string, string> filter = new Dictionary <string, string>();
                filter[CommonConst.CommonField.DISPLAY_ID] = emailData[CommonConst.CommonField.DISPLAY_ID].ToString();
                try
                {
                    MailMessage mail       = new MailMessage();
                    SmtpClient  SmtpServer = new SmtpClient(_appSettingService.GetAppSettingData(CommonConst.CommonField.SMTP_SERVER));

                    mail.From = new MailAddress(emailData[CommonConst.CommonField.FROM].ToString());
                    foreach (var item in emailData[CommonConst.CommonField.TO])
                    {
                        mail.To.Add(item.ToString());
                    }

                    mail.Subject    = emailData[CommonConst.CommonField.SUBJECT].ToString();
                    mail.Body       = emailData[CommonConst.CommonField.BODY].ToString();
                    mail.IsBodyHtml = true;
                    int port = 587;
                    int.TryParse(_appSettingService.GetAppSettingData(CommonConst.CommonField.SMTP_SERVER_PORT), out port);
                    SmtpServer.Port = port;
                    var user     = _appSettingService.GetAppSettingData(CommonConst.CommonField.SMTP_SERVER_USER);
                    var password = _appSettingService.GetAppSettingData(CommonConst.CommonField.SMTP_SERVER_PASSWORD);
                    SmtpServer.Credentials = new System.Net.NetworkCredential(user, password);
                    SmtpServer.EnableSsl   = true;
                    SmtpServer.Send(mail);
                    emailData[CommonConst.CommonField.STATUS] = EmailStatus.Sent.ToString();
                    _dbService.Write(CommonConst.Collection.EMAIL_QUEUE, emailData, filter);

                    return(true);
                }
                catch (Exception ex)
                {
                    emailData[CommonConst.CommonField.STATUS] = EmailStatus.SendError.ToString();
                    _dbService.Write(CommonConst.Collection.EMAIL_QUEUE, emailData, filter);
                    _logger.Error("Error email send ", ex);
                    return(false);
                }
            }
            else
            {
                _logger.Error("Error in add email data in queue");
                return(false);
            }
        }
コード例 #6
0
 public FileKeyValueFileStorage(IEncryption encryption, IAppSettingService appSettingService)
 {
     _encryption        = encryption;
     _appSettingService = appSettingService;
     _storageBasePath   = appSettingService.GetAppSettingData("KeyValueFileStoragePath");
 }
コード例 #7
0
        public bool Send(string toSms, string message)
        {
            JObject smsData = new JObject();

            smsData[CommonConst.CommonField.DISPLAY_ID] = CommonUtility.GetNewID();
            smsData[CommonConst.CommonField.TO]         = toSms;
            smsData[CommonConst.CommonField.BODY]       = message;
            smsData[CommonConst.CommonField.STATUS]     = SMSStatus.Queue.ToString();

            if (_dbService.Write(CommonConst.Collection.SMS_QUEUE, smsData))
            {
                Dictionary <string, string> filter = new Dictionary <string, string>();
                filter[CommonConst.CommonField.DISPLAY_ID] = smsData[CommonConst.CommonField.DISPLAY_ID].ToString();
                try
                {
                    if (_appSettingService.GetAppSettingData("sms_provider") == "PSBULKSMS")
                    {
                        if (PsbulkSMSHelper.SendSMS(
                                message,
                                toSms,
                                _appSettingService.GetAppSettingData("sms_gateway_key"),
                                _appSettingService.GetAppSettingData("gateway_endpoint"),
                                _appSettingService.GetAppSettingData("sms_from"),
                                _logger))
                        {
                            smsData[CommonConst.CommonField.STATUS] = EmailStatus.Sent.ToString();
                            _dbService.Write(CommonConst.Collection.SMS_QUEUE, smsData, filter);
                            return(true);
                        }
                        else
                        {
                            smsData[CommonConst.CommonField.STATUS] = SMSStatus.SendError.ToString();
                            _dbService.Write(CommonConst.Collection.SMS_QUEUE, smsData, filter);
                            return(false);
                        }
                    }
                    else
                    {
                        if (TextLocalSMSHelper.SendSMS(
                                message,
                                toSms,
                                _appSettingService.GetAppSettingData("sms_gateway_key"),
                                _appSettingService.GetAppSettingData("gateway_endpoint"),
                                _appSettingService.GetAppSettingData("sms_from"),
                                _logger))
                        {
                            smsData[CommonConst.CommonField.STATUS] = EmailStatus.Sent.ToString();
                            _dbService.Write(CommonConst.Collection.SMS_QUEUE, smsData, filter);
                            return(true);
                        }
                        else
                        {
                            smsData[CommonConst.CommonField.STATUS] = SMSStatus.SendError.ToString();
                            _dbService.Write(CommonConst.Collection.SMS_QUEUE, smsData, filter);
                            return(false);
                        }
                    }
                }
                catch (Exception ex)
                {
                    smsData[CommonConst.CommonField.STATUS] = SMSStatus.SendError.ToString();
                    _dbService.Write(CommonConst.Collection.SMS_QUEUE, smsData, filter);
                    _logger.Error("Error SMS send ", ex);
                    return(false);
                }
            }
            else
            {
                _logger.Error("Error in add SMS data in queue");
                return(false);
            }
        }