private void WriteSyncServerHistory(ServerHistoryEntryData serverHistoryData, bool writeNewEntry)
        {
            if (serverHistoryData == null)
            {
                throw new ArgumentNullException("serverHistoryEntryData");
            }
            if (this.serverHistoryEntriesList.Count == 0 && !writeNewEntry)
            {
                throw new Exception("last server history entry is null");
            }
            ServerHistoryEntry serverHistoryEntry = writeNewEntry ? null : this.serverHistoryEntriesList.Last <ServerHistoryEntry>();
            DateTime           dateTime           = (DateTime)ExDateTime.UtcNow;

            if (writeNewEntry)
            {
                if (this.serverHistoryEntriesList.Count > this.MaxServerHistoryEntries - 1)
                {
                    this.CleanupOldServerHistory();
                }
                serverHistoryEntry = new ServerHistoryEntry();
                string unescapedCommonName = string.Format("{0}-{1}", dateTime, Environment.MachineName);
                serverHistoryEntry.SetId(this.serverHistoryRootContainerID.GetChildId(unescapedCommonName));
                serverHistoryEntry.Name      = serverHistoryEntry.Id.Name;
                serverHistoryEntry.m_Session = this.serverHistorySession;
                serverHistoryEntry.Version   = 1;
                this.serverHistoryEntriesList.Add(serverHistoryEntry);
            }
            serverHistoryEntry.Timestamp = dateTime;
            serverHistoryEntry.Data      = serverHistoryData.ToBinary();
            this.serverHistorySession.Save(serverHistoryEntry);
        }
 internal void UpdateLastServerHistoryEntry(DateTime passiveTimestamp, string passiveReason)
 {
     if (this.serverHistoryRootContainerID != null)
     {
         ServerHistoryEntryData serverHistoryEntryData = this.ReadLastSyncServerHistory();
         if (serverHistoryEntryData != null && string.Equals(serverHistoryEntryData.ServerName, Environment.MachineName))
         {
             serverHistoryEntryData.PassiveTimestamp = passiveTimestamp;
             serverHistoryEntryData.PassiveReason    = passiveReason;
             this.WriteSyncServerHistory(serverHistoryEntryData, false);
         }
     }
 }
        internal void UpdateOrCreateServerHistoryEntry(DateTime activeTimestamp)
        {
            ServerHistoryEntryData serverHistoryEntryData = this.ReadLastSyncServerHistory();
            string machineName = Environment.MachineName;

            if (serverHistoryEntryData != null && !string.Equals(serverHistoryEntryData.ServerName, machineName, StringComparison.InvariantCultureIgnoreCase) && serverHistoryEntryData.ActiveTimestamp.Equals(serverHistoryEntryData.PassiveTimestamp))
            {
                serverHistoryEntryData.PassiveReason = "Server became passive for unknown reason. Passive timestamp is not accurate.";
                this.WriteSyncServerHistory(serverHistoryEntryData, false);
            }
            if (serverHistoryEntryData == null || !string.Equals(serverHistoryEntryData.ServerName, machineName, StringComparison.InvariantCultureIgnoreCase) || !serverHistoryEntryData.ActiveTimestamp.Equals(serverHistoryEntryData.PassiveTimestamp))
            {
                this.WriteSyncServerHistory(new ServerHistoryEntryData(machineName, activeTimestamp, activeTimestamp, string.Empty), true);
            }
        }