protected override void AddSubpaths(List <IModule> activeModules, PathIdentifier identifier) { if (PackageIdentifier == null) { return; } var processor = new PathProcessor(identifier); processor.Read(state.Folder, skipFolderPaths: true, pathReader: f => { var sharePath = f.MetaEDiscoveryPathIdentifierRead(); if (PackageIdentifier.PathKey != EDiscoveryUtility.E_DISCOVERY_ALL_PACKAGE_PATH_KEY && f.Read <string>(MetadataKeyConstants.E_DISCOVERY_SHARE_PACKGAGE) != PackageName && f.Read <string>(MetadataKeyConstants.E_DISCOVERY_SHARE_PACKGAGE) != null) { return(null); } if (sharePath != null) { return(PackageIdentifier.CreateChild(sharePath.PathKey)); } else { return(sharePath); } }); var paths = RelativePathIdentifier != null ? processor[PackageIdentifier.CreateChild(RelativePathIdentifier.PathKey)].Paths : processor[PackageIdentifier].Paths; foreach (var p in paths) { allRows.Add(new ManagerPathModel { Identifier = p.Identifier, AllowedOperations = GetSubPathOperations(activeModules, p.Identifier), FullPath = p.FullPath, Icons = p.Icons, Name = p.Name, Paths = null }); } base.AddSubpaths(activeModules, identifier); }
public EDiscoveryManagerPathModel GetNotSharedYetPath(FolderModel folder) { // We need to get the staged count, as it will allow us to A. determine if we're going to show the not shared yet folder, // and B. a cound on the not shared yet folder. var stagedCount = EDiscoveryUtility.GetStagedCount(folder); var notSharedIdentifier = new PathIdentifier(folder.Identifier, EDiscoveryUtility.E_DISCOVERY_NOT_SHARED_PATH_KEY); var processor = new PathProcessor(folder.Identifier); processor.Read(folder, skipFolderPaths: true, pathReader: f => { if (f.ShareState() != EDiscoveryShareState.Staged) { return(null); } var sharePath = f.MetaEDiscoveryPathIdentifierRead(); if (sharePath != null) { return(notSharedIdentifier.CreateChild(sharePath.PathKey)); } return(null); }); return(new EDiscoveryManagerPathModel() { Identifier = notSharedIdentifier, Icons = new string[] { EDiscoveryUtility.EDISCOVERY_FOLDER_COLOR_STYLE }, Name = $"Not Shared Yet ({stagedCount.ToString()})", FullPath = "eDiscovery/Not Shared Yet", AllowedOperations = null, Paths = processor[notSharedIdentifier]?.Paths }); }
public PathIdentifier GetOfficerPath(FolderIdentifier folderIdentifier, string firstName, string lastName) { var leoUploadFolder = new PathIdentifier(folderIdentifier, LEOUploadUtility.LEO_UPLOAD_PATH_KEY); // Here we're adding a child folder to the leo upload whenever we add a new officer. var childPath = leoUploadFolder.CreateChild($"{firstName} {lastName}"); return(childPath); }
public List <EDiscoveryManagerPathModel> BuildDatedPackagesDynamicFolder(FolderModel folder) { var managerPaths = new List <EDiscoveryManagerPathModel>(); var packageMap = folder.Read <EDiscoveryPackageMap>(MetadataKeyConstants.E_DISCOVERY_PACKAGE_MAP_METAKEY); if (this.IsModuleActive(folder)) { // go through all the folders, and find all the foreach (var file in folder.Files.Rows .Where(f => f.Read <string>(MetadataKeyConstants.E_DISCOVERY_SHARE_PACKGAGE) != null) ) { var sharePackageName = file.Read <string>(MetadataKeyConstants.E_DISCOVERY_SHARE_PACKGAGE); var sharePackageIdentifier = new PathIdentifier(file.Identifier as FolderIdentifier, "eDiscovery/" + sharePackageName); // Here we're checking to make sure we haven't already added this 'dated share folder' if (!managerPaths.Any(mp => mp.Identifier.Equals(sharePackageIdentifier))) { var processor = new PathProcessor(folder.Identifier); processor.Read(folder, skipFolderPaths: true, pathReader: f => { var sharePath = f.MetaEDiscoveryPathIdentifierRead(); if (sharePackageName != null && f.Read <string>(MetadataKeyConstants.E_DISCOVERY_SHARE_PACKGAGE) != sharePackageName) { return(null); } if (sharePath != null) { return(sharePackageIdentifier.CreateChild(sharePath.PathKey)); } else { return(sharePath); } }); var packagePath = new EDiscoveryManagerPathModel() { Identifier = sharePackageIdentifier, Icons = new string[] { EDiscoveryUtility.EDISCOVERY_FOLDER_COLOR_STYLE }, Name = sharePackageName, FullPath = sharePackageIdentifier.FullName, Paths = processor[sharePackageIdentifier]?.Paths, CustomName = EDiscoveryUtility.GetCustomName(packageMap, sharePackageName), AllowedOperations = EDiscoveryUtility.IsUserEDiscovery(connection.UserAccessIdentifiers) ? new AllowedOperation[] { } : new AllowedOperation[] { AllowedOperation.GetAllowedOperationEditPackageName(folder.Identifier, sharePackageName) }, }; managerPaths.Add(packagePath); } } } return(managerPaths); }
public async Task <ActionResult> UploadChunk( PathIdentifier pathIdentifier, BrowserFileInformation fileInformation, string token, CancellationToken cancellationToken = default(CancellationToken) ) { if (!Request.ContentLength.HasValue) { throw new Exception("Missing Content-Length header"); } if (Request.Headers["Content-Range"].Count == 0) { throw new Exception("Missing Content-Range header"); } if (Request.Headers["Content-Disposition"].Count == 0) { throw new Exception("Missing Content-Disposition header"); } var range = ContentRangeHeaderValue.Parse(Request.Headers["Content-Range"]); if (!range.HasLength) { throw new Exception("Content-Range header does not include total length"); } long from = (long)range.From; long to = (long)range.To; long fileLength = (long)range.Length; var fileName = fileInformation?.Name; if (fileName == null) { var contentDisposition = ContentDispositionHeaderValue.Parse(Request.Headers["Content-Disposition"]); fileName = contentDisposition?.FileName; if (fileName == null) { throw new Exception("Filename is not specified in either Content-Disposition header or fileInformation"); } // for some dumb reason, the ContentDispositionHeaderValue parser doesn't finish parsing file names // it leaves them quoted if (fileName.StartsWith('"') && fileName.EndsWith('"') && fileName.Length > 1) { fileName = WebUtility.UrlDecode(fileName.Substring(1, fileName.Length - 2)); } } Stream stream = Request.Body; UploadContextModel tokenState = null; // test retries //if ((new Random()).NextDouble() < .3) // throw new Exception("Chaos Monkey"); bool isFirstChunk = from == 0; bool isLastChunk = to == (fileLength - 1); FileIdentifier fileIdentifier = null; var folderModel = await Connection.Folder.GetOrThrowAsync(pathIdentifier); var modules = ModuleConfigurator.GetActiveModules(folderModel); // === Step 1: Begin Upload if (isFirstChunk) { var fileModel = new FileModel { Identifier = new FileIdentifier(pathIdentifier, null), Name = fileName, Modified = fileInformation?.LastModified != null ? epoch.AddMilliseconds(fileInformation.LastModified.Value) : DateTime.UtcNow, Length = fileLength, MimeType = fileInformation?.Type ?? Request.ContentType ?? "application/octet-stream", }.InitializeEmptyMetadata(); fileModel.Created = new DateTime(Math.Min(DateTime.UtcNow.Ticks, fileModel.Modified.Ticks), DateTimeKind.Utc); // some browsers will send us the relative path of a file during a folder upload var relativePath = fileInformation?.FullPath; if (!string.IsNullOrWhiteSpace(relativePath) && relativePath != "/") { if (relativePath.StartsWith("/")) { relativePath = relativePath.Substring(1); } pathIdentifier = pathIdentifier.CreateChild(relativePath); } fileModel.MetaPathIdentifierWrite(pathIdentifier); foreach (var module in modules) { await module.PreUploadAsync(folderModel, fileModel); } tokenState = await Connection.File.UploadBeginAsync(fileModel, cancellationToken : cancellationToken); } else { if (token == null) { throw new Exception("Uploaded secondary chunk without token"); } tokenState = JsonConvert.DeserializeObject <UploadContextModel>(token); } // === Step 2: Send this Chunk using (stream) { if (!isLastChunk) { if (to - from != tokenState.ChunkSize - 1) { throw new Exception($"Chunk Size Mismatch: received ({to - from}) expected ({tokenState.ChunkSize})"); } } int chunkIndex = (int)(from / tokenState.ChunkSize); tokenState = await Connection.File.UploadSendChunkAsync( tokenState, chunkIndex, from, to, stream, cancellationToken : cancellationToken ); } // === Step 3: End the Upload if (isLastChunk) // if file is one chunk, all three steps happen in a single call { var fileModel = await Connection.File.UploadEndAsync(tokenState, cancellationToken : cancellationToken); fileIdentifier = fileModel.Identifier; foreach (var module in modules) { await module.PostUploadAsync(folderModel, fileModel); } } return(Json(new APIResponse <UploadedFileResponse> { Response = new UploadedFileResponse { FileIdentifier = fileIdentifier, Token = JsonConvert.SerializeObject(tokenState) } })); }
public override void BuildDynamicFolders(PathIdentifier identifier, ItemQueryResponse page, FolderModel folder, bool isRestrictedView) { if (!page?.PathTree?.Paths?.Any(p => p.Identifier.PathKey == EDiscoveryUtility.E_DISCOVERY_PATH_KEY) ?? false) { if (page.PathTree.Paths == null) { page.PathTree.Paths = new List <ManagerPathModel>(); } var managerPathModels = new List <ManagerPathModel>(); // we have to build up the children first. // First we get all the dated package dynamic paths. var datedPackagePaths = BuildDatedPackagesDynamicFolder(folder); var eDiscoveryIdentifier = new PathIdentifier(identifier) { PathKey = EDiscoveryUtility.E_DISCOVERY_PATH_KEY }; // Last the parent / root node of 'eDiscovery' var eDiscoveryPath = new ManagerPathModel { Identifier = eDiscoveryIdentifier, Icons = new string[] { EDiscoveryUtility.EDISCOVERY_FOLDER_COLOR_STYLE }, Name = EDiscoveryUtility.E_DISCOVERY_PATH_NAME, FullPath = EDiscoveryUtility.E_DISCOVERY_PATH_KEY, AllowedOperations = null, Paths = new List <ManagerPathModel>(), IsExpanded = datedPackagePaths.Count > 0 || EDiscoveryUtility.GetStagedCount(folder) > 0, }; if (datedPackagePaths.Any()) { var allPackagesIdentifier = new PathIdentifier(identifier as FolderIdentifier, EDiscoveryUtility.E_DISCOVERY_ALL_PACKAGE_PATH_KEY); var packageName = "All"; var processor = new PathProcessor(folder.Identifier); processor.Read(folder, skipFolderPaths: true, pathReader: f => { var sharePath = f.MetaEDiscoveryPathIdentifierRead(); if (sharePath != null) { return(allPackagesIdentifier.CreateChild(sharePath.PathKey)); } else { return(sharePath); } }); datedPackagePaths.Insert(0, new EDiscoveryManagerPathModel() { Identifier = allPackagesIdentifier, Icons = new string[] { EDiscoveryUtility.EDISCOVERY_FOLDER_COLOR_STYLE }, Name = packageName, FullPath = allPackagesIdentifier.FullName, Paths = processor[allPackagesIdentifier]?.Paths }); } eDiscoveryPath.Paths = eDiscoveryPath.Paths.Concat(datedPackagePaths).ToList(); if (!isRestrictedView) { eDiscoveryPath.Paths.Add(GetNotSharedYetPath(folder)); } page.PathTree.Paths.Add(eDiscoveryPath); } }