/// <summary> /// Gets the cached local file for a given URL path. /// </summary> /// <param name="urlPath">The URL path.</param> /// <param name="localization">The Localization.</param> /// <returns>The path to the local file.</returns> internal string GetCachedFile(string urlPath, Localization localization) { IBinaryProvider provider = Provider; string baseDir = AppDomain.CurrentDomain.BaseDirectory; string localFilePath = $"{baseDir}/{urlPath}"; if (File.Exists(localFilePath)) { // If our resource exists on the filesystem we can assume static content that is // manually added to web application. return(localFilePath); } // Attempt cache location with fallback to retrieval from content service. localFilePath = $"{baseDir}/{localization.BinaryCacheFolder}/{urlPath}"; using (new Tracer(urlPath, localization, localFilePath)) { Dimensions dimensions; urlPath = StripDimensions(urlPath, out dimensions); if (File.Exists(localFilePath)) { if (IsCached(() => provider.GetBinaryLastPublishedDate(localization, urlPath), localFilePath, localization)) { return(localFilePath); } } var binary = provider.GetBinary(localization, urlPath); if (binary != null) { WriteBinaryToFile(binary.Item1, localFilePath, dimensions); } return(localFilePath); } }
/// <summary> /// Initializes a new instance of the <see cref="MetadataProviderBase"/> class. /// </summary> public MetadataProviderBase(string projectId, string connectionString, IBinaryProvider binaryProvider, Dictionary <string, IBinaryProvider> supportedBinaryProviders, IIndexStore indexStore, IAuditReportProvider auditReportProvider) { ProjectId = projectId; ConnectionString = connectionString; IndexStore = indexStore; AuditReportProvider = auditReportProvider; BinaryProvider = binaryProvider; SupportedBinaryProviders = supportedBinaryProviders; }
/// <summary> /// Initializes a new instance of the <see cref="NullMetadataProvider"/> class. /// </summary> /// <param name="projectId"></param> /// <param name="connectionString"></param> /// <param name="binaryProvider"></param> /// <param name="supportedBinaryProviders"></param> /// <param name="indexStore"></param> /// <param name="auditReportProvider"></param> public NullMetadataProvider(string projectId, string connectionString, IBinaryProvider binaryProvider, Dictionary <string, IBinaryProvider> supportedBinaryProviders, IIndexStore indexStore, IAuditReportProvider auditReportProvider) : base(projectId, connectionString, binaryProvider, supportedBinaryProviders, indexStore, auditReportProvider) { FileStore = new NullFileStore(); File = new FileManager(FileStore, binaryProvider, supportedBinaryProviders); FieldStore = new NullFieldStore(); Field = new FieldManager(FieldStore, indexStore, auditReportProvider); DocumentStore = new NullDocumentStore(); Document = new DocumentManager(DocumentStore, FieldStore, indexStore); }
public BinaryController(IBinaryProvider binaryProvider, ILogger logger) { if (binaryProvider == null) throw new ArgumentNullException("binaryProvider"); if (logger == null) throw new ArgumentNullException("logger"); Logger = logger; BinaryProvider = binaryProvider; }
public BinaryFactory(IBinaryProvider binaryProvider, IFactoryCommonServices factoryCommonServices) : base(factoryCommonServices) { if (binaryProvider == null) throw new ArgumentNullException("binaryProvider"); BinaryProvider = binaryProvider; //overriding cacheAgent GetLastPublished property //CacheAgent.GetLastPublishDateCallBack = GetLastPublishedDateCallBack; }
public BinaryFactory(IBinaryProvider binaryProvider, IFactoryCommonServices factoryCommonServices) : base(factoryCommonServices) { if (binaryProvider == null) { throw new ArgumentNullException("binaryProvider"); } BinaryProvider = binaryProvider; //overriding cacheAgent GetLastPublished property //CacheAgent.GetLastPublishDateCallBack = GetLastPublishedDateCallBack; }
public BinaryFactory(IBinaryProvider binaryProvider, IFactoryCommonServices factoryCommonServices) : base(factoryCommonServices) { if (binaryProvider == null) { throw new ArgumentNullException("binaryProvider"); } BinaryProvider = binaryProvider; CacheValueNull = new Binary() { Title = CacheValueNullTitle }; }
public BinaryController(IBinaryProvider binaryProvider, ILogger logger) { if (binaryProvider == null) { throw new ArgumentNullException("binaryProvider"); } if (logger == null) { throw new ArgumentNullException("logger"); } Logger = logger; BinaryProvider = binaryProvider; }
/// <summary> /// Gets the cached local file for a given binary Id. /// </summary> /// <param name="binaryId">The binary Id.</param> /// <param name="localization">The Localization.</param> /// <returns>The path to the local file.</returns> internal string GetCachedFile(int binaryId, Localization localization, out MemoryStream memoryStream) { memoryStream = null; IBinaryProvider provider = Provider; string baseDir = AppDomain.CurrentDomain.BaseDirectory; string localFilePath = $"{baseDir}/{localization.BinaryCacheFolder}"; using (new Tracer(binaryId, localization, localFilePath)) { try { if (Directory.Exists(localFilePath)) { string[] files = Directory.GetFiles(localFilePath, $"{binaryId}*", SearchOption.TopDirectoryOnly); if (files.Length > 0) { localFilePath = files[0]; if (IsCached(() => provider.GetBinaryLastPublishedDate(localization, binaryId), localFilePath, localization)) { return(localFilePath); } } } } catch (Exception ex) { // Our binary cache folder probably doesn't exist. Log.Warn($"Failed to cache binary at {localFilePath}"); Log.Warn(ex.Message); } var data = provider.GetBinary(localization, binaryId); if (string.IsNullOrEmpty(Path.GetExtension(localFilePath))) { var ext = Path.GetExtension(data.Item2) ?? ""; localFilePath = $"{localFilePath}/{binaryId}{ext}"; } WriteBinaryToFile(data.Item1, localFilePath, null, out memoryStream); return(localFilePath); } }
/// <summary> /// Initializes a new instance of the <see cref="FileManager"/> class. /// </summary> /// <param name="fileStore">The file store.</param> /// <param name="binaryProvider">The default binary provider.</param> /// <param name="supportedBinaryProviders">The supported binary providers.</param> public FileManager(IFileStore fileStore, IBinaryProvider binaryProvider, Dictionary <string, IBinaryProvider> supportedBinaryProviders) { FileStore = fileStore; BinaryProvider = binaryProvider; SupportedBinaryProviders = supportedBinaryProviders; }