コード例 #1
0
        static bool GetResourceFromEnumeration(SafeHCluster hCluster,
                                               SafeHClusEnum hEnum,
                                               uint index, out SafeHResource hResource, out string theResourceName)
        {
            uint type, cch = 0;

            hResource       = null;
            theResourceName = string.Empty;

            uint ret = SafeNativeMethods.ClusterEnum(hEnum, index, out type, null, ref cch);

            if (ret == SafeNativeMethods.ERROR_NO_MORE_ITEMS)
            {
                return(false);
            }
            else if (ret == SafeNativeMethods.ERROR_SUCCESS || ret == SafeNativeMethods.ERROR_MORE_DATA)
            {
                StringBuilder sb = new StringBuilder((int)(++cch));
                ret = SafeNativeMethods.ClusterEnum(hEnum, index, out type, sb, ref cch);

                if (ret == SafeNativeMethods.ERROR_SUCCESS)
                {
                    string resourceName = sb.ToString();

#pragma warning suppress 56523
                    hResource = SafeNativeMethods.OpenClusterResource(hCluster, resourceName);
                    if (hResource.IsInvalid)
                    {
                        hResource = null;
                    }
                    else
                    {
                        theResourceName = resourceName;
                    }
                }
            }

            return(true);
        }
コード例 #2
0
        static string[] GetClusterNodes(SafeHCluster hCluster)
        {
#pragma warning suppress 56523
            SafeHClusEnum hEnum = SafeNativeMethods.ClusterOpenEnum(hCluster, ClusterEnum.Node);
            if (hEnum.IsInvalid)
            {
                return null;
            }

            List<string> nodeList = new List<string>(2); // 2 nodes are a typical cluster configuration            

            using (hEnum)
            {
                uint ret, index = 0;
                do
                {
                    uint type, cch = 0;
                    ret = SafeNativeMethods.ClusterEnum(hEnum, index, out type, null, ref cch);
                    if (ret == SafeNativeMethods.ERROR_NO_MORE_ITEMS)
                    {
                        break;
                    }
                    else if (ret == SafeNativeMethods.ERROR_SUCCESS || ret == SafeNativeMethods.ERROR_MORE_DATA)
                    {
                        StringBuilder sb = new StringBuilder((int)(++cch));
                        ret = SafeNativeMethods.ClusterEnum(hEnum, index, out type, sb, ref cch);
                        if (ret == SafeNativeMethods.ERROR_SUCCESS)
                        {
                            Utilities.Log("Found a node: [" + sb.ToString() + "]");
                            nodeList.Add(sb.ToString());
                        }
                    }
                    index++;
                } while (ret == SafeNativeMethods.ERROR_SUCCESS);
            }

            return nodeList.ToArray();
        }