Beispiel #1
0
        public static List <ReportViewTemplate> LoadTemplates(string templateFolder)
        {
            List <ReportViewTemplate> viewTemplates = new List <ReportViewTemplate>();

            //Templates
            foreach (var templatePath in Directory.GetFiles(templateFolder, "*.cshtml"))
            {
                if (templatePath.EndsWith(".config.cshtml"))
                {
                    continue;
                }
                ReportViewTemplate template = new ReportViewTemplate()
                {
                    Name = Path.GetFileNameWithoutExtension(templatePath)
                };
                template.FilePath          = templatePath;
                template.ConfigurationPath = Path.Combine(templateFolder, Path.GetFileNameWithoutExtension(templatePath) + ".config.cshtml");
                viewTemplates.Add(template);

                if (!File.Exists(template.ConfigurationPath))
                {
                    template.Error = string.Format("Unable to find configuration file '{0}' for the template '{1}'", template.ConfigurationPath, template.Name);
                }
                else
                {
                    template.ParseConfiguration(null);
                }
            }
            return(viewTemplates);
        }
        public static ReportView Create(ReportViewTemplate template)
        {
            ReportView result = new ReportView()
            {
                GUID = Guid.NewGuid().ToString(), TemplateName = template.Name
            };

            return(result);
        }
        public static List <ReportViewTemplate> LoadTemplates(string templateFolder)
        {
            List <ReportViewTemplate> viewTemplates = new List <ReportViewTemplate>();

            //Templates
            foreach (var path in Directory.GetFiles(templateFolder, "*.cshtml"))
            {
                if (path.EndsWith(".config.cshtml"))
                {
                    continue;
                }
                ReportViewTemplate template = new ReportViewTemplate();
                template.Init(path);
                viewTemplates.Add(template);
            }
            return(viewTemplates);
        }
        /// <summary>
        /// Returns a list of ReportViewTemplate from a given folder
        /// </summary>
        public static List <ReportViewTemplate> LoadTemplates(string templateFolder)
        {
            List <ReportViewTemplate> viewTemplates = new List <ReportViewTemplate>();

            //Templates
            foreach (var path in Directory.GetFiles(templateFolder, "*.cshtml"))
            {
                if (path.EndsWith(".config.cshtml") || path.EndsWith(".partial.cshtml"))
                {
                    continue;
                }
                if (path.EndsWith("ModelContainer.cshtml"))
                {
                    continue;                                         //backward compatibility before 6.1
                }
                ReportViewTemplate template = new ReportViewTemplate();
                if (template.Init(path))
                {
                    viewTemplates.Add(template);
                }
            }
            return(viewTemplates);
        }
Beispiel #5
0
        public ReportView AddChildView(ReportView parent, ReportViewTemplate template)
        {
            if (Models.Count == 0) throw new Exception("Unable to create a view: No model available.\r\nPlease create a model first.");

            ReportView result = ReportView.Create(template);
            result.Name = Helper.GetUniqueName(template.Name + " View", (from i in parent.Views select i.Name).ToList());
            result.Report = this;
            result.InitReferences();
            result.SortOrder = parent.Views.Count > 0 ? parent.Views.Max(i => i.SortOrder) + 1 : 1;
            if (template.ForModel) result.ModelGUID = Models[0].GUID;
            parent.Views.Add(result);
            return result;
        }
        public static List<ReportViewTemplate> LoadTemplates(string templateFolder)
        {
            List<ReportViewTemplate> viewTemplates = new List<ReportViewTemplate>();
            //Templates
            foreach (var templatePath in Directory.GetFiles(templateFolder, "*.cshtml"))
            {
                if (templatePath.EndsWith(".config.cshtml")) continue;
                ReportViewTemplate template = new ReportViewTemplate() { Name = Path.GetFileNameWithoutExtension(templatePath) };
                template.FilePath = templatePath;
                template.ConfigurationPath = Path.Combine(templateFolder, Path.GetFileNameWithoutExtension(templatePath) + ".config.cshtml");
                viewTemplates.Add(template);

                if (!File.Exists(template.ConfigurationPath))
                {
                    template.Error = string.Format("Unable to find configuration file '{0}' for the template '{1}'", template.ConfigurationPath, template.Name);
                }
                else
                {
                    template.ParseConfiguration(null);
                }
            }
            return viewTemplates;
        }
        /// <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);
        }
Beispiel #8
0
 public static ReportView Create(ReportViewTemplate template)
 {
     ReportView result = new ReportView() { GUID = Guid.NewGuid().ToString(), TemplateName = template.Name };
     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);
        }