Esempio n. 1
0
        public void Append(CommitLog commitLog, string tmpFilePath)
        {
            CommitLog log = commitLog;
            Exception ex  = null;

            try
            {
                AppendToArchive(tmpFilePath);
            }
            catch (SaveLogFailedException)
            {
                throw;
            }
            catch (Exception e)
            {
                log = new CommitLog(commitLog.Date, commitLog.Message, commitLog.Filename, CommitLog.ArchiveFormat.None, Path.Combine(CommitDirectory, ArchiveFilename));

                ex = e;
            }
            File.Delete(tmpFilePath);

            try
            {
                AppendToJsonLog(log);
            }
            catch (Exception e)
            {
                throw ex is null ? new SaveLogFailedException("履歴テキストの書込に失敗しました。", e) : new SaveLogFailedException("履歴の保存に失敗しました。", ex);
            }

            if (!(ex is null))
            {
                throw ex;
            }
        }
Esempio n. 2
0
 private void RemoveFromArchive(CommitLog log)
 {
     if (log.Format == CommitLog.ArchiveFormat.None)
     {
         File.Delete(Path.Combine(log.SavedPath, log.Filename));
     }
     else
     {
         Compressor.Remove(log.Filename, log.SavedPath);
     }
 }
Esempio n. 3
0
 public void Remove(CommitLog commitLog)
 {
     try
     {
         RemoveFromArchive(commitLog);
         RemoveFromJsonLog(commitLog);
     }
     catch (Exception)
     {
         throw;
     }
 }
Esempio n. 4
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
                );
        }
Esempio n. 5
0
 private void RemoveFromJsonLog(CommitLog log)
 {
     JsonLog = JsonLog.Where(l => !l.Equals(log));
 }
Esempio n. 6
0
 private void AppendToJsonLog(CommitLog log)
 {
     File.AppendAllText(LogFilePath, log.ToJson() + Environment.NewLine);
 }
Esempio n. 7
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();
            }
        }