Esempio n. 1
0
        /// <summary>
        /// Analyze the schema.
        /// </summary>
        /// <param name="sherlock">The sherlock.</param>
        /// <param name="logger">The logger.</param>
        /// <param name="source">The source.</param>
        /// <param name="sourceConnection">The source connection.</param>
        /// <param name="batch">The batch.</param>
        private static async Task AnalyzeSchemaAsync(Sherlock sherlock, ILogger logger, IMappingSource source, IConnection sourceConnection, SQLHelper batch)
        {
            if (!source.ApplyAnalysis &&
                !source.GenerateAnalysis)
            {
                return;
            }

            logger.Information("Analyzing {Info:l} for suggestions.", sourceConnection.DatabaseName);
            var Results = await sherlock.AnalyzeAsync(sourceConnection).ConfigureAwait(false);

            batch.CreateBatch();
            foreach (var Result in Results)
            {
                logger.Information("Finding: {Info:l}", Result.Text);
                logger.Information("Metrics: {Data:l}", Result.Metrics);
                logger.Information("Suggested Fix: {Fix:l}", Result.Fix);
                if (source.ApplyAnalysis && string.IsNullOrEmpty(Result.Fix))
                {
                    batch.AddQuery(CommandType.Text, Result.Fix);
                }
            }
            if (source.ApplyAnalysis)
            {
                logger.Information("Applying fixes for {Info:l}.", sourceConnection.DatabaseName);
                await batch.ExecuteScalarAsync <int>().ConfigureAwait(false);
            }
        }
Esempio n. 2
0
        /**
         * summary: Gets everything needed to start the game prepared. Takes the needed values from the SP file, creates the objects needed
         * to run and display the game, then create <see cref="PlayerActivity"/>
         */
        public void StartGame()
        {
            var settingsFile = gameContext.GetSharedPreferences(Consts.settingsFileName, FileCreationMode.Private);
            int digitsCount  = settingsFile.GetInt(Consts.numberOfDigitsSettingsName, Consts.numberOfDigitsDefault);
            int strength     = settingsFile.GetInt(Consts.engineStrengthSettingsName, Consts.engineStrengthDefault);

            gameStartTimeStamp = DateTime.Now;

            currentGameEngine = new Sherlock(digitsCount, strength);

            ModelPlayer   = new PlayerModel();
            ModelComputer = new ComputerModel();

            gameContext.StartActivity(typeof(PlayerActivity));

            isPlayerTurn = true;
        }
Esempio n. 3
0
        [Test] public void FindRefs()
        {
            var thing1 = new Thing();
            var thing2 = new Thing();

            thing1.PublicEvent += thing1.Handler;

            Assert.True(Sherlock.CheckForReferences(thing1, "PublicEvent", thing1));
            Assert.True(Sherlock.CheckForReferences(thing1, "PrivateEvent", thing1));
            Assert.True(Sherlock.CheckForReferences(thing1, "PrivateCustomEvent", thing1));

            Assert.False(Sherlock.CheckForReferences(thing1, "PublicEvent", thing2));
            Assert.False(Sherlock.CheckForReferences(thing1, "PrivateEvent", thing2));
            Assert.False(Sherlock.CheckForReferences(thing1, "PrivateCustomEvent", thing2));

            thing1.PublicEvent -= thing1.Handler;

            Assert.False(Sherlock.CheckForReferences(thing1, "PublicEvent", thing1));
            Assert.True(Sherlock.CheckForReferences(thing1, "PrivateEvent", thing1));
            Assert.True(Sherlock.CheckForReferences(thing1, "PrivateCustomEvent", thing1));
        }
Esempio n. 4
0
        public void Run(string[] args)
        {
            var found = false;

            foreach (var brick in Sherlock.Search(_tree, args))
            {
                found = true;
                foreach (var catapult in Launcher)
                {
                    if (!catapult.CanLaunch(brick.Item1))
                    {
                        continue;
                    }
                    catapult.Launch(brick.Item1, brick.Item2);
                    break;
                }
            }
            if (!found)
            {
                throw new CommandNotFoundException(string.Join(" ", args));
            }
        }
Esempio n. 5
0
                #pragma warning restore 67, 169, 649

        [Test] public void EventRefCount()
        {
            var thing = new Thing();

            thing.PublicEvent       += thing.Handler;
            thing.PublicCustomEvent += thing.Handler;
            thing.PublicEvent       += thing.Handler;
            thing.PublicCustomEvent += thing.Handler;
            thing.PublicEvent       += thing.Handler;
            thing.PublicEvent       += thing.Handler;

            var expected = new List <string>
            {
                "Thing.PrivateEvent - 1 handlers\r\n" +
                "   Rylogic.UnitTests.TestSherlock+Thing.Handler\r\n",

                "Thing.ProtectedEvent - 0 handlers\r\n",

                "Thing.PublicEvent - 4 handlers\r\n" +
                "   Rylogic.UnitTests.TestSherlock+Thing.Handler\r\n" +
                "   Rylogic.UnitTests.TestSherlock+Thing.Handler\r\n" +
                "   Rylogic.UnitTests.TestSherlock+Thing.Handler\r\n" +
                "   Rylogic.UnitTests.TestSherlock+Thing.Handler\r\n",

                "Thing.PrivateCustomEvent - 1 handlers\r\n" +
                "   Rylogic.UnitTests.TestSherlock+Thing.Handler\r\n",

                "Thing.PublicCustomEvent - 2 handlers\r\n" +
                "   Rylogic.UnitTests.TestSherlock+Thing.Handler\r\n" +
                "   Rylogic.UnitTests.TestSherlock+Thing.Handler\r\n",
            };
            var report = Sherlock.CheckEvents(thing);

            Assert.Equal(expected.Count, report.Count);
            for (int i = 0; i != expected.Count; ++i)
            {
                Assert.Equal(expected[i], report[i]);
            }
        }
Esempio n. 6
0
 /// <summary>
 /// Initializes a new instance of the <see cref="SchemaManager"/> class.
 /// </summary>
 /// <param name="mappings">The mappings.</param>
 /// <param name="config">The configuration.</param>
 /// <param name="logger">The logger.</param>
 /// <param name="dataModeler">The data modeler.</param>
 /// <param name="sherlock">The sherlock analyzer.</param>
 /// <param name="sQLHelper">The s ql helper.</param>
 /// <exception cref="ArgumentNullException">logger</exception>
 public SchemaManager(MappingManager mappings, IConfiguration config, ILogger logger, DataModeler dataModeler, Sherlock sherlock, SQLHelper sQLHelper)
 {
     Models = mappings.Sources.ToList(x => new DataModel(x, config, logger !, dataModeler, sherlock, sQLHelper));
 }
Esempio n. 7
0
 public InvoiceController(ILogger <HomeController> logger, Database database, Sherlock sherlock)
 {
     _logger   = logger ?? throw new ArgumentNullException(nameof(logger));
     _database = database ?? throw new ArgumentNullException(nameof(database));
     _sherlock = sherlock ?? throw new ArgumentNullException(nameof(sherlock));
 }
Esempio n. 8
0
        public async Task Analyze()
        {
            var Results = await Sherlock.AnalyzeAsync(new Connection(Configuration, SqlClientFactory.Instance, "Default")).ConfigureAwait(false);

            Assert.NotEmpty(Results);
        }
Esempio n. 9
0
 static void Main(string[] args)
 {
     var sh = new Sherlock();
 }
Esempio n. 10
0
        /// <summary>
        /// Initializes a new instance of the <see cref="DataModel"/> class.
        /// </summary>
        /// <param name="source">The source.</param>
        /// <param name="config">The configuration.</param>
        /// <param name="logger">The logger.</param>
        /// <param name="dataModeler">The data modeler.</param>
        /// <param name="sherlock">The sherlock.</param>
        /// <param name="batch">The batch.</param>
        /// <exception cref="ArgumentNullException">source or config or logger</exception>
        public DataModel(IMappingSource source, IConfiguration config, ILogger logger, DataModeler dataModeler, Sherlock sherlock, SQLHelper batch)
        {
            if (config is null)
            {
                throw new ArgumentNullException(nameof(config));
            }
            if (source is null)
            {
                throw new ArgumentNullException(nameof(source));
            }

            logger ??= Log.Logger ?? new LoggerConfiguration().CreateLogger() ?? throw new ArgumentNullException(nameof(logger));

            var sourceConnection = new Connection(config, source.Source.Provider, source.Source.Name);
            var sourceSpec       = DataModeler.CreateSource(sourceConnection.DatabaseName ?? string.Empty);

            SourceSpec             = sourceSpec;
            GeneratedSchemaChanges = Task.Run(async() => await GenerateSchemaAsync(source, logger, dataModeler, sourceConnection, sourceSpec).ConfigureAwait(false)).GetAwaiter().GetResult();
            Task.Run(async() => await AnalyzeSchemaAsync(sherlock, logger, source, sourceConnection, batch).ConfigureAwait(false)).GetAwaiter().GetResult();
        }