static void Main(string[] args) { PagarMeService.DefaultApiKey = "DEFINA_AQUI"; PagarMeService.DefaultEncryptionKey = "DEFINA_AQUI"; Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine("PagarMe API Prove of Concept (PoCs)"); Boolean Continue = true; try { PoCs = GetPoCs(); while (Continue) { ShowMenu(); Int32 Option; Int32.TryParse(ConsoleResponse, out Option); if (Option != 0 && Option <= PoCs.Count) { Console.ForegroundColor = ConsoleColor.Green; Option--; IPoC PoC = PoCFactory.Construct(PoCs[Option].Name); PoC.Create(); Console.WriteLine(PoC.Title); Model Model = PoC.GetModel(); String JsonObject = JsonConvert.SerializeObject(Model.ToDictionary(SerializationType.Full)); Console.Write("Id Gerado: "); Console.ForegroundColor = ConsoleColor.Cyan; Console.Write(Model.Id); Console.WriteLine(""); Console.ForegroundColor = ConsoleColor.Green; Console.Write("Objeto Gerado: "); Console.ForegroundColor = ConsoleColor.Cyan; Console.Write(JsonObject); } else { Continue = false; } } } catch (PagarMeException ex) { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine(""); foreach (PagarMeErrorDetail erro in ex.Error.Errors) { Console.WriteLine(String.Format("ERRO: {1}", erro.Parameter, erro.Message)); } Console.ReadKey(); } }
public static IPoC Construct(String PoCName) { IPoC objPoc = null; Assembly a = Assembly.GetExecutingAssembly(); string typeName = a.GetName().Name + ".Entities." + PoCName; objPoc = (IPoC)a.CreateInstance(typeName, true); return(objPoc); }