예제 #1
0
        public static IEnumerable <Scan> GetScans(CxRestContext ctx, CancellationToken token,
                                                  ScanStatus specificStatus)
        {
            try
            {
                String url = null;

                if (specificStatus != ScanStatus.All)
                {
                    url = CxRestContext.MakeUrl(ctx.Url, URL_SUFFIX, new Dictionary <string, string>()
                    {
                        { "scanStatus", specificStatus.ToString() }
                    }
                                                );
                }
                else
                {
                    url = CxRestContext.MakeUrl(ctx.Url, URL_SUFFIX);
                }
                using (var client = ctx.Json.CreateSastClient())
                {
                    using (var scans = client.GetAsync(url, token).Result)
                    {
                        if (token.IsCancellationRequested)
                        {
                            return(null);
                        }

                        if (!scans.IsSuccessStatusCode)
                        {
                            throw new InvalidOperationException(scans.ReasonPhrase);
                        }

                        using (var sr = new StreamReader
                                            (scans.Content.ReadAsStreamAsync().Result))
                            using (var jtr = new JsonTextReader(sr))
                            {
                                JToken jt = JToken.Load(jtr);
                                return(new ScansReader(jt));
                            }
                    }
                }
            }
            catch (HttpRequestException hex)
            {
                _log.Error("Communication error.", hex);
                throw hex;
            }
        }
예제 #2
0
 private void SetScannerStatus(ScanStatus newStatus)
 {
     logger.Trace("Scanner status set to {0}", newStatus.ToString());
     scanTask.Status = newStatus;
 }