Release 4.0.0-preview1-00051
[platform/core/csapi/tizenfx.git] / src / Tizen.Content.MediaContent / Tizen.Content.MediaContent / MediaContentError.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
18 using System;
19 using System.IO;
20 using Tizen.Internals.Errors;
21
22 namespace Tizen.Content.MediaContent
23 {
24     /// <summary>
25     /// Enumeration for media content's error code
26     /// </summary>
27     /// <since_tizen> 3 </since_tizen>
28     /// <remarks><paramref name="NotSupported"/> error occurs when the device does not support the function.</remarks>
29     public enum MediaContentError
30     {
31         None = ErrorCode.None,
32         InvalidParameter = ErrorCode.InvalidParameter,
33         OutOfMemory = ErrorCode.OutOfMemory,
34         InvalidOperation = ErrorCode.InvalidOperation,
35         FileNoSpaceOnDevice = ErrorCode.FileNoSpaceOnDevice,
36         PermissionDenied = ErrorCode.PermissionDenied,
37         TizenMediaContentError = -0x01610000,
38         DatabaseFailed = TizenMediaContentError | 0x01,
39         DatabaseBusy = TizenMediaContentError | 0x02,
40         NetworkFailed = TizenMediaContentError | 0x03,
41         UnsupportedContent = TizenMediaContentError | 0x04,
42         NotSupported = ErrorCode.NotSupported,
43     }
44
45     internal class MediaContentValidator
46     {
47         internal const string LogTag = "Tizen.Content.MediaContent";
48
49         internal static void ThrowIfError(MediaContentError err, string msg)
50         {
51             switch (err)
52             {
53                 case MediaContentError.InvalidParameter:
54                     throw new ArgumentException(msg);
55                 case MediaContentError.OutOfMemory:
56                     throw new OutOfMemoryException(msg);
57                 case MediaContentError.InvalidOperation:
58                     throw new InvalidOperationException(msg);
59                 case MediaContentError.FileNoSpaceOnDevice:
60                     throw new IOException(msg);
61                 case MediaContentError.PermissionDenied:
62                     throw new UnauthorizedAccessException(msg);
63                 case MediaContentError.DatabaseFailed:
64                     throw new InvalidOperationException("[DB Failed]" + msg);
65                 case MediaContentError.DatabaseBusy:
66                     throw new InvalidOperationException("[DB Busy]" + msg);
67                 case MediaContentError.NetworkFailed:
68                     throw new InvalidOperationException("[Network Error]" + msg);
69                 case MediaContentError.UnsupportedContent:
70                     throw new PlatformNotSupportedException(msg);
71             }
72         }
73
74         internal static string CheckString(string value)
75         {
76             return (value != null) ? value : "";
77         }
78     }
79 }