示例#1
0
        public static Task <string> RegisterMediaAsset(string fileContent)
        {
            var requestId = UniqueIdGenerator.GenerateAsString();

            var impl = GetImpl();

            if (impl == null)
            {
                Logger.Debug(typeof(IawAppApi), "has no proper IAWApp API");
                return(Task.FromResult(fileContent.Length.ToString()));
            }

            //androidPostMediaAssetReady(webRequestIdUriEncoded : string, properMediaFileId : string) : void;
            return(Task.FromPromise <string>(
                       new TypeSafePromise <string>((onSucc, onFail) => {
                IAWAppHostApi.RegisterPostMediaAssetReady(requestId, x => onSucc(x));

                try {
                    impl.registerMediaAsset(requestId, fileContent);
                } catch (Exception ex) {
                    Logger.Error(typeof(IawAppApi), "registerMediaAsset got exception {0}", ex);
                    IAWAppHostApi.UnregisterPostMediaAssetReady(requestId);
                    onFail(ex);
                }
            }),
                       (Func <string, string>)(x => x)));
        }
示例#2
0
        public Task <Tuple <ScanResultType, string> > GetNext()
        {
            Logger.Debug(GetType(), "starting scanner webRequestId={0}", _webRequestId);

            if (!_started)
            {
                try {
                    IAWAppHostApi.RegisterPostScanQrReplyHandler(_webRequestId, OnPostScanQrReceived);
                    _impl.requestScanQr(_webRequestId, _pauseAfterBarcode, _layout);
                    _started = true;
                } catch (Exception ex) {
                    Logger.Error(GetType(), "error starting scanner {0}", ex);
                    IAWAppHostApi.UnregisterPostScanQrReplyHandler(_webRequestId);
                    return(Task.FromResult(Tuple.Create(ScanResultType.Error, (string)null)));
                }
            }

            if (_disposed)
            {
                Logger.Error(GetType(), "scanner instance is disposed");
                return(Task.FromResult(Tuple.Create(ScanResultType.Error, (string)null)));
            }

            while (_queued.Any())
            {
                var fst = _queued[0];
                _queued.RemoveAt(0);

                var res = ReplyToTuple(fst);

                if (res != null)
                {
                    return(Task.FromResult(res));
                }
            }

            _currentPromise = new TypeSafePromise <Tuple <ScanResultType, string> >(OnWaitingForPost);
            var tsk = Task.FromPromise <Tuple <ScanResultType, string> >(
                _currentPromise,
                (Func <Tuple <ScanResultType, string>, Tuple <ScanResultType, string> >)(x => x));

            return(tsk);
        }
示例#3
0
 public ScanResult(IAWAppHostApi impl, bool pauseAfterBarcode, LayoutStrategy layout)
 {
     _impl              = impl;
     _layout            = layout;
     _pauseAfterBarcode = pauseAfterBarcode;
 }