// These are just thin wrappers over the SDK to show how to use them: // Call once, or when the carrier changes. May throw DistributedMatchEngine.HttpException. public async Task <bool> Register() { // If MEX is reachable on your SIM card: string aCarrierName = GetCarrierName(); string eCarrierName; if (me.useOnlyWifi) { eCarrierName = carrierName; } else { if (aCarrierName == null) { Debug.Log("Missing CarrierName for RegisterClient."); return(false); } eCarrierName = aCarrierName; } RegisterClientRequest req = me.CreateRegisterClientRequest(eCarrierName, orgName, appName, appVers, authToken, cellID, uniqueIDType, uniqueID, tags); Debug.Log("CarrierName: " + req.carrier_name); Debug.Log("orgName: " + req.org_name); Debug.Log("AppName: " + req.app_name); Debug.Log("AppVers: " + req.app_vers); RegisterClientReply reply = await me.RegisterClient(req); return(reply.status == ReplyStatus.RS_SUCCESS); }
async Task <bool> DoRegisterClient() { bool ok = false; MatchingEngine dme = mexSample.dme; RegisterClientReply reply = null; try { var registerClientRequest = dme.CreateRegisterClientRequest( mexSample.carrierName, mexSample.orgName, mexSample.appName, mexSample.appVers, mexSample.authToken); reply = await dme.RegisterClient(mexSample.host, mexSample.port, registerClientRequest); // the dme object stores the session tokens, so the only thing to do here is // inspect parts of the JSON registration status and retry: if (reply.status != ReplyStatus.RS_SUCCESS) { statusContainer.Post("RegisterClient did not succeed!"); } else { ok = true; } } catch (System.Net.WebException we) { Console.WriteLine(we.StackTrace); statusContainer.Post(we.Source + ", WebException: " + we.Message); statusContainer.Post(we.StackTrace); } finally { if (reply != null) { statusContainer.Post( "RegisterClient Button results:" + " Status: " + reply.status + " SessionCookie: " + reply.session_cookie + " TokenServerURI: " + reply.token_server_uri ); } } return(ok); }
/// Call once, or when the carrier changes. May throw DistributedMatchEngine.HttpException. /// <summary> /// Wrapper for Register Client. First call to establish the connection with your backend(server) deployed on MobiledgeX /// </summary> /// <returns>bool Task</returns> public async Task <bool> Register(string dmeHost = null, uint dmePort = 0) { latestRegisterStatus = false; RegisterClientRequest req = matchingEngine.CreateRegisterClientRequest(orgName, appName, appVers, developerAuthToken.Length > 0 ? developerAuthToken : null); Logger.Log("OrgName: " + req.org_name); Logger.Log("AppName: " + req.app_name); Logger.Log("AppVers: " + req.app_vers); try { await UpdateLocationAndCarrierInfo(); } catch (CarrierInfoException cie) { Debug.LogError("MobiledgeX: Register Exception: " + cie.Message); throw new RegisterClientException(cie.Message); } RegisterClientReply reply = null; try { if (dmeHost != null && dmePort != 0) { Logger.Log("Doing Register Client with DME: " + dmeHost + ", p: " + dmePort + " with req: " + req); reply = await matchingEngine.RegisterClient(dmeHost, dmePort, req); } else { if (!useSelectedRegionInProduction) { #if UNITY_EDITOR Logger.Log("Doing Register Client with DME: " + region + ", p: " + MatchingEngine.defaultDmeRestPort + " with req: " + req); Logger.LogWarning("Region Selection will work only in UnityEditor not on Mobile Devices"); reply = await matchingEngine.RegisterClient(region, MatchingEngine.defaultDmeRestPort, req); #else Logger.Log("Doing Register Client, with req: " + req); reply = await matchingEngine.RegisterClient(req); #endif } else { Logger.Log("MobiledgeX: Doing Register Client with DME: " + region + ", p: " + MatchingEngine.defaultDmeRestPort + " with req: " + req); reply = await matchingEngine.RegisterClient(region, MatchingEngine.defaultDmeRestPort, req); } } } catch (HttpException httpe) { Debug.LogError("MobiledgeX: RegisterClient HttpException: " + httpe.Message); throw new RegisterClientException("RegisterClient Exception: " + httpe.Message + ", HTTP StatusCode: " + httpe.HttpStatusCode + ", API ErrorCode: " + httpe.ErrorCode + "\nStack: " + httpe.StackTrace); } catch (Exception e) { throw new RegisterClientException("MobiledgeX: RegisterClient Exception Type: " + e.GetType() + ", Message: " + e.Message + ", InnerException : " + e.InnerException + "\nStack: " + e.StackTrace); } finally { if (reply == null) { Debug.LogError("MobiledgeX: Register reply NULL!"); throw new RegisterClientException("RegisterClient returned null."); } if (reply.status != ReplyStatus.RS_SUCCESS) { Debug.LogError("MobiledgeX: Register Failed: " + reply.status); throw new RegisterClientException("Bad RegisterClient. RegisterClient status is " + reply.status); } } latestRegisterStatus = true; return(true); }