コード例 #1
0
        private async void ExecuteOnProjectAsync(object sender, Action <int, string, List <SelectedItem> > onProject)
        {
            if (await _authenticationCommand.Login(_serviceProvider, false))
            {
                var projects = await System.Threading.Tasks.Task.Run(() =>
                {
                    var api = AuthorizationManager.GetInstance().GetApi();
                    return(api.ListProjects().Projects);
                });

                var projectNames = projects.Select(p => Tuple.Create(p.ProjectId, p.Name)).ToList();

                var files                = GetSelectedFiles(sender);
                var fileNames            = files.Select(tuple => tuple.FileName).ToList();
                var suggestedProjectName = _lazyProjectFinder.ProjectNameForFiles(fileNames);
                var projectNameDialog    = new ProjectNameDialog(projectNames, suggestedProjectName);
                VsUtils.DisplayDialogWindow(projectNameDialog);

                if (projectNameDialog.ProjectNameProvided)
                {
                    var selectedProjectName = projectNameDialog.SelectedProjectName;
                    var selectedProjectId   = projectNameDialog.SelectedProjectId;
                    _lazyProjectFinder.AssociateProjectWith(selectedProjectName, fileNames);

                    if (!selectedProjectId.HasValue)
                    {
                        var newProjectLanguage = PathUtils.DetermineProjectLanguage(files.Select(f => f.FilePath).ToList());
                        if (!newProjectLanguage.HasValue)
                        {
                            VsUtils.ShowMessageBox(_serviceProvider, "Failed to determine project language",
                                                   $"Failed to determine programming laguage for a project");
                            return;
                        }

                        selectedProjectId = CreateQuantConnectProject(selectedProjectName, newProjectLanguage.Value);
                        if (!selectedProjectId.HasValue)
                        {
                            VsUtils.ShowMessageBox(_serviceProvider, "Failed to create a project", $"Failed to create a project {selectedProjectName}");
                        }
                        onProject.Invoke(selectedProjectId.Value, selectedProjectName, files);
                    }
                    else
                    {
                        onProject.Invoke(selectedProjectId.Value, selectedProjectName, files);
                    }
                }
            }
        }
コード例 #2
0
        private void ExecuteOnProject(object sender, Action <int, string, List <SelectedItem> > onProject)
        {
            if (_logInCommand.DoLogIn(this.ServiceProvider, _package.DataPath, explicitLogin: false))
            {
                var api          = AuthorizationManager.GetInstance().GetApi();
                var projects     = api.ListProjects().Projects;
                var projectNames = projects.Select(p => Tuple.Create(p.ProjectId, p.Name)).ToList();

                var files                = GetSelectedFiles(sender);
                var fileNames            = files.Select(tuple => tuple.FileName).ToList();
                var suggestedProjectName = ProjectFinder.ProjectNameForFiles(fileNames);
                var projectNameDialog    = new ProjectNameDialog(projectNames, suggestedProjectName);
                VsUtils.DisplayDialogWindow(projectNameDialog);

                if (projectNameDialog.ProjectNameProvided())
                {
                    var selectedProjectName = projectNameDialog.GetSelectedProjectName();
                    var selectedProjectId   = projectNameDialog.GetSelectedProjectId();
                    ProjectFinder.AssociateProjectWith(selectedProjectName, fileNames);

                    if (!selectedProjectId.HasValue)
                    {
                        var newProjectLanguage = PathUtils.DetermineProjectLanguage(files.Select(f => f.FilePath).ToList());
                        if (!newProjectLanguage.HasValue)
                        {
                            VsUtils.ShowMessageBox(this.ServiceProvider, "Failed to determine project language",
                                                   $"Failed to determine programming laguage for a project");
                            return;
                        }

                        selectedProjectId = CreateQuantConnectProject(selectedProjectName, newProjectLanguage.Value);
                        if (!selectedProjectId.HasValue)
                        {
                            VsUtils.ShowMessageBox(this.ServiceProvider, "Failed to create a project", $"Failed to create a project {selectedProjectName}");
                        }
                        onProject.Invoke(selectedProjectId.Value, selectedProjectName, files);
                    }
                    else
                    {
                        onProject.Invoke(selectedProjectId.Value, selectedProjectName, files);
                    }
                }
            }
        }
コード例 #3
0
        /// <summary>
        /// Callback for the edit button. Will show a new popup so the user can edit backtest name and note.
        /// Will update the server through API.
        /// </summary>
        private async void Edit_OnClick(object sender, RoutedEventArgs e)
        {
            var obj = ((FrameworkElement)sender).DataContext as DataGridItem;

            if (obj != null)
            {
                var projectId    = obj.ProjectId;
                var backtestId   = obj.BacktestId;
                var backtestNote = obj.Note;
                var window       = new EditBacktestDialog(obj.Name, backtestNote);
                VsUtils.DisplayDialogWindow(window);
                if (window.BacktestNameProvided &&
                    !string.IsNullOrEmpty(window.BacktestName) &&
                    await _authenticationCommand.Login(ServiceProvider.GlobalProvider, false))
                {
                    var result = false;
                    try
                    {
                        result = await System.Threading.Tasks.Task.Run(() =>
                        {
                            var api = AuthorizationManager.GetInstance().GetApi();
                            return(api.UpdateBacktest(projectId, backtestId, window.BacktestName, window.BacktestNote).Success);
                        });
                    }
                    catch (Exception exception)
                    {
                        VsUtils.ShowErrorMessageBox(ServiceProvider.GlobalProvider,
                                                    "QuantConnect Exception", exception.ToString());
                    }
                    if (result)
                    {
                        // lets update the data grid without having to go to the server again
                        obj.Name = window.BacktestName;
                        obj.Note = window.BacktestNote;
                        VsUtils.DisplayInStatusBar(ServiceProvider.GlobalProvider, "Successfully edited backtest");
                    }
                    else
                    {
                        VsUtils.DisplayInStatusBar(ServiceProvider.GlobalProvider, "Failed to edit backtest");
                    }
                }
            }
        }
コード例 #4
0
        /// <summary>
        /// Callback for the new project button. Will show a new popup so the user can select name and language
        /// Will create project calling the server through API.
        /// </summary>
        private async void NewProjectButton_OnClick(object sender, RoutedEventArgs e)
        {
            var window = new NewProjectDialog();

            VsUtils.DisplayDialogWindow(window);
            if (window.CreateNewProject &&
                await _authenticationCommand.Login(ServiceProvider.GlobalProvider, false))
            {
                var result    = false;
                var projectId = 0;
                try
                {
                    var apiResponse = await System.Threading.Tasks.Task.Run(() =>
                    {
                        var api = AuthorizationManager.GetInstance().GetApi();
                        return(api.CreateProject(window.NewProjectName, window.NewProjectLanguage));
                    });

                    if (apiResponse.Success && apiResponse.Projects.Count > 0)
                    {
                        result    = true;
                        projectId = apiResponse.Projects.First().ProjectId;
                    }
                }
                catch (Exception exception)
                {
                    VsUtils.ShowErrorMessageBox(ServiceProvider.GlobalProvider,
                                                "QuantConnect Exception", exception.ToString());
                }
                if (result)
                {
                    // lets update the combo box without having to go to the server again
                    var newProject = new ComboboxProjectItem(projectId, window.NewProjectName, window.NewProjectLanguage);
                    projectNameBox.Items.Add(newProject);
                    projectNameBox.SelectedItem = newProject;
                    VsUtils.DisplayInStatusBar(ServiceProvider.GlobalProvider, "Successfully created a new project");
                }
                else
                {
                    VsUtils.DisplayInStatusBar(ServiceProvider.GlobalProvider, "Failed to create a new project");
                }
            }
        }
コード例 #5
0
        private void SendForBacktestingCallback(object sender, EventArgs e)
        {
            try
            {
                ExecuteOnProjectAsync(sender, async(selectedProjectId, selectedProjectName, files) =>
                {
                    var uploadResult = await System.Threading.Tasks.Task.Run(() =>
                                                                             UploadFilesToServer(selectedProjectId, files));
                    if (!uploadResult)
                    {
                        return;
                    }

                    var compilationResult = await CompileProjectOnServer(selectedProjectId);
                    if (!compilationResult.Item1)
                    {
                        var errorDialog = new ErrorDialog("Compilation Error", compilationResult.Item2);
                        VsUtils.DisplayDialogWindow(errorDialog);
                        return;
                    }

                    var backtestResult = await BacktestProjectOnServer(selectedProjectId, compilationResult.Item2);
                    if (!backtestResult.Item1)
                    {
                        var errorDialog = new ErrorDialog("Backtest Failed", backtestResult.Item2.Error);
                        VsUtils.DisplayDialogWindow(errorDialog);
                        return;
                    }

                    var projectUrl = string.Format(
                        CultureInfo.CurrentCulture,
                        "https://www.quantconnect.com/terminal/#open/{0}/{1}",
                        selectedProjectId,
                        backtestResult.Item2.BacktestId
                        );
                    Process.Start(projectUrl);
                });
            }
            catch (Exception exception)
            {
                VsUtils.ShowErrorMessageBox(_serviceProvider, "QuantConnect Exception", exception.ToString());
            }
        }
コード例 #6
0
        private bool LoginWithDialog(IServiceProvider serviceProvider, Credentials?previousCredentials)
        {
            var logInDialog = new LoginDialog(AuthorizationManager.GetInstance(), previousCredentials, serviceProvider);

            VsUtils.DisplayDialogWindow(logInDialog);

            var credentials = logInDialog.GetCredentials();

            if (credentials.HasValue)
            {
                VSActivityLog.Info("Storing credentials");
                CredentialsManager.StoreCredentials(credentials.Value);
                return(true);
            }
            else
            {
                VSActivityLog.Info("Login cancelled");
                return(false);
            }
        }
コード例 #7
0
        private bool LogInWithDialog(IServiceProvider serviceProvider, Credentials?previousCredentials, string dataFolderPath)
        {
            var logInDialog = new LogInDialog(AuthorizationManager.GetInstance(), previousCredentials, dataFolderPath);

            VsUtils.DisplayDialogWindow(logInDialog);

            var credentials = logInDialog.GetCredentials();

            if (credentials.HasValue)
            {
                _log.Info("Logged in successfully");
                _log.Info("Storring credentials");
                _credentialsManager.StoreCredentials(credentials.Value);
                VsUtils.DisplayInStatusBar(serviceProvider, "Logged into QuantConnect");
                return(true);
            }
            else
            {
                _log.Info("Log in cancelled");
                return(false);
            }
        }