/// <summary> /// /// </summary> /// <param name="unitCount"></param> /// <param name="options"></param> /// <returns></returns> public Estimate GetEstimate(Int32 unitCount, EstimateOptions options) { if (this.Client == null) { throw new InvalidOperationException("The service does not have an APIClient to communicate with"); } return(this.Client.GetEstimate(this, unitCount, options)); }
/// <summary> /// The Get Estimate API is used to get a rough estimate for a project based on the parameters listed below. /// It is useful for client applications that are capable of counting words and that want to give the end customer a rough estimate of how much a project will cost. /// Please note, the estimate will not be the same as the actual price if the onDemand word counting algorithm produces a different result than the client application. /// </summary> /// <param name="service"></param> /// <param name="unitCount"></param> /// <param name="options"></param> /// <returns></returns> public Estimate GetEstimate(Service service, Int32 unitCount, EstimateOptions options) { Estimate result = null; if (service == null) { throw new ArgumentNullException("service", "Must specify a Service to generate an estimate"); } if (options == null) { throw new ArgumentNullException("options", "Must specify estimate options to get an estimate"); } options.Initialize(this, service); String targetLanguagesCSV = String.Join(",", options.TargetLanguages.Select(p => p.LanguageCode).ToArray()); Uri uri = new Uri(this.EndPoint.AbsoluteUri + String.Format("api/estimate?service_id={0}&unit_count={1}¤cy={2}&source_lang={3}&target_lang={4}", service.ServiceID, unitCount, options.Currency, options.SourceLanguage, targetLanguagesCSV)); HttpWebRequest request = CreateRequestGET(uri); using (HttpWebResponse response = request.GetResponse() as HttpWebResponse) { if (response.StatusCode == HttpStatusCode.OK) { using (StreamReader reader = new StreamReader(response.GetResponseStream())) { XDocument document = XDocument.Load(reader); result = new Estimate(document.Element("Estimate"), this); } } else { this.HandleError(response); } } return result; }
/// <summary> /// /// </summary> /// <param name="unitCount"></param> /// <param name="options"></param> /// <returns></returns> public Estimate GetEstimate(Int32 unitCount, EstimateOptions options) { if (this.Client == null) { throw new InvalidOperationException("The service does not have an APIClient to communicate with"); } return this.Client.GetEstimate(this, unitCount, options); }