/// <summary> /// Clean child record. /// <param name="record">The record to be cleared</param> /// </summary> private void CleanChildRecord(TPC.CalendarRecord record) { if (record.GetChildRecordCount(Event.Alarm) > 0) { var alarm = record.GetChildRecord(Event.Alarm, 0); record.RemoveChildRecord(Event.Alarm, alarm); } }
/// <summary> /// Insert item. /// <param name="item">The item to be inserted.</param> /// </summary> public int Insert(RecordItem item) { var record = new TPC.CalendarRecord(Event.Uri); ItemToRecord(item, record); int recordId = manager.Database.Insert(record); record.Dispose(); return(recordId); }
public void Replace(CalendarRecord record, int id) { int error = Interop.Database.Replace(record._recordHandle, id); if (CalendarError.None != (CalendarError)error) { Log.Error(Globals.LogTag, "Replace Failed with error " + error); throw CalendarErrorFactory.GetException(error); } }
/// <summary> /// Removes a child record from the parent record. /// </summary> /// <since_tizen> 4 </since_tizen> /// <param name="propertyId">The property ID.</param> /// <param name="childRecord">The child record.</param> /// <feature>http://tizen.org/feature/calendar</feature> /// <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 RemoveChildRecord(uint propertyId, CalendarRecord childRecord) { int error = Interop.Record.RemoveChildRecord(_recordHandle, propertyId, childRecord._recordHandle); if (CalendarError.None != (CalendarError)error) { Log.Error(Globals.LogTag, "RemoveChildRecord Failed [" + error + "]" + String.Format("{0:X}", propertyId)); throw CalendarErrorFactory.GetException(error); } childRecord._disposedValue = false; }
public int Insert(CalendarRecord record) { int id = -1; int error = Interop.Database.Insert(record._recordHandle, out id); if (CalendarError.None != (CalendarError)error) { Log.Error(Globals.LogTag, "Insert Failed with error " + error); throw CalendarErrorFactory.GetException(error); } return(id); }
/// <summary> /// Removes a record from the calendar list. /// </summary> /// <since_tizen> 4 </since_tizen> /// <param name="record">The record to be removed.</param> /// <feature>http://tizen.org/feature/calendar</feature> /// <exception cref="NotSupportedException">Thrown when the feature is not supported.</exception> public void RemoveRecord(CalendarRecord record) { int error = Interop.List.Remove(_listHandle, record._recordHandle); if (CalendarError.None != (CalendarError)error) { Log.Error(Globals.LogTag, "RemoveRecord Failed with error " + error); throw CalendarErrorFactory.GetException(error); } record._disposedValue = false; _count = -1; _memoryPressure -= CalendarViews.Record.AverageSize; }
/// <summary> /// Deletes multiple records with related child records from the calendar database as a batch operation. /// </summary> /// <since_tizen> 4 </since_tizen> /// <param name="list">The record list</param> /// <privilege>http://tizen.org/privilege/calendar.write</privilege> /// <feature>http://tizen.org/feature/calendar</feature> /// <exception cref="NotSupportedException">Thrown when feature is not supported</exception> /// <exception cref="InvalidOperationException">Thrown when method failed due to invalid operation</exception> /// <exception cref="OutOfMemoryException">Thrown when failed due to out of memory</exception> /// <exception cref="UnauthorizedAccessException">Thrown when application does not have proper privileges</exception> public void Delete(CalendarList list) { CalendarRecord record = null; if (list.Count <= 0) { return; } int[] ids = new int[list.Count]; int i; uint propertyId = 0; list.MoveFirst(); for (i = 0; i < list.Count; i++) { record = list.GetCurrentRecord(); if (0 == propertyId) { if (0 == String.Compare(CalendarViews.Book.Uri, record.Uri)) { propertyId = CalendarViews.Book.Id; } else if (0 == String.Compare(CalendarViews.Event.Uri, record.Uri)) { propertyId = CalendarViews.Event.Id; } else if (0 == String.Compare(CalendarViews.Todo.Uri, record.Uri)) { propertyId = CalendarViews.Todo.Id; } else if (0 == String.Compare(CalendarViews.Timezone.Uri, record.Uri)) { propertyId = CalendarViews.Timezone.Id; } else if (0 == String.Compare(CalendarViews.Extended.Uri, record.Uri)) { propertyId = CalendarViews.Extended.Id; } else { Log.Error(Globals.LogTag, "Invalid uri [" + record.Uri + "]"); continue; } } ids[i] = record.Get <int>(propertyId); list.MoveNext(); } Delete(record.Uri, ids); }
/// <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> /// 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); } Interop.Record.DateTime 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); } }
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); } Interop.Record.DateTime 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); } }
/// <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)); }