Ejemplo n.º 1
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);
            }
        }
Ejemplo n.º 2
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);
        }