예제 #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);
            }
        }
예제 #2
0
        protected void InnerRegister(int eventClasses)
        {
            Task.Run(() => { L4Logger.Info(string.Format("Register service {0} EventClass {1} MessageHandle {2} , class {3}", hService, eventClasses, MessageHandle, this.GetType().Name)); });
            int hResult = XfsApi.WFSAsyncRegister(hService, eventClasses, MessageHandle
                                                  , MessageHandle, ref requestID);

            if (hResult != XFSDefinition.WFS_SUCCESS)
            {
                OnRegisterError(hResult);
            }
        }
예제 #3
0
        public int ExecuteCommand(int commandCode, IntPtr ptrParam, Action <ServiceTypes, string, int, string> errorHandler = null)
        {
            Task.Run(() => { L4Logger.Info(string.Format("ExecuteCommand service {0}  {1} MessageHandle {2} , class {3}", hService, "", MessageHandle, this.GetType().Name)); });

            int hResult = XfsApi.WFSAsyncExecute(hService, commandCode, ptrParam, TimeOut, MessageHandle, ref requestID);

            Task.Run(() => { L4Logger.Info(string.Format("WFSAsyncExecute  serviceName {0}  Result {1} ", serviceName, hResult)); });
            if (hResult != XFSDefinition.WFS_SUCCESS && errorHandler != null)
            {
                errorHandler(serviceType, serviceName, hResult, string.Empty);
            }
            return(hResult);
        }
예제 #4
0
        public void Cancel(bool NeedNotify = true)
        {
            int hResult = XfsApi.WFSCancelAsyncRequest(hService, requestID);

            if (hResult != XFSDefinition.WFS_SUCCESS && CancelError != null && NeedNotify)
            {
                CancelError.Invoke(serviceType, hResult);
            }
            else
            {
                if (CancelComplete != null && NeedNotify)
                {
                    CancelComplete.Invoke(serviceType);
                }
            }
        }
예제 #5
0
        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);
        }
예제 #6
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);
            }
        }