private void RegisterForChangeNotification(IDistributedStoreKey dsKey, AmClusterNotifyHandle hChange) { AmClusterRegkeyHandle clusdbKeyHandle = this.GetClusdbKeyHandle(dsKey); if (clusdbKeyHandle != null && !clusdbKeyHandle.IsInvalid) { ClusterNotifyFlags dwFilter = ClusterNotifyFlags.CLUSTER_CHANGE_REGISTRY_VALUE; IntPtr dwNotifyKey = (IntPtr)1; int num = ClusapiMethods.RegisterClusterNotify(hChange, dwFilter, clusdbKeyHandle, dwNotifyKey); if (num != 0) { NetworkManager.TraceError("RegisterClusterNotify for reg notification 0x{0:X8}", new object[] { num }); throw AmExceptionHelper.ConstructClusterApiException(num, "RegisterClusterNotify(Network Registry)", new object[0]); } } }
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(); } } }