public override async Task <bool> Process(Resource resource) { // write the RPF if (!Directory.Exists("cache/http-files/")) { Directory.CreateDirectory("cache/http-files"); } var rpfName = GetRpfNameFor(resource); try { // create new RPF var rpf = new Formats.RPFFile(); // add required files var requiredFiles = GetRequiredFilesFor(resource); requiredFiles.Where(a => File.Exists(Path.Combine(resource.Path, a))).ToList().ForEach(a => rpf.AddFile(a, File.ReadAllBytes(Path.Combine(resource.Path, a)))); // add external files resource.ExternalFiles.ToList().ForEach(a => rpf.AddFile(a.Key, File.ReadAllBytes(a.Value.FullName))); // and write the RPF rpf.Write(rpfName); // set the hash of the client package for clients to fetch var hash = Utils.GetFileSHA1String(rpfName); resource.ClientPackageHash = hash; // synchronize the files with a download server if (resource.DownloadConfiguration != null && !string.IsNullOrWhiteSpace(resource.DownloadConfiguration.UploadURL)) { var updater = new ResourceUpdater(resource, resource.DownloadConfiguration); resource.IsSynchronizing = true; await updater.SyncResource(); resource.IsSynchronizing = false; } return(true); } catch (Exception e) { this.Log().Error(() => "Error updating client cache file: " + e.Message, e); } return(false); }
public override async Task<bool> Process(Resource resource) { // write the RPF if (!Directory.Exists("cache/http-files/")) { Directory.CreateDirectory("cache/http-files"); } var rpfName = GetRpfNameFor(resource); try { // create new RPF var rpf = new Formats.RPFFile(); // add required files var requiredFiles = GetRequiredFilesFor(resource); requiredFiles.Where(a => File.Exists(Path.Combine(resource.Path, a))).ToList().ForEach(a => rpf.AddFile(a, File.ReadAllBytes(Path.Combine(resource.Path, a)))); // add external files resource.ExternalFiles.ToList().ForEach(a => rpf.AddFile(a.Key, File.ReadAllBytes(a.Value.FullName))); // and write the RPF rpf.Write(rpfName); // set the hash of the client package for clients to fetch var hash = Utils.GetFileSHA1String(rpfName); resource.ClientPackageHash = hash; // synchronize the files with a download server if (resource.DownloadConfiguration != null && !string.IsNullOrWhiteSpace(resource.DownloadConfiguration.UploadURL)) { var updater = new ResourceUpdater(resource, resource.DownloadConfiguration); resource.IsSynchronizing = true; await updater.SyncResource(); resource.IsSynchronizing = false; } return true; } catch (Exception e) { this.Log().Error(() => "Error updating client cache file: " + e.Message, e); } return false; }