private DirectoryEntity GetDirectoryWithLoad(long?id, List <DirectoryInfo> cacheDirectoryInfos, List <DirectoryEntity> cacheDirectoryEntities, List <DirectoryEntity> entitiesToInsert) { DirectoryEntity directory = id.HasValue ? GetDirectory(id.Value, cacheDirectoryEntities) : null; if (id.HasValue && directory == null) { DirectoryInfo directoryInfo = cacheDirectoryInfos?.FirstOrDefault(x => x.Id == id.Value); if (directoryInfo == null) { directoryInfo = webService.GetDirectoryInfo(id.Value); if (directoryInfo != null) { cacheDirectoryInfos?.Add(directoryInfo); } } if (directoryInfo != null) { directory = Create(directoryInfo, cacheDirectoryInfos, cacheDirectoryEntities, entitiesToInsert); } } return(directory); }
protected void btnSave_Click(object sender, EventArgs e) { string msg = string.Empty; if (!CheckInput(out msg)) { ShowMessageToClient(msg, 2, false, false); return; } if (rbtnNewDirectory.Checked) { DirectoryEntity model = GetDirectory(); int id = fileApp.UpdateDirectory(model); if (id > 0) { this.ShowSuccessMessageToClient(); } else { this.ShowFailMessageToClient(fileApp.BrokenRuleMessages, false); } } else if (rbtnNewFile.Checked) { FilesEntity model = GetFile(); if (fileApp.UpdateFile(model)) { ShowSuccessMessageToClient(true, true); } else { ShowFailMessageToClient(fileApp.BrokenRuleMessages, false); } } }
public List <DirectoryEntity> GetAllDirectories() { StringBuilder strSql = new StringBuilder(); strSql.Append("select d.*,'Directory' as Type,u.FirstName,u.LastName,u.UserName,ID as ObjectID "); strSql.Append(" FROM Directories d left join Users u on d.CreatedBy=u.UserID "); Database db = DatabaseFactory.CreateDatabase(); using (DbCommand dbCommand = db.GetSqlStringCommand(strSql.ToString())) { try { using (IDataReader dataReader = db.ExecuteReader(dbCommand)) { List <DirectoryEntity> list = new List <DirectoryEntity>(); while (dataReader.Read()) { list.Add(DirectoryEntity.ReaderBind(dataReader)); } return(list); } } catch (Exception ex) { return(null); } } }
private IEnumerable <IEntity> ExecuteImpl(ExecutionOptions options) { // determine an optimal search order var searchOrder = _priorityComparerFactory.Create(Predicate); var files = EnumeratePaths(options.Progress, options.CancellationToken, searchOrder); // execute the query using (var reader = _entityManager.CreateReader()) { foreach (var file in files) { options.Progress.Report(new QueryProgressReport(ReportType.BeginLoading, file.Path)); IEntity entity = null; if (file.IsFile) { entity = LoadEntity(reader, file.Path); } else // file is a directory { entity = new DirectoryEntity(file.Path); } options.Progress.Report(new QueryProgressReport(ReportType.EndLoading, file.Path)); if (entity != null && CompiledPredicate(entity)) { yield return(entity); } } } options.Progress.Report(new QueryProgressReport(ReportType.EndExecution, null)); }
public DirectoryItem(IDataService dataService, DirectoryEntity entity) { this.dataService = dataService; Entity = entity; Selected = false; Subdirectories = new List <DirectoryItem>(); }
private void Update(CatalogItemEntity entity, CatalogInfo catalogInfo) { BrandItemEntity brandItem = GetBrandWithLoad(catalogInfo.BrandId); DirectoryEntity directory = GetDirectoryWithLoad(catalogInfo.DirectoryId); List <PhotoItemEntity> photos = GetPhotosWithLoad(catalogInfo.Photos); entity.Id = catalogInfo.Id; entity.UID = catalogInfo.UID; entity.Code = catalogInfo.Code; entity.Article = catalogInfo.Article; entity.Brand = brandItem; entity.BrandName = brandItem?.Name; entity.Name = catalogInfo.Name; entity.Unit = catalogInfo.Unit; entity.EnterpriceNormPack = catalogInfo.EnterpriceNormPack; entity.BatchOfSales = catalogInfo.BatchOfSales; entity.Balance = catalogInfo.Balance; entity.Price = catalogInfo.Price; entity.Currency = catalogInfo.Currency; entity.Multiplicity = catalogInfo.Multiplicity; entity.HasPhotos = catalogInfo.HasPhotos; entity.Photos = photos; entity.DateOfCreation = catalogInfo.DateOfCreation; entity.LastUpdated = catalogInfo.LastUpdated; entity.ForceUpdated = catalogInfo.ForceUpdated; entity.Status = LoadAssembler.Convert(catalogInfo.Status); entity.LastUpdatedStatus = catalogInfo.LastUpdatedStatus; entity.Directory = directory; }
public void LoadParent(DirectoryEntity entity) { if (!DataBaseContext.Entry(entity).Reference(p => p.Parent).IsLoaded) { DataBaseContext.Entry(entity).Reference(p => p.Parent).Load(); } }
public void Move( [FromQuery] string from, [FromQuery] string to) { if (string.IsNullOrWhiteSpace(from)) { from = ""; } if (string.IsNullOrWhiteSpace(to)) { to = ""; } var rootDirectory = DirectoryEntity.FromPath(Startup.Configuration[Startup.RootDirectory]); string fromFullPath = System.IO.Path.Combine(Startup.Configuration[Startup.RootDirectory], from); string toFullPath = System.IO.Path.Combine(Startup.Configuration[Startup.RootDirectory], to); // get the file attributes for file or directory FileAttributes fromAttr = System.IO.File.GetAttributes(fromFullPath); if (fromAttr == FileAttributes.Directory) { DirectoryEntity.FromPath(fromFullPath).Move(toFullPath); } else { FileEntity.FromPath(fromFullPath).Move(toFullPath); } }
private void Scan(DirectoryEntity d) { foreach (FileEntity f in d.Files) { f.Read(); for (int i = 0; f.RowCount > i; ++i) { foreach (Condition c in conditions) { c.Test(f.Get[i], i); } } foreach (Condition c in conditions) { if (0 < c.Hit.Count) { foreach (Match m in c.Hit) { m.Path = f.Path; m.Pattern = c.ToString(); Hit.Add(m); } } c.Init(); } f.Clear(); } foreach (DirectoryEntity subD in d.SubDirectories) { Scan(subD); } }
[HttpPut] //[FromBody] Json, que vai conter um userEntity public async Task <ActionResult> Put([FromBody] DirectoryEntity entity) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } try { var result = await _service.Put(entity); if (result != null) { return(Ok(result)); } else { return(BadRequest()); } } catch (ArgumentException ex) { return(StatusCode((int)HttpStatusCode.InternalServerError, ex.Message)); } }
[HttpPost] //[FromBody] Json, que vai conter um userEntity public async Task <ActionResult> Post([FromBody] DirectoryEntity entity) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } try { var result = await _service.Post(entity); if (result != null) { return(Created(new Uri(Url.Link("GetDiretoryWithId", new { id = result.Id })), result)); } else { return(BadRequest()); } } catch (ArgumentException ex) { return(StatusCode((int)HttpStatusCode.InternalServerError, ex.Message)); } }
public List <DirectoryEntity> GetObjects(int parentID) { StringBuilder strSql = new StringBuilder(); strSql.Append(@"select do.ID,do.Logo,do.[Type],do.ObjectID,t.Title,t.[Description],do.CreatedOn,do.CreatedBy,do.ModifiedOn,do.ModifiedBy, u.FirstName,u.LastName,u.UserName,@ParentID as ParentID from DirectoryObjects do left join Tickets t on do.ObjectID=t.TicketID left join Users u on do.CreatedBy=u.UserID where DirectoryID=@ParentID and do.Type='Ticket' union all select do.ID,do.Logo,do.[Type],do.ObjectID,f.FileTitle+f.ContentType as Title,f.ThumbPath as [Description],do.CreatedOn,do.CreatedBy,do.ModifiedOn,do.ModifiedBy, u.FirstName,u.LastName,u.UserName,@ParentID as ParentID from DirectoryObjects do left join dbo.Files f on do.ObjectID=f.FileID left join Users u on do.CreatedBy=u.UserID where DirectoryID=@ParentID and do.Type='File'"); StringBuilder strWhere = new StringBuilder(); List <DirectoryEntity> list = new List <DirectoryEntity>(); Database db = DatabaseFactory.CreateDatabase(); using (DbCommand dbCommand = db.GetSqlStringCommand(strSql.ToString())) { try { db.AddInParameter(dbCommand, "ParentID", DbType.Int32, parentID); using (IDataReader dataReader = db.ExecuteReader(dbCommand)) while (dataReader.Read()) { list.Add(DirectoryEntity.ReaderBind(dataReader)); } return(list); } catch (Exception ex) { return(null); } } }
public void Scan(string path) { DirectoryEntity d = new DirectoryEntity(path, Encoding); d.Describe(); Scan(d); }
public static CatalogItemEntity Assemble(CatalogInfo catalogInfo, BrandItemEntity brandItem, List <PhotoItemEntity> photos, DirectoryEntity directory) { CatalogItemEntity catalogItem = new CatalogItemEntity { Id = catalogInfo.Id, UID = catalogInfo.UID, Code = catalogInfo.Code, Article = catalogInfo.Article, Brand = brandItem, BrandName = brandItem?.Name, Name = catalogInfo.Name, Unit = catalogInfo.Unit, EnterpriceNormPack = catalogInfo.EnterpriceNormPack, BatchOfSales = catalogInfo.BatchOfSales, Balance = catalogInfo.Balance, Price = catalogInfo.Price, Currency = catalogInfo.Currency, Multiplicity = catalogInfo.Multiplicity, HasPhotos = catalogInfo.HasPhotos, Photos = photos, DateOfCreation = catalogInfo.DateOfCreation, LastUpdated = catalogInfo.LastUpdated, ForceUpdated = catalogInfo.ForceUpdated, Status = Convert(catalogInfo.Status), LastUpdatedStatus = catalogInfo.LastUpdatedStatus, Directory = directory }; return(catalogItem); }
public static DirectoryViewModel ToMvcDirectory(this DirectoryEntity directory) { return(new DirectoryViewModel { Name = directory.Name, LastAccessTime = directory.LastAccessTime }); }
public void GetDirectories_DirectoryDoesntExist() { var info = new DirectoryInfoWrapper(testFolder); var entity = new DirectoryEntity(info); Directory.Delete(testFolder, true); Assert.Throws(typeof(FileEntityNotFoundException), () => entity.GetDirectories()); }
public PagingWithUrl <IFileSystemItem> List( string path, FileSystemItemType?type, string q, int skip = 0, int take = 10) { if (string.IsNullOrWhiteSpace(path)) { path = ""; } var rootDirectory = DirectoryEntity.FromPath(Startup.Configuration[Startup.RootDirectory]); string fullPath = System.IO.Path.Combine(Startup.Configuration[Startup.RootDirectory], path); IEnumerable <IFileSystemItem> fullResult; if (!string.IsNullOrWhiteSpace(q)) { fullResult = DirectoryEntity.FromPath(fullPath).Search(q); } else { fullResult = DirectoryEntity.FromPath(fullPath).GetChildren(); } fullResult = fullResult.OrderBy(x => x.Type) // 目錄優先 .Where(x => !type.HasValue || x.Type == type.Value) // 類型過濾 .Select(x => { x.RelativePath = x.Path.Substring(rootDirectory.Path.Length).Replace('\\', '/'); if (x.RelativePath[0] == '/') { x.RelativePath = x.RelativePath.Substring(1); } if (x is FileEntity file) { file.DownloadUrl = $"{Request.Scheme}://{Request.Host}/api/File/download?path={Uri.EscapeDataString(x.RelativePath)}&token={Uri.EscapeDataString(BuildToken(file))}"; } return(x); });; return(new PagingWithUrl <IFileSystemItem>(fullResult, skip, take).Process(x => { var builder = new UriBuilder(Request.GetDisplayUrl()); var queryBuilder = new QueryBuilder(); if (type.HasValue) { queryBuilder.Add("type", type.Value.ToString()); } queryBuilder.Add("skip", (skip + take).ToString()); queryBuilder.Add("take", take.ToString()); builder.Query = queryBuilder.ToString(); x.Next = builder.ToString(); })); }
private void SeedFiles(FileUploadSystemDbContext context) { FileManipulator.GenerateStorage(); if (context.Files.Any()) { return; } var sampleData = this.GetSampleFiles("Cats"); var admin = context.Users.Where(u => u.UserName == "Administrator").FirstOrDefault(); AddFilesToUser(context, sampleData, admin); var dir = new DirectoryEntity { Name = "Directory Test", LocationId = -1, Owner = admin, OwnerId = admin.Id }; admin.Files.Add(dir); context.SaveChanges(); var innerDirectory = new DirectoryEntity { Name = "Inner Directory Test", LocationId = dir.Id, Owner = admin, OwnerId = admin.Id }; dir.FilesContained.Add(innerDirectory); context.SaveChanges(); var someFileAgain = new BinaryFile { Name = "someFileAgain" + Path.GetExtension(sampleData[0]), LocationId = innerDirectory.Id, Owner = admin, OwnerId = admin.Id, Size = new FileInfo(sampleData[0]).Length, Type = Path.GetExtension(sampleData[0]) }; innerDirectory.FilesContained.Add(someFileAgain); context.SaveChanges(); FileManipulator.UploadFile(sampleData[0], someFileAgain.Id, Path.GetExtension(sampleData[0])); var anotherUSer = context.Users.Where(u => u.UserName == "AnotherUser").FirstOrDefault(); var dogs = this.GetSampleFiles("Dogs"); AddFilesToUser(context, dogs, anotherUSer); context.SaveChanges(); }
private CatalogItemEntity Create(CatalogInfo catalogInfo) { BrandItemEntity brandItem = GetBrandWithLoad(catalogInfo.BrandId); DirectoryEntity directory = GetDirectoryWithLoad(catalogInfo.DirectoryId); List <PhotoItemEntity> photos = GetPhotosWithLoad(catalogInfo.Photos); CatalogItemEntity entity = LoadAssembler.Assemble(catalogInfo, brandItem, photos, directory); return(entity); }
public void GetFiles() { File.WriteAllText(testFolder + "\\first", null); var info = new DirectoryInfoWrapper(testFolder); var entity = new DirectoryEntity(info); var files = new List <FileSystemEntity>(entity.GetFiles()); Assert.AreEqual(1, files.Count); Assert.AreEqual("first", files[0].Name); }
public void GetDataTest() { var directoryInfo = new Mock <IDirectoryInfo>(); directoryInfo.Setup(x => x.Exists).Returns(true); directoryInfo.Setup(x => x.Length).Returns(10); var entity = new DirectoryEntity(directoryInfo.Object); Assert.Throws(typeof(NotSupportedException), () => entity.GetData()); }
public void GetParentDirectoryTest() { const string dirName = testFolder + "\\hello"; Directory.CreateDirectory(dirName); var info = new DirectoryInfoWrapper(dirName); var entity = new DirectoryEntity(info); Assert.AreEqual("testFolder", entity.GetParentDirectory().Name); }
public void GetDirectories() { Directory.CreateDirectory(testFolder + "\\dir"); var info = new DirectoryInfoWrapper(testFolder); var entity = new DirectoryEntity(info); var dirs = new List <FileSystemEntity>(entity.GetDirectories()); Assert.AreEqual(1, dirs.Count); Assert.AreEqual("dir", dirs[0].Name); }
private DirectoryEntity GetDirectoryWithLoad(long?id) { List <DirectoryInfo> cacheDirectoryInfos = new List <DirectoryInfo>(); List <DirectoryEntity> cacheDirectoryEntities = new List <DirectoryEntity>(); List <DirectoryEntity> entitiesToInsert = new List <DirectoryEntity>(); DirectoryEntity entity = GetDirectoryWithLoad(id, cacheDirectoryInfos, cacheDirectoryEntities, entitiesToInsert); dataService.DataBaseContext.DirectoryEntities.AddRange(entitiesToInsert); return(entity); }
private DirectoryEntity GetDirectory() { DirectoryEntity model = FileFactory.CreateDirectoryEntity(UserInfo.ID, ObjectFactory.GetInstance <ISystemDateTime>()); model.Description = txtDesc.Text.NoHTML(); model.Logo = "Directory.png"; model.Title = txtTitle.Text.NoHTML(); model.ParentID = int.Parse(ddlCurrent.SelectedValue); model.Type = DirectoryObjectType.Directory.ToString(); return(model); }
public int Insert(DirectoryEntity model) { StringBuilder strSql = new StringBuilder(); strSql.Append("IF not Exists(select 1 from Directories where ID=@ID) begin "); strSql.Append("insert into Directories("); strSql.Append("Title,Description,Logo,CreatedOn,CreatedBy,ModifiedOn,ModifiedBy,ParentID)"); strSql.Append(" values ("); strSql.Append("@Title,@Description,@Logo,@CreatedOn,@CreatedBy,@ModifiedOn,@ModifiedBy,@ParentID)"); strSql.Append(";select ISNULL( SCOPE_IDENTITY(),0); end "); strSql.Append(" else begin "); strSql.Append(" update Directories set "); strSql.Append("Title=@Title,"); strSql.Append("Description=@Description,"); strSql.Append("Logo=@Logo,"); strSql.Append("CreatedOn=@CreatedOn,"); strSql.Append("CreatedBy=@CreatedBy,"); strSql.Append("ModifiedOn=@ModifiedOn,"); strSql.Append("ModifiedBy=@ModifiedBy,"); strSql.Append("ParentID=@ParentID"); strSql.Append(" where ID=@ID; "); strSql.Append(" select @ID; "); strSql.Append(" end "); Database db = DatabaseFactory.CreateDatabase(); using (DbCommand dbCommand = db.GetSqlStringCommand(strSql.ToString())) { try { db.AddInParameter(dbCommand, "ID", DbType.Int32, model.ID); db.AddInParameter(dbCommand, "Title", DbType.AnsiString, model.Title); db.AddInParameter(dbCommand, "Description", DbType.AnsiString, model.Description); db.AddInParameter(dbCommand, "Logo", DbType.AnsiString, model.Logo); db.AddInParameter(dbCommand, "CreatedOn", DbType.DateTime, model.CreatedOn); db.AddInParameter(dbCommand, "CreatedBy", DbType.Int32, model.CreatedBy); db.AddInParameter(dbCommand, "ModifiedOn", DbType.DateTime, model.ModifiedOn); db.AddInParameter(dbCommand, "ModifiedBy", DbType.Int32, model.ModifiedBy); db.AddInParameter(dbCommand, "ParentID", DbType.Int32, model.ParentID); int result; object obj = db.ExecuteScalar(dbCommand); if (!int.TryParse(obj.ToString(), out result)) { return(0); } return(result); } catch (Exception ex) { WebLogAgent.Write(string.Format("[SQLText:{0},{1}Messages:\r\n{2}]", strSql.ToString(), base.FormatParameters(dbCommand.Parameters), ex.Message)); return(0); } } }
public void LengthTest() { var directoryInfo = new Mock <IDirectoryInfo>(); directoryInfo.Setup(x => x.Exists).Returns(true); directoryInfo.Setup(x => x.Length).Returns(10); var entity = new DirectoryEntity(directoryInfo.Object); Assert.AreEqual(10, entity.Length); }
private DirectoryEntity GetDirectory() { DirectoryEntity model = fileApp.GetDirectory(QS("id", 0)); model.Description = txtDesc.Text.NoHTML(); model.Logo = "Directory.png"; model.Title = txtTitle.Text.NoHTML(); model.ParentID = int.Parse(ddlCurrent.SelectedValue); return(model); }
protected FolderHierarchy createFolderHierarchy(DirectoryEntity dir, Guid currentId) { return(new FolderHierarchy() { IsCurrent = dir.Id == currentId, Parent = dir.Parent, Name = dir.Name, Id = dir.Id, ChildFolders = new List <FolderHierarchy>() }); }
public void TestMethod1() { DirectoryEntity d = new DirectoryEntity(@"./a", @"UTF-8"); d.Describe(); Assert.AreEqual(@"a1.txt", d.Files[0].Name); Assert.AreEqual(@"ab", d.SubDirectories[0].Name); Assert.AreEqual(@"ac", d.SubDirectories[1].Name); Assert.AreEqual(@"ab1.txt", d.SubDirectories[0].Files[0].Name); Assert.AreEqual(@"ac1.txt", d.SubDirectories[1].Files[0].Name); }
public static DirectoryEntity ReadDirectory(string strPathBase) { if (!strPathBase.EndsWith(Path.DirectorySeparatorChar.ToString())) { strPathBase += Path.DirectorySeparatorChar; } var targetFolder = new DirectoryInfo(strPathBase); if ((targetFolder.Exists == false)) { return null; } var objDirectoryEntity = new DirectoryEntity(); objDirectoryEntity.Name = targetFolder.Name; objDirectoryEntity.FullPath = strPathBase; return objDirectoryEntity; }
protected void GetSubDirectories() { var targetFolder = new DirectoryInfo(FullPath); DirectoryInfo[] strArrayDirectories = targetFolder.GetDirectories(); _subDirectories = new DirectoryEntity[strArrayDirectories.Length]; DirectoryEntity objDirectoryEntity; for (int i = 0; i < strArrayDirectories.Length; i++) { objDirectoryEntity = new DirectoryEntity(); objDirectoryEntity.Name = strArrayDirectories[i].Name; objDirectoryEntity.FileSearchExtension = FileSearchExtension; objDirectoryEntity.FullPath = FullPath + objDirectoryEntity.Name + Path.DirectorySeparatorChar; _subDirectories[i] = objDirectoryEntity; } }