Ejemplo n.º 1
0
        public override void FromXml(string source)
        {
            // Deserializes element and children from xml string
            XqlParser parser = new XqlParser();

            parser.LoadData(source);
            List <Hashtable> results = parser.Query("SELECT enableScripting, _innerXml FROM " + ElementType);

            if (results.Count == 0)
            {
                throw new HsfElementException("Unable to parse " + ElementType + " from xml");
            }

            // Load flag
            if (results[0]["enableScripting"].ToString() == "True")
            {
                IsScriptingEnabled = true;
            }
            else
            {
                IsScriptingEnabled = false;
            }

            // Load children
            Files.Clear();
            LuaFileElement test = new LuaFileElement();

            results = parser.Query("SELECT _outerXml FROM " + test.ElementType);
            foreach (Hashtable ht in results)
            {
                LuaFileElement newFile = new LuaFileElement();
                newFile.FromXml(ht["_outerXml"].ToString());
                Files.Add(newFile);
            }
        }
Ejemplo n.º 2
0
        public void LoadFromXml(string content)
        {
            // Parse Xml spec for symbols
            XqlParser parser = new XqlParser();

            parser.LoadData(content);

            // Search for keyword definitions
            List <Hashtable> results = parser.Query("SELECT name, type FROM Keyword");

            foreach (Hashtable result in results)
            {
                ScriptingSymbol newSymbol = new ScriptingSymbol();
                newSymbol.Name    = result["name"].ToString();
                newSymbol.Type    = LuaSymbolType.Keyword;
                newSymbol.Enabled = true;
                _symbols.Add(newSymbol);
            }

            // Search for class definitions and symbols within each class scope
            results = parser.Query("SELECT name, _outerXml FROM Class");
            XqlParser subParser = new XqlParser();

            foreach (Hashtable result in results)
            {
                ScriptingSymbol newSymbol = new ScriptingSymbol();
                newSymbol.Name    = result["name"].ToString();
                newSymbol.Type    = LuaSymbolType.Class;
                newSymbol.Enabled = true;
                _symbols.Add(newSymbol);

                // Add method and member symbols within this class scope (disabled until scope opened)
                subParser.LoadData(result["_outerXml"].ToString());
                List <Hashtable> subResults = subParser.Query("SELECT name, type FROM Method");
                foreach (Hashtable subResult in subResults)
                {
                    ScriptingSymbol classMethod = new ScriptingSymbol();
                    classMethod.Name         = subResult["name"].ToString();
                    classMethod.Type         = LuaSymbolType.Function;
                    classMethod.Enabled      = false;
                    classMethod.ParentSymbol = newSymbol;
                    _symbols.Add(classMethod);
                }
                subResults = subParser.Query("SELECT name, type FROM Property");
                foreach (Hashtable subResult in subResults)
                {
                    ScriptingSymbol classProperty = new ScriptingSymbol();
                    classProperty.Name         = subResult["name"].ToString();
                    classProperty.Type         = LuaSymbolType.Local;
                    classProperty.Enabled      = false;
                    classProperty.ParentSymbol = newSymbol;
                    _symbols.Add(classProperty);
                }
            }

            // Sort all symbols and update listbox content
            SortSymbols();
            UpdateItems();
        }
        public override void FromXml(string source)
        {
            // Deserialize asset from xml string
            XqlParser parser = new XqlParser();

            parser.LoadData(source);
            List <Hashtable> results = parser.Query("SELECT _innerXml, name, assetId FROM " + ElementType);

            if (results.Count == 0)
            {
                throw new HsfElementException("Unable to parse " + ElementType + " from xml");
            }

            // Load string values
            Name = results[0]["name"].ToString();
            if (Name == "")
            {
                Name = "Unknown Asset";
            }
            try
            {
                Id = Convert.ToInt64(results[0]["assetId"]);
            }
            catch (FormatException)
            {
                Id = 0;
            }

            // Load subsystems
            parser.LoadData(results[0]["_innerXml"].ToString());
            SubsystemElement sampleSub = new SubsystemElement();

            results = parser.Query("SELECT _outerXml FROM " + sampleSub.ElementType);
            foreach (Hashtable ht in results)
            {
                SubsystemElement newSub = new SubsystemElement();
                newSub.FromXml(ht["_outerXml"].ToString());
                Subsystems.Add(newSub);
            }

            // Load constraints
            ConstraintElement sampleCons = new ConstraintElement();

            results = parser.Query("SELECT _outerXml FROM " + sampleCons.ElementType);
            foreach (Hashtable ht in results)
            {
                ConstraintElement newCons = new ConstraintElement();
                newCons.FromXml(ht["_outerXml"].ToString());
                Constraints.Add(newCons);
            }

            // Load position
            results = parser.Query("SELECT _outerXml FROM " + Position.ElementType);
            Position.FromXml(results[0]["_outerXml"].ToString());
        }
        private void openScenarioFromFile()
        {
            // Opens new scenario using open file dialog
            OpenFileDialog dialog = new OpenFileDialog();

            dialog.Filter = "Hsx file (.hsx)|*.hsx|All files|*.*";
            dialog.Title  = "Open Scenario";
            if (dialog.ShowDialog() != DialogResult.OK)
            {
                return;
            }

            // Loads new scenario using components specified in given HSX file from dialog
            string           filename = dialog.FileName;
            XqlParser        myParser = new XqlParser(filename);
            List <Hashtable> result;

            // Determine paths
            result = myParser.Query("SELECT path FROM hsx"); string            rootPath = (string)result[0]["path"];
            result = myParser.Query("SELECT filename FROM scenario"); string   scenPath = (string)rootPath + result[0]["filename"];
            result = myParser.Query("SELECT filename FROM targetdeck"); string trgtPath = (string)rootPath + result[0]["filename"];
            result = myParser.Query("SELECT filename FROM model"); string      modlPath = (string)rootPath + result[0]["filename"];

            // Create new scenario component from file and attach to form
            ScenarioComponent newScenario = new ScenarioComponent();

            newScenario.FromFile(scenPath);
            ScenarioForm scenarioForm = new ScenarioForm(newScenario, this);

            scenarioForm.FileTarget = filename;
            _scenarios.Add(scenarioForm);

            // Form takes care of itself via node update?
            // Create new targetdeck from file and attach to scenario
            TargetdeckComponent newTargetdeck = new TargetdeckComponent();

            newTargetdeck.FromFile(trgtPath);
            newScenario.Targetdeck = newTargetdeck;

            // Create new model from file and attach to scenario
            ModelComponent newModel = new ModelComponent();

            newModel.FromFile(modlPath);
            newScenario.Model = newModel;

            // Update node tree and select scenario
            UpdateScenarioNode(scenarioForm);
            TreeNode node = getNodeFromForm(scenarioForm);

            mainTreeView.SelectedNode = node;
        }
        public override void FromXml(string source)
        {
            // Deserializes object from xml string
            XqlParser parser = new XqlParser();

            parser.LoadData(source);
            List <Hashtable> results = parser.Query("SELECT scripted, type, key, callKey FROM " + ElementType);

            if (results.Count == 0)
            {
                throw new HsfElementException("Unable to parse " + ElementType + " from xml");
            }

            // Load type enum
            Array posValues = Enum.GetValues(typeof(HsfType));

            foreach (HsfType v in posValues)
            {
                if (Enum.GetName(typeof(HsfType), v) == results[0]["type"].ToString())
                {
                    Type = v;
                }
            }

            // Load flag
            IsScripted = results[0]["scripted"].ToString() == "True" ? true : false;

            // Load strings
            Key     = results[0]["key"].ToString();
            CallKey = results[0]["callKey"].ToString();
        }
Ejemplo n.º 6
0
        public override void FromXml(string source)
        {
            // Attempts to load a position from the given xml string
            XqlParser parser = new XqlParser();

            parser.LoadData(source);
            List <Hashtable> results = parser.Query("SELECT PositionType, ICs FROM " + ElementType);

            if (results.Count == 0)
            {
                throw new HsfElementException("Unable to parse " + ElementType + " from xml");
            }

            // Load enums
            Array posValues = Enum.GetValues(typeof(PositionType));

            foreach (PositionType v in posValues)
            {
                if (Enum.GetName(typeof(PositionType), v) == results[0]["PositionType"].ToString())
                {
                    PositionType = v;
                }
            }

            // Load children
            Ics.FromString(results[0]["ICs"].ToString());
        }
Ejemplo n.º 7
0
        public override void FromXml(string source)
        {
            // Attempts to load a position from the given xml string
            XqlParser parser = new XqlParser();

            parser.LoadData(source);
            List <Hashtable> results = parser.Query("SELECT type, evaluateLUAFcn FROM " + ElementType);

            if (results.Count == 0)
            {
                throw new HsfElementException("Unable to parse " + ElementType + " from xml");
            }

            // Load enum
            Array posValues = Enum.GetValues(typeof(ScheduleEvaluatorType));

            foreach (ScheduleEvaluatorType v in posValues)
            {
                if (Enum.GetName(typeof(ScheduleEvaluatorType), v) == results[0]["type"].ToString())
                {
                    Type = v;
                }
            }

            // Load LUA function?
            if (Type == ScheduleEvaluatorType.scripted)
            {
                _evaluateLuaFcn = results[0]["evaluateLUAFcn"].ToString();
            }
            else
            {
                _evaluateLuaFcn = "";
            }
        }
        public override void FromXml(string source)
        {
            // Deserializes initial condition from xml string
            XqlParser parser = new XqlParser();

            parser.LoadData(source);
            List <Hashtable> results = parser.Query("SELECT type, key, value FROM " + ElementType);

            if (results.Count == 0)
            {
                throw new HsfElementException("Unable to parse " + ElementType + " from xml");
            }

            // Load type enum
            Array posValues = Enum.GetValues(typeof(HsfType));

            foreach (HsfType v in posValues)
            {
                if (Enum.GetName(typeof(HsfType), v) == results[0]["type"].ToString())
                {
                    Type = v;
                }
            }

            // Load values
            Key   = results[0]["key"].ToString();
            Value = results[0]["key"].ToString();
        }
        public override void FromXml(string source)
        {
            // Deserialize object from xml string
            XqlParser parser = new XqlParser();

            parser.LoadData(source);
            List <Hashtable> results = parser.Query("SELECT value, subId, type FROM " + ElementType);

            if (results.Count == 0)
            {
                throw new HsfElementException("Unable to parse " + ElementType + " from xml");
            }

            // Load values
            try
            {
                Value = Convert.ToDouble(results[0]["value"]);
            }
            catch (FormatException)
            {
                Value = 0.0;
            }
            try
            {
                SubId = Convert.ToInt64(results[0]["subId"]);
            }
            catch (FormatException)
            {
                SubId = 0;
            }

            // Load type enum
            Array posValues = Enum.GetValues(typeof(ConstraintType));

            foreach (ConstraintType v in posValues)
            {
                if (Enum.GetName(typeof(ConstraintType), v) == results[0]["type"].ToString())
                {
                    Type = v;
                }
            }

            // Load statevar
            results = parser.Query("SELECT _innerXml FROM " + ElementType);
            Statevar.FromXml(results[0]["_innerXml"].ToString());
        }
        public override void FromXml(string source)
        {
            // Deserializes model from xml string
            XqlParser parser = new XqlParser();

            parser.LoadData(source);

            // Start with Lua
            List <Hashtable> results = parser.Query("SELECT _outerXml FROM " + Lua.ElementType);

            if (results.Count == 0)
            {
                // LUA tages are optional; if there are no tags present, scripting is disabled and no scripts are specified
                //throw new HsfComponentException("Unable to parse " + ElementType + " from xml");
                Lua.IsScriptingEnabled = false;
                Lua.Files.Clear();
            }
            else
            {
                Lua.FromXml(results[0]["_outerXml"].ToString());
            }

            // Next, schedule evaluator
            results = parser.Query("SELECT _outerXml FROM " + ScheduleEvaluator.ElementType);
            if (results.Count == 0)
            {
                throw new HsfComponentException("Unable to parse " + ElementType + " from xml");
            }
            ScheduleEvaluator.FromXml(results[0]["_outerXml"].ToString());

            // Lastly, assets
            AssetElement blankAsset = new AssetElement();

            Assets.Clear();
            results = parser.Query("SELECT _outerXml FROM " + blankAsset.ElementType);
            foreach (Hashtable ht in results)
            {
                AssetElement newAsset = new AssetElement();
                newAsset.FromXml(ht["_outerXml"].ToString());
                Assets.Add(newAsset);
            }
        }
Ejemplo n.º 11
0
        public override void FromFile(string filename)
        {
            // Attempts to load a list of targets from given file
            XqlParser        parser  = new XqlParser(filename);
            List <Hashtable> results = parser.Query("SELECT _outerXml FROM TARGET");

            foreach (Hashtable ht in results)
            {
                Target newTarget = new Target();
                newTarget.FromXml(ht["_outerXml"].ToString());
                Targets.Add(newTarget);
            }
        }
Ejemplo n.º 12
0
        public override void FromXml(string source)
        {
            // Loads targetdeck and children from given raw string
            XqlParser parser = new XqlParser();

            parser.LoadData(source);
            List <Hashtable> results = parser.Query("SELECT _outerXml FROM TARGET");

            foreach (Hashtable ht in results)
            {
                TargetElement newTarget = new TargetElement();
                newTarget.FromXml(ht["_outerXml"].ToString());
                Targets.Add(newTarget);
            }
        }
        public override void FromXml(string source)
        {
            // Deserializes element from xml string
            XqlParser parser = new XqlParser();

            parser.LoadData(source);
            List <Hashtable> results = parser.Query("SELECT src FROM " + ElementType);

            if (results.Count == 0)
            {
                throw new HsfElementException("Unable to parse " + ElementType + " from xml");
            }

            // Load src!
            Src = results[0]["src"].ToString();
        }
        public override void FromXml(string source)
        {
            // Loads component from raw xml string
            XqlParser parser = new XqlParser();

            parser.LoadData(source);
            List <Hashtable> results = parser.Query("SELECT isSunVecConstant FROM SUN");

            if (results.Count == 0)
            {
                throw new HsfComponentException("Unable to parse " + ElementType + " from file");
            }

            // Write values
            IsSunVecConstant = results[0]["isSunVecConstant"].ToString() == "True";
        }
        public override void FromXml(string source)
        {
            // Deserializes element from xml string
            XqlParser parser = new XqlParser();

            parser.LoadData(source);
            List <Hashtable> results = parser.Query("SELECT SubId FROM " + ElementType);

            if (results.Count == 0)
            {
                throw new HsfElementException("Unable to parse " + ElementType + " from xml");
            }

            // Grab sub id
            SubId = Convert.ToInt64(results[0]["SubId"]);
        }
        public override void FromFile(string filename)
        {
            // Loads component and child elements from given file
            XqlParser        parser  = new XqlParser(filename);
            List <Hashtable> results = parser.Query("SELECT scenarioName, _innerXml FROM " + ElementType);

            if (results.Count == 0)
            {
                throw new HsfComponentException("Unable to parse " + ElementType + " from file " + filename);
            }

            // Get values and pass to child elements
            ScenarioName = results[0]["scenarioName"].ToString();
            SimulationParameters.FromXml(results[0]["_innerXml"].ToString());
            SchedulerParameters.FromXml(results[0]["_innerXml"].ToString());
        }
Ejemplo n.º 17
0
        public override void FromXml(string source)
        {
            // Loads values of this element from given Xml string
            XqlParser parser = new XqlParser();

            parser.LoadData(source);
            List <Hashtable> results = parser.Query("SELECT MaxSchedules, NumCrop, SimStep FROM " + ElementType);

            if (results.Count == 0)
            {
                throw new HsfElementException("Unable to parse " + ElementType + " from xml");
            }

            MaxSchedules = Convert.ToDouble(results[0]["MaxSchedules"]);
            CropTo       = Convert.ToDouble(results[0]["NumCrop"]);
            SimStep      = Convert.ToDouble(results[0]["SimStep"]);
        }
        public override void FromXml(string source)
        {
            // Loads values of this element from given Xml string
            XqlParser parser = new XqlParser();

            parser.LoadData(source);
            List <Hashtable> results = parser.Query("SELECT SimStartJD, SimStart, SimEnd FROM " + ElementType);

            if (results.Count == 0)
            {
                throw new HsfElementException("Unable to parse " + ElementType + " from xml");
            }

            SimStartJd = Convert.ToDouble(results[0]["SimStartJD"]);
            SimStart   = Convert.ToDouble(results[0]["SimStart"]);
            SimEnd     = Convert.ToDouble(results[0]["SimEnd"]);
        }
Ejemplo n.º 19
0
        public override void FromXml(string source)
        {
            // Loads component and child elements from raw string data
            XqlParser parser = new XqlParser();

            parser.LoadData(source);
            List <Hashtable> results = parser.Query("SELECT scenarioName, _innerXml FROM " + ElementType);

            if (results.Count == 0)
            {
                throw new HsfComponentException("Unable to parse " + ElementType + " from file");
            }

            // Get values and pass to child elements
            ScenarioName = results[0]["scenarioName"].ToString();
            SimParams.FromXml(results[0]["_innerXml"].ToString());
            SchParams.FromXml(results[0]["_innerXml"].ToString());
        }
        public override void FromXml(string source)
        {
            // Attempts to load this element and children from given xml content string
            XqlParser parser = new XqlParser();

            parser.LoadData(source);
            List <Hashtable> results = parser.Query("SELECT TargetName, TargetType, TaskType, MaxTimes, Value, _innerXml FROM " + ElementType);

            if (results.Count == 0)
            {
                throw new HsfElementException("Unable to parse " + ElementType + " from xml");
            }

            // Load values
            TargetName = results[0]["TargetName"].ToString();
            MaxTimes   = Convert.ToDouble(results[0]["MaxTimes"]);
            Value      = Convert.ToDouble(results[0]["Value"]);

            // Load enums
            Array posValues = Enum.GetValues(typeof(TargetType));

            foreach (TargetType v in posValues)
            {
                if (Enum.GetName(typeof(TargetType), v) == results[0]["TargetType"].ToString())
                {
                    TargetType = v;
                }
            }
            posValues = Enum.GetValues(typeof(TaskType));
            foreach (TaskType v in posValues)
            {
                if (Enum.GetName(typeof(TaskType), v) == results[0]["TaskType"].ToString())
                {
                    TaskType = v;
                }
            }

            // Load children
            Position.FromXml(results[0]["_innerXml"].ToString());
        }
Ejemplo n.º 21
0
        public override void FromXml(string source)
        {
            // Deserializes object from xml string
            XqlParser parser = new XqlParser();

            parser.LoadData(source);
            List <Hashtable> results = parser.Query("SELECT EOMSType, initFcn, evalFcn FROM " + ElementType);

            if (results.Count == 0)
            {
                throw new HsfElementException("Unable to parse " + ElementType + " from xml");
            }

            // Load enum
            Array posValues = Enum.GetValues(typeof(EomsType));

            foreach (EomsType v in posValues)
            {
                if (Enum.GetName(typeof(EomsType), v) == results[0]["EOMSType"].ToString())
                {
                    Type = v;
                }
            }

            // Load function?
            if (Type == EomsType.Scripted)
            {
                _initialFunction    = results[0]["initFcn"].ToString();
                _evaluationFunction = results[0]["evalFcn"].ToString();
            }
            else
            {
                _initialFunction    = "";
                _evaluationFunction = "";
            }
        }
Ejemplo n.º 22
0
        public override void FromXml(string source)
        {
            // Deserialize subsystem object from xml string
            XqlParser parser = new XqlParser();

            parser.LoadData(source);
            List <Hashtable> results = parser.Query("SELECT Type, SubId, Name, _innerXml FROM " + ElementType);

            if (results.Count == 0)
            {
                throw new HsfElementException("Unable to parse " + ElementType + " from xml");
            }

            // Load basic fields and type enum
            string innerXml = results[0]["_innerXml"].ToString();

            Name = results[0]["Name"].ToString();
            Id   = Convert.ToInt64(results[0]["SubId"]);
            Array posValues = Enum.GetValues(typeof(SubsystemType));

            foreach (SubsystemType v in posValues)
            {
                if (Enum.GetName(typeof(SubsystemType), v) == results[0]["Type"].ToString())
                {
                    Type = v;
                }
            }

            // Load others based on type
            if (Type == SubsystemType.Scripted)
            {
                // Set number of fields that must be loaded for scripted subsystems
                results = parser.Query("SELECT initLUAFcn, canPerformLUAFcn, canExtendLUAFcn FROM " + ElementType);
                if (results.Count == 0)
                {
                    throw new HsfElementException("Unable to parse " + ElementType + " from xml");
                }
                _initLuaFcn       = results[0]["initLUAFcn"].ToString();
                _canPerformLuaFcn = results[0]["canPerformLUAFcn"].ToString();
                _canExtendLuaFcn  = results[0]["canExtendLUAFcn"].ToString();
            }
            else
            {
                // Load ALL possible fields for non-scripted subsystem
                results = parser.Query("SELECT * FROM " + ElementType);
                Attributes.Clear();
                foreach (object key in results[0].Keys)
                {
                    Attributes[key] = results[0][key];
                }
            }

            // Load ICs
            parser.LoadData(innerXml);
            IcElement sampleIc = new IcElement();

            results = parser.Query("SELECT _outerXml FROM " + sampleIc.ElementType);
            Ics.Clear();
            foreach (Hashtable ht in results)
            {
                IcElement newIc = new IcElement();
                newIc.FromXml(ht["_outerXml"].ToString());
                Ics.Add(newIc);
            }

            // Load dependencies
            DependencyElement sampleDep = new DependencyElement();

            results = parser.Query("SELECT _outerXml FROM " + sampleDep.ElementType);
            Dependencies.Clear();
            foreach (Hashtable ht in results)
            {
                DependencyElement newDep = new DependencyElement();
                newDep.FromXml(ht["_outerXml"].ToString());
                Dependencies.Add(newDep);
            }

            // Load dependency function
            results = parser.Query("SELECT _outerXml FROM " + DependencyFunction.ElementType);
            if (results.Count > 0)
            {
                DependencyFunction.Enabled = true;
                DependencyFunction.FromXml(results[0]["_outerXml"].ToString());
            }
            else
            {
                DependencyFunction.Enabled = false;
            }
        }