Esempio n. 1
0
        public void Run(int threadCount)
        {
            DatabasePool databasePool = new DatabasePool(threadCount);

            databasePool.Connect();
            QuerySetPool queryPool = new QuerySetPool(databasePool);

            if (!queryPool.ReadFromFile("query.txt"))
            {
                return;
            }

            // create instances of test classes
            ThreadTest[] threadTests = new ThreadTest[threadCount];
            for (int i = 0; i < threadCount; i++)
            {
                threadTests[i] = new ThreadTest(i, queryPool.GetQuerySet(i), queryPool);
            }

            // create instances of Thread class
            Thread[] threads = new Thread[threadCount];
            for (int i = 0; i < threadCount; i++)
            {
                threads[i] = new Thread(threadTests[i].Run);
            }


            Stopwatch sw = new Stopwatch();

            sw.Start();

            // start all test threads
            for (int i = 0; i < threadCount; i++)
            {
                threads[i].Start();
            }

            // Spin for a while waiting for the started thread to become alive:
            for (int i = 0; i < threadCount; i++)
            {
                while (!threads[i].IsAlive)
                {
                    ;
                }
            }

            // Wait until oThread finishes. Join also has overloads
            // that take a millisecond interval or a TimeSpan object.
            for (int i = 0; i < threadCount; i++)
            {
                threads[i].Join();
            }

            string executionTimeTaken = string.Format("\nTime: {0}s\n", sw.Elapsed.TotalMilliseconds / 1000);

            Console.WriteLine(executionTimeTaken);
            databasePool.Close();

            Console.WriteLine("Done.");
        }
Esempio n. 2
0
        internal static Connection ReleaseConnection(string alias)
        {
            lock (_syncRoot)
            {
                Connection connection = null;

                if (_databasePools.Exists(db => db.Alias == alias))
                {
                    DatabasePool pool = _databasePools.Find(db => db.Alias == alias);

                    if (pool != null)
                    {
                        // deque free database connection if the pool has one
                        if (pool.CurrentSize > 0)
                        {
                            connection = pool.DequeueConnection();
                        }
                        // if the pool is empty - create new dedicated database connection
                        else if (pool.CurrentSize == 0)
                        {
                            connection = new Connection(pool.Hostname, pool.Port, pool.DatabaseName, pool.DatabaseType, pool.UserName, pool.UserPassword, alias, true);
                        }
                    }
                }

                return(connection);
            }
        }
Esempio n. 3
0
        public static void CreateDatabasePool(string hostname, int port, string databaseName, ODatabaseType databaseType, string userName, string userPassword, int poolSize, string alias)
        {
            lock (_syncRoot)
            {
                DatabasePool databasePool = new DatabasePool(hostname, port, databaseName, databaseType, userName, userPassword, poolSize, alias);

                _databasePools.Add(databasePool);
            }
        }
Esempio n. 4
0
        public static int DatabasePoolCurrentSize(string alias)
        {
            if (_databasePools.Exists(db => db.Alias == alias))
            {
                DatabasePool pool = _databasePools.Find(db => db.Alias == alias);

                return(pool.CurrentSize);
            }

            return(-1);
        }
Esempio n. 5
0
        public static string CreateDatabasePool(string hostname, int port, string databaseName, ODatabaseType databaseType, string userName, string userPassword, int poolSize, string alias, string clientID = "null")
        {
            OClient.ClientID = clientID;

            lock (_syncRoot)
            {
                DatabasePool databasePool = new DatabasePool(hostname, port, databaseName, databaseType, userName, userPassword, poolSize, alias);

                _databasePools.Add(databasePool);
                return(databasePool.Release);
            }
        }
Esempio n. 6
0
        /// <summary>
        /// Returns the default insert artefact engine for <typeparamref name="T"/>
        /// </summary>
        /// <param name="connectionStringSettings">
        /// The connection string settings.
        /// </param>
        /// <typeparam name="T">
        /// The <see cref="IMaintainableObject"/> based type.
        /// </typeparam>
        /// <returns>
        /// The <see cref="IImportEngine{T}"/>.
        /// </returns>
        public static IImportEngine <T> GetArtefactEngine <T>(ConnectionStringSettings connectionStringSettings) where T : IMaintainableObject
        {
            Func <Database, object> engine;

            if (_artefactEngines.TryGetValue(typeof(T), out engine))
            {
                var database = DatabasePool.GetDatabase(connectionStringSettings);
                return(engine(database) as IImportEngine <T>);
            }

            return(null);
        }
Esempio n. 7
0
        public static void DropDatabasePool(string alias)
        {
            lock (_syncRoot)
            {
                if (_databasePools.Exists(db => db.Alias == alias))
                {
                    DatabasePool pool = _databasePools.Find(db => db.Alias == alias);

                    pool.DropConnections();

                    _databasePools.Remove(pool);
                }
            }
        }
Esempio n. 8
0
        public QuerySetPool(DatabasePool databasePool)
        {
            mDatabasePool = databasePool;
            mTableObjects = new DbTable[databasePool.Count()];
            mQuerySets    = new QuerySet[databasePool.Count()];
            for (int i = 0; i < databasePool.Count(); i++)
            {
                mQuerySets[i] = new QuerySet(databasePool.GetDatabase(i));
            }

            mQueryMethods        = new Collection <MethodInfo>();
            mMethodParameters    = new Collection <Type[]>();
            mQueryNumbers        = new Collection <int>();
            mQueryMaximalNumbers = new Collection <int>();
        }
Esempio n. 9
0
        /// <summary>
        /// Initializes a new instance of the <see cref="MappingStoreManager"/> class.
        /// </summary>
        /// <param name="connectionStringSettings">
        /// The connection string settings.
        /// </param>
        /// <param name="factories">
        /// The factories.
        /// </param>
        /// <param name="artefactImportStatuses">
        /// The artefact import statuses.
        /// </param>
        /// <exception cref="ArgumentNullException">
        /// <paramref name="connectionStringSettings"/> is null
        /// -or-
        /// <paramref name="artefactImportStatuses"/> is null
        /// </exception>
        public MappingStoreManager(ConnectionStringSettings connectionStringSettings, IEngineFactories factories, IList <ArtefactImportStatus> artefactImportStatuses)
        {
            if (connectionStringSettings == null)
            {
                throw new ArgumentNullException("connectionStringSettings");
            }

            if (artefactImportStatuses == null)
            {
                throw new ArgumentNullException("artefactImportStatuses");
            }

            this._connectionStringSettings = connectionStringSettings;
            this._artefactImportStatuses   = artefactImportStatuses;
            this._factories = factories ?? new EngineFactories();
            Database database = DatabasePool.GetDatabase(connectionStringSettings);

            this._measureDimensionRepresentationEngine = new MeasureDimensionRepresentationEngine(database);
        }
Esempio n. 10
0
        public async Task TestUnusualUris()
        {
            DatabasePool.Initialise(1);

            var uri = new Uri("https://en.wikipedia.org/w/index.php?title=Talk:Event_Horizon_Telescope&action=edit");

            Assert.IsTrue(await VerifyUrlIsBlocked(uri), uri.ToString());

            uri = new Uri("http://omim.org/contact");
            Assert.IsTrue(await VerifyUrlIsBlocked(uri), uri.ToString());

            uri = new Uri("https://www.wikipedia.org/wiki/Burger");
            Assert.IsTrue(!await VerifyUrlIsBlocked(uri), uri.ToString());

            uri = new Uri("https://www.bbc.com/news/world-asia-40360168");
            Assert.IsTrue(!await VerifyUrlIsBlocked(uri), uri.ToString());

            uri = new Uri("https://wiki.dolphin-emu.org/index.php?title=Category:Japan_(Release_region)");
            Assert.IsTrue(!await VerifyUrlIsBlocked(uri), uri.ToString());
        }
Esempio n. 11
0
        internal static void ReturnConnection(Connection connection)
        {
            lock (_syncRoot)
            {
                DatabasePool pool = _databasePools.Find(q => q.Alias == connection.Alias);

                // enqueue the connection back if it's active, reusable and the pool size is not full
                // otherwise dispose it
                if ((pool != null) &&
                    (pool.CurrentSize < pool.PoolSize) &&
                    connection.IsActive &&
                    connection.IsReusable)
                {
                    pool.EnqueueConnection(connection);
                }
                else
                {
                    connection.Dispose();
                }
            }
        }
Esempio n. 12
0
 /// <summary>
 /// Initializes a new instance of the <see cref="TextFormatTypesQueryEngine"/> class.
 /// </summary>
 /// <param name="connectionStringSettings">
 /// The connection string settings.
 /// </param>
 public TextFormatTypesQueryEngine(ConnectionStringSettings connectionStringSettings)
     : this(DatabasePool.GetDatabase(connectionStringSettings))
 {
 }
 public GameMetaDataRepository()
 {
     _databasePool = DatabasePool.GetInstance();
 }
 public GuessingSpeedRepository()
 {
     _databasePool = DatabasePool.GetInstance();
 }
Esempio n. 15
0
        public static async Task Main(string[] args)
        {
            if (args.Length < 2)
            {
                Usage();
                return;
            }

            string paths = args[0];

            int.TryParse(args[1], out int startPacketIndex);

            // turn on log4net
            log4net.Config.XmlConfigurator.Configure();

            // catch all errors and log them
            AppDomain.CurrentDomain.UnhandledException += (sender, eventArgs) => Utility.LogException(eventArgs.ExceptionObject as Exception);

            // ignore all certificate validation issues
            ServicePointManager.ServerCertificateValidationCallback = (sender, cert, chain, sslPolicyErrors) => true;

            // console encoding will now be unicode
            Console.OutputEncoding = System.Text.Encoding.UTF8;

            // database init
            DatabasePool.Initialise();

            // configure fetcho
            await SetupConfiguration(paths);

            // upgrade the database
            DatabaseUpgrader.Upgrade();

            // buffers to connect the seperate tasks together
            BufferBlock <IEnumerable <QueueItem> > prioritisationBuffer = CreateBufferBlock(DefaultBufferBlockLimit);
            // really beef this buffers max size up since it takes for ever accumulate so we dont want to lose any
            BufferBlock <IEnumerable <QueueItem> > fetchQueueBuffer = CreateBufferBlock(DefaultBufferBlockLimit * 1000);
            //BufferBlock<IEnumerable<QueueItem>> requeueBuffer = CreateBufferBlock(DefaultBufferBlockLimit);
            ITargetBlock <IEnumerable <QueueItem> > outboxWriter   = CreateOutboxWriter();
            BufferBlock <IWebResourceWriter>        dataWriterPool = CreateDataWriterPool();

            // fetcho!
            var readLinko = new ReadLinko(prioritisationBuffer, startPacketIndex);
            var queueo    = new Queueo(prioritisationBuffer, fetchQueueBuffer, outboxWriter); // DataflowBlock.NullTarget<IEnumerable<QueueItem>>()
            var fetcho    = new Fetcho(fetchQueueBuffer, DataflowBlock.NullTarget <IEnumerable <QueueItem> >(), dataWriterPool);
            var stato     = new Stato("stats.csv", fetcho, queueo, readLinko);
            var controlo  = new Controlo(prioritisationBuffer, fetchQueueBuffer, dataWriterPool, () =>
            {
                readLinko.Shutdown();
                queueo.Shutdown();
                fetcho.Shutdown();
                stato.Shutdown();
            });
            //var requeueWriter = new BufferBlockObjectFileWriter<IEnumerable<QueueItem>>(cfg.DataSourcePath, "requeue", requeueBuffer);
            //var rejectsWriter = new BufferBlockObjectFileWriter<IEnumerable<QueueItem>>(cfg.DataSourcePath, "rejects", new NullTarget);

            // execute
            var tasks = new List <Task>();

            tasks.Add(stato.Process());
            tasks.Add(fetcho.Process());
            await Task.Delay(1000);

            tasks.Add(queueo.Process());
            await Task.Delay(1000);

            tasks.Add(readLinko.Process());
            tasks.Add(controlo.Process());

            await Task.WhenAll(tasks.ToArray()).ConfigureAwait(false);

            CloseAllWriters(dataWriterPool);
            DatabasePool.DestroyAll();
        }
Esempio n. 16
0
 public AmountOfGuessesRepository(IMetaDataCalculator iMetaDataCalculator)
 {
     _databasePool       = DatabasePool.GetInstance();
     _metaDataCalculator = iMetaDataCalculator;
 }
Esempio n. 17
0
        /// <summary>
        /// Create a <see cref="DbTransactionState"/>
        /// </summary>
        /// <param name="connectionStringSettings">
        /// The connection string settings.
        /// </param>
        /// <returns>
        /// The <see cref="DbTransactionState"/>.
        /// </returns>
        public static DbTransactionState Create(ConnectionStringSettings connectionStringSettings)
        {
            var database = DatabasePool.GetDatabase(connectionStringSettings);

            return(Create(database));
        }