public async void runSDSSFields(double ra, double dec, double sr) { HttpClient client = new HttpClient(); client.BaseAddress = new Uri(KeyWords.casjobsREST + "contexts/" + datarelease + "/query"); NewSDSSFields newsdss = new NewSDSSFields(ra, dec, sr); String query = newsdss.getFieldsArrayQuery(); StringContent content = new StringContent(this.getJsonContent(query, casjobstaskname)); content.Headers.ContentType = new MediaTypeHeaderValue(KeyWords.contentJson); client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue(KeyWords.contentDataset)); System.IO.Stream stream = await client.PostAsync(client.BaseAddress, content).Result.Content.ReadAsStreamAsync(); BinaryFormatter formatter = new BinaryFormatter(); DataSet ds; try { ds = (DataSet)formatter.Deserialize(stream); } catch (Exception e) { throw new Exception(e.Message); } fieldArray = newsdss.FieldArray(ds); }
public HttpContent GetContent(DataSet ds) { var response = new HttpResponseMessage(); string SaveResult = ""; ExtraInfo.TryGetValue("SaveResult", out SaveResult); if (this.IsSuccess) { if (this.ExtraInfo["FormatFromUser"] != "html") { NewSDSSFields sf = new NewSDSSFields(); switch (positionType) { case "cone": DefaultCone cstest = new DefaultCone(); vot = cstest.ConeSearch(ds); response.Content = new StringContent(ToXML(vot), Encoding.UTF8, KeyWords.contentXML); if (SaveResult == "true") { response.Content.Headers.Add("Content-Disposition", "attachment;filename=\"result.xml\""); } break; case "FieldArray": response.Content = new StringContent(ToXML(sf.FieldArray(ds)), Encoding.UTF8, KeyWords.contentXML); if (SaveResult == "true") { response.Content.Headers.Add("Content-Disposition", "attachment;filename=\"result.xml\""); } break; case "FieldArrayRect": response.Content = new StringContent(ToXML(sf.FieldArrayRect(ds)), Encoding.UTF8, KeyWords.contentXML); if (SaveResult == "true") { response.Content.Headers.Add("Content-Disposition", "attachment;filename=\"result.xml\""); } break; case "ListOfFields": response.Content = new StringContent(ToXML(sf.ListOfFields(ds)), Encoding.UTF8, KeyWords.contentXML); if (SaveResult == "true") { response.Content.Headers.Add("Content-Disposition", "attachment;filename=\"result.xml\""); } break; case "UrlsOfFields": response.Content = new StringContent(ToXML(sf.UrlOfFields(ds)), Encoding.UTF8, KeyWords.contentXML); if (SaveResult == "true") { response.Content.Headers.Add("Content-Disposition", "attachment;filename=\"result.xml\""); } break; default: Action <Stream, HttpContent, TransportContext> WriteToStream = null; BinaryFormatter fmt; ds.RemotingFormat = SerializationFormat.Binary; fmt = new BinaryFormatter(); WriteToStream = (stream, foo, bar) => { fmt.Serialize(stream, ds); stream.Close(); }; response.Content = new PushStreamContent(WriteToStream, new MediaTypeHeaderValue((KeyWords.contentDataset))); break; } } else { response.Content = new StringContent(getHtmlContent(ds)); } } else // not IsSuccess { if (ExtraInfo["DoReturnHtml"].ToLower() == "true") { response.Content = new StringContent(getHtmlError(ErrorMessage)); } else { if (String.IsNullOrEmpty(TechnicalErrorInfo)) { response.Content = new StringContent(ErrorMessage); } else { response.Content = new StringContent(ErrorMessage + " \nTechnical Info:" + TechnicalErrorInfo); } } } return(response.Content); }