public ServerProperties GetProperties() { DisposedCheck(); IntPtr dataPtr; server.GetStatus(out dataPtr); try { var position = 0; var result = new ServerProperties(); // FILETIME ftStartTime; var time = Marshal.ReadInt64(dataPtr, position); result.StartTime = DateTime.FromFileTimeUtc(time); position += sizeof(long); // FILETIME ftCurrentTime; time = Marshal.ReadInt64(dataPtr, position); result.CurrentTime = DateTime.FromFileTimeUtc(time); position += sizeof(long); // FILETIME ftLastUpdateTime; time = Marshal.ReadInt64(dataPtr, position); result.LastUpdateTime = DateTime.FromFileTimeUtc(time); position += sizeof(long); // tagOPCSERVERSTATE dwServerState; result.ServerState = (ServerState)Marshal.ReadInt32(dataPtr, position); position += sizeof(int); // uint dwGroupCount; result.GroupCount = Marshal.ReadInt32(dataPtr, position); position += sizeof(int); // uint dwBandWidth; result.Bandwidth = Marshal.ReadInt32(dataPtr, position); position += sizeof(int); // ushort wMajorVersion; result.MajorVersion = Marshal.ReadInt16(dataPtr, position); position += sizeof(short); // ushort wMinorVersion; result.MinorVersion = Marshal.ReadInt16(dataPtr, position); position += sizeof(short); // ushort wBuildNumber; result.BuildNumber = Marshal.ReadInt16(dataPtr, position); position += sizeof(short); // ushort wReserved; position += sizeof(short); if (IntPtr.Size == 8) { position += sizeof(int); } // string szVendorInfo; var vendorInfo = Marshal.ReadIntPtr(dataPtr, position); if (vendorInfo != IntPtr.Zero) { result.VendorInfo = Marshal.PtrToStringUni(vendorInfo); Marshal.FreeCoTaskMem(vendorInfo); } return(result); } finally { if (dataPtr != IntPtr.Zero) { Marshal.FreeCoTaskMem(dataPtr); } } }
public ServerProperties GetProperties() { DisposedCheck(); IntPtr dataPtr; server.GetStatus(out dataPtr); try { var position = 0; var result = new ServerProperties(); // FILETIME ftStartTime; var time = Marshal.ReadInt64(dataPtr, position); result.StartTime = DateTime.FromFileTimeUtc(time); position += sizeof(long); // FILETIME ftCurrentTime; time = Marshal.ReadInt64(dataPtr, position); result.CurrentTime = DateTime.FromFileTimeUtc(time); position += sizeof(long); // FILETIME ftLastUpdateTime; time = Marshal.ReadInt64(dataPtr, position); result.LastUpdateTime = DateTime.FromFileTimeUtc(time); position += sizeof(long); // tagOPCSERVERSTATE dwServerState; result.ServerState = (ServerState)Marshal.ReadInt32(dataPtr, position); position += sizeof(int); // uint dwGroupCount; result.GroupCount = Marshal.ReadInt32(dataPtr, position); position += sizeof(int); // uint dwBandWidth; result.Bandwidth = Marshal.ReadInt32(dataPtr, position); position += sizeof(int); // ushort wMajorVersion; result.MajorVersion = Marshal.ReadInt16(dataPtr, position); position += sizeof(short); // ushort wMinorVersion; result.MinorVersion = Marshal.ReadInt16(dataPtr, position); position += sizeof(short); // ushort wBuildNumber; result.BuildNumber = Marshal.ReadInt16(dataPtr, position); position += sizeof(short); // ushort wReserved; position += sizeof(short); if (IntPtr.Size == 8) position += sizeof(int); // string szVendorInfo; var vendorInfo = Marshal.ReadIntPtr(dataPtr, position); if (vendorInfo != IntPtr.Zero) { result.VendorInfo = Marshal.PtrToStringUni(vendorInfo); Marshal.FreeCoTaskMem(vendorInfo); } return result; } finally { if(dataPtr != IntPtr.Zero) Marshal.FreeCoTaskMem(dataPtr); } }