Release 4.0.0-preview1-00051
[platform/core/csapi/tizenfx.git] / src / Tizen.Pims.Contacts / Tizen.Pims.Contacts / ContactsErrorFactory.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.Internals.Errors;
19
20 namespace Tizen.Pims.Contacts
21 {
22     internal enum ContactsError
23     {
24         None = (int)ErrorCode.None,
25         InvalidParameter = (int)ErrorCode.InvalidParameter,
26         NotSupported = (int)ErrorCode.NotSupported,
27         PermissionDenied = (int)ErrorCode.PermissionDenied,
28         OutOfMemory = (int)ErrorCode.OutOfMemory,
29         FileNoSpaceOnDevice = (int)ErrorCode.FileNoSpaceOnDevice,
30         NoData = (int)ErrorCode.NoData,
31
32         DatabaseLocked = -0x02010000 | 0x81,
33         Database = -0x02010000 | 0x9F,
34         IpcNotAvaliable = -0x02010000 | 0xB1,
35         Ipc = -0x02010000 | 0xBF,
36         System = -0x02010000 | 0xEF
37     }
38
39     internal static class Globals
40     {
41         internal const string LogTag = "Tizen.Pims.Contacts";
42     }
43
44     internal static class ContactsErrorFactory
45     {
46         static internal Exception CheckAndCreateException(int error)
47         {
48             ContactsError e = (ContactsError)error;
49             switch (e)
50             {
51                 case ContactsError.None:
52                     return null;
53                 case ContactsError.InvalidParameter:
54                     return new ArgumentException("Invalid Parameters Provided");
55                 case ContactsError.NotSupported:
56                     return new NotSupportedException("Not Supported");
57                 case ContactsError.PermissionDenied:
58                     return new UnauthorizedAccessException("Permission Denied");
59                 case ContactsError.OutOfMemory:
60                     return new OutOfMemoryException("Out of Memory");
61                 case ContactsError.FileNoSpaceOnDevice:
62                     return new InvalidOperationException("File System is Full");
63                 case ContactsError.NoData:
64                     return new InvalidOperationException("No Data");
65                 case ContactsError.DatabaseLocked:
66                     return new InvalidOperationException("Database Locked");
67                 case ContactsError.Database:
68                     return new InvalidOperationException("Database Failed");
69                 case ContactsError.IpcNotAvaliable:
70                     return new InvalidOperationException("IPC Not Avaliable");
71                 case ContactsError.Ipc:
72                     return new InvalidOperationException("IPC failed");
73                 case ContactsError.System:
74                     return new InvalidOperationException("Internal system error");
75                 default:
76                     return new InvalidOperationException("Unknown Error Code");
77             }
78         }
79     }
80 }