Exemple #1
0
        static void Main(string[] args)
        {
            //get current runtime
            DateTime currentRunTime = DateTime.Now;

            // get the session directory servers we will talk to
            NameValueCollection appSettings = ConfigurationManager.AppSettings;

            //this is the string defined in app.config
            //the string can have multiple entries, seperate each entry by a semi-colon (;)
            //each entry must be in the form of: "servername/clustername"
            string connectionBrokers = appSettings.Get("connectionBrokers");

            //what is our error log
            string errLog = appSettings.Get("errorLog");

            //split the connectionBrokers app.config string by semi-colons
            string[] sessionDirs = connectionBrokers.Split(';');

            // get our DB object
            DBConnect db = new DBConnect();

            //update the database with the current runtime date
            //we MUST do this first so that all the updates and statistics calls will have latest data and satisfy FK constraints in the DB
            //insertCurrentRuntime marks the "complete" column to false. this is so we can insert a new runtime, but the web application will
            //not see the new runtime until we mark the complete column to true, which is done after the new stats are gathered/generated etc..
            db.InsertCurrentRuntime(currentRunTime);

            //connect to the session directories, and collect/insert the session info into the DB
            CBConnect cb = new CBConnect();
            cb.LastUpdate = currentRunTime;

            foreach (string entry in sessionDirs)
            {
                string[] currentSD = entry.Split('/');
                if (currentSD.Length == 2)
                {
                    //set the properties for the current Session Directory/Broker to process
                    cb.ServerName = currentSD[0];
                    cb.ClusterName = currentSD[1];

                    Console.WriteLine("\nGathering session info for Cluster: {0} on Connection Broker: {1}", cb.ClusterName, cb.ServerName);

                    //Get the stats and write them to our DB
                    cb.GetStats();
                }
                else
                {
                    string sdErr = "Error Parsing session directory string: " + entry + ", please verify that it is correct!\n";
                    Console.WriteLine("!!ERROR!!");
                    Console.WriteLine("  {0}\n", sdErr);

                    Exception sessionDirException = new Exception(sdErr);
                    CatchError(sessionDirException);
                }
            }

            //try and updat the stats
            //note that each method checks to make sure there were no errors before updating the stats.

            Console.WriteLine("\n\nNow Generating Latest Stats for newly collected info...");

            //update the server Stats
            db.UpdateServerStats();

            //update the domain stats
            db.UpdateDomainStats();

            //update the cluster/per farm stats
            db.UpdateClusterStats();

            //update the curSessions Table
            db.UpdateCurSessions(currentRunTime);

            //get current time
            DateTime endTime = DateTime.Now;
            TimeSpan runtime = endTime.Subtract(currentRunTime);

            //mark this last runtime as complete
            //this needs to be done before we clean out the old stuff from curSessions table
            //so the website/views have data to grab (current runtime is marked as complete
            db.CompleteUpdate(currentRunTime, runtime.Seconds);

            //clean out any old crap from the curSessions table
            db.CleanCurSessions(currentRunTime);

            Console.WriteLine("Done\n");

            //check for errors
            if (Rdscbmon.err)
            {
                //there were errors - so record them
                Console.WriteLine("\n{0} error(s) were encountered: ", exceptions.Count.ToString());
                Console.WriteLine("Please check the log file {0} for more information", errLog);

                //open our error log
                System.IO.StreamWriter errFile = new System.IO.StreamWriter(errLog);

                //write all the exceptions to the error log
                foreach (Exception e in exceptions)
                {
                    errFile.WriteLine("{0}\n\n\n", e);
                }

                //close the error log
                errFile.Close();
            }

            //exit the program with our exit code
            Environment.Exit(code);
        }