Esempio n. 1
0
        /// <summary>
        /// IEnumerator가 아닌 에디터를 위한 WWW 동기코드.
        /// </summary>
        /// <param name="www">WWW.</param>
        /// <param name="request_">요청된 포스트맨의 정보.</param>
        /// <param name="callback_"></param>
        static void DirectWWW(WWW www, System.Action <string> callback_)
        {
            while (!www.isDone)
            {
            }

            if (null != www.error)
            {
                Debug.LogWarning(string.Format("[{0}] - {1}", www.url, www.error));
            }
            else if (null != callback_)
            {
                string text = System.Text.Encoding.UTF8.GetString(www.bytes);

                // ISSUE - 무조건 token이 encrypy되어 날라오는건지. 확인해야함.
                if (text.Contains(CloudBread._aseEncryptDefine))
                {
                    string token = CBTool.GetElementValueFromJson(CloudBread._aseEncryptDefine, text);
                    try
                    {
                        text = CBAuthentication.AES_decrypt(token);
                    }
                    catch
                    {
                        Debug.Log(token);
                        Debug.LogWarning(string.Format("{0} - {1}", www.url, text));
                        throw;
                    }
                }
                callback_(text);
            }
            www.Dispose();
        }
Esempio n. 2
0
 string ReceiveDataPostProcess(string text_)
 {
     if (CBSetting.useEncrypt || text_.Contains(_aseEncryptDefineHeader))
     {
         return(CBAuthentication.AES_decrypt(CBTool.GetElementValueFromJson(_aseEncryptDefine, text_).Trim()));
     }
     return(text_.Trim());
 }
Esempio n. 3
0
 private string GenerateStruct(string postData_, string structType_, string header_, string name_)
 {
     if (postData_.Contains(CloudBread._aseEncryptDefine))
     {
         string token = CBAuthentication.AES_decrypt(CBTool.GetElementValueFromJson(CloudBread._aseEncryptDefine, postData_));
         return(MakeStructFromJson(header_ + name_, "struct", token));
     }
     else
     {
         return(MakeStructFromJson(header_ + name_, structType_, postData_));
     }
 }
Esempio n. 4
0
        private string GenerateStruct(string postData_, string header_)
        {
            if (string.IsNullOrEmpty(postData_))
            {
                return(string.Empty);
            }

            if (postData_.Contains(CloudBread._aseEncryptDefine))
            {
                string token = CBAuthentication.AES_decrypt(CBTool.GetElementValueFromJson(CloudBread._aseEncryptDefine, postData_));
                return(MakeStructFromJson(header_, _structType, token));
            }
            else
            {
                return(MakeStructFromJson(header_, _structType, postData_));
            }
        }
Esempio n. 5
0
        private void DrawBodyRight()
        {
            GUILayout.BeginVertical();
            {
                if (null != _postman && null != _selectedRequest)
                {
                    GUILayout.BeginHorizontal();
                    {
                        GUILayout.Box(_selectedRequest.method, _boxStyle);
                        EditorGUILayout.TextArea(_requestFullURL, _boxStyle, GUILayout.Width(400));

                        _useMyServer = GUILayout.Toggle(_useMyServer, "Use CB.Setting Server");

                        if (GUILayout.Button("Send"))
                        {
                            ResetBodyRight();
                            RequestPostmanTest(_requestFullURL, _requestPostData, _requestHeaders, delegate(string text_)
                            {
                                try
                                {
                                    if (!string.IsNullOrEmpty(text_))
                                    {
                                        _receiveJson   = text_;
                                        _receiveStruct = GenerateStruct(text_, "Receive");
                                    }
                                }
                                catch (System.Exception e_)
                                {
                                    Debug.Log(e_);
                                }
                            });
                        }
                    }
                    GUILayout.EndHorizontal();

                    GUILayout.BeginVertical();
                    {
                        _selectRequestMenuIndex = GUILayout.SelectionGrid(_selectRequestMenuIndex, _requestMenu, 2);

                        GUILayout.BeginHorizontal();
                        {
                            GUILayout.Box(_requestMenu[_selectRequestMenuIndex], _boxStyle);

                            if (0 == _selectRequestMenuIndex && GUILayout.Button("struct Print", GUILayout.Width(100)))
                            {
                                string genStructStr = GenerateStruct(_requestPostData, "Post");
                                Debug.Log(genStructStr);
                            }

                            if (0 == _selectRequestMenuIndex && GUILayout.Button("Decrypt Print", GUILayout.Width(100)))
                            {
                                string decryptStr = CBAuthentication.AES_decrypt(CBTool.GetElementValueFromJson(CloudBread._aseEncryptDefine, _requestPostData));
                                Debug.Log(decryptStr);
                            }

                            if (0 == _selectRequestMenuIndex && GUILayout.Button("Generate Protocol", GUILayout.Width(150)))
                            {
                                string url           = _selectedRequest.url.Substring(_selectedRequest.url.IndexOf("api/"));
                                string postStruct    = GenerateStruct(_requestPostData, "Post");
                                string receiveStruct = GenerateStruct(_requestPostData, "Receive");

                                // postData가 있는 경우/없는경우.
                                RequestPostmanTest(_requestFullURL, _requestPostData, _requestHeaders, delegate(string text_)
                                {
                                    try
                                    {
                                        if (!string.IsNullOrEmpty(text_))
                                        {
                                            string body   = CBToolEditor.GetClassTextFile("Template.CBClass");
                                            receiveStruct = GenerateStruct(text_, "Receive");

                                            string fileText = string.Format(body, _selectRequestName, url, postStruct, receiveStruct, string.IsNullOrEmpty(postStruct) ? postStruct : "Post postData_", null == receiveStruct ? null : text_.StartsWith("[") ? "<Receive[]>" : "<Receive>", string.IsNullOrEmpty(postStruct) ? "null" : "JsonUtility.ToJson(postData_)");
                                            string fileName = string.Format("/CloudBread/Protocols/CloudBread.{0}.{1}.cs", _selectedRequest.method, _selectRequestName);

                                            CBToolEditor.SaveTextFileInProject(fileName, fileText);
                                            AssetDatabase.Refresh();
                                        }
                                    }
                                    catch (System.Exception e_)
                                    {
                                        Debug.Log(e_);
                                    }
                                });
                            }
                        }
                        GUILayout.EndHorizontal();

                        _classBodyScroll_rquestDataPos = GUILayout.BeginScrollView(_classBodyScroll_rquestDataPos, GUILayout.Height(100));
                        {
                            if (0 == _selectRequestMenuIndex)
                            {
                                _requestPostData = EditorGUILayout.TextArea(_requestPostData);
                            }
                            else
                            {
                                _requestHeaders = EditorGUILayout.TextArea(_requestHeaders);
                            }
                        }
                        GUILayout.EndScrollView();
                    }
                    GUILayout.EndVertical();
                }

                if (!string.IsNullOrEmpty(_receiveJson))
                {
                    _classBodyScroll_receiveJsonPos = GUILayout.BeginScrollView(_classBodyScroll_receiveJsonPos, GUILayout.Height(position.height * 0.2f));
                    {
                        EditorGUILayout.TextArea(_receiveJson);
                    }
                    GUILayout.EndScrollView();
                }

                if (!string.IsNullOrEmpty(_receiveStruct))
                {
                    _classBodyScroll_receiveStructPos = GUILayout.BeginScrollView(_classBodyScroll_receiveStructPos);
                    {
                        EditorGUILayout.TextArea(_receiveStruct);
                    }
                    GUILayout.EndScrollView();
                }
            }
            GUILayout.EndVertical();
        }
Esempio n. 6
0
        IEnumerator WWWProcess(string path_, string postData_, System.Action <WWW> completeCallback_, System.Action <string> errorCallback_)
        {
            WWW www = null;

            if (null != postData_)
            {
                if (CBSetting.aseEnCyptUse)
                {
                    postData_ = string.Format(@"{{""{0}"": ""{1}""}}", _aseEncryptDefine, CBAuthentication.AES_encrypt(postData_));
                }
                www = new WWW(path_, System.Text.Encoding.UTF8.GetBytes(postData_), cbHeader);
            }
            else
            {
                www = new WWW(path_, cbForm);
            }

            while (!www.isDone)
            {
                yield return(null);
            }

            if (null != www.error)
            {
                if (null != errorCallback_)
                {
                    //if(!RetryRequest())
                    {
                        Debug.LogError(www.error);
                        errorCallback_(www.error);
                    }
                }
            }
            else
            {
                if (null != completeCallback_)
                {
                    completeCallback_(www);
                }
            }

            www.Dispose();
        }
Esempio n. 7
0
        // json 배열을 감싸는 리스트를 사용할것인가?
        //const string _listCover = @"{{ ""list"" : {0} }}";
        IEnumerator WWWRequest <T>(string path_, string postData_, System.Action <T[]> callback_, System.Action <string> errorCallback_ = null)
        {
            IEnumerator itor = WWWProcess(path_, postData_,
                                          delegate(WWW www)
            {
                if (null != callback_)
                {
                    string receiveText = www.text;
                    if (CBSetting.aseEnCyptUse && receiveText.Contains(_aseEncryptDefine))
                    {
                        receiveText = CBAuthentication.AES_decrypt(CBTool.GetElementValueFromJson(_aseEncryptDefine, receiveText));
                    }
                    try
                    {
                        // #ISSUE
                        // 배열[]이 바로 들어옴.
                        // 클래스에 입히기 위해 배열인 경우 맴버변수에 대한 선언이 필요함.
                        // ex) {"list" : 기존배열 }
                        // 위와 같이 감싸야함.
                        //string text = string.Format(_listCover, www.text);
                        //callback_(JsonUtility.FromJson<T>(text));

                        // 아니면 어쩌나..
                        // 파싱 후 리스트로..근데 항상 리스트로 넘어오나? -> 그렇다함.
                        string text   = receiveText.Remove(receiveText.Length - 2).Remove(0, 1);
                        string[] list = System.Text.RegularExpressions.Regex.Split(text, "},");
                        T[] tList     = new T[list.Length];
                        for (int i = 0; i < list.Length; ++i)
                        {
                            // }, 로 split시에 맨뒤에 있는 항목은 }가 없음.
                            // 그래서 www.text의 맨뒤에서 하나 더 제거한상태로 전체 객체가 뒤에 }가 없게 처리.
                            //tList[i] = JsonUtility.FromJson<T>(list[i].EndsWith("}") ? list[i] : list[i]+"}");
                            tList[i] = JsonUtility.FromJson <T>(list[i] + "}");
                        }
                        callback_(tList);
                    }
                    catch (System.Exception e)
                    {
                        string errorMessage = string.Format("{0}\nurl\n{1}\nwww.text\n{2}\n{3}", "ERROR : Json Parse.", www.url, www.text, e);
                        if (null != errorCallback_)
                        {
                            Debug.Log(errorMessage);
                            errorCallback_(errorMessage);
                        }
                    }
                }
                www.Dispose();
            },
                                          delegate(string text_)
            {
                if (null != errorCallback_)
                {
                    errorCallback_(text_);
                }
            }
                                          );

            while (itor.MoveNext())
            {
                yield return(null);
            }
        }