Ejemplo n.º 1
0
        public void GetStatus()
        {
            try
            {
                if (!_WebSocket.IsAlive)
                {
                    _WebSocket.Connect();
                }

                XfsCommandBase <GetInfoCommand> xfsCommand = new XfsCommandBase <GetInfoCommand>
                {
                    CommandType = CommandType.Getinfo,
                    ServiceType = ServiceTypes.BCR,
                    XfsCommand  = new GetInfoCommand
                    {
                        CommandCode = BCRDefinition.WFS_INF_BCR_STATUS,
                        StatusType  = typeof(WFSBCRSTATUS),
                        Status      = new WFSBCRSTATUS(),
                        Result      = IntPtr.Zero,
                    }
                };
                workingMode = WorkingMode.GettingStatus;
                _WebSocket.Send(Newtonsoft.Json.JsonConvert.SerializeObject(xfsCommand, Formatting.Indented));
            }
            catch (Exception ex)
            {
                L4Logger.Error(ex);
            }
        }
Ejemplo n.º 2
0
 public void ReadData()
 {
     L4Logger.Info(MethodBase.GetCurrentMethod().Name + "  Start");
     if (!blockingQueue.Enqueue(
             new TaskModel
     {
         MethodName = "ReadData",
         WaitForResponse = true
     }
             ))
     {
         L4Logger.Info("another operation in progress");
         return;
     }
     L4Logger.Info(MethodBase.GetCurrentMethod().Name + "  Start for sending xfs command");
     try
     {
         if (!_WebSocket.IsAlive)
         {
             _WebSocket.Connect();
         }
         WFSBCRREADINPUT source = new WFSBCRREADINPUT
         {
             lpwSymbologies = (ushort)BarcodeType.WFS_BCR_SYM_UNKNOWN
         };
         XfsCommandBase <XfsCommand> xfsCommand = new XfsCommandBase <XfsCommand>
         {
             CommandType = CommandType.Execute,
             ServiceType = ServiceTypes.BCR,
             XfsCommand  = new ExecuteCommand
             {
                 CommandCode         = BCRDefinition.WFS_CMD_BCR_READ,
                 Param               = source,
                 ResultModel         = new BarcodeData[1],
                 PramType            = typeof(WFSBCRREADINPUT),
                 ResultModelType     = typeof(BarcodeData),
                 ResultXfs           = new WFSBCRREADOUTPUT[1],
                 ResultXfsType       = typeof(WFSBCRREADOUTPUT),
                 CancelLastCommand   = false,
                 LightControlCommand = new LightControlCommand
                 {
                 },
                 AcceptEvents = new List <int>
                 {
                 }
             }
         };
         _WebSocket.Send(Newtonsoft.Json.JsonConvert.SerializeObject(xfsCommand, Formatting.Indented));
     }
     catch (Exception ex)
     {
         L4Logger.Error(ex);
     }
 }
Ejemplo n.º 3
0
        private Wrapper.Common.XFSDeviceBase AddOrGetServiceBase(XfsCommandBase <OpenCommand> Command)
        {
            if (!XFS_DevicesCollection.Instance.IsContainKey(Command.ServiceType))
            {
                ISTATUS TStatusType;
                ICAPS   TCapabilityType;
                Wrapper.Common.XFSDeviceBase XFSDevice = null;

                switch (Command.ServiceType)
                {
                case ServiceTypes.IDC:
                {
                    TStatusType     = new WFSIDCSTATUS();
                    TCapabilityType = new WFSIDCCAPS();
                    XFSDevice       = new Wrapper.Common.XFSDeviceBase
                    {
                        StatusClass     = TStatusType,
                        CapabilityClass = TCapabilityType
                    };

                    break;
                }

                case ServiceTypes.PIN:
                {
                    TStatusType     = new WFSIDCSTATUS();
                    TCapabilityType = new WFSIDCCAPS();
                    //XFSDevice = new XFSDeviceBase<pinst\\\, WFSIDCCAPS>();
                    break;
                }
                }



                XFS_DevicesCollection.Instance.Add(ServiceTypes.IDC, XFSDevice);

                return(XFSDevice);
            }
            else
            {
                var XFSDevice = XFS_DevicesCollection.Instance.GetValue(Command.ServiceType);

                return(XFSDevice);
            }
        }
Ejemplo n.º 4
0
        public void OpenAndRegister(string serviceName)
        {
            if (!_WebSocket.IsAlive)
            {
                _WebSocket.Connect();
            }
            L4Logger.Info("Open BCR connection");
            XfsCommandBase <XfsCommand> xfsCommand = new XfsCommandBase <XfsCommand>
            {
                CommandType = CommandType.Open,
                ServiceType = ServiceTypes.BCR,
                XfsCommand  = new OpenCommand
                {
                    ServiceName = serviceName
                }
            };

            _WebSocket.Send(Newtonsoft.Json.JsonConvert.SerializeObject(xfsCommand, Formatting.Indented));
            ServiceName = serviceName;
        }
Ejemplo n.º 5
0
 public void Cancel()
 {
     L4Logger.Info(MethodBase.GetCurrentMethod().Name + "  Start for sending xfs command");
     try
     {
         if (!_WebSocket.IsAlive)
         {
             _WebSocket.Connect();
         }
         XfsCommandBase <XfsCommand> xfsCommand = new XfsCommandBase <XfsCommand>
         {
             CommandType = CommandType.Cancel,
             ServiceType = ServiceTypes.BCR,
             XfsCommand  = new ExecuteCommand
             {
             }
         };
         _WebSocket.Send(Newtonsoft.Json.JsonConvert.SerializeObject(xfsCommand, Formatting.Indented));
     }
     catch (Exception ex)
     {
         L4Logger.Error(ex);
     }
 }
Ejemplo n.º 6
0
        protected override void OnMessage(MessageEventArgs e)
        {
            lock (syncObject)
            {
                try
                {
                    L4Logger.Info("XfsCommandBehavior WebSocket_OnMessage => " + e.Data);
                    JObject Parametrs   = JObject.Parse(e.Data);
                    var     CommandType = (CommandType)Enum.ToObject(typeof(CommandType), int.Parse((string)Parametrs["CommandType"]));
                    switch (CommandType)
                    {
                    case CommandType.Init:
                    {
                        //var Command = JsonConvert.DeserializeObject<XfsCommandBase<i>>(e.Data);
                        //CurrentCommand = new XfsCommandBase<IXfsCommand>
                        //{
                        //    CommandType = Command.CommandType,
                        //    XfsCommand = Command.XfsCommand,
                        //    IsExecuteSuccessfully = Command.IsExecuteSuccessfully,
                        //    ServiceType = Command.ServiceType
                        //};

                        //var XFSDevice = AddOrGetServiceBase(Command);

                        //XFSDevice.OpenComplete += XFSDevice_OpenComplete;
                        //XFSDevice.OpenError += XFSDevice_OpenError;
                        //XFSDevice.RegisterComplete += XFSDevice_RegisterComplete;
                        //XFSDevice.RegisterError += XFSDevice_RegisterError;

                        break;
                    }

                    case CommandType.Open:
                    {
                        var Command = JsonConvert.DeserializeObject <XfsCommandBase <OpenCommand> >(e.Data);

                        var XFSDevice = XFS_DevicesCollection.Instance.GetValue(Command.ServiceType);

                        XFSDevice.ResetEvents();

                        XFSDevice.CurrentCommand = new XfsCommandBase <XfsCommand>
                        {
                            CommandType           = CommandType.Open,
                            XfsCommand            = Command.XfsCommand,
                            IsExecuteSuccessfully = Command.IsExecuteSuccessfully,
                            ServiceType           = Command.ServiceType
                        };


                        XFSDevice.OpenComplete         -= XFSDevice_OpenComplete;
                        XFSDevice.OpenError            -= XFSDevice_OpenError; XFSDevice.RegisterComplete -= XFSDevice_RegisterComplete;
                        XFSDevice.RegisterError        -= XFSDevice_RegisterError;
                        XFSDevice.CancelComplete       -= XFSDevice_CancelComplete;
                        XFSDevice.CancelError          -= XFSDevice_CancelError;
                        XFSDevice.ExecuteComplete      -= XFSDevice_ExecuteComplete;
                        XFSDevice.ExecuteCompleteError -= XFSDevice_ExecuteCompleteError;
                        XFSDevice.ExecuteEvent         -= XFSDevice_ExecuteEvent;


                        XFSDevice.OpenComplete         += XFSDevice_OpenComplete;
                        XFSDevice.OpenError            += XFSDevice_OpenError;
                        XFSDevice.RegisterComplete     += XFSDevice_RegisterComplete;
                        XFSDevice.RegisterError        += XFSDevice_RegisterError;
                        XFSDevice.CancelComplete       += XFSDevice_CancelComplete;
                        XFSDevice.CancelError          += XFSDevice_CancelError;
                        XFSDevice.ExecuteComplete      += XFSDevice_ExecuteComplete;
                        XFSDevice.ExecuteCompleteError += XFSDevice_ExecuteCompleteError;
                        XFSDevice.ExecuteEvent         += XFSDevice_ExecuteEvent;
                        if (Command.XfsCommand.AcceptEvents != null)
                        {
                            XFSDevice.eventHandlers.Clear();
                            XFSDevice.eventHandlers.AddRange(Command.XfsCommand.AcceptEvents);
                        }
                        XFSDevice.Open(Command.XfsCommand.ServiceName);

                        break;
                    }

                    case CommandType.Cancel:
                    {
                        XfsCommandBase <CancellCommand> Command = JsonConvert.DeserializeObject <XfsCommandBase <CancellCommand> >(e.Data);
                        var XFSDevice = XFS_DevicesCollection.Instance.GetValue(Command.ServiceType);
                        XFSDevice.CurrentCommand = new XfsCommandBase <XfsCommand>
                        {
                            CommandType           = CommandType.Cancel,
                            XfsCommand            = Command.XfsCommand,
                            IsExecuteSuccessfully = Command.IsExecuteSuccessfully,
                            ServiceType           = Command.ServiceType
                        };
                        XFSDevice.Cancel();
                        break;
                    }

                    case CommandType.Getinfo:
                    {
                        try
                        {
                            XfsCommandBase <GetInfoCommand> Command = JsonConvert.DeserializeObject <XfsCommandBase <GetInfoCommand> >(e.Data);
                            var XFSDevice = XFS_DevicesCollection.Instance.GetValue(Command.ServiceType);
                            L4Logger.Info("Start get info for " + Command.ServiceType);
                            XFSDevice.CurrentCommand = new XfsCommandBase <XfsCommand>
                            {
                                CommandType           = CommandType.Getinfo,
                                XfsCommand            = Command.XfsCommand,
                                IsExecuteSuccessfully = Command.IsExecuteSuccessfully,
                                ServiceType           = Command.ServiceType
                            };
                            L4Logger.Info("call GetStatus");
                            var obj = (ISTATUS)Activator.CreateInstance(Command.XfsCommand.StatusType);

                            XFSDevice.GetStatus(out obj, Command.XfsCommand.CommandCode, Command.XfsCommand.StatusType);

                            L4Logger.Info(" Fill info data");
                            Command.XfsCommand.Status = obj;
                            if (Command.XfsCommand.StatusTypeModel != null)
                            {
                                var model = (IXfsResultModel)Activator.CreateInstance(Command.XfsCommand.StatusTypeModel);
                                model.Fill(obj);
                                Command.XfsCommand.StatusModel = model;
                            }

                            L4Logger.Info("Call to send");
                            Command.IsExecuteSuccessfully = true;
                            SendResponse(Command);
                        }
                        catch (Exception ex)
                        {
                            L4Logger.Error(ex);
                        }
                        break;
                    }

                    case CommandType.Execute:

                    {
                        XfsCommandBase <ExecuteCommand> Command = JsonConvert.DeserializeObject <XfsCommandBase <ExecuteCommand> >(e.Data);

                        var XFSDevice = XFS_DevicesCollection.Instance.GetValue(Command.ServiceType);

                        XFSDevice.CurrentCommand = new XfsCommandBase <XfsCommand>
                        {
                            CommandType           = CommandType.Execute,
                            XfsCommand            = Command.XfsCommand,
                            IsExecuteSuccessfully = Command.IsExecuteSuccessfully,
                            ServiceType           = Command.ServiceType
                        };

                        if (Command.XfsCommand.CancelLastCommand)
                        {
                            XFSDevice.Cancel(false);
                        }

                        //unsafe
                        {
                            List <int> AcceptEvents = new List <int>();
                            if (Command.XfsCommand.AcceptEvents != null)
                            {
                                AcceptEvents.AddRange(Command.XfsCommand.AcceptEvents);
                            }


                            if (Command.XfsCommand.Events != null)
                            {
                                XFSDevice.eventHandlers.Clear();
                                XFSDevice.GlobalEvents.Clear();
                                XFSDevice.eventHandlers.AddRange(AcceptEvents);
                                Command.XfsCommand.Events.ForEach(Event =>
                                    {
                                        XFSDevice.eventHandlers.Add(Event.EventId);
                                        if (Event.IsGlobalEvent)
                                        {
                                            XFSDevice.GlobalEvents.Add(new Wrapper.Common.XFSDeviceBase.GlobalEvent
                                            {
                                                EventId        = Event.EventId,
                                                EventParam     = Event.EventParam,
                                                EventParamType = Event.EventParamType
                                            });
                                        }
                                    });
                            }
                            else
                            {
                                XFSDevice.eventHandlers.Clear();
                                XFSDevice.GlobalEvents.Clear();
                                XFSDevice.eventHandlers.AddRange(AcceptEvents);
                            }
                            XFSDevice.commandHandlers.Add(Command.XfsCommand.CommandCode);
                            IntPtr cmdPtr = IntPtr.Zero;

                            if (Command.XfsCommand.ParamModel != null)
                            {
                                //var objModel = Activator.CreateInstance(Command.XfsCommand.ParamModelType);
                                var param = XFSUtil.Cast(Command.XfsCommand.ParamModel, Command.XfsCommand.ParamModelType);
                                cmdPtr = (param as IXfsModel).ToPopinter();
                            }
                            else
                            {
                                cmdPtr = XFSUtil.StructureToPtr(Command.XfsCommand.Param, Command.XfsCommand.PramType);
                            }
                            int hResult = XFSDevice.ExecuteCommand(
                                Command.XfsCommand.CommandCode,
                                cmdPtr,
                                XFSDevice_ExecuteError);
                            Marshal.FreeHGlobal(cmdPtr);
                            if (hResult == XFS4NET.Model.Common.XFSDefinition.WFS_SUCCESS)
                            {
                                if (Command.XfsCommand.LightControlCommand != null)
                                {
                                    ExcuteSiuCommand(Command.XfsCommand.LightControlCommand.ExecuteSIU, Command.ServiceType);
                                }
                                else
                                {
                                }
                            }
                        }

                        break;
                    }
                    }
                }
                catch (Exception ex)
                {
                    L4Logger.Error(ex);
                }
            }
        }
Ejemplo n.º 7
0
        private void ParsCommand(XfsCommandBase <object> commandBase)
        {
            switch (commandBase.CommandType)
            {
            case CommandType.Execute:
            {
                blockingQueue.Clear();
                var cmnd = JsonConvert.DeserializeObject <ExecuteCommand>(JsonConvert.SerializeObject(commandBase.XfsCommand));
                if (commandBase.IsExecuteSuccessfully)
                {
                    if (cmnd.CommandCode == BCRDefinition.WFS_CMD_BCR_READ)
                    {
                        blockingQueue.Clear();
                        try
                        {
                            var data = XFSUtil.Cast <BarcodeData[]>(cmnd.ResultModel)[0].Value;
                            ReadDataCompleted?.Invoke(data);
                        }
                        catch (Exception ex)
                        {
                            L4Logger.Error(ex);
                            //MediaError.Invoke();
                        }
                    }
                }
                else
                {
                    if (commandBase.ErrorCode == XFSDefinition.WFS_ERR_CANCELED)
                    {
                        return;
                    }
                    if (cmnd.CommandCode == BCRDefinition.WFS_CMD_BCR_READ)
                    {
                        ReadDataError?.Invoke("BCR", commandBase.ErrorCode, commandBase.ErrorCode.ToString());
                        //if (workingMode == WorkingMode.None || workingMode == WorkingMode.EjectCard)
                        //    return;
                        //else
                        //    ReadRawDataError?.Invoke("IDC", commandBase.ErrorCode, commandBase.ErrorCode.ToString());

                        //workingMode = WorkingMode.None;
                    }
                }
                break;
            }

            case CommandType.Open:
            {
                var cmnd = JsonConvert.DeserializeObject <OpenCommand>(JsonConvert.SerializeObject(commandBase.XfsCommand));
                if (commandBase.IsExecuteSuccessfully)
                {
                    if (commandBase.Detail.Equals("XFSDevice_OpenComplete"))
                    {
                        IsOpenned = true;
                        OpenCompleted?.Invoke();
                    }
                    if (commandBase.Detail.Equals("XFSDevice_RegisterComplete"))
                    {
                        RegisterCompleted?.Invoke();
                    }
                }
                else
                {
                    if (commandBase.Detail.Equals("XFSDevice_OpenError"))
                    {
                        IsOpenned = false;
                        OpenError?.Invoke(commandBase.ErrorCode);
                    }
                    if (commandBase.Detail.Equals("XFSDevice_RegisterError"))
                    {
                        RegisterError?.Invoke(commandBase.ErrorCode);
                    }
                }
                break;
            }

            case CommandType.Getinfo:
            {
                var cmnd = JsonConvert.DeserializeObject <GetInfoCommand>(JsonConvert.SerializeObject(commandBase.XfsCommand));
                GetInfoResponse?.Invoke(XFSUtil.Cast <WFSBCRSTATUS>(cmnd.Status), null);
                break;
            }
            }
        }