28cc8655a4b0efa2cc73c2aabbbd9236808a47f5
[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
19 namespace Tizen.Pims.Calendar
20 {
21     /// <summary>
22     /// A class for managing calendar information. It allows applications to use calendar service.
23     /// </summary>
24     /// <since_tizen> 4 </since_tizen>
25     public class CalendarManager : IDisposable
26     {
27         private CalendarDatabase _db = null;
28
29         /// <summary>
30         /// Create a manager.
31         /// </summary>
32         /// <since_tizen> 4 </since_tizen>
33         /// <feature>http://tizen.org/privilege/calendar</feature>
34         /// <exception cref="NotSupportedException">Thrown when feature is not supported</exception>
35         /// <exception cref="InvalidOperationException">Thrown when method failed due to invalid operation</exception>
36         public CalendarManager()
37         {
38             int error = Interop.Service.Connect();
39             if (CalendarError.None != (CalendarError)error)
40             {
41                 Log.Error(Globals.LogTag, "Connect Failed with error " + error);
42                 throw CalendarErrorFactory.GetException(error);
43             }
44             _db = new CalendarDatabase();
45         }
46
47         /// <summary>
48         /// Destroy CalendarManager resource.
49         /// </summary>
50         ~CalendarManager()
51         {
52             Dispose(false);
53         }
54
55 #region IDisposable Support
56         /// To detect redundant calls
57         private bool disposedValue = false;
58
59         /// <summary>
60         /// Disposes of the resources (other than memory) used by the CalendarManager.
61         /// </summary>
62         /// <param name="disposing">true to release both managed and unmanaged resources; false to release only unmanaged resources.</param>
63         protected virtual void Dispose(bool disposing)
64         {
65             if (!disposedValue)
66             {
67                 Log.Debug(Globals.LogTag, "Dispose :" + disposing);
68
69                 int error = Interop.Service.Disconnect();
70                 if (CalendarError.None != (CalendarError)error)
71                 {
72                     Log.Error(Globals.LogTag, "Disconnect Failed with error " + error);
73                     throw CalendarErrorFactory.GetException(error);
74                 }
75                 disposedValue = true;
76             }
77         }
78
79         /// <summary>
80         /// Releases all resources used by the CalendarManager.
81         /// It should be called after having finished using of the object.
82         /// </summary>
83         public void Dispose()
84         {
85             Dispose(true);
86             GC.SuppressFinalize(this);
87         }
88 #endregion
89
90         /// <summary>
91         /// Get database.
92         /// </summary>
93         /// <since_tizen> 4 </since_tizen>
94         /// <value>The database instance</value>
95         public CalendarDatabase Database
96         {
97             get
98             {
99                 return _db;
100             }
101         }
102     }
103 }