# region Copyright
//==================================================================================
// Init.cs
// This file is part of Jetfire.  http://Jetfire.ca
// 
// Jetfire is open software: you can redistribute it and/or modify it under the terms of the GNU General Public
//  License as published by the Free Software Foundation, version 3 of the License.
// 
// Jetfire is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied 
//  warrantyof MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License 
//  for more details.
// 
// You should have received a copy of the GNU General Public License along with Jetfire.  If not, see 
// <http://www.gnu.org/licenses/>.
// REMOVAL OF THIS NOTICE IS VIOLATION OF THE COPYRIGHT.
//==================================================================================
# endregion

# region using
using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using TrackerRealm.Jetfire.TransportCommon;
using TrackerRealm.Jetfire;
using TrackerRealm.Jetfire.Base;
using TrackerRealm.Jetfire.Common;
using TrackerRealm.Jetfire.Nexus;
using TrackerRealm.Jetfire.MemoryTransport;
using TrackerRealm.Jetfire.NexusFileStorage;
# endregion

namespace JetfireCoreExampleTests
{
	/// <summary>
	/// Used to initialize and dispose of Forms Authentication Storage
	/// </summary>
	public class Init
	{
		# region Public Static Methods for File Storage
		/// <summary>
		/// Starts the File Storage - stores data in a file mechanism on disk
		/// </summary>
		/// <param name="fileStorage">reference to File Storage</param>
		/// <returns></returns>
		public static TjMemoryTransport StartFileStorage(ref TjFileStorage fileStorage)
		{
			return Init.StartFileStorage(ref fileStorage, true);
		}
		/// <summary>
		/// Starts the File Storage - stores data in a file mechanism on disk
		/// </summary>
		/// <param name="fileStorage">reference to File Storage</param>
		/// <param name="clearStorage">Option to Clear the Storage</param>
		/// <returns></returns>
		public static TjMemoryTransport StartFileStorage(ref TjFileStorage fileStorage, bool clearStorage)
		{
			fileStorage = new TjFileStorage("c:/jetfiretest");
			// Clear the file storage at startup
			if (clearStorage)
				fileStorage.Clear();
			TjServerNexus serverNexus = new TjServerNexus(fileStorage);
			TjLoginConnection loginConnection = new TjLoginConnection(
				new TjLoginObjectUser(""), 
				new TjLoginObjectSubscription(""), 
				new TjLoginObjectRole[0], null);
			TjMemoryTransport transport = new TjMemoryTransport(loginConnection, serverNexus);
			return transport;
		}
		/// <summary>
		/// Disposes of storage and clears the database.  
		/// IsTest set to false.
		/// </summary>
		/// <param name="fileStorage"></param>
		/// <param name="transport"></param>
		public static void StopFileStorage(TjFileStorage fileStorage, TjMemoryTransport transport)
		{
			if (transport != null)
			{
				TjAuditIncident[] incidents = transport.ClientNexus.ToIncidentArray();
				if (incidents.Length > 0)
					Assert.Fail("There are incidents: " + incidents[0].Message);
				transport.Dispose();
			}
		}
		/// <summary>
		/// Disposes of storage and clears the database.  
		/// IsTest set to false.
		/// </summary>
		/// <param name="fileStorage">File Storage</param>
		/// <param name="transport">Memory Transport</param>
		/// <param name="checkIncidents">Option to Check Incidents (Some exceptions by design)</param>
		public static void StopFileStorage(TjFileStorage fileStorage, TjMemoryTransport transport, 
				bool checkIncidents)
		{
			if (transport != null && checkIncidents)
			{
				TjAuditIncident[] incidents = transport.ClientNexus.ToIncidentArray();
				if (incidents.Length > 0)
					Assert.Fail("There are incidents: " + incidents[0].Message);
			}
			if (transport != null)
				transport.Dispose();
		}
		/// <summary>
		/// Logoff and then log back in - do NOT clear FileStorage
		/// </summary>
		/// <param name="fileStorage"></param>
		/// <param name="transport"></param>
		public static TjNexus LogoffLogin(ref TjFileStorage fileStorage, ref TjMemoryTransport transport)
		{
			Int.SopFileStorage(fileStorage, transport, false);
			fileStorage = null;
			// Log back in
			transport = Init.StartFileStorage(ref fileStorage, false);
			return transport.ClientNexus;
		}
		# endregion
	}
}

Last edited Apr 7, 2008 at 11:30 AM by CharlesW, version 6

Comments

No comments yet.