[NUI] TCSACR-226 code change (#1032)
[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 the calendar information. It allows the applications to use the 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         /// Creates a manager.
31         /// </summary>
32         /// <since_tizen> 4 </since_tizen>
33         /// <feature>http://tizen.org/feature/calendar</feature>
34         /// <exception cref="NotSupportedException">Thrown when the feature is not supported.</exception>
35         /// <exception cref="InvalidOperationException">Thrown when the method failed due to an 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         /// Destroys the 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         /// <since_tizen> 4 </since_tizen>
64         protected virtual void Dispose(bool disposing)
65         {
66             if (!disposedValue)
67             {
68                 Log.Debug(Globals.LogTag, "Dispose :" + disposing);
69
70                 int error = Interop.Service.Disconnect();
71                 if (CalendarError.None != (CalendarError)error)
72                 {
73                     Log.Error(Globals.LogTag, "Disconnect Failed with error " + error);
74                 }
75                 disposedValue = true;
76             }
77         }
78
79         /// <summary>
80         /// Releases all the resources used by the CalendarManager.
81         /// It should be called after it has finished using the object.
82         /// </summary>
83         /// <since_tizen> 4 </since_tizen>
84         public void Dispose()
85         {
86             Dispose(true);
87             GC.SuppressFinalize(this);
88         }
89 #endregion
90
91         /// <summary>
92         /// Gets the database.
93         /// </summary>
94         /// <since_tizen> 4 </since_tizen>
95         /// <value>The database instance.</value>
96         public CalendarDatabase Database
97         {
98             get
99             {
100                 return _db;
101             }
102         }
103     }
104 }