/// <summary> /// Updates the project information in place /// </summary> /// <param name="project"></param> public void UpdateProject(Project project) { Uri uri = new Uri(this.EndPoint.AbsoluteUri + "api/projects/" + project.ProjectID.ToString()); 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); project.UpdateFromXElement(document.Element("Project")); } } else { this.HandleError(response); } } }
/// <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> /// Returns information about a project. /// </summary> /// <param name="projectId"></param> /// <returns></returns> public Project GetProject(Int32 projectId) { Project result = null; Uri uri = new Uri(this.EndPoint.AbsoluteUri + "api/projects/" + projectId.ToString()); 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 Project(document.Element("Project"), this); } } else { this.HandleError(response); } } return result; }