Пример #1
0
        public void LoadClassMappingConfigFromAdmissionApi()
        {
            var serializer  = new JsonSerializer();
            var errorLogger = new ErrorLogger();
            var cache       = new InMemoryCache();
            var client      = new AdmissionClassesClient(cache, serializer, errorLogger);
            int appFormId   = (int)cboApplicationForm.SelectedValue;

            _admisionApiClassMappingConfig = client.GetClasses(appFormId, MisCache.UserEmail, MisCache.UserToken);
        }
Пример #2
0
        public void LoadStudents(int appFormId)
        {
            var serializer  = new JsonSerializer();
            var errorLogger = new ErrorLogger();
            var client      = new AdmissionStudentsClient(serializer, errorLogger);

            var students = client.GetStudents(appFormId, MisCache.UserEmail, MisCache.UserToken);
            //var studentsGridDataSource = students.Where(x => !string.IsNullOrEmpty(x.class_list)).ToList();
            var studentsGridDataSource = students;

            studentsGrid.DataSource = studentsGridDataSource;
            MisCache.Students       = studentsGridDataSource;
        }
Пример #3
0
        public static void LoadApplicationForm(ComboBox cboApplicationForm)
        {
            var serializer  = new JsonSerializer();
            var errorLogger = new ErrorLogger();
            var client      = new AdmissionApplicationFormClient(serializer, errorLogger);
            List <ApplicationFormsItem> appForms = client.GetApplicationForms(MisCache.UserEmail, MisCache.UserToken);

            cboApplicationForm.DataSource    = appForms;
            cboApplicationForm.ValueMember   = "id";
            cboApplicationForm.DisplayMember = "name";


            cboApplicationForm.SelectedValue = 1;
        }
Пример #4
0
        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();
        }
Пример #5
0
        public void PreparePayload(String[] data, int line)
        {
            Dictionary <string, Dictionary <string, object> > body = new Dictionary <string, Dictionary <string, object> >();
            Record parent = new Record();

            int i = 0;

            foreach (String value in data)
            {
                //only if field was mapped
                if (Mapping.ContainsKey(i))
                {
                    MappingPayload.Mapping map = Mapping[i];

                    Dictionary <string, object> dataset = new Dictionary <string, object>();
                    dataset.Add(map.toColumn, value);

                    if (body.ContainsKey(map.toObject))
                    {
                        body[map.toObject].Add(map.toColumn, value);
                    }
                    else
                    {
                        body.Add(map.toObject, dataset);
                    }
                }
                i++;
            }

            parent.attributes.Add("type", ParentObject);
            parent.attributes.Add("referenceId", ParentObject + line.ToString());

            RestSharp.Serialization.Json.JsonSerializer serializer = new RestSharp.Serialization.Json.JsonSerializer();

            parent.fields = body[ParentObject];

            List <Record>  records  = new List <Record>();
            SalesforceBody children = new SalesforceBody();

            foreach (KeyValuePair <string, Dictionary <string, object> > entry in body)
            {
                if (entry.Key == ParentObject)
                {
                    continue;
                }

                Record child = new Record();

                child.attributes.Add("type", entry.Key);
                child.attributes.Add("referenceId", entry.Key + line.ToString());
                child.fields = entry.Value;

                children.records = records;
                parent.children.Add(Meta[entry.Key].labelPlural, new SalesforceBody(child));
            }

            this.body.records.Add(parent);

            if (this.body.records.Count >= BatchSize)
            {
                flush();
            }
        }
Пример #6
0
        private void timer1_Tick(object sender, EventArgs e)
        {
            var cache         = new JsonSerializer();
            var fireAntClient = new FireAntClient(cache, new ErrorLogger());

            string symbol = txtSymbol.Text;

            var intradayItems = fireAntClient.GetIntraday(symbol);

            intradayItems.Reverse();

            var pricing = intradayItems.Select(current => new
            {
                Date    = DateTime.Parse(current.Date).ToString("HH:mm:ss"),
                Price   = current.Price,
                Volumne = current.Volume,
                Side    = GetSideText(current.Side)
            }).ToList();

            dataGridView1.DataSource = pricing;

            if (!pricing.Any())
            {
                return;
            }

            IntraDayQuotes latestPrice = intradayItems.First();

            var currentPrice = latestPrice.Price;

            txtLogging.AppendText($"{DateTime.Now.ToString()} - Total Volume : {latestPrice.TotalVolume}" + Environment.NewLine);


            var jsonBody = PopulateDetailStockPring(latestPrice);

            // check price to BUY
            if (currentPrice <= float.Parse(txtPriceToBuy.Text))
            {
                string subject = $"BUY {symbol} - {currentPrice}";
                if (chkSendNotification.Checked)
                {
                    SendNotification(subject, $"BUY {symbol} for NOW. <br/>" + jsonBody);
                }
                txtLogging.AppendText($"{DateTime.Now.ToString()} - {subject}" + Environment.NewLine);

                DisableTimer();
            }

            // check price to SELL
            if (currentPrice >= float.Parse(txtPriceToSell.Text))
            {
                string subject = $"SELL {symbol} - {currentPrice}";
                if (chkSendNotification.Checked)
                {
                    SendNotification($"SELL {symbol} - {currentPrice}", $"SELL {symbol} for NOW. <br/>" + jsonBody);
                }
                txtLogging.AppendText($"{DateTime.Now.ToString()} - {subject}" + Environment.NewLine);

                DisableTimer();
            }
        }
Пример #7
0
        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();
        }