Exemplo n.º 1
0
        public void BaseAppTest(string[] args,
                                Action <ApplicationConfiguration <Models.Options> > configure,
                                Models.Options expectedOptions)
        {
            var configuration = new ApplicationConfiguration <Models.Options>();

            configure(configuration);
            configuration.OnExecute(opt => opt.ShouldBe(expectedOptions));
            RuntimeCommandBuilder.Build(configuration, args, out var options).Invoke(options);
        }
Exemplo n.º 2
0
        private ChartBuilder GetChartData(CoinGeckoCurrency coin, CoingGeckoSparkline sparkline)
        {
            var prices = sparkline.SparklineIn7D.Price;

            if (!sparkline.SparklineIn7D.Price.Any())
            {
                return(null);
            }

            var data = FillData(prices);

            var dataset = new Dataset
            {
                BorderColor = sparkline.PriceChangePercentage7d > 0 ? "green" : "red",
                Fill        = false,
                Label       = coin.Name,
                Data        = data.Data
            };

            var options = new Models.Options
            {
                Scales = new Scales
                {
                    YAxes = new List <YAx>
                    {
                        new YAx
                        {
                            Ticks = new Ticks
                            {
                                SuggestedMax = data.Max,
                                SuggestedMin = data.Min
                            }
                        }
                    }
                }
            };

            var chart = new Chart
            {
                Type = "sparkline",
                Data = new Data
                {
                    Datasets = new List <Dataset>
                    {
                        dataset
                    }
                },
                Options = options
            };

            return(new ChartBuilder
            {
                Chart = chart
            });
        }
Exemplo n.º 3
0
        private Tests InsertWordTestToDB(WordTest wordTest)
        {
            var numQuestions = wordTest.TestQuestions.Count;

            var newTest = new Tests()
            {
                AuthorID       = UsersService.currentUser.id,
                Name           = wordTest.TestName,
                NumToPassFive  = numQuestions,
                NumToPassFour  = (int)Math.Round(numQuestions * 0.75),
                NumToPassThree = (int)Math.Round(numQuestions * 0.5, MidpointRounding.AwayFromZero),
                PassTime       = wordTest.TestPassTime,
                QuestionTime   = 0
            };

            MainClass.db.Tests.Add(newTest);
            MainClass.db.SaveChanges();
            foreach (var q in wordTest.TestQuestions)
            {
                var newQuestion = new Questions()
                {
                    Text   = q.QuestionText,
                    TestID = newTest.id
                };
                MainClass.db.Questions.Add(newQuestion);
                MainClass.db.SaveChanges();

                foreach (var op in q.OptionsList)
                {
                    if (!op.Contains(" (+)"))
                    {
                        MainClass.db.Options.Add(new Models.Options()
                        {
                            QuestionID = newQuestion.id,
                            Text       = op,
                        });
                    }
                    else
                    {
                        var newAnswer = new Models.Options()
                        {
                            Text       = op.Replace(" (+)", ""),
                            QuestionID = newQuestion.id
                        };
                        MainClass.db.Options.Add(newAnswer);
                        MainClass.db.SaveChanges();
                        newQuestion.AnswerID = newAnswer.id;
                        MainClass.db.SaveChanges();
                    }
                }
            }

            return(newTest);
        }
Exemplo n.º 4
0
 /// <summary>
 /// Does the table have an identity column
 /// </summary>
 /// <param name="options">(options)</param>
 /// <returns>True if so</returns>
 public static bool HasIdentity(Models.Options options)
 {
     if (options != null)
     {
         var ti = ParseTableName(options);
         return(HasIdentity(options.ConnectionString, ti));
     }
     else
     {
         return(false);
     }
 }
Exemplo n.º 5
0
        public MenuHandler(ContentHolder content, int width, int height, Models.Highscores hs)
        {
            mainMenu = new Models.MainMenu(content, width, height);
            credits = new Models.Credits(content, width, height);
            options = new Models.Options(content, width, height);
            endMenu = new Models.EndMenu(content, width, height);
            leaderboards = new Models.Leaderboards(content, width, height, hs);

            sendScore = false;

            Active = true;

            exitGame = false;
        }
Exemplo n.º 6
0
        public Task BaseAppAsyncTest(string[] args,
                                     Action <ApplicationConfiguration <Models.Options> > configure,
                                     Models.Options expectedOptions)
        {
            var configuration = new ApplicationConfiguration <Models.Options>();

            configure(configuration);
            configuration.OnExecuteAsync(opt =>
            {
                opt.ShouldBe(expectedOptions);
                return(Task.CompletedTask);
            });
            return(RuntimeCommandBuilder.Build(configuration, args, out var options).InvokeAsync(options,
                                                                                                 CancellationToken.None));
        }
Exemplo n.º 7
0
        /// <summary>
        /// Parses and normalizes table name
        /// </summary>
        /// <param name="options">(options)</param>
        /// <returns>Table and Schema</returns>
        public static Models.TableInfo ParseTableName(Models.Options options)
        {
            var ti = new Models.TableInfo();

            if (options != null)
            {
                var s = options.Table.Replace("[", "").Replace("]", "");
                int i = s.IndexOf('.');
                if (i < 0)
                {
                    ti.TableName = s;
                }
                else
                {
                    ti.Schema    = s.Substring(0, i);
                    ti.TableName = s.Substring(i + 1);
                }
            }
            return(ti);
        }
Exemplo n.º 8
0
 public Task SendMessagAsync(Models.Options options)
 {
     return(_channel.WriteAndFlushAsync(options));
 }
Exemplo n.º 9
0
        /// <summary>
        /// The Extraction Engine
        /// </summary>
        /// <param name="options">(options)</param>
        public static void Extract(Models.Options options)
        {
            if (options == null)
            {
                return;
            }

            var ti         = ParseTableName(options);
            var isIdentity = HasIdentity(options.ConnectionString, ti);


            if (options.Verbose)
            {
                Console.WriteLine($"{ti.ToString()} has identity {isIdentity}");
            }

            var filename = $"{ti.Schema}-{ti.TableName}-SeedData.sql";

            if (options.AsCsv)
            {
                filename = Path.ChangeExtension(filename, "csv");
            }
            filename = Path.Combine(Directory.GetCurrentDirectory(), filename);
            if (File.Exists(filename))
            {
                File.Delete(filename);
            }

            var sb = new StringBuilder();

            sb.Append("select ");
            if (options.Top > 0)
            {
                sb.Append($"top ({options.Top}) ");
            }

            sb.Append($"* from {ti.ToString()} ");

            if (!string.IsNullOrWhiteSpace(options.Where))
            {
                sb.Append(options.Where);
                sb.Append(" ");
            }

            if (!string.IsNullOrWhiteSpace(options.OrderBy))
            {
                sb.Append(options.OrderBy);
                sb.Append(" ");
            }

            sb.Append(";");

            var sql = sb.ToString();

            if (options.Verbose)
            {
                Console.WriteLine($"SQL Query: {sql}");
            }

            if (options.AsCsv)
            {
                isIdentity = false;
            }

            var dt = SqlHelper.ExecuteSqlWithParametersToDataTable(options.ConnectionString, sql, null);

            if (SqlHelper.HasRows(dt))
            {
                var columns = ColumnsList(dt, !options.AsCsv);

                // New style using
                using var file = new StreamWriter(filename);

                if (isIdentity)
                {
                    file.WriteLine($"SET IDENTITY_INSERT {ti.ToString()} ON");
                }

                if (options.AsCsv)
                {
                    file.WriteLine(columns);
                }

                foreach (DataRow dr in dt.Rows)
                {
                    if (options.AsCsv)
                    {
                        WriteRowCsv(file, dr);
                    }
                    else
                    {
                        WriteRowSql(file, dr, columns, ti);
                    }
                }

                if (isIdentity)
                {
                    file.WriteLine($"SET IDENTITY_INSERT {ti.ToString()} OFF");
                }
            }
            else
            {
                Console.Error.WriteLine($"No Rows Returned for: {sql}");
            }

            Console.WriteLine($"Written to: {filename}");
        }