Exemple #1
0
        public void Run(TrackModel model, AccountModel account, SettingModel settings)
        {
            if (model == null)
            {
                throw new ArgumentNullException(nameof(model));
            }
            Debug.Assert(model.Status == CompletionStatus.None);
            if (!model.Active)
            {
                return;
            }

            bool error = false;

            _process = new ConfigProcess(
                "QuantConnect.Lean.Launcher.exe",
                null,
                Directory.GetCurrentDirectory(),
                true,
                (line) => Log.Trace(line),
                (line) =>
            {
                error = true;
                Log.Error(line, true);
            });

            // Set Environment
            StringDictionary environment = _process.Environment;

            // Set config
            IDictionary <string, string> config = _process.Config;

            if (!SetConfig(config, model, account, settings))
            {
                return;
            }

            // Start process
            try
            {
                if (model.AlgorithmLanguage.Equals(Language.Python))
                {
                    PythonSupport.SetupPython(_process.Environment);
                }
                _process.Start();
                _process.WaitForExit(int.MaxValue, (folder) => PostProcess(folder, model));
                model.Status = error ? CompletionStatus.Error : CompletionStatus.Success;
            }
            catch (Exception ex)
            {
                model.Status = CompletionStatus.Error;
                Log.Error($"{ex.GetType()}: {ex.Message}", true);
            }
            finally
            {
                _process.Dispose();
                _process     = null;
                model.Active = false;
            }
        }
Exemple #2
0
        public void Run(TrackModel model, AccountModel account, SettingModel settings)
        {
            if (model == null)
            {
                throw new ArgumentNullException(nameof(model));
            }
            Debug.Assert(!IsBusy);
            Debug.Assert(!model.Completed);
            if (!model.Active)
            {
                return;
            }

            IsBusy = true;
            bool success = true;

            _process = new ConfigProcess(
                "QuantConnect.Lean.Launcher.exe",
                null,
                Directory.GetCurrentDirectory(),
                true,
                (line) => Log.Trace(line),
                (line) =>
            {
                success = false;
                Log.Error(line);
            });

            // Set Environment
            StringDictionary environment = _process.Environment;

            // Set config
            IDictionary <string, string> config = _process.Config;

            if (!SetConfig(config, model, account, settings))
            {
                return;
            }

            // Start process
            try
            {
                _process.Start();
                _process.WaitForExit(int.MaxValue, (folder) => PostProcess(folder, model));
                if (!success)
                {
                    throw new ApplicationException("See logs for details");
                }
            }
            finally
            {
                _process.Dispose();
                _process     = null;
                model.Active = false;
                IsBusy       = false;
            }

            model.Completed = true;
        }
Exemple #3
0
        internal void RunProcess(string cmd, string[] args, IDictionary <string, string> configs)
        {
            bool ok = true;

            _process = new ConfigProcess(
                cmd,
                string.Join(" ", args),
                Directory.GetCurrentDirectory(),
                true,
                (line) => Log.Trace(line),
                (line) =>
            {
                ok = false;
                Log.Error(line);
            });

            // Set Environment
            StringDictionary environment = _process.Environment;

            // Set config file
            IDictionary <string, string> config = _process.Config;
            string exeFolder = MainService.GetProgramFolder();

            config["debug-mode"]                 = "true";
            config["composer-dll-directory"]     = exeFolder;
            config["results-destination-folder"] = ".";
            config["plugin-directory"]           = ".";
            config["log-handler"]                = "ConsoleLogHandler";
            config["map-file-provider"]          = "LocalDiskMapFileProvider";
            config["#command"]        = cmd;
            config["#parameters"]     = string.Join(" ", args);
            config["#work-directory"] = Directory.GetCurrentDirectory();
            foreach (KeyValuePair <string, string> item in configs)
            {
                config.Add(item);
            }

            // Start process
            try
            {
                _process.Start();
                _process.WaitForExit();
                if (!ok)
                {
                    throw new ApplicationException("See logs for details");
                }
            }
            finally
            {
                _process.Dispose();
                _process = null;
            }
        }
Exemple #4
0
        protected virtual void Dispose(bool disposing)
        {
            if (_isDisposed)
            {
                return;
            }
            if (disposing)
            {
                // TODO: dispose managed state (managed objects)
                if (_process != null)
                {
                    _process.Dispose();
                }
            }

            // TODO: free unmanaged resources (unmanaged objects) and override finalizer
            // TODO: set large fields to null
            _process    = null;
            _isDisposed = true;
        }