Beispiel #1
0
        private void CheckFtpFromAllControllers(List <Models.Signal> signals)
        {
            var startHour     = new TimeSpan(Settings.ScanDayStartHour, 0, 0);
            var endHour       = new TimeSpan(Settings.ScanDayEndHour, 0, 0);
            var analysisStart = ScanDate.Date + startHour;
            var analysisEnd   = ScanDate.Date + endHour;
            var options       = new ParallelOptions();

            options.MaxDegreeOfParallelism = Settings.MaxDegreeOfParallelism;
            MOE.Common.Models.Repositories.IApplicationEventRepository eventRepository = MOE.Common.Models.Repositories.ApplicationEventRepositoryFactory.Create();
            var events = eventRepository.GetApplicationEventsBetweenDatesByApplication(analysisStart, analysisEnd, "FTPFromAllcontrollers");

            Parallel.ForEach(signals, options, signal =>
                             //foreach(var signal in signals)
            {
                ErrorCount = (events.Where(e => e.Description.Contains(signal.SignalID)).Count());
                if (ErrorCount > 0)
                {
                    MOE.Common.Models.SPMWatchDogErrorEvent error = new MOE.Common.Models.SPMWatchDogErrorEvent();
                    Console.WriteLine("Signal " + signal.SignalID + " can not download from this signal during " + ErrorCount.ToString() + " atempts.  ");
                    error.SignalID   = signal.SignalID;
                    error.DetectorID = "0";
                    error.Phase      = 0;
                    error.Direction  = "";
                    error.TimeStamp  = ScanDate;
                    error.Message    = "FTPFromAllControllers could not download from Controller.  Number of attempts were: " + ErrorCount.ToString();
                    error.ErrorCode  = 6;
                    CannotFtpFiles.Add(error);
                }
                //}
            });
        }
Beispiel #2
0
        private bool CheckAsc3LoggingOverSnmp()
        {
            MOE.Common.Models.Repositories.IApplicationEventRepository errorRepository =
                MOE.Common.Models.Repositories.ApplicationEventRepositoryFactory.Create();
            bool success = false;

            for (int counter = 0; counter < SignalFtpOptions.SnmpRetry; counter++)
            {
                int 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", " CheckASC3LoggingOverSNMP_Get",
                                             Models.ApplicationEvent.SeverityLevels.Medium,
                                             Signal.SignalID + " @ " + Signal.IPAddress + " - " + ex.Message);
                    Console.WriteLine(Signal.SignalID + " @ " + Signal.IPAddress + " - " + ex);
                }
                if (snmpState == 1)
                {
                    success = true;
                    break;
                }
                Thread.Sleep(SignalFtpOptions.SnmpTimeout);
            }
            return(success);
        }
Beispiel #3
0
        public static bool BulktoDb(DataTable elTable, BulkCopyOptions options)
        {
            MOE.Common.Models.Repositories.IApplicationEventRepository errorRepository = MOE.Common.Models.Repositories.ApplicationEventRepositoryFactory.Create();
            using (options.Connection)
            {
                using (var bulkCopy =
                           new SqlBulkCopy(options.ConnectionString, SqlBulkCopyOptions.UseInternalTransaction))
                {
                    for (var i = 1;; i++)
                    {
                        try
                        {
                            options.Connection.Open();
                        }
                        catch
                        {
                            Thread.Sleep(Settings.Default.SleepTime);
                        }
                        if (options.Connection.State == ConnectionState.Open)
                        {
                            if (Settings.Default.WriteToConsole)
                            {
                                Console.WriteLine("DB connection established");
                            }

                            break;
                        }
                    }
                    var sigId = "";
                    if (elTable.Rows.Count > 0)
                    {
                        var row = elTable.Rows[0];
                        sigId = row[0].ToString();
                    }

                    if (options.Connection.State == ConnectionState.Open)
                    {
                        bulkCopy.BulkCopyTimeout = Settings.Default.BulkCopyTimeout;

                        bulkCopy.BatchSize = Settings.Default.BulkCopyBatchSize;

                        if (Settings.Default.WriteToConsole)
                        {
                            bulkCopy.SqlRowsCopied +=
                                OnSqlRowsCopied;
                            bulkCopy.NotifyAfter = Settings.Default.BulkCopyBatchSize;
                        }
                        var tablename = Settings.Default.EventLogTableName;
                        bulkCopy.DestinationTableName = tablename;

                        if (elTable.Rows.Count > 0)
                        {
                            try
                            {
                                bulkCopy.WriteToServer(elTable);
                                if (Settings.Default.WriteToConsole)
                                {
                                    Console.WriteLine("!!!!!!!!! The bulk insert executed for Signal " + sigId +
                                                      " !!!!!!!!!");
                                }
                                options.Connection.Close();
                                return(true);
                            }
                            catch (SqlException ex)
                            {
                                if (ex.Number == 2601)
                                {
                                    if (Properties.Settings.Default.WriteToConsole)
                                    {
                                        errorRepository.QuickAdd("FTPFromAllcontrollers", "Signal", "BulktoDB_SQL.ex",
                                                                 Models.ApplicationEvent.SeverityLevels.Medium,
                                                                 "There is a permission error - " + sigId + " - " + ex.Message);
                                        Console.WriteLine("**** There is a permission error - " + sigId + " *****");
                                    }
                                }
                                else
                                {
                                    if (Properties.Settings.Default.WriteToConsole)
                                    {
                                        //Console.WriteLine("****DATABASE ERROR*****");
                                        errorRepository.QuickAdd("FTPFromAllcontrollers", "Signal", "BulktoDB_SQL.ex",
                                                                 Models.ApplicationEvent.SeverityLevels.Medium,
                                                                 "General Error - " + sigId + " - " + ex.Message);
                                        Console.WriteLine("DATABASE ERROR - " + sigId + " - " + ex.Message);
                                    }
                                }
                                options.Connection.Close();
                                return(false);
                            }
                            catch (Exception ex)
                            {
                                errorRepository.QuickAdd("FTPFromAllcontrollers", "Signal", "BulktoDB_Reg.ex",
                                                         Models.ApplicationEvent.SeverityLevels.Medium,
                                                         "General Error - " + sigId + " - " + ex.Message);
                                Console.WriteLine(ex);
                                return(false);
                            }
                        }
                        else
                        {
                            options.Connection.Close();
                            return(false);
                        }
                    }
                    else
                    {
                        return(false);
                    }
                }
            }
        }
Beispiel #4
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.Models.SPM _db = new MOE.Common.Models.SPM();

            MOE.Common.Models.Repositories.ISignalsRepository _sr = SignalsRepositoryFactory.Create(_db);


            var _signals = _sr.GetSignalFTPInfoForAllFTPSignals();



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

            Parallel.ForEach(_signals.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.IpAddress     = row.IP_Address.ToString();
                    signal.SignalID      = row.SignalID.ToString();



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


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


                    //Get the records over FTP
                    if (CheckIfIPAddressIsValid(signal))
                    {
                        try
                        {
                            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);
                }
            }

                             );
        }