public T RunActionWithKey <T>(string keyName, Func <IDistributedStoreKey, T> action, DxStoreKeyAccessMode mode = DxStoreKeyAccessMode.Read) { IDistributedStoreKey distributedStoreKey = string.IsNullOrEmpty(keyName) ? this.rootKey : this.rootKey.OpenKey(keyName, mode, false, null); T result; try { T t = action(distributedStoreKey); result = t; } finally { if (distributedStoreKey != null && !object.ReferenceEquals(distributedStoreKey, this.rootKey)) { distributedStoreKey.Dispose(); } } return(result); }
private void MonitorEvents() { AmClusterNotifyHandle amClusterNotifyHandle = null; IDistributedStoreKey distributedStoreKey = null; IDistributedStoreChangeNotify distributedStoreChangeNotify = null; try { ClusterNotifyFlags networkClusterNotificationMask = RegistryParameters.NetworkClusterNotificationMask; NetworkManager.TraceDebug("SettingClusterMask as 0x{0:x}", new object[] { networkClusterNotificationMask }); amClusterNotifyHandle = ClusapiMethods.CreateClusterNotifyPort(AmClusterNotifyHandle.InvalidHandle, this.ClusterHandle, networkClusterNotificationMask, IntPtr.Zero); if (amClusterNotifyHandle == null || amClusterNotifyHandle.IsInvalid) { int lastWin32Error = Marshal.GetLastWin32Error(); NetworkManager.TraceError("CreateClusterNotifyPort failed. Error code 0x{0:X8}", new object[] { lastWin32Error }); throw new ClusCommonTransientException("CreateClusterNotifyPort", new Win32Exception(lastWin32Error)); } using (IDistributedStoreKey clusterKey = DistributedStore.Instance.GetClusterKey(this.ClusterHandle, null, null, DxStoreKeyAccessMode.Write, false)) { distributedStoreKey = clusterKey.OpenKey("Exchange\\DagNetwork", DxStoreKeyAccessMode.CreateIfNotExist, false, null); } this.RegisterForChangeNotification(distributedStoreKey, amClusterNotifyHandle); TimeSpan t = new TimeSpan(0, 0, RegistryParameters.NetworkStatusPollingPeriodInSecs); while (this.m_clusterHandlesAreValid && !this.m_shutdown) { StringBuilder stringBuilder = new StringBuilder(256); uint num = Convert.ToUInt32(stringBuilder.Capacity); IntPtr zero = IntPtr.Zero; ClusterNotifyFlags clusterNotifyFlags; int clusterNotify = ClusapiMethods.GetClusterNotify(amClusterNotifyHandle, out zero, out clusterNotifyFlags, stringBuilder, ref num, 3000U); if (this.m_shutdown) { break; } if (this.m_netMap == null) { if (!this.TryDriveMapRefresh()) { break; } } else if (clusterNotify == 258) { if (t < ExDateTime.TimeDiff(ExDateTime.Now, this.m_mapLoadTime) && !this.TryDriveMapRefresh()) { break; } } else if (clusterNotify != 0) { NetworkManager.TraceDebug("GetClusterNotify() returned unexpected status code 0x{0:X)", new object[] { clusterNotify }); } else { string text = stringBuilder.ToString(); NetworkManager.TraceDebug("GetClusterNotify() returned notifyKey={0}, filterType=0x{1:x}, resName={2}", new object[] { zero, clusterNotifyFlags, text }); if ((clusterNotifyFlags & ~(ClusterNotifyFlags.CLUSTER_CHANGE_NODE_PROPERTY | ClusterNotifyFlags.CLUSTER_CHANGE_REGISTRY_NAME | ClusterNotifyFlags.CLUSTER_CHANGE_REGISTRY_ATTRIBUTES | ClusterNotifyFlags.CLUSTER_CHANGE_REGISTRY_VALUE | ClusterNotifyFlags.CLUSTER_CHANGE_REGISTRY_SUBTREE | ClusterNotifyFlags.CLUSTER_CHANGE_RESOURCE_STATE | ClusterNotifyFlags.CLUSTER_CHANGE_RESOURCE_DELETED | ClusterNotifyFlags.CLUSTER_CHANGE_RESOURCE_ADDED | ClusterNotifyFlags.CLUSTER_CHANGE_RESOURCE_PROPERTY | ClusterNotifyFlags.CLUSTER_CHANGE_GROUP_STATE | ClusterNotifyFlags.CLUSTER_CHANGE_GROUP_DELETED | ClusterNotifyFlags.CLUSTER_CHANGE_GROUP_ADDED | ClusterNotifyFlags.CLUSTER_CHANGE_GROUP_PROPERTY | ClusterNotifyFlags.CLUSTER_CHANGE_RESOURCE_TYPE_DELETED | ClusterNotifyFlags.CLUSTER_CHANGE_RESOURCE_TYPE_ADDED | ClusterNotifyFlags.CLUSTER_CHANGE_RESOURCE_TYPE_PROPERTY | ClusterNotifyFlags.CLUSTER_CHANGE_CLUSTER_RECONNECT | ClusterNotifyFlags.CLUSTER_CHANGE_QUORUM_STATE | ClusterNotifyFlags.CLUSTER_CHANGE_CLUSTER_PROPERTY)) != ~(ClusterNotifyFlags.CLUSTER_CHANGE_NODE_STATE | ClusterNotifyFlags.CLUSTER_CHANGE_NODE_DELETED | ClusterNotifyFlags.CLUSTER_CHANGE_NODE_ADDED | ClusterNotifyFlags.CLUSTER_CHANGE_NODE_PROPERTY | ClusterNotifyFlags.CLUSTER_CHANGE_REGISTRY_NAME | ClusterNotifyFlags.CLUSTER_CHANGE_REGISTRY_ATTRIBUTES | ClusterNotifyFlags.CLUSTER_CHANGE_REGISTRY_VALUE | ClusterNotifyFlags.CLUSTER_CHANGE_REGISTRY_SUBTREE | ClusterNotifyFlags.CLUSTER_CHANGE_RESOURCE_STATE | ClusterNotifyFlags.CLUSTER_CHANGE_RESOURCE_DELETED | ClusterNotifyFlags.CLUSTER_CHANGE_RESOURCE_ADDED | ClusterNotifyFlags.CLUSTER_CHANGE_RESOURCE_PROPERTY | ClusterNotifyFlags.CLUSTER_CHANGE_GROUP_STATE | ClusterNotifyFlags.CLUSTER_CHANGE_GROUP_DELETED | ClusterNotifyFlags.CLUSTER_CHANGE_GROUP_ADDED | ClusterNotifyFlags.CLUSTER_CHANGE_GROUP_PROPERTY | ClusterNotifyFlags.CLUSTER_CHANGE_RESOURCE_TYPE_DELETED | ClusterNotifyFlags.CLUSTER_CHANGE_RESOURCE_TYPE_ADDED | ClusterNotifyFlags.CLUSTER_CHANGE_RESOURCE_TYPE_PROPERTY | ClusterNotifyFlags.CLUSTER_CHANGE_CLUSTER_RECONNECT | ClusterNotifyFlags.CLUSTER_CHANGE_NETWORK_STATE | ClusterNotifyFlags.CLUSTER_CHANGE_NETWORK_DELETED | ClusterNotifyFlags.CLUSTER_CHANGE_NETWORK_ADDED | ClusterNotifyFlags.CLUSTER_CHANGE_NETWORK_PROPERTY | ClusterNotifyFlags.CLUSTER_CHANGE_NETINTERFACE_STATE | ClusterNotifyFlags.CLUSTER_CHANGE_NETINTERFACE_DELETED | ClusterNotifyFlags.CLUSTER_CHANGE_NETINTERFACE_ADDED | ClusterNotifyFlags.CLUSTER_CHANGE_NETINTERFACE_PROPERTY | ClusterNotifyFlags.CLUSTER_CHANGE_QUORUM_STATE | ClusterNotifyFlags.CLUSTER_CHANGE_CLUSTER_STATE | ClusterNotifyFlags.CLUSTER_CHANGE_CLUSTER_PROPERTY | ClusterNotifyFlags.CLUSTER_CHANGE_HANDLE_CLOSE) && !this.TryDriveMapRefresh()) { break; } } } } finally { if (amClusterNotifyHandle != null) { amClusterNotifyHandle.Dispose(); amClusterNotifyHandle = null; } if (distributedStoreChangeNotify != null) { distributedStoreChangeNotify.Dispose(); } if (distributedStoreKey != null) { distributedStoreKey.Dispose(); } } }
// Token: 0x06000543 RID: 1347 RVA: 0x00013D3C File Offset: 0x00011F3C private XElement GetXElementSnapshotInternal(string keyName) { bool flag = false; bool flag2 = true; string keyName2; string value; if (!string.IsNullOrEmpty(keyName)) { keyName2 = Utils.CombinePathNullSafe(this.rootKeyName, keyName); value = keyName.Substring(keyName.LastIndexOf('\\') + 1); } else { keyName2 = this.rootKeyName; value = "\\"; flag = true; if (this.filterRootKeys.Length > 1) { flag2 = false; } } XElement xelement = new XElement("Key", new XAttribute("Name", value)); XElement xelement2 = xelement; if (this.IsProduceDxStoreFormat && flag) { xelement.Add(new XElement("Key", new XAttribute("Name", "Private"))); XElement xelement3 = new XElement("Key", new XAttribute("Name", "Public")); xelement.Add(xelement3); xelement2 = xelement3; } IDistributedStoreKey distributedStoreKey = flag ? this.baseKey : this.baseKey.OpenKey(keyName2, DxStoreKeyAccessMode.Read, false, null); try { if (flag2 || this.isForceIncludeRootProperties) { foreach (string propertyName in distributedStoreKey.GetValueNames(null)) { bool flag3; RegistryValueKind kind; object value2 = distributedStoreKey.GetValue(propertyName, out flag3, out kind, null); if (value2 != null && flag3) { PropertyValue propertyValue = new PropertyValue(value2, kind); xelement2.Add(propertyValue.ToXElement(propertyName)); } } } IEnumerable <string> subkeyNames = distributedStoreKey.GetSubkeyNames(null); if (subkeyNames != null) { foreach (string path in subkeyNames) { string keyName3 = Utils.CombinePathNullSafe(keyName ?? string.Empty, path); if (!flag || this.IsIncludeKey(keyName3)) { XElement xelementSnapshotInternal = this.GetXElementSnapshotInternal(keyName3); xelement2.Add(xelementSnapshotInternal); } } } } finally { if (distributedStoreKey != null && !flag) { distributedStoreKey.Dispose(); } } return(xelement); }