eventquery.cs :  » Network-Clients » RemoteCalendars » Google » GData » Calendar » C# / CSharp Open Source

Home
C# / CSharp Open Source
1.2.6.4 mono .net core
2.2.6.4 mono core
3.Aspect Oriented Frameworks
4.Bloggers
5.Build Systems
6.Business Application
7.Charting Reporting Tools
8.Chat Servers
9.Code Coverage Tools
10.Content Management Systems CMS
11.CRM ERP
12.Database
13.Development
14.Email
15.Forum
16.Game
17.GIS
18.GUI
19.IDEs
20.Installers Generators
21.Inversion of Control Dependency Injection
22.Issue Tracking
23.Logging Tools
24.Message
25.Mobile
26.Network Clients
27.Network Servers
28.Office
29.PDF
30.Persistence Frameworks
31.Portals
32.Profilers
33.Project Management
34.RSS RDF
35.Rule Engines
36.Script
37.Search Engines
38.Sound Audio
39.Source Control
40.SQL Clients
41.Template Engines
42.Testing
43.UML
44.Web Frameworks
45.Web Service
46.Web Testing
47.Wiki Engines
48.Windows Presentation Foundation
49.Workflows
50.XML Parsers
C# / C Sharp
C# / C Sharp by API
C# / CSharp Tutorial
C# / CSharp Open Source » Network Clients » RemoteCalendars 
RemoteCalendars » Google » GData » Calendar » eventquery.cs
/* Copyright (c) 2006 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.
*/

using System;
using System.Xml;
using System.Text;
using System.Globalization;
using System.Diagnostics;
using Google.GData.Client;

namespace Google.GData.Calendar{

    //////////////////////////////////////////////////////////////////////
    /// <summary>Enum to describe the different sort orders
    /// </summary> 
    //////////////////////////////////////////////////////////////////////
    public enum CalendarSortOrder
    {
        /// <summary> do not create the parameter, do whatever the server does</summary>
        serverDefault,
        /// <summary>sort in ascending order</summary>
        ascending,                       
        /// <summary>sort in descending order</summary>
        descending
    }
    /////////////////////////////////////////////////////////////////////////////


    //////////////////////////////////////////////////////////////////////
    /// <summary>
    /// A subclass of FeedQuery, to create a Calendar query URI.
    /// Provides public properties that describe the different
    /// aspects of the URI, as well as a composite URI.
    /// </summary> 
    //////////////////////////////////////////////////////////////////////
    public class EventQuery : FeedQuery
    {

        public EventQuery()
        : base()
        {
            this.sortOrder = CalendarSortOrder.serverDefault; 
            this.singleEvents = false;
            this.futureEvents = false;
        }

        private DateTime startTime;
        private DateTime endTime;
        private DateTime recurrenceStart;
        private DateTime recurrenceEnd;
        private CalendarSortOrder sortOrder;
        private bool singleEvents;
        private bool futureEvents;


        //////////////////////////////////////////////////////////////////////
        /// <summary>indicates the sortorder of the returned feed</summary> 
        /// <returns> </returns>
        //////////////////////////////////////////////////////////////////////
        public CalendarSortOrder SortOrder
        {
            get {return this.sortOrder;}
            set {this.sortOrder = value;}
        }
        // end of accessor public CalendarSortOrder SortOrder


        //////////////////////////////////////////////////////////////////////
        /// <summary>Decides wether recurring events should be expanded or not</summary> 
        /// <returns> </returns>
        //////////////////////////////////////////////////////////////////////
        public bool SingleEvents
        {
            get {return this.singleEvents;}
            set {this.singleEvents = value;}
        }
        // end of accessor public bool SingleEvents


        //////////////////////////////////////////////////////////////////////
        /// <summary>Decides wether events in the past should be returned. Defa</summary> 
        /// <returns> </returns>
        //////////////////////////////////////////////////////////////////////
        public bool FutureEvents
        {
            get {return this.futureEvents;}
            set {this.futureEvents = value;}
        }
        // end of accessor public bool FutureEvents



        /// <summary>
        ///  Accessor method for StartTime
        /// </summary>
        public DateTime StartTime
        {
            get { return startTime;}
            set { startTime = value;}
        }


        /// <summary>
        ///  Accessor method for EndTime
        /// </summary>
        public DateTime EndTime
        {
            get { return endTime;}
            set { endTime = value;}
        }


        /// <summary>
        ///  Accessor method for RecurrenceStart
        /// </summary>
        public DateTime RecurrenceStart
        {
            get { return recurrenceStart;}
            set { recurrenceStart = value;}
        }


        /// <summary>
        ///  Accessor method for RecurrenceEnd
        /// </summary>
        public DateTime RecurrenceEnd
        {
            get { return recurrenceEnd;}
            set { recurrenceEnd = value;}
        }

        //////////////////////////////////////////////////////////////////////
        /// <summary>protected void ParseUri</summary> 
        /// <param name="targetUri">takes an incoming Uri string and parses all the properties out of it</param>
        /// <returns>throws a query exception when it finds something wrong with the input, otherwise returns a baseuri</returns>
        //////////////////////////////////////////////////////////////////////
        protected override Uri ParseUri(Uri targetUri)
        {
            base.ParseUri(targetUri);
            if (targetUri != null)
            {
                char[] deli = { '?', '&'};

                TokenCollection tokens = new TokenCollection(targetUri.Query, deli);
                foreach (String token in tokens)
                {
                    if (token.Length > 0)
                    {
                        char[] otherDeli = { '='};
                        String[] parameters = token.Split(otherDeli, 2);
                        switch (parameters[0])
                        {
                            case "start-min":
                                this.startTime = DateTime.Parse(parameters[1], CultureInfo.InvariantCulture);
                                break;
                            case "start-max":
                                this.endTime = DateTime.Parse(parameters[1], CultureInfo.InvariantCulture);
                                break;
                            case "recurrence-expansion-start":
                                this.recurrenceStart = DateTime.Parse(parameters[1], CultureInfo.InvariantCulture);
                                break;
                            case "recurrence-expansion-end":
                                this.recurrenceEnd = DateTime.Parse(parameters[1], CultureInfo.InvariantCulture);
                                break;
                            case "singleevents":
                                this.singleEvents = bool.Parse(parameters[1]); 
                                break;
                            case "futureevents":
                                this.futureEvents = bool.Parse(parameters[1]); 
                                break;
                            case "sortorder":
                                this.sortOrder = (CalendarSortOrder) Enum.Parse(typeof(CalendarSortOrder), parameters[1]); 
                                break;
                        }
                    }
                }
            }
            return this.Uri;
        }

        //////////////////////////////////////////////////////////////////////
        /// <summary>Resets object state to default, as if newly created.
        /// </summary> 
        //////////////////////////////////////////////////////////////////////
        protected override void Reset()
        {
            base.Reset();
            startTime = endTime = FeedQuery.EmptyDate;
            recurrenceStart = recurrenceEnd = FeedQuery.EmptyDate;
        }

        //////////////////////////////////////////////////////////////////////
        /// <summary>Creates the partial URI query string based on all
        ///  set properties.</summary> 
        /// <returns> string => the query part of the URI </returns>
        //////////////////////////////////////////////////////////////////////
        protected override string CalculateQuery()
        {
            string path = base.CalculateQuery();
            StringBuilder newPath = new StringBuilder(path, 2048);

            char paramInsertion;

            if (path.IndexOf('?') == -1)
            {
                paramInsertion = '?';
            }
            else
            {
                paramInsertion = '&';
            }
            if (this.StartTime != FeedQuery.EmptyDate)
            {
                newPath.Append(paramInsertion);
                newPath.AppendFormat("start-min={0}", Utilities.UriEncodeReserved(Utilities.LocalDateTimeInUTC(this.StartTime)));
                paramInsertion = '&';
            }
            if (this.EndTime != FeedQuery.EmptyDate)
            {
                newPath.Append(paramInsertion);
                newPath.AppendFormat("start-max={0}", Utilities.UriEncodeReserved(Utilities.LocalDateTimeInUTC(this.EndTime)));
                paramInsertion = '&';
            }
            if (this.RecurrenceStart != FeedQuery.EmptyDate)
            {
                newPath.Append(paramInsertion);
                newPath.AppendFormat("recurrence-expansion-start={0}", Utilities.UriEncodeReserved(Utilities.LocalDateTimeInUTC(this.RecurrenceStart))); 
                paramInsertion = '&';
            }
            if (this.RecurrenceEnd != FeedQuery.EmptyDate)
            {
                newPath.Append(paramInsertion);
                newPath.AppendFormat("recurrence-expansion-end={0}", Utilities.UriEncodeReserved(Utilities.LocalDateTimeInUTC(this.RecurrenceEnd))); 
                paramInsertion = '&';
            }
            if (this.sortOrder != CalendarSortOrder.serverDefault)
            {
                newPath.Append(paramInsertion);
                newPath.AppendFormat("sortorder={0}", this.sortOrder.ToString()); 
                paramInsertion = '&';
            }
            if (this.futureEvents == true)
            {
                newPath.Append(paramInsertion);
                newPath.AppendFormat("futureevents=true"); 
                paramInsertion = '&';
            }
            if (this.singleEvents == true)
            {
                newPath.Append(paramInsertion);
                newPath.AppendFormat("singleevents=true"); 
                paramInsertion = '&';
            }


            return newPath.ToString();
        }
    }
}
www.java2v.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.