/* * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved * * Licensed under the Apache License, Version 2.0 (the License); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * 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; namespace Tizen.Applications { /// /// The class that represents a Tizen application. /// public abstract class Application : IDisposable { internal const string LogTag = "Tizen.Applications"; private static Application s_CurrentApplication = null; private object _lock = new object(); private DirectoryInfo _directoryInfo; private ApplicationInfo _applicationInfo; /// /// Gets the instance of the current application. /// public static Application Current { get { return s_CurrentApplication; } } /// /// Gets the class representing directory information of the current application. /// public DirectoryInfo DirectoryInfo { get { lock (_lock) { if (_directoryInfo == null) { _directoryInfo = new DirectoryInfo(); } } return _directoryInfo; } } /// /// Gets the class representing information of the current application. /// public ApplicationInfo ApplicationInfo { get { lock (_lock) { if (_applicationInfo == null) { string appId = string.Empty; Interop.AppCommon.AppGetId(out appId); if (!string.IsNullOrEmpty(appId)) { _applicationInfo = new ApplicationInfo(appId); } } } return _applicationInfo; } } /// /// Runs the application's main loop. /// /// Arguments from commandline. public virtual void Run(string[] args) { if (args == null) { throw new ArgumentNullException("args"); } s_CurrentApplication = this; } /// /// Exits the main loop of the application. /// public abstract void Exit(); #region IDisposable Support private bool _disposedValue = false; // To detect redundant calls /// /// Releases any unmanaged resources used by this object. Can also dispose any other disposable objects. /// /// If true, disposes any disposable objects. If false, does not dispose disposable objects. protected virtual void Dispose(bool disposing) { if (!_disposedValue) { if (disposing) { if (_applicationInfo != null) { _applicationInfo.Dispose(); } } _disposedValue = true; } } /// /// Finalizer of the application class. /// ~Application() { Dispose(false); } /// /// Releases all resources used by the application class. /// public void Dispose() { Dispose(true); GC.SuppressFinalize(this); } #endregion } }