public StreamAttributes Attributes(string logicalPath) { // Use the local file first, if found StreamAttributes attributes = LocalProvider.Attributes(logicalPath); // Return remote metadata instead if the local doesn't exist and the remote does if (!attributes.Exists) { StreamAttributes remoteAttributes = RemoteProvider.Attributes(logicalPath); if (remoteAttributes.Exists) { attributes = remoteAttributes; } } return(attributes); }
public Stream OpenRead(string logicalPath) { // If configured to only use remote configuration, don't use the local copy for Config and Query if (Configuration.UseRemoteConfiguration) { if (logicalPath.StartsWith("Config\\", StringComparison.OrdinalIgnoreCase) || logicalPath.StartsWith("Query\\", StringComparison.OrdinalIgnoreCase)) { return(RemoteProvider.OpenRead(logicalPath)); } } // Read the local copy first, if found if (LocalProvider.Attributes(logicalPath).Exists) { return(LocalProvider.OpenRead(logicalPath)); } // If there's a remote copy, use that if (LocalProvider.Attributes(logicalPath).Exists == false && RemoteProvider.Attributes(logicalPath).Exists == true) { if (Configuration.ShouldDownload) { // Download the file if configured to Trace.WriteLine($"DOWNLOAD: {logicalPath}"); using (Stream target = LocalProvider.OpenWrite(logicalPath)) { using (Stream source = RemoteProvider.OpenRead(logicalPath)) { source.CopyTo(target); } } return(LocalProvider.OpenRead(logicalPath)); } return(RemoteProvider.OpenRead(logicalPath)); } // If neither location had the item, throw throw new IOException($"\"{logicalPath}\" did not exist in {LocalProvider.Description} or {RemoteProvider.Description}"); }