コード例 #1
0
        /// <summary>
        /// This canWrite() method return true if user has write permission
        /// </summary>
        /// <param name="userID"></param>
        /// <param name="containerID"></param>
        /// <returns></returns>
        public Boolean canWrite(int userID, int containerID)
        {
            if (isOwner(userID, containerID))
            {
                return(true);
            }
            DBManager.CListM          cmgr   = new DBManager.CListM();
            DBManager.ResourceM       resmgr = new DBManager.ResourceM();
            Model.AzureContainerModel rmodel = new Model.AzureContainerModel();
            try
            {
                rmodel = resmgr.getResourceById(connection, containerID);
                String permission = cmgr.checkResourcePermission(connection, userID, rmodel.getContainerName());

                if (permission.Equals("WRITE"))
                {
                    return(true);
                }
            }
            catch (DBLikeExceptions.CloudContainerNotFoundException)
            {
                return(false);
            }
            return(false);
        }
コード例 #2
0
        /// <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);
            }
        }
コード例 #3
0
        /// <summary>
        /// This removeRights() method revoke the user right by deleting the record from CLIST table
        /// </summary>
        /// <param name="otheruserID"></param>
        /// <param name="containerID"></param>
        public void removeRights(int otheruserID, int containerID)
        {
            DBManager.CListM cmgr = new DBManager.CListM();

            try
            {
                cmgr.deleteUserEntryFromCLIST(connection, otheruserID, containerID);

                //CHECK if no user exists in cLIST corresponding to given container
                //if so delete container and omit record form RESOURCE table as well
                Console.WriteLine("ress" + cmgr.isRecordExistsForContainerID(connection, containerID));
                if (!cmgr.isRecordExistsForContainerID(connection, containerID)) //if no other user is sharing this container
                {
                    DBManager.ResourceM rmgr = new DBManager.ResourceM();

                    if (deleteSharedContainer(containerID))
                    {
                        //delete container and entry
                        rmgr.deleteContainerEntryFromCONTAINERS(connection, containerID.ToString());
                    }
                }
            }
            catch (Exception e)
            {
                Console.WriteLine("Resource class removeRights method Exception->" + e.Message);
            }
        }
コード例 #4
0
        /// <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);
            }
        }
コード例 #5
0
        /// <summary>
        /// This deleteSharedContainer() method just deletes container as per given containerID
        /// which means pre-check is required to call this method
        /// </summary>
        /// <param name="containerID"></param>
        /// <returns>true/false/exception</returns>
        public Boolean deleteSharedContainer(int containerID)
        {
            //throw new NotImplementedException();
            //Console.WriteLine("DeleteSharedCOntainer NYI");
            try
            {
                Model.AzureContainerModel res  = new Model.AzureContainerModel();
                DBManager.ResourceM       rmgr = new DBManager.ResourceM();
                res = rmgr.getResourceById(connection, containerID);

                CloudBlobContainer myContainer       = BlobStorageManager.BlobStorage.getCloudBlobContainer(res.getContainerName()); //Container ref
                Boolean            isContainerexists = BlobStorageManager.BlobStorage.isContainerExists(myContainer);

                if (isContainerexists == false)
                {
                    throw new DBLikeExceptions.CloudContainerNotFoundException();
                }

                if (myContainer.ListBlobs().GetEnumerator().MoveNext())
                {
                    throw new ArgumentException("container not empty");
                }
                myContainer.Delete();

                //Delete from database
                DBManager.CListM cmgr = new DBManager.CListM();
                if (cmgr.deleteUserEntryFromCLIST(connection, 0, containerID))                       //delete all records from CLIST
                {
                    if (rmgr.deleteContainerEntryFromCONTAINERS(connection, containerID.ToString())) //delete from CONTAINERS
                    {
                        return(true);
                    }
                }
            }
            catch (Microsoft.WindowsAzure.Storage.StorageException e)
            {
                Console.WriteLine("Resource:deleteSharedContainer Exception:" + e.Message);
            }
            return(false);
        }