Exemple #1
0
        private async void BacktestMenu_Click(object sender, ToolStripItemClickedEventArgs e)
        {
            if (dgrProjects.SelectedRows.Count == 0)
            {
                return;
            }
            var selproj = dgrProjects.SelectedRows[0].DataBoundItem as CombinedProject;

            if (selproj.Id == 0)
            {
                return;
            }

            var sourceControl = e.ClickedItem;

            if (sourceControl.Name == "RefreshBacktestsMenu")
            {
                dgrBacktests.DataSource = null;
                dgrBacktests.DataSource = await QCStudioPluginActions.GetBacktestList(selproj.Id);
            }
            else
            {
                if (dgrBacktests.SelectedRows.Count == 0)
                {
                    return;
                }
                var selbacktest = dgrBacktests.SelectedRows[0].DataBoundItem as BacktestSummary;
                if (string.IsNullOrEmpty(selbacktest.BacktestId) || selbacktest.BacktestId == "0")
                {
                    return;
                }

                switch (sourceControl.Name)
                {
                case "LoadBacktestMenu":
                    QCPluginUtilities.ShowBacktestRemote(selbacktest.BacktestId);

                    break;

                case "DeleteBacktestMenu":
                    await QCStudioPluginActions.DeleteBacktest(selbacktest.BacktestId);

                    RefreshBacktestsMenu.PerformClick();

                    break;

                case "SaveLocallyMenu":
                    await QCStudioPluginActions.SaveRemoteBacktest(selbacktest.BacktestId);

                    break;
                }
            }
        }
Exemple #2
0
        private async void ProjectsMenu_Click(object sender, ToolStripItemClickedEventArgs e)
        {
            var sourceControl = e.ClickedItem;

            switch (sourceControl.Name)
            {
            case "CreateProjectMenu":
                string projectName = QCPluginUtilities.GetStartupProjectName();
                projectName = Microsoft.VisualBasic.Interaction.InputBox("Enter new project name", QCPluginUtilities.AppTitle, projectName);
                projectName = CleanInput(projectName);

                if (string.IsNullOrEmpty(projectName))
                {
                    QCPluginUtilities.OutputCommandString("Project name cannot be empty.", QCPluginUtilities.Severity.Error);
                    return;
                }

                await QCStudioPluginActions.CreateProject(projectName);

                RefreshProjectsMenu.PerformClick();

                break;

            case "LoginMenu":
                QCStudioPluginActions.Login();

                break;

            case "LogoutMenu":
                QCStudioPluginActions.Logout();

                break;

            case "RefreshProjectsMenu":
                dgrProjects.DataSource = await QCStudioPluginActions.GetProjectList();

                var firstrow = dgrProjects.Rows.Cast <DataGridViewRow>().FirstOrDefault(x => (x.DataBoundItem as CombinedProject).Id > 0);
                if (firstrow != null)
                {
                    firstrow.Selected = true;
                }

                RefreshBacktestsMenu.PerformClick();

                break;

            case "ConnectProjectIDMenu":
                var projects  = dgrProjects.DataSource as List <CombinedProject>;
                var cloudproj = projects.Where(x => string.IsNullOrEmpty(x.LocalProjectName)).ToArray();
                var localproj = projects.Where(x => x.Id == 0).ToArray();
                if (localproj.Length == 0 || cloudproj.Length == 0)
                {
                    QCPluginUtilities.OutputCommandString("No orphaned projects found on both cloud and local side.", QCPluginUtilities.Severity.Error);
                    return;
                }

                var win = new ConnectQCID();
                win.cmbCloud.Items.AddRange(cloudproj);
                win.cmbLocal.Items.AddRange(localproj);

                if (dgrProjects.SelectedRows.Count > 0)
                {
                    var selproj2 = dgrProjects.SelectedRows[0].DataBoundItem as CombinedProject;
                    win.cmbCloud.SelectedItem = selproj2;
                    win.cmbLocal.SelectedItem = selproj2;
                }

                var dlgres = win.ShowDialog();

                if (dlgres == DialogResult.OK)
                {
                    var selID   = win.cmbCloud.SelectedItem as CombinedProject;
                    var selName = win.cmbLocal.SelectedItem as CombinedProject;

                    QCPluginUtilities.SetProjectID(selID.Id, selName.uniqueName);
                    RefreshProjectsMenu.PerformClick();
                }

                break;

            default:
                if (dgrProjects.SelectedRows.Count == 0)
                {
                    return;
                }
                var selproj = dgrProjects.SelectedRows[0].DataBoundItem as CombinedProject;
                if (selproj.Id == 0)
                {
                    return;
                }

                switch (sourceControl.Name)
                {
                case "DeleteProjectMenu":
                    await QCStudioPluginActions.DeleteProject(selproj.Id);

                    QCPluginUtilities.SetProjectID(0, selproj.uniqueName);
                    RefreshProjectsMenu.PerformClick();

                    break;

                case "UploadProjectMenu":
                    if (string.IsNullOrEmpty(selproj.LocalProjectPath))
                    {
                        return;
                    }
                    await QCStudioPluginActions.UploadProject(selproj.Id, selproj.CloudProjectName, selproj.LocalProjectPath);

                    break;

                case "DownloadProjectMenu":

                    await QCStudioPluginActions.DownloadProject(selproj.Id, selproj.CloudProjectName, selproj.LocalProjectName, selproj.LocalProjectPath);

                    break;

                case "DisconnectProjectIDMenu":
                    QCPluginUtilities.SetProjectID(0, selproj.uniqueName);
                    RefreshProjectsMenu.PerformClick();

                    break;

                case "CompileProjectMenu":
                    string backtestName = QCPluginUtilities.GetStartupProjectName();
                    backtestName = Microsoft.VisualBasic.Interaction.InputBox("Enter new backtest name", QCPluginUtilities.AppTitle, backtestName);
                    backtestName = CleanInput(backtestName);

                    if (string.IsNullOrWhiteSpace(backtestName))
                    {
                        QCPluginUtilities.OutputCommandString("Backtest name cannot be empty.", QCPluginUtilities.Severity.Error);
                        return;
                    }

                    var isfinished = false;
                    var cnt        = 0;
                    while (!isfinished && cnt++ < 5)
                    {
                        isfinished = await QCStudioPluginActions.CreateBacktest(selproj.Id, backtestName);
                    }

                    break;
                }

                break;
            }
        }
Exemple #3
0
 private void dgrProjects_DoubleClick(object sender, EventArgs e)
 {
     RefreshBacktestsMenu.PerformClick();
 }