Esempio n. 1
0
        private void SendMessage(System.Net.Mail.MailMessage message)
        {
            MOE.Common.Models.Repositories.IApplicationEventRepository er =
                MOE.Common.Models.Repositories.ApplicationEventRepositoryFactory.Create();
            System.Net.Mail.SmtpClient smtp = new System.Net.Mail.SmtpClient(ConfigurationManager.AppSettings["EmailServer"]);

            try
            {
                Console.WriteLine("Sent message to: " + message.To.ToString() + "\nMessage text: " + message.Body + "\n");
                smtp.Send(message);
                System.Threading.Thread.Sleep(500);

                er.QuickAdd("ImportChecker", "Program", "SendMessage",
                            MOE.Common.Models.ApplicationEvent.SeverityLevels.Information,
                            "Email Sent Successfully to: " + message.To.ToString());
            }

            catch (Exception ex)
            {
                try
                {
                    er.QuickAdd("ImportChecker", "Program", "SendMessage",
                                MOE.Common.Models.ApplicationEvent.SeverityLevels.Medium, ex.Message);
                }
                catch (Exception e)
                {
                    Console.WriteLine(e);
                    throw;
                }
            }
        }
Esempio n. 2
0
        static void Main(string[] args)
        {
            DateTime StartTime = DateTime.Today;

            // find the analysis timespan
            if (args.Length > 0)
            {
                try
                {
                    StartTime = DateTime.Parse(args[0]);
                    MOE.Common.Business.WatchDog.WatchDogScan scan =
                        new MOE.Common.Business.WatchDog.WatchDogScan(StartTime);
                    scan.StartScan();
                }
                catch (Exception ex)
                {
                    MOE.Common.Models.Repositories.IApplicationEventRepository errorRepository = MOE.Common.Models.Repositories.ApplicationEventRepositoryFactory.Create();
                    errorRepository.QuickAdd("FTPFromAllcontrollers", "Signal", "TransferFiles", MOE.Common.Models.ApplicationEvent.SeverityLevels.High, ex.Message);
                }
            }
            else
            {
                try
                {
                    MOE.Common.Business.WatchDog.WatchDogScan scan =
                        new MOE.Common.Business.WatchDog.WatchDogScan(StartTime);
                    scan.StartScan();
                }
                catch (Exception ex)
                {
                    MOE.Common.Models.Repositories.IApplicationEventRepository errorRepository = MOE.Common.Models.Repositories.ApplicationEventRepositoryFactory.Create();
                    errorRepository.QuickAdd("FTPFromAllcontrollers", "Signal", "TransferFiles", MOE.Common.Models.ApplicationEvent.SeverityLevels.High, ex.Message);
                }
            }
        }
Esempio n. 3
0
        static void Main(string[] args)
        {
            DateTime startTime = DateTime.Today;

            // find the analysis timespan
            if (args.Length > 0)
            {
                try
                {
                    startTime = DateTime.Parse(args[0]);
                    MOE.Common.Business.WatchDog.WatchDogScan scan =
                        new MOE.Common.Business.WatchDog.WatchDogScan(startTime);
                    scan.StartScan();
                }
                catch (Exception ex)
                {
                    MOE.Common.Models.Repositories.IApplicationEventRepository errorRepository = MOE.Common.Models.Repositories.ApplicationEventRepositoryFactory.Create();
                    errorRepository.QuickAdd("SPMWatchdog", "WatchDog", "WatchDogScan with args", MOE.Common.Models.ApplicationEvent.SeverityLevels.High, ex.Message);
                }
            }
            else
            {
                try
                {
                    MOE.Common.Business.WatchDog.WatchDogScan scan =
                        new MOE.Common.Business.WatchDog.WatchDogScan(startTime);
                    scan.StartScan();
                }
                catch (Exception ex)
                {
                    MOE.Common.Models.Repositories.IApplicationEventRepository errorRepository = MOE.Common.Models.Repositories.ApplicationEventRepositoryFactory.Create();
                    errorRepository.QuickAdd("SPMWatchdog", "WatchDog", "WatchDogScan no args", MOE.Common.Models.ApplicationEvent.SeverityLevels.High, ex.Message);
                }
            }
        }
Esempio n. 4
0
 private void ReceiveData(IAsyncResult asyncResult)
 {
     try
     {
         string senderIPaddress = asyncResult.AsyncState.ToString();
         // Initialise a packet object to store the received data
         Packet receivedData = new Packet(this.dataStream, senderIPaddress);
         // Initialise the IPEndPoint for the clients
         IPEndPoint clients = new IPEndPoint(IPAddress.Any, 0);
         // Initialise the EndPoint for the clients
         EndPoint epSender = (EndPoint)clients;
         // Receive all data
         serverSocket.EndReceiveFrom(asyncResult, ref epSender);
         // Listen for more connections again...
         serverSocket.BeginReceiveFrom(this.dataStream, 0, this.dataStream.Length, SocketFlags.None,
                                       ref epSender, new AsyncCallback(this.ReceiveData), epSender);
     }
     catch (Exception ex)
     {
         MOE.Common.Models.Repositories.IApplicationEventRepository eventRepository =
             MOE.Common.Models.Repositories.ApplicationEventRepositoryFactory.Create();
         eventRepository.QuickAdd("SpeedListener", this.GetType().ToString(), "RecieveData",
                                  MOE.Common.Models.ApplicationEvent.SeverityLevels.High, ex.Message);
     }
 }
Esempio n. 5
0
        public void StartListening()
        {
            try
            {
                // Initialise the IPEndPoint for the clients
                IPEndPoint clients = new IPEndPoint(IPAddress.Any, 0);
                // Initialise the EndPoint for the clients
                EndPoint    epSender = (EndPoint)clients;
                TcpListener listener = new TcpListener(IPAddress.Any, 10088);
                serverSocket = listener.AcceptSocket();
                var childSocketThread = new Thread(() =>
                {
                    byte[] data = new byte[100];
                    serverSocket.BeginReceiveFrom(this.dataStream, 0, this.dataStream.Length, SocketFlags.None,
                                                  ref epSender, new AsyncCallback(ReceiveData), epSender);

                    serverSocket.Close();
                });
                childSocketThread.Start();
            }
            catch (Exception ex)
            {
                MOE.Common.Models.Repositories.IApplicationEventRepository eventRepository =
                    MOE.Common.Models.Repositories.ApplicationEventRepositoryFactory.Create();
                eventRepository.QuickAdd("SpeedListener", this.GetType().ToString(), "StartListening",
                                         MOE.Common.Models.ApplicationEvent.SeverityLevels.High, ex.Message);
            }
        }
Esempio n. 6
0
        private void CheckForLowDetectorHits(MOE.Common.Models.Signal signal)
        {
            List <MOE.Common.Models.Detector> detectors = signal.GetDetectorsForSignalThatSupportAMetric(6);

            //Parallel.ForEach(detectors, options, detector =>
            foreach (MOE.Common.Models.Detector detector in detectors)
            {
                try
                {
                    int      channel   = detector.DetChannel;
                    string   direction = detector.Approach.DirectionType.Description;
                    DateTime start     = new DateTime();
                    DateTime end       = new DateTime();
                    if (Settings.WeekdayOnly && ScanDate.DayOfWeek == DayOfWeek.Monday)
                    {
                        start = ScanDate.AddDays(-3).Date.AddHours(Settings.PreviousDayPMPeakStart);
                        end   = ScanDate.AddDays(-3).Date.AddHours(Settings.PreviousDayPMPeakEnd);
                    }
                    else
                    {
                        start = ScanDate.AddDays(-1).Date.AddHours(Settings.PreviousDayPMPeakStart);
                        end   = ScanDate.AddDays(-1).Date.AddHours(Settings.PreviousDayPMPeakEnd);
                    }
                    int currentVolume = detector.GetVolumeForPeriod(start, end);
                    //Compare collected hits to low hit threshold,
                    if (currentVolume < Convert.ToInt32(Settings.LowHitThreshold))
                    {
                        MOE.Common.Models.SPMWatchDogErrorEvent error = new MOE.Common.Models.SPMWatchDogErrorEvent();
                        error.SignalID   = signal.SignalID;
                        error.DetectorID = detector.DetectorID;
                        error.Phase      = detector.Approach.ProtectedPhaseNumber;
                        error.TimeStamp  = ScanDate;
                        error.Direction  = detector.Approach.DirectionType.Description;
                        error.Message    = "CH: " + channel.ToString() + " - Count: " + currentVolume.ToString();
                        error.ErrorCode  = 2;
                        if (!LowHitCountErrors.Contains(error))
                        {
                            LowHitCountErrors.Add(error);
                        }
                    }
                }

                catch (Exception ex)
                {
                    MOE.Common.Models.Repositories.IApplicationEventRepository er =
                        MOE.Common.Models.Repositories.ApplicationEventRepositoryFactory.Create();

                    er.QuickAdd("SPMWatchDog", "Program", "CheckForLowDetectorHits",
                                MOE.Common.Models.ApplicationEvent.SeverityLevels.Medium, detector.DetectorID + "-" + ex.Message);
                }
            }
            //);
        }
Esempio n. 7
0
        public void StartListening()
        {
            //while (IsRunning)
            //{
            try
            {
                //File.AppendAllText(@"C:\temp\servicenotes.txt", Environment.NewLine + " UDP Listener Is Running " + DateTime.Now.ToString("dd/MM/yyyy hh:mm:ss"));
                // Initialise the ArrayList of connected clients
                this.clientList = new ArrayList();

                // Initialise the socket
                serverSocket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);

                // Initialise the IPEndPoint for the server and listen on port 10088
                IPEndPoint server = new IPEndPoint(IPAddress.Any, 10088);

                // Associate the socket with this IP address and port
                serverSocket.Bind(server);

                // Initialise the IPEndPoint for the clients
                IPEndPoint clients = new IPEndPoint(IPAddress.Any, 0);

                // Initialise the EndPoint for the clients
                EndPoint epSender = (EndPoint)clients;

                // Start listening for incoming data
                serverSocket.BeginReceiveFrom(this.dataStream, 0, this.dataStream.Length, SocketFlags.None,
                                              ref epSender, new AsyncCallback(ReceiveData), epSender);
            }
            catch (Exception ex)
            {
                applicationEventRepository.QuickAdd("SpeedListener", this.GetType().ToString(), "StartListening",
                                                    MOE.Common.Models.ApplicationEvent.SeverityLevels.High, ex.Message);
            }
            //}
        }
 public void AddList(List <Models.SPMWatchDogErrorEvent> SPMWatchDogErrorEvents)
 {
     try
     {
         db.SPMWatchDogErrorEvents.AddRange(SPMWatchDogErrorEvents);
         db.SaveChanges();
     }
     catch (Exception ex)
     {
         MOE.Common.Models.Repositories.IApplicationEventRepository er =
             MOE.Common.Models.Repositories.ApplicationEventRepositoryFactory.Create();
         er.QuickAdd("MOE.Common", "SPMWatchDogErrrorEventRepository", "AddList",
                     MOE.Common.Models.ApplicationEvent.SeverityLevels.Medium, ex.Message);
     }
 }
Esempio n. 9
0
 public void Add(MOE.Common.Models.MetricComment metricComment)
 {
     MOE.Common.Models.MetricComment g = (from r in db.MetricComments
                                          where r.CommentID == metricComment.CommentID
                                          select r).FirstOrDefault();
     if (g == null)
     {
         if (metricComment.MetricTypes == null)
         {
             metricComment.MetricTypes = db.MetricTypes
                                         .Where(x => metricComment.MetricTypeIDs.Contains(x.MetricID)).ToList();
         }
         try
         {
             db.MetricComments.Add(metricComment);
             db.SaveChanges();
         }
         catch (DbEntityValidationException e)
         {
             MOE.Common.Models.Repositories.IApplicationEventRepository repository =
                 MOE.Common.Models.Repositories.ApplicationEventRepositoryFactory.Create();
             string errorMessage = string.Empty;
             foreach (var eve in e.EntityValidationErrors)
             {
                 foreach (var ve in eve.ValidationErrors)
                 {
                     errorMessage += " Property:" + ve.PropertyName + " Error:" + ve.ErrorMessage;
                 }
             }
             repository.QuickAdd("Moe.Common", "MetricCommentRepository", "Add",
                                 ApplicationEvent.SeverityLevels.Medium, errorMessage);
             throw new Exception(errorMessage);
         }
         catch (Exception ex)
         {
             MOE.Common.Models.Repositories.IApplicationEventRepository repository =
                 MOE.Common.Models.Repositories.ApplicationEventRepositoryFactory.Create();
             repository.QuickAdd("Moe.Common", "MetricCommentRepository", "Add",
                                 ApplicationEvent.SeverityLevels.Medium, ex.Message);
             throw;
         }
     }
     else
     {
         this.AddOrUpdate(metricComment);
     }
 }
Esempio n. 10
0
 private void Save()
 {
     try
     {
         MOE.Common.Models.SPM db = new MOE.Common.Models.SPM();
         {
             MOE.Common.Models.Speed_Events se = new MOE.Common.Models.Speed_Events();
             se.DetectorID = this.sensorId;
             se.timestamp  = this.date;
             se.MPH        = this.mph;
             se.KPH        = this.kph;
             Regex r = new Regex("^[a-zA-Z0-9]*$");
             if (r.IsMatch(se.DetectorID))
             {
                 db.Speed_Events.Add(se);
                 db.SaveChanges();
             }
         }
     }
     catch (DbUpdateException ex)
     {
         SqlException innerException = ex.InnerException.InnerException as SqlException;
         if (innerException != null && (innerException.Number == 2627 || innerException.Number == 2601))
         {
         }
         else
         {
             MOE.Common.Models.Repositories.IApplicationEventRepository eventRepository =
                 MOE.Common.Models.Repositories.ApplicationEventRepositoryFactory.Create();
             eventRepository.QuickAdd("SpeedListener", this.GetType().ToString(), "Save",
                                      MOE.Common.Models.ApplicationEvent.SeverityLevels.High, ex.HResult.ToString() + ex.Message + ex.InnerException);
         }
     }
     catch (Exception ex)
     {
         MOE.Common.Models.Repositories.IApplicationEventRepository eventRepository =
             MOE.Common.Models.Repositories.ApplicationEventRepositoryFactory.Create();
         eventRepository.QuickAdd("SpeedListener", this.GetType().ToString(), "Save",
                                  MOE.Common.Models.ApplicationEvent.SeverityLevels.High, ex.HResult.ToString() + ex.Message + ex.InnerException);
     }
 }
Esempio n. 11
0
        static void Main(string[] args)
        {
            MOE.Common.Models.Repositories.IApplicationEventRepository ErrorRepository = MOE.Common.Models.Repositories.ApplicationEventRepositoryFactory.Create();
            int  MaxThreads       = Properties.Settings.Default.MaxThreads;
            int  SNMPTimeout      = Properties.Settings.Default.SNMPTimeout;
            int  SNMPRetry        = Properties.Settings.Default.SNMPRetry;
            int  SNMPPort         = Properties.Settings.Default.SNMPPort;
            bool DeleteAfterFTP   = Properties.Settings.Default.DeleteFilesAfterFTP;
            bool ImportAfterFTP   = Properties.Settings.Default.ImportAfterFTP;
            int  WaitBetweenFiles = Properties.Settings.Default.WaitBetweenFiles;
            var  connection       = ConfigurationManager.ConnectionStrings["SPM"].ConnectionString;

            MOE.Common.Business.BulkCopyOptions Options = new MOE.Common.Business.BulkCopyOptions(connection, Properties.Settings.Default.DestinationTableName,
                                                                                                  Properties.Settings.Default.WriteToConsole, Properties.Settings.Default.forceNonParallel, Properties.Settings.Default.MaxThreads, Properties.Settings.Default.DeleteFiles,
                                                                                                  Properties.Settings.Default.EarliestAcceptableDate, Properties.Settings.Default.BulkCopyBatchSize, Properties.Settings.Default.BulkCopyTimeOut);


            //MOE.Common.Data.Signals.SignalFTPparamsDataTable SignalsDT = new MOE.Common.Data.Signals.SignalFTPparamsDataTable();
            //MOE.Common.Data.SignalsTableAdapters.SignalFTPparamsTableAdapter SignalsTA = new MOE.Common.Data.SignalsTableAdapters.SignalFTPparamsTableAdapter();

            //SignalsTA.Fill(SignalsDT);

            MOE.Common.Models.SPM db = new MOE.Common.Models.SPM();

            var SignalsDT = from r in db.Signals
                            join f in db.ControllerType on r.ControllerTypeID equals f.ControllerTypeID
                            where r.ControllerTypeID != 4
                            select new
            {
                SignalId       = r.SignalID,
                PrimaryName    = r.PrimaryName,
                Secondary_Name = r.SecondaryName,
                Region         = r.Region,
                IP_Address     = r.IPAddress,
                UserName       = f.UserName,
                Password       = f.Password,
                FTPDirectory   = f.FTPDirectory,
                ActiveFTP      = f.ActiveFTP
            };



            var options = new ParallelOptions {
                MaxDegreeOfParallelism = Properties.Settings.Default.MaxThreads
            };

            Parallel.ForEach(SignalsDT.AsEnumerable(), options, row =>
                             //foreach (var row in SignalsDT)
            {
                try
                {
                    MOE.Common.Business.Signal signal = new MOE.Common.Business.Signal();

                    //Initialize the signal, because I didn't make a proper constructor

                    signal.PrimaryName   = row.PrimaryName.ToString();
                    signal.SecondaryName = row.Secondary_Name.ToString();
                    signal.Region        = row.Region.ToString();
                    signal.IpAddress     = row.IP_Address.ToString();
                    signal.SignalID      = row.SignalId.ToString();



                    string Username  = row.UserName;
                    string Password  = row.Password;
                    string LocalDir  = Properties.Settings.Default.HostDir + signal.SignalID + "\\";
                    string RemoteDir = row.FTPDirectory;
                    bool ActiveMode  = row.ActiveFTP;


                    if (!Directory.Exists(LocalDir))
                    {
                        Directory.CreateDirectory(LocalDir);
                    }


                    //Get the records over FTP
                    if (CheckIfIPAddressIsValid(signal))
                    {
                        try
                        {
                            //var tokenSource = new CancellationTokenSource(TimeSpan.FromSeconds(30));
                            //var token = tokenSource.Token;

                            //Task task = Task.Factory.StartNew(() => MOE.Common.Business.Signal.GetCurrentRecords(signal.IpAddress, signal.SignalID, Username, Password, LocalDir, RemoteDir, DeleteAfterFTP,
                            //    SNMPRetry, SNMPTimeout, SNMPPort, ImportAfterFTP, ActiveMode, 0, Options, Properties.Settings.Default.FTPTimeout, token), token);

                            //task.Wait();

                            //if (token.IsCancellationRequested)
                            //    token.ThrowIfCancellationRequested();

                            MOE.Common.Business.Signal.GetCurrentRecords(signal.IpAddress, signal.SignalID, Username, Password, LocalDir, RemoteDir, DeleteAfterFTP,
                                                                         SNMPRetry, SNMPTimeout, SNMPPort, ImportAfterFTP, ActiveMode, 0, Options, Properties.Settings.Default.FTPTimeout);
                        }
                        catch (AggregateException ex)
                        {
                            Console.WriteLine("Error At Highest Level for signal " + ex.Message);
                            ErrorRepository.QuickAdd("FTPFromAllControllers", "Main", "Main Loop", MOE.Common.Models.ApplicationEvent.SeverityLevels.Medium, "Error At Highest Level for signal " + row.SignalId);
                        }
                    }
                }
                catch (AggregateException ex)
                {
                    Console.WriteLine("Error At Highest Level for signal " + ex.Message);
                    ErrorRepository.QuickAdd("FTPFromAllControllers", "Main", "Main Loop", MOE.Common.Models.ApplicationEvent.SeverityLevels.Medium, "Error At Highest Level for signal " + row.SignalId);
                }
            }

                             );



            //if (Properties.Settings.Default.DealWithMoab)
            //{
            //    try
            //    {
            //        DealWithMoab(Options);
            //    }
            //    catch
            //    {

            //    }
            //}
        }