/// <summary> /// Returns a ReportViewTemplate from a given name /// </summary> public static ReportViewTemplate GetViewTemplate(string name) { lock (_viewLock) { if (_viewTemplates == null) { _viewTemplates = ReportViewTemplate.LoadTemplates(ViewsFolder); } } var result = _viewTemplates.FirstOrDefault(i => i.Name == name); if (result == null) { lock (_viewLock) { //Get the name for configuration text to avoid useless parsing and save time foreach (var template in _viewTemplates.Where(i => !i.IsParsed)) { if (template.Configuration.Contains(string.Format("\"{0}\";", name))) { template.ParseConfiguration(); break; } } } } result = _viewTemplates.FirstOrDefault(i => i.Name == name); if (result == null) { System.Diagnostics.Debug.WriteLine("!! Loading all the templates !!"); lock (_viewLock) { //Name not found in configuration -> we parse all... foreach (var template in _viewTemplates.Where(i => !i.IsParsed)) { template.ParseConfiguration(); } } if (name.EndsWith(" HTML")) { name = name.Replace(" HTML", ""); //backward compatibility before 5.0 } if (name == "Model CSV Excel") { name = "Model"; //backward compatibility before 5.0 } result = _viewTemplates.FirstOrDefault(i => i.Name == name); } if (result == null) { throw new Exception(string.Format("Unable to find view template named '{0}'", name)); } //Check if the file has changed if (result.IsModified) { lock (_viewLock) { result.Init(result.FilePath); } } //Check if configuration has been parsed if (!result.IsParsed) { lock (_viewLock) { result.ParseConfiguration(); } } return(result); }
public static ReportViewTemplate GetViewTemplate(string name) { lock (_viewLock) { if (_viewTemplates == null) { _viewTemplates = ReportViewTemplate.LoadTemplates(Repository.Instance.ViewsFolder); } } var result = _viewTemplates.FirstOrDefault(i => i.Name == name); if (result == null) { lock (_viewLock) { //Get the name for configuration text to avoid useless parsing and save time foreach (var template in _viewTemplates.Where(i => !i.IsParsed)) { if (template.Configuration.Contains(string.Format("\"{0}\";", name))) { template.ParseConfiguration(); break; } } } } result = _viewTemplates.FirstOrDefault(i => i.Name == name); if (result == null) { lock (_viewLock) { //Name not found in configuration -> we parse all... foreach (var template in _viewTemplates.Where(i => !i.IsParsed)) { template.ParseConfiguration(); } } result = _viewTemplates.FirstOrDefault(i => i.Name == name); } if (result == null) { throw new Exception(string.Format("Unable to find view template named '{0}'", name)); } //Check if the file has changed if (result.LastModification != File.GetLastWriteTime(result.FilePath) || result.LastConfigModification != File.GetLastWriteTime(result.ConfigurationPath)) { lock (_viewLock) { result.Init(result.FilePath); } } //Check if configuration has been parsed if (!result.IsParsed) { lock (_viewLock) { result.ParseConfiguration(); } } return(result); }