using System; using System.Collections.Generic; using System.Runtime.Serialization; using System.ServiceModel; using System.Text; using System.IO; using System.Configuration; using System.Collections; using FastReport; using FastReport.Utils; using System.ServiceModel.Web; namespace FastReport.Service { public partial class ReportService : IFastReportService { public List GetReportsList() { return GetReportsListByPath(""); } public List GetReportsListXml() { return GetReportsListByPath(""); } public List GetReportsListByPathXml(string path) { return GetReportsListByPath(path); } public List GetReportsListByPath(string path) { string reportsRoot = GetReportsPath(); List list = new List(); if (Directory.Exists(Path.Combine(reportsRoot, path))) { if (string.IsNullOrEmpty(path)) path = ""; List reports = GetReportFiles(Path.Combine(reportsRoot, path)); Report report = new Report(); try { foreach (string s in reports) { ReportItem item = new ReportItem(); item.Path = s.Replace(reportsRoot + Path.DirectorySeparatorChar, ""); item.ID = Crypter.ComputeHash(item.Path); report.Load(s); item.Name = !string.IsNullOrEmpty(report.ReportInfo.Name) ? report.ReportInfo.Name : Path.GetFileNameWithoutExtension(s); item.Description = report.ReportInfo.Description; list.Add(item); } } catch (Exception e) { throw new WebFaultException(new ErrorHandler { Cause = e.Message, ErrorCode = 105 }, System.Net.HttpStatusCode.InternalServerError); } } else throw new WebFaultException(new ErrorHandler { Cause = "Reports directory not found", ErrorCode = 104 }, System.Net.HttpStatusCode.NotFound); return list; } private List GetReportFiles(string path) { List list = new List(); if (Directory.Exists(path)) { string[] reports = Directory.GetFiles(path, "*.frx"); list.AddRange(reports); list.Sort(); string[] dirs = Directory.GetDirectories(path); foreach (string dir in dirs) { List folders = GetReportFiles(Path.Combine(path, dir)); folders.Sort(); list.AddRange(folders); } } return list; } } }