示例#1
0
        /// <summary>
        /// Posts a new message to the database
        /// </summary>
        /// <param name="sessionID">The user's current session ID</param>
        /// <param name="title">The title of the message</param>
        /// <param name="message">The message text</param>
        /// <returns>The message ID for the new message</returns>
        private int PostNewMessage(long sessionID, String title, String message)
        {
            int messageID;

            // Create new database object
            spExecution sp = new spExecution();
            sp.SQLConnect();

            // Post new message
            messageID = sp.PostNewMessage(sessionID, title, message);

            sp.SQLDisconnect(); // disconnect from the database

            return messageID;
        }
示例#2
0
        /// <summary>
        /// Posts a new message to the database
        /// </summary>
        /// <param name="sessionID">The user's current session ID</param>
        /// <param name="title">The title of the message</param>
        /// <param name="message">The message text</param>
        /// <returns>The message ID for the new message</returns>
        private int PostNewMessage(long sessionID, String title, String message)
        {
            int messageID;

            // Create new database object
            spExecution sp = new spExecution();

            sp.SQLConnect();

            // Post new message
            messageID = sp.PostNewMessage(sessionID, title, message);

            sp.SQLDisconnect(); // disconnect from the database

            return(messageID);
        }
示例#3
0
        /// <summary>
        /// Returns a new session ID for the user
        /// </summary>
        /// <param name="userName">The user loggin in</param>
        /// <returns>The user's new session ID</returns>
        private long NewSessionID(String userName)
        {
            long sessionID;

            // Create new database object
            spExecution sp = new spExecution();

            sp.SQLConnect();

            // Create new session ID
            sessionID = sp.NewSessionID(userName);

            sp.SQLDisconnect(); // Disconnect from SQL

            return(sessionID);
        }
示例#4
0
        /// <summary>
        /// Validates a current session ID
        /// </summary>
        /// <param name="sessionID">The user's session ID</param>
        /// <returns>TRUE if valid, FALSE if not</returns>
        private bool isValidSessionID(long sessionID)
        {
            // Create new database connection object
            spExecution sp = new spExecution();

            sp.SQLConnect();

            if (sp.ValidateSessionID(sessionID))
            {
                sp.SQLDisconnect(); // Disconnect from SQL
                return(true);
            }
            else
            {
                sp.SQLDisconnect(); // Disconnect from SQL
                return(false);
            }
        }
示例#5
0
        public long UserLogin(String userName, String password)
        {
            // Create new database object
            spExecution sp = new spExecution();
            sp.SQLConnect();

            // Check if the user name & password are valid
            if (sp.ValidateUser(userName, password) == "1")
            {
                sp.SQLDisconnect(); // Disconnect from SQL
                return NewSessionID(userName);
            }
            else
            {
                sp.SQLDisconnect(); // Disconnect from SQL
                return 0L;
            }
        }
示例#6
0
        public long UserLogin(String userName, String password)
        {
            // Create new database object
            spExecution sp = new spExecution();

            sp.SQLConnect();

            // Check if the user name & password are valid
            if (sp.ValidateUser(userName, password) == "1")
            {
                sp.SQLDisconnect(); // Disconnect from SQL
                return(NewSessionID(userName));
            }
            else
            {
                sp.SQLDisconnect(); // Disconnect from SQL
                return(0L);
            }
        }
示例#7
0
        /// <summary>
        /// Adds a media attachment to a message post
        /// </summary>
        /// <param name="sessionID">User's current session ID</param>
        /// <param name="messageID">The message ID to which the media will be attached</param>
        /// <param name="dataType">The type of media being attached</param>
        /// <param name="data">The base64 media data to be written to the drive</param>
        private void PostMsgAttachment(long sessionID, int messageID, String dataType, String data)
        {
            String fileName = "";

            // Create new database object
            spExecution sp = new spExecution();

            sp.SQLConnect();

            // Set up the base directory for where the data will be stored
            String path = @"C:\Inetpub\MessageLogger\message-media\" +
                          sp.GetUserFromSession(sessionID) + @"\" + messageID + @"\";

            Directory.CreateDirectory(path);

            // Setup the file name
            System.Globalization.CultureInfo ci = System.Globalization.CultureInfo.InstalledUICulture;
            fileName += System.DateTime.Now.ToString("yyyy_mm_dd-hh_mm_ss_fff", ci);

            // Disconnect and reconnect to clear the SQL command
            sp.SQLDisconnect();
            sp.SQLConnect();

            // Post the data to the database
            sp.PostMsgAttachment(sessionID, messageID, dataType, path + fileName);
            sp.SQLDisconnect();

            // Convert the base64 string to a byte array
            byte[] dataBytes = Convert.FromBase64String(data);

            // Create the appropriate filename
            if (dataType == "jpeg-image")
            {
                fileName += ".jpg";
            }
            if (dataType == "png-image")
            {
                fileName += ".jpg";
            }
            else if (dataType == "gif-image")
            {
                fileName += ".gif";
            }
            else if (dataType == "mpeg-video")
            {
                fileName += ".mpg";
            }
            else if (dataType == "wmv-video")
            {
                fileName += ".wmv";
            }
            else if (dataType == "wav-sound")
            {
                fileName += ".wav";
            }

            // Write the file to the drive
            FileStream   fs     = new FileStream(path + fileName, FileMode.Create, FileAccess.Write);
            BinaryWriter writer = new BinaryWriter(fs);

            try
            {
                for (int i = 0; i < dataBytes.Length; i++)
                {
                    writer.Write(dataBytes[i]);
                }
            }
            finally
            {
                writer.Close();
                fs.Close();
            }
        }
示例#8
0
        /// <summary>
        /// Adds a media attachment to a message post
        /// </summary>
        /// <param name="sessionID">User's current session ID</param>
        /// <param name="messageID">The message ID to which the media will be attached</param>
        /// <param name="dataType">The type of media being attached</param>
        /// <param name="data">The base64 media data to be written to the drive</param>
        private void PostMsgAttachment(long sessionID, int messageID, String dataType, String data)
        {
            String fileName = "";

            // Create new database object
            spExecution sp = new spExecution();
            sp.SQLConnect();

            // Set up the base directory for where the data will be stored
            String path = @"C:\Inetpub\MessageLogger\message-media\" +
							sp.GetUserFromSession(sessionID) + @"\" + messageID + @"\";
							
            Directory.CreateDirectory(path);

            // Setup the file name
            System.Globalization.CultureInfo ci = System.Globalization.CultureInfo.InstalledUICulture;
            fileName += System.DateTime.Now.ToString("yyyy_mm_dd-hh_mm_ss_fff", ci);

            // Disconnect and reconnect to clear the SQL command
            sp.SQLDisconnect();
            sp.SQLConnect();

            // Post the data to the database
            sp.PostMsgAttachment(sessionID, messageID, dataType, path + fileName);
            sp.SQLDisconnect();

            // Convert the base64 string to a byte array
            byte[] dataBytes = Convert.FromBase64String(data);

            // Create the appropriate filename
            if (dataType == "jpeg-image")
            {
                fileName += ".jpg";
            }
            if (dataType == "png-image")
            {
                fileName += ".jpg";
            }
            else if (dataType == "gif-image")
            {
                fileName += ".gif";
            }
            else if (dataType == "mpeg-video")
            {
                fileName += ".mpg";
            }
            else if (dataType == "wmv-video")
            {
                fileName += ".wmv";
            }
            else if (dataType == "wav-sound")
            {
                fileName += ".wav";
            }

            // Write the file to the drive
            FileStream fs = new FileStream(path + fileName, FileMode.Create, FileAccess.Write);
            BinaryWriter writer = new BinaryWriter(fs);

            try
            {
                for (int i = 0; i < dataBytes.Length; i++)
                {
                    writer.Write(dataBytes[i]);
                }
            }
            finally
            {
                writer.Close();
                fs.Close();
            }
        }
示例#9
0
        /// <summary>
        /// Validates a current session ID
        /// </summary>
        /// <param name="sessionID">The user's session ID</param>
        /// <returns>TRUE if valid, FALSE if not</returns>
        private bool isValidSessionID(long sessionID)
        {
            // Create new database connection object
            spExecution sp = new spExecution();
            sp.SQLConnect();

            if (sp.ValidateSessionID(sessionID))
            {
                sp.SQLDisconnect(); // Disconnect from SQL
                return true;
            }
            else
            {
                sp.SQLDisconnect(); // Disconnect from SQL
                return false;
            }
        }
示例#10
0
        /// <summary>
        /// Returns a new session ID for the user
        /// </summary>
        /// <param name="userName">The user loggin in</param>
        /// <returns>The user's new session ID</returns>
        private long NewSessionID(String userName)
        {
            long sessionID;

            // Create new database object
            spExecution sp = new spExecution();
            sp.SQLConnect();

            // Create new session ID
            sessionID = sp.NewSessionID(userName);

            sp.SQLDisconnect(); // Disconnect from SQL

            return sessionID;
        }