Ejemplo n.º 1
0
        public static void SendEmail(string sendmessage, ConfigSmtp config)
        {
            try
            {
                MailMessage message = new MailMessage();
                SmtpClient  smtp    = new SmtpClient();
                //message setting
                message.From = new MailAddress(config.emailcredencial);
                message.To.Add(new MailAddress(config.email));

                message.Subject    = "Alert Quote";
                message.IsBodyHtml = false;
                message.Body       = sendmessage;
                //smtp setting
                smtp.Port                  = config.port;
                smtp.Host                  = config.host;
                smtp.EnableSsl             = true;
                smtp.UseDefaultCredentials = false;
                smtp.Credentials           = new NetworkCredential(config.emailcredencial, config.password);
                smtp.DeliveryMethod        = SmtpDeliveryMethod.Network;
                smtp.Send(message);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.ToString());
            }
        }
Ejemplo n.º 2
0
 public static ConfigSmtp HandleConfigJson()
 {
     using (StreamReader r = new StreamReader("../../configSmtp.json"))
     {
         var        json   = r.ReadToEnd();
         ConfigSmtp config = JsonConvert.DeserializeObject <ConfigSmtp>(json);
         return(config);
     }
 }
Ejemplo n.º 3
0
        static int Main(string[] args)
        {
            string[] symbols = { "ABEV3", "AZUL4", "BTOW3", "B3SA3", "BBSE3", "VRML3", "BBDC4", "BBDC3", "PETR4", "PETR3", "BRDT3", "QUAL3", "RADL3", "RAIL3", "SBSP3", "BIDI4" };

            // Getting value of stock
            string symbol = args[0];

            if ((args.Length) != 3)
            {
                Console.WriteLine("Please enter a valid argument params");
                Console.WriteLine("Usagename: prototype <PETR4> <num_max> <num_min>");
                return(0);
            }
            if (!(symbols.Contains(symbol)))
            {
                Console.WriteLine("Invalid stock input");
                return(0);
            }
            else
            {
                //Getting url
                string url = Function.GetURL(symbol);

                // Convert values of max quote and min quote
                double num_max;
                double num_min;
                double.TryParse(args[1], out num_max);
                double.TryParse(args[2], out num_min);

                //Print Result
                Console.WriteLine($"The stock {symbol} is being tracked.");
                Console.WriteLine($"The max price is {num_max} and the min price is {num_min}.");

                string server       = "webfeeder.cedrotech.com";
                string login        = "******";
                string password     = "******";
                string urlParameter = "http://" + server + "/SignIn?login="******"&password="******"http://webfeeder.cedrotech.com/services/quotes/quote/";

                        string urlquote = urlquote_base + symbol;

                        //Getting stock response
                        Task <string> resp = Function.GetStock(urlParameter, urlquote);

                        string response = resp.Result;

                        Quote handledResponse = Function.HandleResponse(response);

                        price = handledResponse.lastTrade;

                        condition = !(num_max <price | num_min> price);

                        //time sleep
                        Thread.Sleep(120000);
                        Console.WriteLine($"The stock {symbol} is being tracking.");
                    } while (condition);

                    //handling alert message

                    string msgemail;

                    if (num_max < price)
                    {
                        msgemail = $"O papel {symbol} pode ser vendido no valor de {price}.";
                    }
                    else
                    {
                        msgemail = $"O papel {symbol} pode ser comprado no valor de {price}.";
                    }

                    //handle ConfigSmtp
                    ConfigSmtp config = Function.HandleConfigJson();

                    //Send email;
                    Function.SendEmail(msgemail, config);
                }
                return(0);
            }
        }