Exemple #1
0
        public void InitServerInfo(string serverIp, string serverPort)
        {
            IsOpenned = false;
            L4Logger.Info("BCR InitServerInfo");
            if (_WebSocket != null)
            {
                _WebSocket.Close();
                _WebSocket.OnMessage -= _WebSocket_OnMessage;
            }
            this.ServerIP   = serverIp;
            this.ServerPort = serverPort;

            _WebSocket            = new WebSocketSharp.WebSocket(string.Format("ws://{0}:{1}/XfsCommandBehavior", ServerIP, ServerPort));
            _WebSocket.OnMessage += _WebSocket_OnMessage;
            _WebSocket.OnClose   += _WebSocket_OnClose;
            _WebSocket.OnError   += _WebSocket_OnError;
            _WebSocket.Connect();

            ReadDataCompleted = null;
            ReadDataError     = null;
            OpenCompleted     = null;
            RegisterCompleted = null;
            OpenError         = null;
            RegisterError     = null;
        }
Exemple #2
0
        public void Fill(object result)
        {
            var data = (WFS_CDM_STATUS)result;

            this.dwGuidLights            = data.dwGuidLights;
            this.fwDevice                = data.fwDevice;
            this.fwDispenser             = data.fwDispenser;
            this.fwIntermediateStacker   = data.fwIntermediateStacker;
            this.fwSafeDoor              = data.fwSafeDoor;
            this.lpszExtra               = data.lpszExtra;
            this.usPowerSaveRecoveryTime = data.usPowerSaveRecoveryTime;
            this.wDevicePosition         = data.wDevicePosition;
            var tmp = Activator.CreateInstance(typeof(WFS_CDM_OUTPOS));

            XFSUtil.PtrToStructure(data.lppPositions, typeof(WFS_CDM_OUTPOS), ref tmp);

            try
            {
                this.lppPositions = new WFS_CDM_OUTPOS
                {
                    fwPosition        = ((WFS_CDM_OUTPOS)tmp).fwPosition,
                    fwPositionStatus  = ((WFS_CDM_OUTPOS)tmp).fwPositionStatus,
                    fwShutter         = ((WFS_CDM_OUTPOS)tmp).fwShutter,
                    fwTransport       = ((WFS_CDM_OUTPOS)tmp).fwTransport,
                    fwTransportStatus = ((WFS_CDM_OUTPOS)tmp).fwTransportStatus
                };
            }
            catch (Exception ex)
            {
                L4Logger.Error(ex);
                L4Logger.Info(string.Format("Device Result => {0}  And PositionXfs {1} )", Newtonsoft.Json.JsonConvert.SerializeObject(tmp), data.lppPositions));
                this.lppPositions = new WFS_CDM_OUTPOS();
            }
        }
Exemple #3
0
        public void Fill(object result)
        {
            var data = (WFSCIMSTATUS)result;

            this.fwDevice = data.fwDevice;
            this.fwIntermediateStacker = data.fwIntermediateStacker;
            this.fwSafeDoor            = data.fwSafeDoor;
            this.lpszExtra             = data.lpszExtra;
            this.fwAcceptor            = data.fwAcceptor;
            this.fwStackerItems        = data.fwStackerItems;
            this.fwBanknoteReader      = data.fwBanknoteReader;
            this.bDropBox = data.bDropBox;

            var tmp = Activator.CreateInstance(typeof(WFSCIMOUTPOS));

            XFSUtil.PtrToStructure(data.lppPositions, typeof(WFSCIMOUTPOS), ref tmp);

            try
            {
                this.lppPositions = new WFSCIMOUTPOS
                {
                    fwPosition        = ((WFSCIMOUTPOS)tmp).fwPosition,
                    fwPositionStatus  = ((WFSCIMOUTPOS)tmp).fwPositionStatus,
                    fwShutter         = ((WFSCIMOUTPOS)tmp).fwShutter,
                    fwTransport       = ((WFSCIMOUTPOS)tmp).fwTransport,
                    fwTransportStatus = ((WFSCIMOUTPOS)tmp).fwTransportStatus
                };
            }
            catch (Exception ex)
            {
                L4Logger.Error(ex);
                L4Logger.Info(string.Format("Device Result => {0}  And PositionXfs {1} )", Newtonsoft.Json.JsonConvert.SerializeObject(tmp), data.lppPositions));
                this.lppPositions = new WFSCIMOUTPOS();
            }
        }
Exemple #4
0
        public void RejectAndCut()
        {
            try
            {
                L4Logger.Info(MethodBase.GetCurrentMethod().Name + "  Start");
                this.Invoke(new Action(() =>
                {
                    //L4Logger.Info("PTR Execute => WFS_CMD_PTR_CONTROL_MEDIA");
                    WFSPTRCONTROLMEDIA ptrmedia = new WFSPTRCONTROLMEDIA();
                    ptrmedia.dwMediaControl     = (int)PTRCapsFwControl.WFS_PTR_CTRLEJECT | (int)PTRCapsFwControl.WFS_PTR_CTRLCUT;

                    IntPtr ptr = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(WFSPTRCONTROLMEDIA)));
                    Marshal.StructureToPtr(ptrmedia, ptr, false);

                    int hResult = XfsApi.WFSAsyncExecute(hService, PTRDefinition.WFS_CMD_PTR_CONTROL_MEDIA, ptr, 0, Handle, ref requestID);
                    //L4Logger.Info(string.Format("PTR RejectAndCut requestID {0}  Result = {1}", requestID, hResult));
                    if (hResult != XFSDefinition.WFS_SUCCESS)
                    {
                        OnPrintErrorError(hResult);
                    }
                    else
                    {
                        OnPrintCompleted();
                    }
                }));
            }
            catch (Exception ex)
            {
                L4Logger.Info(ex.ToString());
            }
        }
Exemple #5
0
 protected override void OnClose(CloseEventArgs e)
 {
     L4Logger.Info("Event OnClose => " + this.ToString());
     XFS_DevicesCollection.Instance.GetAll().ForEach(item =>
     {
         item.Close();
     });
 }
Exemple #6
0
        public bool Enqueue(T item)
        {
            lock (queue)
            {
                if (this.Count > 0)
                {
                    var _item = queue.Dequeue();
                    if (_item.WaitForResponse)
                    {
                        L4Logger.Info("Can not insert item must WaitForResponse => " + _item.MethodName);
                        queue.Enqueue(_item);
                        item.Dispose();
                        return(false);
                    }
                    else
                    {
                    }
                }
                if (closing || null == item)
                {
                    return(false);
                }

                queue.Enqueue(item);
                CancellationTokenSource?.Dispose();
                CancellationTokenSource = new System.Threading.CancellationTokenSource();
                System.Threading.Tasks.Task.Run(async delegate
                {
                    await Task.Delay(item.CommandTimeSpan, CancellationTokenSource.Token);

                    if (!CancellationTokenSource.IsCancellationRequested)
                    {
                        if (ObjectTimeout != null)
                        {
                            if (queue.Count > 0)
                            {
                                var value = (T)queue.Dequeue();
                                L4Logger.Info(string.Format("object Dequeue Timeout method {0} guid {1} ", value.MethodName, value.guid));
                                value.Dispose();
                                ObjectTimeout.Invoke(value);
                            }
                        }
                    }
                });

                L4Logger.Info(string.Format("item inserted  {0}  Timeout  {1}  WaitForResponse {2}  guid {3}",
                                            item.MethodName, item.CommandTimeSpan, item.WaitForResponse, item.guid));

                if (queue.Count == 1)
                {
                    // wake up any blocked dequeue
                    Monitor.PulseAll(queue);
                }
                item = null;
                return(true);
            }
        }
 public XFS_DevicesCollection()
 {
     dictionary = new ConcurrentDictionary <ServiceTypes, XFSDeviceBase>();
     L4Logger.Info("ctor XFS_DevicesCollection");
     //IDC = new IDC.IDC();
     //PIN = new PIN.PIN();
     //PTR = new PTR.PTR();
     //SIU = new SIU.SIU();
 }
Exemple #8
0
 private void BlockingQueue_ObjectTimeout(TaskModel obj)
 {
     L4Logger.Info(MethodBase.GetCurrentMethod().Name + "  Start");
     //L4Logger.Info("IDC working mode => " + workingMode.ToString());
     //if (workingMode == WorkingMode.EjectCard)
     //{
     //    workingMode = WorkingMode.None;
     //    CaptureCard();
     //}
 }
Exemple #9
0
 private void XFSDevice_OpenComplete(ServiceTypes serviceType)
 {
     L4Logger.Info("OpenComplete => " + serviceType.ToString());
     lock (syncObject)
     {
         XFS_DevicesCollection.Instance.GetValue(serviceType).CurrentCommand.IsExecuteSuccessfully = true;
         XFS_DevicesCollection.Instance.GetValue(serviceType).CurrentCommand.Detail = "XFSDevice_OpenComplete";
         SendResponse(XFS_DevicesCollection.Instance.GetValue(serviceType).CurrentCommand);
     }
 }
Exemple #10
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);
            }
        }
Exemple #11
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);
     }
 }
Exemple #12
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);
            }
        }
Exemple #13
0
 protected override void OnExecuteEvent(ref WFSRESULT result)
 {
     switch (result.dwCommandCodeOrEventID)
     {
     case PINDefinition.WFS_EXEE_PIN_KEY:
         WFSPINKEY key = new WFSPINKEY();
         XFSUtil.PtrToStructure(result.lpBuffer, ref key);
         L4Logger.Info("WFS_EXEE_PIN_KEY => " + key.ulDigit);
         OnPINKey(ref key);
         break;
     }
 }
Exemple #14
0
 private void SendResponse(object obj)
 {
     L4Logger.Info("Sending Response  => " + JsonConvert.SerializeObject(obj, Formatting.Indented));
     try
     {
         Send(JsonConvert.SerializeObject(obj, Formatting.Indented));
     }
     catch (Exception ex)
     {
         L4Logger.Error(ex);
     }
 }
Exemple #15
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);
        }
Exemple #16
0
        private void _WebSocket_OnMessage(object sender, MessageEventArgs e)
        {
            try
            {
                L4Logger.Info("Barcode Reader _WebSocket_OnMessage => " + e.Data);
                JObject Parametrs = JObject.Parse(e.Data);
                var     Datatype  = (Datatype)Enum.ToObject(typeof(Datatype), int.Parse((string)Parametrs["Datatype"]));
                switch (Datatype)
                {
                case Datatype.Command:
                {
                    try
                    {
                        var obj = JsonConvert.DeserializeObject <XfsCommandBase <object> >(e.Data);
                        ParsCommand(obj);
                        L4Logger.Info("XfsCommandBase<IXfsCommand> data recived ");
                    }
                    catch (Exception ex)
                    {
                        L4Logger.Error(ex);
                    }
                    break;
                }

                case Datatype.Event:
                {
                    try
                    {
                        var obj = Newtonsoft.Json.JsonConvert.DeserializeObject <ExecuteEventBase>(e.Data);
                        ParsEvent(obj);
                        L4Logger.Info("ExecuteEventBase data recived ");
                    }
                    catch (Exception ex)
                    {
                        L4Logger.Error(ex);
                    }
                    break;
                }
                }
            }
            catch (Exception ex)
            {
                L4Logger.Error(ex);
            }
        }
Exemple #17
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;
        }
Exemple #18
0
        public MainForm()
        {
            InitializeComponent();

            try
            {
                var tmp = XFS_DevicesCollection.Instance;
                L4Logger.Info(string.Format("Open socket for ws://{0}:{1}/XfsCommandBehavior", ServerIP, ServerPort));
                Server = new WebSocketServer(string.Format("ws://{0}:{1}", ServerIP, ServerPort));


                Server.AddWebSocketService <XfsCommandBehavior>("/XfsCommandBehavior");
                //Server.WaitTime = Timeout.InfiniteTimeSpan;

                Server.Start();
            }
            catch (Exception ex)
            {
                L4Logger.Info("Error in init WebSocketServer => " + ex.ToString());
            }
        }
Exemple #19
0
        public static IntPtr FindAndLoadModule(string dllName)
        {
            L4Logger.Info("try to load moudle " + dllName);
            var handdler = IsModuleLoaded(dllName.Substring(0, dllName.LastIndexOf(".")));

            if (handdler != IntPtr.Zero)
            {
                L4Logger.Info("module loaded before Handdler => " + handdler.ToString());
                return(handdler);
            }
            var path = AssemblyDirectory;

            string[] files = Directory.GetFiles(path,
                                                dllName,
                                                SearchOption.AllDirectories);
            var dllpath = files.FirstOrDefault(c => c.Contains(dllName));

            if (dllpath != null)
            {
                L4Logger.Info("Dll found path = " + dllpath);
                var dllDir = dllpath.Replace("\\" + dllName, string.Empty);
                L4Logger.Info("Dll Directory found path = " + dllDir);
                SetDllDirectory(dllDir);
                handdler = LoadLibrary(dllpath);
                L4Logger.Info("Dll loaded handller = " + handdler.ToString());
                if (handdler == IntPtr.Zero)
                {
                    L4Logger.Info("module loaded Failed ErrorCode => " + Marshal.GetLastWin32Error().ToString());
                }
                else
                {
                    L4Logger.Info("module loaded runtime Handdler => " + handdler.ToString());
                }
                return(handdler);
            }
            return(IntPtr.Zero);
        }
Exemple #20
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);
     }
 }
Exemple #21
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);
                }
            }
        }
Exemple #22
0
        private void XFSDevice_ExecuteEvent(ServiceTypes serviceType, int EventID, IntPtr obj)
        {
            L4Logger.Info("XFSDevice_ExecuteEvent");
            lock (syncObject)
            {
                try
                {
                    var math = XFS_DevicesCollection.Instance.GetValue(serviceType).GlobalEvents.FirstOrDefault(c => c.EventId == EventID);
                    if (math != null)
                    {
                        L4Logger.Info("Global Event Reaised");
                        object res = null;
                        res = Activator.CreateInstance(math.EventParamType);
                        XFSUtil.PtrToStructure(obj, math.EventParamType, ref res);
                        ExecuteEventBase eventBase = new ExecuteEventBase
                        {
                            EventID        = EventID,
                            EventParam     = res,
                            EventParamType = math.EventParamType
                        };
                        SendResponse(eventBase);
                    }
                    else if (XFS_DevicesCollection.Instance.GetValue(serviceType).CurrentCommand.XfsCommand is ExecuteCommand)
                    {
                        L4Logger.Info("Command Event Reaised");
                        var    cmnd = (XFS_DevicesCollection.Instance.GetValue(serviceType).CurrentCommand.XfsCommand as ExecuteCommand);
                        object res  = null;
                        if (cmnd != null && cmnd.EventParamType != null)
                        {
                            L4Logger.Info("Event hass response model");
                            res = Activator.CreateInstance(cmnd.EventParamType);
                            XFSUtil.PtrToStructure(obj, cmnd.EventParamType, ref res);

                            ExecuteEventBase eventBase = new ExecuteEventBase
                            {
                                EventID        = EventID,
                                EventParam     = res,
                                EventParamType = cmnd.EventParamType
                            };
                            SendResponse(eventBase);
                        }
                        else if (cmnd.EventParamType == null)
                        {
                            L4Logger.Info("Event not model");
                            ExecuteEventBase eventBase = new ExecuteEventBase
                            {
                                EventID        = EventID,
                                EventParam     = null,
                                EventParamType = null
                            };
                            SendResponse(eventBase);
                        }
                    }
                    else
                    {
                        L4Logger.Info("Un categoriezd Event");
                        ExecuteEventBase eventBase = new ExecuteEventBase
                        {
                            EventID        = EventID,
                            EventParam     = null,
                            EventParamType = null
                        };
                        SendResponse(eventBase);
                    }
                }
                catch (Exception ex)
                {
                }
            }
        }
Exemple #23
0
 private static void SystemEvents_SessionEnding(object sender, Microsoft.Win32.SessionEndingEventArgs e)
 {
     L4Logger.Info("SystemEvents_SessionEnding");
     XFS_DevicesCollection.Instance.GetAll().ForEach(c => c.Close());
 }
Exemple #24
0
 private static void Application_ThreadException(object sender, System.Threading.ThreadExceptionEventArgs e)
 {
     L4Logger.Info("Application_ThreadException =>" + e.Exception.ToString());
 }
Exemple #25
0
 private static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
 {
     L4Logger.Info("CurrentDomain_UnhandledException =>" + e.ExceptionObject.ToString());
 }
Exemple #26
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);
            }
        }
Exemple #27
0
 private void OnApplicationExit(object sender, EventArgs e)
 {
     L4Logger.Info("ApplicationExit");
 }
Exemple #28
0
 private void MainForm_FormClosing(object sender, FormClosingEventArgs e)
 {
     L4Logger.Info("MainForm_FormClosing =>" + e.CloseReason.ToString());
 }
Exemple #29
0
        static void Main()
        {
            try
            {
                Microsoft.Win32.SystemEvents.SessionEnding += SystemEvents_SessionEnding;
                L4Logger.Info("*****************************************************Start Service****************************************************************");

                //var datattttt=  Daricheh.Core.Devices.Security.SecurityUtility.Instance.CalculateCDM(System.IO.File.ReadAllBytes("byte.txt"));
                //NativeMethods.FindAndLoadModule("msxfs.dll");
                AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;

                Application.ThreadException += Application_ThreadException;
                Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException);

                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault(false);


                XFS_DevicesCollection.Instance.Add(ServiceTypes.IDC,
                                                   new Wrapper.Common.XFSDeviceBase
                {
                    serviceType = ServiceTypes.IDC,
                });

                XFS_DevicesCollection.Instance.Add(ServiceTypes.PIN,
                                                   new Wrapper.Common.XFSDeviceBase
                {
                    serviceType = ServiceTypes.PIN,
                });

                XFS_DevicesCollection.Instance.Add(ServiceTypes.SIU,
                                                   new Wrapper.Common.XFSDeviceBase
                {
                    serviceType = ServiceTypes.SIU,
                });

                XFS_DevicesCollection.Instance.Add(ServiceTypes.PTR,
                                                   new Wrapper.Common.XFSDeviceBase
                {
                    serviceType = ServiceTypes.PTR,
                });

                XFS_DevicesCollection.Instance.Add(ServiceTypes.CDM,
                                                   new Wrapper.Common.XFSDeviceBase
                {
                    serviceType = ServiceTypes.CDM,
                });

                XFS_DevicesCollection.Instance.Add(ServiceTypes.CIM,
                                                   new Wrapper.Common.XFSDeviceBase
                {
                    serviceType = ServiceTypes.CIM,
                });

                XFS_DevicesCollection.Instance.Add(ServiceTypes.BCR,
                                                   new Wrapper.Common.XFSDeviceBase
                {
                    serviceType = ServiceTypes.BCR,
                });

                Form frm = XfsApplicationContext.Instance.mainForm;
                Application.Run(XfsApplicationContext.Instance);
                return;
            }

            catch (Win32Exception e)
            {
                L4Logger.Info("Win32 error => " + e.Message);
                Application.Exit();
            }
        }