Exemple #1
0
        internal void TestSendingEmailAndPhoneCall()
        {
            Console.WriteLine("TestSendingEmail started.");
            Utils.Logger.Info("TestSendingEmail() START");
            DailyMorningTimer_Elapsed(null);

            //string biduDelayedPriceCSV = new WebClient().DownloadString("http://download.finance.yahoo.com/d/quotes.csv?s=BIDU&f=sl1d1t1c1ohgv&e=.csv");
            //string biduDelayedPriceCSV = new WebClient().DownloadString("http://finance.yahoo.com/d/quotes.csv?s=BIDU&f=sl1d1t1c1ohgv&e=.csv");
            var biduDelayedPriceCSV = new HttpClient().GetStringAsync("http://finance.yahoo.com/d/quotes.csv?s=BIDU&f=sl1d1t1c1ohgv&e=.csv").Result;
            string[] biduDelayedPriceSplit = biduDelayedPriceCSV.Split(new char[] { ',', ' ' });
            double realTimePrice = Double.Parse(biduDelayedPriceSplit[1]);

            double dailyChange = Double.Parse(biduDelayedPriceSplit[4]);
            double yesterdayClose = realTimePrice - dailyChange;
            double todayPercentChange = realTimePrice / yesterdayClose - 1;
            Console.WriteLine("BIDU %change: " + (todayPercentChange * 100).ToString("0.00") + @"%");
            Utils.Logger.Info("BIDU %change: " + (todayPercentChange * 100).ToString("0.00") + @"%");
            //if (Math.Abs(todayPercentChange) >= 0.04)
            if (Math.Abs(todayPercentChange) >= 0.00)
            {
                new Email { ToAddresses = Utils.Configuration["EmailGyantal"], Subject = "OvermindServer: BIDU price % move", Body = "BIDU price % move. In percentage: " + (todayPercentChange * 100).ToString("0.00") + @"%", IsBodyHtml = false }.Send();

                Console.WriteLine("Email was sent.");
                Utils.Logger.Info("Email was sent.");

                var call = new PhoneCall
                {
                    FromNumber = Caller.Gyantal,
                    ToNumber = PhoneCall.PhoneNumbers[Caller.Gyantal],
                    Message = "This is a warning notification from SnifferQuant. There's a large up or down movement in the ticker B I D U. ... I repeat the ticker: B I D U.",
                    NRepeatAll = 2
                };
                // skipped temporarily
                bool phoneCallSuccess = call.MakeTheCall();
                Console.WriteLine("Phonecall success: " + phoneCallSuccess);
                Utils.Logger.Info("Phonecall success: " + phoneCallSuccess);
            }

            Console.WriteLine("TestSendingEmail Finished.");
            Utils.Logger.Info("TestSendingEmail() END");
        }
Exemple #2
0
        private void InformSupervisors(string p_emailSubject, string p_emailBody, string p_phonecallText, ref Object p_informSupervisorLock, ref DateTime p_lastEmailTime, ref DateTime p_lastPhoneCallTime)
        {
            bool doInformSupervisors = false;
            lock (p_informSupervisorLock)   // if InformSupervisors is called on two different threads at the same time, (if VBroker notified us twice very quickly), we still want to inform user only once
            {
                TimeSpan timeFromLastEmail = DateTime.UtcNow - p_lastEmailTime;
                if (timeFromLastEmail > TimeSpan.FromMinutes(10))
                {
                    doInformSupervisors = true;
                    p_lastEmailTime = DateTime.UtcNow;
                }
            }

            if (!doInformSupervisors)
                return;

            Utils.Logger.Info("InformSupervisors(). Sending Warning email.");
            try
            {
                new Email
                {
                    ToAddresses = Utils.Configuration["EmailGyantal"],
                    Subject = p_emailSubject,
                    Body = p_emailBody,
                    IsBodyHtml = true
                    //IsBodyHtml = false        // has problems with exceptions : /bin/bash: -c: line 1: syntax error near unexpected token `('
                }.Send();
            }
            catch (Exception e)
            {
                Utils.Logger.Error(e, "InformSupervisors() email sending is crashed, but we still try to make the PhoneCall.");
            }


            if (!IsRunningAsLocalDevelopment() && !String.IsNullOrEmpty(p_phonecallText))
            {
                Utils.Logger.Info("InformSupervisors(). Making Phonecall.");

                TimeSpan timeFromLastCall = DateTime.UtcNow - p_lastPhoneCallTime;
                if (timeFromLastCall > TimeSpan.FromMinutes(30))
                {
                    var call = new PhoneCall
                    {
                        FromNumber = Caller.Gyantal,
                        ToNumber = PhoneCall.PhoneNumbers[Caller.Gyantal],
                        Message = p_phonecallText,
                        NRepeatAll = 2
                    };
                    // skipped temporarily
                    bool didTwilioAcceptedTheCommand = call.MakeTheCall();
                    if (didTwilioAcceptedTheCommand)
                    {
                        Utils.Logger.Debug("PhoneCall instruction was sent to Twilio.");
                        p_lastPhoneCallTime = DateTime.UtcNow;
                    }
                    else
                        Utils.Logger.Error("PhoneCall instruction was NOT accepted by Twilio.");
                }
            }


        }
Exemple #3
0
        public void DailyMiddayTimer_Elapsed(object p_sender) // Timer is coming on a ThreadPool thread
        {
            Utils.Logger.Info("DailyMiddayTimer_Elapsed() BEGIN");
            Console.WriteLine(DateTime.UtcNow.ToString("MM'-'dd H:mm:ss", CultureInfo.InvariantCulture) + " : DailyMiddayTimer_Elapsed() BEGIN");
            try
            {
                if (m_dailyMiddayTimer != null)
                {
                    TimeSpan ts = GetNextDailyTimerIntervalMsec(g_DailyMiddayTimerTime);
                    m_dailyMiddayTimer.Change(ts, TimeSpan.FromMilliseconds(-1.0));
                    Utils.Logger.Info("m_dailyMarketWatcherTimer is scheduled at " + (DateTime.UtcNow + ts).ToString("MM'-'dd H:mm:ss", CultureInfo.InvariantCulture));
                }

                // TODO: if market holiday: it shouldn't process anything either
                if (DateTime.UtcNow.DayOfWeek == DayOfWeek.Saturday || DateTime.UtcNow.DayOfWeek == DayOfWeek.Sunday)
                {
                    Utils.Logger.Debug("DailyMiddayTimer_Elapsed(). Weekend is detected. Don't do a thing.");
                    return;
                }

                string gyantalEmailInnerlStr = String.Empty;
                string gyantalPhoneCallInnerStr = String.Empty;
                string charmatEmailInnerlStr = String.Empty;
                string charmatPhoneCallInnerStr = String.Empty;

                double biduTodayPctChange = GetTodayPctChange("BIDU");
                if (Math.Abs(biduTodayPctChange) >= 0.04)
                {
                    gyantalEmailInnerlStr += "BIDU price warning: bigger than usual move. In percentage: " + (biduTodayPctChange * 100).ToString("0.00") + @"%." + Environment.NewLine;
                    gyantalPhoneCallInnerStr += "the ticker B I D U, ";
                }
                double vxxTodayPctChange = GetTodayPctChange("VXX");
                if (Math.Abs(vxxTodayPctChange) >= 0.06)
                {
                    gyantalEmailInnerlStr += "VXX price warning: bigger than usual move. In percentage: " + (vxxTodayPctChange * 100).ToString("0.00") + @"%";
                    gyantalPhoneCallInnerStr += "the ticker V X X ";
                    charmatEmailInnerlStr += "VXX price warning: bigger than usual move. In percentage: " + (vxxTodayPctChange * 100).ToString("0.00") + @"%";
                    charmatPhoneCallInnerStr += "the ticker V X X ";
                }

                double fbTodayPctChange = GetTodayPctChange("FB");
                if (Math.Abs(fbTodayPctChange) >= 0.04)
                {
                    charmatEmailInnerlStr += "Facebook price warning: bigger than usual move. In percentage: " + (fbTodayPctChange * 100).ToString("0.00") + @"%." + Environment.NewLine;
                    charmatPhoneCallInnerStr += "the ticker Facebook, ";
                }

                double amznTodayPctChange = GetTodayPctChange("AMZN");
                if (Math.Abs(amznTodayPctChange) >= 0.04)
                {
                    charmatEmailInnerlStr += "Amazon price warning: bigger than usual move. In percentage: " + (amznTodayPctChange * 100).ToString("0.00") + @"%." + Environment.NewLine;
                    charmatPhoneCallInnerStr += "the ticker Amazon, ";
                }

                double googleTodayPctChange = GetTodayPctChange("FB");
                if (Math.Abs(googleTodayPctChange) >= 0.04)
                {
                    charmatEmailInnerlStr += "Google price warning: bigger than usual move. In percentage: " + (googleTodayPctChange * 100).ToString("0.00") + @"%." + Environment.NewLine;
                    charmatPhoneCallInnerStr += "the ticker Google, ";
                }

                if (!String.IsNullOrEmpty(gyantalEmailInnerlStr))
                {
                    new Email { ToAddresses = Utils.Configuration["EmailGyantal"], Subject = "Overmind: SnifferQuant Price Warning", Body = gyantalEmailInnerlStr, IsBodyHtml = false }.Send();
                    var call = new PhoneCall
                    {
                        FromNumber = Caller.Gyantal,
                        ToNumber = PhoneCall.PhoneNumbers[Caller.Gyantal],
                        Message = "This is a warning notification from SnifferQuant. There's a large up or down movement in " + gyantalPhoneCallInnerStr +  " ... I repeat " + gyantalPhoneCallInnerStr,
                        NRepeatAll = 2
                    };
                    Console.WriteLine(call.MakeTheCall());
                }

                if (!String.IsNullOrEmpty(charmatEmailInnerlStr))
                {
                    new Email { ToAddresses = Utils.Configuration["EmailCharmat0"], Subject = "SnifferQuant Price Warning", Body = charmatEmailInnerlStr, IsBodyHtml = false }.Send();
                    var call = new PhoneCall
                    {
                        FromNumber = Caller.Gyantal,
                        ToNumber = PhoneCall.PhoneNumbers[Caller.Charmat0],
                        Message = "This is a warning notification from SnifferQuant. There's a large up or down movement in " + charmatPhoneCallInnerStr + " ... I repeat " + charmatPhoneCallInnerStr,
                        NRepeatAll = 2
                    };
                    Console.WriteLine(call.MakeTheCall());
                }

                Utils.Logger.Info("DailyMiddayTimer_Elapsed()-4");
            }
            catch (Exception e)
            {
                Console.WriteLine("Exception in DailyMiddayTimer_Elapsed(). See log file.");
                Utils.Logger.Error(e, "Exception in DailyMiddayTimer_Elapsed()");
                new Email { ToAddresses = Utils.Configuration["EmailGyantal"], Subject = "OvermindServer: Crash", Body = "Crash. Exception: " + e.Message + ", StackTrace " + e.StackTrace + ", ToString(): " + e.ToString(), IsBodyHtml = false }.Send();
            }
            Utils.Logger.Info("DailyMiddayTimer_Elapsed() END");
        }
Exemple #4
0
        static public void TestPhoneCall()
        {
            Console.WriteLine("Calling phone number via Twilio. It should ring out.");
            Utils.Logger.Info("Calling phone number via Twilio. It should ring out.");

            try
            {
                var call = new PhoneCall
                {
                    FromNumber = Caller.Gyantal,
                    ToNumber = PhoneCall.PhoneNumbers[Caller.Gyantal],
                    Message = "This is a test phone call from Health Monitor.",
                    NRepeatAll = 2
                };
                // skipped temporarily
                bool didTwilioAcceptedTheCommand = call.MakeTheCall();
                if (didTwilioAcceptedTheCommand)
                {
                    Utils.Logger.Debug("PhoneCall instruction was sent to Twilio.");
                }
                else
                    Utils.Logger.Error("PhoneCall instruction was NOT accepted by Twilio.");
            } catch (Exception e)
            {
                Utils.Logger.Error(e, "Exception in TestPhoneCall().");
            }
        }