예제 #1
0
        public override SiteMapNode BuildSiteMap()
        {
            lock (this)
            {
                // Return immediately if this method has been called before
                if (_root != null)
                {
                    return(_root);
                }

                // Query the database for site map nodes

                string  sSQL   = null;
                DataSet reader = null;
                try
                {
                    sSQL = "SELECT * FROM `SiteMap` WHERE `ApplicationName` = '" + _applicationName + "' ORDER BY `Parent`;";

                    reader       = RawDBQuery.ExecuteDatasetQueryOnDB(sSQL, _connect);
                    _indexID     = 0;
                    _indexTitle  = 2;
                    _indexDesc   = 3;
                    _indexUrl    = 4;
                    _indexRoles  = 5;
                    _indexParent = 6;

                    int iCount = 0;
                    foreach (DataRow dr in reader.Tables[0].Rows)
                    {
                        if (iCount == 0)
                        {
                            _root = CreateSiteMapNodeFromDataRow(dr);
                            AddNode(_root, null);
                        }
                        else
                        {
                            // Create another site map node and
                            // add it to the site map
                            SiteMapNode node =
                                CreateSiteMapNodeFromDataRow(dr);
                            AddNode(node,
                                    GetParentNodeFromDataRow(dr));
                        }
                        iCount++;
                    }
                }
                finally
                {
                    if (reader != null)
                    {
                        reader.Dispose();
                    }
                    reader = null;
                    sSQL   = null;
                }

                // Return the root SiteMapNode
                return(_root);
            }
        }
        protected override void SavePersonalizationBlob
            (WebPartManager webPartManager, string path, string userName,
            byte[] dataBlob)
        {
            System.Data.Odbc.OdbcCommand    updateCommand    = null;
            System.Data.Odbc.OdbcConnection updateConnection = null;
            string sSQL = null;

            try
            {
                sSQL             = "SELECT COUNT(`username`) FROM `personalization` WHERE `username` = '" + userName + "' AND `path` = '" + path + "' and `applicationname` = '" + m_ApplicationName + "';";
                updateConnection = new System.Data.Odbc.OdbcConnection(System.Configuration.ConfigurationManager.ConnectionStrings[m_ConnectionStringName].ToString());
                if (int.Parse(RawDBQuery.ExecuteScalarOnDB(sSQL, System.Configuration.ConfigurationManager.ConnectionStrings[m_ConnectionStringName].ToString()).ToString()) > 0)
                {
                    sSQL          = "UPDATE `personalization` SET `personalizationblob` = ? WHERE `username` = ? AND `applicationname` = ? AND `path` = ?;";
                    updateCommand = new System.Data.Odbc.OdbcCommand(sSQL, updateConnection);
                    updateCommand.Parameters.Clear();
                    updateCommand.Parameters.Add(new System.Data.Odbc.OdbcParameter("personalizationblob", dataBlob));
                    updateCommand.Parameters.Add(new System.Data.Odbc.OdbcParameter("username", userName));
                    updateCommand.Parameters.Add(new System.Data.Odbc.OdbcParameter("applicationname", m_ApplicationName));
                    updateCommand.Parameters.Add(new System.Data.Odbc.OdbcParameter("path", path));
                }
                else
                {
                    sSQL          = "INSERT INTO `personalization` (`username`,`path`,`applicationname`,`personalizationblob`) VALUES (?, ?, ?, ?);";
                    updateCommand = new System.Data.Odbc.OdbcCommand(sSQL, updateConnection);
                    updateCommand.Parameters.Clear();
                    updateCommand.Parameters.Add(new System.Data.Odbc.OdbcParameter("username", userName));
                    updateCommand.Parameters.Add(new System.Data.Odbc.OdbcParameter("path", path));
                    updateCommand.Parameters.Add(new System.Data.Odbc.OdbcParameter("applicationname", m_ApplicationName));
                    updateCommand.Parameters.Add(new System.Data.Odbc.OdbcParameter("personalizationblob", dataBlob));
                }
                updateConnection.Open();
                updateCommand.ExecuteNonQuery();
            }
            finally
            {
                if (updateConnection != null)
                {
                    if (updateConnection.State != System.Data.ConnectionState.Closed)
                    {
                        updateConnection.Close();
                    }
                    else
                    {
                        updateConnection.Dispose();
                    }
                }
                updateConnection = null;
                if (updateCommand != null)
                {
                    updateCommand.Dispose();
                }
                updateCommand = null;
                sSQL          = null;
            }
        }
        protected override void ResetPersonalizationBlob
            (WebPartManager webPartManager, string path, string userName)
        {
            // Delete the specified personalization file
            string sSQL = null;

            try
            {
                sSQL = "DELETE FROM `personalization` WHERE `username` = '" + userName + "' AND `path` = '" + path + "' AND `applicationname` = '" + m_ApplicationName + "';";
                RawDBQuery.ExecuteNonQueryOnDB(sSQL, System.Configuration.ConfigurationManager.ConnectionStrings[m_ConnectionStringName].ToString());
            }
            catch (System.Data.Odbc.OdbcException) { }
        }
        protected override void LoadPersonalizationBlobs
            (WebPartManager webPartManager, string path, string userName,
            ref byte[] sharedDataBlob, ref byte[] userDataBlob)
        {
            // Load shared state
            sharedDataBlob = null;
            userDataBlob   = null;
            object sharedBlobDataObject = null;
            object userBlobDataObject   = null;
            string sSQLShared           = null;
            string sSQLUser             = null;

            try
            {
                sSQLUser = "******" + Environment.NewLine +
                           "WHERE `username` = '" + userName + "' AND " + Environment.NewLine +
                           "`path` = '" + path + "' AND " + Environment.NewLine +
                           "`applicationname` = '" + m_ApplicationName + "';";
                sSQLShared = "SELECT `personalizationblob` FROM `personalization`" + Environment.NewLine +
                             "WHERE `username` IS NULL AND " + Environment.NewLine +
                             "`path` = '" + path + "' AND " + Environment.NewLine +
                             "`applicationname` = '" + m_ApplicationName + "';";
                sharedBlobDataObject = RawDBQuery.ExecuteScalarOnDB(sSQLShared, System.Configuration.ConfigurationManager.ConnectionStrings[m_ConnectionStringName].ToString());
                userBlobDataObject   = RawDBQuery.ExecuteScalarOnDB(sSQLUser, System.Configuration.ConfigurationManager.ConnectionStrings[m_ConnectionStringName].ToString());
                if (sharedBlobDataObject != null)
                {
                    sharedDataBlob =
                        (byte[])sharedBlobDataObject;
                }
                if (userBlobDataObject != null)
                {
                    userDataBlob =
                        (byte[])userBlobDataObject;
                }
            }
            catch (FileNotFoundException)
            {
                // Not an error if file doesn't exist
            }
            finally
            {
                sSQLUser   = null;
                sSQLShared = null;
            }
        }