Example #1
0
        private void ChangeParameter(XmlNode command)
        {
            string value = GetAttributeOrError(command, "Value", "The attribute 'Value' was not found!");
            string error = null;

            if (command.HasChildNodes)
            {
                foreach (XmlNode child in command)
                {
                    if (child.LocalName.ToLowerInvariant() == "parameter")
                    {
                        string parameterName = GetAttributeOrError(child, "ParameterPath", "The attribute 'ParameterPath' was not found!");
                        if (!ModelSystemReflection.AssignValue(Config, ChildStructure, parameterName, value, ref error))
                        {
                            throw new XTMFRuntimeException(this, $"In '{Name}' we were unable assign a variable.\r\n{error}");
                        }
                    }
                }
            }
            else
            {
                string parameterName = GetAttributeOrError(command, "ParameterPath", "The attribute 'ParameterPath' was not found!");
                if (!ModelSystemReflection.AssignValue(Config, ChildStructure, parameterName, value, ref error))
                {
                    throw new XTMFRuntimeException(this, $"In '{Name}' we were unable assign a variable.\r\n{error}");
                }
            }
        }
Example #2
0
        private void ChangeLinkedParameter(XmlNode command)
        {
            string name                = GetAttributeOrError(command, "Name", "The attribute 'Name' was not found!");
            string value               = GetAttributeOrError(command, "Value", "The attribute 'Value' was not found!");
            var    project             = Config.ProjectRepository.ActiveProject;
            var    modelSystemIndex    = project.ModelSystemStructure.IndexOf(ModelSystemReflection.BuildModelStructureChain(Config, this)[0]);
            var    ourLinkedParameters = project.LinkedParameters[modelSystemIndex];
            bool   any = false;

            foreach (var lp in ourLinkedParameters)
            {
                if (lp.Name == name)
                {
                    any = true;
                    foreach (var parameter in lp.Parameters)
                    {
                        ModelSystemReflection.AssignValue(parameter, value);
                    }
                }
            }
            if (!any)
            {
                throw new XTMFRuntimeException("In '" + Name + "' a linked parameter '" + name + "' was not found in order to assign it the value of '" + value + "'.");
            }
        }
Example #3
0
        public bool RuntimeValidation(ref string error)
        {
            if (string.IsNullOrEmpty(ModelSystemName))
            {
                _modelSystemStructure = ModelSystemReflection.BuildModelStructureChain(Configuration, this);
            }
            else
            {
                foreach (var projectRepository in Configuration.ProjectRepository)
                {
                    foreach (var modelSystemStructure in projectRepository.ModelSystemStructure)
                    {
                        if (modelSystemStructure.Name.ToLower() == ModelSystemName.ToLower())
                        {
                            _modelSystemStructure = new List <IModelSystemStructure> {
                                modelSystemStructure
                            }
                        }
                    }
                }
            };

            if (_modelSystemStructure == null)
            {
                error = "Unable to find the model system specified.";
                return(false);
            }

            return(true);
        }
Example #4
0
        private void AddMultiRunCommand()
        {
            var listToUs = ModelSystemReflection.BuildModelStructureChain(Config, this);

            for (int i = listToUs.Count - 1; i >= 0; i--)
            {
                var multiRunFramework = listToUs[i].Module as MultiRun.MultiRunModelSystem;
                if (multiRunFramework != null)
                {
                    multiRunFramework.TryAddBatchCommand("LaunchProgram.ShutdownExternalProgram", (node) =>
                    {
                        var path = multiRunFramework.GetAttributeOrError(node, "Path", "In 'LaunchProgram.ShutdownExternalProgram' we were unable to find an xml attribute called 'Path'!\r\nPlease add this to your batch script.");
                        IModelSystemStructure selectedModule         = null;
                        IModelSystemStructure multiRunFrameworkChild = null;
                        if (!ModelSystemReflection.FindModuleStructure(Config, multiRunFramework.Child, ref multiRunFrameworkChild))
                        {
                            throw new XTMFRuntimeException("We were unable to find the multi-run frameworks child module's model system structure!");
                        }
                        if (!ModelSystemReflection.GetModelSystemStructureFromPath(multiRunFrameworkChild, path, ref selectedModule))
                        {
                            throw new XTMFRuntimeException("We were unable to find a module with the path '" + path + "'!");
                        }
                        var toShutdown = selectedModule.Module as LaunchProgram;
                        if (toShutdown == null)
                        {
                            throw new XTMFRuntimeException("The module with the path '" + path + "' was not of type 'TMG.Frameworks.Extensibility.LaunchProgram'!");
                        }
                        toShutdown.ShutdownProgram();
                    }, true);
                    break;
                }
            }
        }
Example #5
0
        public bool RuntimeValidation(ref string error)
        {
            IModelSystemStructure us = null;

            if (!ModelSystemReflection.FindModuleStructure(Config.ProjectRepository.ActiveProject, this, ref us))
            {
                error = "In '" + Name + "' we were unable to find ourselves!";
                return(false);
            }
            AddMultiRunCommand();
            return(true);
        }
Example #6
0
        private void UnloadResource(XmlNode command)
        {
            string path = GetAttributeOrError(command, "Path", "We were unable to find an attribute called 'Path'!");
            IModelSystemStructure referencedModule = null;

            if (!ModelSystemReflection.GetModelSystemStructureFromPath(ChildStructure, path, ref referencedModule))
            {
                throw new XTMFRuntimeException("In '" + Name + "' we were unable to find the child with the path '" + path + "'!");
            }
            if (referencedModule.IsCollection)
            {
                var children = referencedModule.Children;
                if (children != null)
                {
                    foreach (var child in children)
                    {
                        var mod        = child.Module;
                        var res        = mod as IResource;
                        var dataSource = mod as IDataSource;
                        if (res != null)
                        {
                            res.ReleaseResource();
                        }
                        else if (dataSource != null)
                        {
                            dataSource.UnloadData();
                        }
                    }
                }
            }
            else
            {
                var res        = referencedModule.Module as IResource;
                var dataSource = referencedModule.Module as IDataSource;
                if (res != null)
                {
                    res.ReleaseResource();
                }
                else if (dataSource != null)
                {
                    dataSource.UnloadData();
                }
                else
                {
                    throw new XTMFRuntimeException("In '" + Name + "' the referenced module '" + path + "' is not a resource or data source! Only resources or data sources can be unloaded!");
                }
            }
        }
Example #7
0
        private void ChangeParameter(XmlNode command)
        {
            string value = GetAttributeOrError(command, "Value", "The attribute 'Value' was not found!");

            if (command.HasChildNodes)
            {
                foreach (XmlNode child in command)
                {
                    if (child.LocalName.ToLowerInvariant() == "parameter")
                    {
                        string parameterName = GetAttributeOrError(child, "ParameterPath", "The attribute 'ParameterPath' was not found!");
                        ModelSystemReflection.AssignValue(ChildStructure, parameterName, value);
                    }
                }
            }
            else
            {
                string parameterName = GetAttributeOrError(command, "ParameterPath", "The attribute 'ParameterPath' was not found!");
                ModelSystemReflection.AssignValue(ChildStructure, parameterName, value);
            }
        }
Example #8
0
        private bool LoadChildFromXTMF(ref string error)
        {
            IModelSystemStructure ourStructure = null;

            if (ModelSystemReflection.FindModuleStructure(Config, this, ref ourStructure))
            {
                foreach (var child in ourStructure.Children)
                {
                    if (child.ParentFieldName == "Child")
                    {
                        ChildStructure = child;
                        break;
                    }
                }
            }
            if (ChildStructure == null)
            {
                error = "In '" + Name + "' we were unable to find the Client Model System!";
                return(false);
            }
            return(true);
        }
Example #9
0
        private void UnloadResource(XmlNode command)
        {
            string path      = GetAttributeOrError(command, "Path", "We were unable to find an attribute called 'Path'!");
            bool   recursive = false;
            var    attribute = command.Attributes?["Recursive"];

            if (attribute != null)
            {
                if (!bool.TryParse(attribute.InnerText, out recursive))
                {
                    throw new XTMFRuntimeException(this, "In '" + Name + "' an unload command had a recursive parameter with the value '" + attribute.InnerText + "', which is not true/false!");
                }
            }
            IModelSystemStructure referencedModule = null;

            if (!ModelSystemReflection.GetModelSystemStructureFromPath(ChildStructure, path, ref referencedModule))
            {
                throw new XTMFRuntimeException(this, "In '" + Name + "' we were unable to find the child with the path '" + path + "'!");
            }
            if (referencedModule.IsCollection)
            {
                var children = referencedModule.Children;
                if (children != null)
                {
                    foreach (var child in children)
                    {
                        if (recursive)
                        {
                            UnloadRecursively(child);
                        }
                        else
                        {
                            var mod        = child.Module;
                            var dataSource = mod as IDataSource;
                            if (mod is IResource res)
                            {
                                res.ReleaseResource();
                            }
                            else if (dataSource != null)
                            {
                                dataSource.UnloadData();
                            }
                        }
                    }
                }
            }
            else
            {
                if (recursive)
                {
                    UnloadRecursively(referencedModule);
                }
                else
                {
                    var dataSource = referencedModule.Module as IDataSource;
                    if (referencedModule.Module is IResource res)
                    {
                        res.ReleaseResource();
                    }
                    else if (dataSource != null)
                    {
                        dataSource.UnloadData();
                    }
                    else
                    {
                        throw new XTMFRuntimeException(this, "In '" + Name + "' the referenced module '" + path + "' is not a resource or data source! Only resources or data sources can be unloaded!");
                    }
                }
            }
        }