[TCSACR-81][ADD] Added new property to get account handle
[platform/core/csapi/tizenfx.git] / src / Tizen.Account.AccountManager / Tizen.Account.AccountManager / AccountErrorFactory.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 Tizen;
19
20 namespace Tizen.Account.AccountManager
21 {
22     /// <summary>
23     /// Enumeration for the types of error occured, if any.
24     /// </summary>
25     /// <since_tizen> 3 </since_tizen>
26     public enum AccountError
27     {
28         //TIZEN_ERROR_ACCOUNT = -0x01000000
29         /// <summary>
30         /// Successful.
31         /// </summary>
32         /// <since_tizen> 3 </since_tizen>
33         None = Tizen.Internals.Errors.ErrorCode.None,
34         /// <summary>
35         /// Invalid parameter.
36         /// </summary>
37         /// <since_tizen> 3 </since_tizen>
38         InvalidParameter = Tizen.Internals.Errors.ErrorCode.InvalidParameter,
39         /// <summary>
40         /// Out of memory.
41         /// </summary>
42         /// <since_tizen> 3 </since_tizen>
43         OutOfMemory = Tizen.Internals.Errors.ErrorCode.OutOfMemory,
44         /// <summary>
45         /// Same user name exists in your application.
46         /// </summary>
47         /// <since_tizen> 3 </since_tizen>
48         Duplcated = -0x01000000 | 0x01,
49         /// <summary>
50         /// Empty data.
51         /// </summary>
52         /// <since_tizen> 3 </since_tizen>
53         NoData = Tizen.Internals.Errors.ErrorCode.NoData,
54         /// <summary>
55         /// Elated record does not exist.
56         /// </summary>
57         /// <since_tizen> 3 </since_tizen>
58         RecordNotFound = -0x01000000 | 0x03,
59         /// <summary>
60         /// Invalid operation.
61         /// </summary>
62         /// <since_tizen> 3 </since_tizen>
63         InvalidOperation = Tizen.Internals.Errors.ErrorCode.InvalidOperation,
64         /// <summary>
65         /// DB operation failed.
66         /// </summary>
67         /// <since_tizen> 3 </since_tizen>
68         DBFailed = -0x01000000 | 0x04,
69         /// <summary>
70         ///  DB is not connected.
71         /// </summary>
72         /// <since_tizen> 3 </since_tizen>
73         DBNotOpened = -0x01000000 | 0x05,
74         /// <summary>
75         /// DB query syntax error.
76         /// </summary>
77         /// <since_tizen> 3 </since_tizen>
78         QuerySyntaxError = -0x01000000 | 0x06,
79         /// <summary>
80         /// Iterator has reached the end.
81         /// </summary>
82         /// <since_tizen> 3 </since_tizen>
83         IteratorEnd = -0x01000000 | 0x07,
84         /// <summary>
85         /// Notification failed.
86         /// </summary>
87         /// <since_tizen> 3 </since_tizen>
88         NotificationFailed = -0x01000000 | 0x08,
89         /// <summary>
90         /// Permission denied.
91         /// </summary>
92         /// <since_tizen> 3 </since_tizen>
93         PermissionDenied = Tizen.Internals.Errors.ErrorCode.PermissionDenied,
94         /// <summary>
95         /// XML parse failed.
96         /// </summary>
97         /// <since_tizen> 3 </since_tizen>
98         XMLParseFailed = -0x01000000 | 0x0a,
99         /// <summary>
100         /// XML file not found.
101         /// </summary>
102         /// <since_tizen> 3 </since_tizen>
103         XMLFileNotFound = -0x01000000 | 0x0b,
104         /// <summary>
105         /// Subscription failed
106         /// </summary>
107         /// <since_tizen> 3 </since_tizen>
108         EventSubscriptionFailed = -0x01000000 | 0x0c,
109         /// <summary>
110         /// Account provider is not registered.
111         /// </summary>
112         /// <since_tizen> 3 </since_tizen>
113         ProviderNotRegistered = -0x01000000 | 0x0d,
114         /// <summary>
115         /// Multiple accounts are not supported.
116         /// </summary>
117         /// <since_tizen> 3 </since_tizen>
118         MultipleNotAllowed = -0x01000000 | 0x0e,
119         /// <summary>
120         /// SQLite busy handler expired.
121         /// </summary>
122         /// <since_tizen> 3 </since_tizen>
123         DBBusy = -0x01000000 | 0x10
124     };
125
126     internal class AccountErrorFactory
127     {
128         internal const string LogTag = "Tizen.Account.AccountManager";
129
130         internal static Exception CreateException(AccountError err, string msg)
131         {
132             Log.Info(LogTag, "Got Error " + err + " throwing Exception with msg " + msg);
133             Exception exp;
134             switch (err)
135             {
136                 case AccountError.InvalidParameter:
137                     {
138                         exp = new ArgumentException(msg + " Invalid Parameters Provided");
139                         break;
140                     }
141
142                 case AccountError.OutOfMemory:
143                     {
144                         exp = new OutOfMemoryException(msg + " Out Of Memory");
145                         break;
146                     }
147
148                 case AccountError.InvalidOperation:
149                     {
150                         exp = new InvalidOperationException(msg + " Inavlid operation");
151                         break;
152                     }
153
154                 case AccountError.NoData:
155                     {
156                         exp = new InvalidOperationException(msg + " Empty Data");
157                         break;
158                     }
159
160                 case AccountError.PermissionDenied:
161                     {
162                         exp = new UnauthorizedAccessException(msg + " Permission Denied");
163                         break;
164                     }
165
166                 case AccountError.DBFailed:
167                     {
168                         exp = new InvalidOperationException(msg + " DataBase Failed");
169                         break;
170                     }
171
172                 case AccountError.DBBusy:
173                     {
174                         exp = new InvalidOperationException(msg + " DataBase Busy");
175                         break;
176                     }
177
178                 case AccountError.QuerySyntaxError:
179                     {
180                         exp = new InvalidOperationException(msg + " Network Error");
181                         break;
182                     }
183                 case AccountError.XMLFileNotFound:
184                     {
185                         exp = new System.IO.FileNotFoundException(msg + " XML File not found");
186                         break;
187                     }
188                 case AccountError.XMLParseFailed:
189                     {
190                         exp = new System.IO.InvalidDataException(msg + " XML parse error");
191                         break;
192                     }
193
194                 default:
195                     {
196                         exp = new InvalidOperationException(err + " " + msg);
197                         break;
198                     }
199             }
200
201             return exp;
202         }
203     }
204 }