public static async Task DownloadFileWithCallbackAsync(string url, string file, Action <double, string> callback, bool specialOperation = false) { await Task.Delay(1); var client = new WebClient(); var sw = new Stopwatch(); if (specialOperation) { client.Proxy = new WebProxy(); client.Headers.Add("Accept-Encoding", "identity"); client.Headers.Add("Pragma", "akamai-x-cache-on"); } client.DownloadProgressChanged += (sender, args) => { var bytesPerSecond = args.BytesReceived / sw.Elapsed.TotalSeconds; callback?.Raise(args.BytesReceived / (double)args.TotalBytesToReceive * 100, $"{ByteSizeHelper.ToString(args.BytesReceived)}/{ByteSizeHelper.ToString(args.TotalBytesToReceive)} @ {ByteSizeHelper.ToString(bytesPerSecond, mode: ByteSizeMode.Network)}/s"); }; sw.Start(); client.DownloadFileTaskAsync(url, file).Wait(); }
public PageAnalysisService() { _scoreService = new ScoreService(); _htmlHelper = new HtmlHelper(); _byteSizeHelper = new ByteSizeHelper(); _configurationHelper = new ConfigurationHelper(); }
public PageAnalysisService() { _scoreService = new ScoreService(); _reflectionService = new DefinitionHelper(); _htmlHelper = new HtmlHelper(); _byteSizeHelper = new ByteSizeHelper(); }
public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { if (value is long size && size > 0) { return(ByteSizeHelper.ToString(size)); } return(""); }
/// <summary> /// Gets the file size display. /// </summary> /// <returns>System.String.</returns> public override long?GetSize(SizeUnits sizeUnits) { // RefreshObject(); if (FileInfo?.Length == null) { return(null); } return(ByteSizeHelper.GetSize(FileInfo.Length, sizeUnits)); }
private static int RunList(ListOptions options) { switch (options.Command) { case "packages": var packages = PackageManager.ListPackages().GetAwaiter().GetResult(); foreach (var package in packages) { console.WriteLine(package); } break; case "package-info": if (!string.IsNullOrEmpty(options.Parameter)) { var packageVersions = PackageManager.ListToolchainPackages(options.Parameter).GetAwaiter().GetResult(); foreach (var version in packageVersions) { console.WriteLine($"{version.Name}, {version.Version}, {ByteSizeHelper.ToString(version.Size)}, {version.Published.ToUniversalTime()}"); } return(1); } else { console.WriteLine("package name needs to be provided."); } break; case "toolchains": packages = PackageManager.ListToolchains().GetAwaiter().GetResult(); foreach (var package in packages) { var packageVersions = PackageManager.ListToolchainPackages(package).GetAwaiter().GetResult(); if (packageVersions.Any()) { var version = packageVersions.First(); console.WriteLine($"{version.Name}, {version.Version}, {ByteSizeHelper.ToString(version.Size)}, {version.Published.ToUniversalTime()}"); } } return(1); } return(2); }
public static async Task DownloadFileWithCallbackAsync(string url, string file, Action <double, string> callback) { // Clears async warning, hack, need something better. await Task.Delay(1); var client = new WebClient(); var sw = new Stopwatch(); client.DownloadProgressChanged += (sender, args) => { var bytesPerSecond = args.BytesReceived / sw.Elapsed.TotalSeconds; callback?.Raise(args.BytesReceived / (double)args.TotalBytesToReceive * 100, $"{ByteSizeHelper.ToString(args.BytesReceived)}/{ByteSizeHelper.ToString(args.TotalBytesToReceive)} @ {ByteSizeHelper.ToString(bytesPerSecond, mode: ByteSizeMode.Network)}/s"); }; sw.Start(); client.DownloadFileTaskAsync(url, file).Wait(); }
public static async Task ClonePublicHttpSubmodule(IConsole console, string sourceurl, string workingPath) { TransferProgressHandler transferHandler = e => { console.OverWrite( $"Bytes: {ByteSizeHelper.ToString(e.ReceivedBytes)}, Objects: {e.ReceivedObjects}/{e.TotalObjects}, Indexed: {e.IndexedObjects}"); return(true); }; CheckoutProgressHandler checkoutHandler = (path, steps, totalSteps) => { console.OverWrite($"Checkout: {steps}/{totalSteps}"); }; await Task.Factory.StartNew( () => { Repository.Clone(sourceurl, workingPath, new CloneOptions { OnTransferProgress = transferHandler, OnCheckoutProgress = checkoutHandler }); }); }
public static async Task <PackageEnsureStatus> EnsurePackage(string packageName, string version, IConsole console) { packageName = packageName.ToLower(); if (string.IsNullOrWhiteSpace(packageName)) { console.WriteLine("Package with no name. Check definition in manifest file."); return(PackageEnsureStatus.NotFound); } Version ver = string.IsNullOrWhiteSpace(version) ? null : Version.Parse(version); var packageDirectory = Path.Combine(Platform.PackageDirectory, packageName); if (ver == null && Directory.Exists(packageDirectory)) { var versions = Directory.EnumerateDirectories(packageDirectory); if (versions.Count() != 0) { ver = versions.Select(x => Version.Parse(Path.GetFileName(x))).OrderByDescending(x => x).FirstOrDefault(); packageDirectory = Path.Combine(Platform.PackageDirectory, packageName, ver.ToString()); } else { packageDirectory = Path.Combine(Platform.PackageDirectory, packageName, "0000"); } } else if (ver == null) { packageDirectory = Path.Combine(Platform.PackageDirectory, packageName, "0000"); } else { packageDirectory = Path.Combine(Platform.PackageDirectory, packageName, ver.ToString()); } if (!Directory.Exists(packageDirectory)) { var packages = await ListToolchainPackages(packageName, true); if (packages == null) { console?.WriteLine($"Package {packageName} v{ver} was not found."); return(PackageEnsureStatus.NotFound); } if (ver == null) { ver = packages.OrderByDescending(p => p.Version).FirstOrDefault().Version; } if (!packages.Any(p => p.Version == ver)) { console?.WriteLine($"Package {packageName} was found but version v{ver} not recognised. Lastest is: v{packages.First().Version}"); return(PackageEnsureStatus.NotFound); } var systemPlatform = GetSystemPackagePlatform(); if (!packages.Any(p => p.Platform == systemPlatform || p.Platform == PackagePlatform.Any)) { console?.WriteLine($"Package {packageName} v{ver} was found but is not supported on platform {Platform.AvalonRID}"); var supportedPlatforms = packages.GroupBy(p => p.Platform); if (supportedPlatforms.Any()) { console?.WriteLine($"Package {packageName} v{ver} supports:"); foreach (var platformPkg in supportedPlatforms) { console?.Write($"{platformPkg.Key} "); } console?.WriteLine(); } return(PackageEnsureStatus.NotFound); } console?.WriteLine($"Package: {packageName} v{ver} will be downloaded and installed."); var package = packages.FirstOrDefault(p => p.Version == ver && (p.Platform == systemPlatform || p.Platform == PackagePlatform.Any)); await DownloadPackage(package, p => { console?.OverWrite($"Downloading: [{(((float)p / package.Size) * 100.0f).ToString("0.00")}%] {ByteSizeHelper.ToString(p)}/{ByteSizeHelper.ToString(package.Size)} "); }); console?.OverWrite($"Downloaded Package: {packageName} v{ver}."); console?.WriteLine(); console?.WriteLine($"Extracting Package: {packageName} v{ver}."); await InstallPackage(package, (offset, length) => console.OverWrite($"Extracting: [{(((float)offset / length) * 100.0f).ToString("0.00")}%]")); await LoadAssetsAsync(Path.Combine(Platform.PackageDirectory, package.Name, package.Version.ToString())); await ResolveDependencies(packageName, ver?.ToString(), console); console?.OverWrite($"Package Installed: {packageName} v{ver}."); console?.WriteLine(); return(PackageEnsureStatus.Installed); } else { return(await ResolveDependencies(packageName, ver?.ToString(), console)); } }
public async Task Synchronize(string tag, IConsole console) { TransferProgressHandler transferHandler = e => { console.OverWrite(string.Format("Bytes: {1}, Objects: {2}/{3}, Indexed: {0}", e.IndexedObjects, ByteSizeHelper.ToString(e.ReceivedBytes), e.ReceivedObjects, e.TotalObjects)); return(true); }; CheckoutProgressHandler checkoutHandler = (path, steps, totalSteps) => { console.OverWrite($"Checkout: {steps}/{totalSteps}"); }; await Task.Factory.StartNew(() => { try { var repo = Path.Combine(Platform.ReposDirectory, Name); LibGit2Sharp.Repository repository = null; if (LibGit2Sharp.Repository.IsValid(repo)) { repository = new LibGit2Sharp.Repository(repo); repository.Network.Fetch(repository.Network.Remotes["origin"], new FetchOptions { OnTransferProgress = transferHandler, TagFetchMode = TagFetchMode.All }); } else { if (Directory.Exists(repo)) { Directory.Delete(repo, true); } LibGit2Sharp.Repository.Clone(RepoUrl, repo, new CloneOptions { OnTransferProgress = transferHandler, Checkout = false, OnCheckoutProgress = checkoutHandler }); repository = new LibGit2Sharp.Repository(repo); } repository.Checkout(tag, new CheckoutOptions { OnCheckoutProgress = checkoutHandler }); console.OverWrite("Package installed Successfully."); } catch (Exception e) { console.OverWrite("Error installing package: " + e.Message); } }); }
private void Combine() { Log.Info(Properties.Resources.BeginningFileCombine); _patcherContext.UpdateMainProgress(Properties.Resources.BeginningFileCombine, isIndeterminate: true, isProgressbarVisible: true); var stopwatch = new Stopwatch(); var buffer = new byte[4096]; var completed = 0; var totalRead = 0L; Log.Info(Properties.Resources.OpeningZipForOutput, PatchInfo.ZipFilePath); using (var fileStream = new FileStream(PatchInfo.ZipFilePath, FileMode.Create)) { stopwatch.Start(); var timer = new Timer(callback => { _patcherContext.UpdateMainProgress(Properties.Resources.CombiningFiles, $"{completed}/{PatchInfo.Files.Count} at {ByteSizeHelper.ToString(totalRead / stopwatch.Elapsed.TotalSeconds)}/s", completed / (double)PatchInfo.Files.Count * 100.0); }, null, 200, 200); foreach (var patchFileInfo in PatchInfo.Files) { Log.Info(Properties.Resources.AddingFileName, patchFileInfo.Filename); using (var inputFileStream = new FileStream(Path.Combine(PatchInfo.PatchName, patchFileInfo.Filename), FileMode.Open)) { int count; while ((count = inputFileStream.Read(buffer, 0, buffer.Length)) > 0) { // Placeholder for when I add the cancellation logic yoooooooo. CancellationToken.None.ThrowIfCancellationRequested(); fileStream.Write(buffer, 0, count); totalRead += count; } } completed++; } timer.Change(-1, -1); timer.Dispose(); } Log.Info($"Patch combine complete!"); _patcherContext.UpdateMainProgress("Patch combine complete!"); }
public void TestInit() { _byteSizeHelper = new ByteSizeHelper(); }
private static readonly int MaximumSizeInKb = 33792; // 33 kb public HtmlSizeAnalyzer() { _byteSizeHelper = new ByteSizeHelper(); }
public override string ToString() { return (string.Format("Sequence from {0} to {1}. {2} files. Total size: {3}", StartVersion, EndVersion, Patches.Sum(p => p.Files.Count), ByteSizeHelper.ToString(Size))); }
private static int RunPushPackage(PushPackageOptions options) { if (CloudStorageAccount.TryParse(options.ConnectionString, out var storageAccount)) { try { // Create the CloudBlobClient that represents the Blob storage endpoint for the storage account. CloudBlobClient cloudBlobClient = storageAccount.CreateCloudBlobClient(); var cloudBlobContainer = cloudBlobClient.GetContainerReference(options.PackageName.Replace(".", "-").ToLower()); if (!cloudBlobContainer.ExistsAsync().GetAwaiter().GetResult()) { console.WriteLine($"Package: {options.PackageName} does not exist."); return(2); } if (!File.Exists(options.File)) { console.WriteLine($"File not found: {options.File}"); return(2); } switch (options.Platform) { case "any": case "win-x64": case "osx-x64": case "linux-x64": break; default: console.WriteLine($"Platform {options.Platform} is not valid."); return(2); } var ver = Version.Parse(options.Version); // Get a reference to the blob address, then upload the file to the blob. // Use the value of localFileName for the blob name. CloudBlockBlob cloudBlockBlob = cloudBlobContainer.GetBlockBlobReference($"{options.PackageName}.{options.Platform}.{options.Version}.avpkg"); var fileInfo = new FileInfo(options.File); var progress = new Progress <StorageProgress>(p => { console?.OverWrite($"Uploaded: [{(((float)p.BytesTransferred / fileInfo.Length) * 100.0f).ToString("0.00")}%] {ByteSizeHelper.ToString(p.BytesTransferred)}/{ByteSizeHelper.ToString(fileInfo.Length)} "); }); cloudBlockBlob.Metadata["platform"] = options.Platform; cloudBlockBlob.Metadata["version"] = ver.ToString(); console.WriteLine("Uploading..."); cloudBlockBlob.UploadFromFileAsync(options.File, default(AccessCondition), default(BlobRequestOptions), default(OperationContext), progress, new System.Threading.CancellationToken()).Wait(); console.WriteLine($"Package uploaded: {cloudBlockBlob.Uri}"); return(1); } catch (Exception e) { console.WriteLine("Error: " + e.Message); return(2); } } else { console.WriteLine("Invalid connection string"); return(2); } }
public override string GetSize() { return(ByteSizeHelper.GetSize(DirectoryInfo.GetFiles("*", SearchOption.AllDirectories).Select(f => new FileObject(f).SizeInBytes.GetValueOrDefault(0)).Sum())); }
public override string ToString() { return(string.Format("{0}, {1} files, {2}", PatchName, Files.Count, ByteSizeHelper.ToString(PatchSize))); }