Release 4.0.0-preview1-00051
[platform/core/csapi/tizenfx.git] / src / Tizen.Applications.Badge / Tizen.Applications / BadgeErrorFactory.cs
1 /*
2  * Copyright (c) 2017 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 namespace Tizen.Applications
18 {
19     using System;
20     using System.Runtime.CompilerServices;
21
22     internal enum BadgeError
23     {
24         None = Tizen.Internals.Errors.ErrorCode.None,
25         InvalidParameter = Tizen.Internals.Errors.ErrorCode.InvalidParameter,
26         OutOfMemory = Tizen.Internals.Errors.ErrorCode.OutOfMemory,
27         PermissionDenied = Tizen.Internals.Errors.ErrorCode.PermissionDenied,
28         IoError = Tizen.Internals.Errors.ErrorCode.IoError,
29         DbError = -0x01120000 | 0x01,
30         AlreadyExists = -0x01120000 | 0x02,
31         DBusError = -0x01120000 | 0x03,
32         DoesnotExist = -0x01120000 | 0x04,
33         ServiceError = -0x01120000 | 0x05,
34         InvalidPackage = -0x01120000 | 0x06
35     }
36
37     /// <summary>
38     /// Immutable class for getting the badge information.
39     /// </summary>
40     internal static class BadgeErrorFactory
41     {
42         private static readonly string LogTag = "Tizen.Applications.Badge";
43
44         internal static Exception GetException(BadgeError ret, string msg, [CallerMemberName] string memberName = "", [CallerFilePath] string filePath = "", [CallerLineNumber] int lineNumber = 0)
45         {
46             Log.Error(LogTag, memberName + " : " + lineNumber);
47
48             switch (ret)
49             {
50                 case BadgeError.InvalidParameter:
51                     Log.Error(LogTag, msg);
52                     return new ArgumentException(ret + " error occurred.");
53                 case BadgeError.PermissionDenied:
54                     throw new UnauthorizedAccessException("Permission denied (http://tizen.org/privilege/notification)");
55                 default:
56                     Log.Error(LogTag, msg);
57                     return new InvalidOperationException(ret + " error occurred.");
58             }
59         }
60     }
61 }