Exemplo n.º 1
0
        public void Open(string logicName, bool paramAutoRegister = true,
                         string appID       = "CitydiXFS", string lowVersion = "3.0",
                         string highVersion = "3.0")
        {
            try
            {
                Task.Run(() => { L4Logger.Info("xfs to open service => " + logicName); });
                serviceName  = logicName;
                autoRegister = paramAutoRegister;
                int requestVersion = XFSUtil.ParseVersionString(lowVersion,
                                                                highVersion);
                WFSVERSION srvcVersion = new WFSVERSION();
                WFSVERSION spVersion   = new WFSVERSION();
                int        hResult     = 0;
                if (!isStartup)
                {
                    hResult = XfsApi.WFSStartUp(requestVersion, ref spVersion);
                    Task.Run(() => { L4Logger.Info("xfs start result =>" + hResult); });
                    if (hResult != XFSDefinition.WFS_SUCCESS &&
                        hResult != XFSDefinition.WFS_ERR_ALREADY_STARTED)
                    {
                        OnOpenError(hResult);
                        return;
                    }
                }
                appID = "Citydi";
                Task.Run(() =>
                {
                    L4Logger.Info(string.Format(
                                      "logicName {0} appID {1} hService {2} MessageHandle {3} requestVersion {4} srvcVersion {5} spVersion {6} requestID {7}",
                                      logicName, appID, hService, MessageHandle, requestVersion, srvcVersion, spVersion, requestID));
                });

                //hResult= XfsApi.WFSOpen(logicName, IntPtr.Zero, appID, XFSDefinition.WFS_TRACE_API, XFSConstants.WFS_INDEFINITE_WAIT, requestVersion, ref srvcVersion, ref spVersion, ref hService);
                //L4Logger.Info(string.Format(" service {0} WFSOpen resule {1}", logicName, hResult));
                hResult = XfsApi.WFSAsyncOpen(logicName, IntPtr.Zero, appID, XFSDefinition.WFS_TRACE_ALL_API,
                                              XFSConstants.WFS_INDEFINITE_WAIT, ref hService,
                                              MessageHandle, requestVersion, ref srvcVersion, ref spVersion,
                                              ref requestID);
                Task.Run(() => { L4Logger.Info(string.Format(" service {0} WFSAsyncOpen resule {1}", logicName, hResult)); });
                if (hResult != XFSDefinition.WFS_SUCCESS)
                {
                    OnOpenError(hResult);
                }
            }
            catch (Win32Exception ex)
            {
                L4Logger.Info(ex);
            }
            catch (Exception ex)
            {
                L4Logger.Error(ex);
                OnOpenError(-10000);
            }
        }
Exemplo n.º 2
0
        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);
            }
        }