/// <summary> /// /// </summary> /// <param name="filePaths"></param> /// <param name="options"></param> /// <param name="referenceFilePaths"></param> /// <returns></returns> public Quote GenerateQuote(String[] filePaths, QuoteOptions options, String[] referenceFilePaths = null) { if (this.Client == null) { throw new InvalidOperationException("The service does not have an APIClient to communicate with"); } return(this.Client.GenerateQuote(this, filePaths, options, referenceFilePaths)); }
/// <summary> /// Return a ProductsQuote given a list of products /// </summary> /// <param name="products">A collection of products</param> /// <param name="options"></param> /// <param name="referenceFiles"></param> /// <returns></returns> public Quote GenerateQuote(IEnumerable <Product> products, QuoteOptions options, IEnumerable <File> referenceFiles = null) { if (this.Client == null) { throw new InvalidOperationException("The service does not have an APIClient to communicate with"); } return(this.Client.GenerateQuote(this, products, options, referenceFiles)); }
/// <summary> /// This interface is used to generate a quote from Files that were uploading using the Add File API. A quote can contain multiple projects. /// </summary> /// <param name="service"></param> /// <param name="files"></param> /// <param name="options"></param> /// <param name="referenceFiles">If null, will not use reference files</param> /// <returns></returns> public Quote GenerateQuote(Service service, IEnumerable<File> files, QuoteOptions options, IEnumerable<File> referenceFiles = null) { // Check the service if (service == null) { throw new ArgumentNullException("service", "Must specify a Service to generate a quote"); } if (!service.AcceptsFiles) { throw new ArgumentException("This service does not accept files. Please use GenerateQuote with Products", "service"); } if (options == null) { throw new ArgumentNullException("options", "Must specify options to generate a quote"); } options.Initialize(this, service); // Now Generate the Quote based on the uplaoded files Quote result = null; Uri uri = new Uri(this.EndPoint.AbsoluteUri + "api/quote/generate"); HttpWebRequest request = this.CreateRequestPOST(uri, new GenerateQuote(files, options, referenceFiles)); using (HttpWebResponse response = request.GetResponseWithoutException() as HttpWebResponse) { if (response.StatusCode == HttpStatusCode.Created) { using (StreamReader reader = new StreamReader(response.GetResponseStream())) { XDocument document = XDocument.Load(reader); result = new Quote(document.Element("Quote"), this); } } else { this.HandleError(response); } } return result; }
/// <summary> /// This interface is used to generate a quote from file URLs that will be loaded. A quote can contain multiple projects. /// </summary> /// <param name="service"></param> /// <param name="fileURLs"></param> /// <param name="fileNames"></param> /// <param name="options"></param> /// <param name="referenceFiles">If null, will not use reference files</param> /// <returns></returns> public Quote GenerateQuote(Service service, Uri[] fileURLs, String[] fileNames, QuoteOptions options, IEnumerable<File> referenceFiles = null) { // Check the service if (service == null) { throw new ArgumentNullException("service", "Must specify a Service to generate a quote"); } if (fileURLs == null || fileNames == null) { throw new ArgumentNullException("files", "Must specify the fileURLs and fileNames"); } if (!service.AcceptsFiles) { throw new ArgumentException("This service does not accept files. Please use GenerateQuote with Products", "service"); } if (options == null) { throw new ArgumentNullException("options", "Must specify options to generate a quote"); } options.Initialize(this, service); // Check that the file extensions are valid foreach (String fileName in fileNames) { if (!service.AcceptsExtension(Path.GetExtension(fileName))) { throw new ArgumentOutOfRangeException("fileNames", fileName, "Service does not accept files with this extension"); } } // Upload the files List<File> addedFiles = new List<File>(); for (int i = 0; i < fileNames.Length && i < fileURLs.Length; i++) { addedFiles.Add(this.AddFile(options.SourceLanguage.LanguageCode, fileNames[i], fileURLs[i])); } return this.GenerateQuote(service, addedFiles, options, referenceFiles); }
/// <summary> /// This interface is used to generate a quote from file paths that will be loaded. A quote can contain multiple projects. /// </summary> /// <param name="service"></param> /// <param name="filePaths"></param> /// <param name="options"></param> /// <param name="referenceFilePaths">If null, will not use reference files</param> /// <returns></returns> public Quote GenerateQuote(Service service, string[] filePaths, QuoteOptions options, string[] referenceFilePaths = null) { // Check the service if (service == null) { throw new ArgumentNullException("service", "Must specify a Service to generate a quote"); } if (!service.AcceptsFiles) { throw new ArgumentException("This service does not accept files. Please use GenerateQuote with Products", "service"); } if (options == null) { throw new ArgumentNullException("options", "Must specify options to generate a quote"); } options.Initialize(this, service); // Check that the file extensions are valid foreach (String filePath in filePaths) { if (!service.AcceptsExtension(Path.GetExtension(filePath))) { throw new ArgumentOutOfRangeException("filePaths", filePath, "Service does not accept files with this extension"); } } // Upload the files List<File> addedFiles = new List<File>(); foreach (String filePath in filePaths) { addedFiles.Add(this.AddFile(options.SourceLanguage.LanguageCode, filePath)); } // Upload the reference List<File> referenceFiles = null; if (referenceFilePaths != null) { referenceFiles = new List<File>(); foreach (String referenceFilePath in referenceFilePaths) { referenceFiles.Add(this.AddFile(options.SourceLanguage.LanguageCode, referenceFilePath)); } } return this.GenerateQuote(service, addedFiles, options, referenceFiles); }
/// <summary> /// Return a ProductsQuote given a list of products /// </summary> /// <param name="products">A collection of products</param> /// <param name="options"></param> /// <param name="referenceFiles"></param> /// <returns></returns> public Quote GenerateQuote(IEnumerable<Product> products, QuoteOptions options, IEnumerable<File> referenceFiles = null) { if (this.Client == null) { throw new InvalidOperationException("The service does not have an APIClient to communicate with"); } return this.Client.GenerateQuote(this, products, options, referenceFiles); }
/// <summary> /// /// </summary> /// <param name="filePaths"></param> /// <param name="options"></param> /// <param name="referenceFilePaths"></param> /// <returns></returns> public Quote GenerateQuote(String[] filePaths, QuoteOptions options, String[] referenceFilePaths = null) { if (this.Client == null) { throw new InvalidOperationException("The service does not have an APIClient to communicate with"); } return this.Client.GenerateQuote(this, filePaths, options, referenceFilePaths); }