/* * Copyright (c) 2017 Samsung Electronics Co., Ltd * * Licensed under the Flora License, Version 1.1 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://floralicense.org/license/ * * 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.Runtime.CompilerServices; using Xamarin.Forms; namespace LibTVRefCommonPortable.Utils { /// /// A debugging utility class. /// public sealed class DebuggingUtils { /// /// A debugging API interface /// private static IDebuggingAPIs ism; /// /// An instance of DebuggingUtils /// private static readonly DebuggingUtils instance = new DebuggingUtils(); /// /// A method provides instance of DebuggingUtils. public static DebuggingUtils Instance { get { return instance; } } /// /// Default implementation of IDebuggingAPIs interface . /// This is required for the unit testing of the Calculator application. /// private class DefaultSM : IDebuggingAPIs { /// /// A method displays an error log. /// /// An error message. /// A file name. /// A function name. /// A line number. public void Dbg(string message, String file, String func, Int32 line) { } /// /// A method displays a dialog with a given message. /// /// A debugging message. /// A file name. /// A function name. /// A line number. public void Err(string message, String file, String func, Int32 line) { } /// /// A method displays a debugging log. /// /// A debugging message. public void Popup(string message) { } } /// /// DebuggingUtils constructor which set interface instance. /// private DebuggingUtils() { ism = new DefaultSM(); try { if (DependencyService.Get() != null) { ism = DependencyService.Get(); } } catch (InvalidOperationException e) { Err(e.Message); } } /// /// A method displays a debugging message /// /// A list of command line arguments. /// A file name. /// A function name. /// A line number. public static void Dbg(string message, [CallerFilePath] System.String file = "", [CallerMemberName] System.String func = "", [CallerLineNumber] System.Int32 line = 0) { ism.Dbg(message, file, func, line); } /// /// A method displays an error message /// /// A list of command line arguments. /// A file name. /// A function name. /// A line number. public static void Err(string message, [CallerFilePath] System.String file = "", [CallerMemberName] System.String func = "", [CallerLineNumber] System.Int32 line = 0) { ism.Err(message, file, func, line); } /// /// A method displays a pop up message /// /// A list of command line arguments. public static void Popup(string message) { ism.Popup(message); } } }