コード例 #1
0
        public static Http.Operation DownLoadBean(string _uuid, OnSuccessFinishDelegate _onFinish, OnErrorDelegate _onError)
        {
            string uri = Settings.fangs_domain + "/storage/pullstring";

            Log.Debug("HttpMgr", "DownloadBean: {0}", uri);
            Dictionary <string, object> paramAry = new Dictionary <string, object>(0);

            paramAry.Add("bucket", HttpMgr.Base64Encode(Settings.beans_bucket));
            paramAry.Add("key", HttpMgr.Base64Encode(_uuid));
            Http.Operation operation = http.AsyncPOST(uri, paramAry, (_data) =>
            {
                Log.Debug("HttpMgr", "DownloadBean Finish: {0}", uri);
                JSONNode json = JSON.Parse(System.Text.Encoding.UTF8.GetString(_data));

                string bean = HttpMgr.Base64Decode(json["data"]["value"].Value);
                File.WriteAllText(Path.Combine(beansPath, _uuid + ".json"), bean);
                _onFinish();
            }, (_err) =>
            {
                Log.Error("HttpMgr", _err);
                _onError(_err.errmessage);
            });

            return(operation);
        }
コード例 #2
0
        public static void DownloadManifest(OnSuccessFinishDelegate _onFinish, OnErrorDelegate _onError)
        {
            string uri = Settings.fangs_domain + "/storage/list";

            Log.Debug("HttpMgr", "DownloadMinifest: {0}", uri);
            Dictionary <string, object> paramAry = new Dictionary <string, object>(0);

            paramAry.Add("bucket", HttpMgr.Base64Encode(Settings.beans_bucket));
            paramAry.Add("sort", HttpMgr.Base64Encode("time"));
            paramAry.Add("from", 0);
            paramAry.Add("to", 32);
            Http.Operation operation = http.AsyncPOST(uri, paramAry, (_data) =>
            {
                Log.Debug("HttpMgr", "DownloadMinifest Finish: {0}", uri);
                // parse the response
                JSONNode json = JSON.Parse(System.Text.Encoding.UTF8.GetString(_data));
                int errcode   = json["errcode"].AsInt;
                // 0 is OK
                if (0 != errcode)
                {
                    _onError(string.Format("Download manifest has error, the errorcode is {0}", errcode));
                    return;
                }

                // take all the guid of bean and put them to a array.
                int count      = json["data"]["keys:length"].AsInt;
                string[] beans = new string[count];
                for (int i = 0; i < count; ++i)
                {
                    string field = string.Format("keys:{0}", i);
                    string value = json["data"][field].Value;
                    beans[i]     = Base64Decode(value);
                }
                // save the minifest file with beans
                JSONArray beanAry = new JSONArray();
                foreach (string bean in beans)
                {
                    beanAry.Add(bean);
                }
                JSONClass root = new JSONClass();
                root.Add("beans", beanAry);
                string manifestJson = root.ToJSON(0);

                File.WriteAllText(Path.Combine(beansPath, "manifest.txt"), manifestJson);
                _onFinish();
            }, (_err) =>
            {
                Log.Error("HttpMgr", _err);
                _onError(_err.errmessage);
            });
        }