Arma2NETMySQLPlugin.Startup.StartupConnection C# (CSharp) Method

StartupConnection() public static method

public static StartupConnection ( ) : void
return void
        public static void StartupConnection()
        {
            if (started_up == false)
            {
                //create appdata folder if it doesn't already exist
                var appDataLocation = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "Arma2NETMySQL");
                //check to see if the Arma2NETMySQL folder exists, if not create it
                if (!System.IO.Directory.Exists(appDataLocation)) {
                    System.IO.Directory.CreateDirectory(appDataLocation);
                }

                //Start up logging
                logger_object = new Logger();
                Logger.addMessage(Logger.LogType.Info, "Logging started in directory: " + Logger.getLogDir());

                Logger.addMessage(Logger.LogType.Info, "Arma2NETMySQL Plugin Started.");

                //Use AssemblyInfo.cs version number
                //Holy cow this is confusing...
                //http://stackoverflow.com/questions/909555/how-can-i-get-the-assembly-file-version
                //http://all-things-pure.blogspot.com/2009/09/assembly-version-file-version-product.html
                //http://stackoverflow.com/questions/64602/what-are-differences-between-assemblyversion-assemblyfileversion-and-assemblyin
                Logger.addMessage(Logger.LogType.Info, "Version number: " + System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString());

                //Utils.FileVersion returns the current version that is running
                //Utils.Version returns the API version, when this changes, all plugins need to be recompiled
                //This version call doesn't always seem to play nicely (it causes errors where it can't find the managed.dll)
                //Logger.addMessage(Logger.LogType.Info, "Compiled against Arma2NET Version: " + Utils.FileVersion);

                //Load in Databases.txt file
                //This also sets up the SQLProvider associated with the database
                Logger.addMessage(Logger.LogType.Info, "Loading databases...");
                SQL.dbs = new Databases();

                //set mutex so we know we've started everything up
                started_up = true;
            }
        }

Usage Example

Beispiel #1
0
        //This method is called when callExtension is used from SQF:
        //"Arma2Net.Unmanaged" callExtension "Arma2NetMySQLCommand ..."
        public override string Invoke(string args, int maxResultSize)
        {
            //if we haven't setup the database connection and such yet, this will do it
            Startup.StartupConnection();

            IList <object> arguments;

            if (Format.TrySqfAsCollection(args, out arguments) && arguments.Count == 2 && arguments[0] != null && arguments[1] != null)
            {
                string database      = arguments[0] as string;
                string mysql_command = arguments[1] as string;

                Logger.addMessage(Logger.LogType.Info, "Received - Database: " + database + " SQL Query: " + mysql_command.ToString());

                if (SQL.dbs.SQLProviderExists(database))
                {
                    IEnumerable <string[][]> returned = SQL.dbs.getSQLProvider(database).RunCommand(mysql_command, 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();
            }
        }
All Usage Examples Of Arma2NETMySQLPlugin.Startup::StartupConnection