예제 #1
0
 public async Task <bool> RequestToChoicerQ(dChoice choice)
 {
     return(await RequestToServer(new VmsRequest <dChoice>
     {
         command = QCommand.ChoicerQ,
         data = choice
     },
                                  PQueue.ReceiveServerPipeName
                                  ));
 }
예제 #2
0
        public async Task <bool> StartChoiceAsync(AppDbContext ltctx, dChoice choice)
        {
            var _result = false;

            var _winner = ltctx.tb_lion_winner
                          .Where(w => w.SequenceNo == choice.sequence_no - 1)
                          .SingleOrDefault();

            var _member = ltctx.tb_lion_member
                          .Where(m => m.LoginId == choice.login_id && m.IsAlive == true)
                          .SingleOrDefault();

            if (_winner != null && _member != null)
            {
                // 다음 회차 번호를 select(추출) 테이블에서 choice(선택) 합니다.
                var _no_choice = await NextGameChoiceAsync(ltctx, _member, choice);

                if (_no_choice > 0)
                {
                    WriteMember(choice.sequence_no, choice.login_id, $"game choiced {_no_choice} games");
                }

                if (_no_choice > 0 || choice.resend == true)
                {
                    // 위에서 선택한 게임을 메일로 발송 합니다.
                    var _no_sending = await NextGameSenderAsync(ltctx, _winner, _member, choice);

                    if (_no_sending > 0)
                    {
                        WriteMember(choice.sequence_no, choice.login_id, $"mail sent {_no_sending} games");

                        var _is_notify = await PushChoiceNotification(ltctx, choice, _member, _no_sending);

                        if (_is_notify == true)
                        {
                            WriteMember(choice.sequence_no, choice.login_id, $"push notified");
                        }
                    }
                }

                _result = true;
            }

            return(_result);
        }
예제 #3
0
        private async Task <bool> PushChoiceNotification(AppDbContext ltctx, dChoice choice, mMember member, int no_sending)
        {
            var _result = false;

            var _message = $"{choice.sequence_no}회 예측번호가 {member.EmailAddress}로 {no_sending}게임 발송 되었습니다.";

            {
                var _push = await _notifyPush.PushNotification(ltctx, member, "예측번호발송", _message);

                if (_push.success == true)
                {
                    WriteMember(choice.sequence_no, choice.login_id, $"push choice");
                }

                _result = _push.success;
            }

            return(_result);
        }
예제 #4
0
        public string SaveLottoSheet(mChoice[] lott645_selector, dChoice choice)
        {
            // location of files to compress
            var _zip_directory = "";
            {
                var _zip_packing = $"{ServiceName}_{choice.login_id}_{choice.sequence_no:0000}";

                var _user_directory = Path.Combine(ZipFolder, choice.login_id);
                {
                    if (Directory.Exists(_user_directory) == true)
                    {
                        Directory.Delete(_user_directory, true);
                    }

                    Directory.CreateDirectory(_user_directory);
                }

                _zip_directory = Path.Combine(_user_directory, _zip_packing);
                {
                    if (Directory.Exists(_zip_directory) == true)
                    {
                        Directory.Delete(_zip_directory, true);
                    }

                    Directory.CreateDirectory(_zip_directory);
                }
            }

            // write sheet images
            var _page_no = 1;
            {
                foreach (var _sheet in PrintLottoSheet(lott645_selector, choice.sequence_no, choice.login_id))
                {
                    var _file_name = $"{ServiceName}_{choice.login_id}_{choice.sequence_no:0000}_{_page_no:000}.jpg";
                    {
                        var _img_filepath = Path.Combine(_zip_directory, _file_name);
                        if (File.Exists(_img_filepath))
                        {
                            File.Delete(_img_filepath);
                        }

                        _sheet.Save(_img_filepath, System.Drawing.Imaging.ImageFormat.Jpeg);
                    }

                    _page_no++;
                }
            }

            // write text file
            {
                var _file_name = $"{ServiceName}_{choice.login_id}_{choice.sequence_no:0000}.csv";

                var _txt_filepath = Path.Combine(_zip_directory, _file_name);
                if (File.Exists(_txt_filepath))
                {
                    File.Delete(_txt_filepath);
                }

                using (var _writer = File.OpenWrite(_txt_filepath))
                {
                    using (var _stream = new StreamWriter(_writer))
                    {
                        foreach (var _s in lott645_selector)
                        {
                            var _line = $"{_s.SequenceNo},,"
                                        + $"{_s.Digit1},{_s.Digit2},{_s.Digit3},{_s.Digit4},{_s.Digit5},{_s.Digit6}";

                            _stream.WriteLine(_line);
                        }
                    }
                }
            }

            // create zip file
            var _zip_file = Path.ChangeExtension(_zip_directory, "zip");

            {
                if (File.Exists(_zip_file))
                {
                    File.Delete(_zip_file);
                }

                ZipFile.CreateFromDirectory(_zip_directory, _zip_file);
            }

            return(_zip_file);
        }
예제 #5
0
        public async Task <IActionResult> AddMemberByFacebook([FromForm] ApplicationUser app_user)
        {
            return(await CProxy.UsingAsync(async() =>
            {
                var _result = (success : false, message : "ok");

                while (true)
                {
                    if (String.IsNullOrEmpty(app_user.mail_address) == true)
                    {
                        _result.message = "메일 주소가 필요 합니다";
                        break;
                    }

                    var _value = "";

                    var _validate = __verify_email.TryRemove(app_user.mail_address, out _value);
                    if (_validate == false)
                    {
                        _result.message = $"검증 하고자 하는 메일 주소({app_user.mail_address})가 아닙니다";
                        break;
                    }

                    _validate = _value == app_user.check_number;
                    if (_validate == false)
                    {
                        _result.message = $"메일 검증 번호({app_user.check_number})가 일치 하지 않습니다";
                        break;
                    }

                    if (String.IsNullOrEmpty(app_user.login_name) == true ||
                        String.IsNullOrEmpty(app_user.facebook_id) == true || String.IsNullOrEmpty(app_user.facebook_token) == true
                        )
                    {
                        _result.message = "facebook-id, facebook-token, 회원-이름이 필요 합니다";
                        break;
                    }

                    _validate = await __usermgr.VerifyFacebookToken(app_user.facebook_token, app_user.facebook_id);
                    if (_validate == false)
                    {
                        _result.message = $"facebook-token 또는 facebook-id({app_user.facebook_id}) 오류 입니다";
                        break;
                    }

                    app_user.login_id = app_user.facebook_id;

                    var _member = __db_context.tb_lion_member
                                  .Where(m => m.EmailAddress == app_user.mail_address)
                                  .SingleOrDefault();

                    if (_member == null)
                    {
                        _member = __db_context.tb_lion_member
                                  .Where(m => m.LoginId == app_user.facebook_id)
                                  .SingleOrDefault();

                        if (_member != null)
                        {
                            _result.message = $"동일한 facebook-id({app_user.facebook_id})가 이미 사용 중 입니다";
                            break;
                        }

                        if (__usermgr.AddNewMember(__db_context, app_user) == false)
                        {
                            _result.message = $"모바일 장치 정보 오류 입니다";
                            break;
                        }

                        _result.message = $"신규 회원으로 등록 되었습니다";
                        _result.success = true;
                    }
                    else
                    {
                        if (_member.IsAlive == true)
                        {
                            _result.message = $"다른 회원이 이미 사용하고 있는 메일 주소({app_user.mail_address}) 입니다";
                            break;
                        }

                        if (__usermgr.ReUseMember(__db_context, _member, app_user) == false)
                        {
                            _result.message = $"모바일 장치 정보 오류 입니다";
                            break;
                        }

                        _result.message = $"기존 회원으로 등록 되었습니다";
                        _result.success = true;
                    }

                    // 가입 member(회원)에게 즉시 메일 발송 하도록 큐에 명령을 보냅니다.
                    if (_result.success == true)
                    {
                        var _choice = new dChoice()
                        {
                            login_id = app_user.login_id,
                            sequence_no = __reader.GetNextWeekSequenceNo(),
                            resend = true
                        };

                        await __pipe_client.RequestToChoicerQ(_choice);
                    }

                    break;
                }

                return Ok(new
                {
                    _result.success,
                    _result.message,

                    result = ""
                });
            }));
        }
예제 #6
0
        private async Task <int> NextGameSenderAsync(AppDbContext ltctx, mWinner winner, mMember member, dChoice choice)
        {
            var _result = 0;

            try
            {
                ltctx.Database.BeginTransaction();

                if (member.MailError == false)
                {
                    var _choices = ltctx.tb_lion_choice
                                   .Where(c => c.SequenceNo == choice.sequence_no && c.LoginId == choice.login_id &&
                                          (c.IsMailSent == false || choice.resend == true))
                                   .OrderBy(c => c.Digit1).ThenBy(c => c.Digit2).ThenBy(c => c.Digit3)
                                   .ThenBy(c => c.Digit4).ThenBy(c => c.Digit5).ThenBy(c => c.Digit6)
                                   .ToArray();

                    choice.no_choice = _choices.Length;

                    // 해당 회차에 처리하고자 하는 회원에게 메일 발송이 안된 entity만을 처리 합니다.
                    if (choice.no_choice > 0)
                    {
                        var _verify = await _mailSender.TestMailServerConnectionAsync(member);

                        if (_verify.error_code == SmtpError.GENERIC_SUCCESS)
                        {
                            var _curr_factor = _winnerSelector.GetFactor(ltctx, choice.sequence_no - 0);
                            var _last_factor = _winnerSelector.GetFactor(ltctx, choice.sequence_no - 1);

                            // 선택 번호들을 이미지 처리 함, 최종 zip(압축) 파일로 생성 합니다.
                            var _zip_file = _printOut.SaveLottoSheet(_choices, choice);

                            var _last_jackpot = _winnerScoring.GetJackpot(ltctx, member, choice.sequence_no - 1, member.MaxSelectNumber);

                            // zip 파일을 첨부 하여 메일 발송 합니다.
                            await _mailSender.SendLottoZipFile(_zip_file, choice, winner, member, _curr_factor, _last_factor, _last_jackpot);

                            // 메일 발송 했음을 표기 함
                            _choices
                            .ToList()
                            .ForEach(c => c.IsMailSent = true);

                            _result = choice.no_choice;
                        }
                        else
                        {
                            WriteMember(choice.sequence_no, choice.login_id, $"mail error '{member.EmailAddress}', {_verify.error_code}, {_verify.error_message}");
                        }

                        await ltctx.SaveChangesAsync();
                    }
                }

                ltctx.Database.CommitTransaction();
            }
            catch (Exception ex)
            {
                ltctx.Database.RollbackTransaction();

                _logger.LogError(ex, "receiver.choicer");
            }

            return(_result);
        }
예제 #7
0
        private async Task <int> NextGameChoiceAsync(AppDbContext ltctx, mMember member, dChoice choice)
        {
            var _no_choice = 0;

            try
            {
                var _counter = ltctx.tb_lion_choice
                               .Where(x => x.SequenceNo == choice.sequence_no && x.LoginId == choice.login_id)
                               .Count();

                // 할당량 만큼 choice(선택) 되었으면 더이상 추가 하지 않음
                if (member.MaxSelectNumber > _counter)
                {
                    _no_choice = _winnerMember.WinnerChoice(ltctx, member, choice, _counter);
                    _winnerScoring.PutJackpot(ltctx, member, choice.sequence_no, (short)_no_choice);

                    await ltctx.SaveChangesAsync();
                }
            }
            catch (Exception ex)
            {
                ltctx.Database.RollbackTransaction();

                _logger.LogError(ex, "receiver.choicer");
            }

            return(_no_choice);
        }
예제 #8
0
        public async Task <int> SelectMemberAsync(AppDbContext ltctx, WinnerReader reader, int selectNo, bool resend)
        {
            var _result = 0;

            var _today_winner_no = reader.GetThisWeekSequenceNo();

            // 현재의 예상 번호가 select(추출) 되어 있으면, choice(선택) 한다.
            // analysis(분석) 차수와 같은 차수이면 select(추출)이 있다고 가정한다.
            if (_today_winner_no == selectNo - 1)
            {
                var _digits = new List <short> {
                    0, 0, 0
                };
                {
                    var _master = ltctx.tb_lion_member
                                  .Where(m => m.LoginId == LottoSelectmasterId)
                                  .SingleOrDefault();

                    if (_master != null)
                    {
                        var _offset = 0;

                        if (_master.Digit1 > 0)
                        {
                            if (!_digits.Contains(_master.Digit1))
                            {
                                _digits[_offset] = _master.Digit1;
                                _offset++;
                            }
                        }

                        if (_master.Digit2 > 0)
                        {
                            if (!_digits.Contains(_master.Digit2))
                            {
                                _digits[_offset] = _master.Digit2;
                                _offset++;
                            }
                        }

                        if (_master.Digit3 > 0)
                        {
                            if (!_digits.Contains(_master.Digit3))
                            {
                                _digits[_offset] = _master.Digit3;
                                _offset++;
                            }
                        }
                    }
                }

                // 가입 member(회원)들에게 각자에게 할당 된 갯수만큼을 select(추출)테이블에서 choice(선택) 테이블로
                // 복사 후 메일 발송 하도록 큐에 명령을 보냅니다. (여기서 처리 하지 않고 memberQ에서 pop하여 처리 함)
                var _members = ltctx.tb_lion_member
                               .Where(m => m.IsNumberChoice == true && m.IsMailSend == true && m.IsAlive == true && m.MailError == false)
                               .ToList();

                foreach (var _member in _members)
                {
                    var _no_choice = ltctx.tb_lion_choice
                                     .Where(c => c.SequenceNo == selectNo && c.LoginId == _member.LoginId)
                                     .GroupBy(c => c.IsMailSent)
                                     .Select(n => new { b = n.Key, c = n.Count() })
                                     .ToList();

                    var _no_choice_t = _no_choice.Where(c => c.b == true).Sum(c => c.c);
                    var _no_choice_f = _no_choice.Where(c => c.b == false).Sum(c => c.c);

                    // 기 선택 하였으면 skip 함
                    if (_no_choice_t + _no_choice_f <= 0 || _no_choice_f > 0)
                    {
                        var _choice = new dChoice()
                        {
                            sequence_no = selectNo,
                            login_id    = _member.LoginId,
                            resend      = resend || _no_choice_f > 0,
                            digit1      = _digits[0],
                            digit2      = _digits[1],
                            digit3      = _digits[2]
                        };

                        // member(회원)들에게 메일 발송 하도록 큐에 명령을 보냅니다.
                        await this.RequestToChoicerQ(_choice);

                        _result++;
                    }
                }
            }

            return(_result);
        }
예제 #9
0
        public async Task SendLottoZipFile(string zip_file_path, dChoice choice, mWinner winner, mMember member, mFactor curr_factor, mFactor last_factor, mJackpot last_jackpot)
        {
            var _message = new MimeMessage();
            {
                _message.From.Add(new MailboxAddress(MailSenderName, MailSenderAddress));
                _message.To.Add(new MailboxAddress(member.LoginName, member.EmailAddress));

                _message.Subject = $"[로또번호] {member.LoginName} 님을 위한 [{choice.sequence_no}]회차 로또645 예측 번호 제공 {(member.IsDirectSend ? "D" : "I")}";
            }

            var _curr_no_combination = curr_factor.LNoCombination + curr_factor.RNoCombination;
            var _curr_no_extraction  = curr_factor.LNoExtraction + curr_factor.RNoExtraction;
            var _last_no_extraction  = last_factor.LNoExtraction + last_factor.RNoExtraction;

            var _builder = new BodyBuilder();

            {
                _builder.HtmlBody = $"<div>"
                                    + $"<h4>안녕하세요 '{member.LoginName}'님, '로또645 예측 번호 제공 서비스' 입니다.</h4>"
                                    + $"<p></p>"
                                    + $"<h4>A. [{last_jackpot.SequenceNo}]회 추첨 결과</h4>"
                                    + $"<p>당첨번호: <strong>{winner.Digit1}, {winner.Digit2}, {winner.Digit3}, {winner.Digit4}, {winner.Digit5}, {winner.Digit6} ({winner.Digit7})</strong></p>"
                                    + $"<p>예측결과: {_last_no_extraction:#,##0} 게임</p>"
                                    + $"<ul>"
                                    + $"<li>1등: {last_factor.NoJackpot1,10:#,##0} 게임, {last_factor.WinningAmount1,15:#,##0} 원</li>"
                                    + $"<li>2등: {last_factor.NoJackpot2,10:#,##0} 게임, {last_factor.WinningAmount2,15:#,##0} 원</li>"
                                    + $"<li>3등: {last_factor.NoJackpot3,10:#,##0} 게임, {last_factor.WinningAmount3,15:#,##0} 원</li>"
                                    + $"<li>4등: {last_factor.NoJackpot4,10:#,##0} 게임, {last_factor.WinningAmount4,15:#,##0} 원</li>"
                                    + $"<li>5등: {last_factor.NoJackpot5,10:#,##0} 게임, {last_factor.WinningAmount5,15:#,##0} 원</li>"
                                    + $"</ul>"
                                    + $"<p>회원결과: {last_jackpot.NoChoice} 게임</p>"
                                    + $"<ul>"
                                    + $"<li>지난 주 발송 된 번호 중 {last_jackpot.NoJackpot} 게임, <strong>{last_jackpot.WinningAmount:#,##0}원</strong>이 당첨 되었습니다.</li>"
                                    + $"</ul>"
                                    + $"<h4>B. [{choice.sequence_no}]회 예측 번호</h4>"
                                    + $"<ul>"
                                    + $"<li>전체 45개의 번호 중 <strong>{_curr_no_combination:#,##0}개의 게임</strong>을 조합 했습니다.</li>"
                                    + $"<li>그 중 확률적으로 의미 있는 <strong>{_curr_no_extraction:#,##0}개의 게임</strong>이 추출 되었습니다.</li>"
                                    + $"<li>'{member.LoginName}'님에게 추출 된 {_curr_no_extraction:#,##0}개의 게임 중, 엄선해서 <strong>{choice.no_choice:#,##0}개의 게임</strong>을 보내 드립니다.</li>"
                                    + $"<li>특별히 원하시는 번호(3개 까지)를 아래 [운영자] 메일로 알려 주시면, 해당 번호가 포함 되어 있는 게임만 받을 수 있습니다.</li>"
                                    + $"<li> <a href='https://play.google.com/store/apps/details?id=kr.co.odinsoftware.LION'>로또사자(Android)</a>, "
                                    + $"<a href='https://itunes.apple.com/us/app/%EB%A1%9C%EB%98%90%EC%82%AC%EC%9E%90-lottolion/id1236106275?l=ko&ls=1&mt=8'>로또사자(iOS)</a> "
                                    + $"앱을 설치 하시면, 당첨내역과 이력 조회 및 게임 수 변경, 번호 지정이 가능 합니다.</li>"
                                    + $"</ul>"
                                    + $"<h4>C. 출력 방법</h4>"
                                    + $"<ul>"
                                    + $"<li>이미지 파일을 A4 프린터로 출력 후 로또 용지 크기와 동일하게 절단 합니다.</li>"
                                    + $"<li>A4 한장 당 최대 로또 용지 3장이 출력 됩니다.</li>"
                                    + $"<li>절취선에 맞춰 절단 후 로또 판매점에서 별도로 작성 하지 않고, 출력하신 용지로 바로 구매 가능 합니다.</li>"
                                    + $"<li>절취시 잘못 절단 하면 로또 판매점의 리더기에서 오류가 발생 할 수 있습니다.</li>"
                                    + $"<li>실제 로또 용지와 크기가 동일하게 절단하는 것이 중요 합니다.</li>"
                                    + $"<li>길이(19cm) 및 높이(8.2cm)는 같거나 조금 작아야 오류가 없습니다.</li>"
                                    + $"</ul>"
                                    + $"<h4>D. 회원 가입</h4>"
                                    + $"<ul>"
                                    + $"<li>매주 무료 예측 번호를 원하시는 주변 분이 있는 경우 '메일주소'와 '닉네임'을 아래 [운영자] 메일로 보내 주세요.</li>"
                                    + $"<li>메일 수신을 원하지 않는 경우에도 [운영자]에게 제목을 '수신거부'로 메일 보내 주시면 바로 중단 해 드립니다.</li>"
                                    + $"</ul>"
                                    + $"<h4>E. 연락처</h4>"
                                    + $"<ul>"
                                    + $"<li>회사명: {ServiceProvider}</li>"
                                    + $"<li>연락처: {ServiceProviderPhone}</li>"
                                    + $"<li>사이트: <a href='{ServiceProviderHomePage}'>{ServiceProviderHomePage}</a></li>"
                                    + $"<li>운영자: <a href='mailto:{ServiceProviderMailTo}'>{ServiceProviderMailTo}</a></li>"
                                    + $"</ul>"
                                    + "</div>"
                ;

                _builder.Attachments.Add(zip_file_path);
            }

            _message.Body = _builder.ToMessageBody();

            if (member.IsDirectSend == false)
            {
                using (var _client = new SmtpClient())
                {
                    _client.ServerCertificateValidationCallback = (s, c, h, e) => true;

                    _client.Connect(MailDeliveryServer, MailDeliveryPort, false);

                    // Note: since we don't have an OAuth2 token, disable
                    // the XOAUTH2 authentication mechanism.
                    _client.AuthenticationMechanisms.Remove("XOAUTH2");

                    // Note: only needed if the SMTP server requires authentication
                    _client.Authenticate(MailDeliveryUserName, MailDeliveryUserPassword);

                    _client.Send(_message);
                    _client.Disconnect(true);
                }
            }
            else
            {
                await __smtp_direct.SendMailAsync(_message);
            }
        }