private void SetIsDefault(CoBrandingLogoTypeEnum type, bool value) { switch (type) { case CoBrandingLogoTypeEnum.Light: _isDefaultLogoLight = value; break; case CoBrandingLogoTypeEnum.LightSmall: _isDefaultLogoLightSmall = value; break; case CoBrandingLogoTypeEnum.Dark: _isDefaultLogoDark = value; break; case CoBrandingLogoTypeEnum.Favicon: _isDefaultLogoFavicon = value; break; case CoBrandingLogoTypeEnum.DocsEditor: _isDefaultLogoDocsEditor = value; break; } }
public static Size GetSize(CoBrandingLogoTypeEnum type, bool general) { switch (type) { case CoBrandingLogoTypeEnum.Light: return(new Size( general ? TenantCoBrandingSettings.logoLightSize.Width / 2 : TenantCoBrandingSettings.logoLightSize.Width, general ? TenantCoBrandingSettings.logoLightSize.Height / 2 : TenantCoBrandingSettings.logoLightSize.Height)); case CoBrandingLogoTypeEnum.LightSmall: return(new Size( general ? TenantCoBrandingSettings.logoLightSmallSize.Width / 2 : TenantCoBrandingSettings.logoLightSmallSize.Width, general ? TenantCoBrandingSettings.logoLightSmallSize.Height / 2 : TenantCoBrandingSettings.logoLightSmallSize.Height)); case CoBrandingLogoTypeEnum.Dark: return(new Size( general ? TenantCoBrandingSettings.logoDarkSize.Width / 2 : TenantCoBrandingSettings.logoDarkSize.Width, general ? TenantCoBrandingSettings.logoDarkSize.Height / 2 : TenantCoBrandingSettings.logoDarkSize.Height)); case CoBrandingLogoTypeEnum.Favicon: return(new Size( general ? TenantCoBrandingSettings.logoFaviconSize.Width / 2 : TenantCoBrandingSettings.logoFaviconSize.Width, general ? TenantCoBrandingSettings.logoFaviconSize.Height / 2 : TenantCoBrandingSettings.logoFaviconSize.Height)); case CoBrandingLogoTypeEnum.DocsEditor: return(new Size( general ? TenantCoBrandingSettings.logoDocsEditorSize.Width / 2 : TenantCoBrandingSettings.logoDocsEditorSize.Width, general ? TenantCoBrandingSettings.logoDocsEditorSize.Height / 2 : TenantCoBrandingSettings.logoDocsEditorSize.Height)); } return(new Size(0, 0)); }
private void SetExt(CoBrandingLogoTypeEnum type, String fileExt) { switch (type) { case CoBrandingLogoTypeEnum.Light: _logoLightExt = fileExt; break; case CoBrandingLogoTypeEnum.LightSmall: _logoLightSmallExt = fileExt; break; case CoBrandingLogoTypeEnum.Dark: _logoDarkExt = fileExt; break; case CoBrandingLogoTypeEnum.Favicon: _logoFaviconExt = fileExt; break; case CoBrandingLogoTypeEnum.DocsEditor: _logoDocsEditorExt = fileExt; break; } }
public void SetLogo(CoBrandingLogoTypeEnum type, string logoFileExt, byte[] data) { var store = StorageFactory.GetStorage(TenantProvider.CurrentTenantID.ToString(), moduleName); var isAlreadyHaveBeenChanged = !GetIsDefault(type); if (isAlreadyHaveBeenChanged) { try { store.Delete(BuildLogoFileName(type, GetExt(type), false)); store.Delete(BuildLogoFileName(type, GetExt(type), true)); } catch (Exception e) { log4net.LogManager.GetLogger("ASC").Error(e); } } using (var memory = new MemoryStream(data)) using (var image = Image.FromStream(memory)) { var logoSize = image.Size; var logoFileName = BuildLogoFileName(type, logoFileExt, false); memory.Seek(0, SeekOrigin.Begin); store.Save(logoFileName, memory); } SetExt(type, logoFileExt); SetIsDefault(type, false); var generalSize = GetSize(type, true); var generalFileName = BuildLogoFileName(type, logoFileExt, true); ResizeLogo(type, generalFileName, data, -1, generalSize, store); }
public string GetAbsoluteLogoPath(CoBrandingLogoTypeEnum type, bool general = true) { if (GetIsDefault(type)) { return(GetAbsoluteDefaultLogoPath(type, general)); } return(GetAbsoluteStorageLogoPath(type, general)); }
public static string BuildLogoFileName(CoBrandingLogoTypeEnum type, String fileExt, bool general) { if (type == CoBrandingLogoTypeEnum.Favicon) { fileExt = "ico"; } return(String.Format("logo_{0}{2}.{1}", type.ToString().ToLower(), fileExt, general ? "_general" : "")); }
private string GetAbsoluteStorageLogoPath(CoBrandingLogoTypeEnum type, bool general) { var store = StorageFactory.GetStorage(TenantProvider.CurrentTenantID.ToString(), moduleName); var fileName = BuildLogoFileName(type, GetExt(type), general); if (store.IsFile(fileName)) { return(store.GetUri(fileName).ToString()); } return(GetAbsoluteDefaultLogoPath(type, general)); }
private static void ResizeLogo(CoBrandingLogoTypeEnum type, String fileName, byte[] data, long maxFileSize, Size size, IDataStore store) { //Resize synchronously if (data == null || data.Length <= 0) { throw new UnknownImageFormatException(); } if (maxFileSize != -1 && data.Length > maxFileSize) { throw new ImageWeightLimitException(); } try { using (var stream = new MemoryStream(data)) using (var img = Image.FromStream(stream)) { var imgFormat = img.RawFormat; if (size != img.Size) { using (var img2 = CommonPhotoManager.DoThumbnail(img, size, false, true, false)) { data = CommonPhotoManager.SaveToBytes(img2); } } else { data = CommonPhotoManager.SaveToBytes(img); } //fileExt = CommonPhotoManager.GetImgFormatName(imgFormat); using (var stream2 = new MemoryStream(data)) { store.Save(fileName, stream2); //NOTE: Update cache here //var filePath = Path.GetFileName(photoUrl); //AddToCache(item.UserId, item.Size, fileNPath, true); } } } catch (ArgumentException error) { throw new UnknownImageFormatException(error); } }
public void RestoreDefault(CoBrandingLogoTypeEnum type) { if (!GetIsDefault(type)) { try { SetIsDefault(type, true); var store = StorageFactory.GetStorage(TenantProvider.CurrentTenantID.ToString(), moduleName); store.Delete(BuildLogoFileName(type, GetExt(type), false)); store.Delete(BuildLogoFileName(type, GetExt(type), true)); } catch (Exception e) { log4net.LogManager.GetLogger("ASC").Error(e); } } }
public static string GetAbsoluteDefaultLogoPath(CoBrandingLogoTypeEnum type, bool general) { switch (type) { case CoBrandingLogoTypeEnum.Light: return(general ? WebImageSupplier.GetAbsoluteWebPath("onlyoffice_logo/light_general.png") : WebImageSupplier.GetAbsoluteWebPath("onlyoffice_logo/light.png")); case CoBrandingLogoTypeEnum.LightSmall: return(general ? WebImageSupplier.GetAbsoluteWebPath("onlyoffice_logo/light_small_general.png") : WebImageSupplier.GetAbsoluteWebPath("onlyoffice_logo/light_small.png")); case CoBrandingLogoTypeEnum.Dark: return(general ? WebImageSupplier.GetAbsoluteWebPath("onlyoffice_logo/dark_general.png") : WebImageSupplier.GetAbsoluteWebPath("onlyoffice_logo/dark.png")); case CoBrandingLogoTypeEnum.DocsEditor: return(general ? WebImageSupplier.GetAbsoluteWebPath("onlyoffice_logo/editor_logo_general.png") : WebImageSupplier.GetAbsoluteWebPath("onlyoffice_logo/editor_logo.png")); case CoBrandingLogoTypeEnum.Favicon: return(general ? WebImageSupplier.GetAbsoluteWebPath("onlyoffice_logo/favicon_general.ico") : WebImageSupplier.GetAbsoluteWebPath("onlyoffice_logo/favicon.ico")); } return(""); }
private string GetExt(CoBrandingLogoTypeEnum type) { switch (type) { case CoBrandingLogoTypeEnum.Light: return(_logoLightExt); case CoBrandingLogoTypeEnum.LightSmall: return(_logoLightSmallExt); case CoBrandingLogoTypeEnum.Dark: return(_logoDarkExt); case CoBrandingLogoTypeEnum.Favicon: return(_logoFaviconExt); case CoBrandingLogoTypeEnum.DocsEditor: return(_logoDocsEditorExt); } return(""); }
private bool GetIsDefault(CoBrandingLogoTypeEnum type) { switch (type) { case CoBrandingLogoTypeEnum.Light: return(_isDefaultLogoLight); case CoBrandingLogoTypeEnum.LightSmall: return(_isDefaultLogoLightSmall); case CoBrandingLogoTypeEnum.Dark: return(_isDefaultLogoDark); case CoBrandingLogoTypeEnum.Favicon: return(_isDefaultLogoFavicon); case CoBrandingLogoTypeEnum.DocsEditor: return(_isDefaultLogoDocsEditor); } return(true); }
private bool GetIsDefault(CoBrandingLogoTypeEnum type){ switch (type) { case CoBrandingLogoTypeEnum.Light: return _isDefaultLogoLight; case CoBrandingLogoTypeEnum.LightSmall: return _isDefaultLogoLightSmall; case CoBrandingLogoTypeEnum.Dark: return _isDefaultLogoDark; case CoBrandingLogoTypeEnum.Favicon: return _isDefaultLogoFavicon; case CoBrandingLogoTypeEnum.DocsEditor: return _isDefaultLogoDocsEditor; } return true; }
private string GetExt(CoBrandingLogoTypeEnum type) { switch (type) { case CoBrandingLogoTypeEnum.Light: return _logoLightExt; case CoBrandingLogoTypeEnum.LightSmall: return _logoLightSmallExt; case CoBrandingLogoTypeEnum.Dark: return _logoDarkExt; case CoBrandingLogoTypeEnum.Favicon: return _logoFaviconExt; case CoBrandingLogoTypeEnum.DocsEditor: return _logoDocsEditorExt; } return ""; }
public string GetAbsoluteLogoPath(CoBrandingLogoTypeEnum type, bool general = true) { if (GetIsDefault(type)) { return GetAbsoluteDefaultLogoPath(type, general); } return GetAbsoluteStorageLogoPath(type, general); }
private string GetAbsoluteStorageLogoPath(CoBrandingLogoTypeEnum type, bool general) { var store = StorageFactory.GetStorage(TenantProvider.CurrentTenantID.ToString(), moduleName); var fileName = BuildLogoFileName(type, GetExt(type), general); if (store.IsFile(fileName)) { return store.GetUri(fileName).ToString(); } return GetAbsoluteDefaultLogoPath(type, general); }
public static string GetAbsoluteDefaultLogoPath(CoBrandingLogoTypeEnum type, bool general) { switch (type) { case CoBrandingLogoTypeEnum.Light: return general ? WebImageSupplier.GetAbsoluteWebPath("onlyoffice_logo/light_general.png") : WebImageSupplier.GetAbsoluteWebPath("onlyoffice_logo/light.png"); case CoBrandingLogoTypeEnum.LightSmall: return general ? WebImageSupplier.GetAbsoluteWebPath("onlyoffice_logo/light_small_general.png") : WebImageSupplier.GetAbsoluteWebPath("onlyoffice_logo/light_small.png"); case CoBrandingLogoTypeEnum.Dark: return general ? WebImageSupplier.GetAbsoluteWebPath("onlyoffice_logo/dark_general.png") : WebImageSupplier.GetAbsoluteWebPath("onlyoffice_logo/dark.png"); case CoBrandingLogoTypeEnum.DocsEditor: return general ? WebImageSupplier.GetAbsoluteWebPath("onlyoffice_logo/editor_logo_general.png") : WebImageSupplier.GetAbsoluteWebPath("onlyoffice_logo/editor_logo.png"); case CoBrandingLogoTypeEnum.Favicon: return general ? WebImageSupplier.GetAbsoluteWebPath("onlyoffice_logo/favicon_general.ico") : WebImageSupplier.GetAbsoluteWebPath("onlyoffice_logo/favicon.ico"); } return ""; }
private static void ResizeLogo(CoBrandingLogoTypeEnum type, String fileName, byte[] data, long maxFileSize, Size size, IDataStore store) { //Resize synchronously if (data == null || data.Length <= 0) throw new UnknownImageFormatException(); if (maxFileSize != -1 && data.Length > maxFileSize) throw new ImageWeightLimitException(); try { using (var stream = new MemoryStream(data)) using (var img = Image.FromStream(stream)) { var imgFormat = img.RawFormat; if (size != img.Size) { using (var img2 = CommonPhotoManager.DoThumbnail(img, size, false, true, false)) { data = CommonPhotoManager.SaveToBytes(img2); } } else { data = CommonPhotoManager.SaveToBytes(img); } //fileExt = CommonPhotoManager.GetImgFormatName(imgFormat); using (var stream2 = new MemoryStream(data)) { store.Save(fileName, stream2); //NOTE: Update cache here //var filePath = Path.GetFileName(photoUrl); //AddToCache(item.UserId, item.Size, fileNPath, true); } } } catch (ArgumentException error) { throw new UnknownImageFormatException(error); } }
public static Size GetSize(CoBrandingLogoTypeEnum type, bool general) { switch (type) { case CoBrandingLogoTypeEnum.Light: return new Size( general ? TenantCoBrandingSettings.logoLightSize.Width / 2 : TenantCoBrandingSettings.logoLightSize.Width, general ? TenantCoBrandingSettings.logoLightSize.Height / 2 : TenantCoBrandingSettings.logoLightSize.Height); case CoBrandingLogoTypeEnum.LightSmall: return new Size( general ? TenantCoBrandingSettings.logoLightSmallSize.Width / 2 : TenantCoBrandingSettings.logoLightSmallSize.Width, general ? TenantCoBrandingSettings.logoLightSmallSize.Height / 2 : TenantCoBrandingSettings.logoLightSmallSize.Height); case CoBrandingLogoTypeEnum.Dark: return new Size( general ? TenantCoBrandingSettings.logoDarkSize.Width / 2 : TenantCoBrandingSettings.logoDarkSize.Width, general ? TenantCoBrandingSettings.logoDarkSize.Height / 2 : TenantCoBrandingSettings.logoDarkSize.Height); case CoBrandingLogoTypeEnum.Favicon: return new Size( general ? TenantCoBrandingSettings.logoFaviconSize.Width / 2 : TenantCoBrandingSettings.logoFaviconSize.Width, general ? TenantCoBrandingSettings.logoFaviconSize.Height / 2 : TenantCoBrandingSettings.logoFaviconSize.Height); case CoBrandingLogoTypeEnum.DocsEditor: return new Size( general ? TenantCoBrandingSettings.logoDocsEditorSize.Width / 2 : TenantCoBrandingSettings.logoDocsEditorSize.Width, general ? TenantCoBrandingSettings.logoDocsEditorSize.Height / 2 : TenantCoBrandingSettings.logoDocsEditorSize.Height); } return new Size(0, 0); }
public static string BuildLogoFileName(CoBrandingLogoTypeEnum type, String fileExt, bool general) { if (type == CoBrandingLogoTypeEnum.Favicon) { fileExt = "ico"; } return String.Format("logo_{0}{2}.{1}", type.ToString().ToLower(), fileExt, general ? "_general" : ""); }