From 7154fdd7655361a3cc87478b380c28692a219fb6 Mon Sep 17 00:00:00 2001 From: w4rgo Date: Thu, 27 Nov 2014 00:39:16 +0000 Subject: [PATCH] Added Arma2NETMySQLAsync command to run async procedures. --- Arma2NETMySQLPlugin/Arma2NETMySQLPlugin.cs | 55 ++++++++++++++++++++++ 1 file changed, 55 insertions(+) diff --git a/Arma2NETMySQLPlugin/Arma2NETMySQLPlugin.cs b/Arma2NETMySQLPlugin/Arma2NETMySQLPlugin.cs index e8021b6..8a7e056 100644 --- a/Arma2NETMySQLPlugin/Arma2NETMySQLPlugin.cs +++ b/Arma2NETMySQLPlugin/Arma2NETMySQLPlugin.cs @@ -80,6 +80,61 @@ public override void Unload() } } + [AddIn("Arma2NetMySQLAsync", Version = "0.1.0.0", Publisher = "firefly2442", Description = "Runs MySQL procedure commands asyncronously.")] + public class Arma2NETMySQLPluginAsync : AsyncAddIn + { + //This method is called when callExtension is used from SQF: + //"Arma2Net.Unmanaged" callExtension "Arma2NetMySQLAsync ..." + public override string InvokeAsync(string args, int maxResultSize, CancellationToken token) + { + //if we haven't setup the database connection and such yet, this will do it + Startup.StartupConnection(); + + IList arguments; + if (Format.TrySqfAsCollection(args, out arguments) && arguments.Count >= 2 && arguments[0] != null && arguments[1] != null) + { + string database = arguments[0] as string; + string procedure = arguments[1] as string; + string parameters = arguments[2] as string; + //strip out [] characters at the beginning and end + if (parameters[0].ToString() == "[" && parameters[parameters.Length - 1].ToString() == "]") + { + parameters = parameters.Substring(1, parameters.Length - 2); + } + List split = new List(); + if (parameters != null) + { + split = parameters.Split(',').ToList(); + } + + Logger.addMessage(Logger.LogType.Info, "Received - Database: " + database + " Procedure: " + procedure + " Parameters: " + parameters.ToString()); + + if (SQL.dbs.SQLProviderExists(database)) + { + IEnumerable returned = SQL.dbs.getSQLProvider(database).RunProcedure(procedure, split.ToArray(), maxResultSize); + return Format.ObjectAsSqf(returned); + } + else + { + Logger.addMessage(Logger.LogType.Warning, "The database: " + database + " is not loaded in through the Databases.txt file."); + } + + //Logger.addMessage(Logger.LogType.Info, "Returning false object"); + return Format.ObjectAsSqf(false); + } + else + { + Logger.addMessage(Logger.LogType.Error, "The number and/or format of the arguments passed in doesn't match."); + throw new ArgumentException(); + } + } + + public override void Unload() + { + Startup.Unload(); + } + } + //the function name for the plugin (called from Arma side) [AddIn("Arma2NETMySQLCommand", Version = "0.1.0.0", Publisher = "firefly2442", Description = "Runs raw MySQL/SQLite commands")] public class Arma2NETMySQLPluginCommand : AddIn