private static void SetDefaultDocumentManager() { App.Cache.Companies(); // load companies before in order to avoid an error of transaction scope var temp = App.Cache.EntityLists; // To load entities in cache DocumentManagerProvider.DocumentManagerChooser = new Func <IDocumentManager>(() => { try { var company = App.Cache.Companies().FirstOrDefault(x => x.Id == new Guid("2F018D31-A8E4-47AC-8A29-C78190768147")); if (company != null && company.UseSharepoint) { return(new SharepointDocumentManager() { SharepointDomain = company.SharepointDomain, SharepointLibraryName = company.SharepointLibraryName, SharepointUrl = company.SharepointUrl, SharepointUserName = company.SharepointUserName, SharepointPassword = company.SharepointPassword, SharepointInCloud = company.SharepointInCloud, SharepointUseInternalTagFolder = true //company.SharepointUseInternalTagFolder }); } } catch (Exception ex) { CLLogger.LogError(ex); } return(new JMSLDocumentManager()); }); DocumentManagerProvider.DocumentBaseFolderName = new Func <JMSL.Framework.DAL.Entities.BaseEntitiesDbContext, JMSL.Framework.Business.Entities.EntityInfo, Guid, string>((db, entityInfo, referenceId) => { if (entityInfo != null) { if (entityInfo.Name.Compare("Project")) { return(entityInfo.Name + "\\" + ProjectServices.GetProjectNumberById(db as ComboxDbContext, referenceId).Replace("\"", "")); } else if (entityInfo.Name.Compare("Client")) { return(entityInfo.Name + "\\" + ClientServices.GetClientInfo(db as ComboxDbContext, referenceId).Name.Replace("\"", "")); } else if (entityInfo.Name.Compare("Documentation")) { return(entityInfo.Name); } else { return(entityInfo.Name + "\\"); } } return(string.Empty); }); }
private static void ChangeFileCustomProperties() { var doc = new OleDocumentPropertiesClass(); try { doc.Open(@"C:\test danny.txt"); //doc.SummaryProperties.Company = "ComboxTest"; doc.CustomProperties.Add("ComboxManager", Guid.NewGuid().ToString()); } catch (Exception ex) { CLLogger.LogError(ex); Console.WriteLine(ex.Message); ex = null; } //after making changes, you need to use this line to save them doc.Save(); }
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); } }