public ProjectDocumentImporter(string folder, string templateFolder) { this._rootFolder = folder; this._templateFolder = templateFolder; ProcessFolder(folder, null, string.Empty); CLLogger.LogVerbose(string.Format("The total size of the folder '{0}' is '{1}' mb", folder, totalSize)); }
protected static void Synchronize(object stateInfo) { try { var startingTime = DateTime.Now; SetDefaultDocumentManager(); //new ProjectDocumentImporter(@"P:\Ingenierie\PART DOCUMENTS\PRODUCTION PART\", @"Amélioration continue\À classer"); RenameEntityFolderSharepointProcess.Execute(); CLLogger.LogVerbose("The upload takes " + DateTime.Now.Subtract(startingTime).TotalMinutes.ToString() + " minutes."); } catch (Exception ex) { CLLogger.LogCritical(ex); } }
private void UpdateProjectProgram(Guid projectId, string programName) { var projectNeedsToBeUpdated = false; var programId = Cache.GetProjectProgramId(programName); using (var context = FactoryDbContext.Create()) { projectNeedsToBeUpdated = context.Projects.Any(x => x.Id == projectId && x.ProgramId != programId); } if (projectNeedsToBeUpdated) { var project = Project.Get(projectId); project.ProgramId = programId; project.CurrentUserId = Constants.User.Admin; project.IsModifiedByImport = true; project.Save(); CLLogger.LogVerbose(string.Format("The project '{0}' program as been updated to '{1}'", project.Name, programName)); project = null; } }
private void ProcessFile(FileInfo file, Guid projectId, string comboxPath) { CLLogger.LogVerbose(string.Format("The file '{0}' --> '{2}' will be associated to project '{1}'", file.FullName.Substring(_rootFolder.Length), Cache.GetProjectName(projectId), comboxPath)); totalSize += (file.Length * 1d) / 1024 / 1024; var cleanPath = comboxPath.TrimEnd('\\').Split('\\'); Guid?folderId = null; using (var context = FactoryDbContext.Create()) { for (var i = 0; i < cleanPath.Length; i++) { var currentFolder = CleanStringForWeb(cleanPath[i]); var existingFolderId = context.EntityFolders.Where(x => x.ReferenceId == projectId && x.ParentId == folderId && x.Name == currentFolder).Select(x => x.Id).FirstOrDefault(); if (existingFolderId == Guid.Empty) { var folder = EntityFolder.New(); folder.CurrentUserId = Constants.User.Admin; folder.Id = Guid.NewGuid(); folder.EntityId = Constants.EntityType.Project; folder.ReferenceId = projectId; folder.ParentId = folderId; folder.Name = currentFolder; folder.Save(); folderId = folder.Id; } else { folderId = existingFolderId; } } } var document = Document.New(); document.ReferenceId = projectId; document.EntityId = Constants.EntityType.Project; document.CurrentUserId = Constants.User.Admin; document.CreatedOn = DateTime.Now; document.LastUpdatedOn = DateTime.Now; document.CreatedById = Constants.User.Admin; document.LastUpdatedById = Constants.User.Admin; document.Id = Guid.NewGuid(); document.FolderId = folderId; document.DocumentTypeId = LookupServices.GetLookupItemIdFromTag("LST_DOCUMENT_TYPE_NOT_CLASSIFIED"); document.Filename = CleanStringForWeb(file.Name).Replace("..", "."); document.FileExtension = file.Extension; document.FileContentType = ContentTypes.GetContentTypeFromFileExtension(document.FileExtension); try { using (var stream = file.OpenRead()) { document.Insert <JMSL.Framework.DAL.Entities.Document, Document>(DocumentManagerProvider.Get(), new TransferDocument() { FileName = document.Filename, FileLength = file.Length, FileByteStream = stream }); } } catch (Exception ex) { CLLogger.LogError(ex); } }
private void ProcessFolder(string folder, Guid?parentProjectId, string comboxPath) { if (Directory.Exists(folder)) { foreach (var folderInfo in new DirectoryInfo(folder).GetDirectories()) { var projectId = Cache.GetProjectId(folderInfo.Name, folderInfo.FullName); var originalComboxPath = comboxPath; if (projectId == null) { projectId = parentProjectId; } if (parentProjectId == null || projectId != parentProjectId) { comboxPath = this._templateFolder + @"\"; } if (projectId == Guid.Empty) { //CLLogger.LogVerbose(string.Format("The folder is excluded: '{0}'", folderInfo.FullName)); } else if (projectId != null) {/* * var acceptedProject = new List<string>() { * "1006M3205C001", * "1006M3300C001" * }; * if (acceptedProject.Contains(Cache.GetProjectName(projectId.Value))) * { * if (_projectProgram.ContainsKey(folderInfo.Name)) * { * UpdateProjectProgram(projectId.Value, _projectProgram[folderInfo.Name]); * } * else if (_projectProgram.ContainsKey(Cache.GetProjectName(projectId.Value))) * { * UpdateProjectProgram(projectId.Value, _projectProgram[Cache.GetProjectName(projectId.Value)]); * * if (!folderInfo.Name.ToUpper().Contains("COMMERCIAL") && !folderInfo.Name.ToUpper().Contains("MILITAIRE")) * { * comboxPath += folderInfo.Name + @"\"; * } * } * else if (folderInfo.Name.ToUpper().Contains("COMMERCIAL")) * { * UpdateProjectProgram(projectId.Value, "Commercial"); * } * else if (folderInfo.Name.ToUpper().Contains("MILITAIRE")) * { * UpdateProjectProgram(projectId.Value, "Militaire"); * } * else if (projectId == parentProjectId) * { * comboxPath += folderInfo.Name + @"\"; * } * * if (_folderMapping.ContainsKey(folderInfo.Name.ToUpper())) * { * comboxPath = _folderMapping[folderInfo.Name.ToUpper()] + @"\"; * } * * ProcessFolder(folderInfo.FullName, projectId, comboxPath); * * foreach (var fileInfo in folderInfo.GetFiles()) * { * if (!fileInfo.Name.StartsWith("~") && !_excludedEndFiles.Any(x => fileInfo.Name.Trim().EndsWith(x, StringComparison.InvariantCultureIgnoreCase))) * { * if (!_excludedFileExtensions.Any(x => x.Equals(fileInfo.Extension.Trim(), StringComparison.InvariantCultureIgnoreCase) || * ("." + x).Equals(fileInfo.Extension.Trim(), StringComparison.InvariantCultureIgnoreCase))) * { * ProcessFile(fileInfo, projectId.Value, comboxPath); * } * else * { * CLLogger.LogVerbose(string.Format("The file '{0}' with extension '{1}' will be excluded for project '{2}'", fileInfo.FullName, fileInfo.Extension, Cache.GetProjectName(projectId.Value))); * } * } * else * { * CLLogger.LogVerbose(string.Format("The file '{0}' will be excluded for project '{1}'", fileInfo.FullName, Cache.GetProjectName(projectId.Value))); * } * } * } */ } else { CLLogger.LogVerbose(string.Format("The folder was not imported: '{0}'", folderInfo.FullName)); //ProcessFolder(folderInfo.FullName, null, string.Empty); } comboxPath = originalComboxPath; } } else { CLLogger.LogVerbose(string.Format("The following path was not found : '{0}'", folder)); } }