private static void PutPersonas(List<PersonaRequestModel> personas) { var client = new RestClient("http://localhost:60694/api/"); var request = new RestRequest("Personas", Method.PUT); var jsonSerializer = new RestSharp.Serialization.Json.JsonSerializer(); var serializedList = jsonSerializer.Serialize(personas); request.AddParameter("text/json", serializedList, ParameterType.RequestBody); var response = client.Execute(request); if (response.StatusCode != System.Net.HttpStatusCode.OK) { var responseObject = JsonConvert.DeserializeObject<Error>(response.Content); Console.WriteLine(responseObject.Message); Console.ReadLine(); } else { var responseObject = JsonConvert.DeserializeObject<List<string>>(response.Content); if(responseObject != null || responseObject.Count() > 0) { Console.WriteLine("Las personas Mujeres mayores a 18 años son: "); foreach (var personaResult in responseObject) { Console.WriteLine(personaResult); } } else { Console.WriteLine("No hubo personas Mujeres mayores a 18 años. "); } } Console.ReadLine(); }
static void Main() { serializer = new RestSharp.Serialization.Json.JsonSerializer(); var connection = new ConnectionBuilder() .WithLogging() .Build(); // expects a request named "greeting" with a string argument and returns a string connection.On <string, string>("login", data => { /** * client_id * client_secret * username * password * path to file * login url * **/ string[] args = JsonConvert.DeserializeObject <string[]>(data); ////check number of arguments passed to applicaiton if (args.Length < 6) { ////Console.WriteLine("You dind't pass all necessary parameters"); throw new ArgumentException(Help()); } String Username = args[0]; String Password = args[1]; String ClientID = args[2]; String ClientSecret = args[3]; String LoginUrl = args[4]; csv = args[5]; //create necessary directories SetupDirs(); if (!File.Exists(csv)) { throw new FileNotFoundException("The file was not found!", csv); } Logger = new FileLogger("logs"); SFDC = new Salesforce.Salesforce(ClientID, ClientSecret, Username, Password, LoginUrl, Logger); SFDC.Login(); parser = new CSVThread(csv, Logger, SFDC); return($"Logged to salesforce instance: {SFDC.InstanceUrl}"); }); connection.On <string, string>("initialize", data => { /** * token * instance_url * file_path **/ string[] args = JsonConvert.DeserializeObject <string[]>(data); //check number of arguments passed to applicaiton if (args.Length < 3) { throw new ArgumentException("Caramba, not enough parameters"); } String Token = args[0]; String InstanceUrl = args[1]; String CSV = args[2]; if (!File.Exists(CSV)) { throw new FileNotFoundException("The file was not found!", CSV); } SetupDirs(); Logger = new FileLogger("logs"); SFDC = new Salesforce.Salesforce(Token, InstanceUrl, Logger); parser = new CSVThread(CSV, Logger, SFDC); return($"Logged to salesforce instance: {SFDC.InstanceUrl}"); }); connection.On <string>("getSFDCObjects", () => { List <Sobject> sobjects = SFDC.RetrieveObjects(); return(serializer.Serialize(sobjects)); }); connection.On <string>("getHeaderRow", () => { return(serializer.Serialize(parser.Header.Values.ToList())); }); connection.On <string, string>("getMetadata", fields => { string[] args = JsonConvert.DeserializeObject <string[]>(fields); foreach (string name in args) { SFDC.RetrieveMetadata(name); } Dictionary <String, List <string> > data = SFDC.getMetadata(); return(serializer.Serialize(data)); }); connection.On <string, string>("parse", mapping => { SFDC.SetMapping(mapping, parser.Header); parser.Parse(); return("{\"x\":" + Salesforce.Salesforce.BatchSize + "}"); }); connection.On <string>("getStatus", () => { bool ready = parser.IsReady(); Dictionary <string, string> response = new Dictionary <string, string>(); //Boolean x = false; //response.Add("isReady", x.ToString()); //response.Add("all", "100"); //response.Add("error", "10"); //response.Add("success", "90"); response.Add("isReady", ready.ToString()); response.Add("all", parser.Size.ToString()); response.Add("processed", parser.Processed.ToString()); return(serializer.Serialize(response)); }); connection.On <string>("saveLogs", () => { Logger.Save(); return("{}"); }); // wait for incoming requests connection.Listen(); }