Пример #1
0
        /****
        * Contents in the unzipped directory
        * script: script file to be handled by ScriptHandler
        * powershell: powershell file to be handled by ScriptHandler
        * eucalyptus: eucalyptus file to be handled by EucalyptusParameterHandler
        * include: include file to be handled by IncludeHandler
        * and any other resource files to be used by script/powershell handlers (exe, dll, etc)
        ****/
        override protected void Handle()
        {
            if (!Directory.Exists(UnzippedDir))
            {
                EucaLogger.Error(String.Format("Can't find the unzipped directory {0}", UnzippedDir));
                return;
            }
            else if (File.Exists(UserDataFile))
            {
                try
                {
                    EucaFileUtil.Unzip(UnzippedDir, UserDataFile);
                }
                catch (Exception ex)
                {
                    EucaLogger.Exception(String.Format("Failed to unzip {0} into {1}", UserDataFile, UnzippedDir), ex);
                    return;
                }
            }

            foreach (String filePath in Directory.GetFiles(UnzippedDir))
            {
                String          fileName = Path.GetFileName(filePath).ToLower();
                UserDataHandler handler  = null;
                if (fileName.Equals("script") || fileName.Equals("powershell"))
                {
                    handler = new ScriptHandler();
                }
                else if (fileName.Equals("eucalyptus"))
                {
                    handler = new EucalyptusParameterHandler();
                }
                else if (fileName.Equals("include"))
                {
                    handler = new IncludeHandler();
                }
                else
                {
                    EucaLogger.Debug(String.Format("unknown file: {0}", fileName));
                    continue;
                }

                try
                {
                    handler.HandleUserData(filePath);
                    EucaLogger.Debug(String.Format("Successfully handled the contents in {0}", fileName));
                }
                catch (Exception ex)
                {
                    EucaLogger.Exception(String.Format("failed to handle the file {0}", fileName), ex);
                }
            }
        }
Пример #2
0
        override protected void Handle()
        {
            EucaLogger.Debug("Script/Powershell Handler invoked");

            List <String> scripts = MakeScriptFragments();

            foreach (String file in scripts)
            {
                if (file.EndsWith(".cmd"))
                {
                    ExecuteCommandLine(file);
                }
                else if (file.EndsWith(".ps1"))
                {
                    ExecutePowershell(file);
                }
                else
                {
                    EucaLogger.Error("Unknown file format found");
                }
            }
        }