/// <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 getSharedResourceByGivenName() method returns the shared folder model of givenname and uid /// </summary> /// <param name="connection"></param> /// <param name="uid"></param> /// <param name="givenName"></param> /// <returns></returns> public Model.CListModel getSharedResourceByGivenName(SqlConnection connection, int uid, String givenName) { try { command = new SqlCommand("SELECT C.RID, C.UID, C.OWNER, C.READWRITE FROM CLIST C, CONTAINERS CO WHERE C.UID = @UID AND CO.GIVENNAME = @GIVENNAME AND C.RID = CO.RID"); command.CommandType = CommandType.Text; command.Connection = connection; command.Parameters.AddWithValue("@UID", uid); command.Parameters.AddWithValue("@GIVENNAME", givenName); reader = command.ExecuteReader(); //no containers shared by ownerid if (!reader.HasRows) { return(null); } Model.CListModel cl = new Model.CListModel(); while (reader.Read()) { cl.setRid(reader.GetInt32(0)); cl.setUid(reader.GetInt32(1)); cl.setOwner(reader.GetInt32(2)); cl.setReadwrite(reader.GetInt32(3)); } reader.Close(); return(cl); } catch (SqlException ex) { Console.WriteLine("CLISTM class getSharedResouceByGivenName method exception->" + ex.Message); return(null); } }
/// <summary> /// This grantRights() method set the rights to the otheruserID /// </summary> /// <param name="otheruserID"></param> /// <param name="containerID"></param> /// <param name="writeAccess"></param> /// <returns>true/false</returns> public Boolean grantRights(int otheruserID, int containerID, Boolean writeAccess) { DBManager.ResourceM resmgr = new DBManager.ResourceM(); Model.AzureContainerModel rmodel = new Model.AzureContainerModel(); Model.CListModel cmodel = new Model.CListModel(); try { rmodel = resmgr.getResourceById(connection, containerID); DBManager.CListM cmgr = new DBManager.CListM(); Model.CListModel cmodel1 = new Model.CListModel(); cmodel1 = cmgr.getSharedResourceByGivenName(connection, otheruserID, rmodel.getGivenName()); if (cmodel1 != null) { //If permission already granted to otheruser, then check if requested permission is same Boolean test = false; if (cmodel1.getReadwrite() == 1) { test = true; } if (test == writeAccess) { return(true); //already exist with same permission } else { cmgr.deleteUserEntryFromCLIST(connection, otheruserID, containerID); //delete the record and re-enter } } cmodel.setRid(containerID); cmodel.setUid(otheruserID); cmodel.setOwner(rmodel.getOwner()); if (writeAccess) { cmodel.setReadwrite(1); } else { cmodel.setReadwrite(0); } //Insert into CLIST table bool success = cmgr.insertIntoCList(connection, cmodel); return(success); } catch (DBLikeExceptions.CloudContainerNotFoundException) { return(false); } }
/// <summary> /// This method insert record into CLIST table /// </summary> /// <param name="connection"></param> /// <param name="cm"></param> /// <returns></returns> public Boolean insertIntoCList(SqlConnection connection, Model.CListModel cm) { try { command = new SqlCommand("INSERT INTO CLIST (UID, RID, READWRITE, OWNER) VALUES (@UID, @RID, @READWRITE, @OWNER)"); command.CommandType = CommandType.Text; command.Connection = connection; command.Parameters.AddWithValue("@UID", cm.getUid()); command.Parameters.AddWithValue("@RID", cm.getRid()); command.Parameters.AddWithValue("@OWNER", cm.getOwner()); command.Parameters.AddWithValue("@READWRITE", cm.getReadwrite()); command.ExecuteNonQuery(); return(true); } catch (Exception e) { Console.WriteLine("inserIntoCList method says->" + e.Message); } return(false); }