コード例 #1
0
        private void CmdListMy(string[] args)
        {
            PolyListUserAssetsRequest req;

            if (args.Length > 0 && args[0] == "newest")
            {
                // Default list request (newest).
                req = PolyListUserAssetsRequest.MyNewest();
            }
            else
            {
                // Custom list request.
                req = new PolyListUserAssetsRequest();
            }
            // Mutate the request according to parameters.
            req.visibility = GetEnumOpt(args, "-v", req.visibility);
            req.orderBy    = GetEnumOpt(args, "-o", req.orderBy);
            req.pageSize   = GetIntOpt(args, "-p", req.pageSize);
            req.pageToken  = GetOpt(args, "--pt", req.pageToken);
            // FormatFilter is weird because it's nullable, so we have to test before trying to parse:
            if (HasOpt(args, "-f"))
            {
                req.formatFilter = GetEnumOpt(args, "-f", PolyFormatFilter.BLOCKS /* not used */);
            }

            if (HasOpt(args, "--dry"))
            {
                // Dry run mode.
                PrintLn(req.ToString());
                return;
            }

            // Send the request.
            hasRunListCommand = true;
            PrintLn("Sending listmy request... Please wait.");
            PolyApi.ListUserAssets(req, (PolyStatusOr <PolyListAssetsResult> res) => {
                if (!res.Ok)
                {
                    PrintLn("Request ERROR: " + res.Status);
                    return;
                }
                PrintLn("Request SUCCESS.");
                currentResults = res.Value.assets;
                CmdShow(new string[] {});
            });
        }
コード例 #2
0
        /// <summary>
        /// Starts a new request. If there is already an existing request in progress, it will be cancelled.
        /// </summary>
        /// <param name="request">The request parameters; can be either a ListAssetsRequest or
        /// a PolyListUserAssetsRequest.</param>
        /// <param name="callback"> The callback to invoke when the request finishes.</param>
        private void StartRequest(PolyRequest request, Action <PolyStatusOr <PolyListAssetsResult> > callback)
        {
            int thisQueryId = PrepareForNewQuery(); // for the closure below.

            currentRequest = request;

            if (request is PolyListAssetsRequest)
            {
                PolyListAssetsRequest listAssetsRequest = request as PolyListAssetsRequest;
                PolyApi.ListAssets(listAssetsRequest, (PolyStatusOr <PolyListAssetsResult> result) => {
                    // Only process result if this is indeed the most recent query that we issued.
                    // If we have issued another query since (in which case thisQueryId < queryId),
                    // then ignore the result.
                    if (thisQueryId == queryId && callback != null)
                    {
                        callback(result);
                    }
                });
            }
            else if (request is PolyListUserAssetsRequest)
            {
                PolyListUserAssetsRequest listUserAssetsRequest = request as PolyListUserAssetsRequest;
                PolyApi.ListUserAssets(listUserAssetsRequest, (PolyStatusOr <PolyListAssetsResult> result) => {
                    if (thisQueryId == queryId && callback != null)
                    {
                        callback(result);
                    }
                });
            }
            else if (request is PolyListLikedAssetsRequest)
            {
                PolyListLikedAssetsRequest listLikedAssetsRequest = request as PolyListLikedAssetsRequest;
                PolyApi.ListLikedAssets(listLikedAssetsRequest, (PolyStatusOr <PolyListAssetsResult> result) => {
                    if (thisQueryId == queryId && callback != null)
                    {
                        callback(result);
                    }
                });
            }
            else
            {
                Debug.LogError("Request failed. Must be either a PolyListAssetsRequest or PolyListUserAssetsRequest");
            }
        }