Ejemplo n.º 1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="eventType"></param>
        /// <param name="outXml"></param>
        /// <returns></returns>
        public static BarcodeEventArgs Parse(Int16 eventType, String outXml)
        {
            Contract.Requires(outXml != null);
            Contract.Ensures(Contract.Result <BarcodeEventArgs>() != null);

            BarcodeEventArgs eventArgs = new BarcodeEventArgs();
            XElement         outArgs   = XDocument
                                         .Parse(outXml)
                                         .Elements("outArgs")
                                         .FirstOrDefault();
            XElement scanData = outArgs
                                .Elements("arg-xml")
                                .Elements("scandata")
                                .FirstOrDefault();

            eventArgs.eventType = (BarcodeEventType)eventType;
            eventArgs.scannerId = outArgs
                                  .Elements("scannerID")
                                  .Select(scannerId => scannerId.Value.ToInt32())
                                  .FirstOrDefault();
            eventArgs.modelNumber = scanData
                                    .Elements("modelnumber")
                                    .Select(modelnumber => modelnumber.Value.Trim())
                                    .FirstOrDefault();
            eventArgs.serialNumber = scanData
                                     .Elements("serialnumber")
                                     .Select(serialnumber => serialnumber.Value.Trim())
                                     .FirstOrDefault();
            eventArgs.guid = scanData
                             .Elements("GUID")
                             .Select(guid => guid.Value.ToGuid())
                             .FirstOrDefault();
            eventArgs.dataType = scanData
                                 .Elements("datatype")
                                 .Select(dataType => (BarcodeDataType)dataType.Value.ToInt32())
                                 .FirstOrDefault();
            eventArgs.dataLabel = scanData
                                  .Elements("datalabel")
                                  .Select(dataLabel => dataLabel.Value
                                          .Replace("0x", String.Empty)
                                          .Split(' ')
                                          .Select(v => Convert.ToByte(v, 16))
                                          .DecodeToString(Encoding.UTF8))
                                  .FirstOrDefault();
            eventArgs.rawData = scanData
                                .Elements("rawdata")
                                .Select(dataLabel => dataLabel.Value
                                        .Replace("0x", String.Empty)
                                        .Split(' ')
                                        .Select(v => Convert.ToByte(v, 16))
                                        .ToArray())
                                .FirstOrDefault();
            return(eventArgs);
        }
 private IObservable <BarcodeEventArgs> CreateWhenBarcodeScanned()
 {
     return(Observable.FromEvent(
                (Action <BarcodeEventArgs> handler) =>
                new _ICoreScannerEvents_BarcodeEventEventHandler(
                    delegate(Int16 eventType, ref String outXml)
     {
         handler(BarcodeEventArgs.Parse(eventType, outXml));
     }),
                handler => this.coreScanner.BarcodeEvent += handler,
                handler => this.coreScanner.BarcodeEvent -= handler));
 }