Release 4.0.0-preview1-00051
[platform/core/csapi/tizenfx.git] / src / Tizen.Pims.Calendar / Tizen.Pims.Calendar / CalendarManager.cs
1 /*
2  * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
3  *
4  * Licensed under the Apache License, Version 2.0 (the License);
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an AS IS BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 using System;
18 using System.Collections.Generic;
19 using static Interop.Calendar.Service;
20
21 namespace Tizen.Pims.Calendar
22 {
23     /// <summary>
24     /// A class for managing calendar information. It allows applications to use calendar service.
25     /// </summary>
26     public class CalendarManager : IDisposable
27     {
28         private CalendarDatabase _db = null;
29
30         /// <summary>
31         /// Create a manager.
32         /// </summary>
33         /// <exception cref="InvalidOperationException">Thrown when method failed due to invalid operation</exception>
34         public CalendarManager()
35         {
36             int error = Interop.Calendar.Service.Connect();
37             if (CalendarError.None != (CalendarError)error)
38             {
39                 Log.Error(Globals.LogTag, "Connect Failed with error " + error);
40                 throw CalendarErrorFactory.GetException(error);
41             }
42             _db = new CalendarDatabase();
43         }
44
45         ~CalendarManager()
46         {
47             Dispose(false);
48         }
49
50 #region IDisposable Support
51         /// To detect redundant calls
52         private bool disposedValue = false;
53
54         protected virtual void Dispose(bool disposing)
55         {
56             if (!disposedValue)
57             {
58                 Log.Debug(Globals.LogTag, "Dispose :" + disposing);
59
60                 int error = Interop.Calendar.Service.Disconnect();
61                 if (CalendarError.None != (CalendarError)error)
62                 {
63                     Log.Error(Globals.LogTag, "Disconnect Failed with error " + error);
64                     throw CalendarErrorFactory.GetException(error);
65                 }
66                 disposedValue = true;
67             }
68         }
69
70         /// <summary>
71         /// Releases all resources used by the CalendarManager.
72         /// It should be called after finished using of the object.
73         /// </summary>
74         public void Dispose()
75         {
76             Dispose(true);
77         }
78 #endregion
79
80         /// <summary>
81         /// Get database.
82         /// </summary>
83         public CalendarDatabase Database
84         {
85             get
86             {
87                 return _db;
88             }
89         }
90     }
91 }