Exemple #1
0
 public static CsmRuntime VerifyInit()
 {
     if (Current == null)
     {
         Current = new CsmRuntime();
     }
     return(Current);
 }
Exemple #2
0
        private void Run()
        {
            CsmRuntime.VerifyInit();
            var args     = new ToolArgsParser().Parse(Args).ToList();
            var csFiles  = args.Where(t => t.Name == null && t.Switch == null && t.Value != null).Select(t => t.Value).ToList();
            var oneLines = args.Where(t => t.Name == "e").Select(t => t.Value).ToList();

            var csFilename = csFiles.FirstOrDefault();
            var Csm        = new CsmRuntime {
                Compilations = { new CsmCompilation {
                                     Scripts = oneLines.Select(t => new CsmScript{
                            Code = t
                        }).ToList()
                                 } }
            };

            if (csFilename != null)
            {
                var CsFile = csFilename.ToFileInfo();
                if (!CsFile.Exists && CsFile.Extension != ".cs")
                {
                    CsFile = (CsFile.FullName + ".cs").ToFileInfo();
                }
                if (!CsFile.Exists)
                {
                    throw new Exception("File not found " + csFilename);
                }
                Csm.Compilations[0].Scripts.Add(new CsmScript {
                    File = CsFile
                });
            }
            if (Csm.Compilations[0].Scripts.IsEmpty())
            {
                while (true)
                {
                    var line = Console.ReadLine();
                    if (line.IsNullOrEmpty())
                    {
                        continue;
                    }
                    try
                    {
                        line.ExecuteAsCsmScript();
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine(e.Message);
                    }
                }
            }
            Csm.Run();
        }
Exemple #3
0
 public static void ExecuteAsCsmScript(this string script)
 {
     CsmRuntime.VerifyInit().Run(new CsmScript {
         Code = script
     });
 }
Exemple #4
0
 public static void ExecuteAsCsmFile(this string filename)
 {
     CsmRuntime.VerifyInit().Run(new CsmScript {
         File = filename.ToFileInfo()
     });
 }