Ejemplo n.º 1
0
        public static bool CheckIfIPAddressIsValid(MOE.Common.Business.Signal signal)
        {
            bool hasValidIP = false;

            IPAddress ip;



            if (signal.IpAddress == "0")
            {
                return(false);
            }

            if (signal.IpAddress == "0.0.0.0")
            {
                return(false);
            }

            //test to see if the address is reachable
            if (IPAddress.TryParse(signal.IpAddress, out ip))
            {
                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   = pingSender.Send(signal.IpAddress, timeout, buffer, pingOptions);
                if (reply.Status != IPStatus.Success)
                {
                    hasValidIP = false;
                }
                else
                {
                    hasValidIP = true;
                }
            }

            return(hasValidIP);
        }
Ejemplo n.º 2
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
            //    {

            //    }
            //}
        }
Ejemplo n.º 3
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);
                }
            }

                             );
        }