/// <summary> /// Compare arguments by compare mark. /// </summary> /// <param name="mark">Compare mark.</param> /// <param name="arg1">Argument 1.</param> /// <param name="arg2">Argument 2.</param> /// <param name="dex">Index of line.</param> internal bool CompareArguments(MochaScriptComparisonMark mark, object arg1, object arg2, int dex) { try { if (mark == MochaScriptComparisonMark.Undefined) { throw Throw(dex + 1, "|| ComparisonMark failed, no such ComparisonMark!"); } if (mark == MochaScriptComparisonMark.Equal) { return(arg1.Equals(arg2)); } if (mark == MochaScriptComparisonMark.NotEqual) { return(!arg1.Equals(arg2)); } var a1 = (decimal)MochaData.GetDataFromString(MochaDataType.Decimal, arg1.ToString()); var a2 = (decimal)MochaData.GetDataFromString(MochaDataType.Decimal, arg2.ToString()); if (mark == MochaScriptComparisonMark.EqualBigger) { return(a1 >= a2); } if (mark == MochaScriptComparisonMark.EqualSmaller) { return(a1 <= a2); } if (mark == MochaScriptComparisonMark.Bigger) { return(a1 > a2); } else { return(a1 < a2); } } catch { return(false); } }
/// <summary> /// Runs the active MochaQ query. Even if there is an incoming value, it will not return. /// </summary> public void Run() { if (!MochaQ.IsRunQuery()) { throw new MochaException(@"This MochaQ command is not ""Run"" type command."); } Database.OnConnectionCheckRequired(this, new EventArgs()); if (Database.Provider.Readonly) { throw new MochaException("This connection is can read only, cannot task of write!"); } //Check null. if (string.IsNullOrEmpty(MochaQ)) { throw new MochaException("This MochaQ query is empty, invalid!"); } //Check BREAKQUERY. if (MochaQ.Command.Contains("BREAKQUERY")) { return; } string[] queryPaths = MochaQ.Command.Split(':'); queryPaths[0] = queryPaths[0].ToUpperInvariant(); //File system. if (queryPaths[0].StartsWith("FILESYSTEM_")) { if (queryPaths.Length == 1) { if (queryPaths[0] == "FILESYSTEM_CLEARDISKS") { Database.FileSystem.ClearDisks(); return; } else { throw new MochaException("Invalid query. The content of the query could not be processed, wrong!"); } } else if (queryPaths.Length == 2) { if (queryPaths[0] == "FILESYSTEM_REMOVEDISK") { Database.FileSystem.RemoveDisk(queryPaths[1]); return; } else if (queryPaths[0] == "FILESYSTEM_REMOVEDIRECTORY") { Database.FileSystem.RemoveDirectory(queryPaths[1]); return; } else if (queryPaths[0] == "FILESYSTEM_REMOVEFILE") { Database.FileSystem.RemoveFile(queryPaths[1]); return; } else { throw new MochaException("Invalid query. The content of the query could not be processed, wrong!"); } } else if (queryPaths.Length == 3) { if (queryPaths[0] == "FILESYSTEM_CREATEDISK") { Database.FileSystem.CreateDisk(queryPaths[1], queryPaths[2]); return; } else if (queryPaths[0] == "FILESYSTEM_CREATEDIRECTORY") { Database.FileSystem.CreateDirectory(queryPaths[1], queryPaths[2]); return; } else { throw new MochaException("Invalid query. The content of the query could not be processed, wrong!"); } } else { throw new MochaException("Invalid query. The content of the query could not be processed, wrong!"); } } if (queryPaths.Length == 1) { if (queryPaths[0] == "RESETMOCHA") { Database.Reset(); return; } else if (queryPaths[0] == "RESETTABLES") { Database.OnChanging(this, new EventArgs()); IEnumerable <XElement> tableRange = Database.Doc.Root.Element("Tables").Elements(); for (int index = 0; index < tableRange.Count(); index++) { tableRange.ElementAt(index).Elements().Remove(); } Database.Save(); return; } else if (queryPaths[0] == "CLEARSECTORS") { Database.ClearSectors(); return; } else if (queryPaths[0] == "CLEARSTACKS") { Database.ClearStacks(); return; } else if (queryPaths[0] == "CLEARTABLES") { Database.ClearTables(); return; } else if (queryPaths[0] == "CLEARALL") { Database.ClearAll(); return; } else if (queryPaths[0] == "CLEARLOGS") { Database.ClearLogs(); return; } else if (queryPaths[0] == "RESTORETOFIRSTLOG") { Database.RestoreToFirstLog(); return; } else if (queryPaths[0] == "RESTORETOLASTLOG") { Database.RestoreToLastLog(); return; } else { throw new MochaException("Invalid query. The content of the query could not be processed, wrong!"); } } else if (queryPaths.Length == 2) { if (queryPaths[0] == "REMOVETABLE") { Database.RemoveTable(queryPaths[1]); return; } else if (queryPaths[0] == "CREATETABLE") { Database.CreateTable(queryPaths[1]); return; } else if (queryPaths[0] == "CREATESTACK") { Database.AddStack(new MochaStack(queryPaths[1])); return; } else if (queryPaths[0] == "REMOVESECTOR") { Database.RemoveSector(queryPaths[1]); return; } else if (queryPaths[0] == "REMOVESTACK") { Database.RemoveStack(queryPaths[1]); return; } else if (queryPaths[0] == "SETPASSWORD") { Database.SetPassword(queryPaths[1]); return; } else if (queryPaths[0] == "SETDESCRIPTION") { Database.SetDescription(queryPaths[1]); return; } else if (queryPaths[0] == "RESTORETOLOG") { Database.RestoreToLog(queryPaths[1]); return; } else if (queryPaths[0] == "CLEARROWS") { Database.ClearRows(queryPaths[1]); return; } else if (queryPaths[0] == "RESETTABLE") { if (!Database.ExistsTable(queryPaths[1])) { throw new MochaException("Table not found in this name!"); } Database.OnChanging(this, new EventArgs()); Database.Doc.Root.Element("Tables").Elements(queryPaths[1]).Elements().Remove(); Database.Save(); return; } else if (queryPaths[0] == "CREATEMOCHA") { MochaDatabase.CreateMochaDB(Path.Combine(queryPaths[1]) + ".bjay", string.Empty, string.Empty); return; } else { throw new MochaException("Invalid query. The content of the query could not be processed, wrong!"); } } else if (queryPaths.Length == 3) { if (queryPaths[0] == "REMOVECOLUMN") { Database.RemoveColumn(queryPaths[1], queryPaths[2]); return; } else if (queryPaths[0] == "REMOVETABLEATTRIBUTE") { Database.RemoveTableAttribute(queryPaths[1], queryPaths[2]); return; } else if (queryPaths[0] == "REMOVESTACKATTRIBUTE") { Database.RemoveStackAttribute(queryPaths[1], queryPaths[2]); return; } else if (queryPaths[0] == "REMOVESECTORATTRIBUTE") { Database.RemoveSectorAttribute(queryPaths[1], queryPaths[2]); return; } else if (queryPaths[0] == "SETSECTORDATA") { Database.SetSectorData(queryPaths[1], queryPaths[2]); return; } else if (queryPaths[0] == "SETSECTORDESCRIPTION") { Database.SetSectorDescription(queryPaths[1], queryPaths[2]); return; } else if (queryPaths[0] == "SETSTACKDESCRIPTION") { Database.SetStackDescription(queryPaths[1], queryPaths[2]); return; } else if (queryPaths[0] == "SETTABLEDESCRIPTION") { Database.SetTableDescription(queryPaths[1], queryPaths[2]); return; } else if (queryPaths[0] == "REMOVEROW") { Database.RemoveRow(queryPaths[1], int.Parse(queryPaths[2])); return; } else if (queryPaths[0] == "RENAMETABLE") { Database.RenameTable(queryPaths[1], queryPaths[2]); return; } else if (queryPaths[0] == "REMOVESTACKITEM") { Database.RemoveStackItem(queryPaths[1], queryPaths[2]); return; } else if (queryPaths[0] == "RENAMESECTOR") { Database.RenameSector(queryPaths[1], queryPaths[2]); return; } else if (queryPaths[0] == "RENAMESTACK") { Database.RenameStack(queryPaths[1], queryPaths[2]); return; } else if (queryPaths[0] == "CREATECOLUMN") { Database.CreateColumn(queryPaths[1], queryPaths[2]); return; } else if (queryPaths[0] == "CREATEMOCHA") { MochaDatabase.CreateMochaDB(Path.Combine(queryPaths[1] + queryPaths[2]) + ".bjay", string.Empty, string.Empty); return; } else { throw new MochaException("Invalid query. The content of the query could not be processed, wrong!"); } } else if (queryPaths.Length == 4) { if (queryPaths[0] == "RENAMECOLUMN") { Database.RenameColumn(queryPaths[1], queryPaths[2], queryPaths[3]); return; } else if (queryPaths[0] == "REMOVECOLUMNATTRIBUTE") { Database.RemoveColumnAttribute(queryPaths[1], queryPaths[2], queryPaths[3]); return; } else if (queryPaths[0] == "REMOVESTACKITEMATTRIBUTE") { Database.RemoveStackItemAttribute(queryPaths[1], queryPaths[2], queryPaths[3]); return; } else if (queryPaths[0] == "SETCOLUMNDESCRIPTION") { Database.SetColumnDescription(queryPaths[1], queryPaths[2], queryPaths[3]); return; } else if (queryPaths[0] == "SETCOLUMNDATATYPE") { Database.SetColumnDataType(queryPaths[1], queryPaths[2], MochaData.GetDataTypeFromName(queryPaths[3])); return; } else if (queryPaths[0] == "ADDDATA") { Console.WriteLine((queryPaths[3] != "") + "||'" + queryPaths[3] + "'"); if (queryPaths[3] != "") { Database.AddData(queryPaths[1], queryPaths[2], MochaData.GetDataFromString( Database.GetColumnDataType(queryPaths[1], queryPaths[2]) , queryPaths[3])); } else { Database.AddData(queryPaths[1], queryPaths[2], null); } return; } else if (queryPaths[0] == "CREATESTACKITEM") { Database.AddStackItem(queryPaths[1], queryPaths[3], new MochaStackItem(queryPaths[2])); return; } else if (queryPaths[0] == "RENAMESTACKITEM") { Database.RenameStackItem(queryPaths[1], queryPaths[2], queryPaths[3]); return; } else if (queryPaths[0] == "SETSTACKITEMVALUE") { Database.SetStackItemValue(queryPaths[1], queryPaths[2], queryPaths[3]); return; } else if (queryPaths[0] == "SETSTACKITEMDESCRIPTION") { Database.SetStackItemDescription(queryPaths[1], queryPaths[2], queryPaths[3]); return; } else if (queryPaths[0] == "UPDATEFIRSTDATA") { Database.UpdateFirstData(queryPaths[1], queryPaths[2], queryPaths[3]); return; } else if (queryPaths[0] == "UPDATELASTDATA") { Database.UpdateLastData(queryPaths[1], queryPaths[2], queryPaths[3]); return; } else if (queryPaths[0] == "ADDSECTOR") { MochaSector Sector = new MochaSector(queryPaths[1], queryPaths[2], queryPaths[3]); Database.AddSector(Sector); return; } else { throw new MochaException("Invalid query. The content of the query could not be processed, wrong!"); } } else if (queryPaths.Length == 5) { if (queryPaths[0] == "UPDATEDATA") { Database.UpdateData(queryPaths[1], queryPaths[2], int.Parse(queryPaths[3]), queryPaths[4]); return; } else { throw new MochaException("Invalid query. The content of the query could not be processed, wrong!"); } } }