[Tizen.WebView] Fix document build warnings
[platform/core/csapi/tizenfx.git] / src / Tizen.PhonenumberUtils / Tizen.PhonenumberUtils / PhonenumberUtils.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.PhonenumberUtils
20 {
21     /// <summary>
22     /// The PhonenumberUtils class provides methods for parsing, formatting and normalizing phone numbers.
23     /// </summary>
24     /// <since_tizen> 4 </since_tizen>
25     public class PhonenumberUtils : IDisposable
26     {
27         private bool disposed = false;
28
29         /// <summary>
30         /// Creates a PhonenumberUtils.
31         /// </summary>
32         /// <feature>http://tizen.org/feature/network.telephony</feature>
33         /// <exception cref="InvalidOperationException">Thrown when method failed due to invalid operation</exception>
34         /// <exception cref="NotSupportedException">Thrown when feature is not supported</exception>
35         /// <since_tizen> 4 </since_tizen>
36         public PhonenumberUtils()
37         {
38             int ret;
39
40             ret = Interop.PhonenumberUtils.Connect();
41             if (ret != (int)PhonenumberUtilsError.None)
42             {
43                 Log.Error(Globals.LogTag, "Failed to connect, Error - " + (PhonenumberUtilsError)ret);
44                 PhonenumberUtilsErrorFactory.ThrowPhonenumberUtilsException(ret);
45             }
46         }
47
48         ~PhonenumberUtils()
49         {
50             Dispose(false);
51         }
52
53         /// <summary>
54         /// Releases all resources used by the PhonenumberUtils.
55         /// It should be called after finished using of the object.
56         /// </summary>
57         /// <since_tizen> 4 </since_tizen>
58         public void Dispose()
59         {
60             Dispose(true);
61             GC.SuppressFinalize(this);
62         }
63
64         private void Dispose(bool disposing)
65         {
66             if (disposed)
67                 return;
68
69             // Free unmanaged objects
70             int ret;
71
72             ret = Interop.PhonenumberUtils.Disconnect();
73             if (ret != (int)PhonenumberUtilsError.None)
74                 Log.Error(Globals.LogTag, "Failed to disconnect, Error - " + (PhonenumberUtilsError)ret);
75
76             disposed = true;
77         }
78
79         /// <summary>
80         /// Gets the location string from number, region, and language.
81         /// </summary>
82         /// <param name="number">The number</param>
83         /// <param name="region">The region of number</param>
84         /// <param name="language">The language of location</param>
85         /// <returns>The location string</returns>
86         /// <feature>http://tizen.org/feature/network.telephony</feature>
87         /// <exception cref="InvalidOperationException">Thrown when method failed due to invalid operation</exception>
88         /// <exception cref="NotSupportedException">Thrown when feature is not supported</exception>
89         /// <exception cref="ArgumentException">Thrown when input coordinates are invalid</exception>
90         /// <exception cref="OutOfMemoryException">Thrown when failed due to out of memory</exception>
91         /// <since_tizen> 4 </since_tizen>
92         public string GetLocationFromNumber(string number, Region region, Language language)
93         {
94             int ret;
95             string result;
96
97             ret = Interop.PhonenumberUtils.GetLocationFromNumber(number, (int)region, (int)language, out result);
98             if (ret != (int)PhonenumberUtilsError.None)
99             {
100                 Log.Error(Globals.LogTag, "Failed to get location, Error - " + (PhonenumberUtilsError)ret);
101                 PhonenumberUtilsErrorFactory.ThrowPhonenumberUtilsException(ret);
102             }
103
104             return result;
105         }
106
107         /// <summary>
108         /// Gets the formatted number.
109         /// </summary>
110         /// <param name="number">The number</param>
111         /// <param name="region">The region of number</param>
112         /// <returns>The formatted number string</returns>
113         /// <feature>http://tizen.org/feature/network.telephony</feature>
114         /// <exception cref="InvalidOperationException">Thrown when method failed due to invalid operation</exception>
115         /// <exception cref="NotSupportedException">Thrown when feature is not supported</exception>
116         /// <exception cref="ArgumentException">Thrown when input coordinates are invalid</exception>
117         /// <exception cref="OutOfMemoryException">Thrown when failed due to out of memory</exception>
118         /// <since_tizen> 4 </since_tizen>
119         public string GetFormattedNumber(string number, Region region)
120         {
121             int ret;
122             string result;
123
124             ret = Interop.PhonenumberUtils.GetFormmatedNumber(number, (int)region, out result);
125             if (ret != (int)PhonenumberUtilsError.None)
126             {
127                 Log.Error(Globals.LogTag, "Failed to get formatted number, Error - " + (PhonenumberUtilsError)ret);
128                 PhonenumberUtilsErrorFactory.ThrowPhonenumberUtilsException(ret);
129             }
130
131             return result;
132         }
133
134         /// <summary>
135         /// Gets the normalized number.
136         /// </summary>
137         /// <param name="number">The number</param>
138         /// <returns>The normalized number</returns>
139         /// <privilege>http://tizen.org/privilege/telephony</privilege>
140         /// <feature>http://tizen.org/feature/network.telephony</feature>
141         /// <exception cref="InvalidOperationException">Thrown when method failed due to invalid operation</exception>
142         /// <exception cref="NotSupportedException">Thrown when feature is not supported</exception>
143         /// <exception cref="ArgumentException">Thrown when input coordinates are invalid</exception>
144         /// <exception cref="OutOfMemoryException">Thrown when failed due to out of memory</exception>
145         /// <exception cref="UnauthorizedAccessException">Thrown when application does not have proper privileges</exception>
146         /// <remarks>
147         /// Normalized number starts with plus('+') and country code, and excludes the separators such as dash or space.
148         /// It is a format of E.164 standard including the country code based on current network.
149         /// </remarks>
150         /// <since_tizen> 4 </since_tizen>
151         public string GetNormalizedNumber(string number)
152         {
153             int ret;
154             string result;
155
156             ret = Interop.PhonenumberUtils.GetNormailizedNumber(number, out result);
157             if (ret != (int)PhonenumberUtilsError.None)
158             {
159                 Log.Error(Globals.LogTag, "Failed to get normalized number, Error - " + (PhonenumberUtilsError)ret);
160                 PhonenumberUtilsErrorFactory.ThrowPhonenumberUtilsException(ret);
161             }
162
163             return result;
164         }
165     }
166 }