/
AccountErrorFactory.cs
219 lines (204 loc) · 7.37 KB
/
AccountErrorFactory.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
/*
* Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
*
* Licensed under the Apache License, Version 2.0 (the License);
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an AS IS BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
using System;
using System.IO;
using Tizen.System;
namespace Tizen.Account.AccountManager
{
/// <summary>
/// Enumeration for the types of error occurred, if any.
/// </summary>
/// <since_tizen> 3 </since_tizen>
public enum AccountError
{
//TIZEN_ERROR_ACCOUNT = -0x01000000
/// <summary>
/// Successful.
/// </summary>
/// <since_tizen> 3 </since_tizen>
None = Tizen.Internals.Errors.ErrorCode.None,
/// <summary>
/// Invalid parameter.
/// </summary>
/// <since_tizen> 3 </since_tizen>
InvalidParameter = Tizen.Internals.Errors.ErrorCode.InvalidParameter,
/// <summary>
/// Out of memory.
/// </summary>
/// <since_tizen> 3 </since_tizen>
OutOfMemory = Tizen.Internals.Errors.ErrorCode.OutOfMemory,
/// <summary>
/// Same user name exists in your application.
/// </summary>
/// <since_tizen> 4 </since_tizen>
Duplicated = -0x01000000 | 0x01,
/// <summary>
/// Empty data.
/// </summary>
/// <since_tizen> 3 </since_tizen>
NoData = Tizen.Internals.Errors.ErrorCode.NoData,
/// <summary>
/// Elated record does not exist.
/// </summary>
/// <since_tizen> 3 </since_tizen>
RecordNotFound = -0x01000000 | 0x03,
/// <summary>
/// Invalid operation.
/// </summary>
/// <since_tizen> 3 </since_tizen>
InvalidOperation = Tizen.Internals.Errors.ErrorCode.InvalidOperation,
/// <summary>
/// DB operation failed.
/// </summary>
/// <since_tizen> 3 </since_tizen>
DBFailed = -0x01000000 | 0x04,
/// <summary>
/// DB is not connected.
/// </summary>
/// <since_tizen> 3 </since_tizen>
DBNotOpened = -0x01000000 | 0x05,
/// <summary>
/// DB query syntax error.
/// </summary>
/// <since_tizen> 3 </since_tizen>
QuerySyntaxError = -0x01000000 | 0x06,
/// <summary>
/// Iterator has reached the end.
/// </summary>
/// <since_tizen> 3 </since_tizen>
IteratorEnd = -0x01000000 | 0x07,
/// <summary>
/// Notification failed.
/// </summary>
/// <since_tizen> 3 </since_tizen>
NotificationFailed = -0x01000000 | 0x08,
/// <summary>
/// Permission denied.
/// </summary>
/// <since_tizen> 3 </since_tizen>
PermissionDenied = Tizen.Internals.Errors.ErrorCode.PermissionDenied,
/// <summary>
/// XML parse failed.
/// </summary>
/// <since_tizen> 3 </since_tizen>
XMLParseFailed = -0x01000000 | 0x0a,
/// <summary>
/// XML file not found.
/// </summary>
/// <since_tizen> 3 </since_tizen>
XMLFileNotFound = -0x01000000 | 0x0b,
/// <summary>
/// Subscription failed
/// </summary>
/// <since_tizen> 3 </since_tizen>
EventSubscriptionFailed = -0x01000000 | 0x0c,
/// <summary>
/// Account provider is not registered.
/// </summary>
/// <since_tizen> 3 </since_tizen>
ProviderNotRegistered = -0x01000000 | 0x0d,
/// <summary>
/// Multiple accounts are not supported.
/// </summary>
/// <since_tizen> 3 </since_tizen>
MultipleNotAllowed = -0x01000000 | 0x0e,
/// <summary>
/// SQLite busy handler expired.
/// </summary>
/// <since_tizen> 3 </since_tizen>
DBBusy = -0x01000000 | 0x10
};
internal class AccountErrorFactory
{
internal const string LogTag = "Tizen.Account.AccountManager";
internal static Exception CreateException(AccountError err, string msg)
{
Log.Info(LogTag, "Got Error " + err + " throwing Exception with msg " + msg);
Exception exp;
switch (err)
{
case AccountError.InvalidParameter:
{
exp = new ArgumentException($"{msg} Invalid Parameters Provided");
break;
}
case AccountError.OutOfMemory:
{
exp = new OutOfMemoryException($"{msg} Out Of Memory");
break;
}
case AccountError.InvalidOperation:
{
exp = new InvalidOperationException($"{msg} Inavlid operation");
break;
}
case AccountError.NoData:
{
exp = new InvalidOperationException($"{msg} Empty Data");
break;
}
case AccountError.PermissionDenied:
{
exp = new UnauthorizedAccessException($"{msg} Permission Denied");
break;
}
case AccountError.DBFailed:
{
exp = new InvalidOperationException($"{msg} DataBase Failed");
break;
}
case AccountError.DBBusy:
{
exp = new InvalidOperationException($"{msg} DataBase Busy");
break;
}
case AccountError.QuerySyntaxError:
{
exp = new InvalidOperationException($"{msg} Network Error");
break;
}
case AccountError.XMLFileNotFound:
{
exp = new FileNotFoundException($"{msg} XML File not found");
break;
}
case AccountError.XMLParseFailed:
{
exp = new InvalidDataException($"{msg} XML parse error");
break;
}
default:
{
exp = new InvalidOperationException(err + " " + msg);
break;
}
}
return exp;
}
internal static bool IsAccountFeatureSupported()
{
return ((Information.TryGetValue("http://tizen.org/feature/account", out bool IsAccountSupported)) && IsAccountSupported);
}
internal static void CheckAccountFeature()
{
if (IsAccountFeatureSupported() == false)
{
Log.Warn(AccountErrorFactory.LogTag, "platform account feature is disabled");
throw new NotSupportedException("platform account feature is disabled");
}
}
}
}