static public Uri UploadResourceIfNeeded(DfsClient dfs, string localPath, Uri dfsDirectory, out long modificationTime, out long size, ILogger logger = null) { ConsoleLogger.EnsureLogger(ref logger); string suffix = MakeHash(localPath); string localFileName = Path.GetFileName(localPath); string dfsFileName = localFileName + "." + suffix; Uri dfsPath = dfs.Combine(dfsDirectory, dfsFileName); if (dfs.GetFileStatus(dfsPath, out modificationTime, out size)) { return(dfsPath); } logger.Log("Uploading " + dfsPath.AbsoluteUri); dfs.PutDfsFile(dfsPath, localPath); if (dfs.GetFileStatus(dfsPath, out modificationTime, out size)) { return(dfsPath); } throw new ApplicationException("Failed to upload resource " + localPath + " to " + dfsPath); }
public static XElement MakeDfsResourceFromRemote(DfsClient dfsClient, Uri resource, ILogger logger = null) { ConsoleLogger.EnsureLogger(ref logger); long modificationTime; long size; bool b = dfsClient.GetFileStatus(resource, out modificationTime, out size); if (!b) { throw new ApplicationException("Unknown resource " + resource.AbsoluteUri); } string fileName = resource.AbsoluteUri.Substring(resource.AbsoluteUri.LastIndexOf('/') + 1); return MakeResourceElement(fileName, modificationTime, size, dfsClient, resource); }