/// <summary> /// Adds a new calendar to project file. Adds a new calendar to project file. /// </summary> /// <param name="name"></param> /// <param name="fileName"></param> /// <param name="storage"></param> /// <param name="folder"></param> /// <param name="body"></param> /// <returns></returns> public CalendarItemResponse PostProjectCalendar (string name, string fileName, string storage, string folder, Calendar body) { // create path and map variables var ResourcePath = "/tasks/{name}/calendars/?appSid={appSid}&fileName={fileName}&storage={storage}&folder={folder}".Replace("{format}","json"); ResourcePath = Regex.Replace(ResourcePath, "\\*", "").Replace("&", "&").Replace("/?", "?").Replace("toFormat={toFormat}", "format={format}"); // query params var queryParams = new Dictionary<String, String>(); var headerParams = new Dictionary<String, String>(); var formParams = new Dictionary<String, object>(); // verify required params are set if (name == null || body == null ) { throw new ApiException(400, "missing required params"); } if (name == null){ ResourcePath = Regex.Replace(ResourcePath, @"([&?])name=", ""); }else{ ResourcePath = ResourcePath.Replace("{" + "name" + "}", apiInvoker.ToPathValue(name)); } if (fileName == null){ ResourcePath = Regex.Replace(ResourcePath, @"([&?])fileName=", ""); }else{ ResourcePath = ResourcePath.Replace("{" + "fileName" + "}", apiInvoker.ToPathValue(fileName)); } if (storage == null){ ResourcePath = Regex.Replace(ResourcePath, @"([&?])storage=", ""); }else{ ResourcePath = ResourcePath.Replace("{" + "storage" + "}", apiInvoker.ToPathValue(storage)); } if (folder == null){ ResourcePath = Regex.Replace(ResourcePath, @"([&?])folder=", ""); }else{ ResourcePath = ResourcePath.Replace("{" + "folder" + "}", apiInvoker.ToPathValue(folder)); } try { if (typeof(CalendarItemResponse) == typeof(ResponseMessage)) { var response = apiInvoker.invokeBinaryAPI(basePath, ResourcePath, "POST", queryParams, null, headerParams, formParams); return (CalendarItemResponse) ApiInvoker.deserialize(response, typeof(CalendarItemResponse)); } else { var response = apiInvoker.invokeAPI(basePath, ResourcePath, "POST", queryParams, body, headerParams, formParams); if(response != null){ return (CalendarItemResponse) ApiInvoker.deserialize(response, typeof(CalendarItemResponse)); } else { return null; } } } catch (ApiException ex) { if(ex.ErrorCode == 404) { return null; } else { throw ex; } } }
public void TestPostProjectCalendar() { TasksApi target = new TasksApi(APIKEY, APPSID, BASEPATH); StorageApi storageApi = new StorageApi(APIKEY, APPSID, BASEPATH); string name = "sample-project.mpp"; string fileName = null; string storage = null; string folder = null; Calendar body = new Calendar(); body.Name = "NewCalander"; body.Uid = 0; storageApi.PutCreate(name, null, null, System.IO.File.ReadAllBytes("\\temp\\tasks\\resources\\" + name)); CalendarItemResponse actual; actual = target.PostProjectCalendar(name, fileName, storage, folder, body); Assert.AreEqual("201", actual.Code); Assert.IsInstanceOfType(new CalendarItemResponse(), actual.GetType()); }