Ejemplo n.º 1
0
        public Automator(string ConfigFileName, Translation GlobalTranslation)
        {
            tsl = GlobalTranslation;
            // Read the Config File
            CurrentConfig = ReadConfigFile(CurrentConfig,ConfigFileName);
            PrintMessagesToConsole(CurrentConfig,tsl);

               // Get login / password from console
               GetCredentials(ref CurrentConfig.OutputUserLogin, ref CurrentConfig.OutputUserPassword, "[LOGININPUT]", "[PASSWORDINPUT]");

            // Create MezzoObject
            myMezzoObject = new MezzoObject(CurrentConfig.OutputUserLogin, CurrentConfig.OutputUserPassword, CurrentConfig.OutputServerUrl);
            // Change workspace
            myMezzoObject.ChangeWorkspace(CurrentConfig.OutputWorkspaceId);
            Utils.MaMessage(String.Format(tsl.T("[CONNECTED]"), DateTime.Now.ToString(TimeFormat), myMezzoObject.UserCurrentFullName), Utils.maMessageLineType.WriteLine, Utils.maMessageOutput.ConsoleAndLog, CurrentConfig.LogFile);
            Utils.MaMessage("");
        }
Ejemplo n.º 2
0
        private void PrintMessagesToConsole(Config CurrentConfig, Translation tsl)
        {
            // Welcome message
            Utils.MaMessage("", Utils.maMessageLineType.WriteLine, Utils.maMessageOutput.Log, CurrentConfig.LogFile);
            Utils.MaMessage("============================================================", Utils.maMessageLineType.WriteLine, Utils.maMessageOutput.Log, CurrentConfig.LogFile);
            Utils.MaMessage(String.Format(tsl.T("[COPYRIGHT]"),VersionNumber),Utils.maMessageLineType.WriteLine,Utils.maMessageOutput.ConsoleAndLog,CurrentConfig.LogFile);
            Utils.MaMessage(String.Format(tsl.T("[STARTED]"), DateTime.Now.ToString()), Utils.maMessageLineType.WriteLine, Utils.maMessageOutput.ConsoleAndLog, CurrentConfig.LogFile);
            // Run mode message
            if (CurrentConfig.AutomationDelay == 0)
                Utils.MaMessage(tsl.T("[RUNONCE]"));
            else
                Utils.MaMessage(String.Format(tsl.T("[TRIGGER]"), CurrentConfig.AutomationDelay.ToString()));

            Utils.MaMessage(tsl.T("[CTRLC]"), Utils.maMessageLineType.WriteLine);
            Utils.MaMessage("");

               // Get login / password from console
            Utils.MaMessage(String.Format(tsl.T("[CONNECTING]"), DateTime.Now.ToString(TimeFormat), CurrentConfig.OutputServerUrl), Utils.maMessageLineType.WriteLine, Utils.maMessageOutput.ConsoleAndLog, CurrentConfig.LogFile);
        }
Ejemplo n.º 3
0
        static void Main(string[] args)
        {
            Timer mainTimer = null;

            try
            {
                // If there is an argument passed
                if (args.Length > 0)
                {
                    // Initialize Translations
                    // If more than one arg, the second is translation file
                    if (args.Length == 2)
                    {
                        trans = new Translation(args[1]);
                    }
                    else
                    {
                        // else we search in app directory
                        trans = new Translation(System.Environment.CurrentDirectory + "/" + "translation.xml");
                    }

                    if (trans.Count > 0)
                    {

                        // Creates an new Automator Class instance
                        currentAutomator = new Automator(args[0],trans);
                        // If AutomationDelay == 0 (RunOnce)
                        if (currentAutomator.CurrentConfig.AutomationDelay == 0)
                        {
                            currentAutomator.AutomateIt(null);
                        }
                        // Timed execution
                        else
                        {
                            // Create the delegate that invokes methods for the timer.
                            TimerCallback timerDelegate = new TimerCallback(currentAutomator.AutomateIt);
                            // Create a timer
                            mainTimer = new Timer(timerDelegate, autoRstEvent, 0, Timeout.Infinite);
                            // Loop for timer events
                            do
                            {
                                //autoRstEvent.WaitOne();
                                if (autoRstEvent.WaitOne())
                                {
                                    mainTimer.Change(currentAutomator.CurrentConfig.AutomationDelay * 1000, Timeout.Infinite);
                                }
                            } while (true);
                        }
                    }
                    else
                    {
                        Utils.MaMessage("Error : No translation file found or translation file not valid");
                        Utils.MaMessage("A file named translation.xml must be found in the application directory");
                        Utils.MaMessage("or must be specified as the second argument on the command line");
                    }
                }
                else
                {
                    if (trans != null)
                    {
                        Utils.MaMessage(trans.T("[CONFIGFILEERROR]"));
                        Utils.MaMessage(trans.T("[CONFIGFILEERROREXAMPLE]"));
                    }
                    else
                    {
                        Utils.MaMessage("Error : you must specify a config file name as first argument on the command line");
                        Utils.MaMessage("Example : ma /home/user/config.xml");
                    }
                }
            }
            catch (Exception e)
            {
                if (trans != null)
                {
                    Utils.MaMessage(String.Format(trans.T("[MAMAINERROR]"), e.Message), Utils.maMessageLineType.WriteLine, Utils.maMessageOutput.ConsoleAndLog, currentAutomator.CurrentConfig.LogFile);
                }
                else
                {
                    Utils.MaMessage(String.Format("MezzoAutomator.Main : an error has occurred : {0}", e.Message), Utils.maMessageLineType.WriteLine, Utils.maMessageOutput.ConsoleAndLog, currentAutomator.CurrentConfig.LogFile);
                }
            }
        }