public ProjectFileViewModel(ProjectFilePath path, ShqContext db)
        {
            this.Name = System.IO.Path.GetFileName(path.Path);
            this.Path = path.Path;

            FileInfo fi = new FileInfo(path.FullPath);

            this.Size            = fi.Length;
            this.CreatedTime     = fi.CreationTime.ToString();
            this.LastModfiedTime = fi.LastWriteTime.ToString();

            Id = ShqConstants.GetPathId(path.Path);
            if (Id > 0)
            {
                this.Name = System.IO.Path.GetFileNameWithoutExtension(this.Name);

                var f = db.ProjectFiles.FirstOrDefault(item => item.Id == Id);
                if (f == null)
                {
                    this.Name = "";
                }
                else
                {
                    this.Privilege = f.Privilege;

                    CreatedBy   = new ShqUserRequestViewModel(db.ShqUsers.Where(u => u.IdentityUser.Id == db.ProjectFiles.FirstOrDefault(item => item.Id == Id).CreatedById).FirstOrDefault(), db);
                    CreatedTime = f.CreatedTime.ToString();

                    LastModifiedBy  = new ShqUserRequestViewModel(db.ShqUsers.Where(u => u.IdentityUser.Id == db.ProjectFiles.FirstOrDefault(item => item.Id == Id).LastModifiedById).FirstOrDefault(), db);
                    LastModfiedTime = f.LastModfiedTime.ToString();

                    this.Level = f.Level;
                }
            }
        }
示例#2
0
        public ProjectFolderViewModel(ProjectFilePath path, SearchOption searchOption, ShqContext db, int folderLevel = 1)
        {
            this.Path = path.Path;
            this.Name = System.IO.Path.GetFileName(path.Path);

            Id = ShqConstants.GetPathId(path.Path);
            if (Id > 0)
            {
                this.Name = System.IO.Path.GetFileNameWithoutExtension(this.Name);
                var f = db.ProjectFiles.FirstOrDefault(item => item.Id == Id);
                if (f == null)
                {
                    this.Name = "";
                }
                else
                {
                    CreatedBy   = new ShqUserRequestViewModel(db.ShqUsers.Where(u => u.IdentityUser.Id == db.ProjectFiles.FirstOrDefault(item => item.Id == Id).CreatedById).FirstOrDefault(), db);
                    CreatedTime = f.CreatedTime.ToString();

                    LastModifiedBy  = new ShqUserRequestViewModel(db.ShqUsers.Where(u => u.IdentityUser.Id == db.ProjectFiles.FirstOrDefault(item => item.Id == Id).LastModifiedById).FirstOrDefault(), db);
                    LastModfiedTime = f.LastModfiedTime.ToString();

                    this.Privilege = f.Privilege;
                    this.Level     = f.Level;
                }
            }

            if (this.Name == "")
            {
                return;
            }

            if ((searchOption == SearchOption.TopDirectoryOnly && folderLevel == 1) || searchOption == SearchOption.AllDirectories)
            {
                string[] directory, files;
                directory = Directory.GetDirectories(path.FullPath);
                files     = Directory.GetFiles(path.FullPath);

                if (directory != null && directory.Length > 0)
                {
                    foreach (var d in directory)
                    {
                        var pf = new ProjectFolderViewModel(new ProjectFilePath {
                            FullPath = d, Path = System.IO.Path.Combine(path.Path, System.IO.Path.GetFileName(d))
                        }, searchOption, db, folderLevel);
                        if (pf.Name != "")
                        {
                            this.SubFolders.Add(pf);
                        }
                    }

                    if (this.SubFolders != null && this.SubFolders.Count > 0)
                    {
                        this.SubFolders.Sort((x, y) => x.Name.CompareTo(y.Name));
                    }
                }

                if (files != null && files.Length > 0)
                {
                    foreach (var f in files)
                    {
                        var ff = new ProjectFileViewModel(new ProjectFilePath {
                            FullPath = f, Path = System.IO.Path.Combine(path.Path, System.IO.Path.GetFileName(f))
                        }, db);
                        if (ff.Name != "")
                        {
                            this.Files.Add(ff);
                        }
                    }

                    if (this.Files != null && this.Files.Count > 0)
                    {
                        this.Files.Sort((x, y) => x.Name.CompareTo(y.Name));
                    }
                }

                folderLevel--;
            }
        }