Esempio n. 1
0
        static void Main()
        {
            BaseGateway aBaseGateway = new BaseGateway();

            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            MessageBox.Show(aBaseGateway.ConfirmConnection());
            Application.Run(new ChooseLoginUI());
        }
Esempio n. 2
0
        public async Task <string> GetOpenId(string code, string organizationId = null)
        {
            WeChatOpenIdResponseDTO result = null;

            BaseGateway gateway = null;

            if (string.IsNullOrEmpty(organizationId))
            {
                gateway = _gateways.Get <WechatpayGateway>();
            }
            else
            {
                WeChatAppConfiguration appConfig = _wechatAppConfigurationRepository.GetFiltered(o => o.OrganizationId == organizationId).FirstOrDefault();
                if (appConfig != null)
                {
                    var wechatpayMerchant = new PaySharp.Wechatpay.Merchant
                    {
                        AppId           = appConfig.AppId,
                        MchId           = appConfig.MchId,
                        Key             = appConfig.Key,
                        AppSecret       = appConfig.AppSecret,
                        SslCertPath     = appConfig.SslCertPath,
                        SslCertPassword = appConfig.SslCertPassword,
                        NotifyUrl       = appConfig.NotifyUrl
                    };

                    gateway = new WechatpayGateway(wechatpayMerchant);
                }
                else
                {
                    gateway = _gateways.Get <WechatpayGateway>();
                }
            }

            var reqModel = new WeChatOpenIdRequestDTO {
                AppId = gateway.Merchant.AppId, Code = code, Secret = _configuration.WeChatAppSecret
            };

            result = await _wechatApiProxy.CheckAuthCode(reqModel);

            //TODO:验签

            return(result?.OpenId ?? string.Empty);
        }
Esempio n. 3
0
 /// <summary>
 ///  设置顺序节点
 /// </summary>
 /// <param name="agent"></param>
 /// <param name="gateway"></param>
 public static void WithGateway(this BaseAgent agent, BaseGateway gateway)
 {
     agent.Gateway = gateway;
 }
Esempio n. 4
0
 /// <summary>
 /// 初始化支付成功网关事件数据
 /// </summary>
 /// <param name="gateway">支付网关</param>
 public PaySucceedEventArgs(BaseGateway gateway)
     : base(gateway)
 {
 }
Esempio n. 5
0
 public StudentService() : base(new BaseGateway <Student>(), new Validator <Student>())
 {
     _gateway       = new BaseGateway <Student>();
     _schoolGateway = new BaseGateway <School>();
 }
Esempio n. 6
0
 protected void AddAgent(BaseAgent agent, BaseGateway gateway)
 {
 }
        private async Task DepositoDifferito(List <EmendamentiDto> listaEMendamenti, string path,
                                             PersonaDto utenteRichiedente)
        {
            //STAMPA PDF DEPOSITATO (BACKGROUND MODE)
            Log.Debug($"[{_stampa.UIDStampa}] BACKGROUND MODE - Genera PDF Depositato");

            var listaPdfEmendamentiGenerati =
                await GeneraPDFEmendamenti(listaEMendamenti, path);

            Log.Debug($"[{_stampa.UIDStampa}] BACKGROUND MODE - Salva EM nel repository");

            var em   = listaEMendamenti.First();
            var atto = await apiGateway.Atti.Get(_stampa.UIDAtto);

            var dirSeduta = $"Seduta_{atto.SEDUTE.Data_seduta:yyyyMMdd}";
            var dirPDL    = Regex.Replace($"{atto.TIPI_ATTO.Tipo_Atto} {atto.NAtto}", @"[^0-9a-zA-Z]+",
                                          "_");
            var pathRepository = $"{_model.RootRepository}/{dirSeduta}/{dirPDL}";

            if (!Directory.Exists(pathRepository))
            {
                Directory.CreateDirectory(pathRepository);
            }

            var destinazioneDeposito = Path.Combine(pathRepository,
                                                    Path.GetFileName(listaPdfEmendamentiGenerati.First().Value.Path));

            SpostaFascicolo(listaPdfEmendamentiGenerati.First().Value.Path, destinazioneDeposito);
            _stampa.PathFile = Path.Combine($"{dirSeduta}/{dirPDL}",
                                            Path.GetFileName(listaPdfEmendamentiGenerati.First().Value.Path));
            _stampa.UIDEM = em.UIDEM;
            await apiGateway.Stampe.JobUpdateFileStampa(_stampa);

            var bodyMail = await apiGateway.Emendamento.GetBody(em.UIDEM, TemplateTypeEnum.PDF, true);

            if (atto.SEDUTE.Data_effettiva_inizio.HasValue)
            {
                var ruoloSegreteriaAssempblea =
                    await apiGateway.Persone.GetRuolo(RuoliIntEnum.Segreteria_Assemblea);

                Log.Debug(
                    $"[{_stampa.UIDStampa}] BACKGROUND MODE - EM depositato il {listaEMendamenti.First().DataDeposito}");
                if (Convert.ToDateTime(listaEMendamenti.First().DataDeposito) >
                    atto.SEDUTE.Data_effettiva_inizio.Value)
                {
                    Log.Debug($"[{_stampa.UIDStampa}] BACKGROUND MODE - Seduta già iniziata");

                    try
                    {
                        await BaseGateway.SendMail(new MailModel
                        {
                            DA      = _model.EmailFrom,
                            A       = $"{ruoloSegreteriaAssempblea.ADGroupShort}@consiglio.regione.lombardia.it",
                            OGGETTO =
                                $"[TRATTAZIONE AULA] {atto.TIPI_ATTO.Tipo_Atto} {atto.NAtto}: Depositato {listaEMendamenti.First().N_EM}",
                            MESSAGGIO = bodyMail
                        },
                                                   _auth.jwt);
                    }
                    catch (Exception e)
                    {
                        Log.Debug($"[{_stampa.UIDStampa}] Invio mail segreteria", e);
                        await apiGateway.Stampe.AddInfo(_stampa.UIDStampa, $"Invio mail a segreteria ERRORE. Motivo: {e.Message}");
                    }
                }
            }
            else
            {
                Log.Debug($"[{_stampa.UIDStampa}] BACKGROUND MODE - Seduta non è ancora iniziata");
            }

            var email_destinatari       = $"{utenteRichiedente.email};[email protected]";
            var email_destinatariGruppo = string.Empty;
            var email_destinatariGiunta = string.Empty;

            if (em.id_gruppo < 10000)
            {
                Log.Debug(
                    $"[{_stampa.UIDStampa}] BACKGROUND MODE - Invio mail a Capo Gruppo e Segreteria Politica");
                var capoGruppo = await apiGateway.Persone.GetCapoGruppo(em.id_gruppo);

                var segreteriaPolitica = await apiGateway.Persone
                                         .GetSegreteriaPolitica(em.id_gruppo, false, true);

                if (segreteriaPolitica.Any())
                {
                    email_destinatariGruppo = segreteriaPolitica.Select(u => u.email)
                                              .Aggregate((i, j) => $"{i};{j}");
                }
                if (capoGruppo != null)
                {
                    email_destinatariGruppo += $";{capoGruppo.email}";
                }
            }
            else
            {
                Log.Debug($"[{_stampa.UIDStampa}] BACKGROUND MODE - Invio mail a Giunta Regionale");
                var giuntaRegionale = await apiGateway.Persone.GetGiuntaRegionale();

                var segreteriaGiuntaRegionale = await apiGateway.Persone
                                                .GetSegreteriaGiuntaRegionale(false, true);

                if (segreteriaGiuntaRegionale.Any())
                {
                    email_destinatariGiunta += segreteriaGiuntaRegionale.Select(u => u.email)
                                               .Aggregate((i, j) => $"{i};{j}");
                }
                if (giuntaRegionale.Any())
                {
                    email_destinatariGiunta +=
                        giuntaRegionale.Select(u => u.email).Aggregate((i, j) => $"{i};{j}");
                }
            }

            if (!string.IsNullOrEmpty(email_destinatariGruppo))
            {
                email_destinatari += ";" + email_destinatariGruppo;
            }
            if (!string.IsNullOrEmpty(email_destinatariGiunta))
            {
                email_destinatari += ";" + email_destinatariGiunta;
            }

            try
            {
                var resultInvio = await BaseGateway.SendMail(new MailModel
                {
                    DA      = _model.EmailFrom,
                    A       = email_destinatari,
                    OGGETTO =
                        $"{atto.TIPI_ATTO.Tipo_Atto} {atto.NAtto}: Depositato {listaEMendamenti.First().N_EM}",
                    MESSAGGIO      = bodyMail,
                    pathAttachment = destinazioneDeposito,
                    IsDeposito     = true
                },
                                                             _auth.jwt);

                if (resultInvio)
                {
                    await apiGateway.Stampe.JobSetInvioStampa(_stampa);
                }
            }
            catch (Exception e)
            {
                Log.Debug($"[{_stampa.UIDStampa}] Invio mail deposito", e);
                await apiGateway.Stampe.AddInfo(_stampa.UIDStampa, $"Invio mail deposito ERRORE. Motivo: {e.Message}");
            }
        }
Esempio n. 8
0
 /// <summary>
 /// 构造函数
 /// </summary>
 /// <param name="gateway">支付网关</param>
 public UnKnownNotifyEventArgs(BaseGateway gateway)
     : base(gateway)
 {
 }
 protected void FeedGateway(BaseGateway gateway)
 {
     FeedFlowNode(gateway);
     gateway.GatewayDirection = GatewayDirection;
 }
Esempio n. 10
0
 public CreateStudent()
 {
     InitializeComponent();
     _gatewaySchool  = new BaseGateway <School>();
     _gatewayStudent = new BaseGateway <Student>();
 }
Esempio n. 11
0
 /// <summary>
 /// 初始化未知网关事件数据
 /// </summary>
 /// <param name="gateway">支付网关</param>
 public UnknownGatewayEventArgs(BaseGateway gateway)
     : base(gateway)
 {
 }
Esempio n. 12
0
        public async Task SyncOrderStatus(string orderId)
        {
            var orderDTO = await _orderServiceProxy.GetById(orderId);

            if (orderDTO == null)
            {
                return;
            }

            BaseGateway gateway = null;

            if (string.IsNullOrEmpty(orderDTO.OrganizationId))
            {
                gateway = _gateways.Get <WechatpayGateway>();
            }
            else
            {
                WeChatAppConfiguration appConfig = _wechatAppConfigurationRepository.GetFiltered(o => o.OrganizationId == orderDTO.OrganizationId).FirstOrDefault();
                if (appConfig != null)
                {
                    var wechatpayMerchant = new PaySharp.Wechatpay.Merchant
                    {
                        AppId           = appConfig.AppId,
                        MchId           = appConfig.MchId,
                        Key             = appConfig.Key,
                        AppSecret       = appConfig.AppSecret,
                        SslCertPath     = appConfig.SslCertPath,
                        SslCertPassword = appConfig.SslCertPassword,
                        NotifyUrl       = appConfig.NotifyUrl
                    };

                    gateway = new WechatpayGateway(wechatpayMerchant);
                }
                else
                {
                    gateway = _gateways.Get <WechatpayGateway>();
                }
            }


            var request = new QueryRequest();

            request.AddGatewayData(new QueryModel()
            {
                OutTradeNo = orderDTO.OrderNo
            });

            var response = gateway.Execute(request);

            if (response.ReturnCode == "SUCCESS")
            {
                if (response.ResultCode == "SUCCESS")
                {
                    if (response.TradeState == TradeState.SUCCESS.ToString())
                    {
                        await _orderServiceProxy.SetOrderPaidSuccessed(orderId);
                    }
                    if (response.TradeState == TradeState.REVOKED.ToString() ||
                        response.TradeState == TradeState.CLOSED.ToString())
                    {
                        await _orderServiceProxy.SetOrderPaidFailed(orderId);
                    }
                }
            }
        }
Esempio n. 13
0
 public BaseService(BaseGateway <T> gateway, IValidator <T> validator)
 {
     Gateway   = gateway;
     Validator = validator;
 }
Esempio n. 14
0
 public BaseService()
 {
     Gateway   = new BaseGateway <T>();
     Validator = new Validator <T>();
 }
Esempio n. 15
0
 public MainController(BaseGateway <IMdApi, ITdApi> gateway)
 {
     this.Gateway = gateway;
     MainEvent    = new EventDefine();
 }
Esempio n. 16
0
 /// <summary>
 /// 初始化支付失败网关事件数据
 /// </summary>
 /// <param name="gateway">支付网关</param>
 public PayFailedEventArgs(BaseGateway gateway)
     : base(gateway)
 {
 }
Esempio n. 17
0
 public HomeController(BaseGateway context)
 {
     _context = context;
 }
Esempio n. 18
0
 public TeamService() : base(new TeamGateway(), new TeamValidator())
 {
     _gateway       = new TeamGateway();
     _schoolGateway = new BaseGateway <School>();
 }
Esempio n. 19
0
 /// <summary>
 /// 构造函数
 /// </summary>
 /// <param name="gateway">支付网关</param>
 public RefundSucceedEventArgs(BaseGateway gateway)
     : base(gateway)
 {
 }
Esempio n. 20
0
 public ArticulosController(BaseGateway context)
 {
     _context = context;
 }
Esempio n. 21
0
        public async Task <OpenIDSessionKeyDTO> GetSessionKey(string code, string organizationId = null, string applicationId = null)
        {
            WeChatOpenIdResponseDTO result = null;

            BaseGateway gateway = null;

            if (string.IsNullOrEmpty(organizationId))
            {
                gateway = _gateways.Get <WechatpayGateway>();
            }
            else
            {
                WeChatAppConfiguration appConfig = _wechatAppConfigurationRepository.GetFiltered(o => o.OrganizationId == organizationId).FirstOrDefault();
                if (appConfig != null)
                {
                    var wechatpayMerchant = new PaySharp.Wechatpay.Merchant
                    {
                        AppId           = appConfig.AppId,
                        MchId           = appConfig.MchId,
                        Key             = appConfig.Key,
                        AppSecret       = appConfig.AppSecret,
                        SslCertPath     = appConfig.SslCertPath,
                        SslCertPassword = appConfig.SslCertPassword,
                        NotifyUrl       = appConfig.NotifyUrl
                    };

                    gateway = new WechatpayGateway(wechatpayMerchant);
                }
                else
                {
                    gateway = _gateways.Get <WechatpayGateway>();
                }
            }

            var reqModel = new WeChatOpenIdRequestDTO {
                AppId = gateway.Merchant.AppId, Code = code, Secret = _configuration.WeChatAppSecret
            };

            result = await _wechatApiProxy.CheckAuthCode(reqModel);

            //TODO:验签

            AppletUserSessionDTO dto = null;

            if (result != null)
            {
                await _authServiceProxy.AddOrUpdateAppletUser(new AppletUserDTO
                {
                    ApplicationId  = applicationId,
                    Channel        = UserChannel.WeChat,
                    NickName       = "",
                    OpenId         = result.OpenId,
                    OrganizationId = organizationId,
                    UserId         = "",
                    UserPortrait   = ""
                });

                dto = await _authServiceProxy.AddOrUpdateAppletUserSession(new AppletUserSessionDTO
                {
                    UserId     = "",
                    OpenId     = result.OpenId,
                    SessionKey = result.SessionKey
                });
            }

            return(new OpenIDSessionKeyDTO {
                GooiosSessionKey = dto.GooiosSessionKey, OpenId = dto.OpenId
            });
        }
        private async Task Stampa(List <EmendamentiDto> listaEMendamenti, string path,
                                  PersonaDto utenteRichiedente)
        {
            try
            {
                var atto = await apiGateway.Atti.Get(_stampa.UIDAtto);

                if (_stampa.Da > 0 && _stampa.A > 0)
                {
                    listaEMendamenti = listaEMendamenti.GetRange(_stampa.Da - 1, _stampa.A - (_stampa.Da - 1));
                }

                var bodyCopertina = await apiGateway.Emendamento.GetCopertina(new CopertinaModel
                {
                    Atto        = atto,
                    TotaleEM    = listaEMendamenti.Count,
                    Ordinamento = _stampa.Ordine.HasValue
                        ? (OrdinamentoEnum)_stampa.Ordine.Value
                        : OrdinamentoEnum.Presentazione
                });

                var nameFilePDFCopertina = $"COPERTINAEM_{DateTime.Now:ddMMyyyy_hhmmss}.pdf";
                var DirCopertina         = Path.Combine(path, nameFilePDFCopertina);
                PdfStamper.CreaPDFCopertina(bodyCopertina, DirCopertina);
                await apiGateway.Stampe.AddInfo(_stampa.UIDStampa, "Copertina generata");

                var listaPdfEmendamentiGenerati =
                    await GeneraPDFEmendamenti(listaEMendamenti, path);

                var countNonGenerati = listaPdfEmendamentiGenerati.Count(item => !File.Exists(item.Value.Path));
                await apiGateway.Stampe.AddInfo(_stampa.UIDStampa, $"PDF NON GENERATI [{countNonGenerati}]");

                //Funzione che fascicola i PDF creati prima
                var nameFileTarget = $"Fascicolo_{DateTime.Now:ddMMyyyy_hhmmss}.pdf";
                var FilePathTarget = Path.Combine(path, nameFileTarget);
                PdfStamper.CreateMergedPDF(FilePathTarget, DirCopertina,
                                           listaPdfEmendamentiGenerati.ToDictionary(item => item.Key, item => item.Value.Path));
                await apiGateway.Stampe.AddInfo(_stampa.UIDStampa, "FASCICOLAZIONE COMPLETATA");

                var _pathStampe = Path.Combine(_model.CartellaLavoroStampe, nameFileTarget);
                Log.Debug($"[{_stampa.UIDStampa}] Percorso stampe {_pathStampe}");
                SpostaFascicolo(FilePathTarget, _pathStampe);

                var URLDownload = Path.Combine(_model.UrlCLIENT, $"stampe/{_stampa.UIDStampa}");
                _stampa.PathFile = nameFileTarget;
                await apiGateway.Stampe.JobUpdateFileStampa(_stampa);

                if (_stampa.Scadenza.HasValue)
                {
                    try
                    {
                        var bodyMail    = $"Gentile {utenteRichiedente.DisplayName},<br>la stampa richiesta sulla piattaforma PEM è disponibile al seguente link:<br><a href='{URLDownload}' target='_blank'>{URLDownload}</a>";
                        var resultInvio = await BaseGateway.SendMail(new MailModel
                        {
                            DA        = _model.EmailFrom,
                            A         = utenteRichiedente.email,
                            OGGETTO   = "Link download fascicolo",
                            MESSAGGIO = bodyMail
                        },
                                                                     _auth.jwt);

                        if (resultInvio)
                        {
                            await apiGateway.Stampe.JobSetInvioStampa(_stampa);
                        }
                    }
                    catch (Exception e)
                    {
                        Log.Debug($"[{_stampa.UIDStampa}] Invio mail", e);
                        await apiGateway.Stampe.AddInfo(_stampa.UIDStampa, $"Invio mail ERRORE. Motivo: {e.Message}");
                    }
                }
                else
                {
                    if (_stampa.Ordine.HasValue)
                    {
                        if ((OrdinamentoEnum)_stampa.Ordine.Value == OrdinamentoEnum.Presentazione)
                        {
                            atto.LinkFascicoloPresentazione = URLDownload;
                        }
                        if ((OrdinamentoEnum)_stampa.Ordine.Value == OrdinamentoEnum.Votazione)
                        {
                            atto.LinkFascicoloVotazione = URLDownload;
                        }
                        await apiGateway.Atti.ModificaFiles(atto);
                    }
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                throw e;
            }
        }
Esempio n. 23
0
 /// <summary>
 /// 构造函数
 /// </summary>
 /// <param name="gateway">支付网关</param>
 public CancelSucceedEventArgs(BaseGateway gateway)
     : base(gateway)
 {
 }
        public async Task ExecuteAsync(StampaDto stampa)
        {
            _stampa = stampa;
            var utenteRichiedente = await apiGateway.Persone.Get(_stampa.UIDUtenteRichiesta);

            try
            {
                await apiGateway.Stampe.AddInfo(_stampa.UIDStampa,
                                                $"Inizio lavorazione - Tentativo {_stampa.Tentativi} di {_model.NumMaxTentativi}");

                if (_stampa.Tentativi < Convert.ToInt16(_model.NumMaxTentativi))
                {
                    //GetFascicolo
                    var path = string.Empty;
                    GetFascicolo(ref path);
                    //

                    //GetListEM
                    var listaEMendamenti = await GetListaEM();

                    //

                    if (_stampa.NotificaDepositoEM)
                    {
                        await DepositoDifferito(listaEMendamenti, path, utenteRichiedente);
                    }
                    else
                    {
                        await Stampa(listaEMendamenti, path, utenteRichiedente);
                    }

                    PulisciCartellaLavoroTemporanea(path);
                }
                else
                {
                    try
                    {
                        await BaseGateway.SendMail(new MailModel
                        {
                            DA        = _model.EmailFrom,
                            A         = utenteRichiedente.email,
                            OGGETTO   = "Errore generazione stampa",
                            MESSAGGIO = $"ID stampa: [{_stampa.UIDStampa}], per l'atto: [{_stampa.UIDAtto}]"
                        },
                                                   _auth.jwt);
                    }
                    catch (Exception e)
                    {
                        Log.Debug($"[{_stampa.UIDStampa}] Invio mail EXCEPTION", e);
                        await apiGateway.Stampe.AddInfo(_stampa.UIDStampa, $"Invio mail EXCEPTION ERRORE. Motivo: {e.Message}");
                    }
                }

                OnWorkerFinish?.Invoke(this, true);
            }
            catch (Exception ex)
            {
                OnWorkerFinish?.Invoke(this, false);

                Log.Error($"[{_stampa.UIDStampa}] ERROR", ex);
                try
                {
                    await apiGateway.Stampe.JobErrorStampa(_stampa.UIDStampa, ex.Message);

                    await apiGateway.Stampe.JobUnLockStampa(_stampa.UIDStampa);
                }
                catch (Exception ex2)
                {
                    Log.Error($"[{_stampa.UIDStampa}] ERROR", ex2);
                    try
                    {
                        await BaseGateway.SendMail(new MailModel
                        {
                            DA        = _model.EmailFrom,
                            A         = utenteRichiedente.email,
                            OGGETTO   = "Errore generazione fascicolo",
                            MESSAGGIO = ex.Message
                        },
                                                   _auth.jwt);
                    }
                    catch (Exception exMail)
                    {
                        Log.Error($"[{_stampa.UIDStampa}] ERROR", exMail);
                        await apiGateway.Stampe.JobErrorStampa(_stampa.UIDStampa, exMail.Message);
                    }
                }
            }
        }
Esempio n. 25
0
 public SendEventResult(BaseGateway gateway, bool success)
 {
     Gateway = gateway;
     Success = success;
 }