Пример #1
0
        /// <summary>
        /// Add a project to the list of projects.
        /// This will add the project to the database.
        /// It will also set the new project as the
        /// selected project.  If the project already
        /// exist, it will display a messagebox warning.
        /// </summary>
        /// <param name="prj">Project to add.</param>
        public async Task AddProject(Project prj)
        {
            // Add project to DB
            _pm.AddNewProject(prj);

            await System.Windows.Application.Current.Dispatcher.BeginInvoke(new System.Action(() =>
            {
                // Create the VM
                ProjectListItemViewModel newPrjVm = new ProjectListItemViewModel(prj, this);

                // Add project VM to the list
                ProjectList.Insert(0, newPrjVm);

                // Set the new project as the selected project
                SelectedProjectVM = newPrjVm;

                _pm.SelectedProject = prj;
            }));
        }
Пример #2
0
        /// <summary>
        /// Delete the project.  This will remove the project and
        /// the project's view model.
        /// </summary>
        /// <param name="projectVM">Project to remove.</param>
        public void DeleteProject(ProjectListItemViewModel projectVM)
        {
            if (projectVM != null)
            {
                string dir     = projectVM.ProjectFolderPath;
                string prjName = projectVM.ProjectName;

                // Unselect the project VM
                if (_SelectedProjectVM == projectVM)
                {
                    _pm.SelectedProject.Dispose();
                    SelectedProjectVM.IsSelected = false;
                    SelectedProjectVM.Dispose();
                    SelectedProjectVM = null;
                }

                // Delete the project from the database
                _pm.RemoveProject(projectVM.ProjectName);

                System.Windows.Application.Current.Dispatcher.BeginInvoke(new System.Action(() =>
                {
                    // Dispose of the VM
                    projectVM.Dispose();

                    var tempPrjList = new ReactiveList <ProjectListItemViewModel>(ProjectList);
                    tempPrjList.Remove(projectVM);

                    ProjectList = tempPrjList;
                    this.NotifyOfPropertyChange(() => this.ProjectList);

                    // Delete the selected project from the list
                    //_ProjectList.Remove(projectVM);
                }));


                // Prompt to delete the folder content also
                this.PromptToPermenatelyDelete(dir, prjName);
            }
        }
Пример #3
0
        /// <summary>
        /// Run this method async to get the list of all
        /// the projects.
        /// </summary>
        /// <returns>List of all the projects.</returns>
        private async Task ScanProjectAsync()
        {
            IsProjectLoading = true;

            List <ProjectListItemViewModel> missingImageList = new List <ProjectListItemViewModel>();

            ProjectList = new ReactiveList <ProjectListItemViewModel>();

            var list = await Task.Run(() => _pm.GetProjectList());

            foreach (var prj in list)
            {
                await System.Windows.Application.Current.Dispatcher.BeginInvoke(new System.Action(() =>
                {
                    // Create a project list item and add it to the list
                    var prjVM = new ProjectListItemViewModel(prj, this);
                    ProjectList.Add(prjVM);

                    // Check if the project image exist
                    if (prjVM.ProjectImage == null)
                    {
                        // Add name to list to later create image
                        missingImageList.Add(prjVM);

                        // Get the project for the image name
                        //Project project = _pm.GetProject(prjVM.ProjectName);

                        //// If the project image does not exist, create the image now
                        //if (!File.Exists(project.GetProjectImagePath()))
                        //{
                        //    Task.Run(() =>
                        //    {
                        //        prjVM.RefreshDisplay();
                        //        this.NotifyOfPropertyChange(() => this.ProjectList);
                        //    });
                        //}
                    }

                    // Set the last selected project
                    if (prj.ProjectID == _pm.GetSelectedProjectID())
                    {
                        if (_pm.IsProjectSelected)
                        {
                            _SelectedProjectVM = prjVM;
                        }
                        else
                        {
                            SelectedProjectVM = prjVM;
                        }
                        _SelectedProjectVM.IsSelected = true;
                        this.NotifyOfPropertyChange(() => this.SelectedProjectVM);
                    }

                    prj.Dispose();
                }));
            }

            //// Load the missing project images 1 at a time.
            //// If a load them all it once, it takes to much memory
            //foreach (var prjVM in missingImageList)
            //{
            //    //Get the project for the image name
            //    Project project = _pm.GetProject(prjVM.ProjectName);

            //    // If the project image does not exist, create the image now
            //    if (!File.Exists(project.GetProjectImagePath()))
            //    {
            //        Task.Run(() =>
            //        {
            //            prjVM.RefreshDisplay();
            //            this.NotifyOfPropertyChange(() => this.ProjectList);
            //        });
            //    }
            //}

            IsProjectLoading = false;
        }