예제 #1
0
        async Task FormatFile(PolicyContainer policies, FilePath file)
        {
            string mime = DesktopService.GetMimeTypeForUri(file);

            if (mime == null)
            {
                return;
            }
            var formatter = CodeFormatterService.GetFormatter(mime);

            if (formatter != null)
            {
                try {
                    var content = await TextFileUtility.ReadAllTextAsync(file);

                    var formatted = formatter.FormatText(policies, content.Text);
                    if (formatted != null)
                    {
                        TextFileUtility.WriteText(file, formatted, content.Encoding);
                    }
                } catch (Exception ex) {
                    TemplatingServices.LogError("File formatting failed", ex);
                }
            }
        }
예제 #2
0
        IEnumerable <SolutionTemplate> LoadTemplates()
        {
            try {
                var templateEngine = TemplatingServices.TemplatingEngine;
                templateEngine.LoadTemplates();

                return(templateEngine.Templates);
            } catch (Exception ex) {
                TemplatingServices.LogError("Unable to load templates.", ex);
                cachedTemplates = new SolutionTemplate [0];
                cacheExpiryDate = DateTime.UtcNow.Add(cacheExpiryTimeSpan);
            }
            return(cachedTemplates);
        }
예제 #3
0
        public void LoadTemplates()
        {
            if (loaded || !TemplatingServices.Options.TemplateFolders.Any())
            {
                return;
            }

            EnsureInitialized();

            var settingsLoader = (SettingsLoader)settings.SettingsLoader;

            foreach (string folder in TemplatingServices.Options.TemplateFolders)
            {
                if (Directory.Exists(folder))
                {
                    try {
                        settingsLoader.UserTemplateCache.Scan(folder);
                    } catch (Exception ex) {
                        string message = string.Format("Unable to load templates from folder '{0}.", folder);
                        TemplatingServices.LogError(message, ex);
                    }
                }
            }

            // If there are no templates found then do not save the settings. This
            // avoids a null reference exception in the settingsLoader.Save method.
            if (!settingsLoader.MountPoints.Any())
            {
                loaded = true;
                return;
            }

            settingsLoader.Save();
            paths.WriteAllText(paths.User.FirstRunCookie, string.Empty);

            foreach (TemplateInfo templateInfo in settingsLoader.UserTemplateCache.TemplateInfo)
            {
                var template = new CustomSolutionTemplate(templateInfo);
                templates.Add(template);
            }

            loaded = true;
        }
        public static void FormatFile(PolicyContainer policies, FilePath fileName)
        {
            CodeFormatter formatter = GetFormatter(fileName);

            if (formatter == null)
            {
                return;
            }

            try {
                string content   = File.ReadAllText(fileName);
                string formatted = formatter.FormatText(policies, content);
                if (formatted != null)
                {
                    TextFileUtility.WriteText(fileName, formatted, Encoding.UTF8);
                }
            } catch (Exception ex) {
                TemplatingServices.LogError("File formatting failed", ex);
            }
        }
 public override void LogMessage(string message)
 {
     TemplatingServices.LogInfo(message);
 }