private void Init() { DefaultScript = new ScriptObject(); _defaultScriptFile = Path.Combine( Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData), Settings.AppName, "default.dccscript"); try { if (File.Exists(_defaultScriptFile)) DefaultScript = ServiceProvider.ScriptManager.Load(_defaultScriptFile); } catch (Exception exception) { Log.Error("Error loading default scrip", exception); } }
public void Execute(ScriptObject scriptObject) { ShouldStop = false; IsBusy = true; scriptObject.Variabiles.Items.Clear(); scriptObject.ExitLoop = false; CurrentScript = scriptObject; GenerateVariabiles(); foreach (IScriptCommand command in scriptObject.Commands) { command.IsExecuted = false; command.Executing = false; } _timer.Start(); var thread = new Thread(ExecuteThread); thread.Start(scriptObject); }
public ScriptObject Load(string fileName) { ScriptObject res = new ScriptObject(); XmlDocument doc = new XmlDocument(); doc.Load(fileName); XmlNode rootNode = doc.SelectSingleNode("/dccscript"); if (rootNode == null) throw new ArgumentException("Wrong start of script. Should use ScriptObject"); if (GetValue(rootNode, "UseExternal") == "true") res.UseExternal = true; res.SelectedConfig = ServiceProvider.Settings.DeviceConfigs.Get(GetValue(rootNode, "SelectedConfig")); XmlNode commandNode = doc.SelectSingleNode("/dccscript/commands"); if (commandNode != null) { foreach (XmlNode node in commandNode.ChildNodes) { foreach (var command in AvaiableCommands) { if (command.Name.ToLower() == node.Name.ToLower()) res.Commands.Add(((IScriptCommand) Activator.CreateInstance(command.GetType())).Load(node)); } } } return res; }
public bool Verify(ScriptObject scriptObject) { if (scriptObject == null) return false; var res = true; if (scriptObject.Commands.Count == 0) { ServiceProvider.ScriptManager.OutPut("No commands are defined"); res = false; } return res; }
public void Save(ScriptObject scriptObject, string fileName) { XmlDocument doc = new XmlDocument(); XmlNode docNode = doc.CreateXmlDeclaration("1.0", "UTF-8", null); doc.AppendChild(docNode); XmlNode rootNode = doc.CreateElement("dccscript"); rootNode.Attributes.Append(CreateAttribute(doc, "UseExternal", scriptObject.UseExternal ? "true" : "false")); rootNode.Attributes.Append(CreateAttribute(doc, "SelectedConfig", scriptObject.SelectedConfig == null ? "" : scriptObject.SelectedConfig.Name)); doc.AppendChild(rootNode); XmlNode commandsNode = doc.CreateElement("commands"); rootNode.AppendChild(commandsNode); foreach (IScriptCommand avaiableCommand in scriptObject.Commands) { commandsNode.AppendChild(avaiableCommand.Save(doc)); } doc.Save(fileName); }