Exemplo n.º 1
0
        /// <summary>
        /// Adds a new comment to the database. Does not affect the task
        /// </summary>
        /// <param name="task">
        /// A <see cref="TaskCore"/>
        /// </param>
        /// <param name="comment">
        /// A <see cref="CommentData"/>
        /// </param>
        public static void AddComment(TaskCore task, CommentData comment)
        {
            SqliteCommand cmd = conn.CreateCommand ();
            cmd.CommandText = "INSERT INTO Comments(TaskId, Subject, Author, Message, PostDate) VALUES (@taskid, @subject, @author, @message, @postdate);";
            cmd.Parameters.AddWithValue ("@taskid", task.Id.ToString ());
            cmd.Parameters.AddWithValue ("@subject", comment.Title);
            cmd.Parameters.AddWithValue ("@author", comment.Author);
            cmd.Parameters.AddWithValue ("@message", comment.Content);
            cmd.Parameters.AddWithValue ("@postdate", comment.PostDate.ToString (DateFormat));

            LogQuery (cmd);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Gets the taskcore object from the sqlite cursor
        /// </summary>
        /// <param name="cursor">
        /// A <see cref="SqliteDataReader"/>. This won't be traversed, must be 
        /// called each time the cursor moves ahead
        /// </param>
        /// <returns>
        /// A <see cref="TaskCore"/> - allocated and re-created
        /// Returns null if reading failed
        /// </returns>
        public static TaskCore GetTaskCoreFromCursor(SqliteDataReader cursor)
        {
            // this assumes a single task exists

            // the task to be extracted from the cursor
            TaskCore task = new TaskCore ();

            try {
                task.Id = cursor.GetInt32 (cursor.GetOrdinal ("TaskId"));
                task.Depends = cursor.GetInt32 (cursor.GetOrdinal ("Depends"));
                task.Title = cursor.GetString (cursor.GetOrdinal ("Name"));
                task.Description = cursor.GetString (cursor.GetOrdinal ("Description"));
                task.Priority = cursor.GetInt32 (cursor.GetOrdinal ("Priority"));
                task.DueDate = cursor.GetDateTime (cursor.GetOrdinal ("DueDate"));
                task.CreateDate = cursor.GetDateTime (cursor.GetOrdinal ("CreateDate"));
            } catch {
                log.ERROR ("Reading from cursor failed");
                return null;
            }

            // now, extract the comments.
            SqliteCommand cmd = new SqliteCommand (conn);

            cmd.CommandText = String.Format ("SELECT * FROM Comments WHERE (TaskId = {0});", task.Id);
            log.WARN ("Trying to read comments with query - " + cmd.CommandText);

            SqliteDataReader commentCursor = cmd.ExecuteReader ();

            while (commentCursor.Read ()) {
                CommentData comment = new CommentData ();

                try {
                    comment.Id = commentCursor.GetInt32 (commentCursor.GetOrdinal ("CommentID"));
                    comment.TaskId = commentCursor.GetInt32 (commentCursor.GetOrdinal ("TaskId"));
                    comment.Title = commentCursor.GetString (commentCursor.GetOrdinal ("Subject"));
                    comment.Author = commentCursor.GetString (commentCursor.GetOrdinal ("Author"));
                    comment.Content = commentCursor.GetString (commentCursor.GetOrdinal ("Message"));
                    comment.PostDate = commentCursor.GetDateTime (commentCursor.GetOrdinal ("PostDate"));
                    log.DEBUG ("Extracted comment - " + comment.ToString ());
                } catch {
                    log.ERROR ("Something went wrong while retrieving comment");
                    return null;
                }
                task.Comments.Add (comment);
            }
            log.DEBUG ("Extracted task as : " + task.ToString ());
            return task;
        }
Exemplo n.º 3
0
        /*protected void AddCommentToGui(CommentData comment)
        {
            // create the expander which will contain this
            Expander container = new Gtk.Expander(comment.Author);

            // Create a HBox which will contain the comment entry and buttons
            VBox entryContainer = new VBox();

            // Create a VBox for the subject and comment body
            VBox commentVBox = new VBox();
            Label subjectLabel = new Label("Subject: " + comment.Title);
         TextView commentView = new TextView();
            commentView.Buffer.Text = comment.Content;

            // Make sure that the comment view content is sufficiently large
            commentView.SetSizeRequest(1,100);
            HBox hbox_1 = new HBox();

            Button quoteButton = new Button("Quote");
            Button replyButton = new Button("Reply");

            // Subject | Quote | Reply
            hbox_1.PackStart(subjectLabel, true, false, 0);
            hbox_1.PackStart(quoteButton, true, false, 0);
            hbox_1.PackStart(replyButton, true, false, 0);

            // pack the subject and comment into it
            commentVBox.PackStart(hbox_1, false, true, 0);
            commentVBox.PackStart(commentView, true, true, 0);

            // Pack both the boxes togetherin the entryContainer
            entryContainer.PackStart(commentVBox, true, false, 0);

            // Add the entry container to the main expander widget
            container.Add(entryContainer);

            // Add the main expander to the comment vbox
            // commentVBox.PackStart(container, false, false, 0); //WTF?
            // hook into the Expand event so that we can resize the widget
            container.Activated += ContainerActivated;
        }*/
        protected void AddCommentToGui(CommentData comment)
        {
            // Create a new HBox to hold the subject line and the reply buttons, content, etc
            Label subjectLabel = new Label (comment.Title);
            Button quoteButton = new Button ("Quote");
            Button replyButton = new Button ("Reply");

            // Push the comment with little ">"s to the reply window
            quoteButton.Clicked += delegate(object sender, EventArgs e) { this.AddCommentQuote (comment); };

            replyButton.Clicked += delegate(object sender, EventArgs e) {
                this.AddCommentQuote (comment);
                // set the reply title as "Re:"
                subjectEntry.Text = "Re: " + comment.Title;
            };

            HBox subjectHBox = new HBox ();
            subjectHBox.PackStart (subjectLabel, true, true, 0);
            subjectHBox.PackStart (quoteButton, false, false, 0);
            subjectHBox.PackStart (replyButton, false, false, 0);

            // Create the entry and the VBox to hold the comment together
            TextView iterCommentView = new TextView ();
            iterCommentView.Buffer.Text = comment.Content;
            iterCommentView.HeightRequest = 100;
            iterCommentView.WrapMode = WrapMode.Word;
            iterCommentView.Editable = false;

            VBox iterVBox = new VBox ();
            iterVBox.PackStart (subjectHBox, false, false, 0);
            iterVBox.PackStart (iterCommentView, true, true, 0);

            // Create an expander
            Expander iterContainer = new Expander (comment.Author);

            iterContainer.Add (iterVBox);
            iterContainer.Activated += ContainerActivated;

            iterContainer.ShowAll ();

            commentVBox.PackStart (iterContainer, true, true, 0);
        }
Exemplo n.º 4
0
        void AddCommentButtonClicked(object sender, EventArgs e)
        {
            CommentData comment = new CommentData ();

            // Re-create all the comment information
            comment.Title = subjectEntry.Text;
            comment.Author = "Me";
            // TODO TODO TODO - change this
            comment.Content = commentTextView.Buffer.Text;
            comment.PostDate = DateTime.Now;

            CommentAddedEventArgs args = new CommentAddedEventArgs ();
            args.newComment = comment;

            NewCommentAdded (args);

            // now add the comment to the GUI
            AddCommentToGui (comment);

            // Clear out the reply window
            this.commentTextView.Buffer.Text = "";
            this.subjectEntry.Text = "";
        }
Exemplo n.º 5
0
 protected void AddCommentQuote(CommentData comment)
 {
     // Don't erase the existing comment no matter what.
     // construct a "quoted" reply from the comment
     string quoteString = "\n";
     quoteString += "On " + comment.PostDate.ToString () + ", " + comment.Author + " wrote:";
     string[] commentLines = comment.Content.Split ('\n');
     foreach (string commentLine in commentLines) {
         quoteString += "> " + commentLine + "\n";
     }
     commentTextView.Buffer.Text += quoteString;
 }