Panel de discusión – obtener discusiones y mensajes (Got a Match?)

by Nicolás Ferreira 28. June 2008 00:00

A continuación lo que se intenta hacer es interpretar discusiones que pertenezcan a una lista de SharePoint de tipo "Panel de discusión" siguiendo la misma estructura de presentación que nos brinda la vista "Encadenada".

Panel de discusión - obtener discusiones y mensajes (Got a Match?): Vista Encadenada

Investigando saqué las siguientes conclusiones:

1 – El tipo de lista "Panel de discusión" por defecto viene con dos tipos de contenido: "Discusión" y "Mensaje".

Panel de discusión - obtener discusiones y mensajes (Got a Match?): Tipo de contenido Discusión

Panel de discusión - obtener discusiones y mensajes (Got a Match?): Tipo de contenido Mensaje

2 – El tipo de contenido "Discusión" tiene como padre al tipo de contenido "Folder".
3 – Ambos tipos de contenido comparten las columnas "Asunto" y "Cuerpo", la diferencia es que el tipo de contenido "Mensaje" tiene la columna "Asunto" oculta ya que no tiene sentido que una respuesta (o mensaje) tenga asunto.
4 – El campo "ThreadIndex" que está oculto y que pertenece a las listas de tipo "Panel de discusión" contiene el nivel al que pertenece un elemento en la jerarquía discusión/mensajes.
5 – La vista "Encadenada" da la sensación de jerarquía utilizando imágenes cuyo ancho podemos calcular así: ((string)pSPListItem[SPBuiltInFieldId.ThreadIndex]).Length – 46.

    <!-- Discusión - Cuerpo de la discusión. -->
    <img height="1" width="0" alt="" src="/_layouts/images/blank.gif" />
    <!-- 1 -->
    <img height="1" width="10" alt="" src="/_layouts/images/blank.gif" />
    <!-- 1.1 -->
    <img height="1" width="20" alt="" src="/_layouts/images/blank.gif" />
    <!-- 1.1.1 -->
    <img height="1" width="30" alt="" src="/_layouts/images/blank.gif" />
    <!-- 2 -->
    <img height="1" width="10" alt="" src="/_layouts/images/blank.gif" />

La estructura "ThreadIndex" de los elementos que aparecen en la primer imagen se ve así:

0×01CAA77AE5804DE8A753BCA349C89DA0D34D712CF855 – Discusión – Cuerpo de la discusión.
0×01CAA77AE5804DE8A753BCA349C89DA0D34D712CF855000002BA85 – 1
0×01CAA77AE5804DE8A753BCA349C89DA0D34D712CF855000002BA850000016FC8 – 1.1
0×01CAA77AE5804DE8A753BCA349C89DA0D34D712CF855000002BA850000016FC800000142DF – 1.1.1
0×01CAA77AE5804DE8A753BCA349C89DA0D34D712CF8550000073CDB – 2

Se me ocurrió el siguiente modelo:

Panel de discusión - obtener discusiones y mensajes (Got a Match?): Diagrama de clases

Como un panel de discusión por defecto lo único que puede contener son discusiones y mensajes (o respuestas) y dado que una discusión y un mensaje comparten ciertos atributos, la clase "ElementoPanelDeDiscusion" sirve como clase base para "Discusion" y "Mensaje".

Notar que la clase "Discusion" tiene la propiedad "Asunto" mientras que la clase "Mensaje" no la tiene.

La propiedad "Padre" en la clase "Discusion" devuelve null, mientras que en la clase "Mensaje" puede devolver "Discusion" o "Mensaje" (ya que un mensaje puede pertenecer a una discusión o a una respuesta dentro de otra respuesta). Por último, "PanelDeDiscusion" es la clase que hace todo el trabajo.

using System;
using System.Collections.Generic;
using System.Text;
using System.Collections.ObjectModel;

namespace NicolasFerreira.SharePoint
{
    public abstract class ElementoPanelDeDiscusion
    {
        private string _Cuerpo;

        public string Cuerpo
        {
            get { return _Cuerpo; }
        }
        internal List<Mensaje> _Mensajes;

        public ReadOnlyCollection<Mensaje> Mensajes
        {
            get { return _Mensajes.AsReadOnly(); }
        }

        public abstract ElementoPanelDeDiscusion Padre { get; }

        internal string _ThreadIndex;
        internal ElementoPanelDeDiscusion(string pCuerpo)
        {
            _Mensajes = new List<Mensaje>();
            _Cuerpo = pCuerpo;
        }
    }
}

using System;
using System.Collections.Generic;
using System.Text;

namespace NicolasFerreira.SharePoint
{
    public class Discusion : ElementoPanelDeDiscusion
    {
        private string _Asunto;

        public string Asunto
        {
            get { return _Asunto; }
        }
        internal Discusion(string pCuerpo, string pAsunto)
            : base(pCuerpo)
        {
            _Asunto = pAsunto;
        }

        public override ElementoPanelDeDiscusion Padre
        {
            get { return null; }
        }
    }
}

using System;
using System.Collections.Generic;
using System.Text;

namespace NicolasFerreira.SharePoint
{
    public class Mensaje : ElementoPanelDeDiscusion
    {
        internal ElementoPanelDeDiscusion _Padre = null;

        public override ElementoPanelDeDiscusion Padre
        {
            get { return _Padre; }
        }

        internal Mensaje(string pCuerpo)
            : base(pCuerpo)
        {
        }
    }
}

using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.SharePoint;

namespace NicolasFerreira.SharePoint.Listas
{
    /// <summary>
    /// Clase encargada de manipular el tipo de lista "Panel de discusión".
    /// </summary>
    public static class PanelDeDiscusion
    {
        /// <summary>
        /// Método fábrica que devolverá un objeto de tipo Discusion o Mensaje dependiendo de T.
        /// </summary>
        /// <typeparam name="T">Tipo de objeto que se desea obtener. El tipo debe heredar de la clase ElementoPanelDeDiscusion.</typeparam>
        /// <param name="pSPListItem">SPListItem que contiene la información necesaria como para crear el tipo de objeto especificado en T.</param>
        private static T CrearElementoPanelDeDiscusion<T>(SPListItem pSPListItem)
             where T : ElementoPanelDeDiscusion
        {
            ElementoPanelDeDiscusion lElementoPanelDeDiscusion = null;
            if (typeof(T) == typeof(Discusion))
            {
                lElementoPanelDeDiscusion = new Discusion((string)pSPListItem[SPBuiltInFieldId.Body],
                    pSPListItem[SPBuiltInFieldId.Title].ToString());
            }
            else if (typeof(T) == typeof(Mensaje))
            {
                lElementoPanelDeDiscusion = new Mensaje((string)pSPListItem[SPBuiltInFieldId.Body]);
            }
            if (lElementoPanelDeDiscusion != null)
            {
                lElementoPanelDeDiscusion._ThreadIndex = ((string)pSPListItem[SPBuiltInFieldId.ThreadIndex]);
            }
            return lElementoPanelDeDiscusion as T;
        }
        /// <summary>
        /// Método que devolverá todas las discusiones que haya en una lista.
        /// </summary>
        /// <param name="pSPListPanelDeDiscusion">SPList que contiene la información necesaria como para obtener todas las discusiones.</param>
        public static List<SPListItem> ObtenerDiscusiones(SPList pSPListPanelDeDiscusion)
        {
            List<SPListItem> lDiscusiones = new List<SPListItem>();
            /*Para obtener todas las discusiones de la lista,
             * tenemos que utilizar la propiedad Folders de SPList.*/
            foreach (SPListItem lSPListItemDiscusion in pSPListPanelDeDiscusion.Folders)
            {
                lDiscusiones.Add(lSPListItemDiscusion);
            }
            return lDiscusiones;
        }
        /// <summary>
        /// Método que devolverá un objeto de tipo Discusion con la discusión (incluyendo mensajes y mensajes anidados).
        /// </summary>
        /// <param name="pSPListItemDiscusion">SPListItem que contiene la información necesaria de la discusión que queremos interpretar.</param>
        public static Discusion ObtenerDiscusion(SPListItem pSPListItemDiscusion)
        {
            Discusion lDiscusion = null;
            /*Para obtener todos los mensajes (incluidos los anidados) lo hago con un SPQuery y establezco
             * la propiedad Folder al valor de pSPListItemDiscusion.Folder que es la carpeta de la discusión.*/
            SPQuery lSPQuery = new SPQuery();
            lSPQuery.Folder = pSPListItemDiscusion.Folder;
            SPListItemCollection lSPListItemCollection = pSPListItemDiscusion.ParentList.GetItems(lSPQuery);
            List<SPListItem> lSPListItemMensajes = new List<SPListItem>();
            foreach (SPListItem lSPListItemMensaje in lSPListItemCollection)
            {
                lSPListItemMensajes.Add(lSPListItemMensaje);
            }
            lSPListItemMensajes.Sort(new ThreadIndexComparer()); //Ordeno los mensajes.
            lDiscusion = CrearElementoPanelDeDiscusion<Discusion>(pSPListItemDiscusion); //Creo la discusión para luego agregar mensajes.
            Mensaje lMensaje = null; //Lo utilizo para tener como referencia el último mensaje que agregué a una discusión o a un mensaje.
            foreach (SPListItem lSPListItemMensaje in lSPListItemMensajes)
            {
                //ThreadIndex contiene el nivel al que pertenece el mensaje.
                string lThreadIndex = ((string)lSPListItemMensaje[SPBuiltInFieldId.ThreadIndex]);
                if (lMensaje != null)
                /*Si anteriormente agregué un mensaje en alguna parte entonces puede que el
                 * nuevo mensaje tenga relación o no con el agregado.*/
                {
                    bool lContinuar = true;
                    while (lContinuar)
                    {
                        if (lThreadIndex.StartsWith(lMensaje._ThreadIndex))
                        /*Verifico si existe una relación
                         * (esto es posible gracias a la estructura del campo ThreadIndex).*/
                        {
                            /*Como existe una relación con el mensaje agregado anteriormente,
                             * entonces el nuevo mensaje es hijo del anterior.*/
                            Mensaje lNuevoMensaje = CrearElementoPanelDeDiscusion<Mensaje>(lSPListItemMensaje);
                            lNuevoMensaje._Padre = lMensaje; //Le indico al nuevo mensaje que su padre va a ser el agregado anteriormente.
                            lMensaje._Mensajes.Add(lNuevoMensaje);
                            lMensaje = lNuevoMensaje; //¡El nuevo mensaje pasa a ser antiguo!
                            lContinuar = false;
                        }
                        else
                        {
                            /*Como no hay relación entre el mensaje agregado anteriormente y el que intento agregar ahora,
                             * me voy moviendo "hacia atrás" en busca de un mensaje que tenga relación
                             * con el que intento agregar.*/
                            if (lMensaje.Padre is Mensaje)
                            {
                                lMensaje = ((Mensaje)lMensaje.Padre);
                            }
                            else
                            {
                                //Ningún mensaje es padre del mensaje que intento agregar, entonces el mensaje es hijo de la discusión.
                                lMensaje = null;
                                lContinuar = false;
                            }
                        }
                    }
                }
                if (lMensaje == null)
                {
                    lMensaje = CrearElementoPanelDeDiscusion<Mensaje>(lSPListItemMensaje);
                    lDiscusion._Mensajes.Add(lMensaje);
                    lMensaje._Padre = lDiscusion;
                }
            }
            return lDiscusion;
        }
    }
}

using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.SharePoint;

namespace NicolasFerreira.SharePoint
{
    internal class ThreadIndexComparer : IComparer<SPListItem>
    {
        #region IComparer Members

        public int Compare(SPListItem x, SPListItem y)
        {
            string xThreadIndex = ((string)x[SPBuiltInFieldId.ThreadIndex]);
            string yThreadIndex = ((string)y[SPBuiltInFieldId.ThreadIndex]);

            return string.Compare(xThreadIndex, yThreadIndex);
        }

        #endregion
    }
}

Panel de discusión - obtener discusiones y mensajes (Got a Match?): Inspección

Descargar el código.

Tags:

WSS 3.0/MOSS 2007

Comments

7/27/2010 4:30:38 AM #

Hypercom

I know you are using Microsofts BlogEngine.NET but can you please tell me which theme that you are using?  I've been looking all over and wanted one like the one here. I came from wordpress and am trying to figure out BlogEngine.

Hypercom United States | Reply

8/5/2010 1:44:14 AM #

e-cigarette

I like that you've touched on this subject, it's somewhat of a rariety.

e-cigarette United States | Reply

8/11/2010 9:25:48 PM #

Virility Ex

I don’t agree with most folks here; since I started reading this post I couldn't stop until ,  even though it wasn't just what I had been trying to find, was a nice read though. I will immediately grab your RSS feed to maintain informed of any updates.

Virility Ex United States | Reply

8/12/2010 9:16:02 AM #

NABancard

Whats Up
I attempted to sign up to your feed however the link did not work.  I'll come back tomorrow.

NABancard United States | Reply

8/12/2010 3:01:05 PM #

Virility Ex

Hi, maybe I am being some how off topic here, nonetheless I had been reading your site and it appears outstanding!. I’m creating a web site and attempting to make it interesting, however every single time I touch it I screw something up. Did you design and style the website by yourself? Can somebody with very little knowleadge do it, as well as add updates without messing it up? Anyway, info on here, extremely helpful.

Virility Ex United States | Reply

8/12/2010 6:30:27 PM #

my computer is slow

That's news to me; I didn’t know the many ripples and depth to the case until I searched here through Bing! Great job.

my computer is slow United States | Reply

8/12/2010 11:42:18 PM #

Buy Provillus

Thank you for making a sincere effort to explain this. I feel fairly strong about it and would like to read more. If it's OK, as you find out more in depth knowledge, would you mind writing more posts similar to this one with more information?

Buy Provillus United States | Reply

8/13/2010 3:12:11 PM #

how do you get pregnant

In fact, I’m just starting out in marketing media and working on to find out how to do it well - resources like this blog are very helpful. As our website is based in the US, is kind of new to us The case above is something that I worry too well, how to show your own genuine enthusiasm and contribute to the opportunity.

how do you get pregnant United States | Reply

8/13/2010 6:43:21 PM #

make money on the web

Hey, probably I will be a little bit off topic here, however I had been reading your website and it looks great!. I’m creating a blog and attempting to make it appear clean, however every single time I touch it I mess something up. Did you build and style the website by yourself? Can a person with very little technical knowleadge do it, as well as add frequent updates without messing it up? Anyway, info on here, extremely helpful.

make money on the web United States | Reply

8/14/2010 7:17:14 AM #

make money on the web

She is just extraordinary! Everything she touches it turns to gold, so no matter some gossips or fabrications about her, she stays on the top. Way to go girl, the sky is your limit.

make money on the web United States | Reply

8/14/2010 4:51:02 PM #

making money on the web

I differ with most guys here; since I found this post I couldn't stop until I was done, while it wasn't just what I had been looking for, was still a fantastic read though. I will instantly grab your feed to keep in touch of future updates.

making money on the web United States | Reply

8/15/2010 5:57:50 AM #

Venapro

All new to me; I wasn't aware of the many ramifications and depth to this case until I searched here through Bing! Great job.

Venapro United States | Reply

8/18/2010 3:35:22 AM #

how to make a girl squirt

I differ with most folks here; I started reading this blog post I couldn't stop until , although it wasn't just what I had been looking for, was a great read though. I will immediately get your blog feed to keep in touch of coming updates.

how to make a girl squirt United States | Reply

8/18/2010 10:50:59 PM #

Virility Ex Review

Totally new to me; I didn’t know the many ramifications and depth to the case until I surfed here through Google! Good job.

Virility Ex Review United States | Reply

8/19/2010 4:03:57 AM #

venapro

Many resources like the one you just mentioned here will be very helpful to me! I will link to this page on my website. Thank you for posting that link, nevertheless, it appears to be broken.

venapro United States | Reply

8/19/2010 5:07:46 PM #

computer runs slow

Actually, I’m just beginning in marketing media and trying to learn how to do it well - resources like this blog are incredibly helpful. As our Site is based in the US, it’s all a bit new to us. The example mention is something that I worry too well, how to show your own genuine enthusiasm and share to the fact.

computer runs slow United States | Reply

8/24/2010 1:32:22 PM #

how to last longer in bed

In point of fact, I’m just getting my feet wet in management media and trying to find out how to do it well - resources like this blog are a great resource. As our company is based in the US, is kind of new to us The reference mention is something that I worry too well, how to show your own genuine enthusiasm and contribute to the community.

how to last longer in bed United States | Reply

8/24/2010 6:26:47 PM #

Hipolito M. Wiseman

Llegué a este post buscando por Google, de veras de los mejores que he encontrado, información útil.

Hipolito M. Wiseman United States | Reply

8/24/2010 11:35:48 PM #

how to last longer in bed

She is just wonderful! Everything she touches turns to gold, so no matter some chitchats or lies about her, she stays on the top. Way to go girl, we love you

how to last longer in bed United States | Reply

8/25/2010 11:04:10 AM #

how to stop premature ejaculation

I disagree with most guys here; since I found this blog post I couldn't stop until I was done, while it wasn't just what I had been looking for, was indeed a very good read though. I will immediately take your feed to keep in touch of any updates.

how to stop premature ejaculation United States | Reply

8/25/2010 12:09:36 PM #

Interior School

With the economy the way it is, and with the acceptance process being so unpredictable <A href="interiorschool.womandiary.net">interior school</A>, I saw apply to as many schools as you can afford

Interior School United States | Reply

8/25/2010 10:17:13 PM #

make money on the web

In point of fact, I’m just beginning in marketing media and starting to learn how to do it well - resources like this blog post are very helpful. As our company is based in the US, it’s all a bit new to us. The example above is something that I worry about as well, how to show your own genuine enthusiasm and share to the opportunity.

make money on the web United States | Reply

8/26/2010 9:35:15 AM #

why is my computer so slow

Thank you for making the truthful effort to explain this. I feel very strong about it and would like to nkwo more. If you can, as you learn more in depth knowledge, would you mind writing more articles similar to this one with more tips?

why is my computer so slow United States | Reply

8/26/2010 12:42:15 PM #

Vernita Senk

great blog! keep up the great work!

Vernita Senk United States | Reply

8/26/2010 5:48:56 PM #

computer running slow

This is a good point there. I made a investigation on the topic and found many people will agree with your article. Any way I'll be subscribing to your feed and I wish you post again soon.

computer running slow United States | Reply

8/27/2010 2:52:19 AM #

how to last longer in bed

Many resources like the one you mentioned here will be very useful to me! I will link to this blog on my blog. Thanks for posting that link, nonetheless, it appears to be down.

how to last longer in bed United States | Reply

8/27/2010 11:34:52 AM #

how to make a woman squirt

She is just wonderful! Everything she touches turns to gold, so regardless of some rumors or fabrications about her, she remains on the top. So go girl, you're the best

how to make a woman squirt United States | Reply

8/28/2010 3:18:59 AM #

hgh energizer review

I am just getting my feet wet in management media and trying to learn how to do it well - resources like this article are incredibly helpful. As our Site is based in the US, it’s all a bit new to us. The example above is something that I worry too well, how to show your own authentic enthusiasm and contribute to the community.

hgh energizer review United States | Reply

8/29/2010 7:51:36 PM #

provestra

She is just wonderful! Everything she touches converts to gold, so in spite of some rumors or fabrications about her, she remains on the top. So go girl, we love you

provestra United States | Reply

8/29/2010 11:00:55 PM #

Best Smokeless Cigarette

I would like to thank you for the efforts you have made in writing this article. I am hoping the same best work from you in the future as well. In fact your creative writing abilities has inspired me to start my own BlogEngine blog now. Really the blogging is spreading its wings rapidly. Your write up is a fine example of it.

Best Smokeless Cigarette United States | Reply

8/30/2010 2:19:24 AM #

semenax

I disagree with most people here; I started reading this post I couldn't stop until I finished, although it wasn't just what I had been searching for, was still a fantastic read though. I will instantaneously grab your feed to stay in touch of future updates.

semenax United States | Reply

8/30/2010 7:00:58 PM #

bowtrol

In fact, I’m just starting out in marketing media and trying to find out how to do it well - resources like this blog post are a great resource. As our Site is based in the US, it’s all a bit new to us. The reference above is something that I worry about as well, how to show your own authentic enthusiasm and contribute to the community.

bowtrol United States | Reply

8/30/2010 9:23:05 PM #

Sheron Solina

Going to see Skazi Tonight. Its gonna be excellent. There playing with Kyau & Albert. Then next month ill be seeing Richie Hawtin. epic nights ahead

Sheron Solina Ireland | Reply

8/31/2010 11:10:18 PM #

Lemonade Cleansing Diet

Please let me know if you're looking for a writer for your blog. You have some really good articles and I think I would be a good asset.

Lemonade Cleansing Diet United States | Reply

9/1/2010 1:19:17 AM #

internet income

I differ with most guys here; I started reading this blog post I couldn't stop until I was done, while it wasn't just what I had been searching for, was indeed a very good read though. I will immediately grab your RSS feed to maintain informed of any updates.

internet income United States | Reply

9/1/2010 7:26:51 AM #

Girls Cam

We are a group of volunteers and starting a new initiative in a community. Your blog provided us valuable information to work on.You have done a marvellous job!

Girls Cam United States | Reply

9/1/2010 9:24:48 AM #

virility ex review

I am just starting out in management media and working on to find out how to do it well - resources like this blog post are very helpful. As our company is based in the US, it’s all a bit new to us. The reference mention is something that I worry about as well, how to show your own real enthusiasm and contribute to the community.

virility ex review United States | Reply

9/1/2010 4:30:01 PM #

gilt overmantle mirror

Considerably, the post is in reality the finest on that laudable topic. I fit in with your conclusions and can eagerly look forward to your incoming updates. Saying thanks definitely will not simply be acceptable, for the wonderful clarity in your writing. I definitely will at once grab your rss feed to stay privy of any kind of updates. Pleasant work and much success in your business efforts!

gilt overmantle mirror United States | Reply

9/1/2010 8:58:12 PM #

Jilleen

Well, the article is really the sweetest on this noteworthy topic. I agree with your conclusions and will thirstily look forward to your coming updates. Saying thanks will not just be enough, for the wonderful lucidity in your writing. I will right away grab your rss feed to stay abreast of any updates. Good work and much success in your business enterprize!

Jilleen United States | Reply

9/2/2010 2:41:25 AM #

How To Make A Solar Panel

Totally new to me; I wasn't aware of the many ramifications and depth to the case until I searched here through Yahoo! Fantastic job.

How To Make A Solar Panel United States | Reply

9/2/2010 10:16:55 AM #

niche blue print reviews

Thank you for making the sincere effort to explain this. I feel fairly strong about this and would like to nkwo more. If it's OK, as you learn more in depth knowledge, would you mind writing more posts similar to this one with more information?

niche blue print reviews United States | Reply

9/3/2010 5:04:23 AM #

Virility Ex

She is just great! All she touches converts to gold, so regardless of some rumors or fabrications about her, she remains on the top. Way to go girl, you're the best

Virility Ex United States | Reply

9/3/2010 12:31:41 PM #

Virility Ex

She is just great! All she touches it turns to gold, so regardless of some rumors or fabrications about her, she stays on the top. So go girl, the sky is your limit.

Virility Ex United States | Reply

9/4/2010 1:19:07 AM #

satellite tv for pc

I disagree with most guys here; I found this post I couldn't stop until ,  even though it wasn't just what I had been looking for, was indeed a great read though. I will immediately get your RSS feed to stay in touch of future updates.

satellite tv for pc United States | Reply

Add comment


(Will show your Gravatar icon)

  Country flag

biuquote
  • Comment
  • Preview
Loading