public static void TurnOffASC3LoggingOverSNMP(int SNMPRetry, int SNMPPort, int SNMPTimeout, string ServerIPAddress) { var errorRepository = ApplicationEventRepositoryFactory.Create(); for (var counter = 0; counter < SNMPRetry; counter++) { try { SmnpSet(ServerIPAddress, "1.3.6.1.4.1.1206.3.5.2.9.17.1.0", "0", "i", SNMPPort); } catch (SnmpException ex) { errorRepository.QuickAdd("FTPFromAllcontrollers", "Signal", " TurnOffASC3LoggingOverSNMP", ApplicationEvent.SeverityLevels.Medium, ServerIPAddress + " " + ex.Message); Console.WriteLine(ex); } var SNMPState = 10; try { SNMPState = SnmpGet(ServerIPAddress, "1.3.6.1.4.1.1206.3.5.2.9.17.1.0", "0", "i"); } catch (SnmpException ex) { errorRepository.QuickAdd("FTPFromAllcontrollers", "Signal", " TurnOffASC3LoggingOverSNMP", ApplicationEvent.SeverityLevels.Medium, ServerIPAddress + " " + ex.Message); Console.WriteLine(ex); } if (SNMPState == 0) { break; } Thread.Sleep(SNMPTimeout); } }
private void TurnOnAsc3LoggingOverSnmp() { var errorRepository = ApplicationEventRepositoryFactory.Create(); for (var counter = 0; counter < SignalFtpOptions.SnmpRetry; counter++) { try { SmnpSet(Signal.IPAddress, "1.3.6.1.4.1.1206.3.5.2.9.17.1.0", "1", "i", SignalFtpOptions.SnmpPort); } catch (Exception ex) { errorRepository.QuickAdd("FTPFromAllcontrollers", "Signal", " TurnOnASC3LoggingOverSNMP_Set", Models.ApplicationEvent.SeverityLevels.Medium, Signal.SignalID + " @ " + Signal.IPAddress + " - " + ex.Message); Console.WriteLine(Signal.SignalID + " @ " + Signal.IPAddress + " - " + ex); } var snmpState = 10; try { snmpState = SnmpGet(Signal.IPAddress, "1.3.6.1.4.1.1206.3.5.2.9.17.1.0", "1", "i"); } catch (Exception ex) { errorRepository.QuickAdd("FTPFromAllcontrollers", "Signal", " TurnOnASC3LoggingOverSNMP_Get", Models.ApplicationEvent.SeverityLevels.Medium, Signal.SignalID + " @ " + Signal.IPAddress + " - " + ex.Message); Console.WriteLine(Signal.SignalID + " @ " + Signal.IPAddress + " - " + ex); } if (snmpState == 1) { break; } Thread.Sleep(SignalFtpOptions.SnmpTimeout); } }
public void Initialize() { Db.ClearTables(); Db.PopulateSignal(); Db.PopulateSignalsWithApproaches(); Db.PopulateApproachesWithDetectors(); var signals = Db.Signals; foreach (var signal in signals) { foreach (var approach in signal.Approaches) { Db.PopulateApproachSplitFailAggregationsWithRandomRecords(Convert.ToDateTime("1/1/2016"), Convert.ToDateTime("1/1/2018"), approach); } } ApproachSplitFailAggregationRepositoryFactory.SetApplicationEventRepository( new InMemoryApproachSplitFailAggregationRepository(Db)); MOE.Common.Models.Repositories.SignalsRepositoryFactory.SetSignalsRepository( new InMemorySignalsRepository(Db)); MetricTypeRepositoryFactory.SetMetricsRepository(new InMemoryMetricTypeRepository(Db)); ApplicationEventRepositoryFactory.SetApplicationEventRepository(new InMemoryApplicationEventRepository(Db)); Models.Repositories.DirectionTypeRepositoryFactory.SetDirectionsRepository( new InMemoryDirectionTypeRepository()); SignalsRepository = SignalsRepositoryFactory.Create(); }
public PedDelaySignal(string signalID, DateTime startDate, DateTime endDate) { _SignalID = signalID; _StartDate = startDate; _EndDate = endDate; try { _Plans = new PlansBase(signalID, startDate, endDate); var pedPhaseNumbers = ControllerEventLogs.GetPedPhases(signalID, startDate, endDate); ConcurrentBag <PedPhase> pedPhases = new ConcurrentBag <PedPhase>(); Parallel.ForEach(pedPhaseNumbers, currentPhase => //foreach(int currentPhase in pedPhaseNumbers) { var pedPhase = new PedPhase(currentPhase, signalID, startDate, endDate, _Plans); pedPhases.Add(pedPhase); }); _PedPhases = pedPhases.OrderBy(x => x.PhaseNumber).ToList(); } catch (Exception e) { var errorLog = ApplicationEventRepositoryFactory.Create(); errorLog.QuickAdd(System.Reflection.Assembly.GetExecutingAssembly().GetName().ToString(), this.GetType().DisplayName(), e.TargetSite.ToString(), ApplicationEvent.SeverityLevels.High, e.Message); } }
public Controller_Event_Log GetFirstEventBeforeDateByEventCodeAndParameter(string signalId, int eventCode, int eventParam, DateTime date) { try { DateTime tempDate = date.AddDays(-1); var lastEvent = _db.Controller_Event_Log.Where(c => c.SignalID == signalId && c.Timestamp >= tempDate && c.Timestamp < date && c.EventCode == eventCode && c.EventParam == eventParam) .OrderByDescending(c => c.Timestamp).FirstOrDefault(); return(lastEvent); } catch (Exception ex) { IApplicationEventRepository logRepository = ApplicationEventRepositoryFactory.Create(); ApplicationEvent e = new ApplicationEvent(); e.ApplicationName = "MOE.Common"; e.Class = GetType().ToString(); e.Function = "GetEventsByEventCodesParamWithOffsetAndLatencyCorrection"; e.SeverityLevel = ApplicationEvent.SeverityLevels.High; e.Description = ex.Message; e.Timestamp = DateTime.Now; logRepository.Add(e); return(null); } }
private int GetPercentile(List <int> speeds, double percentile) { var percentileValue = 0; try { var tempPercentileIndex = SpeedVolume * percentile - 1; if (SpeedVolume > 3) { var percentileIndex = 0; if (tempPercentileIndex % 1 > 0) { percentileIndex = Convert.ToInt32(Math.Round(tempPercentileIndex + .5)); percentileValue = speeds[percentileIndex]; } else { percentileIndex = Convert.ToInt32(tempPercentileIndex); var speed1 = speeds[percentileIndex]; var speed2 = speeds[percentileIndex + 1]; double rawEightyfifth = (speed1 + speed2) / 2; percentileValue = Convert.ToInt32(Math.Round(rawEightyfifth)); } } } catch (Exception e) { var errorLog = ApplicationEventRepositoryFactory.Create(); errorLog.QuickAdd(Assembly.GetExecutingAssembly().GetName().ToString(), GetType().DisplayName(), e.TargetSite.ToString(), ApplicationEvent.SeverityLevels.High, e.Message); throw new Exception("Error creating Percentile"); } return(percentileValue); }
public void Initialize() { Db.ClearTables(); Db.PopulateSignal(); Db.PopulateSignalsWithApproaches(); Db.PopulateApproachesWithDetectors(); var signals = Db.Signals; foreach (var signal in signals) { Db.PopulatePreemptAggregations(Convert.ToDateTime("1/1/2016"), Convert.ToDateTime("1/1/2018"), signal.SignalID, signal.VersionID); } ApproachRepositoryFactory.SetApproachRepository(new InMemoryApproachRepository(Db)); PreemptAggregationDatasRepositoryFactory.SetArchivedMetricsRepository( new InMemoryPreemptAggregationDatasRepository(Db)); MOE.Common.Models.Repositories.SignalsRepositoryFactory.SetSignalsRepository( new InMemorySignalsRepository(Db)); MetricTypeRepositoryFactory.SetMetricsRepository(new InMemoryMetricTypeRepository(Db)); ApplicationEventRepositoryFactory.SetApplicationEventRepository(new InMemoryApplicationEventRepository(Db)); DetectorAggregationsRepositoryFactory.SetDetectorAggregationRepository(new InMemoryDetectorAggregationsRepository(Db)); Models.Repositories.DirectionTypeRepositoryFactory.SetDirectionsRepository( new InMemoryDirectionTypeRepository()); SignalsRepository = SignalsRepositoryFactory.Create(); PreemptAggregationDatasRepositoryFactory.SetArchivedMetricsRepository(new InMemoryPreemptAggregationDatasRepository(Db)); }
public List <Controller_Event_Log> GetEventsByEventCodesParamWithOffsetAndLatencyCorrection(string signalId, DateTime startTime, DateTime endTime, List <int> eventCodes, int param, double offset, double latencyCorrection) { try { var events = (from s in _db.Controller_Event_Log where s.SignalID == signalId && s.Timestamp >= startTime && s.Timestamp <= endTime && s.EventParam == param && eventCodes.Contains(s.EventCode) select s).ToList(); events.Sort((x, y) => DateTime.Compare(x.Timestamp, y.Timestamp)); foreach (var cel in events) { cel.Timestamp = cel.Timestamp.AddMilliseconds(offset); cel.Timestamp = cel.Timestamp.AddSeconds(0 - latencyCorrection); } return(events); } catch (Exception ex) { IApplicationEventRepository logRepository = ApplicationEventRepositoryFactory.Create(); ApplicationEvent e = new ApplicationEvent(); e.ApplicationName = "MOE.Common"; e.Class = GetType().ToString(); e.Function = "GetEventsByEventCodesParamWithOffsetAndLatencyCorrection"; e.SeverityLevel = ApplicationEvent.SeverityLevels.High; e.Timestamp = DateTime.Now; e.Description = ex.Message; logRepository.Add(e); throw; } }
public List <Controller_Event_Log> GetSignalEventsByEventCodes(string signalId, DateTime startTime, DateTime endTime, List <int> eventCodes) { try { var events = (from s in _db.Controller_Event_Log where s.SignalID == signalId && s.Timestamp >= startTime && s.Timestamp <= endTime && eventCodes.Contains(s.EventCode) select s).ToList(); events.Sort((x, y) => DateTime.Compare(x.Timestamp, y.Timestamp)); return(events); } catch (Exception ex) { IApplicationEventRepository logRepository = ApplicationEventRepositoryFactory.Create(); ApplicationEvent e = new ApplicationEvent(); e.ApplicationName = "MOE.Common"; e.Class = GetType().ToString(); e.Function = "GetSignalEventsByEventCodes"; e.SeverityLevel = ApplicationEvent.SeverityLevels.High; e.Timestamp = DateTime.Now; e.Description = ex.Message; logRepository.Add(e); throw; } }
public List <Controller_Event_Log> GetSignalEventsByEventCode(string signalId, DateTime startTime, DateTime endTime, int eventCode) { try { return((from r in _db.Controller_Event_Log where r.SignalID == signalId && r.Timestamp >= startTime && r.Timestamp < endTime && r.EventCode == eventCode select r).ToList()); } catch (Exception ex) { IApplicationEventRepository logRepository = ApplicationEventRepositoryFactory.Create(); ApplicationEvent e = new ApplicationEvent(); e.ApplicationName = "MOE.Common"; e.Class = GetType().ToString(); e.Function = "GetSignalEventsByEventCode"; e.SeverityLevel = ApplicationEvent.SeverityLevels.High; e.Timestamp = DateTime.Now; e.Description = ex.Message; logRepository.Add(e); throw; } }
public List <Controller_Event_Log> GetTopNumberOfSignalEventsBetweenDates(string signalId, int numberOfRecords, DateTime startTime, DateTime endTime) { try { List <Controller_Event_Log> events = (from r in _db.Controller_Event_Log where r.SignalID == signalId && r.Timestamp >= startTime && r.Timestamp < endTime select r).Take(numberOfRecords).ToList(); if (events != null) { return(events); } List <Controller_Event_Log> emptyEvents = new List <Controller_Event_Log>(); return(emptyEvents); } catch (Exception ex) { IApplicationEventRepository logRepository = ApplicationEventRepositoryFactory.Create(); ApplicationEvent e = new ApplicationEvent(); e.ApplicationName = "MOE.Common"; e.Class = GetType().ToString(); e.Function = "GetTopNumberOfSignalEventsBetweenDates"; e.SeverityLevel = ApplicationEvent.SeverityLevels.High; e.Timestamp = DateTime.Now; e.Description = ex.Message; logRepository.Add(e); throw; } }
protected void GetSignalObjects() { try { if (Signals == null) { Signals = new List <Models.Signal>(); } if (Signals.Count == 0) { var signalRepository = SignalsRepositoryFactory.Create(); foreach (var filterSignal in FilterSignals) { if (!filterSignal.Exclude) { var signals = signalRepository.GetSignalsBetweenDates(filterSignal.SignalId, StartDate, EndDate); foreach (var signal in signals) { RemoveApproachesByFilter(filterSignal, signal); signal.Approaches = signal.Approaches.OrderBy(a => a.ProtectedPhaseNumber).ToList(); } Signals.AddRange(signals); } } } } catch (Exception e) { var errorLog = ApplicationEventRepositoryFactory.Create(); errorLog.QuickAdd(Assembly.GetExecutingAssembly().GetName().ToString(), GetType().DisplayName(), e.TargetSite.ToString(), ApplicationEvent.SeverityLevels.High, e.Message); throw new Exception("Unable to apply signal filter"); } }
static void Main(string[] args) { IApplicationEventRepository errorRepository = ApplicationEventRepositoryFactory.Create(); SignalFtpOptions signalFtpOptions = new SignalFtpOptions( Convert.ToInt32(ConfigurationManager.AppSettings["SNMPTimeout"]), Convert.ToInt32(ConfigurationManager.AppSettings["SNMPRetry"]), Convert.ToInt32(ConfigurationManager.AppSettings["SNMPPort"]), Convert.ToBoolean(ConfigurationManager.AppSettings["DeleteFilesAfterFTP"]), ConfigurationManager.AppSettings["LocalDirectory"], Convert.ToInt32(ConfigurationManager.AppSettings["FTPConnectionTimeoutInSeconds"]), Convert.ToInt32(ConfigurationManager.AppSettings["FTPReadTimeoutInSeconds"]), Convert.ToBoolean(ConfigurationManager.AppSettings["skipCurrentLog"]), Convert.ToBoolean(ConfigurationManager.AppSettings["RenameDuplicateFiles"]), Convert.ToInt32(ConfigurationManager.AppSettings["waitBetweenFileDownloadMilliseconds"]) ); int maxThreads = Convert.ToInt32(ConfigurationManager.AppSettings["MaxThreads"]); MOE.Common.Models.SPM db = new MOE.Common.Models.SPM(); ISignalsRepository signalsRepository = SignalsRepositoryFactory.Create(db); var signals = signalsRepository.GetLatestVersionOfAllSignalsForFtp(); var options = new ParallelOptions { MaxDegreeOfParallelism = maxThreads }; Parallel.ForEach(signals.AsEnumerable(), options, signal => //foreach (var signal in signals) { try { MOE.Common.Business.SignalFtp signalFtp = new MOE.Common.Business.SignalFtp(signal, signalFtpOptions); if (!Directory.Exists(signalFtpOptions.LocalDirectory + signal.SignalID)) { Directory.CreateDirectory(signalFtpOptions.LocalDirectory + signal.SignalID); } //Get the records over FTP if (CheckIfIPAddressIsValid(signal)) { try { signalFtp.GetCurrentRecords(); } 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 " + signal.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 " + signal.SignalID); } } ); }
public void Initialize() { InMemoryApplicationEventRepository appRep = new InMemoryApplicationEventRepository(_db); InMemoryControllerEventLogRepository cel = new InMemoryControllerEventLogRepository(_db); ControllerEventLogRepositoryFactory.SetRepository(cel); ApplicationEventRepositoryFactory.SetApplicationEventRepository(appRep); }
CheckForLowDetectorHits(Models.Signal signal) { var detectors = signal.GetDetectorsForSignalThatSupportAMetric(6); //Parallel.ForEach(detectors, options, detector => foreach (var detector in detectors) { try { if (detector.DetectionTypes != null && detector.DetectionTypes.Any(d => d.DetectionTypeID == 2)) { var channel = detector.DetChannel; var direction = detector.Approach.DirectionType.Description; var start = new DateTime(); var 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); } var currentVolume = detector.GetVolumeForPeriod(start, end); //Compare collected hits to low hit threshold, if (currentVolume < Convert.ToInt32(Settings.LowHitThreshold)) { var error = new 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) { var er = ApplicationEventRepositoryFactory.Create(); er.QuickAdd("SPMWatchDog", "Program", "CheckForLowDetectorHits", ApplicationEvent.SeverityLevels.Medium, detector.DetectorID + "-" + ex.Message); } } //); }
protected void LogMetricRun() { var appEventRepository = ApplicationEventRepositoryFactory.Create(); var applicationEvent = new ApplicationEvent(); applicationEvent.ApplicationName = "SPM Website"; applicationEvent.Description = MetricType.ChartName + " Executed"; applicationEvent.SeverityLevel = ApplicationEvent.SeverityLevels.Low; applicationEvent.Timestamp = DateTime.Now; appEventRepository.Add(applicationEvent); }
private static bool TestIPAddress(MOE.Common.Models.Signal Signal) { IPAddress ip; bool hasValidIP = true; hasValidIP = IPAddress.TryParse(Signal.IPAddress, out ip); if (Signal.IPAddress == "0") { hasValidIP = false; } //test to see if the address is reachable if (hasValidIP) { Ping pingSender = new Ping(); PingOptions pingOptions = new PingOptions(); // Use the default Ttl value which is 128, // but change the fragmentation behavior. pingOptions.DontFragment = true; // Create a buffer of 32 bytes of data to be transmitted. string data = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"; byte[] buffer = Encoding.ASCII.GetBytes(data); int timeout = 120; PingReply reply = null; try { reply = pingSender.Send(Signal.IPAddress, timeout, buffer, pingOptions); if (reply.Status != IPStatus.Success) { var errorLog = ApplicationEventRepositoryFactory.Create(); errorLog.QuickAdd(System.Reflection.Assembly.GetExecutingAssembly().GetName().ToString(), "GetMaxTimeRecords", "TestIPAddress", ApplicationEvent.SeverityLevels.High, "Signal - " + Signal.SignalID + " IP Address - " + Signal.IPAddress + " - Invalid IP Address"); hasValidIP = false; } } catch (Exception e) { if (reply == null || reply.Status != IPStatus.Success) { var errorLog = ApplicationEventRepositoryFactory.Create(); errorLog.QuickAdd(System.Reflection.Assembly.GetExecutingAssembly().GetName().ToString(), "GetMaxTimeRecords", e.TargetSite.ToString(), ApplicationEvent.SeverityLevels.High, "Signal - " + Signal.SignalID + " IP Address - " + Signal.IPAddress + " - " + e.Message); hasValidIP = false; } } } return(hasValidIP); }
public SignalAggregationCreateMetricTestsBase() { Db.ClearTables(); Db.PopulateSignal(); Db.PopulateSignalsWithApproaches(); Db.PopulateApproachesWithDetectors(); MOE.Common.Models.Repositories.SignalsRepositoryFactory.SetSignalsRepository(new InMemorySignalsRepository(Db)); MetricTypeRepositoryFactory.SetMetricsRepository(new InMemoryMetricTypeRepository(Db)); ApplicationEventRepositoryFactory.SetApplicationEventRepository(new InMemoryApplicationEventRepository(Db)); Common.Models.Repositories.DirectionTypeRepositoryFactory.SetDirectionsRepository(new InMemoryDirectionTypeRepository()); ApproachRepositoryFactory.SetApproachRepository(new InMemoryApproachRepository(Db)); MOE.Common.Models.Repositories.ApproachEventCountAggregationRepositoryFactory.SetRepository (new InMemoryApproachEventCountAggregationRepository(Db)); MOE.Common.Models.Repositories.SignalEventCountAggregationRepositoryFactory.SetRepository (new InMemorySignalEventCountAggregationRepository(Db)); SetSpecificAggregateRepositoriesForTest(); }
public static void DeleteFilesFromFTPServer(FTPSClient FTP, List <string> FilesToDelete, int WaitBetweenRecords, string RemoteDirectory, string Server) //, CancellationToken Token) { var errorRepository = ApplicationEventRepositoryFactory.Create(); foreach (var FTPFile in FilesToDelete) { try { FTP.DeleteFile(FTPFile); } catch (FTPException ex) { errorRepository.QuickAdd("FTPFromAllcontrollers", "Signal", " DeleteFilesFromFTPServer", ApplicationEvent.SeverityLevels.Medium, Server + " " + ex.Message); Console.WriteLine(ex.Message); } catch (AggregateException) { Console.WriteLine("Connection Failure"); } catch (SocketException ex) { errorRepository.QuickAdd("FTPFromAllcontrollers", "Signal", " DeleteFilesFromFTPServer", ApplicationEvent.SeverityLevels.Medium, Server + " " + ex.Message); Console.WriteLine(ex.Message); } catch (IOException ex) { errorRepository.QuickAdd("FTPFromAllcontrollers", "Signal", " DeleteFilesFromFTPServer", ApplicationEvent.SeverityLevels.Medium, Server + " " + ex.Message); Console.WriteLine(ex.Message); } catch (Exception ex) { errorRepository.QuickAdd("FTPFromAllcontrollers", "Signal", " DeleteFilesFromFTPServer", ApplicationEvent.SeverityLevels.Medium, Server + " " + ex.Message); Console.WriteLine("Exception:" + ex.Message + " While Deleting file: " + FTPFile + " from " + RemoteDirectory + " on " + Server); } Thread.Sleep(WaitBetweenRecords); } }
private void DeleteFilesFromFtpServer(FtpClient ftpClient, List <String> filesToDelete) { var errorRepository = ApplicationEventRepositoryFactory.Create(); foreach (var ftpFile in filesToDelete) { try { ftpClient.DeleteFile(Signal.ControllerType.FTPDirectory + "/" + ftpFile); } catch (FTPException ex) { errorRepository.QuickAdd("FTPFromAllcontrollers", "Signal", "DeleteFilesFromFTPServer", Models.ApplicationEvent.SeverityLevels.Medium, Signal.SignalID + " @ " + Signal.IPAddress + " - " + ex.Message); Console.WriteLine(Signal.SignalID + " @ " + Signal.IPAddress + " - " + ex.Message); } catch (AggregateException) { errorRepository.QuickAdd("FTPFromAllcontrollers", "Signal", "DeleteFilesFromFTPServer", Models.ApplicationEvent.SeverityLevels.Medium, Signal.SignalID + " @ " + Signal.IPAddress + " - " + "Connection Failure one or more errors occured deleting the file via FTP"); Console.WriteLine(Signal.SignalID + " @ " + Signal.IPAddress + " - " + "Connection Failure one or more errors occured deleting the file via FTP"); } catch (SocketException ex) { errorRepository.QuickAdd("FTPFromAllcontrollers", "Signal", "DeleteFilesFromFTPServer", Models.ApplicationEvent.SeverityLevels.Medium, Signal.SignalID + " @ " + Signal.IPAddress + " - " + ex.Message); Console.WriteLine(ex.Message); } catch (IOException ex) { errorRepository.QuickAdd("FTPFromAllcontrollers", "Signal", "DeleteFilesFromFTPServer", Models.ApplicationEvent.SeverityLevels.Medium, Signal.SignalID + " @ " + Signal.IPAddress + " - " + ex.Message); Console.WriteLine(ex.Message); } catch (Exception ex) { errorRepository.QuickAdd("FTPFromAllcontrollers", "Signal", "DeleteFilesFromFTPServer", Models.ApplicationEvent.SeverityLevels.Medium, Signal.SignalID + " @ " + Signal.IPAddress + " - " + ex.Message); Console.WriteLine("Exception:" + ex.Message + " While Deleting file: " + ftpFile + " from " + Signal.ControllerType.FTPDirectory + " on " + Signal.IPAddress); } if (SignalFtpOptions.WaitBetweenFileDownloadInMilliseconds > 0) { Thread.Sleep(SignalFtpOptions.WaitBetweenFileDownloadInMilliseconds); } } }
private void SendMessage(MailMessage message) { var er = ApplicationEventRepositoryFactory.Create(); var smtp = new SmtpClient(Settings.EmailServer); try { Console.WriteLine("Sent message to: " + message.To + "\nMessage text: " + message.Body + "\n"); smtp.Send(message); Thread.Sleep(5000); er.QuickAdd("SPMWatchDog", "Program", "SendMessage", ApplicationEvent.SeverityLevels.Information, "Email Sent Successfully to: " + message.To); } catch (Exception ex) { er.QuickAdd("SPMWatchDog", "Program", "SendMessage", ApplicationEvent.SeverityLevels.Medium, ex.Message); } }
public void Initialize() { db.ClearTables(); XmlToListImporter.LoadControllerEventLog("7185_10_17_2017.xml", db); XmlToListImporter.LoadSignals("signals.xml", db); XmlToListImporter.LoadApproaches("approachesfor7185.xml", db); XmlToListImporter.LoadDetectors("detectorsFor7185.xml", db); XmlToListImporter.AddDetectionTypesToDetectors ("DetectorTypesforDetectorsFor7185.xml", db); XmlToListImporter.AddDetectionTypesToMetricTypes("mtdt.xml", db); MOE.Common.Models.Repositories.SignalsRepositoryFactory.SetSignalsRepository( new InMemorySignalsRepository(db)); MetricTypeRepositoryFactory.SetMetricsRepository(new InMemoryMetricTypeRepository(db)); ApplicationEventRepositoryFactory.SetApplicationEventRepository( new InMemoryApplicationEventRepository(db)); Models.Repositories.DirectionTypeRepositoryFactory.SetDirectionsRepository( new InMemoryDirectionTypeRepository()); ApproachRepositoryFactory.SetApproachRepository(new InMemoryApproachRepository(db)); ControllerEventLogRepositoryFactory.SetRepository(new InMemoryControllerEventLogRepository(db)); DetectorRepositoryFactory.SetDetectorRepository(new InMemoryDetectorRepository(db)); }
private void GetChart(SplitFailPhase splitFailPhase, string chartName, List <string> returnString, bool getPermissivePhase, Approach approach) { var sfChart = new SplitFailChart(this, splitFailPhase, getPermissivePhase); var detector = approach.GetDetectorsForMetricType(12).FirstOrDefault(); if (detector != null) { var direction = detector.MovementType.Description; if (getPermissivePhase) { sfChart.Chart.BackColor = Color.LightGray; } } Thread.Sleep(300); chartName = chartName.Replace(".", approach.DirectionType.Description + "."); try { sfChart.Chart.SaveImage(MetricFileLocation + chartName, ChartImageFormat.Jpeg); } catch (Exception ex) { try { sfChart.Chart.SaveImage(MetricFileLocation + chartName, ChartImageFormat.Jpeg); } catch { var appEventRepository = ApplicationEventRepositoryFactory.Create(); var applicationEvent = new ApplicationEvent(); applicationEvent.ApplicationName = "SPM Website"; applicationEvent.Description = MetricType.ChartName + ex.Message + " Failed While Saving File"; applicationEvent.SeverityLevel = ApplicationEvent.SeverityLevels.Medium; applicationEvent.Timestamp = DateTime.Now; appEventRepository.Add(applicationEvent); } } returnString.Add(MetricWebPath + chartName); }
private bool TransferFile(FtpClient ftpClient, FtpListItem ftpListItem) { try { string localFileName = ftpListItem.Name; Console.WriteLine(@"Transfering " + ftpListItem.Name + @" from " + Signal.ControllerType.FTPDirectory + @" on " + Signal.IPAddress + @" to " + SignalFtpOptions.LocalDirectory + Signal.SignalID); //chek to see if the local dir exists. //if not, make it. if (!Directory.Exists(SignalFtpOptions.LocalDirectory)) { Directory.CreateDirectory(SignalFtpOptions.LocalDirectory); } if (SignalFtpOptions.RenameDuplicateFiles && File.Exists(SignalFtpOptions.LocalDirectory + Signal.SignalID + @"\" + ftpListItem.Name)) { char[] fileExtension = new[] { '.', 'd', 'a', 't' }; string tempFileName = localFileName.TrimEnd(fileExtension); localFileName = tempFileName + "-" + Convert.ToInt32(DateTime.Now.TimeOfDay.TotalSeconds) + ".dat"; FileToBeDeleted = localFileName; } if (!ftpClient.DownloadFile(SignalFtpOptions.LocalDirectory + Signal.SignalID + @"\" + localFileName, ".." + Signal.ControllerType.FTPDirectory + @"/" + ftpListItem.Name)) { Console.WriteLine(@"Unable to download file " + Signal.ControllerType.FTPDirectory + @"/" + ftpListItem.Name); var errorLog = ApplicationEventRepositoryFactory.Create(); errorLog.QuickAdd("FTPFromAllControllers", "MOE.Common.Business.SignalFTP", "TransferFile", ApplicationEvent.SeverityLevels.High, Signal.ControllerType.FTPDirectory + " @ " + Signal.IPAddress + " - " + "Unable to download file " + Signal.ControllerType.FTPDirectory + @"/" + ftpListItem.Name); return(false); } return(true); } catch (Exception e) { Console.WriteLine(e); var errorLog = ApplicationEventRepositoryFactory.Create(); errorLog.QuickAdd("FTPFromAllControllers", "MOE.Common.Business.SignalFTP", "TransferFile", ApplicationEvent.SeverityLevels.High, "SignalID " + Signal.SignalID + " > " + Signal.ControllerType.FTPDirectory + @"/" + ftpListItem.Name + " File can't be downloaded. Error Mesage " + e.Message); File.Delete(SignalFtpOptions.LocalDirectory + Signal.SignalID + @"\" + FileToBeDeleted); return(false); } }
public static void InitializeTestDataFor7185Feb012018(InMemoryMOEDatabase db) { db.ClearTables(); XmlToListImporter.LoadControllerEventLog("7185Events02_01_2018.Xml", db); XmlToListImporter.LoadSignals("signals.xml", db); XmlToListImporter.LoadApproaches("approachesfor7185.xml", db); XmlToListImporter.LoadDetectors("detectorsFor7185.xml", db); XmlToListImporter.AddDetectionTypesToDetectors ("DetectorTypesforDetectorsFor7185.xml", db); XmlToListImporter.AddDetectionTypesToMetricTypes("mtdt.xml", db); MOE.Common.Models.Repositories.SignalsRepositoryFactory.SetSignalsRepository( new InMemorySignalsRepository(db)); MetricTypeRepositoryFactory.SetMetricsRepository(new InMemoryMetricTypeRepository(db)); ApplicationEventRepositoryFactory.SetApplicationEventRepository( new InMemoryApplicationEventRepository(db)); DirectionTypeRepositoryFactory.SetDirectionsRepository( new InMemoryDirectionTypeRepository()); SpeedEventRepositoryFactory.SetSignalsRepository(new InMemorySpeedEventRepository(db)); ApproachRepositoryFactory.SetApproachRepository(new InMemoryApproachRepository(db)); ControllerEventLogRepositoryFactory.SetRepository(new InMemoryControllerEventLogRepository(db)); DetectorRepositoryFactory.SetDetectorRepository(new InMemoryDetectorRepository(db)); XmlToListImporter.LoadSpeedEvents("7185speed.xml", db); }
public int GetEventCountByEventCodesParamDateTimeRange(string signalId, DateTime startTime, DateTime endTime, int startHour, int startMinute, int endHour, int endMinute, List <int> eventCodes, int param) { try { return ((from s in _db.Controller_Event_Log where s.SignalID == signalId && s.Timestamp >= startTime && s.Timestamp <= endTime && ((s.Timestamp.Hour > startHour && s.Timestamp.Hour < endHour) || (s.Timestamp.Hour == startHour && s.Timestamp.Hour == endHour && s.Timestamp.Minute >= startMinute && s.Timestamp.Minute <= endMinute) || (s.Timestamp.Hour == startHour && s.Timestamp.Hour < endHour && s.Timestamp.Minute >= startMinute) || (s.Timestamp.Hour < startHour && s.Timestamp.Hour == endHour && s.Timestamp.Minute <= endMinute)) && s.EventParam == param && eventCodes.Contains(s.EventCode) select s).Count()); } catch (Exception ex) { IApplicationEventRepository logRepository = ApplicationEventRepositoryFactory.Create(); ApplicationEvent e = new ApplicationEvent(); e.ApplicationName = "MOE.Common"; e.Class = GetType().ToString(); e.Function = "GetEventCountByEventCodesParamDateTimeRange"; e.SeverityLevel = ApplicationEvent.SeverityLevels.High; e.Timestamp = DateTime.Now; e.Description = ex.Message; logRepository.Add(e); throw; } }
static void Main(string[] args) { IApplicationEventRepository errorRepository = ApplicationEventRepositoryFactory.Create(); //while (true) //{ try { SignalFtpOptions signalFtpOptions = new SignalFtpOptions( Convert.ToInt32(ConfigurationManager.AppSettings["SNMPTimeout"]), Convert.ToInt32(ConfigurationManager.AppSettings["SNMPRetry"]), Convert.ToInt32(ConfigurationManager.AppSettings["SNMPPort"]), Convert.ToBoolean(ConfigurationManager.AppSettings["DeleteFilesAfterFTP"]), ConfigurationManager.AppSettings["LocalDirectory"], Convert.ToInt32(ConfigurationManager.AppSettings["FTPConnectionTimeoutInSeconds"]), Convert.ToInt32(ConfigurationManager.AppSettings["FTPReadTimeoutInSeconds"]), Convert.ToBoolean(ConfigurationManager.AppSettings["skipCurrentLog"]), Convert.ToBoolean(ConfigurationManager.AppSettings["RenameDuplicateFiles"]), Convert.ToInt32(ConfigurationManager.AppSettings["waitBetweenFileDownloadMilliseconds"]), Convert.ToInt32(ConfigurationManager.AppSettings["MaximumNumberOfFilesTransferAtOneTime"]) ); int maxThreads = Convert.ToInt32(ConfigurationManager.AppSettings["MaxThreads"]); int minutesToWait = Convert.ToInt32(ConfigurationManager.AppSettings["MinutesToWait"]); MOE.Common.Models.SPM db = new MOE.Common.Models.SPM(); ISignalsRepository signalsRepository = SignalsRepositoryFactory.Create(db); var signals = signalsRepository.GetLatestVersionOfAllSignalsForFtp(); //.Where(s =>s.SignalID =="7060"); // EOS Signal at Bangerter and 3500 South var options = new ParallelOptions { MaxDegreeOfParallelism = maxThreads }; Parallel.ForEach(signals.AsEnumerable(), options, signal => //foreach (var signal in signals) { try { MOE.Common.Business.SignalFtp signalFtp = new MOE.Common.Business.SignalFtp(signal, signalFtpOptions); if (!Directory.Exists(signalFtpOptions.LocalDirectory + signal.SignalID)) { Directory.CreateDirectory(signalFtpOptions.LocalDirectory + signal.SignalID); } if (CheckIfIPAddressIsValid(signal)) { try { signalFtp.GetCurrentRecords(); } 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 " + signal.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 " + signal.SignalID); } //} }); //string timeNow = DateTime.Now.ToString("t"); //Console.WriteLine("At {0}, it is time to take a nap. Program will wait for {1} minutes.", timeNow, minutesToWait); //System.Threading.Thread.Sleep(minutesToWait * 60 * 1000); } catch (AggregateException ex) { Console.WriteLine("Error At Highest Level for Main (FTPfromAllControllers) " + ex.Message); errorRepository.QuickAdd("FTPFromAllControllers", "Main", "Main Loop", MOE.Common.Models.ApplicationEvent.SeverityLevels.Medium, "Error At Highest Level for Main (FTPfromAllControllers) at " + DateTime.Now.ToString("g")); } //} }
private void DeleteAllEosFiles(Signal signal, List <string> retrievedFiles) { //Console.WriteLine(); Console.WriteLine(); Console.WriteLine(); Console.WriteLine("Start of DeleteAllEosFIles"); Console.WriteLine("The Host is {0}", signal.IPAddress.ToString()); FtpClient sftpEos = new FtpClient { Credentials = new NetworkCredential(signal.ControllerType.UserName, signal.ControllerType.Password), DataConnectionType = FtpDataConnectionType.PASV, DataConnectionEncryption = true, SslProtocols = System.Security.Authentication.SslProtocols.Tls12, EnableThreadSafeDataConnections = true, EncryptionMode = FtpEncryptionMode.None }; sftpEos.Host = signal.IPAddress.ToString(); sftpEos.Connect(); Console.WriteLine("After Connection for {0} signalId {1} is connected ", signal.IPAddress.ToString(), signal.SignalID, sftpEos.IsConnected.ToString()); var errorRepository = ApplicationEventRepositoryFactory.Create(); var filePattern = ".datZ"; var remotePWD = sftpEos.GetWorkingDirectory(); using (sftpEos) { //Console.WriteLine(" In the retrieved files, there are {0} files. PWD is {1}", retrievedFiles.Count(), remotePWD); foreach (var ftpFileName in retrievedFiles) { if (ftpFileName.EndsWith(filePattern)) { try { sftpEos.DeleteFile("../" + Signal.ControllerType.FTPDirectory + "/" + ftpFileName); // Console.Write(" This file is deleted -> ..{0}/{1}\r", Signal.ControllerType.FTPDirectory, ftpFileName); } catch (AggregateException) { errorRepository.QuickAdd("FTPFromAllcontrollers", "Signal", "DeleteFilesFromFTPServer", Models.ApplicationEvent.SeverityLevels.Medium, Signal.SignalID + " @ " + Signal.IPAddress + " - " + "Connection Failure one or more errors occured deleting the file via FTP"); Console.WriteLine(Signal.SignalID + " @ " + Signal.IPAddress + " - " + "Connection Failure one or more errors occured deleting the file via FTP"); } catch (SocketException ex) { errorRepository.QuickAdd("FTPFromAllcontrollers", "Signal", "DeleteFilesFromFTPServer", Models.ApplicationEvent.SeverityLevels.Medium, Signal.SignalID + " @ " + Signal.IPAddress + " - " + ex.Message); Console.WriteLine(ex.Message); } catch (IOException ex) { errorRepository.QuickAdd("FTPFromAllcontrollers", "Signal", "DeleteFilesFromFTPServer", Models.ApplicationEvent.SeverityLevels.Medium, Signal.SignalID + " @ " + Signal.IPAddress + " - " + ex.Message); Console.WriteLine(ex.Message); } catch (Exception ex) { errorRepository.QuickAdd("FTPFromAllcontrollers", "Signal", "DeleteFilesFromFTPServer", Models.ApplicationEvent.SeverityLevels.Medium, Signal.SignalID + " @ " + Signal.IPAddress + " - " + ex.Message); Console.WriteLine("Exception:" + ex.Message + " While Deleting file: " + ftpFileName + " from " + Signal.ControllerType.FTPDirectory + " on " + Signal.IPAddress); } if (SignalFtpOptions.WaitBetweenFileDownloadInMilliseconds > 0) { Thread.Sleep(SignalFtpOptions.WaitBetweenFileDownloadInMilliseconds); } } } } sftpEos.Disconnect(); }
public static bool GetCurrentRecords(string Server, string SignalId, string User, string Password, string LocalDir, string RemoteDir, bool DeleteFilesAfterFTP, int SNMPRetry, int SNMPTimeout, int SNMPPort, bool ImportAfterFTP, bool activemode, int waitbetweenrecords, BulkCopyOptions Options, int FTPTimeout) //, CancellationToken Token) { var recordsComplete = false; var errorRepository = ApplicationEventRepositoryFactory.Create(); //Initialize the FTP object var RetryFiles = new List <string>(); var FTP = new FTPSClient(); var Cred = new NetworkCredential(User, Password); var SSLMode = ESSLSupportMode.ClearText; var DM = EDataConnectionMode.Passive; if (activemode) { DM = EDataConnectionMode.Active; } var connected = false; var FilePattern = ".dat"; try { try { var tokenSource = new CancellationTokenSource(TimeSpan.FromSeconds(30)); var token2 = tokenSource.Token; Task task = Task.Factory.StartNew( () => FTP.Connect(Server, 21, Cred, SSLMode, null, null, 0, 0, 0, FTPTimeout, true, DM) , token2); task.Wait(token2); if (token2.IsCancellationRequested) { token2.ThrowIfCancellationRequested(); } } catch (AggregateException) { errorRepository.QuickAdd("FTPFromAllcontrollers", "Signal", "ConnectToController", ApplicationEvent.SeverityLevels.Medium, "The connection task timed out for signal " + Server); } { Console.WriteLine("Connection Failure"); } connected = true; } //If there is an error, Print the error and go on to the next file. catch (FTPException ex) { errorRepository.QuickAdd("FTPFromAllcontrollers", "Signal", "ConnectToController", ApplicationEvent.SeverityLevels.Medium, Server + " " + ex.Message); Console.WriteLine(ex.Message); } catch (AggregateException) { Console.WriteLine("Connection Failure"); } catch (SocketException ex) { errorRepository.QuickAdd("FTPFromAllcontrollers", "Signal", "ConnectToController", ApplicationEvent.SeverityLevels.Medium, Server + " " + ex.Message); Console.WriteLine(ex.Message); } catch (IOException ex) { errorRepository.QuickAdd("FTPFromAllcontrollers", "Signal", "ConnectToController", ApplicationEvent.SeverityLevels.Medium, Server + " " + ex.Message); Console.WriteLine(ex.Message); } catch (Exception ex) { errorRepository.QuickAdd("FTPFromAllcontrollers", "Signal", "ConnectToController", ApplicationEvent.SeverityLevels.Medium, Server + " " + ex.Message); Console.WriteLine(ex.Message); } if (connected) { try { //if (Token.IsCancellationRequested) //{ // Token.ThrowIfCancellationRequested(); //} FTP.SetCurrentDirectory(".."); FTP.SetCurrentDirectory(RemoteDir); } catch (AggregateException) { Console.WriteLine("Connection Failure for " + Server); } catch (Exception ex) { errorRepository.QuickAdd("FTPFromAllcontrollers", "Signal", "GetCurrentRecords", ApplicationEvent.SeverityLevels.Medium, Server + " " + ex.Message); Console.WriteLine(ex.Message); } try { IList <DirectoryListItem> RemoteFiles = null; var tokenSource = new CancellationTokenSource(TimeSpan.FromSeconds(30)); var token = tokenSource.Token; Task task = Task.Factory.StartNew(() => RemoteFiles = FTP.GetDirectoryList(RemoteDir) , token); task.Wait(token); if (token.IsCancellationRequested) { token.ThrowIfCancellationRequested(); } var RetrievedFiles = new List <string>(); //errorRepository.QuickAdd("FTPFromAllcontrollers","Signal", "GetFTPFileList", Models.ApplicationEvent.SeverityLevels.Information, "Retrevied File list from " + Server); if (RemoteFiles != null) { foreach (var FTPFile in RemoteFiles) { if (!FTPFile.IsDirectory && FTPFile.Name.Contains(FilePattern)) { try { //if (Token.IsCancellationRequested) //{ // Token.ThrowIfCancellationRequested(); //} //If there are no errors, get the file, and add the filename to the retrieved files array for deletion later var token2 = tokenSource.Token; var task2 = Task.Factory.StartNew( () => TransferFiles(FTP, FTPFile.Name, LocalDir, RemoteDir, Server) , token2); task2.Wait(token2); if (token2.IsCancellationRequested) { token2.ThrowIfCancellationRequested(); } else { RetrievedFiles.Add(FTPFile.Name); recordsComplete = true; } } //If there is an error, Print the error and try the file again. catch (AggregateException) { errorRepository.QuickAdd("FTPFromAllcontrollers", "Signal", "TransferFiles", ApplicationEvent.SeverityLevels.Medium, "Transfer Task Timed Out"); } catch (Exception ex) { var errorMessage = "Exception:" + ex.Message + " While Transfering file: " + FTPFile + " from " + RemoteDir + " on " + Server + " to " + LocalDir; Console.WriteLine(errorMessage); errorRepository.QuickAdd("FTPFromAllcontrollers", "Signal", "TransferFiles", ApplicationEvent.SeverityLevels.Medium, errorMessage); RetryFiles.Add(FTPFile.Name); } Thread.Sleep(waitbetweenrecords); } } } //Delete the files we downloaded. We don't want ot have to deal with the file more than once. If we delete the file form the controller once we capture it, it will reduce redundancy. if (DeleteFilesAfterFTP) { DeleteFilesFromFTPServer(FTP, RetrievedFiles, waitbetweenrecords, RemoteDir, Server); //, Token); } } catch (Exception ex) { errorRepository.QuickAdd("FTPFromAllcontrollers", "Signal", "RetrieveFiles", ApplicationEvent.SeverityLevels.Medium, Server + " " + ex.Message); Console.WriteLine(ex.Message); } FTP.Close(); FTP.Dispose(); //********************************************************** //I don't think this is doing much good. -SJ 11-22-2016 //Try to get the missing files again with a new FTP connection //if (RetryFiles.Count > 1) //{ // foreach (string FTPFile in RetryFiles) // { // try // { // Thread.Sleep(waitbetweenrecords); // FTPSClient _FTP = new FTPSClient(); // _FTP.Connect(Server, 21, Cred, SSLMode, null, null, 0, 0, 0, 6000, false, DM); // TransferFiles(_FTP, FTPFile, LocalDir, RemoteDir, Server); // if (DeleteFilesAfterFTP) // { // try // { // _FTP.DeleteFile(FTPFile); // } // catch (Exception ex) // { // Console.WriteLine("Exception:" + ex.Message + " While Deleting file: " + FTPFile + " from " + RemoteDir + " on " + Server + " to " + LocalDir); // } // } // _FTP.Close(); // _FTP.Dispose(); // } // //If there is an error, Print the error and move on. // catch (Exception ex1) // { // Console.WriteLine("Exception:" + ex1.Message + " While Transfering file: " + FTPFile + " from " + RemoteDir + " on " + Server + " to " + LocalDir); // } // } // } // RetryFiles.Clear(); //************************************** //Turn Logging off. //The ASC3 controller stoploggin if the current file is removed. to make sure logging comtinues, we must turn the loggin feature off on the //controller, then turn it back on. try { TurnOffASC3LoggingOverSNMP(SNMPRetry, SNMPPort, SNMPTimeout, Server); Thread.Sleep(SNMPTimeout); TurnOnASC3LoggingOverSNMP(SNMPRetry, SNMPPort, SNMPTimeout, Server); } catch { } } return(recordsComplete); }
public void GetCurrentRecords() { var errorRepository = ApplicationEventRepositoryFactory.Create(); FtpClient ftpClient = new FtpClient(Signal.IPAddress); ftpClient.Credentials = new NetworkCredential(Signal.ControllerType.UserName, Signal.ControllerType.Password); ftpClient.ConnectTimeout = SignalFtpOptions.FtpConectionTimeoutInSeconds * 1000; ftpClient.ReadTimeout = SignalFtpOptions.FtpReadTimeoutInSeconds * 1000; if (Signal.ControllerType.ActiveFTP) { ftpClient.DataConnectionType = FtpDataConnectionType.AutoActive; } var filePattern = ".dat"; using (ftpClient) { try { ftpClient.Connect(); } //If there is an error, Print the error and go on to the next file. catch (FTPException ex) { errorRepository.QuickAdd("FTPFromAllcontrollers", "Signal", "GetCurrentRecords_ConnectToController", Models.ApplicationEvent.SeverityLevels.Medium, Signal.SignalID + " @ " + Signal.IPAddress + " - " + ex.Message); Console.WriteLine(Signal.SignalID + " @ " + Signal.IPAddress + " - " + ex.Message); return; } catch (AggregateException) { errorRepository.QuickAdd("FTPFromAllcontrollers", "Signal", "GetCurrentRecords_ConnectToController", Models.ApplicationEvent.SeverityLevels.Medium, Signal.SignalID + " @ " + Signal.IPAddress + " - " + "Connection Failure - One or more errors occured"); Console.WriteLine(Signal.SignalID + " @ " + Signal.IPAddress + " - " + "Connection Failure - One or more errors occured before connection established"); return; } catch (SocketException ex) { errorRepository.QuickAdd("FTPFromAllcontrollers", "Signal", "GetCurrentRecords_ConnectToController", Models.ApplicationEvent.SeverityLevels.Medium, Signal.SignalID + " @ " + Signal.IPAddress + " - " + ex.Message); Console.WriteLine(Signal.SignalID + " @ " + Signal.IPAddress + " - " + ex.Message); return; } catch (IOException ex) { errorRepository.QuickAdd("FTPFromAllcontrollers", "Signal", "GetCurrentRecords_ConnectToController", Models.ApplicationEvent.SeverityLevels.Medium, Signal.SignalID + " @ " + Signal.IPAddress + " - " + ex.Message); Console.WriteLine(Signal.SignalID + " @ " + Signal.IPAddress + " - " + ex.Message); return; } catch (Exception ex) { errorRepository.QuickAdd("FTPFromAllcontrollers", "Signal", "GetCurrentRecords_ConnectToController", Models.ApplicationEvent.SeverityLevels.Medium, Signal.SignalID + " @ " + Signal.IPAddress + " - " + ex.Message); Console.WriteLine(Signal.SignalID + " @ " + Signal.IPAddress + " - " + ex.Message); return; } if (ftpClient.IsConnected && ftpClient.DirectoryExists(".." + Signal.ControllerType.FTPDirectory)) { try { FtpListItem[] remoteFiles = ftpClient.GetListing(".." + Signal.ControllerType.FTPDirectory); var retrievedFiles = new List <string>(); if (remoteFiles != null) { DateTime localDate = DateTime.Now; if (SignalFtpOptions.SkipCurrentLog) { localDate = localDate.AddMinutes(-16); } else { localDate = localDate.AddMinutes(120); } foreach (var ftpFile in remoteFiles) { if (ftpFile.Type == FtpFileSystemObjectType.File && ftpFile.Name.Contains(filePattern) && ftpFile.Created < localDate) { try { if (TransferFile(ftpClient, ftpFile)) { retrievedFiles.Add(ftpFile.Name); } } //If there is an error, Print the error and try the file again. catch (AggregateException) { errorRepository.QuickAdd("FTPFromAllcontrollers", "Signal", "GetCurrentRecords_TransferFiles", Models.ApplicationEvent.SeverityLevels.Medium, Signal.SignalID + " @ " + Signal.IPAddress + " - " + "Transfer Task Timed Out"); break; } catch (Exception ex) { string errorMessage = "Exception:" + ex.Message + " While Transfering file: " + ftpFile + " from signal" + Signal.SignalID + " @ " + Signal.ControllerType.FTPDirectory + " on " + Signal.IPAddress + " to " + SignalFtpOptions.LocalDirectory + Signal.SignalID; Console.WriteLine(errorMessage); errorRepository.QuickAdd("FTPFromAllcontrollers", "Signal", "GetCurrentRecords_TransferFiles", Models.ApplicationEvent.SeverityLevels.Medium, errorMessage); //retryFiles.Add(ftpFile.Name); break; } if (SignalFtpOptions.WaitBetweenFileDownloadInMilliseconds > 0) { Thread.Sleep(SignalFtpOptions.WaitBetweenFileDownloadInMilliseconds); } } } //Delete the files we downloaded. We don't want ot have to deal with the file more than once. If we delete the file form the controller once we capture it, it will reduce redundancy. if (SignalFtpOptions.DeleteAfterFtp) { DeleteFilesFromFtpServer(ftpClient, retrievedFiles); //, Token); } } } catch (Exception ex) { errorRepository.QuickAdd("FTPFromAllcontrollers", "Signal", "GetCurrentRecords_RetrieveFiles", Models.ApplicationEvent.SeverityLevels.Medium, Signal.SignalID + " @ " + Signal.IPAddress + " - " + ex.Message); Console.WriteLine(Signal.SignalID + " @ " + Signal.IPAddress + " - " + ex.Message); } //ftp.Close(); } else { errorRepository.QuickAdd("FTPFromAllcontrollers", "Signal", "GetCurrentRecords_ConnectToController", Models.ApplicationEvent.SeverityLevels.Medium, Signal.SignalID + " @ " + Signal.IPAddress + " - " + "Cannot find directory " + Signal.ControllerType.FTPDirectory); Console.WriteLine(Signal.SignalID + " @ " + Signal.IPAddress + " - " + "Cannot find directory " + Signal.ControllerType.FTPDirectory); return; } //Turn Logging off. //The ASC3 controller stoploggin if the current file is removed. to make sure logging continues, we must turn the loggin feature off on the //controller, then turn it back on. try { if (SignalFtpOptions.SkipCurrentLog && CheckAsc3LoggingOverSnmp()) { //Do Nothing } else { try { TurnOffAsc3LoggingOverSnmp(); Thread.Sleep(SignalFtpOptions.SnmpTimeout); TurnOnAsc3LoggingOverSnmp(); } catch { } } } catch { } } }