/// <summary>
        /// Network snapshots async.
        /// </summary>
        /// <returns>The snapshots async.</returns>
        /// <param name="limit">Limit.</param>
        /// <param name="offset">Offset.</param>
        /// <param name="assetId">Asset identifier.</param>
        /// <param name="order">Order.</param>
        /// <param name="isAuth">If set to <c>true</c> is auth.</param>
        public async Task <List <Snapshot> > NetworkSnapshotsAsync(int limit, string offset, string assetId, string order, bool isAuth)
        {
            string req = "/network/snapshots";

            req += "?limit=" + limit.ToString();

            string reqForAuthToken = req;

            req             += "&offset=" + offset;
            reqForAuthToken += "&offset=" + HttpUtility.UrlEncode(offset);

            req += "&asset=" + assetId;
            req += "&order=" + order;

            reqForAuthToken += "&asset=" + assetId;
            reqForAuthToken += "&order=" + order;



            var request = new RestRequest(req, Method.GET);

            request.AddHeader("Content-Type", "application/json");
            request.AddHeader("Content-length", "0");

            if (isAuth)
            {
                string token = MixinUtils.GenJwtAuthCode("GET", reqForAuthToken, "", userConfig.ClientId, userConfig.SessionId, priKey);

                var jwtAuth = new RestSharp.Authenticators.JwtAuthenticator(token);
                jwtAuth.Authenticate(client, request);
            }

            var cts      = new CancellationTokenSource(ReadTimeout);
            var response = await client.ExecuteTaskAsync <Data>(request, cts.Token);

            if (null == response.Data.data)
            {
                var errorinfo = JsonConvert.DeserializeObject <MixinError>(response.Content);
                throw new MixinException(errorinfo);
            }

            var rz = JsonConvert.DeserializeObject <List <Snapshot> >(response.Data.data);

            return(rz);
        }
Beispiel #2
0
        /// <summary>
        /// Network snapshots async.
        /// </summary>
        /// <returns>The snapshots async.</returns>
        /// <param name="limit">Limit.</param>
        /// <param name="offset">Offset.</param>
        /// <param name="assetId">Asset identifier.</param>
        /// <param name="order">Order.</param>
        /// <param name="isAuth">If set to <c>true</c> is auth.</param>
        public async Task <List <Snapshot> > NetworkSnapshotsAsync(int limit, string offset, string assetId, string order, bool isAuth)
        {
            string req = "/network/snapshots";

            var request = new RestRequest(req, Method.GET);

            request.AddHeader("Content-Type", "application/json");
            request.AddHeader("Content-length", "0");
            request.AddParameter("limit", limit, ParameterType.QueryString);
            request.AddParameter("offset", offset, ParameterType.QueryString);
            if (!string.IsNullOrEmpty(assetId))
            {
                request.AddParameter("asset", assetId);
            }
            if (!string.IsNullOrEmpty(order))
            {
                request.AddParameter("order", order);
            }

            if (isAuth)
            {
                string token = MixinUtils.GenJwtAuthCode("GET", req, "", userConfig.ClientId, userConfig.SessionId, priKey);
                System.Console.WriteLine("token:" + token);

                var jwtAuth = new RestSharp.Authenticators.JwtAuthenticator(token);
                jwtAuth.Authenticate(client, request);
            }

            var cts      = new CancellationTokenSource(ReadTimeout);
            var response = await client.ExecuteTaskAsync <Data>(request, cts.Token);

            if (null == response.Data.data)
            {
                var errorinfo = JsonConvert.DeserializeObject <MixinError>(response.Content);
                throw new MixinException(errorinfo);
            }

            var rz = JsonConvert.DeserializeObject <List <Snapshot> >(response.Data.data);

            return(rz);
        }
 private string GenEncrypedPin(string pin)
 {
     return(MixinUtils.GenEncrypedPin(pin, userConfig.PinToken, userConfig.SessionId, rsaParameters, getIterator()));
 }
 private string GenPostJwtToken(string uri, string body)
 {
     return(MixinUtils.GenJwtAuthCode("POST", uri, body, userConfig.ClientId, userConfig.SessionId, priKey));
 }