Esempio n. 1
0
        public void Setup()
        {
            Telemetry.Enabled = false;
            _handler = new ConfigHandler();

            File.Copy(originalConfigFile, processingConfigFile, true);
        }
Esempio n. 2
0
        private void AddConfig(object sender, EventArgs e)
        {
            var question = MessageBox.Show($"This will remove the file from {Constants.CONFIG_FILENAME}.\r\rDo you want to continue?", Constants.VSIX_NAME, MessageBoxButtons.OKCancel, MessageBoxIcon.Question);

            if (question == DialogResult.Cancel)
                return;

            ConfigHandler handler = new ConfigHandler();

            try
            {
                foreach (Config config in _configs)
                {
                    handler.RemoveConfig(config);
                }
            }
            catch (Exception ex)
            {
                Logger.Log(ex);
                WebCompilerPackage._dte.StatusBar.Text = $"Could not update {Constants.CONFIG_FILENAME}. Make sure it's not write-protected or has syntax errors.";
            }
        }
Esempio n. 3
0
        private void AddConfig(object sender, EventArgs e)
        {
            string folder = _item.ContainingProject.GetRootFolder();
            string configFile = _item.ContainingProject.GetConfigFile();
            string relativeFile = FileHelpers.MakeRelative(configFile, ProjectHelpers.GetSelectedItemPaths().First());

            // Recompile if already configured
            if (_reCompileConfigs.Any())
            {
                string absoluteFile = Path.Combine(folder, relativeFile).Replace("/", "\\");
                CompilerService.SourceFileChanged(configFile, absoluteFile);
                return;
            }

            // Create new config
            WebCompilerPackage._dte.StatusBar.Progress(true, "Compiling file", 0, 3);
            string inputFile = _item.Properties.Item("FullPath").Value.ToString();
            string outputFile = GetOutputFileName(inputFile);

            if (string.IsNullOrEmpty(outputFile))
                return;

            string relativeOutputFile = FileHelpers.MakeRelative(configFile, outputFile);
            Config config = CreateConfigFile(relativeFile, relativeOutputFile);

            WebCompilerPackage._dte.StatusBar.Progress(true, "Compiling file", 1, 3);

            ConfigHandler handler = new ConfigHandler();
            handler.AddConfig(configFile, config);

            _item.ContainingProject.AddFileToProject(configFile, "None");
            WebCompilerPackage._dte.StatusBar.Progress(true, "Compiling file", 2, 3);

            // Create defaults file
            string defaultsFile = Path.Combine(folder, Constants.DEFAULTS_FILENAME);
            ProjectHelpers.CheckFileOutOfSourceControl(defaultsFile);
            handler.CreateDefaultsFile(defaultsFile);
            ProjectHelpers.AddNestedFile(configFile, defaultsFile);
            WebCompilerPackage._dte.StatusBar.Progress(true, "Creating defaults file", 3, 3);

            CompilerService.Process(configFile, new[] { config });
            WebCompilerPackage._dte.StatusBar.Progress(false, "Compiling file");
        }
Esempio n. 4
0
        /// <summary>
        /// Compiles all configs with the same input file extension as the specified sourceFile
        /// </summary>
        private IEnumerable <CompilerResult> SourceFileChanged(string configFile,
                                                               string sourceFile,
                                                               string projectPath,
                                                               HashSet <string> compiledFiles)
        {
            lock (_syncRoot)
            {
                string folder = Path.GetDirectoryName(configFile);
                List <CompilerResult> list = new List <CompilerResult>();
                var configs = ConfigHandler.GetConfigs(configFile);

                // Compile if the file if it's referenced directly in compilerconfig.json
                foreach (Config config in configs)
                {
                    Config matchingConfig = config.Match(folder, sourceFile);
                    if (matchingConfig != null)
                    {
                        list.Add(ProcessConfig(folder, matchingConfig));
                        compiledFiles.Add(matchingConfig.InputFile.ToLowerInvariant());
                    }
                }

                //compile files that are dependent on the current file
                var dependencies = DependencyService.GetDependencies(projectPath, sourceFile);
                if (dependencies != null)
                {
                    string key = sourceFile.ToLowerInvariant();

                    if (dependencies.ContainsKey(key))
                    {
                        //compile all files that have references to the compiled file
                        foreach (var file in dependencies[key].DependentFiles.ToArray())
                        {
                            if (!compiledFiles.Contains(file.ToLowerInvariant()))
                            {
                                list.AddRange(SourceFileChanged(configFile, file, projectPath, compiledFiles));
                            }
                        }
                    }
                }
                else
                {
                    // If not referenced directly, compile all configs with same file extension
                    if (list.Count == 0)
                    {
                        string sourceExtension = Path.GetExtension(sourceFile);

                        foreach (Config config in configs)
                        {
                            string inputExtension = Path.GetExtension(config.InputFile);

                            if (inputExtension.Equals(sourceExtension, StringComparison.OrdinalIgnoreCase))
                            {
                                list.Add(ProcessConfig(folder, config));
                            }
                        }
                    }
                }

                return(list);
            }
        }
Esempio n. 5
0
        public void Setup()
        {
            _handler = new ConfigHandler();

            File.Copy(originalConfigFile, processingConfigFile, true);
        }