コード例 #1
0
ファイル: Program.cs プロジェクト: AlexaProjects/Alexa
        private static long globalTimeout = 900000; //default global timeout is 15 minutes

        //in this class I don't use try catch statement, so if the user doesn't add the argument the application will be crash
        //and you can see the error from the event viewer of windows, this because I don't know yet the path of log file and I
        //cannot write any error message.
        static void Main(string[] args)
        {
            //init configuration utilities class
            ConfigUtils.Init(args[0]);

            //init CryptoUtils
            CryptoUtils.Init();

            //if the username (and other attributes) for the share is set...
            if (ConfigUtils.LogFolderUserName != "" && ConfigUtils.LogFolderPassword != "" && ConfigUtils.LogFolder.IndexOf(@"\\") != -1)
            {
                //...call the share connect function
                SystemUtils.NetworkShare.Connect(ConfigUtils.LogFolder, ConfigUtils.LogFolderUserName, ConfigUtils.LogFolderPassword);
            }

            //init log utilities class
            LogUtils.Init();

            //check if another instance of Al'exa is running
            if (SystemUtils.ProcessUtils.CheckAlexaInstances() == true)
            {
                Console.WriteLine("UNKNOWN: another instance of Al'exa is running");
                LogUtils.Write(new StackFrame(0, true), LogUtils.ErrorLevel.Error, "Another instance of Al'exa is running");
                Environment.Exit(3);
            }

            //Hide current window calling windows API.
            //NB: To do this we can also set "Windows Application" on the output type property of Visual Studio.
            //But in that way we cannot print any message on the standard output
            IntPtr windowHandle = Process.GetCurrentProcess().MainWindowHandle;

            SystemUtils.User32.HideWindow(windowHandle);

            //get user name and user domain of the account used to run Al'exa
            userName   = Environment.UserName;
            userDomain = Environment.UserDomainName;

            //call the wormup
            WarmUp();


            //get the regular expression containing the name of processes to kill
            _processToKillRegEx = ConfigUtils.ProcessesToKill;

            //get all processes (of the above user) that are running now
            if (_processToKillRegEx != "")
            {
                processesBeforeAlexa = SystemUtils.ProcessUtils.GetUserProcesses(userDomain, userName);
            }

            try
            {
                //get the global timeout attribute, it isn't mandatory.
                globalTimeout = long.Parse(ConfigUtils.Global.SelectSingleNode("performance").Attributes["timeout.value"].Value);
            }
            catch { }

            //new thread to check global timeout
            Thread _timeoutThread = new Thread(new ThreadStart(CheckTimeout));

            _timeoutThread.IsBackground = true;

            //save the start time, this will be saved in the xml output file
            //into the global node
            OutputUtils.Global.startTime = DateTime.Now;
            //start the stopwatch that measure the elapsed time of all Al'exa steps and computer vision time
            _globalTime.Start();

            //start the thread
            _timeoutThread.Start();

            //init Core utilities class
            CoreUtils.Init();

            //execute all the steps
            CoreUtils.RunSteps(ConfigUtils.AlexaSteps);

            //stop the stopwatch
            _globalTime.Stop();

            //save the output file
            Finish(false);
        }