Release 4.0.0-preview1-00271
[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                 }
74                 disposedValue = true;
75             }
76         }
77
78         /// <summary>
79         /// Releases all resources used by the CalendarManager.
80         /// It should be called after having finished using of the object.
81         /// </summary>
82         public void Dispose()
83         {
84             Dispose(true);
85             GC.SuppressFinalize(this);
86         }
87 #endregion
88
89         /// <summary>
90         /// Get database.
91         /// </summary>
92         /// <since_tizen> 4 </since_tizen>
93         /// <value>The database instance</value>
94         public CalendarDatabase Database
95         {
96             get
97             {
98                 return _db;
99             }
100         }
101     }
102 }