Beispiel #1
0
 public void Load(IServiceProvider serviceProvider)
 {
     _ironPythonLanguage = new IronPythonLanguage(true);
     _languageManager    = (ILanguageManager)serviceProvider.GetService(typeof(ILanguageManager));
     for (int i = _languageManager.Languages.Count - 1; i >= 0; i--)
     {
         if (_languageManager.Languages[i].Name == "IronPython")
         {
             _languageManager.UnregisterLanguage(_languageManager.Languages[i]);
         }
     }
     _languageManager.RegisterLanguage(_ironPythonLanguage);
 }
        /// <summary>
        /// Start application and initialize all needed systems
        /// </summary>
        protected void Application_Start()
        {
            // Create scripting
            language = new IronPythonLanguage();
            host     = new DlrHost <IronPythonLanguage>(language);
            host.AddImportResolver(new NoImporter());

            // Search paths
            Host.AddSearchPath(System.Web.Hosting.HostingEnvironment.ApplicationPhysicalPath);

            // Load app.py and execute
            var source = Host.ScriptEngine.CreateScriptSourceFromString
                         (
                System.IO.File.ReadAllText(System.Web.Hosting.HostingEnvironment.ApplicationPhysicalPath + "app.py")
                         );

            source.Execute(Host.DefaultScope.ScriptScope);

            app = (AspNetMvcAPI.Application)Host.DefaultScope.CreateClassInstance("App").Instance;

            // Call start
            app.start();
        }
Beispiel #3
0
        static void Main(string[] args)
        {
            if (args.Length > 0)
            {
                // Create host
                var language = new IronPythonLanguage();
                language.Argv = args.ToList();

                var host = new DlrHost <IronPythonLanguage>(language);

                host.AddSearchPath(@"C:\Program Files (x86)\IronPython 2.7\Lib\");
                host.AddSearchPath(System.IO.Path.GetDirectoryName(args[0]));

                try
                {
                    host.DefaultScope.ExecuteScript(args.First());
                }
                catch (Exception ex)
                {
                    Environment.Exit(1);
                }
            }
        }