IEnumerator GetPresenceAsync(UnityTask <Presence> task) { var btask = BalancerClient.GetServerUrl(Url, IsCluster, ApplicationKey); yield return(TaskManager.StartRoutine(btask.WaitRoutine())); if (btask.IsFaulted) { task.Exception = btask.Exception; task.Status = TaskStatus.Faulted; yield break; } var server = btask.Result; var presenceUrl = String.IsNullOrEmpty(server) ? server : server[server.Length - 1] == '/' ? server : server + "/"; presenceUrl = String.Format("{0}presence/{1}/{2}/{3}", presenceUrl, ApplicationKey, AuthenticationToken, Channel); var htask = HttpClient.GetAsync(presenceUrl); yield return(TaskManager.StartRoutine(htask.WaitRoutine())); if (htask.IsFaulted) { task.Exception = htask.Exception; task.Status = TaskStatus.Faulted; yield break; } task.Result = Deserialize(htask.Content); }
IEnumerator GetUrlFromCluster(UnityTask task) { if (PrototypeUri.IsCluster) { var request = new Uri(PrototypeUri.IsSecure ? "https://" + PrototypeUri.Url + "/server/ssl/1.0" : "http://" + PrototypeUri.Url + "/server/1.0"); var www = Client.GetAsync(request.ToString()); yield return(TaskManager.StartRoutine(www.WaitRoutine())); if (www.IsFaulted) { task.Status = TaskStatus.Faulted; task.Exception = www.Exception; yield break; } var response = JsonMapper.ToObject <ClusterResponse>(www.Content).url; EnpointUri = new Uri(response); //var request = new Uri(PrototypeUri.IsSecure ? "https://" + PrototypeUri.Url + "/server/ssl/1.0" : "http://" + PrototypeUri.Url + "/server/1.0"); //var response = ClusterClient.GetClusterServer(request.ToString(), ApplicationKey); //EnpointUri = new Uri(response); } else { EnpointUri = new Uri(PrototypeUri.IsSecure ? "https://" + PrototypeUri.Url : "http://" + PrototypeUri.Url); //EnpointUri = new Uri(PrototypeUri.IsSecure ? "https://" + PrototypeUri.Url + "/server/ssl/1.0" : "http://" + PrototypeUri.Url + "/server/1.0"); } }
IEnumerator GetServerFromBalancerAsync(UnityTask <string> task) { var parsedUrl = String.IsNullOrEmpty(ApplicationKey) ? Url : Url + "?appkey=" + ApplicationKey; var innerTask = Client.GetAsync(parsedUrl); yield return(TaskManager.StartRoutine(innerTask.WaitRoutine())); if (innerTask.IsFaulted) { task.Exception = innerTask.Exception; task.Status = TaskStatus.Faulted; yield break; } task.Result = ParseBalancerResponse(innerTask.Content); }
IEnumerator GetAsync(UnityTask <string> task) { var clusterRequestParameter = !String.IsNullOrEmpty(ApplicationKey) ? String.Format("appkey={0}", ApplicationKey) : String.Empty; var clusterUrl = String.Format("{0}{1}?{2}", Url, !String.IsNullOrEmpty(Url) && Url[Url.Length - 1] != '/' ? "/" : String.Empty, clusterRequestParameter); var hTask = Client.GetAsync(clusterUrl); yield return(TaskManager.StartRoutine(hTask.WaitRoutine())); if (hTask.IsFaulted) { task.Exception = hTask.Exception; task.Status = TaskStatus.Faulted; yield break; } task.Result = ParseResponse(hTask.Content); }