/// <summary> /// This method return the containerID by givenname and uid /// returns rid only when uid is listed corresponding to given container name /// else it is considered that there exists no such container for userid /// </summary> /// <param name="userid"></param> /// <param name="givenname"></param> /// <returns>rid/-1</returns> public int getContainerID(int userid, String givenname) { DBManager.ResourceM resmgr = new DBManager.ResourceM(); try { Model.AzureContainerModel resource = new Model.AzureContainerModel(); resource = resmgr.getResourceByGivenName(connection, userid, givenname); if (resource == null) { Model.CListModel cl = new Model.CListModel(); DBManager.CListM cmgr = new DBManager.CListM(); cl = cmgr.getSharedResourceByGivenName(connection, userid, givenname); if (cl == null) { return(-1); } return(cl.getRid()); } else { return(resource.getRid()); } } catch (DBLikeExceptions.CloudContainerNotFoundException) { return(-1); } }
/// <summary> /// This createSharedContainer() method creates the shared container which is owned by given userid /// CloudContainerAlreadyExistException if already exists /// </summary> /// <param name="userid"></param> /// <param name="givenname"></param> /// <returns>id for new container on success, else -1</returns> public int createSharedContainer(int userid, String givenname) { DBManager.ResourceM resmgr = new DBManager.ResourceM(); Model.AzureContainerModel resource = new Model.AzureContainerModel(); try { resource = resmgr.getResourceByGivenName(connection, userid, givenname); Model.UserModel user = new Model.UserModel(); DBManager.UserM umgr = new DBManager.UserM(); user = umgr.getUserRecordByID(connection, userid); File f = new File(); String[] list = f.list(user.getEmailId(), ""); for (int i = 0; i < list.Length; i++) { String[] tokens = list[i].Split(':'); if (tokens.Length == 3) { if (tokens[2].Equals(givenname)) //there exist the container with same name { throw new DBLikeExceptions.CloudContainerAlreadyExistException(); } } else if (tokens.Length == 2) { if (tokens[1].Equals(givenname)) //there exist the container with same name { throw new DBLikeExceptions.CloudContainerAlreadyExistException(); } } } if (resource != null) { throw new DBLikeExceptions.CloudContainerAlreadyExistException(); } DBManager.CListM cmgr = new DBManager.CListM(); //cmgr.insertIntoCList(); String[] sharedContainers = cmgr.getSharedContainersOwnedByUser(connection, userid); int counter = 001; //Console.WriteLine("shareddddddddd"+sharedContainers.Length); if (sharedContainers != null) { int size = sharedContainers.Length; String[] containerSuffix = new String[size]; String[] temp; //SHOULD NOT ALLOW USER TO GIVE SAME NAME TO DIFFERENT SHARED CONTAINER for (int i = 0; i < size; i++) { temp = sharedContainers[i].Split(':'); int pos = temp[0].IndexOf("d") + 1; Console.WriteLine("Position" + pos); String scnt = temp[0].Substring(pos); containerSuffix[i] = new string(scnt.Where(char.IsDigit).ToArray()); //no need but leaving as it is } var result = (from m in containerSuffix select m).Max(); Console.WriteLine("result" + result); counter = Int32.Parse(result) + 1; Console.WriteLine("New counter--" + counter); } String containerName = userid + "shared" + counter; CloudBlobContainer myContainer = BlobStorageManager.BlobStorage.getCloudBlobContainer(containerName); myContainer.CreateIfNotExists(); Model.AzureContainerModel resource1 = new Model.AzureContainerModel(); //Insert record into CONTAINERS table resource1.setOwner(userid); resource1.setContainerName(containerName); resource1.setGivenName(givenname); Boolean res = resmgr.insertIntoResources(connection, resource1); if (res) { int rid1 = getContainerID(userid, givenname); return(rid1); } return(-1); } catch (SqlException) { return(-1); } }