Exemplo n.º 1
0
    private IEnumerator GetMailingListsCoroutine(ListsReadyCallback success, NoConnectionCallback noConnection)
    {
        UnityWebRequest request = UnityWebRequest.Get(Constants.serverAddress + "/api/mailinglists");

        request.chunkedTransfer = false;

        yield return(request.SendWebRequest());

        while (!request.isDone)
        {
            yield return(new WaitForEndOfFrame());
        }

        if (request.isNetworkError)
        {
            Debug.Log("Network error: Cannot get lists: " + request.error + ", Code = " + request.responseCode);
            if (noConnection != null)
            {
                noConnection();
            }
        }
        else if (request.isHttpError)
        {
            Debug.Log("Http error: Cannot get lists: " + request.error + ", Code = " + request.responseCode);
            if (noConnection != null)
            {
                noConnection();
            }
        }
        else
        {
            try
            {
                Dictionary <string, ListInfo> lists = JsonConvert.DeserializeObject <Dictionary <string, ListInfo> >(request.downloadHandler.text);
                m_CachedListNames = new List <string>();
                m_CachedLists     = new Dictionary <string, ListInfo>();

                foreach (var list in lists)
                {
                    //Debug.Log(list.Value.name + ": " + list.Value._id);
                    m_CachedListNames.Add(list.Value.name);
                    m_CachedLists[list.Value._id] = list.Value;
                }

                if (success != null)
                {
                    success();
                }
            } catch (Exception)
            {
                Debug.LogWarning("Warning: Getting mailing lists failed.");
                m_CachedListNames = new List <string>();
                m_CachedLists     = new Dictionary <string, ListInfo>();
            }
        }
    }
Exemplo n.º 2
0
 public void GetUsers(UsersReceivedCallback callback, ListsReadyCallback listCallback, NoConnectionCallback failCallback)
 {
     if (m_CachedUsernames != null && callback != null)
     {
         callback(m_CachedUsernames);
     }
     else
     {
         StartCoroutine(GetRolesCoroutine());
         StartCoroutine(GetMailingListsCoroutine(listCallback, failCallback));
         StartCoroutine(GetUsersCoroutine(() => { callback(m_CachedUsernames); }, failCallback));
     }
 }