Beispiel #1
0
        private async Task ArchiveReport(Report report)
        {
            reloadTask.Wait();

            await Task.Run(() =>
            {
                FileInfo reportInfo          = new FileInfo(report.Path);
                FileInfo generatedReportInfo = new FileInfo(Path.Combine(reportInfo.Directory.FullName, report.GetGeneratedReportName()));

                DateTime now = DateTime.Now;

                // Check if archiving is needed
                if (generatedReportInfo.Exists)
                {
                    DateTime oldArchiveDate = Utils.RoundDateTime(generatedReportInfo.LastWriteTime, report.ArchiveTime);
                    DateTime newArchiveDate = Utils.RoundDateTime(now, report.ArchiveTime);

                    if (newArchiveDate != oldArchiveDate)
                    {
                        string archiveName   = GetArchiveName(oldArchiveDate);
                        FileInfo archiveInfo = new FileInfo(Path.Combine(ArchiveDirectory.FullName, archiveName));

                        if (!ArchiveDirectory.Exists)
                        {
                            ArchiveDirectory.Create();
                        }

                        if (!archiveInfo.Exists)
                        {
                            using (FileStream archiveStream = archiveInfo.Create())
                                using (ZipArchive archive = new ZipArchive(archiveStream, ZipArchiveMode.Create))
                                    archive.ToString();
                        }

                        using (FileStream archiveStream = archiveInfo.Open(FileMode.Open))
                            using (ZipArchive archive = new ZipArchive(archiveStream, ZipArchiveMode.Update))
                            {
                                string reportArchiveName = report.GetArchivedReportName(oldArchiveDate);

                                ZipArchiveEntry reportArchiveEntry = archive.GetEntry(reportArchiveName);
                                if (reportArchiveEntry == null)
                                {
                                    reportArchiveEntry = archive.CreateEntry(reportArchiveName, CompressionLevel.Optimal);

                                    using (FileStream reportStream = generatedReportInfo.OpenRead())
                                        using (Stream reportArchiveStream = reportArchiveEntry.Open())
                                            reportStream.CopyTo(reportArchiveStream);
                                }
                            }
                    }
                }
            });

            await CleanArchives(report);
        }
        /// <summary>
        /// Erzeugt eine neue Verwaltungsinstanz und lädt die aktuellen Auftragsliste.
        /// </summary>
        /// <param name="rootDirectory">Meldet das Verzeichnis, unterhalb dessen alle
        /// Aufträge und Protokolle angelegt werden.</param>
        /// <param name="server">Die VCR.NET Instanz, der diese Verwaltung zugeordnet ist.</param>
        internal JobManager(DirectoryInfo rootDirectory, VCRServer server)
        {
            // Remember
            RootDirectory = rootDirectory;
            Server        = server;

            // Create root directory
            RootDirectory.Create();

            // Create working directories
            CollectorDirectory.Create();
            ArchiveDirectory.Create();
            JobDirectory.Create();
            LogDirectory.Create();

            // Load all jobs
            foreach (var job in VCRJob.Load(JobDirectory))
            {
                if (job.UniqueID.HasValue)
                {
                    m_Jobs[job.UniqueID.Value] = job;
                }
            }
        }