Esempio n. 1
0
        public void Commit()
        {
            try
            {
                var dictionary = TransactionPool.GetDictionary;
                lock (_locker)
                {
                    _log.Info(string.Format("[COMMIT] START WRITING"));

                    foreach (var key in dictionary)
                    {
                        if (key.Value.Modified == null)
                        {
                            return;
                        }

                        _log.Info(string.Format("[COMMIT] Data commit {0}", key.Value.FilePath));
                        using (var transaction = new Transaction(key.Value.FilePath, key.Value.Modified))
                        {
                            transaction.WriteStream();
                        }

                        if (File.Exists(key.Value.FilePath + ".backup"))
                        {
                            File.Delete(key.Value.FilePath + ".backup");
                        }
                    }
                    MarkAsModified();
                    TransactionPool.SetMarker(false);
                    TransactionPool = null;
                }
            }
            catch (Exception exception)
            {
                TransactionPool = null;
                TransactionPool?.RollBack();

                _log.Error($"[COMMIT]:{exception.Message}");
                throw new Exception("Transaction failed.", exception);
            }
        }