/// <summary> /// Prepare this Historics query. /// </summary> public void prepare() { if (isDeleted()) { throw new InvalidDataException("Cannot set the name of a deleted Historics query"); } if (m_playback_id.Length > 0) { throw new InvalidDataException("This Historics query has already been prepared"); } Dictionary <string, string> parameters = new Dictionary <string, string>(); parameters.Add("hash", m_stream_hash); parameters.Add("start", Utils.DateTimeToUnixTimestamp(m_start_date).ToString()); parameters.Add("end", Utils.DateTimeToUnixTimestamp(m_end_date).ToString()); parameters.Add("name", m_name); parameters.Add("sources", string.Join(",", m_sources.ToArray())); try { JSONdn res = m_user.callApi("historics/prepare", parameters); if (!res.has("id")) { throw new InvalidDataException("Prepared successfully but no playback ID in the response"); } m_playback_id = res.getStringVal("id"); if (!res.has("dpus")) { throw new InvalidDataException("Prepared successfully but no DPU cost in the response"); } m_dpus = res.getDoubleVal("dpus"); if (!res.has("availability")) { throw new InvalidDataException("Prepared successfully but no availability in the response"); } m_availability = new HistoricDataAvailability(new JSONdn(res.getJVal("availability"))); } catch (ApiException e) { // 400 = Missing or bad parameters. // 404 = Historics query not found. if (e.Code == 400 || e.Code == 404) { throw new InvalidDataException(e.Message); } throw new ApiException("Unexpected API response code: " + e.Code.ToString() + " " + e.Message); } // Update our data. reloadData(); }
/// <summary> /// Constructor. /// </summary> /// <param name="data">The JSON API response.</param> public Dpu(JSONdn data) { m_dpu = new Dictionary<string, DpuItem>(); foreach (string key in data.getKeys("detail")) { DpuItem item = new DpuItem(data.getIntVal("detail." + key + ".count"), data.getDoubleVal("detail." + key + ".dpu")); if (data.has("detail." + key + ".targets")) { JToken t = data.getJVal("detail." + key + ".targets"); foreach (string targetkey in data.getKeys("detail." + key + ".targets")) { JSONdn t2 = new JSONdn(t[targetkey]); item.addTarget(targetkey, new DpuItem(t2.getIntVal("count"), t2.getDoubleVal("dpu"))); } } m_dpu.Add(key, item); } m_total = data.getDoubleVal("dpu"); }
/// <summary> /// Send the CSDL to DataSift for compilation. /// </summary> public void compile() { // We must have some CSDL in order to compile the CSDL! if (m_csdl.Length == 0) { throw new InvalidDataException("Cannot compile an empty definition"); } try { Dictionary <string, string> parameters = new Dictionary <string, string>(); parameters.Add("csdl", m_csdl); JSONdn res = m_user.callApi("compile", parameters); if (!res.has("hash")) { throw new CompileFailedException("Compiled successfully but no hash in the response"); } m_hash = res.getStringVal("hash"); if (!res.has("created_at")) { throw new CompileFailedException("Compiled successfully but no created_at in the response"); } m_created_at = res.getDateTimeVal("created_at", "yyyy-MM-dd HH:mm:ss"); if (!res.has("dpu")) { throw new CompileFailedException("Compiled successfully but no DPU in the response"); } m_total_dpu = res.getDoubleVal("dpu"); } catch (ApiException e) { clearHash(); if (e.Code == 400) { throw new CompileFailedException(e.Message); } throw new CompileFailedException("Unexpected API response code: " + e.Code.ToString() + " " + e.Message); } }
/// <summary> /// Constructor. /// </summary> /// <param name="data">The JSON API response.</param> public Dpu(JSONdn data) { m_dpu = new Dictionary <string, DpuItem>(); foreach (string key in data.getKeys("detail")) { DpuItem item = new DpuItem(data.getIntVal("detail." + key + ".count"), data.getDoubleVal("detail." + key + ".dpu")); if (data.has("detail." + key + ".targets")) { JToken t = data.getJVal("detail." + key + ".targets"); foreach (string targetkey in data.getKeys("detail." + key + ".targets")) { JSONdn t2 = new JSONdn(t[targetkey]); item.addTarget(targetkey, new DpuItem(t2.getIntVal("count"), t2.getDoubleVal("dpu"))); } } m_dpu.Add(key, item); } m_total = data.getDoubleVal("dpu"); }
/// <summary> /// Initialise this object from teh data in a JSON object. /// </summary> /// <param name="data">The JSON object.</param> public void init(JSONdn data) { if (!data.has("id")) { throw new ApiException("No playback ID in the response"); } if (m_playback_id.Length > 0 && m_playback_id.CompareTo(data.getStringVal("id")) != 0) { throw new ApiException("Incorrect playback ID in the response"); } m_playback_id = data.getStringVal("id"); if (!data.has("definition_id")) { throw new ApiException("No definition hash in the response"); } m_stream_hash = data.getStringVal("definition_id"); if (!data.has("name")) { throw new ApiException("No name in the response"); } m_name = data.getStringVal("name"); if (!data.has("start")) { throw new ApiException("No start timestamp in the response"); } m_start_date = data.getDateTimeFromLongVal("start"); if (!data.has("end")) { throw new ApiException("No end timestamp in the response"); } m_end_date = data.getDateTimeFromLongVal("end"); if (!data.has("created_at")) { throw new ApiException("No created at timestamp in the response"); } m_created_at = data.getDateTimeFromLongVal("created_at"); if (!data.has("status")) { throw new ApiException("No status in the response"); } m_status = data.getStringVal("status"); if (!data.has("progress")) { throw new ApiException("No progress in the response"); } m_progress = data.getIntVal("progress"); if (!data.has("sources")) { throw new ApiException("No sources in the response"); } m_sources.Clear(); foreach (JToken source in data.getJVal("sources")) { m_sources.Add(source.ToString()); } if (!data.has("sample")) { throw new ApiException("No sample in the response"); } m_sample = data.getDoubleVal("sample"); }