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))); }
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); }
public ScanResult(IAWAppHostApi impl, bool pauseAfterBarcode, LayoutStrategy layout) { _impl = impl; _layout = layout; _pauseAfterBarcode = pauseAfterBarcode; }