Ejemplo n.º 1
0
        /// <summary>
        /// This method should return TRUE if user account created successfully
        /// FALSE if user record already exist in database
        /// THE CONTAINER IS NAMED AS USERID [unique identifier]
        /// </summary>
        /// <param name="username"></param>
        /// <param name="password"></param>
        /// <returns></returns>
        public Boolean createUser(String fullname, String username, String password)
        {
            Model.UserModel user = new Model.UserModel();
            DBManager.UserM u    = new DBManager.UserM();
            user = u.getUserRecord(connection, username);

            //if user already exist, false
            if (!(user == null))
            {
                return(false);
            }

            //Insert record into USERS table
            u.insertIntoUsers(connection, fullname, username, password);
            user = u.getUserRecord(connection, username);

            //default private container created
            //Container get created by the unique user id
            Console.WriteLine("Container created with " + user.getUid() + " name");

            Microsoft.WindowsAzure.Storage.Blob.CloudBlobContainer myContainer = BlobStorageManager.BlobStorage.getCloudBlobContainer((user.getUid()).ToString());
            myContainer.CreateIfNotExists();

            String containerName = (user.getUid()).ToString();

            //Insert record into CONTAINERS table
            DBManager.ResourceM r = new DBManager.ResourceM();
            Console.WriteLine(containerName + "////" + user.getUid());
            Model.AzureContainerModel re = new Model.AzureContainerModel();
            re.setOwner(user.getUid());
            re.setContainerName(containerName);
            re.setGivenName(user.getEmailId());  //Changed here since server front end is considering private container name as user email id
            Boolean res = r.insertIntoResources(connection, re);

            return(res);
        }
Ejemplo n.º 2
0
        /// <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);
            }
        }