/// <summary> /// Creates child container under given parent container. /// </summary> /// <param name="childName">Name of Child container</param> /// <return>True if created successfully /// False otherwise</return> public Boolean createChildContainer(String childName) { try { byte[] buf = Encoding.UTF8.GetBytes( "{ \"metadata\" : { \"cTime\" : \"" + DateTime.Now.ToString() + "\" } }"); PutHTTPRequest request = new PutHTTPRequest(this.client); request.createHTTPRequest(path + "/" + childName, Resource1.ContainerRequest); request.addBody(buf); ExecutionResult executionResult = request.executeRequest(); return true; } catch (ExceptionHandler) { return false; } }
// /// <summary> /// Creates a new container in account /// </summary> /// <param name="containerName">Name of Container to be created</param> /// <returns>True if created successfully /// False otherwise</returns> public Boolean createContainer(String containerName) { try { PutHTTPRequest request = new PutHTTPRequest(this.client); path = CommonConstants.CDMI_PATH_CONSTANT + client.username + "/" + containerName; byte[] buf = Encoding.UTF8.GetBytes( "{ \"metadata\" : {\"cTime\" : \"" + DateTime.Now.ToString() + "\"} }"); request.createHTTPRequest(path, Resource1.ContainerRequest); request.addBody(buf); ExecutionResult executionResult = request.executeRequest(); return true; } catch (ExceptionHandler) { return false; } }
/// <summary> /// Creates child container under given parent container. /// </summary> /// <param name="childName">Name of Child container</param> /// <param name="metadataFilePath">Path of metadata file</param> /// <return>True if created successfully /// False otherwise</return> public Boolean createChildContainer(String childName,String metadataFilePath) { try { String[] metadataFile = File.ReadAllLines(metadataFilePath); StringBuilder metadataContents = new StringBuilder(); foreach (String entry in metadataFile) { metadataContents.Append(entry); } byte[] buf = Encoding.UTF8.GetBytes( "{ \"metadata\" : { \"cTime\" : \"" + DateTime.Now.ToString() + "\"" +","+ metadataContents.ToString()+" } }"); PutHTTPRequest request = new PutHTTPRequest(this.client); request.createHTTPRequest(path + "/" + childName, Resource1.ContainerRequest); request.addBody(buf); ExecutionResult executionResult = request.executeRequest(); return true; } catch (ExceptionHandler) { return false; } }
/// <summary> /// Creates child object under given parent container with medatadata file. /// </summary> /// <param name="childName">Name of child object</param> /// <param name="filePath">Path of file to be uploaded</param> /// <param name="metadataFilePath">Path of metadata file</param> /// <returns>True if created successfully /// False otherwise</returns> public Boolean createChildObject(String childName, String filePath, String metadataFilePath) { try { String objectValue = File.ReadAllText(filePath); byte[] value = Encoding.UTF8.GetBytes(objectValue); objectValue = Convert.ToBase64String(value); String[] metadataFile = File.ReadAllLines(metadataFilePath); StringBuilder metadataContents = new StringBuilder(); foreach (String entry in metadataFile) { metadataContents.Append(entry); } byte[] buf = Encoding.UTF8.GetBytes( "{ \"mimetype\" : \"text/plain\"," + "\"value\" : \"" + objectValue + "\" ,\"metadata\" : { \"cTime\" : \"" + DateTime.Now.ToString() + "\"" + "," + metadataContents.ToString() + " } }"); String trial = System.Text.Encoding.UTF8.GetString(buf); PutHTTPRequest request = new PutHTTPRequest(this.client); request.createHTTPRequest(path + "/" + childName, Resource1.ObjectRequest); request.addBody(buf); ExecutionResult executionResult = request.executeRequest(); return true; } catch (ExceptionHandler) { return false; } }
/// <summary> /// Creates child object under given parent container. /// </summary> /// <param name="childName">Name of Child Object</param> /// <param name="filePath">Path of file to be uploaded</param> /// <return>True if created successfully /// False otherwise</return> public Boolean createChildObject(String childName, String filePath) { try { String objectValue = File.ReadAllText(filePath); byte[] value = Encoding.UTF8.GetBytes(objectValue); objectValue = Convert.ToBase64String(value); byte[] buf = Encoding.UTF8.GetBytes( "{ \"mimetype\" : \"text/plain\"," + "\"value\" : \"" + objectValue + "\" ,\"metadata\" : { \"cTime\" : \"" + DateTime.Now.ToString() + "\" } }"); PutHTTPRequest request = new PutHTTPRequest(this.client); request.createHTTPRequest(path + "/" + childName, Resource1.ObjectRequest); request.addBody(buf); ExecutionResult executionResult = request.executeRequest(); return true; } catch (ExceptionHandler) { return false; } }