private void btnConcluir_Click(object sender, EventArgs e) { if (String.IsNullOrEmpty(txbCPF.Text) || String.IsNullOrEmpty(txbSenha.Text)) { MessageBox.Show("Preencha todos os campos."); return; } Vip = new Vip() { CPF = txbCPF.Text, Senha = txbSenha.Text }; Close(); }
/// <summary> /// Registra uma lista de selos e retorna uma cópia da lista com o estado dos /// selos atualizados. Caso haja algum problema durante o processo o método /// retorna nulo. /// </summary> /// <param name="vip"></param> /// <param name="lista"></param> /// <returns></returns> public List<Selo> RegistrarSelos(Vip vip, List<Selo> lista) { this.vip = vip; this.novosSelos = new List<Selo>(); this.selos = lista; progresso = new DadosProgresso(lista.Count, 0, 0); barProgresso.Maximum = 0; barProgresso.Maximum = progresso.TotalSelos; AtualizarProgresso(); Task tarefa = new Task(Registrar); tarefa.Start(); ShowDialog(); return novosSelos; }
public static string Serializar(Vip vip) { string objSerializado = null; DataContractSerializer dcs = new DataContractSerializer(typeof(Vip)); using (Stream memoria = new MemoryStream()) { dcs.WriteObject(memoria, vip); memoria.Seek(0, SeekOrigin.Begin); using (StreamReader reader = new StreamReader(memoria)) { objSerializado = reader.ReadToEnd(); } } return objSerializado; }
private void executar() { ClubVipAPI site = new SiteClubVip(); site.SeloRegistrado += onSeloRegistrado; site.RegistroConcluido += onRegistroTerminado; Vip v = new Vip() { CPF = "11175899607", Senha = "9145" }; List<Selo> selos = new List<Selo>() { new Selo() { Codigo = "00000" }, new Selo() { Codigo = "11111" }, new Selo() { Codigo = "22222" }, new Selo() { Codigo = "33333" }, new Selo() { Codigo = "44444" }, new Selo() { Codigo = "55555" } }; Msg("Registrando selo ..."); try { site.RegistrarSelos(v, selos); Msg("Registrando selo [OK]"); } catch (ClubVip.Servico.Excecoes.LoginInvalido excpt) { Msg(excpt.Message); } Console.ReadKey(); }
private void btnCancelar_Click(object sender, EventArgs e) { Vip = null; Close(); }
private void IniciarServico() { //REGISTRAR BROADCAST broadcast = new ClubVipBroadCast(); broadcast.SeloRegistrado += SeloRegistrado; broadcast.RegistroConcluido += RegistroConcluido; broadcast.RegistroCancelado += RegistroCancelado; broadcast.AutenticacaoConcluida += AutenticacaoConcluida; IntentFilter intentFilter = new IntentFilter(); intentFilter.AddAction(ClubVipService.ACTION_SELO_REGISTRADO); intentFilter.AddAction(ClubVipService.ACTION_REGISTRO_CONCLUIDO); intentFilter.AddAction(ClubVipService.ACTION_REGISTRO_CANCELADO); intentFilter.AddAction(ClubVipService.ACTION_AUTENTICADO); RegisterReceiver(broadcast, intentFilter); //INICIAR SERVIÇO Vip vip = new Vip() { CPF = "11175899607", Senha = "9145" }; Intent serviceIntent = new Intent(this, typeof(ClubVipService)); serviceIntent.PutExtra(ClubVipService.EXTRA_VIP, WrapperVip.Serializar(vip)); serviceIntent.PutExtra(ClubVipService.EXTRA_LISTA_SELOS, WrapperSelo.SerializarLista(listaSelos)); StartService(serviceIntent); registrando = true; }
/// <summary> /// Registra uma lista de selos. Cada selo registrado aciona o evento "SeloRegistrado" que recebe uma cópia do selo. /// Ao termino do registro o evento "RegistroTerminado é acionado". /// Os selos da lista passada como parâmetro não são alterados. /// </summary> /// <param name="vip">Vip que irá receber os selos</param> /// <param name="selos">Selos a serem registrados</param> public override void RegistrarSelos(Vip vip, List<Selo> selos) { //Task<HttpResponseMessage> tarefaRequest; CookieContainer conteiner = new CookieContainer(); EstadoSelo estadoSelo = EstadoSelo.Nulo; using (HttpClientHandler handler = new HttpClientHandler() { CookieContainer = conteiner }) { using (HttpClient cliente = new HttpClient(handler)) { cliente.BaseAddress = new System.Uri(BASE_URI); HttpResponseMessage resposta; cancelar = false; #region Login /* Tentando corrigir um bug que ocorre durante o login no site do clubvip. Mesmo quando o usuário e senha estão corretos o site vai para página principal, loga, entratanto retorna a página de login. CASO O BUG SENHA RESOLVIDO APENAS AS LINHAS MARCADAS COM EXCLAMAÇÃO DEVEM SER MANTIDAS. */ int contarnarSiteBug = 3; while (contarnarSiteBug > 0) { //!!!!!!!!!!!!!!!!!!!!!!!!!!!! resposta = Logar(cliente, vip); try { //!!!!!!!!!!!!!!!!!!!!!!!!!!!! GarantirLoginSucesso(resposta); contarnarSiteBug = -1; } catch (Excecoes.ErroAcessoSite excpt) { contarnarSiteBug--; if (contarnarSiteBug == 0) throw excpt; } } /* fim correção de bug */ #endregion if (eventoAutenticacaoConcluida != null) eventoAutenticacaoConcluida(); string uriPostSelo = null; foreach (Selo selo in selos) { if (cancelar) { if (eventoRegistroCancelado != null) eventoRegistroCancelado(); return; } resposta = ObterPaginaRegistro(cliente); ChecarErrosAcesso(resposta); uriPostSelo = String.Format(URI_SELOS, ObterIDUriSelos(resposta)); resposta = Registrar(cliente, uriPostSelo, selo); estadoSelo = VerificarRegistro(resposta); if (eventoSeloRegistrado != null) { Selo novoSelo = selo.Clone(); novoSelo.Estado = estadoSelo; eventoSeloRegistrado(novoSelo); } } if (eventoRegistroConcluido != null) eventoRegistroConcluido(); } } }
private HttpResponseMessage Logar(HttpClient cliente, Vip vip) { //POST: logar no site List<KeyValuePair<string, string>> parametros = new List<KeyValuePair<string, string>>(); parametros.Add(new KeyValuePair<string, string>(PARAMETRO_CPF, vip.CPF)); parametros.Add(new KeyValuePair<string, string>(PARAMETRO_SENHA, vip.Senha)); HttpContent conteudo = new FormUrlEncodedContent(parametros); Task<HttpResponseMessage> tarefaRequest = cliente.PostAsync(URI_LOGIN, conteudo); tarefaRequest.Wait(); HttpResponseMessage resposta = tarefaRequest.Result; resposta.EnsureSuccessStatusCode(); return resposta; }
public abstract void RegistrarSelos(Vip vip, List<Selo> selos);