Example #1
0
        /// <summary>
        /// This method checks the user's permission on particular container
        /// </summary>
        /// <param name="connection"></param>
        /// <param name="containerName"></param>
        /// <returns>NIL/READ/WRITE</returns>
        public String checkResourcePermission(SqlConnection connection, int uid, String containerName)
        {
            ResourceM resource = new ResourceM();

            Model.AzureContainerModel r = new Model.AzureContainerModel();
            r = resource.getResourceByContainerName(connection, containerName);
            int resourceID = r.getRid();

            try
            {
                command             = new SqlCommand("SELECT READWRITE FROM CLIST WHERE RID = @RID AND UID = @UID");
                command.CommandType = CommandType.Text;
                command.Connection  = connection;
                command.Parameters.AddWithValue("@UID", uid);
                command.Parameters.AddWithValue("@RID", resourceID);
                reader = command.ExecuteReader();

                //If no record is available; it means no permission is granted to given user on given container
                if (!reader.HasRows)
                {
                    return("NIL");
                }

                int permission = 0;
                while (reader.Read())
                {
                    permission = reader.GetInt32(0);
                }
                reader.Close();

                if (permission == 0)
                {
                    return("READ");
                }
                else
                {
                    return("WRITE");
                }
            }
            catch (SqlException ex)
            {
                Console.WriteLine("CListM class: checkResourcePermission method exception->" + ex.Message);
            }
            return("NIL");
        }
Example #2
0
        /// <summary>
        /// This method returns the list of containers which are shared with given user
        /// each element seems like "CONTAINERNAME:OWNERFULLNAME:GIVENCONTAINERNAME" //User friendly manner
        /// </summary>
        /// <param name="connection"></param>
        /// <param name="userid"></param>
        /// <returns>null/string array contains the name of containers</returns>
        public String[] getSharedContainersWithUser(SqlConnection connection, int userid)
        {
            String[] sharedContainers = null;
            try {
                command             = new SqlCommand("SELECT RID, OWNER FROM CLIST WHERE UID = @UID");
                command.CommandType = CommandType.Text;
                command.Connection  = connection;
                command.Parameters.AddWithValue("@UID", userid);
                reader = command.ExecuteReader();

                //no containers shared with user
                if (!reader.HasRows)
                {
                    return(null);
                }

                ResourceM r                                = new ResourceM();
                UserM     u                                = new UserM();
                int       currRid                          = 0;
                String    ownerName                        = null;
                Model.AzureContainerModel cont             = new Model.AzureContainerModel();
                List <String>             containersString = new List <String>();
                while (reader.Read())
                {
                    currRid = reader.GetInt32(0);
                    cont    = r.getResourceById(connection, currRid);
                    Console.WriteLine("Owner: " + reader.GetInt32(1));
                    ownerName = (u.getUserRecordByID(connection, (reader.GetInt32(1)))).getFullName();
                    containersString.Add((cont.getContainerName()) + ":" + ownerName + ":" + (cont.getGivenName()));
                }
                reader.Close();

                sharedContainers = containersString.ToArray();
                return(sharedContainers);
            }
            catch (SqlException ex)
            {
                Console.WriteLine("CListM class: getSharedContainersWithUser method Exception->" + ex.Message);
            }
            return(null);
        }
Example #3
0
        /// <summary>
        /// This method returns the list of containers which are shared by given ownerid
        /// each element seems like "CONTAINERNAME:GIVENNAME" //User friendly manner
        /// </summary>
        /// <param name="connection"></param>
        /// <param name="ownerid"></param>
        /// <returns></returns>
        public String[] getSharedContainersOwnedByUser(SqlConnection connection, int ownerid)
        {
            String[] sharedContainers = null;
            try {
                command             = new SqlCommand("SELECT RID FROM CLIST WHERE OWNER = @OWNER");
                command.CommandType = CommandType.Text;
                command.Connection  = connection;
                command.Parameters.AddWithValue("@OWNER", ownerid);
                reader = command.ExecuteReader();

                //no containers shared by ownerid
                if (!reader.HasRows)
                {
                    return(null);
                }

                ResourceM r = new ResourceM();

                int           currRid          = 0;
                List <String> containersString = new List <String>();
                while (reader.Read())
                {
                    currRid = reader.GetInt32(0);
                    containersString.Add(((r.getResourceById(connection, currRid)).getContainerName()) + ":" + ((r.getResourceById(connection, currRid)).getGivenName()));
                }
                reader.Close();
                foreach (string author in containersString)
                {
                    Console.WriteLine(author);
                }
                sharedContainers = containersString.ToArray();
                return(sharedContainers);
            }
            catch (SqlException ex)
            {
                Console.WriteLine("CListM class: getSharedContainersOwnedByUser method Exception->" + ex.Message);
            }
            return(null);
        }