예제 #1
0
        public IHttpActionResult GetStatus()
        {
            try
            {
                var request = Context.AuthenticatedRequest;
                var siteId  = request.GetQueryInt("siteId");
                var ruleId  = request.GetQueryInt("ruleId");

                if (!request.IsAdminLoggin ||
                    !request.AdminPermissions.HasSitePermissions(siteId, Utils.PluginId))
                {
                    return(Unauthorized());
                }

                var guid  = request.GetPostString("guid");
                var cache = ProgressCache.GetCache(guid);

                var percentage = cache.TotalCount == 0 ? string.Empty : (cache.SuccessCount / cache.TotalCount).ToString("0.00%");

                return(Ok(new
                {
                    Value = cache,
                    Percentage = percentage
                }));
            }
            catch (Exception ex)
            {
                return(InternalServerError(ex));
            }
        }
예제 #2
0
        public async Task PaginateServices(string apiBaseUrl, string id, ServiceProcessorAsync processor, WebServiceReader webServiceReader, string parameters = "", int?totalPagesOverride = null)
        {
            int pageNo     = 0;
            int totalPages = totalPagesOverride ?? 1;

            while (pageNo < totalPages)
            {
                pageNo++;

                string serviceUrl = apiBaseUrl + "/services/";

                serviceUrl += parameters;

                if (!serviceUrl.Contains("?"))
                {
                    serviceUrl += "?";
                }
                else
                {
                    serviceUrl += "&";
                }

                WebServiceResponse serviceList = await webServiceReader.ConvertToDynamic(serviceUrl + "page=" + pageNo);

                try
                {
                    if (serviceList == null)
                    {
                        continue;
                    }
                    int tmp = Convert.ToInt32(serviceList.Data.totalPages);
                    if (!totalPagesOverride.HasValue || tmp < totalPages)
                    {
                        totalPages = tmp;
                    }
                }
                catch
                {
                    //if this isn't here we will ignore it and just paginate the first page. This issue will be reported upon in pagination
                }

                if (!await processor(serviceList.Data, totalPages, serviceList.HashCode))
                {
                    break;
                }

                ProgressCache.Update(id, pageNo, totalPages);
            }
        }
예제 #3
0
 public static Progress Progress(string id)
 {
     return(ProgressCache.Get(id));
 }