Пример #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);
                    }
                }
            }
        }
        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);
                    }
                }
            }
        }