예제 #1
0
        public void DeleteUnusedLogs()
        {
            try
            {
                var logs         = Repository.DbContext.MyLogs.Where(l => l.Id > 0).ToList();
                var utcNow       = GlobalWebData.ToUniversalTime();
                var utcPast24    = new DateTime(GlobalWebData.ToUniversalTime().Ticks).Add(System.TimeSpan.FromHours(System.Convert.ToDouble((24 * -1))));
                var log24        = logs.Where(l => l.Date >= utcPast24 && l.Date <= utcNow).ToList();
                var logBefore24  = logs.Except(log24);
                var logsABorrrar = logBefore24.ToList();

                if (logsABorrrar.Count > 0)
                {
                    foreach (MyLogs log in logsABorrrar)
                    {
                        MylogRepository.Delete(log);
                    }
                    MylogRepository.DetectChanges();
                    MylogRepository.Save();
                    ExceptionUtility.Info("Se borraron antiguos logs...");
                }
            }
            catch (Exception ex) {
                ExceptionUtility.Error(ex, this.GetType());
            }
        }
예제 #2
0
        private static void UpdateXMLFile(int intCount)
        {
            try
            {
                var file = GlobalWebData.GetRootPath() + "mailManagementInfo.xml";

                if (!File.Exists(file))
                {
                    CreateMailManagementInfo();
                }

                XmlDocument myXmlDocument = new XmlDocument();
                myXmlDocument.Load(file);
                XmlNode node;
                node = myXmlDocument.DocumentElement;

                foreach (XmlNode node1 in node.ChildNodes)
                {
                    if (node1.Name == "count")
                    {
                        string newCount = intCount.ToString();
                        node1.InnerText = newCount;
                    }
                }

                myXmlDocument.Save(file);
            }
            catch (Exception ex) {
            }
        }
예제 #3
0
        public void SaveLog(String log, String deviceId)
        {
            DeviceLog newlog = new DeviceLog();

            newlog.DeviceId = deviceId;
            newlog.Date     = GlobalWebData.ToUniversalTime();
            newlog.Log      = log;
            earthquakeRepository.DbContext.DevicesLogs.Add(newlog);
            earthquakeRepository.Save();
        }
예제 #4
0
        private bool Register(string registerId, string deviceId)
        {
            RegistrationDevice registration = new RegistrationDevice();

            registration.Date           = GlobalWebData.ToUniversalTime();
            registration.RegistrationId = registerId;
            registration.DeviceId       = deviceId;
            earthquakeRepository.DbContext.RegistrationDevices.Add(registration);
            earthquakeRepository.Save();
            return(true);
        }
예제 #5
0
 private List <string> CreateTweeterKeyWords()
 {
     try
     {
         var file = GlobalWebData.GetRootPath() + "tweeterKeyWords.xml";
         return(CreateXmlFile(file, "TweeterKeyWords", GetDefaultTweeterKeyWords()));
     }
     catch (Exception ex)
     {
         ExceptionUtility.Error(ex, this.GetType());
         return(GetDefaultTweeterKeyWords());
     }
 }
예제 #6
0
        private static Dictionary <string, string> CreateMailManagementInfo()
        {
            var file = GlobalWebData.GetRootPath() + "mailManagementInfo.xml";

            Dictionary <string, string> elements = new Dictionary <string, string>();

            elements.Add("count", count);
            elements.Add("permitted", permitted);


            CreateFile(file);

            return(elements);
        }
예제 #7
0
        public IList <Earthquake> GetLast24HoursEarthquakes(IList <Earthquake> allEarthquakes)
        {
            try
            {
                var utcNow    = GlobalWebData.ToUniversalTime();
                var utcPast24 = new DateTime(GlobalWebData.ToUniversalTime().Ticks).Add(TimeSpan.FromHours(System.Convert.ToDouble((24 * -1))));
                return(allEarthquakes.Where(e => e.UTCDateTime >= utcPast24 && e.UTCDateTime <= utcNow).ToList());
            }

            catch (Exception ex)
            {
                ExceptionUtility.Error(ex, this.GetType());
                return(new List <Earthquake>());
            }
        }
예제 #8
0
        public IList <Tweet> GetEarliesTweets(IList <Tweet> allTweets)
        {
            try
            {
                var utcNow       = GlobalWebData.ToUniversalTime();
                var utcMonthPast = new DateTime(GlobalWebData.ToUniversalTime().Ticks).Add(TimeSpan.FromHours(System.Convert.ToDouble((720 * -1))));
                return(allTweets.Where(t => t.DateTime < utcMonthPast).ToList());
            }

            catch (Exception ex)
            {
                ExceptionUtility.Error(ex, this.GetType());
                return(new List <Tweet>());
            }
        }
예제 #9
0
 public IList <Earthquake> GetEarthquakesBeforeTwoWeeks(IList <Earthquake> allEarthquakes)
 {
     try
     {
         var utcNow               = GlobalWebData.ToUniversalTime();
         var utcPastSevenDays     = new DateTime(GlobalWebData.ToUniversalTime().Ticks).Add(System.TimeSpan.FromHours(System.Convert.ToDouble((336 * -1))));
         var pastSevenDays        = allEarthquakes.Where(e => e.UTCDateTime >= utcPastSevenDays).ToList();
         var earthBeforeSevenDays = allEarthquakes.Except(pastSevenDays);
         return(earthBeforeSevenDays.ToList());
     }
     catch (Exception ex)
     {
         ExceptionUtility.Error(ex, this.GetType());
         return(new List <Earthquake>());
     }
 }
예제 #10
0
        private static Dictionary <string, string> ReadWords()
        {
            var      file      = GlobalWebData.GetRootPath() + "mailManagementInfo.xml";
            XElement ele       = XElement.Load(file);
            var      count     = from c in XElement.Load(file).Elements("count") select c;
            var      permitted = from p in XElement.Load(file).Elements("permitted") select p;


            Dictionary <string, string> elements = new Dictionary <string, string>();

            elements.Add("count", count.FirstOrDefault().Value);
            elements.Add("permitted", permitted.FirstOrDefault().Value);


            return(elements);
        }
예제 #11
0
        public void RunScheduledTasks()
        {
            try
            {
                lock (lockCollectionEarthquakes)
                {
                    earthquakeExpert.CollectData();
                }

                lock (lockNotification)
                {
                    earthquakeExpert.NotifySensibleEarthquakes();
                }

                lock (lockCollectionTweeters)
                {
                    earthquakeExpert.CollectTwitterData();
                }

                lock (lockDeleteEarthquakes)
                {
                    earthquakeExpert.DeleteEarthquakesBeforeTwoWeeks();
                }

                /*lock (lockDeleteDuplicatesEarthquakes)
                 * {
                 *  earthquakeExpert.DeleteDuplicateEarthQuakes();
                 * }*/

                lock (lockDeleteLogs)
                {
                    earthquakeExpert.DeleteUnusedLogs();
                }

                lock (lockDeleteTweeters)
                {
                    earthquakeExpert.DeleteEarliesTweeters();
                }

                ExceptionUtility.Info("ciclo completo..." + GlobalWebData.ToUniversalTime());
            }

            catch (Exception ex) {
                ExceptionUtility.Error(ex, this.GetType());
            }
        }
예제 #12
0
        private DateTime GetDate(string date)
        {
            DateTime dateTime  = DateTime.UtcNow;
            var      todayData = date.Split('-');

            if (todayData.Length == 4)
            {
                date = todayData[0];
            }

            switch (date)
            {
            //TODAY
            case ("1"):
                int year  = int.Parse(todayData[3]);
                int month = int.Parse(todayData[2]);
                int day   = int.Parse(todayData[1]);
                dateTime = new DateTime(year, month, day, 0, 0, 0).AddHours(3);
                break;

            //LAST 24 HS.
            case ("2"):
                dateTime = new DateTime(GlobalWebData.ToUniversalTime().Ticks).Add(System.TimeSpan.FromHours(System.Convert.ToDouble((24 * -1))));
                break;

            //LAST 48 HS.
            case ("3"):
                dateTime = new DateTime(GlobalWebData.ToUniversalTime().Ticks).Add(System.TimeSpan.FromHours(System.Convert.ToDouble((48 * -1))));
                break;

            //LAST WEEK
            case ("4"):
                dateTime = new DateTime(GlobalWebData.ToUniversalTime().Ticks).Add(System.TimeSpan.FromHours(System.Convert.ToDouble((168 * -1))));
                break;

            //LAST TWO WEEKS
            case ("5"):
                dateTime = new DateTime(GlobalWebData.ToUniversalTime().Ticks).Add(System.TimeSpan.FromHours(System.Convert.ToDouble((336 * -1))));
                break;
            }

            return(dateTime);
        }
예제 #13
0
        private void NotificateMultipleDevices(List <RegistrationDevice> devices, Earthquake earthquake)
        {
            PushNotification.PushNotification pn = new PushNotification.PushNotification();

            foreach (var device in devices)
            {
                //------------------------Send Notification----------------------------
                var ok = pn.Android(device.RegistrationId, earthquake.GetNotificationData());
                //--------------------------------------------------------------------

                if (ok.Contains("success\":0"))
                {
                    ExceptionUtility.Error(new Exception(device.RegistrationId), this.GetType());
                    Repository.DeleteDevice(device);
                    Repository.Save();
                }
            }

            ExceptionUtility.Info(string.Concat("send notification to GCM ", GlobalWebData.ToUniversalTime()));
        }
예제 #14
0
        public List <Tweet> GetTwitters()
        {
            List <Tweet> twits   = new List <Tweet>();
            var          twitter = new Twitter("xNBdzXy7tkyD1kstIDcg", "0nSriIwDZkFR7qcf6nsnQh3bqecn7IGoTqpIr8Xk6gc",
                                               "1451422718-kwIAaVppRGys6dltQXKIUt39vNbIg5e4PFD1Rgu",
                                               "1LPbBbwYcAELk3dl50WIwZMp38gt2wWGwkOkzVQGQM");

            var responseTwitter = twitter.GetTweets(MyConfigurationManager.GetTweeterQuery());

            JObject jobjectTwitter1 = JObject.Parse(responseTwitter);

            var resultado12 = jobjectTwitter1["statuses"];

            var twittsList2 = resultado12.ToList();

            foreach (JToken twitt in twittsList2)
            {
                var text     = twitt["text"].ToString();
                var textUper = text.ToUpper();
                var uperText = text.ToString().ToUpper();


                bool containsForbiddenWords = ContainsForbiddenWords(textUper);
                bool containsKeyWords       = ContainsKeyWords(uperText);

                if (!containsForbiddenWords && containsKeyWords)
                {
                    var          user       = twitt["user"];
                    var          screenName = user["screen_name"].ToString();
                    var          name       = user["name"].ToString();
                    var          date       = twitt["created_at"].ToString().Replace("\\", "").Replace("\"", "");
                    const string format     = "ddd MMM dd HH:mm:ss zzzz yyyy";
                    var          realtime   = DateTime.ParseExact(date, format, CultureInfo.InvariantCulture);
                    var          utcTime    = GlobalWebData.ToUniversalTime(realtime);//.Subtract(System.TimeSpan.FromHours(System.Convert.ToDouble(2)));
                    twits.Add(twitterFactory.Create(name, screenName, text, utcTime));
                }
            }


            return(twits);
        }
예제 #15
0
        public static Dictionary <string, string> GetmailManagementInfo()
        {
            Dictionary <string, string> defaults = new Dictionary <string, string>();
            var file = GlobalWebData.GetRootPath() + "mailManagementInfo.xml";

            try
            {
                if (File.Exists(file))
                {
                    defaults = ReadWords();
                }
                else
                {
                    defaults = CreateMailManagementInfo();
                }

                return(defaults);
            }
            catch (Exception ex)
            {
                return(GetDefaultMailManagementInfo());
            }
        }
예제 #16
0
        public List <string> GetKeyWords()
        {
            List <string> defaults = new List <string>();

            try
            {
                var file = GlobalWebData.GetRootPath() + "tweeterKeyWords.xml";
                if (File.Exists(file))
                {
                    ReadWords(defaults, file);
                }
                else
                {
                    defaults = CreateTweeterKeyWords();
                }

                return(defaults);
            }
            catch (Exception ex)
            {
                ExceptionUtility.Error(ex, this.GetType());
                return(GetDefaultTweeterKeyWords());
            }
        }
예제 #17
0
 public Earthquake Create(DateTime utcTime, decimal latitude, decimal longitude, decimal depth, decimal
                          magnitude, bool isSensible, Place place, Source source, MagnitudeType magnitudeType)
 {
     return(new Earthquake(Guid.NewGuid(), utcTime, latitude, longitude, depth, magnitude, isSensible, place, source, magnitudeType, GlobalWebData.ToUniversalTime()));
 }
예제 #18
0
 protected void Application_End(Object sender, EventArgs e)
 {
     ExceptionUtility.Warn("Terminando Argentina Sismos.... " + GlobalWebData.ToUniversalTime());
     KeepAliveManager.KeepWakeUp();
 }
예제 #19
0
        protected void Application_Start()
        {
            try
            {
                AreaRegistration.RegisterAllAreas();
                WebApiConfig.Register(GlobalConfiguration.Configuration);
                FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
                RouteConfig.RegisterRoutes(RouteTable.Routes);
                BundleConfig.RegisterBundles(BundleTable.Bundles);
                AuthConfig.RegisterAuth();

                RouteTable.Routes.MapRoute("Robots.txt", "robots.txt", new { controller = "Home", action = "Robots" });

                home = new HomeController();
                HomeController.SetDefaultDirectory();


                Database.SetInitializer(/*new DropCreateDatabaseIfModelChangesInitializer()*/ new CreateIfNoExistInitilizer());


                ExceptionUtility.Info("iniciando ArgetinaSismos..." + GlobalWebData.ToUniversalTime());


                ISourceRepository sourceRepository = new SourceRepository(new AplicationContextFactory());
                var appRepository = new EarthquakeRepository(new AplicationContextFactory());


                //--------------------------------------------------------------------------------------------------------


                /*for (int i = 100; i < 30000; i++) {
                 *
                 *  RegistrationDevice rd = new RegistrationDevice();
                 *  rd.Date = DateTime.Now;
                 *  rd.DeviceId = "359718776788248"+i;
                 *  rd.RegistrationId = i+"reEq5wZykVbsOq_oPL7ZRBjyZJ3XIMSuCCDtipam8dYI4Rko0an0nw1-SjX-bRDrVVcaXGj9Koau4RkPAKM5k5We4qG_Xi-I04VdQAhteqPMVAYC2Xf7HlFeT3NCBKPMf_jTvRRaKsZ0BcXqOHZsu7MnLU3NCw";
                 *  sourceRepository.DbContext.RegistrationDevices.Add(rd);
                 *  sourceRepository.Save();
                 *
                 * }*/


                //--------------------------------------------------------------------------------------------------------

                CollectorFactory collectorFactory = new CollectorFactory(sourceRepository);


                var inpresEarthquakeCollectorHtml = collectorFactory.GetInpresEarthquakeCollectorHtml();
                var eMSCEarthquakeCollectorXML    = collectorFactory.GetEMSCEarthquakeCollectorXML();
                var ssuchEarthquakeCollectorHtml  = collectorFactory.GetSSUCHEarthquakeCollectorHtml();

                IDictionary <string, EarthquakeCollector> collectors = new Dictionary <string, EarthquakeCollector>();
                collectors.Add("InpresEarthquakeCollectorHtml", inpresEarthquakeCollectorHtml);
                collectors.Add("EMSCEarthquakeCollectorXML", eMSCEarthquakeCollectorXML);
                collectors.Add("SSUCHEarthquakeCollectorHtml", ssuchEarthquakeCollectorHtml);

                earthquakeExpert = new EarthquakeExpert(collectors, new EarthquakeRepository(new AplicationContextFactory()),
                                                        new AplicationContextFactory(), new MylogRepository(new AplicationContextFactory()), new TwitterCollector());
                //--------------------------------------------------------------------------------------------

                Scheduler.Run("test", 1, RunScheduledTasks);
            }
            catch (Exception ex)
            {
                ExceptionUtility.Error(ex, this.GetType());
                var message = ExceptionUtility.GetExceptionData(ex, this.GetType());
            }
        }
예제 #20
0
 public ActionResult ExternalWakeUp(string site)
 {
     ExceptionUtility.Info(site + " :Wakeup!!!!..." + GlobalWebData.ToUniversalTime());
     return(Json(new { Message = "OK!" }, JsonRequestBehavior.AllowGet));
 }
예제 #21
0
        public override IList <Earthquake> Collect()
        {
            try
            {
                IList <Earthquake>   earthquakes     = new List <Earthquake>();
                List <MagnitudeType> MagnitudesTypes = new List <MagnitudeType>();
                List <Place>         Places          = new List <Place>();

                var docArgentina = SourceManagerHTML.GetDocument(WebSiteUrl);


                //check if data is available
                if (string.IsNullOrEmpty(docArgentina.DocumentNode.InnerText))
                {
                    UpdateSourceStatus(false);
                    return(new List <Earthquake>());
                }
                UpdateSourceStatus(true);

                // Get all tables in the document
                HtmlNodeCollection tables = docArgentina.DocumentNode.SelectNodes("//table");

                var earthquakeTable = tables.Where(tb => tb.Id.Equals("sismos")).Single();



                // Iterate all rows in the first table
                HtmlNodeCollection rows1 = earthquakeTable.SelectNodes(".//tr");
                if (rows1.Count > 1)
                {
                    for (int i = 2; rows1.Count > i; ++i)
                    {
                        // Iterate all columns in this row
                        HtmlNodeCollection cols = rows1[i].SelectNodes(".//td");
                        var cantidadColumnas    = cols.Count;
                        if (cantidadColumnas >= 8)
                        {
                            var  sensible1  = cols[8];
                            bool isSensible = sensible1.OuterHtml.Contains("#D40000");



                            string        LocalDateTimeYear = string.Empty;
                            DateTime      UTCDateTime       = new DateTime();
                            decimal       Latitude          = 0;
                            decimal       Longitude         = 0;
                            decimal       Depth             = 0;
                            decimal       Magnitude         = 0;
                            decimal       decimalValue      = 0;
                            Place         Place             = null;
                            MagnitudeType MagnitudeType     = null;

                            for (int j = 0; j < cols.Count; ++j)
                            {
                                string value = cols[j].InnerText;
                                switch (j)
                                {
                                //Local time
                                case (1):
                                    LocalDateTimeYear = value;
                                    break;

                                case (2):
                                    StringBuilder sb          = new StringBuilder();
                                    string        stringValue = sb.Append(LocalDateTimeYear).Append(" ").Append(value).ToString();
                                    const string  format      = "dd/MM/yyyy HH:mm:ss";
                                    var           realtime    = DateTime.ParseExact(stringValue, format, CultureInfo.InvariantCulture);
                                    UTCDateTime = GlobalWebData.ToUniversalTime(realtime);
                                    break;

                                //Latitude
                                case (3):
                                    /*string[] coord1 = value.Split('�');
                                     * string[] coord2 = coord1[1].Split('\'');
                                     * var degrees = Convert.ToDecimal(coord1[0], CultureInfo.InvariantCulture);
                                     * var minutes = Convert.ToDecimal(coord2[0], CultureInfo.InvariantCulture);
                                     * var seconds = Convert.ToDecimal(coord2[1], CultureInfo.InvariantCulture);
                                     * Latitude = Earthquake.GetDecimal(degrees, minutes, seconds);*/
                                    Latitude = decimal.Parse(value, CultureInfo.InvariantCulture);
                                    break;

                                //Longitude
                                case (4):
                                    /*string[] coord3 = value.Split('�');
                                     * string[] coord4 = coord3[1].Split('\'');
                                     * var degrees1 = Convert.ToDecimal(coord3[0], CultureInfo.InvariantCulture);
                                     * var minutes1 = Convert.ToDecimal(coord4[0], CultureInfo.InvariantCulture);
                                     * var seconds1 = Convert.ToDecimal(coord4[1], CultureInfo.InvariantCulture);
                                     * Longitude = Earthquake.GetDecimal(degrees1, minutes1, seconds1);*/
                                    Longitude = decimal.Parse(value, CultureInfo.InvariantCulture);
                                    break;

                                //Depth
                                case (5):
                                    string[] depthArray = value.Split(' ');
                                    decimalValue = Convert.ToDecimal(depthArray[0], CultureInfo.InvariantCulture);
                                    Depth        = decimalValue;
                                    break;

                                //Magnitude
                                case (6):
                                    string[] magnitudArray = value.Split(' ');
                                    decimalValue = Convert.ToDecimal(magnitudArray[0], CultureInfo.InvariantCulture);
                                    Magnitude    = decimalValue;

                                    //tambien inferir que los sismos de 3.5 o mas son sensibles...

                                    double? d            = 3.5;
                                    decimal?topMagnitude = (decimal?)d.Value;
                                    // decimal topMagnitude = decimal.Parse( "3.5");
                                    if (Magnitude >= topMagnitude)
                                    {
                                        isSensible = true;
                                    }
                                    var mtypes = MagnitudesTypes.Where(mt => mt.Type.Equals(magnitudeTypeArgentina)).FirstOrDefault();

                                    if (mtypes == null)
                                    {
                                        mtypes = this.IMagnitudeTypeRepository.FindByType(magnitudeTypeArgentina);
                                        if (mtypes != null)
                                        {
                                            MagnitudesTypes.Add(mtypes);
                                        }
                                    }

                                    if (mtypes == null)
                                    {
                                        mtypes = this.IMagnitudeTypeFactory.Create(magnitudeTypeArgentina);
                                        IMagnitudeTypeRepository.DbContext.MagtitudesTypes.Add(mtypes);
                                        IMagnitudeTypeRepository.Save();
                                        MagnitudesTypes.Add(mtypes);
                                    }

                                    MagnitudeType = mtypes;
                                    break;

                                //Place
                                case (7):
                                    value = value.ToUpper();
                                    string country;

                                    if (value.Contains("CHILE"))
                                    {
                                        country = countryChile;
                                    }
                                    else if (value.Contains("BOLIVIA"))
                                    {
                                        country = countryBolivia;
                                    }
                                    else
                                    {
                                        country = countryArgentina;
                                    }

                                    var pla = Places.Where(pl => pl.PlaceName.Equals(value) && pl.Country.Equals(country)).FirstOrDefault();

                                    if (pla == null)
                                    {
                                        pla = this.IPlaceRepository.FindByPlaceCountry(value, country);
                                        if (pla != null)
                                        {
                                            Places.Add(pla);
                                        }
                                    }

                                    if (pla == null)
                                    {
                                        pla = this.IPlaceFactory.Create(value, country);
                                        IPlaceRepository.DbContext.Places.Add(pla);
                                        IPlaceRepository.Save();
                                        Places.Add(pla);
                                    }

                                    Place = pla;
                                    break;
                                }
                            }
                            Earthquake earthquake = this.IEarthqueakeFactory.Create(UTCDateTime, Latitude, Longitude, Depth,
                                                                                    Magnitude, isSensible, Place, Source, MagnitudeType);
                            earthquakes.Add(earthquake);
                        }
                        else
                        {
                            ExceptionUtility.Warn(string.Concat("cantidad de columnas", " ", cantidadColumnas, " ", this.GetType()));
                        }
                    }
                }
                return(earthquakes);
            }
            catch (Exception ex)
            {
                ExceptionUtility.Error(ex, this.GetType());
                return(new List <Earthquake>());
            }
        }