Exemplo n.º 1
0
        // Token: 0x06000076 RID: 118 RVA: 0x000031F8 File Offset: 0x000013F8
        private DateTime GetBootTimeWithWmi(ManagementClass mgmtClass, AmServerName machineName)
        {
            DateTime  dateTime = ExDateTime.Now.UniversalTime;
            Exception ex       = null;

            try
            {
                using (ManagementObjectCollection instances = mgmtClass.GetInstances())
                {
                    if (instances != null)
                    {
                        using (ManagementObjectCollection.ManagementObjectEnumerator enumerator = instances.GetEnumerator())
                        {
                            while (enumerator.MoveNext())
                            {
                                ManagementBaseObject managementBaseObject = enumerator.Current;
                                ManagementObject     managementObject     = (ManagementObject)managementBaseObject;
                                using (managementObject)
                                {
                                    string dmtfDate = (string)managementObject["LastBootupTime"];
                                    dateTime = ManagementDateTimeConverter.ToDateTime(dmtfDate).ToUniversalTime();
                                    AmTrace.Debug("GetBootTimeWithWmi: WMI says that the boot time for {0} is {1}.", new object[]
                                    {
                                        machineName,
                                        dateTime
                                    });
                                }
                            }
                            goto IL_102;
                        }
                    }
                    AmTrace.Error("GetBootTimeWithWmi: WMI could not query the boot time on server {0}: No instances found for management path {1}.", new object[]
                    {
                        machineName,
                        mgmtClass.ClassPath.Path
                    });
                    ReplayEventLogConstants.Tuple_GetBootTimeWithWmiFailure.LogEvent(string.Empty, new object[]
                    {
                        machineName,
                        Strings.NoInstancesFoundForManagementPath(mgmtClass.ClassPath.Path)
                    });
                    IL_102 :;
                }
            }
            catch (COMException ex2)
            {
                ex = ex2;
            }
            catch (UnauthorizedAccessException ex3)
            {
                ex = ex3;
            }
            catch (ManagementException ex4)
            {
                ex = ex4;
            }
            catch (OutOfMemoryException ex5)
            {
                ex = ex5;
            }
            if (ex != null)
            {
                AmTrace.Error("GetBootTimeWithWmi: WMI could not query the boot time on server {0}: {1}", new object[]
                {
                    machineName,
                    ex
                });
                ReplayEventLogConstants.Tuple_GetBootTimeWithWmiFailure.LogEvent(string.Empty, new object[]
                {
                    machineName,
                    ex.Message
                });
            }
            return(dateTime);
        }
Exemplo n.º 2
0
        private static void SaveDatabasePropertiesOnMultipleServerSites(ITopologyConfigurationSession rwSession, Database database, MiniServer sourceServer, MiniServer targetServer, bool isBestEffort)
        {
            Server     server          = rwSession.FindServerByName(Environment.MachineName);
            ADObjectId localServerSite = server.ServerSite;
            Exception  ex = SharedHelper.RunADOperationEx(delegate(object param0, EventArgs param1)
            {
                rwSession.Save(database);
            });

            if (ex != null)
            {
                AmTrace.Error("Failed to update properties on the default local site (error={0})", new object[]
                {
                    ex
                });
                ReplayCrimsonEvents.DatabasePropertyLocalSiteUpdateFailed.Log <string, Guid, string, string, string>(database.Name, database.Guid, targetServer.Name, localServerSite.DistinguishedName, ex.Message);
                if (!isBestEffort)
                {
                    throw ex;
                }
            }
            ADObjectId adobjectId  = (sourceServer != null) ? sourceServer.ServerSite : null;
            ADObjectId adobjectId2 = (targetServer != null) ? targetServer.ServerSite : null;

            ADObjectId[] source = new ADObjectId[]
            {
                adobjectId,
                adobjectId2
            };
            ADObjectId[] sites = (from s in source
                                  where s != null && !s.Equals(localServerSite)
                                  select s).Distinct <ADObjectId>().ToArray <ADObjectId>();
            if (sites.Length > 0)
            {
                string[] array = (from s in sites
                                  select s.DistinguishedName).ToArray <string>();
                string[] dcsContacted = null;
                ex = SharedHelper.RunADOperationEx(delegate(object param0, EventArgs param1)
                {
                    dcsContacted = rwSession.ReplicateSingleObject(database, sites);
                });
                if (ex != null)
                {
                    AmTrace.Error("Failed to initiate replication for remote sites (error={0})", new object[]
                    {
                        ex
                    });
                }
                for (int i = 0; i < sites.Length; i++)
                {
                    if (dcsContacted == null || string.IsNullOrEmpty(dcsContacted[i]))
                    {
                        AmTrace.Error("Replication request for site '{0}' was not submitted to any DC", new object[]
                        {
                            array[i]
                        });
                    }
                    else
                    {
                        AmTrace.Debug("Replication request for site '{0}' was submitted to DC '{1}'", new object[]
                        {
                            array[i],
                            dcsContacted[i]
                        });
                    }
                }
                if (ex != null)
                {
                    ReplayCrimsonEvents.DatabasePropertyRemoteSiteReplicationFailed.Log <string, Guid, string, string, string, string>(database.Name, database.Guid, targetServer.Name, string.Join(",", array), (dcsContacted != null) ? string.Join(",", dcsContacted) : string.Empty, ex.Message);
                    if (!isBestEffort)
                    {
                        throw ex;
                    }
                }
                else
                {
                    ReplayCrimsonEvents.DatabasePropertyRemoteSiteReplicationSucceeded.Log <string, Guid, string, string, string>(database.Name, database.Guid, targetServer.Name, string.Join(",", array), (dcsContacted != null) ? string.Join(",", dcsContacted) : string.Empty);
                }
            }
        }