Logo Search packages:      
Sourcecode: gdata-sharp version File versions  Download package

evententry.cs

/* Copyright (c) 2006-2008 Google Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
*/
/* Change history
* Oct 13 2008  Joe Feser       joseph.feser@gmail.com
* Converted ArrayLists and other .NET 1.1 collections to use Generics
* Combined IExtensionElement and IExtensionElementFactory interfaces
* 
*/
using System;
using System.Xml;
using System.IO; 
using System.Collections;
using Google.GData.Client;
using Google.GData.Extensions;

namespace Google.GData.Calendar {


    // a few new subelements

    //////////////////////////////////////////////////////////////////////
    /// <summary>subelements definition for the event entry thar are calendar specific
    /// </summary> 
    //////////////////////////////////////////////////////////////////////
00037     public class GCalNameTable
    {
        /// <summary>syncEvent</summary>
00040         public const string XmlSyncEventElement = "syncEvent"; 
        /// <summary>sequence element</summary>
00042         public const string XmlSequenceElement = "sequence"; 
        /// <summary>uid element</summary>
00044         public const string XmlUidElement = "uid"; 
    }
    //end of public class GCalEventTable


     /// <summary>
    /// Indicates whether this is a sync scenario where we allow setting the gCal:uid, the gCal:sequence, 
    /// and the organizer of an event. This element makes sense only when inserting and updating
    ///  events. This element should primarily be used in a sync scenario.
    /// </summary>
00054     public class GCalSyncEvent : SimpleAttribute
    {
        /// <summary>
        /// default calendar access level constructor
        /// </summary>        
00059         public GCalSyncEvent()
            : base(GCalNameTable.XmlSyncEventElement, GDataParserNameTable.gCalPrefix, 
              GDataParserNameTable.NSGCal)
        {
        }

        /// <summary>
        /// default calendar acccess level
        ///  constructor with an initial value
        /// </summary>
        /// <param name="initValue"></param>
00070         public GCalSyncEvent(string initValue)
            : base(GCalNameTable.XmlSyncEventElement, GDataParserNameTable.gCalPrefix, 
            GDataParserNameTable.NSGCal, initValue)
        {
        }
    }

     /// <summary>
    /// Indicates the globally unique identifier (UID) of the event as defined in Section 4.8.4.7 of RFC 2445.
    /// </summary>
00080     public class GCalUid : SimpleAttribute
    {
        /// <summary>
        /// default calendar access level constructor
        /// </summary>        
00085         public GCalUid()
            : base(GCalNameTable.XmlUidElement, GDataParserNameTable.gCalPrefix, 
              GDataParserNameTable.NSGCal)
        {
        }

        /// <summary>
        /// default calendar acccess level
        ///  constructor with an initial value
        /// </summary>
        /// <param name="initValue"></param>
00096         public GCalUid(string initValue)
            : base(GCalNameTable.XmlUidElement, GDataParserNameTable.gCalPrefix, 
            GDataParserNameTable.NSGCal, initValue)
        {
        }
    }


    /// <summary>
    /// Indicates the revision sequence number of the event as defined in Section 4.8.7.4 of RFC 2445. Must be non-negative.
    /// </summary>
00107     public class GCalSequence : SimpleAttribute
    {
        /// <summary>
        /// default calendar access level constructor
        /// </summary>        
00112         public GCalSequence()
            : base(GCalNameTable.XmlSequenceElement, GDataParserNameTable.gCalPrefix, 
              GDataParserNameTable.NSGCal)
        {
        }

        /// <summary>
        /// default calendar acccess level
        ///  constructor with an initial value
        /// </summary>
        /// <param name="initValue"></param>
00123         public GCalSequence(string initValue)
            : base(GCalNameTable.XmlSequenceElement, GDataParserNameTable.gCalPrefix, 
            GDataParserNameTable.NSGCal, initValue)
        {
        }
    }


    //////////////////////////////////////////////////////////////////////
    /// <summary>
    /// Entry API customization class for defining entries in an Event feed.
    /// </summary>
    //////////////////////////////////////////////////////////////////////
00136     public class EventEntry : AbstractEntry
    {


        /// <summary>
        /// Category used to label entries that contain Event extension data.
        /// </summary>
00143         public static AtomCategory EVENT_CATEGORY =
        new AtomCategory(GDataParserNameTable.Event, new AtomUri(BaseNameTable.gKind));

        /// <summary>
        /// Constructs a new EventEntry instance with the appropriate category
        /// to indicate that it is an event.
        /// </summary>
00150         public EventEntry()
        : base()
        {
            Categories.Add(EVENT_CATEGORY);
            addEventEntryExtensions();
        }

        /// <summary>
        /// Constructs a new EventEntry instance with provided data.
        /// </summary>
        /// <param name="title">The descriptive title of the event ("What" in the UI)</param>
00161         public EventEntry(string title) : this()
        {
            this.Title.Text = title;
        }

        /// <summary>
        /// Constructs a new EventEntry instance with provided data.
        /// </summary>
        /// <param name="title">The descriptive title of the event ("What" in the UI)</param>
        /// <param name="description">A longer description of the event 
        /// ("Description" in the UI)</param>
00172         public EventEntry(string title, string description) : this(title)
        {
            this.Content.Content = description;
        }

        /// <summary>
        /// Constructs a new EventEntry instance with provided data.
        /// </summary>
        /// <param name="title">The descriptive title of the event ("What" in the UI)</param>
        /// <param name="description">A longer description of the event 
        /// ("Description" in the UI)</param>
        /// <param name="location">The location of the event ("Where" in the UI)</param>
00184         public EventEntry(string title, string description, string location)
            : this(title, description)
        {
            Where eventLocation = new Where();
            eventLocation.ValueString = location;
            this.Locations.Add(eventLocation);
            
        }

        /// <summary>
        ///  helper method to add extensions to the evententry
        /// </summary>
00196         private void addEventEntryExtensions()
        {
            this.AddExtension(new Reminder());
            this.AddExtension(new Where());
            this.AddExtension(new Who());
            this.AddExtension(new When());
            this.AddExtension(new OriginalEvent());
            this.AddExtension(new SendNotifications());
            this.AddExtension(new Transparency());
            this.AddExtension(new Visibility());
            this.AddExtension(new EventStatus());
            this.AddExtension(new RecurrenceException());
            this.AddExtension(new Comments());
            this.AddExtension(new ExtendedProperty());
            this.AddExtension(new Recurrence());
            this.AddExtension(new GCalSequence());
            this.AddExtension(new GCalUid());
            this.AddExtension(new GCalSyncEvent());
        }

        /// <summary>
        /// Constructs a new EventStatus  instance
        /// </summary>
00219         public class EventStatus : EnumConstruct
        {
            /// <summary>
            ///  default constructor
            /// </summary>
00224             public EventStatus()
            : base(GDataParserNameTable.XmlEventStatusElement)
            {
            }

            /// <summary>
            ///  EventStatus constructor 
            /// </summary>
            /// <param name="value">indicates the default status</param>
00233             public EventStatus(string value)
            : base(GDataParserNameTable.XmlEventStatusElement, value)
            {
            }
            /// <summary>string constant for a confirmed event</summary>
00238             public const string CONFIRMED_VALUE = BaseNameTable.gNamespacePrefix + "event.confirmed";
            /// <summary>string constant for a tentative accepted event</summary>
00240             public const string TENTATIVE_VALUE = BaseNameTable.gNamespacePrefix + "event.tentative";
            /// <summary>string constant for a cancelled event</summary>
00242             public const string CANCELED_VALUE = BaseNameTable.gNamespacePrefix + "event.canceled";

            /// <summary>EventStatus constant for a confirmed event</summary>
00245             public static EventStatus CONFIRMED = new EventStatus(CONFIRMED_VALUE);
            /// <summary>EventStatus constant for a tentative event</summary>
00247             public static EventStatus TENTATIVE = new EventStatus(TENTATIVE_VALUE);
            /// <summary>EventStatus constant for a Cancelled  event</summary>
00249             public static EventStatus CANCELED = new EventStatus(CANCELED_VALUE);
        }

        /// <summary>
        /// Visibility class indicates the visibility of an eventNode
        /// </summary>
00255         public class Visibility : EnumConstruct
        {
            /// <summary>
            ///  default constructor
            /// </summary>
00260             public Visibility()
            : base(GDataParserNameTable.XmlVisibilityElement)
            {
            }

            /// <summary>
            ///  Visibility constructor with a string to indicate default value
            /// </summary>
            /// <param name="value">the default visibility value</param>
00269             public Visibility(string value)
            : base(GDataParserNameTable.XmlVisibilityElement, value)
            {
            }

            /// <summary>string constant for the default visibility value</summary>
00275             public const string DEFAULT_VALUE = BaseNameTable.gNamespacePrefix + "event.default";
            /// <summary>string constant for the public visibility value</summary>
00277             public const string PUBLIC_VALUE = BaseNameTable.gNamespacePrefix + "event.public";
            /// <summary>string constant for the confidential visibility value</summary>
00279             public const string CONFIDENTIAL_VALUE = BaseNameTable.gNamespacePrefix + "event.confidential";
            /// <summary>string constant for the private visibility value</summary>
00281             public const string PRIVATE_VALUE = BaseNameTable.gNamespacePrefix + "event.private";

            /// <summary>object constant for the private visibility value</summary>
00284             public static Visibility DEFAULT = new Visibility(DEFAULT_VALUE);
            /// <summary>object constant for the private visibility value</summary>
00286             public static Visibility PUBLIC = new Visibility(PUBLIC_VALUE);
            /// <summary>object constant for the private visibility value</summary>
00288             public static Visibility CONFIDENTIAL = new Visibility(CONFIDENTIAL_VALUE);
            /// <summary>object constant for the private visibility value</summary>
00290             public static Visibility PRIVATE = new Visibility(PRIVATE_VALUE);
        }

        /// <summary>
        ///  the Transparency of an event class
        /// </summary>
00296         public class Transparency : EnumConstruct
        {
            /// <summary>
            ///  default constructor
            /// </summary>
00301             public Transparency()
            : base(GDataParserNameTable.XmlTransparencyElement)
            {
            }

            /// <summary>
            ///  constructor with a default string value
            /// </summary>
            /// <param name="value">transparency value</param>
00310             public Transparency(string value)
            : base(GDataParserNameTable.XmlTransparencyElement, value)
            {
            }

            /// <summary>string constant for the opaque transparency value</summary>
00316             public const string OPAQUE_VALUE = BaseNameTable.gNamespacePrefix + "event.opaque";
            /// <summary>string constant for the transparent trancparency value</summary>
00318             public const string TRANSPARENT_VALUE = BaseNameTable.gNamespacePrefix + "event.transparent";

            /// <summary>object constant for the opaque transparency value</summary>
00321             public static Transparency OPAQUE = new Transparency(OPAQUE_VALUE);
            /// <summary>object constant for the transparent transparency value</summary>
00323             public static Transparency TRANSPARENT = new Transparency(TRANSPARENT_VALUE);
        }

        /// <summary>
        ///  indicates if an eventupdate should reissue notifications
        /// false by default
        /// </summary>
00330         public class SendNotifications : EnumConstruct
        {
            /// <summary>
            ///  default constructor
            /// </summary>
00335             public SendNotifications()
            : base(GDataParserNameTable.XmlSendNotificationsElement,
                   GDataParserNameTable.gCalPrefix,
                   GDataParserNameTable.NSGCal)
            {
            }

            /// <summary>
            ///  constructor with a default string value
            /// </summary>
            /// <param name="value">transparency value</param>
00346             public SendNotifications(string value)
            : base(GDataParserNameTable.XmlSendNotificationsElement,
                   GDataParserNameTable.gCalPrefix,
                   GDataParserNameTable.NSGCal, value)
            {
            }
        }

         /// <summary>
        ///  indicates if this new entry should be a quickadd
        /// false by default
        /// </summary>
00358         public class QuickAddElement : EnumConstruct
        {
            /// <summary>
            ///  default constructor
            /// </summary>
00363             public QuickAddElement()
            : base(GDataParserNameTable.XmlQuickAddElement,
                   GDataParserNameTable.gCalPrefix,
                   GDataParserNameTable.NSGCal)
            {
            }

            /// <summary>
            ///  constructor with a default string value
            /// </summary>
            /// <param name="value">transparency value</param>
00374             public QuickAddElement(string value)
            : base(GDataParserNameTable.XmlQuickAddElement, value)
            {
            }
        }



#region EventEntry Attributes

        private ExtensionCollection<When> times;
        private ExtensionCollection<Where> locations;
        private ExtensionCollection<Who> participants;
#endregion

#region Public Methods
        /// <summary>
        ///  property accessor for the WhenCollection
        /// </summary>
        public ExtensionCollection<When> Times
00394         {
            get 
            {
                if (this.times == null)
                {
                    this.times = new ExtensionCollection<When>(this);
                }
                return this.times;
            }
        }

        /// <summary>
        ///  property accessor for the WhereCollection
        /// </summary>
        public ExtensionCollection<Where> Locations
00409         {
            get 
            {
                if (this.locations == null)
                {
                    this.locations = new ExtensionCollection<Where>(this);
                }
                return this.locations;
            }
        }

        /// <summary>
        ///  property accessor for the whos in the event
        /// </summary>
        public ExtensionCollection<Who> Participants
00424         {
            get 
            {
                if (this.participants == null)
                {
                    this.participants = new ExtensionCollection<Who>(this); 
                }
                return this.participants;
            }
        }


        /// <summary>
        ///  property accessor for the Eventnotifications
        ///  set this to True for notfications to be send 
        /// </summary>
        public bool Notifications
00441         {
            get 
            { 
                SendNotifications n = FindExtension(GDataParserNameTable.XmlSendNotificationsElement,
                                     GDataParserNameTable.NSGCal) as SendNotifications;

                if (n == null)
                {
                    return false;
                }
                return n.Value == Utilities.XSDTrue; 
            }
            set
            {
                SendNotifications n = FindExtension(GDataParserNameTable.XmlSendNotificationsElement,
                                     GDataParserNameTable.NSGCal) as SendNotifications;
                if (value == true)
                {
                    if (n == null)
                    {
                        n = new SendNotifications(); 
                        ExtensionElements.Add(n);
                    }
                    n.Value = Utilities.XSDTrue;
                }
                else 
                {
                    if (n != null)
                    {
                        DeleteExtensions(GDataParserNameTable.XmlSendNotificationsElement,
                                     GDataParserNameTable.NSGCal);
                    }
                }
            }
        }


        /// <summary>
        ///  property accessor QuickAdd
        /// To create an event using Google Calendar's quick add feature, set the event 
        /// entry's content to the quick add string you'd like to use. Then add a 
        /// gCal:quickadd element with a value attribute set to true
        /// </summary>
        public bool QuickAdd
00485         {
            get 
            { 
                QuickAddElement q = FindExtension(GDataParserNameTable.XmlQuickAddElement,
                                     GDataParserNameTable.NSGCal) as QuickAddElement;

                if (q == null)
                {
                    return false;
                }
                return q.Value == Utilities.XSDTrue; 
            }
            set
            {
                QuickAddElement q = FindExtension(GDataParserNameTable.XmlQuickAddElement,
                                     GDataParserNameTable.NSGCal) as QuickAddElement;
                if (value == true)
                {
                    if (q == null)
                    {
                        q = new QuickAddElement(); 
                        ExtensionElements.Add(q);
                    }
                    q.Value = Utilities.XSDTrue;
                }
                else 
                {
                    if (q != null)
                    {
                        DeleteExtensions(GDataParserNameTable.XmlQuickAddElement,
                                     GDataParserNameTable.NSGCal);
                    }
                }
            }
        }



        /// <summary>
        ///  property accessor for the EventStatus
        /// </summary>
        public EventStatus Status
00527         {
            get 
            { 
                return FindExtension(GDataParserNameTable.XmlEventStatusElement,
                                     GDataParserNameTable.gNamespace) as EventStatus;
            }
            set
            {
                ReplaceExtension(GDataParserNameTable.XmlEventStatusElement,
                                     GDataParserNameTable.gNamespace, value);
            }
        }


        /// <summary>
        ///  property accessor for the Event Visibility 
        /// </summary>
        public Visibility EventVisibility
00545         {
            get 
            { 
                return FindExtension(GDataParserNameTable.XmlVisibilityElement,
                                     GDataParserNameTable.gNamespace) as Visibility;
            }
            set
            {
                ReplaceExtension(GDataParserNameTable.XmlVisibilityElement,
                                     GDataParserNameTable.gNamespace, value);
            }
        }

        /// <summary>
        ///  property accessor for the EventTransparency
        /// </summary>
        public Transparency EventTransparency
00562         {
            get 
            { 
                return FindExtension(GDataParserNameTable.XmlTransparencyElement,
                                     GDataParserNameTable.gNamespace) as Transparency;
            }
            set
            {
                ReplaceExtension(GDataParserNameTable.XmlTransparencyElement,
                                     GDataParserNameTable.gNamespace, value);
            }
        }

        /// <summary>
        ///  property accessor for the Recurrence
        /// </summary>
        public Recurrence Recurrence
00579         {
            get 
            { 
                return FindExtension(GDataParserNameTable.XmlRecurrenceElement,
                                     GDataParserNameTable.gNamespace) as Recurrence;
            }
            set
            {
                ReplaceExtension(GDataParserNameTable.XmlRecurrenceElement,
                                     GDataParserNameTable.gNamespace, value);
            }
        }

      /// <summary>
      ///  property accessor for the RecurrenceException
      /// </summary>
      public RecurrenceException RecurrenceException
00596       {
            get 
            { 
                return FindExtension(GDataParserNameTable.XmlRecurrenceExceptionElement,
                                     GDataParserNameTable.gNamespace) as RecurrenceException;
            }
            set
            {
                ReplaceExtension(GDataParserNameTable.XmlRecurrenceExceptionElement,
                                     GDataParserNameTable.gNamespace, value);
            }
      }

        /// <summary>
        /// property accessor for the OriginalEvent
        /// </summary>
        public OriginalEvent OriginalEvent
00613         {
            get 
            { 
                return FindExtension(GDataParserNameTable.XmlOriginalEventElement,
                                     GDataParserNameTable.gNamespace) as OriginalEvent;
            }
            set
            {
                ReplaceExtension(GDataParserNameTable.XmlOriginalEventElement,
                                     GDataParserNameTable.gNamespace, value);
            }
        }

        /// <summary>
        ///  property accessor for the Comments
        /// </summary>
        public Comments Comments
00630         {
            get 
            { 
                return FindExtension(GDataParserNameTable.XmlCommentsElement,
                                 GDataParserNameTable.gNamespace) as Comments;
            }
            set
            {
                ReplaceExtension(GDataParserNameTable.XmlCommentsElement,
                                     GDataParserNameTable.gNamespace, value);
            }
        }


        /// <summary>
        /// returns the first reminder of the Times collection
        /// </summary>
        /// <returns>When object for the reminder or NULL</returns>
00648         protected When GetFirstReminder()
        {
            return this.Times != null && this.Times.Count > 0 ? this.Times[0] : null; 
        }


        /// <summary>
        /// returns the FIRST reminder for backwards compatibility
        /// if set, will REMOVE all reminders, but this one (array of one)
        /// </summary>
        public Reminder Reminder 
00659         {
            get 
            {
                if (this.Reminders != null && this.Reminders.Count > 0)
                {
                    return this.Reminders[0];
                }
                return null;
            }
            set 
            {
                this.Reminders.Clear();
                if (value != null)
                {
                    this.Reminders.Add(value);
                }
            }
        }

        /// <summary>
        /// property accessor for the Reminder
        /// </summary>
        public ExtensionCollection<Reminder> Reminders
00682         {
            get 
            { 
                // if we are a recurrent event, reminder is on the entry/toplevel
                if (this.Recurrence != null)
                {
                    //TODO could not get the generic overload to work. we for now just copy the list a few times.
                    ExtensionList list = new ExtensionList(this);

                    FindExtensions(GDataParserNameTable.XmlReminderElement,
                                      BaseNameTable.gNamespace, list);

                    ExtensionCollection<Reminder> collection = new ExtensionCollection<Reminder>(this);
                    foreach (Reminder var in list)
                    {
                        collection.Add(var);
                    }

                    return collection;
                } 
                else
                {
                    // in the non recurrent case, it's on the first when element
                    When w = GetFirstReminder(); 
                    if (w != null)
                    {
                        return w.Reminders; 
                    }
                }
                return null; 
            }
        }

        /// <summary>
        /// as eventId is a commonly used part in the calendar world, we expose it
        /// here. In general the EventId is the last part of the AtomId
        /// </summary>
        public string EventId 
00720         {
            get 
            {
                string[] elements = this.Id.AbsoluteUri.Split(new char[] {'/'});
                if (elements != null && elements.Length > 0)
                {
                    return elements[elements.Length - 1];
                }
                return null;
            }
        }


        /// <summary>
        /// Property to retrieve/set an associated WebContentLink
        /// </summary>
        public WebContentLink WebContentLink
00737         {
            get
            {
                return this.Links.FindService(WebContentLink.WEB_CONTENT_REL, 
                    null) as WebContentLink;
            }
            set
            {
                this.Links.Add(value);
            }
        }


        /// <summary>
        ///  property accessor for the SyncEvent element
        /// </summary>
        public GCalSyncEvent  SyncEvent
00754         {
            get 
            { 
                return FindExtension(GCalNameTable.XmlSyncEventElement,
                                     GDataParserNameTable.NSGCal) as GCalSyncEvent;
            }
            set
            {
                ReplaceExtension(GCalNameTable.XmlSyncEventElement,
                                     GDataParserNameTable.NSGCal, value);
            }
        }

        /// <summary>
        ///  property accessor for the uid element
        /// </summary>
        public GCalUid  Uid
00771         {
            get 
            { 
                return FindExtension(GCalNameTable.XmlUidElement,
                                     GDataParserNameTable.NSGCal) as GCalUid;
            }
            set
            {
                ReplaceExtension(GCalNameTable.XmlUidElement,
                                     GDataParserNameTable.NSGCal, value);
            }
        }
                /// <summary>
        ///  property accessor for the SyncEvent element
        /// </summary>
        public GCalSequence  Sequence
00787         {
            get 
            { 
                return FindExtension(GCalNameTable.XmlSequenceElement,
                                     GDataParserNameTable.NSGCal) as GCalSequence;
            }
            set
            {
                ReplaceExtension(GCalNameTable.XmlSequenceElement,
                                     GDataParserNameTable.NSGCal, value);
            }
        }



#endregion

        /// <summary>
        /// this is the subclassing method for AtomBase derived 
        /// classes to overload what childelements should be created
        /// needed to create CustomLink type objects, like WebContentLink etc
        /// </summary>
        /// <param name="reader">The XmlReader that tells us what we are working with</param>
        /// <param name="parser">the parser is primarily used for nametable comparisons</param>
        /// <returns>AtomBase</returns>
00812         public override AtomBase CreateAtomSubElement(XmlReader reader, AtomFeedParser parser)
        {
            Object localname = reader.LocalName;

            if ((localname.Equals(parser.Nametable.Link)))
            {
                if (reader.GetAttribute(GDataParserNameTable.XmlAttributeRel) == 
                    WebContentLink.WEB_CONTENT_REL)
                {
                    return new WebContentLink(false);
                }
            }
            return base.CreateAtomSubElement(reader, parser);
            
        }
    }
}




Generated by  Doxygen 1.6.0   Back to index