예제 #1
0
        // Adds an incoming connection to the queue
        private void Listen(IAsyncResult Result)
        {
            // Check if server is bound
            if (Listener.Server.IsBound)
            {
                try
                {
                    // Get incoming connection
                    var Connection = Listener.EndAcceptTcpClient(Result);

                    // Lock our connection queue to prevent any race conditions
                    lock (ConnectionQueue)
                    {
                        // Add the incoming connection to our connection queue
                        ConnectionQueue.Enqueue(Connection);

                        // Signal that a connection is ready to be accepted
                        ReadyEvent.Set();
                    }

                    // Start listening again
                    Listener.BeginAcceptTcpClient(Listen, null);
                }
                catch { }
            }
        }
예제 #2
0
        // Listens for new requests and enqueues them
        private void Listen()
        {
            while (Listener.IsListening)
            {
                // Accept new connection context
                var Context = Listener.BeginGetContext((IAsyncResult Result) =>
                {
                    try
                    {
                        // Lock our context queue to prevent race conditions
                        lock (ContextQueue)
                        {
                            // Add new connection context to our context queue
                            ContextQueue.Enqueue(Listener.EndGetContext(Result));

                            // Signal that a context is ready to be accepted
                            ReadyEvent.Set();
                        }
                    }
                    catch { }
                }, null);

                // Wait for exit
                if (WaitHandle.WaitAny(new[] { StopEvent, Context.AsyncWaitHandle }) == 0)
                {
                    return;
                }
            }
        }
예제 #3
0
        /// <summary>
        /// Initialize the GPU emulation context.
        /// </summary>
        /// <param name="logLevel">The log level required.</param>
        public void Initialize(GraphicsDebugLevel logLevel)
        {
            HostInitalized.WaitOne();

            Renderer.Initialize(logLevel);
            Methods.ShaderCache.Initialize();
            ReadyEvent.Set();
        }
예제 #4
0
        // Non-queries the database manually
        public void NonQuery(string Data)
        {
            // Create SQL command
            var Command = new SqliteCommand(Data, Connection);

            // Add data to our write queue
            WriteQueue.Enqueue(Command);
            ReadyEvent.Set();
        }
예제 #5
0
 // Adds an outgoing message to our queue
 internal void SendMessage(byte[] Data)
 {
     // Lock message queue to prevent race conditions
     lock (OutgoingMessageQueue)
     {
         // Add data to outgoing message queue
         OutgoingMessageQueue.Enqueue(Data);
         ReadyEvent.Set();
     }
 }
예제 #6
0
        // Creates a table if it does not exist
        // TODO - add table versions to update existing tables
        public void CreateTable(string TableName, ValueList Values)
        {
            // Check for bad values
            if (string.IsNullOrEmpty(TableName))
            {
                throw new ArgumentException("Table name cannot be empty");
            }
            if (Values == null || Values.Count == 0)
            {
                throw new ArgumentException("Supplied value list was null or empty");
            }

            // Create values string
            StringBuilder Data = new StringBuilder($"CREATE TABLE IF NOT EXISTS {TableName} (");

            for (int i = 0; i < Values.Count; i++)
            {
                if (i > 0)
                {
                    Data.Append(", ");
                }

                var Entry = Values[i];
                Data.Append($"{Entry.Name}");
                if (!Entry.Primary)
                {
                    Data.Append($" {Entry.Type}");
                    if (Entry.Size > 0)
                    {
                        Data.Append($"({Entry.Size})");
                    }
                    if (Entry.Unique)
                    {
                        Data.Append(" UNIQUE");
                    }
                    if (Entry.Value != null)
                    {
                        Data.Append($" DEFAULT '{Entry.Value}'");
                    }
                }
                else
                {
                    Data.Append(" INTEGER PRIMARY KEY");
                }
            }
            Data.Append(")");

            // Create SQL command
            var Command = new SqliteCommand(Data.ToString(), Connection);

            // Add data to our write queue
            WriteQueue.Enqueue(Command);
            ReadyEvent.Set();
        }
예제 #7
0
파일: Peer.cs 프로젝트: fexra/CantiLib
        // Adds a byte array to our packet reading buffer
        internal void AddData(byte[] Data)
        {
            // Lock our incoming data queue to prevent race conditions
            lock (IncomingBufferQueue)
            {
                // Add the incoming data to our queue
                IncomingBufferQueue.Enqueue(Data);

                // Signal a ready event
                ReadyEvent.Set();
            }
        }
예제 #8
0
        public void CreateTable(string TableName, ValueList Values)
        {
            // Check for bad values
            if (string.IsNullOrEmpty(TableName))
            {
                throw new ArgumentException("Table name cannot be empty");
            }
            if (Values == null || Values.Count == 0)
            {
                throw new ArgumentException("Supplied value list was null or empty");
            }

            // Create values string
            string CommandString = "";

            for (int i = 0; i < Values.Count; i++)
            {
                if (i > 0)
                {
                    CommandString += ", ";
                }

                var Entry = Values[i];
                CommandString += $"{Entry.Name} {Entry.Type}";
                if (Entry.Size > 0)
                {
                    CommandString += $"({Entry.Size})";
                }
                if (Entry.Unique)
                {
                    CommandString += " UNIQUE";
                }
                if (Entry.Value != null)
                {
                    CommandString += $" DEFAULT '{Entry.Value.Value}'";
                }
            }

            // Create SQL command
            var Command = new SqliteCommand($"CREATE TABLE IF NOT EXISTS {TableName} ({CommandString})", Connection);

            // Add data to our write queue
            WriteQueue.Enqueue(Command);
            ReadyEvent.Set();
        }
예제 #9
0
        // Adds a log message to the message queue
        private void AddMessage(LogLabel Label, object Input, params object[] Params)
        {
            // Lock the message queue to prevent race conditions
            lock (MessageQueue)
            {
                // Add to message queue
                MessageQueue.Enqueue(new LogMessage
                {
                    Prefix    = ShowPrefix,
                    Label     = Label,
                    Timestamp = DateTime.Now,
                    Message   = string.Format($"{Input}", Params)
                });

                // Signal ready event
                ReadyEvent.Set();
            }
        }
예제 #10
0
        // Adds a row to the database
        public void Add(string TableName, ValueList Values)
        {
            // Check for bad values
            if (string.IsNullOrEmpty(TableName))
            {
                return;
            }
            if (Values == null || Values.Count == 0)
            {
                return;
            }

            // Begin constructing an SQL command
            StringBuilder Data = new StringBuilder($"INSERT INTO {TableName} (");

            // Loop through the given values
            StringBuilder ValueList = new StringBuilder();

            for (int i = 0; i < Values.Count; i++)
            {
                // Add name to command string
                if (i > 0)
                {
                    Data.Append(", ");
                    ValueList.Append(", ");
                }
                Data.Append($"{Values[i].Name}");
                ValueList.Append($"@{Values[i].Name}_1");
            }
            Data.Append($") VALUES ({ValueList})");

            // Create SQL command
            var Command = new SqliteCommand(Data.ToString(), Connection);

            // Add values from the value list
            foreach (var Value in Values)
            {
                Command.Parameters.AddWithValue($"{Value.Name}_1", Value.Value);
            }

            // Add data to our write queue
            WriteQueue.Enqueue(Command);
            ReadyEvent.Set();
        }
예제 #11
0
        // Updates a row in the database
        public void Update(string TableName, ValueList Values, ValueList Conditions)
        {
            // Check for bad values
            if (string.IsNullOrEmpty(TableName))
            {
                return;
            }
            if (Values == null || Values.Count == 0)
            {
                return;
            }
            if (Conditions == null || Conditions.Count == 0)
            {
                return;
            }

            // Begin constructing an SQL command
            StringBuilder Data = new StringBuilder($"UPDATE {TableName} SET ");

            // Loop through the given values
            for (int i = 0; i < Values.Count; i++)
            {
                // Add name to command string
                if (i > 0)
                {
                    Data.Append(", ");
                }
                Data.Append($"{Values[i].Name} = @{Values[i].Name}_1");
            }

            // Add conditions
            Data.Append(" WHERE ");
            for (int i = 0; i < Conditions.Count; i++)
            {
                // Add name to command string
                if (i > 0)
                {
                    Data.Append(" AND ");
                }
                Data.Append($"{Conditions[i].Name} = @{Conditions[i].Name}_2");
            }

            // Create SQL command
            var Command = new SqliteCommand(Data.ToString(), Connection);

            // Add values from the value list
            foreach (var Value in Values)
            {
                Command.Parameters.AddWithValue($"{Value.Name}_1", Value.Value);
            }

            // Add conditions from the conditions list
            foreach (var Condition in Conditions)
            {
                Command.Parameters.AddWithValue($"{Condition.Name}_2", Condition.Value);
            }

            // Add data to our write queue
            WriteQueue.Enqueue(Command);
            ReadyEvent.Set();
        }