예제 #1
0
파일: MainViewModel.cs 프로젝트: forki/Labs
        public MainViewModel(string configFile, string grammarFile)
        {
            _parser            = new RRParser(grammarFile);
            _configurationFile = configFile;

            var methods = GetType().GetMethods();

            _commandMethods = methods
                              .Where(m => m.GetCustomAttribute <CommandAttribute>(false) != null);
            _helpCommandMethods = methods
                                  .Where(m => m.GetCustomAttribute <HelpCommandAttribute>(false) != null);
            _helpDescCommandMethods = methods
                                      .Where(m => m.GetCustomAttribute <HelpDescriptionCommandAttribute>(false) != null);

            _foregroundColor = _greenColor;
            _state           = new State(this);
            _worker          = new Worker(this);
            LoadConfiguration();
        }
예제 #2
0
        public void RelatedRecords_Parser_Tests()
        {
            #region text commands

            var commands = @"
back
clone as SomeOtherName
clone catalog MyCatalog as SomeOther12_catName
clone catalog SampleCat
clone
columns 2
columns
export as html
export as json
export as sql
export as sql nochild
export Html_Table as html
export _Tablename as json
export _Table_Name_12 as sql
export _Table_Name_12 as sql nochild
export ThisTable as xml
export as xml
import catalog SampleZ server localhostz user devz password pwdz
import catalog SampleY user devy password pwdy
import catalog SampleX
load catalog _Catalog_Name default
load catalog CatalogName
load
relate ThisTable to OtherTable12 on Column1 = column_2
relate to OtherTable12 on Column1 = column_2
remove catalog CatalogName
remove
refresh
refresh catalog My_Catalog
home
table Test21 where col1 = '1.34'
table Test21 where col1 like '%Price 1.34%'
table Test21 default where col1 = '1.34'
table Test21 default where col1 like '%Price 1.34%'
table Test21 default
table Test21 where col1 between 1 and 10
table Test21 where col1 not between 1 and 10
table Test21 where col1 between 1.34 and 245.234
table Test21 where col1 not between 1.34 and 245.234
table Test21 where col1 >= -1
table Test21 where col1 >= -121.340
table Test21 where col1 >= 1
table Test21 where col1 >= 121.340
table Test21 where col1 > -1
table Test21 where col1 > -121.340
table Test21 where col1 > 1
table Test21 where col1 > 121.340
table Test21 where col1 <= -1
table Test21 where col1 <= -121.340
table Test21 where col1 <= 1
table Test21 where col1 <= 121.340
table Test21 where col1 <> 1
table Test21 where col1 <> 121.340
table Test21 where col1 <> -1
table Test21 where col1 <> -121.340
table Test21 where col1 = -1
table Test21 where col1 = -121.340
table Test21 where col1 = 1
table Test21 where col1 = 121.340
table Test21 where col_some12 is not null
table Test21 where col12xo is null
table Test21
tables 10
tables
catalogs
catalogs 10
top 100
unrelate This_Table12 to OtherTable12
unrelate to OtherTable12
child
child 2
child MyTable
help
transform
transform template Controller
transform Tickets
transform Tickets template Controller
transform qrySample
transform qrySample template Controller
query TicketNumber
query TicketNumber row 10
run qry_Name2Test
";
            var parms    = new string[]
            {
                "_paramInt = 3",
                "param_Dec = 1.0",
                "paramStrId = 'sample'",
                "param_IdNull = null"
            };

            var parmStr = new StringBuilder();
            for (var i = 0; i < parms.Length; i++)
            {
                var single = "run qry_Name2Test with " + parms[i];
                var agg    = single;
                parmStr.AppendFormat("{0}{1}", single, Environment.NewLine);
                for (var j = 0; j < 4; j++)
                {
                    if (i != j)
                    {
                        agg += ", " + parms[j];
                        parmStr.AppendFormat("{0}{1}", agg, Environment.NewLine);
                    }
                }

                agg = single;
                for (var j = 0; j < 5; j++)
                {
                    if (i != j)
                    {
                        agg += ", " + parms[i];
                        parmStr.AppendFormat("{0}{1}", agg, Environment.NewLine);
                    }
                }
            }

            commands += parmStr.ToString();

            #endregion text commands

            var parser = new RRParser(
                Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "relatedrecords.cgt"));

            using (var stream = File.CreateText(
                       Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "commands.cs")))
            {
                stream.Write(commands);
            }

            using (var stream = File.CreateText(
                       Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "methods.cs")))
            {
                var methods       = new StringBuilder();
                var hlpMethods    = new StringBuilder();
                var tstHlpMethods = new StringBuilder();

                foreach (var cmd in commands.Replace("'", "\"").Split(Environment.NewLine.ToCharArray(),
                                                                      StringSplitOptions.RemoveEmptyEntries))
                {
                    var results = parser.Parse(cmd);
                    if (!results.isAccepted)
                    {
                        var x = cmd;
                    }
                    Assert.IsTrue(results.isAccepted);

                    DumpCommandMethods(results.Tokens, methods);
                    DumpHelperMethods(results.Tokens, hlpMethods);
                    DumpTestMethods(results.Tokens, tstHlpMethods, cmd);
                }

                stream.Write(methods.ToString());
                stream.Write(hlpMethods.ToString());
                stream.Write(tstHlpMethods.ToString());
            }
        }