Example #1
0
        private async Task <CompressionResult> CompressFile(string fileName)
        {
            string targetFile = Path.ChangeExtension(Path.GetTempFileName(), Path.GetExtension(fileName));

            ProcessStartInfo start = new ProcessStartInfo("cmd")
            {
                WindowStyle      = ProcessWindowStyle.Hidden,
                WorkingDirectory = Path.Combine(Path.GetDirectoryName(GetType().Assembly.Location), @"Resources\tools\"),
                Arguments        = GetArguments(fileName, targetFile),
                UseShellExecute  = false,
                CreateNoWindow   = true,
            };

            try
            {
                using (var process = await start.ExecuteAsync())
                {
                    return(new CompressionResult(fileName, targetFile));
                }
            }
            catch
            {
                CompressionResult result = new CompressionResult(fileName, targetFile);
                File.Delete(targetFile);
                return(result);
            }
        }
Example #2
0
        private static void HandleResult(string file, CompressionResult result)
        {
            string name = file.Contains(_dataUriPrefix) ? "The dataUri" : Path.GetFileName(file);

            if (result.Saving > 0)
            {
                ProjectHelpers.CheckOutFileFromSourceControl(result.OriginalFileName);
                File.Copy(result.ResultFileName, result.OriginalFileName, true);

                string text = "Compressed " + name + " by " + result.Saving + " bytes / " + result.Percent + "%";
                WebEssentialsPackage.DTE.StatusBar.Text = text;
                Logger.Log(result.ToString());
            }
            else
            {
                WebEssentialsPackage.DTE.StatusBar.Text = name + " is already optimized";
            }
        }
        private static void HandleResult(string file, CompressionResult result)
        {
            string name = file.Contains(_dataUriPrefix) ? "the dataUri" : Path.GetFileName(file);

            if (result.Saving > 0)
            {
                ProjectHelpers.CheckOutFileFromSourceControl(result.OriginalFileName);
                File.Copy(result.ResultFileName, result.OriginalFileName, true);

                string text = "Compressed " + name + " by " + result.Saving + " bytes / " + result.Percent + "%";
                WebEssentialsPackage.DTE.StatusBar.Text = text;
                Logger.Log(result.ToString());
            }
            else
            {
                WebEssentialsPackage.DTE.StatusBar.Text = name + " is already optimized";
            }
        }
        private async Task<CompressionResult> CompressFile(string fileName)
        {
            string targetFile = Path.ChangeExtension(Path.GetTempFileName(), Path.GetExtension(fileName));

            ProcessStartInfo start = new ProcessStartInfo("cmd")
            {
                WindowStyle = ProcessWindowStyle.Hidden,
                WorkingDirectory = Path.Combine(Path.GetDirectoryName(GetType().Assembly.Location), @"Resources\tools\"),
                Arguments = GetArguments(fileName, targetFile),
                UseShellExecute = false,
                CreateNoWindow = true,
            };

            try
            {
                using (var process = await start.ExecuteAsync())
                {
                    return new CompressionResult(fileName, targetFile);
                }
            }
            catch
            {
                CompressionResult result = new CompressionResult(fileName, targetFile);
                File.Delete(targetFile);
                return result;
            }
        }