Example #1
0
        /// <summary>
        /// Retrieves one or more servers in the current subscription.
        /// </summary>
        /// <param name="serverName">
        /// The specific name of the server to retrieve, or <c>null</c> to
        /// retrieve all servers in the current subscription.
        /// </param>
        /// <returns>A list of servers in the subscription.</returns>
        internal IEnumerable <SqlDatabaseServerContext> GetAzureSqlDatabaseServersProcess(string serverName)
        {
            IEnumerable <SqlDatabaseServerContext> processResult = null;

            try
            {
                InvokeInOperationContext(() =>
                {
                    SqlDatabaseServerList servers = RetryCall(subscription =>
                                                              Channel.GetServers(subscription));
                    Operation operation = WaitForSqlDatabaseOperation();

                    if (string.IsNullOrEmpty(serverName))
                    {
                        // Server name is not specified, return all servers
                        // in the subscription.
                        processResult = servers.Select(server => new SqlDatabaseServerContext
                        {
                            ServerName           = server.Name,
                            Location             = server.Location,
                            AdministratorLogin   = server.AdministratorLogin,
                            OperationStatus      = operation.Status,
                            OperationDescription = CommandRuntime.ToString(),
                            OperationId          = operation.OperationTrackingId
                        });
                    }
                    else
                    {
                        // Server name is specified, find the one with the
                        // specified rule name and return that.
                        SqlDatabaseServer server = servers.FirstOrDefault(s => s.Name == serverName);
                        if (server != null)
                        {
                            processResult = new List <SqlDatabaseServerContext>
                            {
                                new SqlDatabaseServerContext
                                {
                                    ServerName           = server.Name,
                                    Location             = server.Location,
                                    AdministratorLogin   = server.AdministratorLogin,
                                    OperationStatus      = operation.Status,
                                    OperationDescription = CommandRuntime.ToString(),
                                    OperationId          = operation.OperationTrackingId
                                }
                            };
                        }
                        else
                        {
                            throw new ItemNotFoundException(string.Format(CultureInfo.InvariantCulture, Resources.GetAzureSqlDatabaseServerNotFound, serverName));
                        }
                    }
                });
            }
            catch (CommunicationException ex)
            {
                this.WriteErrorDetails(ex);
            }

            return(processResult);
        }
Example #2
0
        /// <summary>
        /// Initialize the gaming server environment.
        /// </summary>
        public static void Initialize()
        {
            Program.Logger.WriteInfo("Initializing a new gaming environment...");
            try
            {
                try
                {
                    // Load "general" settings from runescape.ini.
                    Configuration = Configuration.Load(@"..\data\runescape.ini");
                }
                catch (Exception) // Most likely error in config file or no file found.
                {
                    throw;
                }

                // Initialize the database server.
                SqlDatabaseServer databaseServer = new SqlDatabaseServer(
                    Configuration["Master.Database.Host"],
                    Configuration["Master.Database.Port"],
                    Configuration["Master.Database.User"],
                    Configuration["Master.Database.Pass"]);

                // Initialize a database from the database server.
                SqlDatabase database = new SqlDatabase(
                    Configuration["Master.Database.Name"],
                    Configuration["Master.Database.MinPoolSize"],
                    Configuration["Master.Database.MaxPoolSize"]);

                //  Initialize the database manager and test connection.
                databaseManager = new SqlDatabaseManager(database, databaseServer);
                databaseManager.SetClientAmount(10);
                databaseManager.ReleaseClient(databaseManager.GetClient().Handle);
                databaseManager.StartMonitor();

                // Initialize the tcp connection manager and start listening.
                connectionManager = new ConnectionManager(
                    Configuration["TcpConnection.LocalIP"],
                    Configuration["TcpConnection.Port"],
                    Configuration["TcpConnection.MaxConnections"]);

                // Start the connection manager's core listener with user-specified logging/checking.
                connectionManager.Listener.Start(Configuration["TcpConnection.CheckBlacklist"]);

                // Initialize the remote connection manager and start listening.
                remoteManager = new RemoteManager(
                    Configuration["RemoteConnection.LocalIP"],
                    Configuration["RemoteConnection.Port"]);
                remoteManager.Listener.Start(false);

                // Initialize the scripting manager.
                scriptManager = new ScriptManager();
                scriptManager.Initialize();

                // Check to make sure database verion is valid.
                if (!(bool)Database.Execute(new DatabaseVersionCheck()))
                {
                    throw new Exception("The jolt database you are using, is outdated.");
                }

                /*
                 *  Engine is now able to run cause the connections have been initialized
                 *  with no errors (yet!), so we will initialize the game engine.
                 */
                IsRunning = true;

                // Initilize the game engine.
                GameEngine.Initialize();

                Program.Logger.WriteInfo("Initialized a new runescape gaming environment.");
            }
            catch (Exception ex)
            {
                Program.Logger.WriteException(ex);
                Program.Logger.WriteError("Could not set up server correctly."
                                          + "\nPlease referr to the error message above. Shutting down...");
                Thread.Sleep(5000);
                Environment.Exit(0);
                Terminate(false);
            }
        }