예제 #1
0
        /// <summary>
        /// Returns a collection of config objects that all contain the specified sourceFile
        /// </summary>
        public static IEnumerable <Config> IsFileConfigured(string configFile, string sourceFile)
        {
            try
            {
                var           configs = ConfigHandler.GetConfigs(configFile);
                string        folder  = Path.GetDirectoryName(configFile);
                List <Config> list    = new List <Config>();

                foreach (Config config in configs)
                {
                    string input = Path.Combine(folder, config.InputFile.Replace("/", "\\"));

                    if (input.Equals(sourceFile, StringComparison.OrdinalIgnoreCase))
                    {
                        list.Add(config);
                    }
                }

                return(list);
            }
            catch (Exception ex)
            {
                Telemetry.TrackException(ex);
                return(null);
            }
        }
예제 #2
0
        /// <summary>
        /// Execute the Clean Task
        /// </summary>
        public override bool Execute()
        {
            var configFile = new FileInfo(FileName);

            if (!configFile.Exists)
            {
                Log.LogWarning(configFile.FullName + " does not exist");
                return(true);
            }

            Log.LogMessage(MessageImportance.High, Environment.NewLine + "WebCompiler: Begin cleaning output of " + configFile.Name);
            Telemetry.SetDeviceName("MSBuild");

            try
            {
                var processor = new ConfigFileProcessor();
                processor.DeleteOutputFiles(configFile.FullName);

                Log.LogMessage(MessageImportance.High, "WebCompiler: Done cleaning output of " + configFile.Name);

                return(true);
            }
            catch (Exception ex)
            {
                Log.LogError(ex.Message);
                Telemetry.TrackException(ex);
                return(false);
            }
        }
예제 #3
0
        /// <summary>
        /// Execute the Task
        /// </summary>
        public override bool Execute()
        {
            FileInfo configFile = new FileInfo(FileName);

            if (!configFile.Exists)
            {
                Log.LogWarning(configFile.FullName + " does not exist");
                return(true);
            }

            Log.LogMessage(MessageImportance.High, Environment.NewLine + "WebCompiler: Begin compiling " + configFile.Name);
            Telemetry.SetDeviceName("MSBuild");

            ConfigFileProcessor processor = new ConfigFileProcessor();

            processor.BeforeProcess += (s, e) => { if (e.ContainsChanges)
                                                   {
                                                       FileHelpers.RemoveReadonlyFlagFromFile(e.Config.GetAbsoluteOutputFile());
                                                   }
            };
            processor.AfterProcess           += Processor_AfterProcess;
            processor.BeforeWritingSourceMap += (s, e) => { FileHelpers.RemoveReadonlyFlagFromFile(e.ResultFile); };
            processor.AfterWritingSourceMap  += Processor_AfterWritingSourceMap;

            FileMinifier.BeforeWritingMinFile += (s, e) => { if (e.ContainsChanges)
                                                             {
                                                                 FileHelpers.RemoveReadonlyFlagFromFile(e.ResultFile);
                                                             }
            };
            FileMinifier.AfterWritingMinFile   += FileMinifier_AfterWritingMinFile;
            FileMinifier.BeforeWritingGzipFile += (s, e) => { if (e.ContainsChanges)
                                                              {
                                                                  FileHelpers.RemoveReadonlyFlagFromFile(e.ResultFile);
                                                              }
            };
            FileMinifier.AfterWritingGzipFile += FileMinifier_AfterWritingGzipFile;

            CompilerService.Initializing += (s, e) => { Log.LogMessage(MessageImportance.High, "WebCompiler installing updated versions of the compilers..."); };

            try
            {
                var  results      = processor.Process(configFile.FullName);
                bool isSuccessful = true;

                foreach (CompilerResult result in results)
                {
                    if (result.HasErrors)
                    {
                        isSuccessful = false;

                        foreach (var error in result.Errors)
                        {
                            Log.LogError("WebCompiler", "0", "", error.FileName, error.LineNumber, error.ColumnNumber, error.LineNumber, error.ColumnNumber, error.Message, null);
                        }
                    }
                }

                Log.LogMessage(MessageImportance.High, "WebCompiler: Done compiling " + configFile.Name);
                return(isSuccessful);
            }
            catch (Exception ex)
            {
                Log.LogError(ex.Message);
                Telemetry.TrackException(ex);
                return(false);
            }
        }