// Copyright (C) 2016, The Duplicati Team // http://www.duplicati.com, info@duplicati.com // // This library is free software; you can redistribute it and/or modify // it under the terms of the GNU Lesser General Public License as // published by the Free Software Foundation; either version 2.1 of the // License, or (at your option) any later version. // // This library is distributed in the hope that it will be useful, but // WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. // // You should have received a copy of the GNU Lesser General Public // License along with this library; if not, write to the Free Software // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA using System; namespace Duplicati.Library.Localization { /// /// Helper class for choosing a temporary localization context /// internal class LocalizationContext : IDisposable { /// /// The previous context /// private object m_prev; /// /// Flag to prevent double dispose /// private bool m_isDisposed = true; /// /// Initializes a new instance of the class. /// /// The localization to use. public LocalizationContext(System.Globalization.CultureInfo ci) { m_prev = System.Runtime.Remoting.Messaging.CallContext.LogicalGetData(LocalizationService.LOGICAL_CONTEXT_KEY); System.Runtime.Remoting.Messaging.CallContext.LogicalSetData(LocalizationService.LOGICAL_CONTEXT_KEY, ci.Name); m_isDisposed = false; } /// /// Releases all resource used by the object. /// /// Call when you are finished using the /// . The method leaves /// the in an unusable state. After calling /// , you must release all references to the /// so the garbage collector can reclaim the /// memory that the was occupying. public void Dispose() { if (!m_isDisposed) { System.Runtime.Remoting.Messaging.CallContext.LogicalSetData(LocalizationService.LOGICAL_CONTEXT_KEY, m_prev); m_isDisposed = true; } } } }