Exemplo n.º 1
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Initializes a new instance of the <see cref="T:CacheManager"/> class.
		/// </summary>
		/// ------------------------------------------------------------------------------------
		public CacheManager()
		{
			if (!Properties.Settings.Default.UseFileCache)
				return;

			// Register the remote class
			if (Properties.Settings.Default.UseRemoteCache)
			{
				if (RemotingConfiguration.IsWellKnownClientType(typeof(RemoteCacheManager)) == null)
				{
					// save temporary config file to configure the type
					string config = string.Format("<?xml version=\"1.0\" encoding=\"utf-8\" ?>" +
								"<configuration><system.runtime.remoting><application><client>" +
								"<wellknown  type=\"SIL.FieldWorks.Tools.FileCache.RemoteCacheManager, RemoteFileCache\" " +
								"url=\"tcp://{0}:8700/FileCache.rem\"/></client>" +
								"<channels><channel ref=\"tcp\" port=\"0\"><serverProviders><formatter ref=\"binary\" typeFilterLevel=\"Full\" />" +
								"</serverProviders><clientProviders><formatter ref=\"binary\" typeFilterLevel=\"Full\"/></clientProviders>" +
								"</channel></channels></application></system.runtime.remoting></configuration>",
								Properties.Settings.Default.RemoteHost);
					string tempConfigFile = Path.GetTempFileName();
					StreamWriter writer = new StreamWriter(tempConfigFile);
					writer.Write(config);
					writer.Close();

					RemotingConfiguration.Configure(tempConfigFile, true);

					// now delete our temporary config file
					File.Delete(tempConfigFile);
				}

				m_remoteCacheMgr = new RemoteCacheManager();
			}
		}
Exemplo n.º 2
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Executes in two distinct scenarios.
		/// 1. If disposing is true, the method has been called directly
		/// or indirectly by a user's code via the Dispose method.
		/// Both managed and unmanaged resources can be disposed.
		/// 2. If disposing is false, the method has been called by the
		/// runtime from inside the finalizer and you should not reference (access)
		/// other managed objects, as they already have been garbage collected.
		/// Only unmanaged resources can be disposed.
		/// </summary>
		/// <param name="disposing">if set to <c>true</c> this method is called from the
		/// Dispose() method, if set to <c>false</c> it's called from finalizer.</param>
		/// <remarks>
		/// If any exceptions are thrown, that is fine.
		/// If the method is being done in a finalizer, it will be ignored.
		/// If it is thrown by client code calling Dispose,
		/// it needs to be handled by fixing the bug.
		/// If subclasses override this method, they should call the base implementation.
		/// </remarks>
		/// ------------------------------------------------------------------------------------
		protected override void Dispose(bool disposing)
		{
			if (disposing)
			{
				// Dispose managed resources here.
				if (m_remoteCacheMgr != null)
				{
					try
					{
						m_remoteCacheMgr.Close();
					}
					catch (Exception e)
					{
						Console.WriteLine("Got exception accessing remote cache: " + e.Message);
					}
				}
			}

			// Dispose unmanaged resources here
			m_remoteCacheMgr = null;

			base.Dispose(disposing);
		}