Object prevalence engine. Provides transparent object persistence to deterministic systems.

The prevalent system class must be serializable and deterministic: two instances of the same class when exposed to the same set of commands and queries must reach the same final state and yield the same query results.

In order to be deterministic, the prevalent system class must use PrevalenceEngine.Clock or PrevalenceEngine.Now for all its date/time related functions.

Any change to the prevalent system must be represented by a serializable command object (ICommand) executed through ExecuteCommand.

Queries to the prevalent system are best implemented as query objects (IQuery) executed through ExecuteQuery.

The prevalence engine employs a reader/writer lock strategy to coordenate the work of command and query objects - that way multiple query objects are allowed to execute in paralell and command objects are only allowed to execute one by one.

The great news is that if you design your prevalent system in such a way that its state is only manipulated and queried through command and query objects you don't have to worry about synchronization, to a simple example of such a system please refer to the Bamboo.Prevalence.Tests project.

Optionally, if you don't like the idea of designing your system around command and query objects and would rather use simple method calls onto your prevalent system class, take a look at PrevalenceActivator.CreateTransparentEngine or Bamboo.Prevalence.Attributes.TransparentPrevalenceAttribute.

Inheritance: System.MarshalByRefObject
コード例 #1
0
		public Application()
		{
			string prevalenceBase = Path.Combine(Environment.CurrentDirectory, "data");

			_engine = PrevalenceActivator.CreateTransparentEngine(typeof(ToDoList), prevalenceBase);
			_system = _engine.PrevalentSystem as ToDoList;
		}
コード例 #2
0
		/// <summary>
		/// Returns a list with all the files in the PrevalenceBase
		/// folder sorted by name.
		/// </summary>
		/// <param name="engine">the prevalence engine</param>
		/// <returns>list of files sorted by name</returns>
		public static FileInfo[] GetPrevalenceFilesSortedByName(PrevalenceEngine engine)
		{
			DirectoryInfo prevalenceBase = engine.PrevalenceBase;			
			FileInfo[] files = prevalenceBase.GetFiles("*.*");
			SortFilesByName(files);
			return files;
		}
コード例 #3
0
ファイル: Program.cs プロジェクト: LarryVon/TestRepo
 public SnapshotTaker(PrevalenceEngine engine, double interval)
 {
     _engine = engine;
     _timer = new Timer(interval);
     _timer.AutoReset = true;
     _timer.Elapsed += new ElapsedEventHandler(Elapsed);
     _timer.Start();
 }
コード例 #4
0
		public ProjectController( PestControlModel model, 
			PrevalenceEngine engine, SourceControlManager scm, BuildSystemManager bsm)
		{
			_engine = engine;
			_model = model;
			_scm = scm;
			_bsm = bsm;
		}
コード例 #5
0
		public void SetUp()
		{
			// O primeiro passo � limpar qualquer resqu�cio de
			// testes anteriores para come�ar com uma "base" limpa
			ClearPrevalenceBase();

			_engine = PrevalenceActivator.CreateEngine(typeof(TaskManagementSystem), PrevalenceBase);
			_system = _engine.PrevalentSystem as TaskManagementSystem;
		}
コード例 #6
0
		private void CreateSnapshotTaker(PrevalenceEngine engine, float snapshotPeriod)
		{
			TimeSpan period = TimeSpan.FromHours(snapshotPeriod);
			ICleanUpPolicy policy = (ICleanUpPolicy) Kernel[PrevalenceFacility.CleanupPolicyComponentPropertyKey];

			SnapshotTaker taker = new SnapshotTaker(engine, period, policy);

			Kernel.AddComponentInstance(PrevalenceFacility.SnapShotTakerComponentPropertyKey, taker);
		}
コード例 #7
0
ファイル: Prevayler.cs プロジェクト: bamboo/Bamboo.Prevalence
		protected void Application_Start(Object sender, EventArgs e)
		{
			string datapath = ConfigurationSettings.AppSettings["DataPath"];
			long counter = Convert.ToInt64(ConfigurationSettings.AppSettings["DataSnapshot"]);
			long delay = 0;

			engine = PrevalenceActivator.CreateEngine(typeof(PetStore), datapath);
			timer = new Timer(new TimerCallback(TakeSnapshot), null, delay, counter);
		}
コード例 #8
0
		public void Init()
		{
			DefaultConfigurationStore store = new DefaultConfigurationStore();
			XmlInterpreter interpreter = new XmlInterpreter( new ConfigResource() );
			interpreter.ProcessResource(interpreter.Source, store);
			_container = new PestControlContainer(interpreter);

			_model = (PestControlModel) _container["pestcontrolModel"];
			_engine = (PrevalenceEngine) _container["prevalenceengine"];
		}
コード例 #9
0
        static PrevalenceEngine GetCurrent(string methodName)
        {
            PrevalenceEngine current = PrevalenceEngine.Current;

            if (null == current)
            {
                throw new InvalidOperationException(string.Format("{0} can only be called during the execution of a command or query!"));
            }
            return(current);
        }
コード例 #10
0
		/// <summary>
		/// Returns a list with all the files that are no
		/// longer necessary to restore the state of
		/// the prevalence system.
		/// </summary>
		/// <param name="engine">the prevalence engine</param>
		/// <returns>list with files sorted by name</returns>
		public static FileInfo[] GetUnnecessaryPrevalenceFiles(PrevalenceEngine engine)
		{
			FileInfo[] all = GetPrevalenceFilesSortedByName(engine);			
			int lastSnapshotIndex = FindLastSnapshot(all);
			if (lastSnapshotIndex > 0)
			{	
				return GetFileInfoRange(all, 0, lastSnapshotIndex);				
			}
			else
			{
				return NullCleanUpPolicy.EmptyFileInfoArray;
			}
		}
コード例 #11
0
		/// <summary>
		/// Creates a new SnapshotTaker for the PrevalenceEngine engine
		/// with a period between snapshots equals to period. Files
		/// will be removed according to the specified cleanUpPolicy object.
		/// </summary>
		/// <param name="engine">prevalence engine to take snapshots from</param>
		/// <param name="period">period between snapshots</param>
		/// <param name="cleanUpPolicy">clean up policy</param>
		public SnapshotTaker(PrevalenceEngine engine, TimeSpan period, ICleanUpPolicy cleanUpPolicy)
		{
			if (null == engine)
			{
				throw new ArgumentNullException("engine");
			}			

			if (null == cleanUpPolicy)
			{
				throw new ArgumentNullException("cleanUpPolicy");
			}

			_cleanUpPolicy = cleanUpPolicy;
			_timer = new Timer(new TimerCallback(OnTimer), engine, period, period);			
		}
コード例 #12
0
		/// <summary>
		/// Creates a new prevalence engine for the prevalent system
		/// type specified by the systemType argument with the option
		/// to automatically support the migration from older serialization
		/// layout versions.
		/// </summary>
		/// <param name="systemType">prevalent system type, must be serializable</param>
		/// <param name="prevalenceBase">directory where to store log files</param>
		/// <param name="autoVersionMigration">include support for auto version migration</param>
		/// <param name="handler">delegate to receive notifications about any exceptions during recovery</param>
		/// <returns>a new prevalence engine</returns>
		public static PrevalenceEngine CreateEngine(System.Type systemType, string prevalenceBase, bool autoVersionMigration, PrevalenceEngine.ExceptionDuringRecoveryHandler handler)
		{
			CheckEngineParameters(systemType, prevalenceBase);

			BinaryFormatter formatter;

			if (autoVersionMigration)
			{
				formatter = CreateAutoVersionMigrationFormatter(systemType);
			}
			else
			{
				formatter = CreateBinaryFormatter();
			}

			return CreateRequestedEngine(systemType, prevalenceBase, formatter, handler);
		}
コード例 #13
0
ファイル: MainForm.cs プロジェクト: bamboo/Bamboo.Prevalence
		public MainForm()
		{
			//
			// Required for Windows Form Designer support
			//
			InitializeComponent();

			//
			// TODO: Add any constructor code after InitializeComponent call
			//
			_engine = PrevalenceActivator.CreateEngine(typeof(TaskManagementSystem), PrevalenceBase);
			_system = _engine.PrevalentSystem as TaskManagementSystem;

			RefreshProjectView();

			_status.Text = PrevalenceBase;
		}
コード例 #14
0
		public PrevalentSystemProxy(PrevalenceEngine engine, MarshalByRefObject system) : base(system.GetType())
		{
			_engine = engine;
			_system = system;
		}
コード例 #15
0
 private static void InternalCreateCacheSystem(string dataDir)
 {
     if (!Directory.Exists(dataDir))
     {
         LoggingService.InfoFormatted("建立缓存目录{0}", new object[] { dataDir });
         Directory.CreateDirectory(dataDir);
     }
     _engine = PrevalenceActivator.CreateTransparentEngine(typeof(CacheSystem), dataDir);
     _system = _engine.PrevalentSystem as CacheSystem;
 }
コード例 #16
0
		public TestCurrentCommandAndQuery(PrevalenceEngine engine)
		{
			_engine = engine;
		}
コード例 #17
0
		public TransparentPrevalenceEngine(System.Type systemType, string prevalenceBase, BinaryFormatter formatter, PrevalenceEngine.ExceptionDuringRecoveryHandler handler) :
			base(systemType, prevalenceBase, formatter, handler)
		{
			CreateProxy();
		}
コード例 #18
0
 static MoteurPrevalence()
 {
     Moteur = PrevalenceActivator.CreateEngine(typeof(Stockage), Path.Combine(Path.GetTempPath(), "Persistance"));
 }
コード例 #19
0
		/// <summary>
		/// Should be implemented by derived classes. 
		/// See <see cref="ICleanUpPolicy.SelectFiles"/> for details.
		/// </summary>
		/// <param name="engine"></param>
		/// <returns></returns>
		public abstract FileInfo[] SelectFiles(PrevalenceEngine engine);
コード例 #20
0
		/// <summary>
		/// Same as <see cref="PrevalenceBaseUtil.GetUnnecessaryPrevalenceFiles"/>.
		/// </summary>
		/// <param name="engine"></param>
		/// <returns></returns>
		public override FileInfo[] SelectFiles(PrevalenceEngine engine)
		{			
			return GetUnnecessaryPrevalenceFiles(engine);			
		}
コード例 #21
0
		/// <summary>
		/// Returns the last (most recent) snapshot file in the <see cref="PrevalenceEngine.PrevalenceBase"/>
		/// folder or null when no snapshot exists.
		/// </summary>
		/// <param name="engine">the prevalence engine</param>
		/// <returns></returns>
		public static FileInfo FindLastSnapshot(PrevalenceEngine engine)
		{
			FileInfo[] snapshots = GetSnapshotFiles(engine);
			if (snapshots.Length > 0)
			{
				return snapshots[snapshots.Length-1];
			}
			return null;
		}
コード例 #22
0
		/// <summary>
		/// Returns all snapshot files in the <see cref="PrevalenceEngine.PrevalenceBase"/>
		/// folder sorted by filename.
		/// </summary>
		/// <param name="engine">the prevalence engine</param>
		/// <returns></returns>
		public static FileInfo[] GetSnapshotFiles(PrevalenceEngine engine)
		{
			FileInfo[] files = engine.PrevalenceBase.GetFiles("*.snapshot");
			SortFilesByName(files);
			return files;
		}
コード例 #23
0
		private static PrevalenceEngine CreateRequestedEngine(System.Type systemType, string prevalenceBase, BinaryFormatter formatter, PrevalenceEngine.ExceptionDuringRecoveryHandler handler)
		{
			if (Attribute.IsDefined(systemType, typeof(Bamboo.Prevalence.Attributes.TransparentPrevalenceAttribute), false))
			{
				return new TransparentPrevalenceEngine(systemType, prevalenceBase, formatter, handler);
			}
			else
			{
				return new PrevalenceEngine(systemType, prevalenceBase, formatter, handler);
			}
		}
コード例 #24
0
		public RegistrationController( PrevalenceEngine engine )
		{
			_engine = engine;
		}
コード例 #25
0
		protected void Application_Start(object sender, EventArgs args)
		{			
			_engine = PrevalenceActivator.CreateTransparentEngine(typeof(UserLoginSystem), PrevalenceBase);
		}
コード例 #26
0
		/// <summary>
		/// Creates a new SnapshotTaker for the PrevalenceEngine engine
		/// with a period between snapshots equals to period but with no file
		/// cleanup policy (no files will be deleted from the prevalence base folder).
		/// </summary>
		/// <param name="engine">prevalence engine to take snapshots from</param>
		/// <param name="period">period between snapshots</param>
		public SnapshotTaker(PrevalenceEngine engine, TimeSpan period) : this(engine, period, NullCleanUpPolicy.Default)
		{			
		}
コード例 #27
0
		/// <summary>
		/// Creates a new prevalence engine for the prevalent system
		/// type specified by the systemType argument.
		/// </summary>
		/// <param name="systemType">prevalent system type, must be serializable</param>
		/// <param name="prevalenceBase">directory where to store log files</param>
		/// <param name="formatter">serialization formatter that should be used for reading from/writing to the logs</param>
		/// <param name="handler">delegate to receive notifications of any exceptions thrown during recovery</param>
		/// <returns>a new prevalence engine</returns>
		public static PrevalenceEngine CreateEngine(System.Type systemType, string prevalenceBase, BinaryFormatter formatter, PrevalenceEngine.ExceptionDuringRecoveryHandler handler)
		{
			CheckEngineParameters(systemType, prevalenceBase);
			Assertion.AssertParameterNotNull("formatter", formatter);

			return CreateRequestedEngine(systemType, prevalenceBase, formatter, handler);
		}
コード例 #28
0
 private void SetupEngine()
 {
     engine = PrevalenceActivator.CreateTransparentEngine(typeof (CacheSystem), dataDir);
     system = engine.PrevalentSystem as CacheSystem;
     taker = new SnapshotTaker(engine, TimeSpan.FromMinutes(5), CleanUpAllFilesPolicy.Default);
 }