private static void DirectoryChangeEvent(object source, FileSystemEventArgs eventInfo)
        {
            MonitoredDatabase.FileWatcher fileWatcher = source as MonitoredDatabase.FileWatcher;
            MonitoredDatabase             database    = fileWatcher.Database;
            long num = 0L;

            if (database.GetGenerationNumberFromFilename(eventInfo.Name, out num))
            {
                MonitoredDatabase.Tracer.TraceDebug <long, string>((long)database.GetHashCode(), "DirectoryChangeEvent: Log 0x{0:X} exists for db '{1}'", num, database.DatabaseName);
                DateTime? writeTimeUtc = null;
                Exception ex           = null;
                try
                {
                    FileInfo fileInfo = new FileInfo(eventInfo.FullPath);
                    if (!fileInfo.Exists)
                    {
                        throw new FileNotFoundException("FileNotFound");
                    }
                    writeTimeUtc = new DateTime?(fileInfo.LastWriteTimeUtc);
                }
                catch (IOException ex2)
                {
                    ex = ex2;
                }
                catch (UnauthorizedAccessException ex3)
                {
                    ex = ex3;
                }
                if (ex != null)
                {
                    MonitoredDatabase.Tracer.TraceError <string, string>((long)database.GetHashCode(), "DirectoryChangeEvent for {0} failed with exception {1}", eventInfo.FullPath, ex.Message);
                    ReplayCrimsonEvents.MonitoredDBFileNotifyFailure.Log <string, string, string, string>(database.DatabaseName, Environment.MachineName, eventInfo.FullPath, ex.ToString());
                }
                database.DetectNewEndOfLog(num, writeTimeUtc, false);
            }
        }
Exemple #2
0
 // Token: 0x0600239A RID: 9114 RVA: 0x000A71C8 File Offset: 0x000A53C8
 public static void StartMonitoredDatabase(ReplayConfiguration config)
 {
     lock (RemoteDataProvider.s_singletonLock)
     {
         MonitoredDatabase monitoredDatabase = null;
         if (RemoteDataProvider.s_databases.TryGetInstance(config.Identity, out monitoredDatabase))
         {
             throw new MonitoredDatabaseInitException(config.DatabaseName, "MonitoredDatabase should not have existed");
         }
         MonitoredDatabase monitoredDatabase2 = new MonitoredDatabase(config);
         MonitoredDatabaseInitException ex    = monitoredDatabase2.StartMonitoring();
         if (ex != null)
         {
             throw ex;
         }
         RemoteDataProvider.s_databases.AddInstance(monitoredDatabase2);
         RemoteDataProvider.Tracer.TraceDebug <string>((long)monitoredDatabase2.GetHashCode(), "StartMonitoredDatabase has activated {0}", monitoredDatabase2.DatabaseName);
     }
 }
Exemple #3
0
        // Token: 0x06002398 RID: 9112 RVA: 0x000A6E5C File Offset: 0x000A505C
        public static void MonitorDatabases(List <string> databasesToStopMonitoring, List <string> databasesToRestartMonitoring, Dictionary <string, ReplayConfiguration> configurationsFound)
        {
            List <MonitoredDatabase> list = new List <MonitoredDatabase>(databasesToStopMonitoring.Count);

            lock (RemoteDataProvider.s_singletonLock)
            {
                if (RemoteDataProvider.s_tprEnabled)
                {
                    return;
                }
                MonitoredDatabase[] allInstances = RemoteDataProvider.s_databases.GetAllInstances();
                foreach (MonitoredDatabase monitoredDatabase in allInstances)
                {
                    if (databasesToStopMonitoring.Contains(monitoredDatabase.Identity))
                    {
                        ExTraceGlobals.MonitoredDatabaseTracer.TraceDebug <string>(0L, "Config for MonitoredDatabase is gone: {0}", monitoredDatabase.Config.DatabaseName);
                        SourceSeedTable.Instance.CancelSeedingIfAppropriate(SourceSeedTable.CancelReason.CopyRemoved, monitoredDatabase.DatabaseGuid);
                        list.Add(monitoredDatabase);
                        RemoteDataProvider.s_databases.RemoveInstance(monitoredDatabase);
                    }
                }
                foreach (KeyValuePair <string, ReplayConfiguration> keyValuePair in configurationsFound)
                {
                    ReplayConfiguration value = keyValuePair.Value;
                    bool flag2 = value.Type == ReplayConfigType.RemoteCopySource;
                    bool flag3 = flag2 || (value.Type == ReplayConfigType.RemoteCopyTarget && !value.ReplayState.Suspended);
                    MonitoredDatabase monitoredDatabase2 = null;
                    if (RemoteDataProvider.s_databases.TryGetInstance(value.Identity, out monitoredDatabase2))
                    {
                        if (flag3 && !databasesToRestartMonitoring.Contains(monitoredDatabase2.Identity))
                        {
                            RemoteDataProvider.Tracer.TraceDebug <string>((long)monitoredDatabase2.GetHashCode(), "Config not changed, or the associated RI was not restarted. Continuing to monitor: {0}", value.DatabaseName);
                            continue;
                        }
                        RemoteDataProvider.Tracer.TraceDebug <string>((long)monitoredDatabase2.GetHashCode(), "Config for MonitoredDatabase is changing or a restart was requested: {0}", value.DatabaseName);
                        SourceSeedTable.Instance.CancelSeedingIfAppropriate(SourceSeedTable.CancelReason.ConfigChanged, monitoredDatabase2.DatabaseGuid);
                        list.Add(monitoredDatabase2);
                    }
                    if (!flag2)
                    {
                        RemoteDataProvider.Tracer.TraceDebug <string>(0L, "Not starting monitor for {0}", value.DatabaseName);
                        if (monitoredDatabase2 != null)
                        {
                            RemoteDataProvider.s_databases.RemoveInstance(monitoredDatabase2);
                        }
                    }
                    else
                    {
                        if (monitoredDatabase2 != null && !monitoredDatabase2.IsPassiveCopy)
                        {
                            monitoredDatabase2.StopMonitoring();
                        }
                        MonitoredDatabase monitoredDatabase3 = new MonitoredDatabase(value);
                        if (monitoredDatabase3.StartMonitoring() == null)
                        {
                            if (monitoredDatabase2 != null)
                            {
                                RemoteDataProvider.s_databases.UpdateInstance(monitoredDatabase2, monitoredDatabase3);
                            }
                            else
                            {
                                RemoteDataProvider.s_databases.AddInstance(monitoredDatabase3);
                            }
                            RemoteDataProvider.Tracer.TraceDebug <string>((long)monitoredDatabase3.GetHashCode(), "Now monitoring: {0}", value.DatabaseName);
                        }
                        else
                        {
                            RemoteDataProvider.Tracer.TraceError <ReplayConfiguration>((long)monitoredDatabase3.GetHashCode(), "Unable to monitor remote requests for configuration {0}", value);
                            if (monitoredDatabase2 != null)
                            {
                                RemoteDataProvider.s_databases.RemoveInstance(monitoredDatabase2);
                            }
                        }
                    }
                }
            }
            foreach (MonitoredDatabase monitoredDatabase4 in list)
            {
                monitoredDatabase4.StopMonitoring();
            }
            list.Clear();
        }