protected virtual bool InnerGetInfo <T>(int category, IntPtr inParam, Type type, out T value) { IntPtr pOutParam = IntPtr.Zero; value = (T)Activator.CreateInstance(type); int hResult = XfsApi.WFSGetInfo(hService, category, inParam, TimeOut, ref pOutParam); if (hResult == XFSDefinition.WFS_SUCCESS) { WFSRESULT wfsResult = (WFSRESULT)Marshal.PtrToStructure(pOutParam, typeof(WFSRESULT)); if (wfsResult.hResult == XFSDefinition.WFS_SUCCESS) { value = (T)((ISTATUS)value).UnMarshal(wfsResult.lpBuffer); XfsApi.WFSFreeResult(pOutParam); return(true); } } XfsApi.WFSFreeResult(pOutParam); return(false); }
protected override void WndProc(ref Message m) { if (m.Msg >= XFSDefinition.WFS_OPEN_COMPLETE && m.Msg <= XFSDefinition.WFS_SYSTEM_EVENT) { var msg = m.Msg; Task.Run(() => { L4Logger.Info(string.Format("Xfs WndProc ServiceName {0} msg {1} ", ServiceName, msg)); }); WFSRESULT result = new WFSRESULT(); if (m.LParam != IntPtr.Zero) { XFSUtil.PtrToStructure(m.LParam, ref result); } switch (m.Msg) { case XFSDefinition.WFS_OPEN_COMPLETE: { Task.Run(() => { L4Logger.Info("OpenCompleted => " + serviceType.ToString()); }); OnOpenComplete(); } break; case XFSDefinition.WFS_CLOSE_COMPLETE: OnCloseComplete(); break; case XFSDefinition.WFS_REGISTER_COMPLETE: { Task.Run(() => { L4Logger.Info("RegisterCompleted => " + serviceType.ToString()); }); OnRegisterComplete(); } break; case XFSDefinition.WFS_EXECUTE_COMPLETE: Task.Run(() => { L4Logger.Info(string.Format("ExecuteCompleted Service => {0} CommandCode => {1} ", serviceType.ToString(), result.dwCommandCodeOrEventID)); }); if (commandHandlers.Contains(result.dwCommandCodeOrEventID)) { OnExecuteComplete(ref result, result.dwCommandCodeOrEventID); } break; case XFSDefinition.WFS_EXECUTE_EVENT: case XFSDefinition.WFS_SERVICE_EVENT: case XFSDefinition.WFS_USER_EVENT: case XFSDefinition.WFS_SYSTEM_EVENT: Task.Run(() => { L4Logger.Info(string.Format("WFS_SYSTEM_EVENT servicename {0} lpBuffer {1} EventId => ", serviceName, result.lpBuffer, result.dwCommandCodeOrEventID)); }); if (eventHandlers.Contains(result.dwCommandCodeOrEventID)) { OnExecuteEvent(ref result); } else { Task.Run(() => { L4Logger.Info(string.Format("EventId = {0} AcceptsEvents = {1}", result.dwCommandCodeOrEventID, string.Join(",", eventHandlers.ToArray()))); }); } break; } XfsApi.WFSFreeResult(ref result); } else { base.WndProc(ref m); } }