public ErrorPromise <RegisterationErrorResultStatus> Register(string username, string password) { IDispatcher dispatcher = GameDispatcher.Dispatcher; ErrorDeferred <RegisterationErrorResultStatus> deferred = new ErrorDeferred <RegisterationErrorResultStatus>(); string authenticationId = InfoResolver.Resolve <BacktoryInfo>().AuthenticationId; string url = "https://api.backtory.com/auth/users"; ThreadPool.QueueUserWorkItem(state => { try { HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(new Uri(url)); webRequest.KeepAlive = true; webRequest.Method = "POST"; webRequest.ContentType = "application/json; charset=utf-8"; webRequest.Headers.Add("X-Backtory-Authentication-Id", authenticationId); string body = JsonConvert.SerializeObject(new { username, password }); byte[] resoponse = Encoding.UTF8.GetBytes(body); webRequest.ContentLength = resoponse.Length; using (System.IO.Stream requestStream = webRequest.GetRequestStream()) { requestStream.Write(resoponse, 0, resoponse.Length); } using (WebResponse webResponse = webRequest.GetResponse()) { using (System.IO.Stream responseStream = webResponse.GetResponseStream()) { using (StreamReader reader = new StreamReader(responseStream)) { reader.ReadToEnd(); } } } dispatcher.Dispach(() => { deferred.Resolve(); }); } catch (WebException we) { dispatcher.Dispach(() => { HttpWebResponse httpWebResponse = we.Response as HttpWebResponse; if (httpWebResponse != null) { if (httpWebResponse.StatusCode == HttpStatusCode.Conflict) { deferred.Reject(RegisterationErrorResultStatus.UsernameIsInUse); return; } } deferred.Reject(RegisterationErrorResultStatus.CannotConnectToServer); }); } }); return(deferred.Promise()); }
private void FailedDefered(ShowVideoFailed failed) { if (_deferred != null) { ErrorDeferred <ShowVideoFailed> errorDeferred = _deferred; _deferred = null; errorDeferred.Reject(failed); } }
public ErrorPromise <ShowVideoFailed> ShowVideo(string zone, bool skipable) { Initialize(); ErrorDeferred <ShowVideoFailed> deferred = new ErrorDeferred <ShowVideoFailed>(); if (_deferred != null) { deferred.Reject(ShowVideoFailed.AlreadyShowingVideo); return(deferred.Promise()); } _deferred = deferred; _isSkipable = skipable; Tapsell.requestAd(zone, false, result => { Debug.Log("On ad exists"); // onAdAvailable TapsellShowOptions showOptions = new TapsellShowOptions(); showOptions.backDisabled = false; showOptions.immersiveMode = false; showOptions.rotationMode = TapsellShowOptions.ROTATION_UNLOCKED; showOptions.showDialog = true; Tapsell.showAd(result.adId, showOptions); }, zoneId => { Debug.Log("On no ad available"); // onNoAdAvailable FailedDefered(ShowVideoFailed.NoVideoAvilable); }, error => { Debug.Log("On Error"); // onError FailedDefered(ShowVideoFailed.ProviderError); }, zoneId => { Debug.Log("On no network"); // onNoNetwork FailedDefered(ShowVideoFailed.ProviderError); }, result => { Debug.Log("On Expire"); // onExpiring FailedDefered(ShowVideoFailed.ProviderError); // this ad is expired, you must download a new ad for this zone }); return(deferred.Promise()); }
public ErrorPromise <ShowVideoFailed> ShowVideo(string zone, bool skipable) { if (_deferred != null) { ErrorDeferred <ShowVideoFailed> deferred = new ErrorDeferred <ShowVideoFailed>(); deferred.Reject(ShowVideoFailed.AlreadyShowingVideo); return(deferred.Promise()); } _deferred = new ErrorDeferred <ShowVideoFailed>(); TaplighInterface.Instance.ShowVideoAd(skipable); return(_deferred.Promise()); }
public void Initialize() { if (_isInitialized) { return; } _isInitialized = true; Tapsell.initialize(InfoResolver.Resolve <TapsellInfo>().Key); Tapsell.setRewardListener( result => { if (!result.completed) { if (result.rewarded && _isSkipable) { ErrorDeferred <ShowVideoFailed> errorDeferred = _deferred; _deferred = null; errorDeferred.Resolve(); } else { FailedDefered(ShowVideoFailed.Cancel); } } else { if (!result.rewarded) { FailedDefered(ShowVideoFailed.ProviderError); } else { ErrorDeferred <ShowVideoFailed> errorDeferred = _deferred; _deferred = null; errorDeferred.Resolve(); } } } ); }
public void Initialize() { if (_initialized) { return; } _initialized = true; TaplighInterface.Instance.InitializeTapligh(InfoResolver.Resolve <TaplighInfo>().Key); TaplighInterface.Instance.OnShowAdListener = (result, s) => { switch (result) { case ShowAdResult.NO_INTERNET_ACSSES: case ShowAdResult.BAD_TOKEN_USED: case ShowAdResult.INTERNAL_ERROR: { if (_deferred == null) { return; } ErrorDeferred <ShowVideoFailed> errorDeferred = _deferred; _deferred = null; errorDeferred.Reject(ShowVideoFailed.ProviderError); } break; case ShowAdResult.NO_AD_AVAILABLE: case ShowAdResult.NO_AD_READY: { if (_deferred == null) { return; } ErrorDeferred <ShowVideoFailed> errorDeferred = _deferred; _deferred = null; errorDeferred.Reject(ShowVideoFailed.NoVideoAvilable); } break; case ShowAdResult.AD_AVAILABLE: break; case ShowAdResult.AD_VIEWED_COMPLETELY: break; case ShowAdResult.AD_CLICKED: break; case ShowAdResult.AD_IMAGE_CLOSED: break; case ShowAdResult.AD_VIDEO_CLOSED_AFTER_FULL_VIEW: { if (_deferred == null) { return; } ErrorDeferred <ShowVideoFailed> errorDeferred = _deferred; _deferred = null; errorDeferred.Resolve(); } break; case ShowAdResult.AD_VIDEO_CLOSED_ON_VIEW: { if (_deferred == null) { return; } ErrorDeferred <ShowVideoFailed> errorDeferred = _deferred; _deferred = null; errorDeferred.Reject(ShowVideoFailed.Cancel); } break; default: throw new ArgumentOutOfRangeException("result", result, null); } }; }