public async Task<CircleShape> GetCircleInfoAsync (CircleShape input) { HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create (new Uri (WebServiceAPI + "colors/random")); request.ContentType = "application/json"; request.Method = "GET"; using (WebResponse response = await request.GetResponseAsync ()) { using (StreamReader reader = new StreamReader (response.GetResponseStream ())) { try { var content = reader.ReadToEnd (); if (string.IsNullOrWhiteSpace (content)) { return input; } else { var doc = XDocument.Parse (content); return doc.Root.Descendants ("rgb") .Select (x => { int R = int.Parse (x.Element ("red").Value); int G = int.Parse (x.Element ("green").Value); int B = int.Parse (x.Element ("blue").Value); return new CircleShape () { Id = input.Id, FilledColor = Color.FromArgb (255, R, G, B), Center_X = input.Center_X, Center_Y = input.Center_Y, Radius = input.Radius }; }).FirstOrDefault () ?? input; } } catch { return input; } } } }
public async Task<ShapeBase> GeneralShapeRandom (int maxHeight, int maxWidth) { _maxHeight = maxHeight; _maxWidth = maxWidth; int shapeType = _randomSeed.Next (10); ShapeBase result = new CircleShape (); if (shapeType % 2 == 0) { result = new CircleShape (); _shapeID++; result.Id = _shapeID; } else { result = await GetSquareShapesFromQueue (); } result.Center_X = result.Center_X == 0 ? _randomSeed.Next (10, maxWidth) : result.Center_X; result.Center_Y = result.Center_Y == 0 ? _randomSeed.Next (10, maxHeight) : result.Center_Y; result.Radius = result.Radius == 0 ? _randomSeed.Next (10, (maxWidth + maxHeight) / 8) : result.Radius; result.GenerateColor (); return result; }