private static DhcpServerClient GetClientVQ(DhcpServer Server, IntPtr SearchInfo) { try { IntPtr clientPtr; DhcpErrors result = Api.DhcpGetClientInfoVQ(Server.ipAddress.ToString(), SearchInfo, out clientPtr); if (result == DhcpErrors.JET_ERROR) { return(null); } if (result != DhcpErrors.SUCCESS) { throw new DhcpServerException("DhcpGetClientInfoVQ", result); } try { var client = (DHCP_CLIENT_INFO_VQ)Marshal.PtrToStructure(clientPtr, typeof(DHCP_CLIENT_INFO_VQ)); return(DhcpServerClient.FromNative(Server, client)); } finally { Api.DhcpRpcFreeMemory(clientPtr); } } finally { Marshal.FreeHGlobal(SearchInfo); } }
internal DhcpServerException(string apiFunction, DhcpErrors error, string additionalMessage) { ApiFunction = apiFunction; this.error = error; ApiErrorMessage = BuildApiErrorMessage(error); message = BuildMessage(apiFunction, additionalMessage, error, ApiErrorMessage); }
internal DhcpServerException(string ApiFunction, DhcpErrors Error) { this.ApiFunction = ApiFunction; this.error = Error; this.errorMessage = new Lazy <string>(this.GetApiErrorMessage); }
internal static DhcpServerAuditLog GetParams(DhcpServer Server) { string auditLogDir; int diskCheckInterval, maxLogFilesSize, minSpaceOnDisk; DhcpErrors result = Api.DhcpAuditLogGetParams(Server.ipAddress.ToString(), 0, out auditLogDir, out diskCheckInterval, out maxLogFilesSize, out minSpaceOnDisk); if (result != DhcpErrors.SUCCESS) { throw new DhcpServerException("DhcpAuditLogGetParams", result); } return(new DhcpServerAuditLog(auditLogDir, diskCheckInterval, maxLogFilesSize, minSpaceOnDisk)); }
private string BuildApiErrorMessage(DhcpErrors error) { var errorType = typeof(DhcpErrors).GetMember(error.ToString()); if (errorType.Length != 0) { var errorAttribute = errorType[0].GetCustomAttributes(typeof(DhcpErrorDescriptionAttribute), false); if (errorAttribute.Length != 0) { return(((DhcpErrorDescriptionAttribute)errorAttribute[0]).Description); } } return("Unknown Error"); }
private static IEnumerable <DhcpServerClient> GetClientsVQ(DhcpServer Server, DHCP_IP_ADDRESS SubnetAddress) { IntPtr clientsPtr; IntPtr resultHandle = IntPtr.Zero; int clientsRead, clientsTotal; DhcpErrors result = Api.DhcpEnumSubnetClientsVQ(Server.ipAddress.ToString(), SubnetAddress, ref resultHandle, 65536, out clientsPtr, out clientsRead, out clientsTotal); if (result != DhcpErrors.SUCCESS && result != DhcpErrors.ERROR_MORE_DATA) { throw new DhcpServerException("DhcpEnumSubnetClientsVQ", result); } while (result == DhcpErrors.SUCCESS || result == DhcpErrors.ERROR_MORE_DATA) { try { using (var clients = DHCP_CLIENT_INFO_ARRAY_VQ.Read(clientsPtr)) { foreach (var client in clients.Clients) { yield return(DhcpServerClient.FromNative(Server, client.Item2)); } } } finally { Api.DhcpRpcFreeMemory(clientsPtr); clientsPtr = IntPtr.Zero; } if (result == DhcpErrors.SUCCESS) { yield break; // Last results } clientsRead = 0; clientsTotal = 0; result = Api.DhcpEnumSubnetClientsVQ(Server.ipAddress.ToString(), SubnetAddress, ref resultHandle, 65536, out clientsPtr, out clientsRead, out clientsTotal); if (result != DhcpErrors.SUCCESS && result != DhcpErrors.ERROR_MORE_DATA) { throw new DhcpServerException("DhcpEnumSubnetClientsVQ", result); } } }
private string BuildMessage(string apiFunction, string additionalMessage, DhcpErrors error, string apiErrorMessage) { var builder = new StringBuilder(); if (apiFunction != null) { builder.Append("An error occurred calling '").Append(apiFunction).Append("'. "); } if (additionalMessage != null) { builder.Append(additionalMessage).Append(". "); } builder.Append(apiErrorMessage).Append(" [").Append(error.ToString()).Append(' ').Append((uint)error).Append(']'); return(builder.ToString()); }
private static IEnumerable <DhcpServerClient> GetClientsV5(DhcpServer Server, DHCP_IP_ADDRESS SubnetAddress) { IntPtr clientsPtr; IntPtr resultHandle = IntPtr.Zero; int clientsRead, clientsTotal; DhcpErrors result = Api.DhcpEnumSubnetClientsV5(Server.ipAddress.ToString(), SubnetAddress, ref resultHandle, 65536, out clientsPtr, out clientsRead, out clientsTotal); if (result != DhcpErrors.SUCCESS && result != DhcpErrors.ERROR_MORE_DATA && result != DhcpErrors.ERROR_NO_MORE_ITEMS) { throw new DhcpServerException("DhcpEnumSubnetClientsV5", result); } while (result == DhcpErrors.SUCCESS || result == DhcpErrors.ERROR_MORE_DATA) { try { var clients = (DHCP_CLIENT_INFO_ARRAY_V5)Marshal.PtrToStructure(clientsPtr, typeof(DHCP_CLIENT_INFO_ARRAY_V5)); foreach (var client in clients.Clients) { yield return(DhcpServerClient.FromNative(Server, client)); } } finally { Api.DhcpRpcFreeMemory(clientsPtr); } if (result == DhcpErrors.SUCCESS) { yield break; // Last results } result = Api.DhcpEnumSubnetClientsV5(Server.ipAddress.ToString(), SubnetAddress, ref resultHandle, 65536, out clientsPtr, out clientsRead, out clientsTotal); if (result != DhcpErrors.SUCCESS && result != DhcpErrors.ERROR_MORE_DATA && result != DhcpErrors.ERROR_NO_MORE_ITEMS) { throw new DhcpServerException("DhcpEnumSubnetClientsV5", result); } } }
internal DhcpServerException(string apiFunction, DhcpErrors error) : this(apiFunction, error, null) { }
internal DhcpServerException(string ApiFunction, DhcpErrors Error, string AdditionalMessage) : this(ApiFunction, Error) { this.additionalMessage = AdditionalMessage; }