Example #1
0
        public PickPTabViewModel(IStatusNotificationService statusNotificationServiceParam,
                                 ITabNavigationService tabNavigationServiceParam,
                                 IDatabaseService databaseServiceParam,
                                 IProjectDataService projectDataServiceParam)
        {
            statusNotificationService       = statusNotificationServiceParam;
            tabNavigationService            = tabNavigationServiceParam;
            databaseService                 = databaseServiceParam;
            projectDataService              = projectDataServiceParam;
            databaseService.DatabaseChange += DatabaseService_DatabaseChange;

            //Initialize commands.
            ProjectCreateCommand = new AnotherCommandImplementation(t =>
            {
            });

            ProjectOpenCommand = new AnotherCommandImplementation(t =>
            {
                if (CommonFileDialog.IsPlatformSupported)
                {
                    CommonOpenFileDialog folderDialog = new CommonOpenFileDialog("Project Picker")
                    {
                        IsFolderPicker = true,
                    };

                    var diagRes = folderDialog.ShowDialog();
                    if (diagRes == CommonFileDialogResult.Ok)
                    {
                        ProjectLoading(folderDialog.FileName);
                    }
                }
                else
                {
                    statusNotificationService.SendMessage(new Notification()
                    {
                        Kind = NotificationKind.Error, Message = "This Application requires Windows Vista(I think) or up, because I simply refuse to also spawn the classic folder picker. Sorry.", Title = "For the love of everything holy: UPDATE!", Time = DateTime.Now
                    });
                }
            });

            ProjectSelectCommand = new AnotherCommandImplementation(o =>
            {
                if (o is RecentProject project)
                {
                    ProjectLoading(project.Location);
                }
                else
                {
                    statusNotificationService.SendMessage(new Notification()
                    {
                        Kind = NotificationKind.Error, Message = "The picker failed to load the selected project. There might be an issue with the database.", Title = "Loading Failure", Time = DateTime.Now
                    });
                    // TODO: add interaction to remove reference from picker.
                }
            }
                                                                    );
        }
        public ProjectViewModel(IStatusNotificationService statusNotificationServiceParam, IProjectDataService projectDataServiceParam, ITabNavigationService tabNavigationServiceParam)
        {
            ProjectFiles = new ObservableCollection <BaseMd>();

            tabNavigationService              = tabNavigationServiceParam;
            statusNotificationService         = statusNotificationServiceParam;
            projectDataService                = projectDataServiceParam;
            projectDataService.ProjectLoaded += ProjectDataService_ProjectLoaded;

            ViewTeamCommand = new AnotherCommandImplementation(t =>
            {
                statusNotificationServiceParam.SendMessage(new Notification()
                {
                    Kind = NotificationKind.Other, Message = t.ToString(), Title = "DEBUG Team", Time = DateTime.Now
                });
            });

            ViewReadmeCommand = new AnotherCommandImplementation(r =>
            {
                if (r is ReadMe readMe)
                {
                    tabNavigationService.CreateTab("ReadMeTab", r);
                }
            });
        }
        public bool LoadProject(string projectPath)
        {
            if (Directory.Exists(projectPath))
            {
                if (Repository.IsValid(projectPath))
                {
                    var repo = new Repository(projectPath);
                    // Store new repo in to the recent projects table.
                    RecentProject project = databaseService.WriteInDb(() =>
                    {
                        RecentProject foundProject;

                        using (var db = new LiteDatabase(App.DbPath))
                        {
                            var col = db.GetCollection <RecentProject>();
                            var res = Path.GetFileNameWithoutExtension(projectPath);

                            foundProject = col.FindOne(f => f.Location == projectPath && f.Name == res);
                            foundProject = new RecentProject()
                            {
                                Id = foundProject?.Id ?? 0, Date = DateTime.Now, Name = res, Location = projectPath
                            };

                            // Need to test Upsert a lot more.
                            col.Upsert(foundProject);

                            //if (find == null)
                            //{
                            //    col.Insert(new RecentProject() { Date = DateTime.Now, Name = res, Location = folderDialog.FileName });
                            //}
                            //else
                            //{
                            //    find.Date = DateTime.Now;
                            //    col.Update(find);
                            //}
                        }

                        return(foundProject);
                    }, nameof(RecentProject));

                    ProjectPath = projectPath;

                    // Read all relevant md files

                    var mdFilePaths = Directory.GetFiles(projectPath, "*.md", SearchOption.TopDirectoryOnly);

                    var resTeam = from mdFile in mdFilePaths
                                  where mdFile.ToLower().EndsWith("team.md")
                                  select new Team()
                    {
                        LastUpdate   = File.GetLastWriteTime(mdFile),
                        FileName     = Path.GetFileName(mdFile),
                        FullFileName = mdFile
                    };


                    var resReadMe = from mdFile in mdFilePaths
                                    where mdFile.ToLower().EndsWith(".md")
                                    select new ReadMe()
                    {
                        Text         = CreateMarkup(mdFile),
                        LastUpdate   = File.GetLastWriteTime(mdFile),
                        FileName     = Path.GetFileName(mdFile),
                        FullFileName = mdFile
                    };

                    //var resOther = from mdFile in mdFilePaths
                    //               where mdFile.ToLower().EndsWith(".md") //&& !resReadMe.Contains<BaseMd>(mdFile)
                    //               select new BaseMd() { Text = File.ReadAllText(Path.Combine(projectPath, mdFile)) };


                    var castedProjectFiles = ProjectFiles as List <BaseMd>;
                    castedProjectFiles.Clear();
                    castedProjectFiles.AddRange(resTeam);

                    // NOTE: reworked it to show every kind of MD file other than 'Team' as 'ReadMe' due to time constraints. - 22 Jan 18

                    foreach (var item in resReadMe)
                    {
                        castedProjectFiles.Remove(item);
                    }
                    castedProjectFiles.AddRange(resReadMe);
                    //                    castedProjectFiles.AddRange(resOther);

                    ProjectLoaded?.Invoke(project, new EventArgs());
                    return(true);
                }
                else
                {
                    statusNotificationService.SendMessage(new Notification()
                    {
                        Kind    = NotificationKind.Warning,
                        Message = "The directory is not a valid git repo.",
                        Title   = "Invalid Repo",
                        Time    = DateTime.Now
                    });
                    return(false);
                }
            }
            else
            {
                statusNotificationService.SendMessage(new Notification()
                {
                    Kind    = NotificationKind.Warning,
                    Message = "The remembered directory does not exist (anymore).",
                    Title   = "Not Found",
                    Time    = DateTime.Now
                });
                return(false);
            }
        }