Example #1
0
        public Commit(IPXPmx model, IPEFormConnector connector, string message, ICompressor compressor, LogArchive logArchive)
        {
            Compressor = compressor;
            LogArchive = logArchive;

            Connector = connector;
            Model     = model;

            DateTime now = DateTime.Now;

            Log = new CommitLog(
                now,
                message,
                (date, msg) => $"{date:yyyy-MM-dd-HH-mm-ss-ff}_{Regex.Replace(msg, @"[<>:\/\\|? *""]", "")}.pmx",
                CommitLog.ConvertFormatEnum(Compressor.ArchiveFormat),
                LogArchive.ArchivePath
                );
        }
Example #2
0
        public void ReCompress(Action <object, DetailedProgressEventArgs, string> detailedProgressHandler, Action <string> otherProgressHandler, Action unCompressLogRetryProgress)
        {
            var unCompLogs = CommitLogs.Where(log => log.Format == CommitLog.ArchiveFormat.None);

            var doesAddUnCompLogsToArchive = false;

            if (unCompLogs.Any())
            {
                doesAddUnCompLogsToArchive = MessageBox.Show(
                    $"未圧縮履歴が存在しました。{Environment.NewLine}圧縮アーカイブに追加しますか?",
                    "未圧縮履歴の再圧縮",
                    MessageBoxButtons.YesNo) == DialogResult.Yes;
            }

            // 展開フォルダへの追加に失敗したログと例外を保存するリスト
            var failedCopyLogs = new List <(CommitLog Log, Exception Ex)>();

            Compressor.ReCompress(
                ArchivePathWitoutExt,
                detailedProgressHandler,
                otherProgressHandler,
                doesAddUnCompLogsToArchive ? (extractPath) =>
            {
                unCompressLogRetryProgress?.Invoke();

                foreach (var log in unCompLogs)
                {
                    try
                    {
                        File.Copy(Path.Combine(log.SavedPath, log.Filename), Path.Combine(extractPath, log.Filename));
                    }
                    catch (Exception ex)
                    {
                        failedCopyLogs.Add((log, ex));
                    }
                }

                if (failedCopyLogs.Any())
                {
                    MessageBox.Show($"以下の未圧縮履歴の圧縮アーカイブへの追加に失敗しました。{Environment.NewLine}" +
                                    failedCopyLogs.Select(failed => failed.Log.Filename + " : " + failed.Ex.Message),
                                    "未圧縮履歴の再圧縮", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }
            } : (Action <string>)null
                );

            if (doesAddUnCompLogsToArchive)
            {
                foreach (var log in unCompLogs.Where(log => !failedCopyLogs.Select(pair => pair.Log).Contains(log)))
                {
                    // 追加に成功した未圧縮ログの削除
                    // 未圧縮状態でのログはここで削除しないと
                    // 再圧縮に失敗した場合一時フォルダもろとも消去される
                    Remove(log);
                    // ここで追加しないと再圧縮失敗時に不正なログが追加されてしまう
                    AppendToJsonLog(new CommitLog(log.Date, log.Message, log.Filename,
                                                  CommitLog.ConvertFormatEnum(Compressor.ArchiveFormat),
                                                  ArchivePath));
                }
                OrderLog();
            }
        }