///<Summary>
 ///Get Space Versions
 ///</Summary>
 public VersionList GetSpaceVersions(Project project, string id)
 {
     string spaceVersionJson = this.GetRequest("projects/" + project.id + "/spaces/" + id + "/versions");
     VersionList versions = JsonConvert.DeserializeObject<VersionList>(spaceVersionJson);
     return versions;
 }
 public string UploadModel(Project project, string filePath, string fileName)
 {
     string response = this.UploadFile("projects/" + project.id + "/models", filePath, fileName);
     return response;
 }
 ///<Summary>
 ///Create Space
 ///</Summary>
 public Space CreateSpace(Project project, Space parentSpace, string name)
 {
     string spaceData = "{\"name\": \"" + name + "\"}";
     string spaceJson = this.PostRequest("projects/" + project.id + "/spaces/" + parentSpace.id + "/subspaces", spaceData);
     Space space = JsonConvert.DeserializeObject<Space>(spaceJson);
     return space;
 }
 ///<Summary>
 ///
 ///</Summary>
 public Project SetProjectDescription(Project project, string description)
 {
     string projectData = "{\"description\": \"" + description + "\"}";
     string projectJson = this.PutRequest("projects/" + project.id, projectData);
     Project setProject = JsonConvert.DeserializeObject<Project>(projectJson);
     return setProject;
 }
 ///<Summary>
 ///
 ///</Summary>
 public Space SetSpace(Project project, Space space)
 {
     string spaceData = JsonConvert.SerializeObject(space);
     string spaceJson = this.PutRequest("projects/" + project.id + "/spaces/" + space.id, spaceData);
     Space setSpace = JsonConvert.DeserializeObject<Space>(spaceJson);
     return setSpace;
 }
 public string SetModel(Project project, Model model, string filePath, string fileName)
 {
     string response = this.UploadFile("projects/" + project.id + "/models/" + model.id, filePath, fileName);
     return response;
 }
 ///<Summary>
 ///
 ///</Summary>
 public MetaModel SetModelReference(Project project, Space space, MetaModel modelReference)
 {
     string modelReferenceData = JsonConvert.SerializeObject(modelReference);
     string modelReferenceJson = this.PostRequest("projects/" + project.id + "/spaces/" + space.id + "/metamodels/" + modelReference.id, modelReferenceData);
     MetaModel setModelReference = JsonConvert.DeserializeObject<MetaModel>(modelReferenceJson);
     return setModelReference;
 }
 ///<Summary>
 ///Get Model Details By Type : Right now, only "original", "prc", "json", "bin" are supported
 ///</Summary>
 public Model GetModelDetails(Project project, string id, string type)
 {
     string modelJson = this.GetRequest("projects/" + project.id + "/models/" + id + "/data?format=" + type);
     Model model = JsonConvert.DeserializeObject<Model>(modelJson);
     return model;
 }
 ///<Summary>
 ///Get Model Reference Details
 ///</Summary>
 public MetaModel GetModelReferenceDetails(Project project, Space space, string id)
 {
     string modelReferenceJson = this.GetRequest("projects/" + project.id + "/spaces/" + space.id + "/metamodels/" + id);
     MetaModel modelReference = JsonConvert.DeserializeObject<MetaModel>(modelReferenceJson);
     return modelReference;
 }
 ///<Summary>
 ///Download Model From Project, returns the full url for the file
 ///</Summary>
 public string DownloadModel(Project project, string id, string fileName, string path, string modelType)
 {
     Model model = this.GetModelDetails(project, id);
     string url = this.url + "projects/" + project.id + "/models/" + model.id + "/data?format=" + modelType;
     this.DownloadFile(path, fileName, url);
     return url;
 }
 ///<Summary>
 ///Download Model From Space
 ///</Summary>
 public string DownloadModel(Project project, Space space, string id, string path, string fileName)
 {
     return null;
 }
 ///<Summary>
 ///Delete Space
 ///</Summary>
 public void DeleteSpace(Project project, string id)
 {
     this.DeleteRequest("projects/" + project.id + "/spaces/" + id);
 }
 ///<Summary>
 ///Delete Model Reference
 ///</Summary>
 public void DeleteModelReference(Project project, Space space, string id)
 {
     this.DeleteRequest("projects/" + project.id + "/spaces/" + space.id + "/metamodels/" + id);
 }
 ///<Summary>
 ///Delete Model
 ///</Summary>
 public void DeleteModel(Project project, string id)
 {
     this.DeleteRequest("projects/" + project.id + "/models/" + id);
 }
 ///<Summary>
 ///Get SubSpace
 ///</Summary>
 public Space GetSubSpace(Project project, Space parent, string id)
 {
     string spaceJson = this.GetRequest("projects/" + project.id + "/spaces/" + parent.id + "/subspaces/" + id);
     Space space = JsonConvert.DeserializeObject<Space>(spaceJson);
     return space;
 }
 ///<Summary>
 ///Get Models References in Space
 ///</Summary>
 public MetaModelList GetModelReferencesDetails(Project project, Space space)
 {
     string modelReferenceJson = this.GetRequest("projects/" + project.id + "/spaces/" + space.id + "/metamodels");
     MetaModelList modelReferences = JsonConvert.DeserializeObject<MetaModelList>(modelReferenceJson);
     return modelReferences;
 }
 ///<Summary>
 ///Get SubSpaces By Parent ID
 ///</Summary>
 public SubSpaceList GetSubSpaces(Project project, Space parent)
 {
     string spaceJson = this.GetRequest("projects/" + project.id + "/spaces/" + parent.id + "/subspaces");
     SubSpaceList descendants = JsonConvert.DeserializeObject<SubSpaceList>(spaceJson);
     return descendants;
 }
 ///<Summary>
 ///Get Details of Models in Project
 ///</Summary>
 public ModelList GetModels(Project project)
 {
     string modelJson = this.GetRequest("projects/" + project.id + "/models");
     ModelList models = JsonConvert.DeserializeObject<ModelList>(modelJson);
     return models;
 }
        public Model SetModelAndVersion(Project project, Model model, string message, string modelFileName, string modelPath, string coverImageName, string coverImagePath)
        {
            // Read model file data
            FileStream modelFs = new FileStream(modelPath, FileMode.Open, FileAccess.Read);
            byte[] modelData = new byte[modelFs.Length];
            modelFs.Read(modelData, 0, modelData.Length);
            modelFs.Close();

            // Read coverImage data
            FileStream imageFs = new FileStream(coverImagePath, FileMode.Open, FileAccess.Read);
            byte[] imageData = new byte[imageFs.Length];
            imageFs.Read(imageData, 0, imageData.Length);
            imageFs.Close();

            // Generate post objects
            Dictionary<string, object> postParameters = new Dictionary<string, object>();
            postParameters.Add("message", message);
            postParameters.Add("file", new FileParameter(modelData, modelFileName));
            postParameters.Add("cover_img", new FileParameter(imageData, coverImageName));

            //make the request
            String modelJson = this.PostMultiPartFormDataPostRequest("projects/" + project.id + "/models/"+model.id, postParameters);

            NewModel returnModel = JsonConvert.DeserializeObject<NewModel>(modelJson);
            return returnModel.model;
        }
 public Version getModelVersion(Project project, Model model, string id)
 {
     string versionJson = this.GetRequest("projects/" + project.id + "/models/" + model.id + "/versions/"+id);
     Version version = JsonConvert.DeserializeObject<Version>(versionJson);
     return version;
 }
 ///<Summary>
 ///
 ///</Summary>
 public Project SetProject(Project project)
 {
     string projectData = JsonConvert.SerializeObject(project);
     string projectJson = this.PutRequest("projects/" + project.id, projectData);
     Project setProject = JsonConvert.DeserializeObject<Project>(projectJson);
     return setProject;
 }
 ///<Summary>
 ///Get Model Versions
 ///</Summary>
 public VersionList GetModelVersions(Project project, string id)
 {
     string versionListJson = this.GetRequest("projects/" + project.id + "/models/" + id + "/versions");
     VersionList versions = JsonConvert.DeserializeObject<VersionList>(versionListJson);
     return versions;
 }
        /*

         * Set

        */
        ///<Summary>
        ///TODO Set Project Name, Description
        ///</Summary>
        public Project SetProjectName(Project project, string name)
        {
            string projectData = "{\"name\": \"" + name + "\"}";
            string projectJson = this.PutRequest("projects/" + project.id, projectData);
            Project setProject = JsonConvert.DeserializeObject<Project>(projectJson);
            return setProject;
        }
 ///<Summary>
 ///Get Root Space
 ///</Summary>
 public Space GetRootSpace(Project project)
 {
     SpaceList spaceList = this.GetSpaces(project);
     foreach (Space space in spaceList.spaces)
     {
         if (this.IsRootSpace(space))
         {
             return space;
         }
     }
     return spaceList.spaces[0];
 }
 ///<Summary>
 ///TODO Set Space - Name, Transformation Matrix
 ///</Summary>
 public Space SetSpaceName(Project project, Space space, string name)
 {
     string spaceData = "{\"name\": \"" + name + "\"}";
     string spaceJson = this.PutRequest("projects/" + project.id + "/spaces/" + space.id, spaceData);
     Space setSpace = JsonConvert.DeserializeObject<Space>(spaceJson);
     return setSpace;
 }
 ///<Summary>
 /// Get All Spaces
 ///</Summary>
 public SpaceList GetSpaces(Project project)
 {
     string spaceJson = this.GetRequest("projects/" + project.id + "/spaces");
     SpaceList spaces = JsonConvert.DeserializeObject<SpaceList>(spaceJson);
     return spaces;
 }
 public string UploadModel(Project project, Space space, string filePath, string fileName)
 {
     string response = this.UploadFile("projects/" + project.id + "/models?spaceId=" + space.id, filePath, fileName);
     return response;
 }
 ///<Summary>
 ///Create a Model Reference (Metamodel) to a Model
 ///</Summary>
 public MetaModel CreateModelReference(Project project, Space space, Model model)
 {
     string modelData = "{\"modelId\": \"" + model.id + "\"}";
     string modelJson = this.PostRequest("projects/" + project.id + "/spaces/" + space.id + "/metamodels", modelData);
     MetaModel modelReference = JsonConvert.DeserializeObject<MetaModel>(modelJson);
     return modelReference;
 }