コード例 #1
0
        public static String LoginServer(String UserName, String Password)
        {
            String res = String.Empty;

            AS400   server = new AS400();
            Boolean isc    = false;

            server.setSystemName(ConfigurationManager.AppSettings["as400Server"]);
            server.setUserId(UserName);   //user del login
            server.setPassword(Password); //pwd del login

            try
            {
                try { server.connectService(0); } //se si connette allora l'utente di login esiste ed entro
                catch { isc = false; }

                isc = server.isConnected();

                if (isc)
                {
                    HttpContext.Current.Session.Add("user_" + ConfigurationManager.AppSettings["as400Server"], UserName);

                    //creo la connessione all'as400 da usare dopo per il monitoring
                    Boolean conf     = LoadConfiguration();
                    Boolean Multipar = Convert.ToBoolean(ConfigurationManager.AppSettings["MultiPartition"]);
                    if (Multipar)
                    {
                        String url = "/partitions/" + ConfigurationManager.AppSettings["as400Server"];
                        if (!conf)
                        {
                            url += "/configuration.aspx";
                        }
                        else
                        {
                            url += "/default.aspx";
                        }
                        return(new JavaScriptSerializer().Serialize(url));
                    }
                    else
                    {
                        if (!conf)
                        {
                            return(new JavaScriptSerializer().Serialize("/configuration.aspx"));
                        }
                        else
                        {
                            return(new JavaScriptSerializer().Serialize("/default.aspx"));
                        }
                    }
                }
                else
                {
                    return(new JavaScriptSerializer().Serialize("Errore: user inesistente o password sbagliata!"));
                }
            }
            catch (Exception ex)
            {
                return(new JavaScriptSerializer().Serialize("Errore: " + ex.Message));
            }
        }
コード例 #2
0
        public int mainTask(CancellationToken ct_main)
        {
            try
            {
                ls_AS400Server = read_AS400_Server();// carico la lista
            }
            catch (Exception ex)
            {
                ev.WriteEventToMyLog(Source, "errore: " + ex.Message, EventLogEntryType.Error, 88);
            }
            ev.WriteEventToMyLog(Source, "Numero server OS400: " + ls_AS400Server.Count.ToString(), EventLogEntryType.Information, 8);

            foreach (AS400Server s in ls_AS400Server)
            {
                AS400 server = Connessione_AS400(s);
                if (server != null)
                {
                    Persistence p = new Persistence {
                        ServerName = s.ServerName, jobs = new List <JobDetails> {
                        }
                    };                                                                                        // persistenza dei job in errore
                    Task t = Task <int> .Factory.StartNew(() => Start_OS400(ct_main, p, server, s), ct_main); // lancio il controllo Os400 come task
                }
            }

            Generazione_Task_PING();


            return(0);
        }
コード例 #3
0
        public static String LaunchCommand(String SERVER, String USER, String PWD, String FILE)
        {
            String res     = String.Empty;
            String COMMAND = "CALL PGM(PMBRS/PBRS30CL) PARM('@FILE@')";
            AS400  as400   = null;

            try
            {
                COMMAND = COMMAND.Replace("@FILE@", FILE.PadRight(18));

                // Create an AS400 object
                as400 = new AS400(SERVER, USER, PWD);

                // Create a Command object
                CommandCall command = new CommandCall(as400);

                // Run the command.

                Boolean success = command.run(COMMAND);

                if (success)
                {
                    res = "Commando Eseguito Correttamente.";
                }
                else
                {
                    res = "Command Failed!";
                }
                AS400Message[] messageList = command.getMessageList();
                foreach (AS400Message message in messageList)
                {
                    res += message.getText() + "\n";
                }

                return(res);
            }
            catch (Exception ex)
            {
                return(ex.Message);
            }
            finally
            {
                try
                {
                    // Make sure to disconnect
                    as400.disconnectAllServices();
                }
                catch { }
            }
        }
コード例 #4
0
 private AS400 Connessione_AS400(AS400Server s)
 {
     try
     {
         AS400 server = new AS400();
         server.setSystemName(s.ServerName);
         server.setUserId(s.userid);     //utente con diritti *ALLOBJ
         server.setPassword(s.password);
         return(server);
     }
     catch (Exception ex)
     {
         return(null);
     }
 }
コード例 #5
0
        private int Start_OS400(CancellationToken ct_main, Persistence p, AS400 srv, AS400Server s)
        {
            while (true)                                            // loop infinito
            {
                Task t = Generazione_Task_JOBS(s, ls_jobs, p, srv); // questo ha un timeout
                t.Wait();

                Thread.Sleep(30 * 1000);

                if (ct_main.IsCancellationRequested)
                {
                    break;
                }                                              // se lancio una richiesta di cancellazione manuale esco dal while
            }
            return(0);
        }
コード例 #6
0
        private Boolean Ping_OS400(CancellationToken ct, AS400Server srv)
        {
            PingCls ping = new PingCls();

            while (true)
            {
                #region LOGICA DEL PING

                if (ping.isAvailable(srv.ServerName))
                {
                    ev.WriteEventToMyLog(Source + " - PING", "ping a " + srv.ServerName + " OK!", EventLogEntryType.Warning, 888);
                    Boolean isStop = srv.cTokenSource.IsCancellationRequested;

                    if (isStop)
                    {
                        srv.cTokenSource.Cancel();// per sicurezza lo spengo e ne genero un altro altrimenti ne crea di multipli

                        var ct_main = ctsource_main.Token;
                        ct_main.Register(() => cancelNotification_Main());// gestione cancellazione notifica
                        AS400       server = Connessione_AS400(srv);
                        Persistence p      = new Persistence {
                            ServerName = srv.ServerName, jobs = new List <JobDetails> {
                            }
                        };                                                                                          // persistenza dei job in errore
                        Task t = Task <int> .Factory.StartNew(() => Start_OS400(ct_main, p, server, srv), ct_main); // lancio il controllo Os400 come task
                    }
                }
                else
                {
                    ev.WriteEventToMyLog(Source + " - PING", "Ping per " + srv.ServerName + " Fallito!", EventLogEntryType.Error, 999);
                    srv.cTokenSource.Cancel();// spengo il monitor del server
                }
                #endregion

                Thread.Sleep(20 * 1000);// aspetto 10 secondi e pingo ancora

                if (ct.IsCancellationRequested)
                {
                    break;
                }                                         // se lancio una richiesta di cancellazione manuale esco dal while
            }

            return(true);
        }
コード例 #7
0
        public static Boolean check_IFS(String rootDir)
        {
            String machine  = ConfigurationManager.AppSettings["as400Server"];
            String user     = ConfigurationManager.AppSettings["as400User"];
            String password = ConfigurationManager.AppSettings["as400Pwd"];

            AS400 server = new AS400();

            server.setSystemName(machine);
            server.setUserId(user);
            server.setPassword(password);
            IFSFile dir = new IFSFile(server, rootDir);

            if (dir.exists())
            {
                return(true);
            }



            return(false);
        }
コード例 #8
0
/*
 *      protected void Login1_Authenticate(object sender, AuthenticateEventArgs e)
 *      {
 *          AS400 server = new AS400();
 *          Boolean isc = false;
 *
 *          server.setSystemName(ConfigurationManager.AppSettings["as400Server"]);
 *          server.setUserId(Login1.UserName); //user del login
 *          server.setPassword(Login1.Password); //pwd del login
 *
 *          try { server.connectService(0); } //se si connette allora l'utente di login esiste ed entro
 *          catch { isc = false; }
 *
 *          isc = server.isConnected();
 *          //isc = true;
 *          if (isc)
 *          {
 *              e.Authenticated = true;
 *              //creo la connessione all'as400 da usare dopo per il monitoring
 *              Boolean res=LoadConfiguration();
 *              Boolean Multipar=Convert.ToBoolean(ConfigurationManager.AppSettings["MultiPartition"]);
 *              if (Multipar)
 *              {
 *                  if (!res)
 *                      Response.Redirect("/partitions/" + ConfigurationManager.AppSettings["as400Server"] + "/configuration.aspx", true);
 *                  Session.Add("user_" + ConfigurationManager.AppSettings["as400Server"], Login1.UserName);
 *                  Response.Redirect("/partitions/" + ConfigurationManager.AppSettings["as400Server"] + "/default.aspx", true);
 *              }
 *              else
 *              {
 *                  if (!res)
 *                      Response.Redirect( "/configuration.aspx", true);
 *                  Session.Add("user_" + ConfigurationManager.AppSettings["as400Server"], Login1.UserName);
 *                  Response.Redirect(  "/default.aspx", true);
 *
 *              }
 *
 *          }
 *          else
 *              e.Authenticated = false;
 *      }
 */
        public static Boolean LoadConfiguration()
        {
            AS400 system = new AS400();

            //se l'utente si è connesso allora creo una sessione di connessione as400 con un utente *ALLOBJ, server per poter reperire il monitor del server
            system.setSystemName(ConfigurationManager.AppSettings["as400Server"]);
            system.setUserId(ConfigurationManager.AppSettings["as400User"]); //utente con diritti *ALLOBJ
            system.setPassword(ConfigurationManager.AppSettings["as400Pwd"]);

            HttpContext.Current.Session.Add("iseries_" + ConfigurationManager.AppSettings["as400Server"], system);

            //Creo la connessione all'as400 via JDBC da usare per le fasi di lettura e scrittura dei dati
            AS400JDBCRowSet rowset = FunzioniComuni.connectJdbcAS400(ConfigurationManager.AppSettings["as400Server"],
                                                                     ConfigurationManager.AppSettings["as400User"], ConfigurationManager.AppSettings["as400Pwd"]);

            if (rowset != null)
            {
                HttpContext.Current.Session.Add("iseriesJDBC_" + ConfigurationManager.AppSettings["as400Server"], rowset);

                //carico i dati per il server FTP
                string FTPAddress = "";

                FtpServer ftpServer = new FtpServer();
                rowset.setCommand("SELECT FTIIP,FTCSI,FTPOR,FTUSE,FTPSW,FTTYP,FTPAT,FTFTP,FTKEY FROM PMBRS.FTPCF00F");
                rowset.execute();


                while (rowset.next())
                {
                    string port = rowset.getString(3).Trim();
                    if (port != "" && port != "21")// 21 è default e non lo metto
                    {
                        FTPAddress = "ftp://" + rowset.getString(1).Trim() + ":" + rowset.getString(3).Trim();
                    }
                    else
                    {
                        FTPAddress = "ftp://" + rowset.getString(1).Trim();
                    }

                    ftpServer.ftpAddressURI = FTPAddress;
                    ftpServer.ftpAddress    = rowset.getString(1).Trim();
                    ftpServer.user          = rowset.getString(4).Trim();
                    ftpServer.pwd           = rowset.getString(5).Trim();
                    ftpServer.ccsid         = rowset.getString(2).Trim();
                    ftpServer.ftpType       = rowset.getString(6).Trim();
                    ftpServer.ftpPath       = rowset.getString(7).Trim();
                    ftpServer.port          = port;// porta
                    ftpServer.ftpSecure     = rowset.getString("FTFTP").Trim();
                    ftpServer.ftpSecureKey  = rowset.getString("FTKEY").Trim();

                    HttpContext.Current.Session.Add("ftpServer_" + ConfigurationManager.AppSettings["as400Server"], ftpServer);
                    return(true);// ho trovato la configurazione
                }

                return(false);// la configurazione è vuota se esce qui
            }
            else
            {
                return(false);
            }
        }
コード例 #9
0
        public Task Generazione_Task_JOBS(AS400Server srv, List <JOB> ls_jobs, Persistence p, AS400 s)
        {
            ev.WriteEventToMyLog(Source + " - Taks Jobs", "Avvio Task Jobs per " + srv.ServerName, EventLogEntryType.Information, 4);

            try
            {
                ls_jobs = Read_Job_Monitored();// carico dalla tabella i job da monitorare tutti i giri
            }
            catch (Exception ex)
            {
                ev.WriteEventToMyLog(Source + " - Taks Jobs", "Errore: " + ex.Message, EventLogEntryType.Error, 44);
            }

            // srv.cTokenSource.Cancel();// per sicurezza lo cancello nel caso non fosse già cancellato
            srv.cTokenSource = new CancellationTokenSource(TimeoutToken);
            var cToken = srv.cTokenSource.Token;              // quando non si vuole specificare il tipo per comodità si mette var

            cToken.Register(() => cancelNotification_JOBS()); // gestione cancellazione notifica


            // creo il task del controllo jobs e gli passo i par di connessione più il token di eventuale cancellazione
            Task taskJobs = Task <int> .Factory.StartNew(() => os400.JOBLIST(cToken, srv.ServerName, srv.userid, srv.password, ls_jobs, p, s), cToken);

            return(taskJobs);
        }