Ejemplo n.º 1
0
        /// <summary>
        /// Adds new shared root folder to virtual server.
        /// </summary>
        /// <param name="enabled">Specifies if shared root folder is enabled.</param>
        /// <param name="name">Shared root folder name.</param>
        /// <param name="description">Shared root folder description.</param>
        /// <param name="type">Shared root folder type.</param>
        /// <param name="boundedUser">Bounded user.</param>
        /// <param name="boundedFolder">Bounded folder.</param>
        public SharedRootFolder Add(bool enabled, string name, string description, SharedFolderRootType_enum type, string boundedUser, string boundedFolder)
        {
            /* AddSharedRootFolder <virtualServerID> "<rootFolderID>" "<rootFolderName>" "<description>" <type> "<boundedUser>" "boundedFolder" <enabled>
             *    Responses:
             +OK
             *      -ERR <errorText>
             */

            string id = Guid.NewGuid().ToString();

            // Call TCP AddSharedRootFolder
            m_pVirtualServer.Server.TcpClient.TcpStream.WriteLine("AddSharedRootFolder " +
                                                                  m_pVirtualServer.VirtualServerID + " " +
                                                                  TextUtils.QuoteString(id) + " " +
                                                                  TextUtils.QuoteString(name) + " " +
                                                                  TextUtils.QuoteString(description) + " " +
                                                                  (int)type + " " +
                                                                  TextUtils.QuoteString(boundedUser) + " " +
                                                                  TextUtils.QuoteString(boundedFolder) + " " +
                                                                  enabled
                                                                  );

            string response = m_pVirtualServer.Server.ReadLine();

            if (!response.ToUpper().StartsWith("+OK"))
            {
                throw new Exception(response);
            }

            SharedRootFolder rootFolder = new SharedRootFolder(m_pVirtualServer, this, id, enabled, name, description, type, boundedUser, boundedFolder);

            m_pRootFolders.Add(rootFolder);
            return(rootFolder);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Adds new shared root folder to virtual server.
        /// </summary>
        /// <param name="enabled">Specifies if shared root folder is enabled.</param>
        /// <param name="name">Shared root folder name.</param>
        /// <param name="description">Shared root folder description.</param>
        /// <param name="type">Shared root folder type.</param>
        /// <param name="boundedUser">Bounded user.</param>
        /// <param name="boundedFolder">Bounded folder.</param>
        public SharedRootFolder Add(bool enabled,string name,string description,SharedFolderRootType_enum type,string boundedUser,string boundedFolder)
        {
            /* AddSharedRootFolder <virtualServerID> "<rootFolderID>" "<rootFolderName>" "<description>" <type> "<boundedUser>" "boundedFolder" <enabled>
                  Responses:
                    +OK                     
                    -ERR <errorText>
            */

            string id = Guid.NewGuid().ToString();

            // Call TCP AddSharedRootFolder
            m_pVirtualServer.Server.TcpClient.TcpStream.WriteLine("AddSharedRootFolder " + 
                m_pVirtualServer.VirtualServerID + " " + 
                TextUtils.QuoteString(id) + " " + 
                TextUtils.QuoteString(name) + " " + 
                TextUtils.QuoteString(description) + " " + 
                (int)type + " " +
                TextUtils.QuoteString(boundedUser) + " " + 
                TextUtils.QuoteString(boundedFolder) + " " + 
                enabled
            );
                        
            string response = m_pVirtualServer.Server.ReadLine();
            if(!response.ToUpper().StartsWith("+OK")){
                throw new Exception(response);
            }

            SharedRootFolder rootFolder = new SharedRootFolder(m_pVirtualServer,this,id,enabled,name,description,type,boundedUser,boundedFolder);
            m_pRootFolders.Add(rootFolder);
            return rootFolder;
        }
Ejemplo n.º 3
0
 /// <summary>
 /// Default constructor.
 /// </summary>
 /// <param name="rootID">Root Folder ID.</param>
 /// <param name="enabled">Specifies if root folder is enabled.</param>
 /// <param name="folderName">Root folder visible name.</param>
 /// <param name="description">Description text.</param>
 /// <param name="rootType">Specifies what type root folder is.</param>
 /// <param name="boundedUser">User which to bound root folder.</param>
 /// <param name="boundedFolder">BoundingUser folder name which to bound root folder.</param>
 public SharedFolderRoot(string rootID,bool enabled,string folderName,string description,SharedFolderRootType_enum rootType,string boundedUser,string boundedFolder)
 {
     m_RootID        = rootID;
     m_Enabled       = enabled;
     m_FolderName    = folderName;
     m_Description   = description;
     m_RootType      = rootType;
     m_BoundedUser   = boundedUser;
     m_BoundedFolder = boundedFolder;
 }
Ejemplo n.º 4
0
 /// <summary>
 /// Default constructor.
 /// </summary>
 /// <param name="rootID">Root Folder ID.</param>
 /// <param name="enabled">Specifies if root folder is enabled.</param>
 /// <param name="folderName">Root folder visible name.</param>
 /// <param name="description">Description text.</param>
 /// <param name="rootType">Specifies what type root folder is.</param>
 /// <param name="boundedUser">User which to bound root folder.</param>
 /// <param name="boundedFolder">BoundingUser folder name which to bound root folder.</param>
 public SharedFolderRoot(string rootID, bool enabled, string folderName, string description, SharedFolderRootType_enum rootType, string boundedUser, string boundedFolder)
 {
     m_RootID        = rootID;
     m_Enabled       = enabled;
     m_FolderName    = folderName;
     m_Description   = description;
     m_RootType      = rootType;
     m_BoundedUser   = boundedUser;
     m_BoundedFolder = boundedFolder;
 }
Ejemplo n.º 5
0
 /// <summary>
 /// Default constructor.
 /// </summary>
 /// <param name="virtualServer">Owner virtual server.</param>
 /// <param name="owner">Owner SharedRootFolderCollection collection that owns this root folder.</param>
 /// <param name="id">Root folder ID.</param>
 /// <param name="enabled">Specifies if root folder is enabled.</param>
 /// <param name="name">Root folder name.</param>
 /// <param name="description">Root folder description.</param>
 /// <param name="type">Root folder type.</param>
 /// <param name="boundedUser">Root folder bounded user.</param>
 /// <param name="boundedFolder">Root folder bounded folder.</param>
 internal SharedRootFolder(VirtualServer virtualServer, SharedRootFolderCollection owner, string id, bool enabled, string name, string description, SharedFolderRootType_enum type, string boundedUser, string boundedFolder)
 {
     m_pVirtualServer = virtualServer;
     m_pOwner         = owner;
     m_ID             = id;
     m_Enabled        = enabled;
     m_Name           = name;
     m_Description    = description;
     m_FolderType     = type;
     m_BoundedUser    = boundedUser;
     m_BoundedFolder  = boundedFolder;
 }
Ejemplo n.º 6
0
 /// <summary>
 /// Default constructor.
 /// </summary>
 /// <param name="virtualServer">Owner virtual server.</param>
 /// <param name="owner">Owner SharedRootFolderCollection collection that owns this root folder.</param>
 /// <param name="id">Root folder ID.</param>
 /// <param name="enabled">Specifies if root folder is enabled.</param>
 /// <param name="name">Root folder name.</param>
 /// <param name="description">Root folder description.</param>
 /// <param name="type">Root folder type.</param>
 /// <param name="boundedUser">Root folder bounded user.</param>
 /// <param name="boundedFolder">Root folder bounded folder.</param>
 internal SharedRootFolder(VirtualServer virtualServer,SharedRootFolderCollection owner,string id,bool enabled,string name,string description,SharedFolderRootType_enum type,string boundedUser,string boundedFolder)
 {
     m_pVirtualServer = virtualServer;
     m_pOwner         = owner;
     m_ID             = id;
     m_Enabled        = enabled;
     m_Name           = name;
     m_Description    = description;
     m_FolderType     = type;
     m_BoundedUser    = boundedUser;
     m_BoundedFolder  = boundedFolder;
 }
        private void m_Ok_Click(object sender, EventArgs e)
        {
            SharedFolderRootType_enum rootType = (SharedFolderRootType_enum)((WComboBoxItem)m_pRootFolderType.SelectedItem).Tag;

            //--- Validate values ------------------------//
            if (rootType == SharedFolderRootType_enum.BoundedRootFolder && m_pBoundedUser.Text == "")
            {
                MessageBox.Show(this, "Please select bounded user !", "Error:", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            if (rootType == SharedFolderRootType_enum.BoundedRootFolder && m_pBoundedFolder.Text == "")
            {
                MessageBox.Show(this, "Please select bounded folder !", "Error:", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            //--------------------------------------------//


            // Add new
            if (m_pRootFolder == null)
            {
                m_pRootFolder = m_pVirtualServer.RootFolders.Add(
                    m_pEnabled.Checked,
                    m_pRootFolderName.Text,
                    m_pDescription.Text,
                    (SharedFolderRootType_enum)((WComboBoxItem)m_pRootFolderType.SelectedItem).Tag,
                    m_pBoundedUser.Text,
                    m_pBoundedFolder.Text
                    );
            }
            // Update
            else
            {
                m_pRootFolder.Enabled       = m_pEnabled.Checked;
                m_pRootFolder.Name          = m_pRootFolderName.Text;
                m_pRootFolder.Description   = m_pDescription.Text;
                m_pRootFolder.Type          = (SharedFolderRootType_enum)((WComboBoxItem)m_pRootFolderType.SelectedItem).Tag;
                m_pRootFolder.BoundedUser   = m_pBoundedUser.Text;
                m_pRootFolder.BoundedFolder = m_pBoundedFolder.Text;
                m_pRootFolder.Commit();
            }

            this.DialogResult = DialogResult.OK;
        }
        /// <summary>
        /// Add shared folder root.
        /// </summary>
        /// <param name="rootID">Root folder ID. Guid.NewID().ToString() is suggested.</param>
        /// <param name="enabled">Specifies if root folder is enabled.</param>
        /// <param name="folder">Folder name which will be visible to public.</param>
        /// <param name="description">Description text.</param>
        /// <param name="rootType">Specifies what type root folder is.</param>
        /// <param name="boundedUser">User which to bound root folder.</param>
        /// <param name="boundedFolder">Folder which to bound to public folder.</param>
        public void AddSharedFolderRoot(string rootID,bool enabled,string folder,string description,SharedFolderRootType_enum rootType,string boundedUser,string boundedFolder)
        {
            /* Implementation notes:
                *) Validate values. Throw ArgumnetExcetion if invalid values.
                *) Ensure that root ID doesn't exists.
                *) Ensure that root doesn't exists.
                *) Add root folder.
            */

            if(rootID == null || rootID == ""){
                throw new Exception("Invalid rootID value, rootID can't be '' or null !");
            }

            //--- Validate values -------------------------------------//
            ArgsValidator.ValidateNotNull(rootID);
            ArgsValidator.ValidateSharedFolderRoot(folder);
            ArgsValidator.ValidateNotNull(description);
            if(rootType == SharedFolderRootType_enum.BoundedRootFolder){
                ArgsValidator.ValidateUserName(boundedUser);
                ArgsValidator.ValidateFolder(boundedFolder);
            }
            //---------------------------------------------------------//

            /* We handle these is SQL, sql returns these errors in ErrorText

                *) Ensure that root ID doesn't exists.
                *) Ensure that root doesn't exists.
            */

            // Insert group
            using(WSqlCommand sqlCmd = new WSqlCommand(m_ConStr,"lspr_AddSharedFolderRoot")){
                sqlCmd.AddParameter("_rootID"        ,NpgsqlDbType.Varchar,rootID);
                sqlCmd.AddParameter("_enabled"       ,NpgsqlDbType.Boolean,enabled);
                sqlCmd.AddParameter("-folder"        ,NpgsqlDbType.Varchar,folder);
                sqlCmd.AddParameter("_description"   ,NpgsqlDbType.Varchar,description);
                sqlCmd.AddParameter("_rootType"      ,NpgsqlDbType.Integer,rootType);
                sqlCmd.AddParameter("_boundedUser"   ,NpgsqlDbType.Varchar,boundedUser);
                sqlCmd.AddParameter("_boundedFolder" ,NpgsqlDbType.Varchar,boundedFolder);

                DataSet ds = sqlCmd.Execute();
            }
        }
Ejemplo n.º 9
0
 public void UpdateSharedFolderRoot(string rootID, bool enabled, string folder, string description, SharedFolderRootType_enum rootType, string boundedUser, string boundedFolder)
 {
     if (rootID == null || rootID == "")
     {
         throw new Exception("Invalid rootID value, rootID can't be '' or null !");
     }
     ArgsValidator.ValidateNotNull(rootID);
     ArgsValidator.ValidateSharedFolderRoot(folder);
     ArgsValidator.ValidateNotNull(description);
     if (rootType == SharedFolderRootType_enum.BoundedRootFolder)
     {
         ArgsValidator.ValidateUserName(boundedUser);
         ArgsValidator.ValidateFolder(boundedFolder);
     }
     this.m_UpdSync.BeginUpdate();
     try
     {
         if (!this.ContainsID(this.dsSharedFolderRoots.Tables["SharedFoldersRoots"], "RootID", rootID))
         {
             throw new Exception("Invalid root ID, specified root ID '" + rootID + "' doesn't exist !");
         }
         foreach (DataRow dataRow in this.dsSharedFolderRoots.Tables["SharedFoldersRoots"].Rows)
         {
             if (dataRow["RootID"].ToString().ToLower() == rootID)
             {
                 if (dataRow["Folder"].ToString().ToLower() != folder.ToLower() && this.SharedFolderRootExists(folder))
                 {
                     throw new Exception("Invalid root folder name, specified root folder '" + folder + "' already exists !");
                 }
                 dataRow["Enabled"] = enabled;
                 dataRow["Folder"] = folder;
                 dataRow["Description"] = description;
                 dataRow["RootType"] = (int)rootType;
                 dataRow["BoundedUser"] = boundedUser;
                 dataRow["BoundedFolder"] = boundedFolder;
                 this.dsSharedFolderRoots.WriteXml(this.m_DataPath + "SharedFoldersRoots.xml", XmlWriteMode.IgnoreSchema);
                 break;
             }
         }
     }
     catch (Exception ex)
     {
         throw ex;
     }
     finally
     {
         this.m_UpdSync.EndUpdate();
     }
 }
Ejemplo n.º 10
0
        /// <summary>
        /// Updates shared folder root.
        /// </summary>
        /// <param name="rootID">Root Folder which to update.</param>
        /// <param name="enabled">Specifies if root folder is enabled.</param>
        /// <param name="folder">Folder name which will be visible to public.</param>
        /// <param name="description">Description text.</param>
        /// <param name="rootType">Specifies what type root folder is.</param>
        /// <param name="boundedUser">User which to bound root folder.</param>
        /// <param name="boundedFolder">Folder which to bound to public folder.</param>
        public void UpdateSharedFolderRoot(string rootID,bool enabled,string folder,string description,SharedFolderRootType_enum rootType,string boundedUser,string boundedFolder)
        {
            if(rootID == null || rootID == ""){
                throw new Exception("Invalid rootID value, rootID can't be '' or null !");
            }

            //--- Validate values -------------------------------------//
            ArgsValidator.ValidateNotNull(rootID);
            ArgsValidator.ValidateSharedFolderRoot(folder);
            ArgsValidator.ValidateNotNull(description);
            if(rootType == SharedFolderRootType_enum.BoundedRootFolder){
                ArgsValidator.ValidateUserName(boundedUser);
                ArgsValidator.ValidateFolder(boundedFolder);
            }
            //---------------------------------------------------------//

            m_UpdSync.BeginUpdate();

			try{
                /* Implementation notes:
                    *) Validate values. Throw ArgumnetExcetion if invalid values.
                    *) Ensure that root ID exists.
                    *) If root folder name is changed, ensure that new root folder won't conflict 
                       any other root folder name. Throw Exception if does.     
                    *) Update root folder.
                */

                // Ensure that group with specified ID does exist.
                if(!ContainsID(dsSharedFolderRoots.Tables["SharedFoldersRoots"],"RootID",rootID)){
                    throw new Exception("Invalid root ID, specified root ID '" + rootID + "' doesn't exist !");
                }

                //--- Update root folder
                foreach(DataRow dr in dsSharedFolderRoots.Tables["SharedFoldersRoots"].Rows){
                    if(dr["RootID"].ToString().ToLower() == rootID){
                        // If root folder name is changed, ensure that new root folder won't conflict 
                        //   any other root folder name. Throw Exception if does.
                        if(dr["Folder"].ToString().ToLower() != folder.ToLower()){
                            if(SharedFolderRootExists(folder)){
                                throw new Exception("Invalid root folder name, specified root folder '" + folder + "' already exists !");
                            }
                        }

                     // dr["RootID"]        = rootID;
					    dr["Enabled"]       = enabled;
					    dr["Folder"]        = folder;
                        dr["Description"]   = description;
					    dr["RootType"]      = (int)rootType;
					    dr["BoundedUser"]   = boundedUser;
                        dr["BoundedFolder"] = boundedFolder;

                        dsSharedFolderRoots.WriteXml(m_DataPath + "SharedFoldersRoots.xml",XmlWriteMode.IgnoreSchema);
                        break;
                    }
                }
			}
			catch(Exception x){
				throw x;
			}
			finally{
				m_UpdSync.EndUpdate();
			}
        }
Ejemplo n.º 11
0
        /// <summary>
        /// Add shared folder root.
        /// </summary>
        /// <param name="rootID">Root folder ID. Guid.NewID().ToString() is suggested.</param>
        /// <param name="enabled">Specifies if root folder is enabled.</param>
        /// <param name="folder">Folder name which will be visible to public.</param>
        /// <param name="description">Description text.</param>
        /// <param name="rootType">Specifies what type root folder is.</param>
        /// <param name="boundedUser">User which to bound root folder.</param>
        /// <param name="boundedFolder">Folder which to bound to public folder.</param>
        public void AddSharedFolderRoot(string rootID,bool enabled,string folder,string description,SharedFolderRootType_enum rootType,string boundedUser,string boundedFolder)
        {
            if(rootID == null || rootID == ""){
                throw new Exception("Invalid rootID value, rootID can't be '' or null !");
            }

            //--- Validate values -------------------------------------//
            ArgsValidator.ValidateNotNull(rootID);
            ArgsValidator.ValidateSharedFolderRoot(folder);
            ArgsValidator.ValidateNotNull(description);
            if(rootType == SharedFolderRootType_enum.BoundedRootFolder){
                ArgsValidator.ValidateUserName(boundedUser);
                ArgsValidator.ValidateFolder(boundedFolder);
            }
            //---------------------------------------------------------//
                        
            m_UpdSync.BeginUpdate();

			try{
                /* Implementation notes:
                    *) Validate values. Throw ArgumnetExcetion if invalid values.
                    *) Ensure that root ID doesn't exists.
                    *) Ensure that root doesn't exists.
                    *) Add root folder.
                */

                // Ensure that root ID doesn't exists.
                if(ContainsID(dsSharedFolderRoots.Tables["SharedFoldersRoots"],"RootID",rootID)){
                    throw new Exception("Invalid root ID, specified root ID '" + rootID + "' already exists !");
                }

                // Ensure that folder doesn't exists.
                if(SharedFolderRootExists(folder)){
                    throw new ArgumentException("Invalid root folder value, root folder '" + folder + "' already exists !");
                }

			
				DataRow dr = dsSharedFolderRoots.Tables["SharedFoldersRoots"].NewRow();
				dr["RootID"]        = rootID;
				dr["Enabled"]       = enabled;
				dr["Folder"]        = folder;
                dr["Description"]   = description;
				dr["RootType"]      = (int)rootType;
				dr["BoundedUser"]   = boundedUser;
                dr["BoundedFolder"] = boundedFolder;
							
				dsSharedFolderRoots.Tables["SharedFoldersRoots"].Rows.Add(dr);
				dsSharedFolderRoots.WriteXml(m_DataPath + "SharedFoldersRoots.xml",XmlWriteMode.IgnoreSchema);
			}
			catch(Exception x){
				throw x;
			}
			finally{
				m_UpdSync.EndUpdate();
			}
        }
        /// <summary>
        /// Add shared folder root.
        /// </summary>
        /// <param name="rootID">Root folder ID. Guid.NewID().ToString() is suggested.</param>
        /// <param name="enabled">Specifies if root folder is enabled.</param>
        /// <param name="folder">Folder name which will be visible to public.</param>
        /// <param name="description">Description text.</param>
        /// <param name="rootType">Specifies what type root folder is.</param>
        /// <param name="boundedUser">User which to bound root folder.</param>
        /// <param name="boundedFolder">Folder which to bound to public folder.</param>
        public void AddSharedFolderRoot(string rootID,bool enabled,string folder,string description,SharedFolderRootType_enum rootType,string boundedUser,string boundedFolder)
        {
            /* Implementation notes:
                *) Validate values. Throw ArgumnetExcetion if invalid values.
                *) Ensure that root ID doesn't exists.
                *) Ensure that root doesn't exists.
                *) Add root folder.
            */

            if(rootID == null || rootID == ""){
                throw new Exception("Invalid rootID value, rootID can't be '' or null !");
            }

            //--- Validate values -------------------------------------//
            ArgsValidator.ValidateNotNull(rootID);
            ArgsValidator.ValidateSharedFolderRoot(folder);
            ArgsValidator.ValidateNotNull(description);
            if(rootType == SharedFolderRootType_enum.BoundedRootFolder){
                ArgsValidator.ValidateUserName(boundedUser);
                ArgsValidator.ValidateFolder(boundedFolder);
            }
            //---------------------------------------------------------//

            /* We handle these is SQL, sql returns these errors in ErrorText

                *) Ensure that root ID doesn't exists.
                *) Ensure that root doesn't exists.
            */

            // Insert group
            using(WSqlCommand sqlCmd = new WSqlCommand(m_ConStr,"lspr_AddSharedFolderRoot")){
                sqlCmd.AddParameter("@rootID"        ,SqlDbType.NVarChar ,rootID);
                sqlCmd.AddParameter("@enabled"       ,SqlDbType.Bit      ,enabled);
                sqlCmd.AddParameter("@folder"        ,SqlDbType.NVarChar ,folder);
                sqlCmd.AddParameter("@description"   ,SqlDbType.NVarChar ,description);
                sqlCmd.AddParameter("@rootType"      ,SqlDbType.Int      ,rootType);
                sqlCmd.AddParameter("@boundedUser"   ,SqlDbType.NVarChar ,boundedUser);
                sqlCmd.AddParameter("@boundedFolder" ,SqlDbType.NVarChar ,boundedFolder);

                DataSet ds = sqlCmd.Execute();
                ds.Tables[0].TableName = "Result";

                // Proccess adding errors
                if(ds.Tables["Result"].Rows.Count > 0 && ds.Tables["Result"].Rows[0]["ErrorText"].ToString().Length > 0){
                    throw new Exception(ds.Tables["Result"].Rows[0]["ErrorText"].ToString());
                }
            }
        }