예제 #1
0
        /// <summary>
        /// Setzt den übergebenen HistoryLogEntry auf 'deleted' und schreibt das in die Datenbank
        /// </summary>
        /// <param name="HLE">Der übergebene HistoryLogEntry der aus der Tabelle kommt</param>
        private void RemoveHistoryLogEntry(HistoryLogEntry HLE)
        {
            // Erstellt eine Datenbankverbindung
            var mssql = new MsSql();

            // Öffnet die Datenbankverbindung
            mssql.Open();

            // Der Update SQL Befehl
            string sql = $"UPDATE schedule SET Status = 'deleted' WHERE ID = @id";

            SqlCommand cmd = new SqlCommand(sql, mssql.Con);

            // Hängt die ID als Parameter an
            cmd.Parameters.AddWithValue("@id", HLE.ID);

            // Führt die Query aus
            cmd.ExecuteNonQuery();

            // Schliest die Datenbankverbindung
            mssql.Close();

            // Lädt die HistoryLogs neu
            AsyncLoadedHistoryLog(100);
        }
예제 #2
0
        /// <summary>
        ///     Deserialize the history log file.
        /// </summary>
        /// <param name="logFile">The file path.</param>
        private void Deserialize(XContainer logFile)
        {
            try
            {
                _historyLogs = new List <HistoryLogEntry>();

                foreach (XElement _historyLogEntries in logFile.Descendants("LogEntry"))
                {
                    var    _entryFilePath = _historyLogEntries.Descendants("FilePath").Nodes();
                    string _file          = string.Concat(_entryFilePath);

                    // var _dateModified = _historyLogEntries.Descendants("DateModified").Nodes();
                    // string _dateTime = string.Concat(_dateModified);
                    if (File.Exists(_file))
                    {
                        HistoryLogEntry _historyLogEntry = new HistoryLogEntry(_file);

                        if (!Exists(_historyLogEntry))
                        {
                            _historyLogs.Add(_historyLogEntry);
                        }
                    }
                }

                UpdateMenu();
            }
            catch (Exception e)
            {
                VisualExceptionDialog.Show(e);
            }
        }
예제 #3
0
        /// <summary>
        ///     Gets a value determined whether the history contains the log entry.
        /// </summary>
        /// <param name="historyLogEntry">The history log entry.</param>
        /// <returns>
        ///     <see cref="HistoryLogEntry" />
        /// </returns>
        public bool Exists(HistoryLogEntry historyLogEntry)
        {
            var _duplicateExists = false;

            foreach (HistoryLogEntry _logs in _historyLogs)
            {
                if (_logs.Equals(historyLogEntry))
                {
                    _duplicateExists = true;
                }
            }

            return(_duplicateExists);
        }
예제 #4
0
        public unsafe void CancelHistoryEntriesFrom(ClusterOperationContext context, long from, long term, string msg)
        {
            var reversedIndex = Bits.SwapBytes(from);

            var table = context.Transaction.InnerTransaction.OpenTable(LogHistoryTable, LogHistorySlice);

            using (Slice.External(context.Transaction.InnerTransaction.Allocator, (byte *)&reversedIndex, sizeof(long), out Slice key))
            {
                var results  = table.SeekForwardFrom(LogHistoryTable.Indexes[LogHistoryIndexSlice], key, 0);
                var toCancel = new List <HistoryLogEntry>();
                foreach (var seekResult in results)
                {
                    var entryHolder = seekResult.Result;
                    var entryTerm   = ReadTerm(entryHolder);

                    if (entryTerm == term)
                    {
                        continue;
                    }

                    var entry = new HistoryLogEntry
                    {
                        Guid   = ReadGuid(entryHolder),
                        Type   = ReadType(entryHolder),
                        Index  = ReadIndex(entryHolder),
                        Status = ReadState(entryHolder),
                        Term   = entryTerm
                    };

                    if (entry.Status != HistoryStatus.Appended)
                    {
                        throw new InvalidOperationException($"Can't cancel the entry with index {entry.Index} and term {entry.Term}, it is already committed.");
                    }

                    toCancel.Add(entry);
                }

                foreach (var entry in toCancel)
                {
                    UpdateInternal(context, entry.Guid, entry.Type, entry.Index, term, entry.Status, null, new OperationCanceledException(msg));
                }
            }
        }
예제 #5
0
        /// <summary>
        ///     Add the file to the history.
        /// </summary>
        /// <param name="filePath">The file path.</param>
        public void Add(string filePath)
        {
            if (!File.Exists(filePath))
            {
                return;
            }

            if (_historyLogs.Count < _maximumHistory)
            {
                HistoryLogEntry _logEntry = new HistoryLogEntry(filePath);

                bool _duplicateExists = Exists(_logEntry);

                if (!_duplicateExists)
                {
                    _historyLogs.Add(_logEntry);
                }
            }
            else
            {
                if (Exists(new HistoryLogEntry(filePath)))
                {
                    return;
                }

                var      _list = _historyLogs.Select(_historyLog => _historyLog.DateModified).ToList();
                DateTime _minimumDateTimeModified = _list.Min();

                foreach (HistoryLogEntry _historyLogEntry in _historyLogs)
                {
                    if (_historyLogEntry.DateModified == _minimumDateTimeModified)
                    {
                        Remove(_historyLogEntry);
                    }
                }
            }
        }
예제 #6
0
 /// <summary>
 ///     Removes the history entry log from the list.
 /// </summary>
 /// <param name="historyLogEntry">The history log entry.</param>
 public void Remove(HistoryLogEntry historyLogEntry)
 {
     _historyLogs.Remove(historyLogEntry);
 }