Report getScheduledReport(SealSchedule refSchedule)
        {
            Report report = null;

            if (File.Exists(refSchedule.ReportPath))
            {
                report = Report.LoadFromFile(refSchedule.ReportPath, Repository.Instance);
            }

            if (!File.Exists(refSchedule.ReportPath) || (report != null && report.GUID != refSchedule.ReportGUID))
            {
                //Report has been moved or renamed: search report from its GUID in the report folder
                report = Repository.Instance.FindReport(Repository.Instance.ReportsFolder, refSchedule.ReportGUID);
                if (report == null)
                {
                    //Remove the schedules of the report
                    var reportSchedules = _schedules.Values.Where(i => i.ReportGUID == refSchedule.ReportGUID).ToList();
                    foreach (var schedule in reportSchedules)
                    {
                        File.Delete(schedule.FilePath);
                        lock (_schedules)
                        {
                            _schedules.Remove(schedule.GUID);
                        }
                    }
                }
            }
            return(report);
        }
Exemple #2
0
        /// <summary>
        /// Load a web schedule from a file
        /// </summary>
        static public SealSchedule LoadFromFile(string path)
        {
            SealSchedule result = null;

            try
            {
                path = FileHelper.ConvertOSFilePath(path);
                if (!File.Exists(path))
                {
                    throw new Exception("File not found: " + path);
                }

                XmlSerializer serializer = new XmlSerializer(typeof(SealSchedule));
                using (XmlReader xr = XmlReader.Create(path))
                {
                    result = (SealSchedule)serializer.Deserialize(xr);
                }
                result.FilePath         = path;
                result.LastModification = File.GetLastWriteTime(path);
            }
            catch (Exception ex)
            {
                throw new Exception(string.Format("Unable to read the file '{0}'.\r\n{1}\r\n", path, ex.Message, ex.StackTrace));
            }
            return(result);
        }
        void loadSchedules()
        {
            if (_schedules == null)
            {
                _schedules = new Dictionary <string, SealSchedule>();
            }
            lock (_schedules)
            {
                foreach (var file in Directory.GetFiles(Repository.Instance.SchedulesFolder, "*.xml"))
                {
                    var schedule = _schedules.Values.FirstOrDefault(i => i.FilePath == file);
                    if (schedule == null || (!schedule.BeingExecuted && File.GetLastWriteTime(file) != schedule.LastModification))
                    {
                        try
                        {
                            schedule = SealSchedule.LoadFromFile(file);
                            //Adjust report path if necessary (case of copy between Windows OS to Linux OS)
                            if (!File.Exists(schedule.ReportPath))
                            {
                                var newReportPath = Repository.Instance.ReportsFolder + schedule.ReportPath;
                                if (Path.DirectorySeparatorChar == '/' && newReportPath.Contains("\\"))
                                {
                                    newReportPath = newReportPath.Replace("\\", "/");
                                }
                                else if (Path.DirectorySeparatorChar == '\\' && newReportPath.Contains("/"))
                                {
                                    newReportPath = newReportPath.Replace("/", "\\");
                                }
                                if (File.Exists(newReportPath))
                                {
                                    schedule.ReportPath = newReportPath;
                                }
                            }

                            if (_schedules.ContainsKey(schedule.GUID))
                            {
                                _schedules[schedule.GUID] = schedule;
                            }
                            else
                            {
                                _schedules.Add(schedule.GUID, schedule);
                            }
                        }

                        catch (Exception ex)
                        {
                            Helper.WriteLogEntryScheduler(EventLogEntryType.Error, "Error loading '{0}'.\r\n{1}", file, ex.Message);
                        }
                    }
                }

                //Remove lost schedules
                foreach (var schedule in _schedules.Values.Where(i => !File.Exists(i.FilePath)).ToList())
                {
                    _schedules.Remove(schedule.GUID);
                }
            }
        }
        public SealSchedule CreateSchedule(string guid, string name, Report report)
        {
            var sealSchedule = new SealSchedule()
            {
                GUID = guid
            };

            sealSchedule.ReportPath = report.FilePath;
            sealSchedule.ReportGUID = report.GUID;
            sealSchedule.FilePath   = Path.Combine(report.Repository.SchedulesFolder, name) + ".xml";
            return(sealSchedule);
        }
        Report getScheduledReport(SealSchedule refSchedule)
        {
            Report report     = null;
            var    reportPath = refSchedule.ReportPath;

            if (!File.Exists(reportPath))
            {
                reportPath = Repository.Instance.ReportsFolder + reportPath;
            }

            if (File.Exists(reportPath))
            {
                report = Report.LoadFromFile(reportPath, Repository.Instance);
            }

            if (!File.Exists(reportPath) || (report != null && report.GUID != refSchedule.ReportGUID))
            {
                Helper.WriteLogEntryScheduler(EventLogEntryType.Warning, "The report of schedule '{0}' does not exists ('{1}').\r\nSearching for the report in the repository...", refSchedule.FilePath, refSchedule.ReportPath);

                //Report has been moved or renamed: search report from its GUID in the report folder
                report = Repository.Instance.FindReport(Repository.Instance.ReportsFolder, refSchedule.ReportGUID);
                if (report != null)
                {
                    Helper.WriteLogEntryScheduler(EventLogEntryType.Warning, "Report of schedule '{0}' has changed to '{1}'", refSchedule.FilePath, report.FilePath);
                }
            }

            if (report == null)
            {
                Helper.WriteLogEntryScheduler(EventLogEntryType.Warning, "Report of schedule '{0}' not found, removing all schedules for the report GUID '{1}'", refSchedule.FilePath, refSchedule.ReportGUID);
                //Remove the schedules of the report
                var reportSchedules = _schedules.Values.Where(i => i.ReportGUID == refSchedule.ReportGUID).ToList();
                foreach (var schedule in reportSchedules)
                {
                    if (File.Exists(schedule.FilePath))
                    {
                        File.Delete(schedule.FilePath);
                    }
                    lock (_schedules)
                    {
                        _schedules.Remove(schedule.GUID);
                    }
                }
            }

            return(report);
        }
 public void SaveSchedule(SealSchedule schedule)
 {
     loadSchedules();
     lock (_schedules)
     {
         if (_schedules.ContainsKey(schedule.GUID))
         {
             File.Delete(_schedules[schedule.GUID].FilePath);
             _schedules[schedule.GUID] = schedule;
         }
         else
         {
             _schedules.Add(schedule.GUID, schedule);
         }
         schedule.SaveToFile();
     }
 }
        /// <summary>
        /// Save a schedule in the repository
        /// </summary>
        public void SaveSchedule(SealSchedule schedule, Report report)
        {
            loadSchedules();
            lock (_schedules)
            {
                if (_schedules.ContainsKey(schedule.GUID))
                {
                    File.Delete(_schedules[schedule.GUID].FilePath);
                    _schedules[schedule.GUID] = schedule;
                }
                else
                {
                    _schedules.Add(schedule.GUID, schedule);
                }

                //Remove repository path
                schedule.ReportPath = report.FilePath.Replace(Repository.Instance.ReportsFolder, "");
                schedule.SaveToFile();
            }
        }
        void loadSchedules()
        {
            if (_schedules == null)
            {
                _schedules = new Dictionary <string, SealSchedule>();
            }
            lock (_schedules)
            {
                foreach (var file in Directory.GetFiles(Repository.Instance.SchedulesFolder, "*.xml"))
                {
                    var schedule = _schedules.Values.FirstOrDefault(i => i.FilePath == file);
                    if (schedule == null || (!schedule.BeingExecuted && File.GetLastWriteTime(file) != schedule.LastModification))
                    {
                        try
                        {
                            schedule = SealSchedule.LoadFromFile(file);
                            if (_schedules.ContainsKey(schedule.GUID))
                            {
                                _schedules[schedule.GUID] = schedule;
                            }
                            else
                            {
                                _schedules.Add(schedule.GUID, schedule);
                            }
                        }

                        catch (Exception ex)
                        {
                            Helper.WriteLogEntryScheduler(EventLogEntryType.Error, "Error loading '{0}'.\r\n{1}", file, ex.Message);
                        }
                    }
                }

                //Remove lost schedules
                foreach (var schedule in _schedules.Values.Where(i => !File.Exists(i.FilePath)).ToList())
                {
                    _schedules.Remove(schedule.GUID);
                }
            }
        }