コード例 #1
0
        public static async Task RunAsync(BuildContext ctx)
        {
            var  cmd         = ctx.GetCommand();
            bool forceSwitch = (cmd as ISupportForceSwitch)?.ForceSwitch ?? false;

            var ap = ctx.GetArtifactPackage();

            var(wasAlreadyPresent, localPath) = await ArtifactsApi.FetchArtifact(ctx, ap, forceSwitch);

            if (wasAlreadyPresent)
            {
                await Console.Out.WriteLineAsync("Download skipped, file exists: " + localPath);
            }
            else
            {
                var fileSize = new FileInfo(localPath).Length;
                await Console.Out.WriteLineAsync($"Saved: ({fileSize.Bytes().Humanize("MB")}) {localPath}");
            }
        }
コード例 #2
0
        public static async Task RunAsync(BuildContext ctx)
        {
            var  cmd         = ctx.GetCommand();
            bool forceSwitch = (cmd as ISupportForceSwitch)?.ForceSwitch ?? false;

            var ap = ctx.GetArtifactPackage();

            long reportThreshold = 0;

            var(wasAlreadyPresent, localPath) =
                await ArtifactsApi.FetchArtifact(
                    ctx, ap, forceSwitch,
                    (bytesRead, bytesReadTotal) =>
            {
                reportThreshold += bytesRead;

                // Throttle reporting
                if (reportThreshold >= (1024 * 1024 * 5))
                {
                    reportThreshold = 0;
                    Console.Out.WriteAsync(".");
                }
            },
                    bytesReadTotal =>
            {
                Console.Out.WriteLineAsync();
            });

            if (wasAlreadyPresent)
            {
                Console.WriteLine("Download skipped, file exists: " + localPath);
            }
            else
            {
                var fileSize = new FileInfo(localPath).Length;
                Console.WriteLine($"Saved: ({fileSize.Bytes().Humanize("MB")}) {localPath}");
            }
        }
コード例 #3
0
        public void Handle(LogFileLoaded message)
        {
            var size = new FileInfo(message.LogFile).Length;

            FileSize = size.Bytes().Humanize("#.##");
        }
コード例 #4
0
ファイル: Optimiser.cs プロジェクト: MCKanpolat/dotnet-tinify
        async Task CompressFile(string file)
        {
            try
            {
                Console.WriteLine($"Compressing {Path.GetFileName(file)}...");

                var originalSizeInBytes = new FileInfo(file).Length;

                var source = Tinify.FromFile(file);
                await source.ToFile(file);

                var newSizeInBytes = new FileInfo(file).Length;
                var percentChange  = (newSizeInBytes - originalSizeInBytes) * 100.0 / originalSizeInBytes;

                Console.WriteLine($"Compression complete. {Path.GetFileName(file)} was {originalSizeInBytes.Bytes()}, now {newSizeInBytes.Bytes()} (-{percentChange:0}%)");
            }
            catch (System.Exception ex)
            {
                Console.WriteLine($"An error occurred compressing {Path.GetFileName(file)}: ");
                Console.WriteLine(ex);
            }
        }