Release 4.0.0-preview1-00051
[platform/core/csapi/tizenfx.git] / src / Tizen.Pims.Calendar / Tizen.Pims.Calendar / CalendarErrorFactory.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.Calendar
21 {
22     internal enum CalendarError
23     {
24         None = Tizen.Internals.Errors.ErrorCode.None,                           /**< Successful */
25         OutOfMemory = Tizen.Internals.Errors.ErrorCode.OutOfMemory,             /**< Out of Memory (-12) */
26         InvalidParameter = Tizen.Internals.Errors.ErrorCode.InvalidParameter,   /**< Invalid parameter (-22) */
27         FileNoSpace = Tizen.Internals.Errors.ErrorCode.FileNoSpaceOnDevice,     /** <FS Full (-28) */
28         PermissionDenied = Tizen.Internals.Errors.ErrorCode.PermissionDenied,   /**< Permission denied (-13) */
29         NotSupported = Tizen.Internals.Errors.ErrorCode.NotSupported,           /**< Not supported (-1073741822) */
30         NoData = Tizen.Internals.Errors.ErrorCode.NoData,                       /**< Requested data does not exist (-61) */
31         DBLocked = Globals.ErrorCalendar | 0x81,                                /**< Database table locked or file locked (-33619839) */
32         ErrorDB = Globals.ErrorCalendar | 0x9F,                                 /**< Unknown DB error (-33619809) */
33         IPCNotAvailable = Globals.ErrorCalendar | 0xB1,                         /**< IPC server is not available (-33619791) */
34         ErrorIPC = Globals.ErrorCalendar | 0xBF,                                /**< Unknown IPC error (-33619777) */
35         ErrorSystem = Globals.ErrorCalendar | 0xEF,                             /**< Internal system module error (-33619729) */
36         ErrorInternal = Globals.ErrorCalendar | 0x04,                           /**< Implementation Error Temporary Use (-33619713) */
37         DBNotFound = Globals.ErrorCalendar | 0x05,                              /**< No data in DB (-33554427) */
38     };
39
40     internal static class Globals
41     {
42         internal const string LogTag = "Tizen.Pims.Calendar";
43         internal const int ErrorCalendar = -0x02000000;
44     }
45
46     internal static class CalendarErrorFactory
47     {
48         internal static void ThrowException(int e)
49         {
50             throw GetException(e);
51         }
52
53         internal static Exception GetException(int e)
54         {
55             Exception exp;
56             switch ((CalendarError)e)
57             {
58             case CalendarError.OutOfMemory:
59                 exp = new OutOfMemoryException("Out of memory");
60                 Log.Error(Globals.LogTag, "Out of memory");
61                 break;
62             case CalendarError.InvalidParameter:
63                 exp = new ArgumentException("Invalid parameter");
64                 Log.Error(Globals.LogTag, "Invalid parameter");
65                 break;
66             case CalendarError.FileNoSpace:
67                 exp = new InvalidOperationException("File no space Error");
68                 Log.Error(Globals.LogTag, "File no space Error");
69                 break;
70             case CalendarError.PermissionDenied:
71                 exp = new UnauthorizedAccessException("Permission denied");
72                 Log.Error(Globals.LogTag, "Permission denied");
73                 break;
74             case CalendarError.NotSupported:
75                 exp = new NotSupportedException("Not supported");
76                 Log.Error(Globals.LogTag, "Not supported");
77                 break;
78             case CalendarError.NoData:
79                 exp = new InvalidOperationException("No data found");
80                 Log.Error(Globals.LogTag, "No data found");
81                 break;
82             case CalendarError.DBLocked:
83                 exp = new InvalidOperationException("DB locked");
84                 Log.Error(Globals.LogTag, "DB locked");
85                 break;
86             case CalendarError.ErrorDB:
87                 exp = new InvalidOperationException("DB error");
88                 Log.Error(Globals.LogTag, "DB error");
89                 break;
90             case CalendarError.IPCNotAvailable:
91                 exp = new InvalidOperationException("IPC not available");
92                 Log.Error(Globals.LogTag, "IPC not available");
93                 break;
94             case CalendarError.ErrorIPC:
95                 exp = new InvalidOperationException("IPC error");
96                 Log.Error(Globals.LogTag, "IPC error");
97                 break;
98             case CalendarError.ErrorSystem:
99                 exp = new InvalidOperationException("System error");
100                 Log.Error(Globals.LogTag, "System error");
101                 break;
102             case CalendarError.ErrorInternal:
103                 exp = new InvalidOperationException("Internal error");
104                 Log.Error(Globals.LogTag, "Internal error");
105                 break;
106             default:
107                 exp = new InvalidOperationException("Invalid operation");
108                 Log.Error(Globals.LogTag, "Invalid operation");
109                 break;
110             }
111             return exp;
112         }
113     }
114 }