private bool ExecuteTemplateOverride(TemplateOperations operation, ZeusTemplate template, ZeusSavedInput input, ShowGUIEventHandler guiEventHandler)
 {
     switch (operation)
     {
         case TemplateOperations.Execute:
             this._mdi.PerformMdiFuntion(this, "ExecutionQueueStart");
             ZeusProcessManager.ExecuteTemplate(template.FullFileName, _executionCallback);
             break;
         case TemplateOperations.ExecuteLoadedInput:
             this._mdi.PerformMdiFuntion(this, "ExecutionQueueStart");
             ZeusProcessManager.ExecuteSavedInput(input.FilePath, _executionCallback);
             break;
         case TemplateOperations.SaveInput:
             SaveFileDialog saveFileDialog = new SaveFileDialog();
             saveFileDialog.Filter = "Zues Input Files (*.zinp)|*.zinp";
             saveFileDialog.FilterIndex = 0;
             saveFileDialog.RestoreDirectory = true;
             if (saveFileDialog.ShowDialog() == DialogResult.OK)
             {
                 this._mdi.PerformMdiFuntion(this, "ExecutionQueueStart");
                 ZeusProcessManager.RecordTemplateInput(template.FullFileName, saveFileDialog.FileName, _executionCallback);
             }
             break;
     }
     return true;
 }
        public IZeusSavedInput ExecuteTemplateAndCollectInput(IZeusContext context, string templatePath)
        {
            var template       = new ZeusTemplate(templatePath);
            var collectedInput = new ZeusSavedInput();

            DefaultSettings.Instance.PopulateZeusContext(context);
            template.ExecuteAndCollect(context, DefaultSettings.Instance.ScriptTimeout, collectedInput.InputData.InputItems);
            collectedInput.Save();

            return(collectedInput);
        }
Exemple #3
0
        public IZeusSavedInput CollectTemplateInput(IZeusContext context, string templatePath)
        {
            ZeusTemplate    template       = new ZeusTemplate(templatePath);
            ZeusSavedInput  collectedInput = new ZeusSavedInput();
            DefaultSettings settings       = DefaultSettings.Instance;

            settings.PopulateZeusContext(context);
            template.Collect(context, settings.ScriptTimeout, collectedInput.InputData.InputItems);
            collectedInput.Save();

            return(collectedInput);
        }
        public IZeusSavedInput ExecuteTemplateAndCollectInput(IZeusContext context, string templatePath)
        {
            ZeusTemplate template = new ZeusTemplate(templatePath);
            ZeusSavedInput collectedInput = new ZeusSavedInput();
            DefaultSettings settings = DefaultSettings.Instance;

            settings.PopulateZeusContext(context);
            template.ExecuteAndCollect(context, settings.ScriptTimeout, collectedInput.InputData.InputItems);
            collectedInput.Save();

            return collectedInput;
        }
        public void ExecuteTemplate(IZeusContext context, string templatePath, string inputFilePath)
        {
            var            template   = new ZeusTemplate(templatePath);
            ZeusSavedInput savedInput = null;

            if (!string.IsNullOrEmpty(inputFilePath))
            {
                savedInput = new ZeusSavedInput(inputFilePath);
            }

            context.Log.Write("Executing: " + template.Title);
            if (savedInput != null)
            {
                context.Input.AddItems(savedInput.InputData.InputItems);
                template.Execute(context, DefaultSettings.Instance.ScriptTimeout, true);
            }
            else
            {
                DefaultSettings.Instance.PopulateZeusContext(context);
                template.Execute(context, DefaultSettings.Instance.ScriptTimeout, false);
            }
        }
 private bool templateBrowserControl1_ExecuteOverride(TemplateOperations operation, ZeusTemplate template, ZeusSavedInput input, ShowGUIEventHandler guiEventHandler)
 {
     switch (operation)
     {
         case TemplateOperations.Execute:
             ZeusProcessManager.ExecuteTemplate(template.FullFileName, processCallback);
             break;
         case TemplateOperations.ExecuteLoadedInput:
             ZeusProcessManager.ExecuteSavedInput(input.FilePath, processCallback);
             break;
         case TemplateOperations.SaveInput:
             SaveFileDialog saveFileDialog = new SaveFileDialog();
             saveFileDialog.Filter = "Zues Input Files (*.zinp)|*.zinp";
             saveFileDialog.FilterIndex = 0;
             saveFileDialog.RestoreDirectory = true;
             if (saveFileDialog.ShowDialog() == DialogResult.OK)
             {
                 ZeusProcessManager.RecordTemplateInput(template.FullFileName, saveFileDialog.FileName, processCallback);
             }
             break;
     }
     return true;
 }
		private void Parse(string[] args) 
		{
			int numargs = args.Length;
			string arg;

			if (numargs == 0) 
			{
				this._showHelp = true;
				return;
			}

			for (int i = 0; i < numargs; i++) 
			{
				arg = args[i];

				switch (arg)
                {
                    case "-internaluse":
                        this._internalUse = true;
                        break;
                    case "-installvs2005":
                        this._installVS2005 = true;
                        break;
                    case "-tc":
                    case "-testconnection":
                        this._mode = ProcessMode.MyMeta;
                        if (numargs > (i + 2))
                        {
                            this._connType = args[++i];
                            this._connString = args[++i];
                        }
                        else
                        {
                            this._valid = false;
                            this._errorMessage = "Invalid switch usage: " + arg;
                        }
                        break;
					case "-aio":
					case "-addintrinsicobject":
						if (numargs > (i+3)) 
						{
							string assembly = args[++i];
							string classpath = args[++i];
							string varname = args[++i];

							ZeusIntrinsicObject iobj = new ZeusIntrinsicObject(assembly, classpath, varname);
							this._intrinsicObjects.Add(iobj);
						}
						else 
						{
							this._valid = false;
							this._errorMessage = "Invalid switch usage: " + arg;
						}
						break;
					case "-rio":
					case "-removeintrinsicobject":
                        if (numargs > (i + 1))
                        {
                            string varname = args[++i];
                            foreach (ZeusIntrinsicObject zio in ZeusConfig.Current.IntrinsicObjects)
                            {
                                if (zio.VariableName == varname && !_intrinsicObjectsToRemove.Contains(zio))
                                {
                                    this._intrinsicObjectsToRemove.Add(zio);
                                    break;
                                }
                            }
                        }
                        else
                        {
                            this._valid = false;
                            this._errorMessage = "Invalid switch usage: " + arg;
                        }
                        break;
					case "-r":
					case "-relative":
						this._makeRelative = true;
						break;
					case "-s":
					case "-silent":
						this._silent = true;
						break;
					case "-?":
					case "-h":
					case "-help":
						this._showHelp = true;
						break;
					case "-l":
					case "-logfile":
						this._enableLog = true;
						if (numargs > (i+1)) 
							this._pathLog = args[++i];
						else 
						{
							this._valid = false;
							this._errorMessage = "Invalid switch usage: " + arg;
						}
						break;
					case "-o":
					case "-outfile":
						if (numargs > (i+1)) 
							this._pathOutput = args[++i];
						else 
						{
							this._valid = false;
							this._errorMessage = "Invalid switch usage: " + arg;
						}
						break;
					case "-p":
					case "-project":
						this._mode = ProcessMode.Project;
						if (numargs > (i+1)) 
							this._pathProject = args[++i];
						else 
						{
							this._valid = false;
							this._errorMessage = "Invalid switch usage: " + arg;
						}
						break;
					case "-mumd":
                    case "-mergeusermetadata":
                        this._mode = ProcessMode.MyMeta;
                        this._metaDataMerge = true;
                        if (numargs > (i + 5))
                        {
                            this._metaDataFile1 = args[++i];
                            this._metaDatabase1 = args[++i];
                            this._metaDataFile2 = args[++i];
                            this._metaDatabase2 = args[++i];
                            this._metaDataFileMerged = args[++i];
                        }
                        else
                        {
                            this._valid = false;
                            this._errorMessage = "Invalid switch usage: " + arg;
                        }
                        break;
                    case "-m":
                    case "-pf":
                    case "-module":
                    case "-projectfolder":
						if (numargs > (i+1)) 
						{
							string data = args[++i];
							if (!_moduleNames.Contains(data))
								this._moduleNames.Add(data);
						}
						else 
						{
							this._valid = false;
							this._errorMessage = "Invalid switch usage: " + arg;
						}
                        break;
                    case "-rti":
                    case "-recordtemplateinstance":
                        if (numargs > (i + 1))
                        {
                            this._projectItemToRecord = args[++i];
                            this._mode = ProcessMode.Project;
                        }
                        else
                        {
                            this._valid = false;
                            this._errorMessage = "Invalid switch usage: " + arg;
                        }
                        break;
                    case "-ti":
                    case "-templateinstance":
                        if (numargs > (i + 1))
                        {
                            string data = args[++i];
                            if (!_projectItems.Contains(data))
                                this._projectItems.Add(data);
                        }
                        else
                        {
                            this._valid = false;
                            this._errorMessage = "Invalid switch usage: " + arg;
                        }
                        break;
					case "-i":
					case "-inputfile":
						this._mode = ProcessMode.Template;
						if (numargs > (i+1)) 
							this._pathXmlData = args[++i];
						else  
						{
							this._valid = false;
							this._errorMessage = "Invalid switch usage: " + arg;
						}
						break;
					case "-t":
					case "-template":
						this._mode = ProcessMode.Template;
						if (numargs > (i+1)) 
							this._pathTemplate = args[++i];
						else 
						{
							this._valid = false;
							this._errorMessage = "Invalid switch usage: " + arg;
						}
						break;
					case "-c":
					case "-collect":
						this._mode = ProcessMode.Template;
						if (numargs > (i+1)) 
							this._pathCollectXmlData = args[++i];
						else 
						{
							this._valid = false;
							this._errorMessage = "Invalid switch usage: " + arg;
						}
						break;
					case "-e":
					case "-timeout":
						if (numargs > (i+1)) 
						{
							try 
							{
								this._timeout = Int32.Parse(args[++i]);
							}
							catch 
							{
								this._timeout = -1;
							}
						}
						else 
						{
							this._valid = false;
							this._errorMessage = "Invalid switch usage: " + arg;
						}
						break;
					default:
						_valid = false;
						this._errorMessage = "Invalid argument: " + arg;
						break;
				}
			}

			if (this._makeRelative) 
			{
				if (this._pathCollectXmlData != null)
					this._pathCollectXmlData = Zeus.FileTools.MakeAbsolute(this._pathCollectXmlData, FileTools.ApplicationPath);
				if (this._pathLog != null)
                    this._pathLog = Zeus.FileTools.MakeAbsolute(this._pathLog, FileTools.ApplicationPath);
				if (this._pathOutput != null)
                    this._pathOutput = Zeus.FileTools.MakeAbsolute(this._pathOutput, FileTools.ApplicationPath);
				if (this._pathProject != null)
                    this._pathProject = Zeus.FileTools.MakeAbsolute(this._pathProject, FileTools.ApplicationPath);
				if (this._pathTemplate != null)
                    this._pathTemplate = Zeus.FileTools.MakeAbsolute(this._pathTemplate, FileTools.ApplicationPath);
				if (this._pathXmlData != null)
                    this._pathXmlData = Zeus.FileTools.MakeAbsolute(this._pathXmlData, FileTools.ApplicationPath);
                if (this._metaDataFile1 != null)
                    this._metaDataFile1 = Zeus.FileTools.MakeAbsolute(this._metaDataFile1, FileTools.ApplicationPath);
                if (this._metaDataFile2 != null)
                    this._metaDataFile2 = Zeus.FileTools.MakeAbsolute(this._metaDataFile2, FileTools.ApplicationPath);
                if (this._metaDataFileMerged != null)
                    this._metaDataFileMerged = Zeus.FileTools.MakeAbsolute(this._metaDataFileMerged, FileTools.ApplicationPath);
			}


			// Validate required fields are filled out for the selected mode.
			if (_valid) 
			{
                if (this.Mode == ProcessMode.MyMeta) 
                {
                    if (this._metaDataMerge)
                    {
                        if (!System.IO.File.Exists(_metaDataFile1) || !System.IO.File.Exists(_metaDataFile2))
                        {
                            _valid = false;
                            this._errorMessage = "The two source files must exist for the merge to work!";
                        }
                    }
                }
				else if (this._mode == ProcessMode.Project) 
				{
					if (this._pathProject == null)
					{
						_valid = false;
						this._errorMessage = "Project Path Required";
					}
					else 
					{
						try 
						{
							this._project = new ZeusProject(this._pathProject);
							this._project.Load();
						}
						catch (Exception ex)
						{
							this._project = null;
							this._valid = false;
							this._errorMessage = ex.Message;
						}
					}


                    if (this._pathTemplate != null)
                    {
                        try
                        {
                            this._template = new ZeusTemplate(this._pathTemplate);
                        }
                        catch (Exception ex)
                        {
                            this._template = null;
                            this._valid = false;
                            this._errorMessage = ex.Message;
                        }
                    }
				}
				else if (this._mode == ProcessMode.Template) 
				{
					if ( (this._pathTemplate == null) && (this._pathXmlData == null) )
					{
						_valid = false;
						this._errorMessage = "Template path or XML input path required.";
					}
					else 
					{
						if (this._pathTemplate != null)
						{
							try 
							{
								this._template = new ZeusTemplate(this._pathTemplate);
							}
							catch (Exception ex)
							{
								this._template = null;
								this._valid = false;
								this._errorMessage = ex.Message;
							}
						}

						if ( (this._valid) && (this._pathXmlData != null) )
						{
							try 
							{
								this._savedInput = new ZeusSavedInput(this._pathXmlData);
								this._savedInput.Load();

								if (this._template == null) 
								{
									this._template = new ZeusTemplate(this._savedInput.InputData.TemplatePath);
								}
							}
							catch (Exception ex)
							{
								this._savedInput = null;
								this._template = null;
								this._valid = false;
								this._errorMessage = ex.Message;
							}
						}

						if ( (this._valid) && (this._pathCollectXmlData != null) )
						{
							try 
							{
								this._inputToSave = new ZeusSavedInput(this._pathCollectXmlData);
								this._inputToSave.InputData.TemplatePath = this._template.FilePath + this._template.FileName;
								this._inputToSave.InputData.TemplateUniqueID = this._template.UniqueID;
							}
							catch (Exception ex)
							{
								this._inputToSave = null;
								this._valid = false;
								this._errorMessage = ex.Message;
							}
						}
					}
				}

			}
		}
		public void ExecuteLoadedInput() 
		{
			try 
			{
                DefaultSettings settings = DefaultSettings.Instance;
				ZeusSimpleLog log = new ZeusSimpleLog();

				OpenFileDialog openFileDialog = new OpenFileDialog();
				openFileDialog.Filter = "Zues Input Files (*.zinp)|*.zinp";
				openFileDialog.FilterIndex = 0;
				openFileDialog.RestoreDirectory = true;
				openFileDialog.Multiselect = true;
				if(openFileDialog.ShowDialog() == DialogResult.OK)
				{
					Cursor.Current = Cursors.WaitCursor;

					foreach (string filename in openFileDialog.FileNames) 
					{
						ZeusSavedInput savedInput = new ZeusSavedInput(filename);
						if (savedInput.Load()) 
						{
							ZeusContext context = new ZeusContext();
							context.Input.AddItems(savedInput.InputData.InputItems);
							context.Log = log;

							ZeusTemplate template = new ZeusTemplate(savedInput.InputData.TemplatePath);
							template.Execute(context, settings.ScriptTimeout, true);

							if (log.HasExceptions) 
							{
								throw log.Exceptions[0];
							}
						}
					}

					Cursor.Current = Cursors.Default;
					MessageBox.Show(this, "Selected files have been executed.");
				}
			}
			catch (Exception ex)
			{
                mdi.ErrorsOccurred(ex);
                //ZeusDisplayError formError = new ZeusDisplayError(ex);
				//formError.SetControlsFromException();			
				//formError.ShowDialog(this);
			}

			Cursor.Current = Cursors.Default;
		}
		public void SaveInput(ZeusTemplate template) 
		{
			try 
			{
                DefaultSettings settings = DefaultSettings.Instance;

				ZeusSimpleLog log = new ZeusSimpleLog();
				ZeusContext context = new ZeusContext();
				context.Log = log;

				ZeusSavedInput collectedInput = new ZeusSavedInput();
				collectedInput.InputData.TemplateUniqueID = template.UniqueID;
				collectedInput.InputData.TemplatePath = template.FilePath + template.FileName;

				settings.PopulateZeusContext(context);
				template.Collect(context, settings.ScriptTimeout, collectedInput.InputData.InputItems);
					
				if (log.HasExceptions) 
				{
					throw log.Exceptions[0];
				}
				else 
				{
					SaveFileDialog saveFileDialog = new SaveFileDialog();
					saveFileDialog.Filter = "Zues Input Files (*.zinp)|*.zinp";
					saveFileDialog.FilterIndex = 0;
					saveFileDialog.RestoreDirectory = true;
					if(saveFileDialog.ShowDialog() == DialogResult.OK)
					{
						Cursor.Current = Cursors.WaitCursor;

						collectedInput.FilePath = saveFileDialog.FileName;
						collectedInput.Save();
					}
				}

				MessageBox.Show(this, "Input collected and saved to file: \r\n" + collectedInput.FilePath);
			}
			catch (Exception ex)
			{
                mdi.ErrorsOccurred(ex);
                //ZeusDisplayError formError = new ZeusDisplayError(ex);
				//formError.SetControlsFromException();			
				//formError.ShowDialog(this);
			}

			Cursor.Current = Cursors.Default;
		}
        private void _SaveTemplateInput()
        {
            try
            {
                Directory.SetCurrentDirectory(Application.StartupPath);
                this.RefreshTemplateFromControl();

                DefaultSettings settings = DefaultSettings.Instance;

                ZeusSimpleLog log = new ZeusSimpleLog();
                log.LogEntryAdded += new EventHandler(Log_EntryAdded);
                ZeusContext context = new ZeusContext();
                context.Log = log;

                ZeusSavedInput collectedInput = new ZeusSavedInput();
                collectedInput.InputData.TemplateUniqueID = _template.UniqueID;
                collectedInput.InputData.TemplatePath = _template.FilePath + _template.FileName;

                settings.PopulateZeusContext(context);

                _template.Collect(context, settings.ScriptTimeout, collectedInput.InputData.InputItems);

                if (log.HasExceptions)
                {
                    throw log.Exceptions[0];
                }
                else
                {
                    SaveFileDialog saveFileDialog = new SaveFileDialog();
                    saveFileDialog.Filter = "Zues Input Files (*.zinp)|*.zinp";
                    saveFileDialog.FilterIndex = 0;
                    saveFileDialog.RestoreDirectory = true;
                    if (saveFileDialog.ShowDialog() == DialogResult.OK)
                    {
                        Cursor.Current = Cursors.WaitCursor;

                        collectedInput.FilePath = saveFileDialog.FileName;
                        collectedInput.Save();
                    }
                }

                MessageBox.Show(this, "Input collected and saved to file:" + "\r\n" + collectedInput.FilePath);
            }
            catch (Exception ex)
            {
                HandleExecuteException(ex);
            }

            Cursor.Current = Cursors.Default;
        }
        public void ExecuteLoadedInput()
        {
            bool overridden = false;
            
            OpenFileDialog openFileDialog = new OpenFileDialog();
            openFileDialog.Filter = "Zues Input Files (*.zinp)|*.zinp";
            openFileDialog.FilterIndex = 0;
            openFileDialog.RestoreDirectory = true;
            openFileDialog.Multiselect = true;
            if (openFileDialog.ShowDialog() == DialogResult.OK)
            {
                ZeusSavedInput savedInput = null;
                ZeusTemplate template = null;
                if (ExecuteTemplateOverride != null)
                {
                    try
                    {
                        foreach (string filename in openFileDialog.FileNames)
                        {
                            savedInput = new ZeusSavedInput(filename);
                            if (savedInput.Load())
                            {
                                template = new ZeusTemplate(savedInput.InputData.TemplatePath);

                                overridden = ExecuteTemplateOverride(TemplateOperations.ExecuteLoadedInput, template, savedInput, _guiHandler);
                                if (!overridden) break;
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        OnErrorsOccurred(ex);
                    }
                }
                

                if (!overridden)
                {
                    try
                    {
                        ZeusSimpleLog log = new ZeusSimpleLog();
                        DefaultSettings settings = DefaultSettings.Instance;

                        Cursor.Current = Cursors.WaitCursor;

                        foreach (string filename in openFileDialog.FileNames)
                        {
                            savedInput = new ZeusSavedInput(filename);
                            if (savedInput.Load())
                            {
                                ZeusContext context = new ZeusContext();
                                context.Input.AddItems(savedInput.InputData.InputItems);
                                context.Log = log;

                                template = new ZeusTemplate(savedInput.InputData.TemplatePath);
                                template.Execute(context, settings.ScriptTimeout, true);

                                foreach (string filePath in context.Output.SavedFiles)
                                {
                                    this.OnGeneratedFileSaved(filePath);
                                }

                                if (log.HasExceptions)
                                {
                                    throw log.Exceptions[0];
                                }
                            }
                        }

                        Cursor.Current = Cursors.Default;
                        MessageBox.Show(this, "Selected files have been executed.");

                    }
                    catch (Exception ex)
                    {
                        OnErrorsOccurred(ex);
                    }

                    Cursor.Current = Cursors.Default;
                }
            }
        }
        public void SaveInput(ZeusTemplate template)
        {
            bool overridden = false;
            if (ExecuteTemplateOverride != null)
            {
                overridden = ExecuteTemplateOverride(TemplateOperations.SaveInput, template, null, _guiHandler);
            }

            if (!overridden)
            {
                try
                {
                    DefaultSettings settings = DefaultSettings.Instance;

                    ZeusSimpleLog log = new ZeusSimpleLog();
                    ZeusContext context = new ZeusContext();
                    context.Log = log;

                    ZeusSavedInput collectedInput = new ZeusSavedInput();
                    collectedInput.InputData.TemplateUniqueID = template.UniqueID;
                    collectedInput.InputData.TemplatePath = template.FilePath + template.FileName;

                    settings.PopulateZeusContext(context);
                    template.Collect(context, settings.ScriptTimeout, collectedInput.InputData.InputItems);

                    if (log.HasExceptions)
                    {
                        throw log.Exceptions[0];
                    }
                    else
                    {
                        SaveFileDialog saveFileDialog = new SaveFileDialog();
                        saveFileDialog.Filter = "Zues Input Files (*.zinp)|*.zinp";
                        saveFileDialog.FilterIndex = 0;
                        saveFileDialog.RestoreDirectory = true;
                        if (saveFileDialog.ShowDialog() == DialogResult.OK)
                        {
                            Cursor.Current = Cursors.WaitCursor;

                            collectedInput.FilePath = saveFileDialog.FileName;
                            collectedInput.Save();
                        }
                    }

                    MessageBox.Show(this, "Input collected and saved to file: \r\n" + collectedInput.FilePath);
                }
                catch (Exception ex)
                {
                    OnErrorsOccurred(ex);
                }

                Cursor.Current = Cursors.Default;
            }
        }
Exemple #13
0
        private void Parse(string[] args)
        {
            int    numargs = args.Length;
            string arg;

            if (numargs == 0)
            {
                this._showHelp = true;
                return;
            }

            for (int i = 0; i < numargs; i++)
            {
                arg = args[i];

                switch (arg)
                {
                case "-internaluse":
                    this._internalUse = true;
                    break;

                case "-installvs2005":
                    this._installVS2005 = true;
                    break;

                case "-tc":
                case "-testconnection":
                    this._mode = ProcessMode.MyMeta;
                    if (numargs > (i + 2))
                    {
                        this._connType   = args[++i];
                        this._connString = args[++i];
                    }
                    else
                    {
                        this._valid        = false;
                        this._errorMessage = "Invalid switch usage: " + arg;
                    }
                    break;

                case "-aio":
                case "-addintrinsicobject":
                    if (numargs > (i + 3))
                    {
                        string assembly  = args[++i];
                        string classpath = args[++i];
                        string varname   = args[++i];

                        ZeusIntrinsicObject iobj = new ZeusIntrinsicObject(assembly, classpath, varname);
                        this._intrinsicObjects.Add(iobj);
                    }
                    else
                    {
                        this._valid        = false;
                        this._errorMessage = "Invalid switch usage: " + arg;
                    }
                    break;

                case "-rio":
                case "-removeintrinsicobject":
                    if (numargs > (i + 1))
                    {
                        string varname = args[++i];
                        foreach (ZeusIntrinsicObject zio in ZeusConfig.Current.IntrinsicObjects)
                        {
                            if (zio.VariableName == varname && !_intrinsicObjectsToRemove.Contains(zio))
                            {
                                this._intrinsicObjectsToRemove.Add(zio);
                                break;
                            }
                        }
                    }
                    else
                    {
                        this._valid        = false;
                        this._errorMessage = "Invalid switch usage: " + arg;
                    }
                    break;

                case "-r":
                case "-relative":
                    this._makeRelative = true;
                    break;

                case "-s":
                case "-silent":
                    this._silent = true;
                    break;

                case "-?":
                case "-h":
                case "-help":
                    this._showHelp = true;
                    break;

                case "-l":
                case "-logfile":
                    this._enableLog = true;
                    if (numargs > (i + 1))
                    {
                        this._pathLog = args[++i];
                    }
                    else
                    {
                        this._valid        = false;
                        this._errorMessage = "Invalid switch usage: " + arg;
                    }
                    break;

                case "-o":
                case "-outfile":
                    if (numargs > (i + 1))
                    {
                        this._pathOutput = args[++i];
                    }
                    else
                    {
                        this._valid        = false;
                        this._errorMessage = "Invalid switch usage: " + arg;
                    }
                    break;

                case "-p":
                case "-project":
                    this._mode = ProcessMode.Project;
                    if (numargs > (i + 1))
                    {
                        this._pathProject = args[++i];
                    }
                    else
                    {
                        this._valid        = false;
                        this._errorMessage = "Invalid switch usage: " + arg;
                    }
                    break;

                case "-mumd":
                case "-mergeusermetadata":
                    this._mode          = ProcessMode.MyMeta;
                    this._metaDataMerge = true;
                    if (numargs > (i + 5))
                    {
                        this._metaDataFile1      = args[++i];
                        this._metaDatabase1      = args[++i];
                        this._metaDataFile2      = args[++i];
                        this._metaDatabase2      = args[++i];
                        this._metaDataFileMerged = args[++i];
                    }
                    else
                    {
                        this._valid        = false;
                        this._errorMessage = "Invalid switch usage: " + arg;
                    }
                    break;

                case "-m":
                case "-pf":
                case "-module":
                case "-projectfolder":
                    if (numargs > (i + 1))
                    {
                        string data = args[++i];
                        if (!_moduleNames.Contains(data))
                        {
                            this._moduleNames.Add(data);
                        }
                    }
                    else
                    {
                        this._valid        = false;
                        this._errorMessage = "Invalid switch usage: " + arg;
                    }
                    break;

                case "-rti":
                case "-recordtemplateinstance":
                    if (numargs > (i + 1))
                    {
                        this._projectItemToRecord = args[++i];
                        this._mode = ProcessMode.Project;
                    }
                    else
                    {
                        this._valid        = false;
                        this._errorMessage = "Invalid switch usage: " + arg;
                    }
                    break;

                case "-ti":
                case "-templateinstance":
                    if (numargs > (i + 1))
                    {
                        string data = args[++i];
                        if (!_projectItems.Contains(data))
                        {
                            this._projectItems.Add(data);
                        }
                    }
                    else
                    {
                        this._valid        = false;
                        this._errorMessage = "Invalid switch usage: " + arg;
                    }
                    break;

                case "-i":
                case "-inputfile":
                    this._mode = ProcessMode.Template;
                    if (numargs > (i + 1))
                    {
                        this._pathXmlData = args[++i];
                    }
                    else
                    {
                        this._valid        = false;
                        this._errorMessage = "Invalid switch usage: " + arg;
                    }
                    break;

                case "-t":
                case "-template":
                    this._mode = ProcessMode.Template;
                    if (numargs > (i + 1))
                    {
                        this._pathTemplate = args[++i];
                    }
                    else
                    {
                        this._valid        = false;
                        this._errorMessage = "Invalid switch usage: " + arg;
                    }
                    break;

                case "-c":
                case "-collect":
                    this._mode = ProcessMode.Template;
                    if (numargs > (i + 1))
                    {
                        this._pathCollectXmlData = args[++i];
                    }
                    else
                    {
                        this._valid        = false;
                        this._errorMessage = "Invalid switch usage: " + arg;
                    }
                    break;

                case "-e":
                case "-timeout":
                    if (numargs > (i + 1))
                    {
                        try
                        {
                            this._timeout = Int32.Parse(args[++i]);
                        }
                        catch
                        {
                            this._timeout = -1;
                        }
                    }
                    else
                    {
                        this._valid        = false;
                        this._errorMessage = "Invalid switch usage: " + arg;
                    }
                    break;

                default:
                    _valid             = false;
                    this._errorMessage = "Invalid argument: " + arg;
                    break;
                }
            }

            if (this._makeRelative)
            {
                if (this._pathCollectXmlData != null)
                {
                    this._pathCollectXmlData = Zeus.FileTools.MakeAbsolute(this._pathCollectXmlData, FileTools.ApplicationPath);
                }
                if (this._pathLog != null)
                {
                    this._pathLog = Zeus.FileTools.MakeAbsolute(this._pathLog, FileTools.ApplicationPath);
                }
                if (this._pathOutput != null)
                {
                    this._pathOutput = Zeus.FileTools.MakeAbsolute(this._pathOutput, FileTools.ApplicationPath);
                }
                if (this._pathProject != null)
                {
                    this._pathProject = Zeus.FileTools.MakeAbsolute(this._pathProject, FileTools.ApplicationPath);
                }
                if (this._pathTemplate != null)
                {
                    this._pathTemplate = Zeus.FileTools.MakeAbsolute(this._pathTemplate, FileTools.ApplicationPath);
                }
                if (this._pathXmlData != null)
                {
                    this._pathXmlData = Zeus.FileTools.MakeAbsolute(this._pathXmlData, FileTools.ApplicationPath);
                }
                if (this._metaDataFile1 != null)
                {
                    this._metaDataFile1 = Zeus.FileTools.MakeAbsolute(this._metaDataFile1, FileTools.ApplicationPath);
                }
                if (this._metaDataFile2 != null)
                {
                    this._metaDataFile2 = Zeus.FileTools.MakeAbsolute(this._metaDataFile2, FileTools.ApplicationPath);
                }
                if (this._metaDataFileMerged != null)
                {
                    this._metaDataFileMerged = Zeus.FileTools.MakeAbsolute(this._metaDataFileMerged, FileTools.ApplicationPath);
                }
            }


            // Validate required fields are filled out for the selected mode.
            if (_valid)
            {
                if (this.Mode == ProcessMode.MyMeta)
                {
                    if (this._metaDataMerge)
                    {
                        if (!System.IO.File.Exists(_metaDataFile1) || !System.IO.File.Exists(_metaDataFile2))
                        {
                            _valid             = false;
                            this._errorMessage = "The two source files must exist for the merge to work!";
                        }
                    }
                }
                else if (this._mode == ProcessMode.Project)
                {
                    if (this._pathProject == null)
                    {
                        _valid             = false;
                        this._errorMessage = "Project Path Required";
                    }
                    else
                    {
                        try
                        {
                            this._project = new ZeusProject(this._pathProject);
                            this._project.Load();
                        }
                        catch (Exception ex)
                        {
                            this._project      = null;
                            this._valid        = false;
                            this._errorMessage = ex.Message;
                        }
                    }


                    if (this._pathTemplate != null)
                    {
                        try
                        {
                            this._template = new ZeusTemplate(this._pathTemplate);
                        }
                        catch (Exception ex)
                        {
                            this._template     = null;
                            this._valid        = false;
                            this._errorMessage = ex.Message;
                        }
                    }
                }
                else if (this._mode == ProcessMode.Template)
                {
                    if ((this._pathTemplate == null) && (this._pathXmlData == null))
                    {
                        _valid             = false;
                        this._errorMessage = "Template path or XML input path required.";
                    }
                    else
                    {
                        if (this._pathTemplate != null)
                        {
                            try
                            {
                                this._template = new ZeusTemplate(this._pathTemplate);
                            }
                            catch (Exception ex)
                            {
                                this._template     = null;
                                this._valid        = false;
                                this._errorMessage = ex.Message;
                            }
                        }

                        if ((this._valid) && (this._pathXmlData != null))
                        {
                            try
                            {
                                this._savedInput = new ZeusSavedInput(this._pathXmlData);
                                this._savedInput.Load();

                                if (this._template == null)
                                {
                                    this._template = new ZeusTemplate(this._savedInput.InputData.TemplatePath);
                                }
                            }
                            catch (Exception ex)
                            {
                                this._savedInput   = null;
                                this._template     = null;
                                this._valid        = false;
                                this._errorMessage = ex.Message;
                            }
                        }

                        if ((this._valid) && (this._pathCollectXmlData != null))
                        {
                            try
                            {
                                this._inputToSave = new ZeusSavedInput(this._pathCollectXmlData);
                                this._inputToSave.InputData.TemplatePath     = this._template.FilePath + this._template.FileName;
                                this._inputToSave.InputData.TemplateUniqueID = this._template.UniqueID;
                            }
                            catch (Exception ex)
                            {
                                this._inputToSave  = null;
                                this._valid        = false;
                                this._errorMessage = ex.Message;
                            }
                        }
                    }
                }
            }
        }
Exemple #14
0
        private void _ProcessTemplate()
        {
            ZeusTemplate   template       = this._argmgr.Template;
            ZeusSavedInput savedInput     = this._argmgr.SavedInput;
            ZeusSavedInput collectedInput = this._argmgr.InputToSave;
            ZeusContext    context        = new ZeusContext();

            context.Log = _log;
            DefaultSettings settings;

            this._log.Write("Executing: " + template.Title);
            try
            {
                if (savedInput != null)
                {
                    context.Input.AddItems(savedInput.InputData.InputItems);
                    template.Execute(context, this._argmgr.Timeout, true);
                }
                else if (collectedInput != null)
                {
                    settings = DefaultSettings.Instance;
                    settings.PopulateZeusContext(context);
                    template.ExecuteAndCollect(context, this._argmgr.Timeout, collectedInput.InputData.InputItems);
                    collectedInput.Save();
                }
                else
                {
                    settings = DefaultSettings.Instance;
                    settings.PopulateZeusContext(context);
                    template.Execute(context, this._argmgr.Timeout, false);
                }

                if (this._argmgr.PathOutput != null)
                {
                    StreamWriter writer = File.CreateText(this._argmgr.PathOutput);
                    writer.Write(context.Output.text);
                    writer.Flush();
                    writer.Close();
                }
                else
                {
                    if (!_argmgr.IsSilent)
                    {
                        Console.WriteLine(context.Output.text);
                    }
                }
            }
            catch (Exception ex)
            {
                this._log.Write(ex);
                this._log.Write("Template execution failed.");
            }

            if (context != null && this._argmgr.InternalUseOnly)
            {
                foreach (string file in context.Output.SavedFiles)
                {
                    this._log.Write("[GENERATED_FILE]" + file);
                }
            }
        }
        public void ExecuteTemplate(IZeusContext context, string templatePath, string inputFilePath)
        {
            ZeusTemplate template = new ZeusTemplate(templatePath);
            ZeusSavedInput savedInput = null;
            DefaultSettings settings = DefaultSettings.Instance;

            if (!string.IsNullOrEmpty(inputFilePath))
            {
                savedInput = new ZeusSavedInput(inputFilePath);
            }

            context.Log.Write("Executing: " + template.Title);
            if (savedInput != null)
            {
                context.Input.AddItems(savedInput.InputData.InputItems);
                template.Execute(context, settings.ScriptTimeout, true);
            }
            else
            {
                settings.PopulateZeusContext(context);
                template.Execute(context, settings.ScriptTimeout, false);
            }
        }