public FormatXPath ( string xpath ) : string | ||
xpath | string | the xpath to format |
return | string |
/// <summary> /// Gets all suitable Scripts defined in the model.Suitable Scripts have: /// <para /> 2 or three parameters /// <para /> Tag: EA-Matic /// </summary> /// <param name="model"></param> /// <returns></returns> public static List <Script> GetEaMaticScripts(Model model) { if (model != null) { XmlDocument xmlScripts = model.SqlQuery(@"select s.ScriptID, s.Notes, s.Script,ps.Script as SCRIPTGROUP, ps.Notes as GROUPNOTES from t_script s inner join t_script ps on s.ScriptAuthor = ps.ScriptName where s.Script like '%EA-Matic%'" ); //check the hash before continuing int newHash = xmlScripts.InnerXml.GetHashCode(); //only create the scripts of the hash is different //otherwise we returned the cached scripts if (newHash != _scriptHash) { //set the new hash code _scriptHash = newHash; //reset scripts _allScripts = new List <Script>(); //set flag to reload scripts in includableScripts _reloadModelIncludableScripts = true; _modelIncludableScripts = new Dictionary <string, string>(); XmlNodeList scriptNodes = xmlScripts.SelectNodes("//Row"); foreach (XmlNode scriptNode in scriptNodes) { //get the <notes> node. If it contains "Group Type=" then it is a group. Else we need to find "Language=" XmlNode notesNode = scriptNode.SelectSingleNode(model.FormatXPath("Notes")); if (notesNode.InnerText.Contains(_scriptLanguageIndicator)) { //we have an actual script. //the name of the script string scriptName = GetValueByName(notesNode.InnerText, _scriptNameIndicator); //now figure out the language string language = GetValueByName(notesNode.InnerText, _scriptLanguageIndicator); //get the ID XmlNode idNode = scriptNode.SelectSingleNode(model.FormatXPath("ScriptID")); string scriptId = idNode.InnerText; //get the group XmlNode groupNode = scriptNode.SelectSingleNode(model.FormatXPath("SCRIPTGROUP")); string groupName = groupNode.InnerText; //then get the code XmlNode codeNode = scriptNode.SelectSingleNode(model.FormatXPath("Script")); if (codeNode != null && language != string.Empty) { //if the script is still empty EA returns NULL string scriptCode = codeNode.InnerText; if (scriptCode.Equals("NULL", StringComparison.InvariantCultureIgnoreCase)) { scriptCode = string.Empty; } var script = new Script(scriptId, scriptName, groupName, scriptCode, language, model); //and create the script if both code and language are found _allScripts.Add(script); //also add the script to the include dictionary _modelIncludableScripts.Add("!INC " + script.GroupName + "." + script.Name, script.Code); } } } //Add the static EA-Matic scripts to allScripts foreach (Script staticScript in StaticEaMaticScripts) { //add the model to the static script first staticScript._model = model; //then add the static scrip to all scripts _allScripts.Add(staticScript); } //load the code of the scripts (because a script can include another script we can only load the code after all scripts have been created) foreach (Script script in _allScripts) { script.ReloadCode(); } } } return(_allScripts); }
/// <summary> /// Gets all suitable Scripts defined in the model.Suitable Scripts have: /// <para /> 2 or three parameters /// <para /> Tag: EA-Matic /// </summary> /// <param name="model"></param> /// <returns></returns> public static List<Script> GetEaMaticScripts(Model model) { if (model != null) { XmlDocument xmlScripts = model.SqlQuery(@"select s.ScriptID, s.Notes, s.Script,ps.Script as SCRIPTGROUP, ps.Notes as GROUPNOTES from t_script s inner join t_script ps on s.ScriptAuthor = ps.ScriptName where s.Script like '%EA-Matic%'"); //check the hash before continuing int newHash = xmlScripts.InnerXml.GetHashCode(); //only create the scripts of the hash is different //otherwise we returned the cached scripts if (newHash != _scriptHash) { //set the new hash code _scriptHash = newHash; //reset scripts _allScripts = new List<Script>(); //set flag to reload scripts in includableScripts _reloadModelIncludableScripts = true; _modelIncludableScripts = new Dictionary<string, string>(); XmlNodeList scriptNodes = xmlScripts.SelectNodes("//Row"); foreach (XmlNode scriptNode in scriptNodes) { //get the <notes> node. If it contains "Group Type=" then it is a group. Else we need to find "Language=" XmlNode notesNode = scriptNode.SelectSingleNode(model.FormatXPath("Notes")); if (notesNode.InnerText.Contains(_scriptLanguageIndicator)) { //we have an actual script. //the name of the script string scriptName = GetValueByName(notesNode.InnerText, _scriptNameIndicator); //now figure out the language string language = GetValueByName(notesNode.InnerText, _scriptLanguageIndicator); //get the ID XmlNode idNode = scriptNode.SelectSingleNode(model.FormatXPath("ScriptID")); string scriptId = idNode.InnerText; //get the group XmlNode groupNode = scriptNode.SelectSingleNode(model.FormatXPath("SCRIPTGROUP")); string groupName = groupNode.InnerText; //then get the code XmlNode codeNode = scriptNode.SelectSingleNode(model.FormatXPath("Script")); if (codeNode != null && language != string.Empty) { //if the script is still empty EA returns NULL string scriptCode = codeNode.InnerText; if (scriptCode.Equals("NULL",StringComparison.InvariantCultureIgnoreCase)) { scriptCode = string.Empty; } var script = new Script(scriptId,scriptName,groupName,scriptCode, language,model); //and create the script if both code and language are found _allScripts.Add(script); //also add the script to the include dictionary _modelIncludableScripts.Add("!INC "+ script.GroupName + "." + script.Name,script.Code); } } } //Add the static EA-Matic scripts to allScripts foreach (Script staticScript in StaticEaMaticScripts) { //add the model to the static script first staticScript._model = model; //then add the static scrip to all scripts _allScripts.Add(staticScript); } //load the code of the scripts (because a script can include another script we can only load the code after all scripts have been created) foreach (Script script in _allScripts) { script.ReloadCode(); } } } return _allScripts; }