/// <summary> /// /// </summary> /// <param name="projectName"></param> /// <param name="products"></param> /// <param name="options"></param> /// <param name="referenceFiles"></param> /// <returns></returns> public Project AddProject(String projectName, IEnumerable <Product> products, ProjectOptions 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.AddProject(projectName, this, products, options, referenceFiles)); }
/// <summary> /// Adds a new project to onDemand. Should be used in conjunction with Generate Quote to make a purchase. /// </summary> /// <param name="projectName"></param> /// <param name="service"></param> /// <param name="products"></param> /// <param name="options"></param> /// <param name="referenceFiles"></param> /// <returns></returns> public Project AddProject(String projectName, Service service, IEnumerable<Product> products, ProjectOptions options, IEnumerable<File> referenceFiles = null) { // Check the service if (service == null) { throw new ArgumentNullException("service", "Must specify a Service to add a project"); } // Check the service if (service == null) { throw new ArgumentNullException("service", "Must specify a Service to add a project"); } if (!service.AcceptsProducts) { throw new ArgumentException("This service does not accept projdcuts. Please use AddProject with files", "service"); } if (options == null) { throw new ArgumentNullException("options", "Must specify project options to add a project"); } if (options == null) { throw new ArgumentNullException("options", "Must specify project options to add a project"); } options.Initialize(this, service); Project result = null; Uri uri = new Uri(this.EndPoint.AbsoluteUri + "api/projects/add"); HttpWebRequest request = this.CreateRequestPOST(uri, new AddProject(projectName, products, 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 Project(document.Element("Project"), this); } } else { this.HandleError(response); } } return result; }
/// <summary> /// /// </summary> /// <param name="projectName"></param> /// <param name="products"></param> /// <param name="options"></param> /// <param name="referenceFiles"></param> /// <returns></returns> public Project AddProject(String projectName, IEnumerable<Product> products, ProjectOptions 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.AddProject(projectName, this, products, options, referenceFiles); }
/// <summary> /// Adds a new project to onDemand. Should be used in conjunction with Generate Quote to make a purchase. /// </summary> /// <param name="projectName"></param> /// <param name="service"></param> /// <param name="filePaths"></param> /// <param name="options"></param> /// <param name="referenceFilePaths"></param> /// <returns></returns> public Project AddProject(String projectName, Service service, String[] filePaths, ProjectOptions options, String[] referenceFilePaths = null) { // Check the service if (service == null) { throw new ArgumentNullException("service", "Must specify a Service to add a project"); } if (!service.AcceptsFiles) { throw new ArgumentException("This service does not accept files. Please use AddProject with Products", "service"); } if (options == null) { throw new ArgumentNullException("options", "Must specify project options to add a project"); } 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("fileNames", 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.AddProject(projectName, service, addedFiles, options, referenceFiles); }
/// <summary> /// /// </summary> /// <param name="projectName"></param> /// <param name="filePaths"></param> /// <param name="options"></param> /// <param name="referenceFilePaths"></param> /// <returns></returns> public Project AddProject(String projectName, String[] filePaths, ProjectOptions options, String[] referenceFilePaths = null) { if (this.Client == null) { throw new InvalidOperationException("The service does not have an APIClient to communicate with"); } return this.Client.AddProject(projectName, this, filePaths, options, referenceFilePaths); }