public void ParseScriptAndRun(ISerial serial_device, String script_stream, int stream_size) { // Script file is empty if (string.IsNullOrEmpty(script_stream.Trim())) { Errors.LogErrorNowAndKill(new ScriptEmptyException()); //this.OnError (); return; } Script script = new Script(); XmlSerializer s = new XmlSerializer(typeof(Script)); try { using (StringReader reader = new StringReader(script_stream.Substring(0, stream_size))) { script = (Script)s.Deserialize(reader); } buildScriptActions(serial_device, script); } catch (Exception e) { if (!Errors.IsOwnException(e)) { Errors.LogErrorNowAndKill(new ScriptWrongStructureException()); // Script file has invalid format or structure } else { Errors.LogErrorNowAndKill(e); // ScriptLogfileInvalidException, ScriptActionTypeInvalidException } //this.OnError (); return; } this.Run(); }