internal static void Init() { try { if (isInit) { return; } lock (Locker) { if (isInit) { return; } DIHelper.Register(); var container = DIHelper.Resolve(); IDaoFactory factory; if (!container.TryResolve(out factory)) { factory = new DaoFactory(); Logger.Fatal("Could not resolve IDaoFactory instance. Using default DaoFactory instead."); } IFileStorageService storageService; if (!container.TryResolve(out storageService)) { storageService = new FileStorageServiceController(); Logger.Fatal("Could not resolve IFileStorageService instance. Using default FileStorageServiceController instead."); } DaoFactory = factory; FileStorageService = storageService; SocketManager = new SocketManager(); if (CoreContext.Configuration.Standalone) { ClearCache(); } ThumbnailExtension = ConfigurationManagerExtension.AppSettings["files.thumbnail.exts"] ?? "png"; isInit = true; } } catch (Exception error) { Logger.Fatal("Could not resolve IDaoFactory instance. Using default DaoFactory instead.", error); DaoFactory = new DaoFactory(); FileStorageService = new FileStorageServiceController(); } }
internal static void Init() { try { if (isInit) { return; } lock (Locker) { if (isInit) { return; } DIHelper.Register(); var container = DIHelper.Resolve(); IDaoFactory factory; if (!container.TryResolve(out factory)) { factory = new DaoFactory(); Logger.Fatal("Could not resolve IDaoFactory instance. Using default DaoFactory instead."); } IFileStorageService storageService; if (!container.TryResolve(out storageService)) { storageService = new FileStorageServiceController(); Logger.Fatal("Could not resolve IFileStorageService instance. Using default FileStorageServiceController instead."); } DaoFactory = factory; FileStorageService = storageService; SocketManager = new SocketManager(); isInit = true; } } catch (Exception error) { Logger.Fatal("Could not resolve IDaoFactory instance. Using default DaoFactory instead.", error); DaoFactory = new DaoFactory(); FileStorageService = new FileStorageServiceController(); } }
public static void ChangeAttachedFileLinksAddresses(this MailDraftData draft, ILog log = null) { if (log == null) { log = new NullLog(); } var doc = new HtmlDocument(); doc.LoadHtml(draft.HtmlBody); var linkNodes = doc.DocumentNode.SelectNodes("//a[contains(@class,'mailmessage-filelink-link')]"); if (linkNodes == null) { return; } var fileStorageService = new FileStorageServiceController(); var setLinks = new List <Tuple <string, string> >(); foreach (var linkNode in linkNodes) { var fileId = linkNode.Attributes["data-fileid"].Value; var objectId = "file_" + fileId; linkNode.Attributes["class"].Remove(); // 'mailmessage-filelink-link' linkNode.Attributes["data-fileid"].Remove(); // 'data-fileid' var setLink = setLinks.SingleOrDefault(x => x.Item1 == fileId); if (setLink != null) { linkNode.SetAttributeValue("href", setLink.Item2); log.InfoFormat("ChangeAttachedFileLinks() Change file link href: {0}", fileId); continue; } var aceCollection = new AceCollection { Entries = new ItemList <string> { objectId }, Aces = new ItemList <AceWrapper> { new AceWrapper { SubjectId = FileConstant.ShareLinkId, SubjectGroup = true, Share = draft.FileLinksShareMode } } }; fileStorageService.SetAceObject(aceCollection, false); log.InfoFormat("ChangeAttachedFileLinks() Set public accees to file: {0}", fileId); var sharedInfo = fileStorageService.GetSharedInfo(new ItemList <string> { objectId }) .Find(r => r.SubjectId == FileConstant.ShareLinkId); linkNode.SetAttributeValue("href", sharedInfo.Link); log.InfoFormat("ChangeAttachedFileLinks() Change file link href: {0}", fileId); setLinks.Add(new Tuple <string, string>(fileId, sharedInfo.Link)); } linkNodes = doc.DocumentNode.SelectNodes("//div[contains(@class,'mailmessage-filelink')]"); foreach (var linkNode in linkNodes) { linkNode.Attributes["class"].Remove(); } draft.HtmlBody = doc.DocumentNode.OuterHtml; }