示例#1
0
        internal static IntPtr ConvertCalendarTimeToStruct(CalendarTime value)
        {
            Console.WriteLine("convert calendar");
            IntPtr caltime = Interop.Record.CreateCalTime();

            Interop.Record.SetCalTimeType(caltime, value._type);

            if ((int)CalendarTime.Type.Utc == value._type)
            {
                DateTime epoch = new DateTime(1970, 1, 1, 0, 0, 0);
                Interop.Record.SetCalTimeUtime(caltime, (value.UtcTime.Ticks - epoch.Ticks) / 10_000_000);
                //Log.Debug(Globals.LogTag, "Sameer local time is if:" + Interop.Record.GetCalTimeLocalMonth(caltime) + "," + Interop.Record.GetCalTimeLocalMday(caltime) + "," + Interop.Record.GetCalTimeLocalHour(caltime) + "," + Interop.Record.GetCalTimeLocalMinute(caltime));
            }
            else
            {
                Interop.Record.SetCalTimeLocalYear(caltime, value.LocalTime.Year);
                Interop.Record.SetCalTimeLocalMonth(caltime, value.LocalTime.Month);
                Interop.Record.SetCalTimeLocalMday(caltime, value.LocalTime.Day);
                Interop.Record.SetCalTimeLocalHour(caltime, value.LocalTime.Hour);
                Interop.Record.SetCalTimeLocalMinute(caltime, value.LocalTime.Minute);
                Interop.Record.SetCalTimeLocalSecond(caltime, value.LocalTime.Second);
                //Log.Debug(Globals.LogTag, "Sameer local time is:" + Interop.Record.GetCalTimeLocalHour(caltime) + "," + Interop.Record.GetCalTimeLocalMinute(caltime));
            }
            return(caltime);
        }
        /// <summary>
        /// Get allday instance list.
        /// To get allday instance list, InstanceLocaltimeBook uri must be used.
        /// Range is set from the first day of selected date to the last day of selected data.
        /// <param name="dt">The selected datetime</param>
        /// </summary>
        private TPC.CalendarList GetAlldayInstances(DateTime dt)
        {
            TPC.CalendarList list = null;

            TPC.CalendarTime from = new TPC.CalendarTime(dt.Year, dt.Month, dt.Day, 0, 0, 0);
            TPC.CalendarTime to   = new TPC.CalendarTime(dt.AddDays(1).Year, dt.AddDays(1).Month, dt.AddDays(1).Day, 0, 0, 0);

            TPC.CalendarQuery  query  = new TPC.CalendarQuery(InstanceLocaltimeBook.Uri);
            TPC.CalendarFilter filter = new TPC.CalendarFilter(InstanceLocaltimeBook.Uri,
                                                               InstanceLocaltimeBook.Start, TPC.CalendarFilter.IntegerMatchType.GreaterThanOrEqual, from);
            filter.AddCondition(TPC.CalendarFilter.LogicalOperator.And,
                                InstanceLocaltimeBook.Start, TPC.CalendarFilter.IntegerMatchType.LessThan, to);
            query.SetFilter(filter);
            try
            {
                list = manager.Database.GetRecordsWithQuery(query, 0, 0);
            }
            catch (Exception)
            {
            }
            filter.Dispose();
            query.Dispose();

            return(list);
        }
示例#3
0
 /// <summary>
 /// Sets a value of the property to a record.
 /// </summary>
 /// <since_tizen> 4 </since_tizen>
 /// <param name="propertyId">The property ID</param>
 /// <param name="value">value</param>
 /// <feature>http://tizen.org/feature/calendar</feature>
 /// <exception cref="NotSupportedException">Thrown when feature is not supported</exception>
 /// <exception cref="ArgumentException">Thrown when one of the arguments provided to a method is not valid</exception>
 public void Set <T>(uint propertyId, T value)
 {
     if (typeof(T) == typeof(string))
     {
         string val   = Convert.ToString(value);
         int    error = Interop.Record.SetString(_recordHandle, propertyId, val);
         if (CalendarError.None != (CalendarError)error)
         {
             Log.Error(Globals.LogTag, "Set String Failed [" + error + "]" + String.Format("{0:X}", propertyId));
             throw CalendarErrorFactory.GetException(error);
         }
     }
     else if (typeof(T) == typeof(int))
     {
         int val   = Convert.ToInt32(value);
         int error = Interop.Record.SetInteger(_recordHandle, propertyId, val);
         if (CalendarError.None != (CalendarError)error)
         {
             Log.Error(Globals.LogTag, "Set Integer Failed [" + error + "]" + String.Format("{0:X}", propertyId));
             throw CalendarErrorFactory.GetException(error);
         }
     }
     else if (typeof(T) == typeof(long))
     {
         long val   = Convert.ToInt64(value);
         int  error = Interop.Record.SetLli(_recordHandle, propertyId, val);
         if (CalendarError.None != (CalendarError)error)
         {
             Log.Error(Globals.LogTag, "Set Long Failed [" + error + "]" + String.Format("{0:X}", propertyId));
             throw CalendarErrorFactory.GetException(error);
         }
     }
     else if (typeof(T) == typeof(double))
     {
         double val   = Convert.ToDouble(value);
         int    error = Interop.Record.SetDouble(_recordHandle, propertyId, val);
         if (CalendarError.None != (CalendarError)error)
         {
             Log.Error(Globals.LogTag, "Set Double Failed [" + error + "]" + String.Format("{0:X}", propertyId));
             throw CalendarErrorFactory.GetException(error);
         }
     }
     else if (typeof(T) == typeof(CalendarTime))
     {
         CalendarTime            time = (CalendarTime)Convert.ChangeType(value, typeof(CalendarTime));
         Interop.Record.DateTime val  = ConvertCalendarTimeToStruct(time);
         int error = Interop.Record.SetCalendarTime(_recordHandle, propertyId, val);
         if (CalendarError.None != (CalendarError)error)
         {
             Log.Error(Globals.LogTag, "Set CalendarTime Failed [" + error + "]" + String.Format("{0:X}", propertyId));
             throw CalendarErrorFactory.GetException(error);
         }
     }
     else
     {
         Log.Error(Globals.LogTag, "Not supported Data T/ype");
         throw CalendarErrorFactory.GetException((int)CalendarError.NotSupported);
     }
 }
示例#4
0
        internal static CalendarTime ConvertIntPtrToCalendarTime(Interop.Record.DateTime time)
        {
            CalendarTime value;

            if ((int)CalendarTime.Type.Utc == time.type)
            {
                DateTime epoch = new DateTime(1970, 1, 1, 0, 0, 0);
                value = new CalendarTime(time.utime * 10000000 + epoch.Ticks);
            }
            else
            {
                value = new CalendarTime(time.local.year, time.local.month, time.local.mday, time.local.hour, time.local.minute, time.local.second);
            }
            value._type = time.type;
            return(value);
        }
示例#5
0
        internal static CalendarTime ConvertIntPtrToCalendarTime(IntPtr caltime)
        {
            CalendarTime value;

            if ((int)CalendarTime.Type.Utc == Interop.Record.GetCalTimeType(caltime))
            {
                DateTime epoch = new DateTime(1970, 1, 1, 0, 0, 0);
                value = new CalendarTime(Interop.Record.GetCalTimeUtime(caltime) * 10_000_000 + epoch.Ticks);
            }
            else
            {
                value = new CalendarTime(Interop.Record.GetCalTimeLocalYear(caltime), Interop.Record.GetCalTimeLocalMonth(caltime), Interop.Record.GetCalTimeLocalMday(caltime),
                                         Interop.Record.GetCalTimeLocalHour(caltime), Interop.Record.GetCalTimeLocalMinute(caltime), Interop.Record.GetCalTimeLocalSecond(caltime));
            }
            value._type = Interop.Record.GetCalTimeType(caltime);
            return(value);
        }
        /// <summary>
        /// Get item from record.
        /// <param name="record">The record</param>
        /// <param name="item">The item to be converted from record.</param>
        /// </summary>
        private void RecordToItem(TPC.CalendarRecord record, RecordItem item, TPC.CalendarTime start, TPC.CalendarTime end, bool isAllday)
        {
            item.Index       = record.Get <int>(Event.Id);
            item.Summary     = record.Get <string>(Event.Summary);
            item.Location    = record.Get <string>(Event.Location);
            item.Description = record.Get <string>(Event.Description);
            item.Priority    = getPriorityIndex(record.Get <int>(Event.Priority));
            item.Sensitivity = getSensitivityIndex(record.Get <int>(Event.Sensitivity));
            item.Status      = getStatusIndex(record.Get <int>(Event.EventStatus));

            item.StartTime  = isAllday == true ? start.LocalTime : start.UtcTime;
            item.EndTime    = isAllday == true ? end.LocalTime : end.UtcTime;
            item.IsAllday   = isAllday;
            item.Recurrence = getRecurrenceIndex(record.Get <int>(Event.Freq));

            item.DisplayTime = String.Format("{0} - {1}",
                                             item.IsAllday == true ? item.StartTime.ToLocalTime().ToString("yyyy/MM/dd") : item.StartTime.ToLocalTime().ToString("yyyy/MM/dd HH:mm"),
                                             item.IsAllday == true ? item.EndTime.ToLocalTime().ToString("yyyy/MM/dd") : item.EndTime.ToLocalTime().ToString("yyyy/MM/dd HH:mm"));

            if (item.Recurrence > 0)
            {
                switch (record.Get <int>(Event.RangeType))
                {
                default:
                /// count
                case (int)TPC.CalendarTypes.RangeType.Count:
                    item.UntilType  = 0;
                    item.UntilCount = record.Get <int>(Event.Count);
                    break;

                /// until
                case (int)TPC.CalendarTypes.RangeType.Until:
                    item.UntilType = 1;
                    var until = record.Get <TPC.CalendarTime>(Event.Until);
                    item.UntilTime = until.UtcTime;
                    break;
                }
            }

            if (record.Get <int>(Event.HasAlarm) > 0)
            {
                var alarm = record.GetChildRecord(Event.Alarm, 0);
                item.Reminder = getReminderIndex(alarm.Get <int>(Alarm.Tick), alarm.Get <int>(Alarm.TickUnit));
            }
        }
        /// <summary>
        /// Get utc instance list.
        /// To get not-allday instance list, InstanceUtimeBook uri must be used.
        /// This does not include allday instances.
        /// Range is set from the first day of selected date to the last day of selected data.
        /// <param name="dt">The selected datetime</param>
        /// </summary>
        private TPC.CalendarList GetUtcInstances(DateTime dt)
        {
            TPC.CalendarList list;

            DateTime firstDate = new DateTime(dt.Year, dt.Month, dt.Day, 0, 0, 0, DateTimeKind.Local);

            TPC.CalendarTime from = new TPC.CalendarTime(firstDate.ToUniversalTime().Ticks);
            TPC.CalendarTime to   = new TPC.CalendarTime(from.UtcTime.AddDays(1).Ticks);

            TPC.CalendarQuery  query  = new TPC.CalendarQuery(InstanceUtimeBook.Uri);
            TPC.CalendarFilter filter = new TPC.CalendarFilter(InstanceUtimeBook.Uri,
                                                               InstanceUtimeBook.Start, TPC.CalendarFilter.IntegerMatchType.GreaterThanOrEqual, from);
            filter.AddCondition(TPC.CalendarFilter.LogicalOperator.And,
                                InstanceUtimeBook.Start, TPC.CalendarFilter.IntegerMatchType.LessThan, to);
            query.SetFilter(filter);
            list = manager.Database.GetRecordsWithQuery(query, 0, 0);
            filter.Dispose();
            query.Dispose();

            return(list);
        }
示例#8
0
        internal static Interop.Record.DateTime ConvertCalendarTimeToStruct(CalendarTime value)
        {
            Interop.Record.DateTime time = new Interop.Record.DateTime();
            time.type = value._type;

            if ((int)CalendarTime.Type.Utc == value._type)
            {
                DateTime epoch = new DateTime(1970, 1, 1, 0, 0, 0);
                time.utime = (value.UtcTime.Ticks - epoch.Ticks) / 10000000;
            }
            else
            {
                time.local.year   = value.LocalTime.Year;
                time.local.month  = value.LocalTime.Month;
                time.local.mday   = value.LocalTime.Day;
                time.local.hour   = value.LocalTime.Hour;
                time.local.minute = value.LocalTime.Minute;
                time.local.second = value.LocalTime.Second;
            }
            return(time);
        }
示例#9
0
        /// <summary>
        /// Gets a object from a record.
        /// </summary>
        /// <since_tizen> 4 </since_tizen>
        /// <param name="propertyId">The property ID</param>
        /// <returns>
        /// The value of the property corresponding to property id.
        /// </returns>
        /// <feature>http://tizen.org/feature/calendar</feature>
        /// <exception cref="NotSupportedException">Thrown when feature is not supported</exception>
        /// <exception cref="ArgumentException">Thrown when one of the arguments provided to a method is not valid</exception>
        public T Get <T>(uint propertyId)
        {
            object parsedValue = null;

            if (typeof(T) == typeof(string))
            {
                string val;
                int    error = Interop.Record.GetString(_recordHandle, propertyId, out val);
                if (CalendarError.None != (CalendarError)error)
                {
                    Log.Error(Globals.LogTag, "Get String Failed [" + error + "]" + String.Format("{0:X}", propertyId));
                    throw CalendarErrorFactory.GetException(error);
                }
                parsedValue = Convert.ChangeType(val, typeof(T));
            }
            else if (typeof(T) == typeof(int))
            {
                int val;
                int error = Interop.Record.GetInteger(_recordHandle, propertyId, out val);
                if (CalendarError.None != (CalendarError)error)
                {
                    Log.Error(Globals.LogTag, "Get Intger Failed [" + error + "]" + String.Format("{0:X}", propertyId));
                    throw CalendarErrorFactory.GetException(error);
                }
                parsedValue = Convert.ChangeType(val, typeof(T));
            }
            else if (typeof(T) == typeof(long))
            {
                long val;
                int  error = Interop.Record.GetLli(_recordHandle, propertyId, out val);
                if (CalendarError.None != (CalendarError)error)
                {
                    Log.Error(Globals.LogTag, "Get Long Failed [" + error + "]" + String.Format("{0:X}", propertyId));
                    throw CalendarErrorFactory.GetException(error);
                }
                parsedValue = Convert.ChangeType(val, typeof(T));
            }
            else if (typeof(T) == typeof(double))
            {
                double val;
                int    error = Interop.Record.GetDouble(_recordHandle, propertyId, out val);
                if (CalendarError.None != (CalendarError)error)
                {
                    Log.Error(Globals.LogTag, "Get Double Failed [" + error + "]" + String.Format("{0:X}", propertyId));
                    throw CalendarErrorFactory.GetException(error);
                }
                parsedValue = Convert.ChangeType(val, typeof(T));
            }
            else if (typeof(T) == typeof(CalendarTime))
            {
                IntPtr time;
                int    error = Interop.Record.GetCalTime(_recordHandle, propertyId, out time);
                if (CalendarError.None != (CalendarError)error)
                {
                    Log.Error(Globals.LogTag, "Get CalendarTime Failed [" + error + "]" + String.Format("{0:X}", propertyId));
                    throw CalendarErrorFactory.GetException(error);
                }
                CalendarTime val = ConvertIntPtrToCalendarTime(time);
                parsedValue = Convert.ChangeType(val, typeof(T));
            }
            else
            {
                Log.Error(Globals.LogTag, "Not supported Data T/ype");
                throw CalendarErrorFactory.GetException((int)CalendarError.NotSupported);
            }
            return((T)parsedValue);
        }
        /// <summary>
        /// Get record from item.
        /// <param name="item">The item</param>
        /// <param name="record">The record to be converted from item.</param>
        /// </summary>
        private void ItemToRecord(RecordItem item, TPC.CalendarRecord record)
        {
            record.Set <string>(Event.Summary, item.Summary);
            record.Set <string>(Event.Location, item.Location);
            record.Set <string>(Event.Description, item.Description);

            TPC.CalendarTime start;
            TPC.CalendarTime end;
            if (item.IsAllday)
            {
                start = new TPC.CalendarTime(item.StartTime.Year, item.StartTime.Month, item.StartTime.Day,
                                             item.StartTime.Hour, item.StartTime.Minute, item.StartTime.Second);
                end = new TPC.CalendarTime(item.EndTime.Year, item.EndTime.Month, item.EndTime.Day,
                                           item.EndTime.Hour, item.EndTime.Minute, item.EndTime.Second);
            }
            else
            {
                start = new TPC.CalendarTime(item.StartTime.ToUniversalTime().Ticks);
                end   = new TPC.CalendarTime(item.EndTime.ToUniversalTime().Ticks);
            }
            record.Set <TPC.CalendarTime>(Event.Start, start);
            record.Set <TPC.CalendarTime>(Event.End, end);

            switch (item.Recurrence)
            {
            default:
            case 0:
                /// none
                record.Set <int>(Event.Freq, (int)TPC.CalendarTypes.Recurrence.None);
                break;

            case 1:
                /// daily
                record.Set <int>(Event.Freq, (int)TPC.CalendarTypes.Recurrence.Daily);
                break;

            case 2:
                /// weekly
                record.Set <int>(Event.Freq, (int)TPC.CalendarTypes.Recurrence.Weekly);
                break;

            case 3:
                /// monthly
                record.Set <int>(Event.Freq, (int)TPC.CalendarTypes.Recurrence.Monthly);
                break;

            case 4:
                /// yearly
                record.Set <int>(Event.Freq, (int)TPC.CalendarTypes.Recurrence.Yearly);
                break;
            }

            switch (item.UntilType)
            {
            default:
            /// count
            case 0:
                record.Set <int>(Event.RangeType, (int)TPC.CalendarTypes.RangeType.Count);
                record.Set <int>(Event.Count, item.UntilCount);
                break;

            /// until
            case 1:
                record.Set <int>(Event.RangeType, (int)TPC.CalendarTypes.RangeType.Until);
                var until = new TPC.CalendarTime(new DateTime(item.UntilTime.Year, item.UntilTime.Month, item.UntilTime.Day,
                                                              item.UntilTime.Hour, item.UntilTime.Minute, item.UntilTime.Second, DateTimeKind.Local).Ticks);
                record.Set <TPC.CalendarTime>(Event.Until, until);
                break;
            }

            if (item.Reminder > 0)
            {
                TPC.CalendarRecord alarm;
                alarm = new TPC.CalendarRecord(Alarm.Uri);
                alarm.Set <int>(Alarm.Tick, getTick(item.Reminder));
                alarm.Set <int>(Alarm.TickUnit, getUnit(item.Reminder));
                record.AddChildRecord(Event.Alarm, alarm);
            }

            record.Set <int>(Event.Priority, getPriority(item.Priority));
            record.Set <int>(Event.Sensitivity, getSensitivity(item.Sensitivity));
            record.Set <int>(Event.EventStatus, getStatus(item.Status));
        }
示例#11
0
        /// <summary>
        /// Adds a condition for the CalendarTime type.
        /// </summary>
        /// <since_tizen> 4 </since_tizen>
        /// <feature>http://tizen.org/feature/calendar</feature>
        /// <param name="logicalOperator">The operator type.</param>
        /// <param name="propertyId">The property ID to add a condition.</param>
        /// <param name="matchType">The match flag.</param>
        /// <param name="matchValue">The match value.</param>
        /// <exception cref="NotSupportedException">Thrown when the feature is not supported.</exception>
        /// <exception cref="ArgumentException">Thrown when one of the arguments provided to a method is not valid.</exception>
        public void AddCondition(LogicalOperator logicalOperator, uint propertyId, IntegerMatchType matchType, CalendarTime matchValue)
        {
            int error = Interop.Filter.AddOperator(_filterHandle, logicalOperator);

            if (CalendarError.None != (CalendarError)error)
            {
                Log.Error(Globals.LogTag, "AddCondition Failed with error " + error);
                throw CalendarErrorFactory.GetException(error);
            }

            IntPtr time = CalendarRecord.ConvertCalendarTimeToStruct(matchValue);

            error = Interop.Filter.AddCalendarTime(_filterHandle, propertyId, matchType, time);
            if (CalendarError.None != (CalendarError)error)
            {
                Log.Error(Globals.LogTag, "AddCondition Failed with error " + error);
                throw CalendarErrorFactory.GetException(error);
            }
        }
示例#12
0
        public CalendarFilter(string viewUri, uint propertyId, IntegerMatchType matchType, CalendarTime matchValue)
        {
            int error = 0;

            error = Interop.Filter.Create(viewUri, out _filterHandle);
            if (CalendarError.None != (CalendarError)error)
            {
                Log.Error(Globals.LogTag, "CalendarFilter Failed with error " + error);
                throw CalendarErrorFactory.GetException(error);
            }

            IntPtr time = CalendarRecord.ConvertCalendarTimeToStruct(matchValue);

            error = Interop.Filter.AddCalendarTime(_filterHandle, propertyId, matchType, time);
            if (CalendarError.None != (CalendarError)error)
            {
                Interop.Filter.Destroy(_filterHandle);
                Log.Error(Globals.LogTag, "CalendarFilter Failed with error " + error);
                throw CalendarErrorFactory.GetException(error);
            }
        }