protected override object Instantiate() { Type systemType = (Type) Model.ExtendedProperties[PrevalenceFacility.SystemTypePropertyKey]; String dir = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, (String) Model.ExtendedProperties[PrevalenceFacility.StorageDirPropertyKey]); bool autoVersionMigration = (bool) Model.ExtendedProperties[PrevalenceFacility.AutoMigrationPropertyKey]; bool resetStorage = (bool) Model.ExtendedProperties[PrevalenceFacility.ResetStoragePropertyKey]; float snapshotPeriod = (float)Model.ExtendedProperties[PrevalenceFacility.SnapshotPeriodPropertyKey]; if (resetStorage) { DeleteStorageDir(dir); } PrevalenceEngine engine = PrevalenceActivator.CreateEngine( systemType, dir, autoVersionMigration); if (snapshotPeriod > 0) { CreateSnapshotTaker(engine, snapshotPeriod); } return(engine); }
static void Main(string[] args) { string prevalenceBase = Path.Combine(Environment.CurrentDirectory, "data"); ClearPrevalenceBase(prevalenceBase); PrevalenceEngine engine = PrevalenceActivator.CreateEngine(typeof(Library), prevalenceBase); Library library = engine.PrevalentSystem as Library; Console.Write("Loading titles.xml... "); XmlDocument data = new XmlDocument(); data.Load("titles.xml"); Console.WriteLine("done!"); foreach (XmlElement title in data.SelectNodes("//title")) { library.AddTitle(new Title(title.GetAttribute("name"), title.GetAttribute("summary"))); } Console.Write("Taking snapshot... "); engine.TakeSnapshot(); Console.WriteLine("done!"); Console.WriteLine("Version 1.0 data successfully set up!"); }
public AttributeMapper(PrevalenceEngine Engine) { Mapping = new Dictionary <string, Tuple <FieldInfo, Dictionary <string, PropertyInfo> > >(); foreach (FieldInfo Field in Engine.PrevalentSystem.GetType().GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic)) { object[] TableAttributes = Field.GetCustomAttributes(typeof(SQLTableAttribute), false); if (TableAttributes.Length == 0) { continue; } string TableName = (TableAttributes[0] as SQLTableAttribute).TableName; if (!Field.FieldType.IsGenericType || Field.FieldType.GetGenericTypeDefinition() != typeof(List <>)) { throw new NotImplementedException("This version of the Bamboo ADO.NET provider only supports List<T> for SQL table associations"); } Type TargetType = Field.FieldType.GetGenericArguments()[0]; Dictionary <string, PropertyInfo> ColumnAssociations = new Dictionary <string, PropertyInfo>(); foreach (PropertyInfo InnerMember in TargetType.GetProperties(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic)) { object[] ColumnAttributes = InnerMember.GetCustomAttributes(typeof(SQLColumnAttribute), false); if (ColumnAttributes.Length == 0) { continue; } ColumnAssociations.Add((ColumnAttributes[0] as SQLColumnAttribute).ColumnName, InnerMember); } Mapping.Add(TableName, new Tuple <FieldInfo, Dictionary <string, PropertyInfo> >(Field, ColumnAssociations)); } }
static void Main(string[] args) { PrevalenceEngine engine = PrevalenceActivator.CreateTransparentEngine(typeof(ObjectModel.Company), Path.Combine(Path.GetTempPath(), "CompanySystem")); ObjectModel.Company company = engine.PrevalentSystem as ObjectModel.Company; // adding a new department is easy... ObjectModel.Department sales = new ObjectModel.Department("Sales"); company.AddDepartment(sales); // adding a user is easy too, you only have // to remember to put the right department // reference... ObjectModel.Employee employee = new ObjectModel.Employee("John Salesman"); employee.Department = new ObjectModel.Department(sales.ID); company.AddEmployee(employee); DisplayObjects(company); // updating an employee... ObjectModel.Employee updEmployee = new ObjectModel.Employee(employee.ID); updEmployee.Name = "Rodrigo B. de Oliveira"; company.UpdateEmployee(updEmployee); DisplayObjects(company); company.RemoveEmployee(employee.ID); DisplayObjects(company); }
public Application() { string prevalenceBase = Path.Combine(Environment.CurrentDirectory, "data"); _engine = PrevalenceActivator.CreateTransparentEngine(typeof(ToDoList), prevalenceBase); _system = _engine.PrevalentSystem as ToDoList; }
public ProjectController(PestControlModel model, PrevalenceEngine engine, SourceControlManager scm, BuildSystemManager bsm) { _engine = engine; _model = model; _scm = scm; _bsm = bsm; }
/// <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); }
public SnapshotTaker(PrevalenceEngine engine, double interval) { _engine = engine; _timer = new Timer(interval); _timer.AutoReset = true; _timer.Elapsed += new ElapsedEventHandler(Elapsed); _timer.Start(); }
protected void CrashRecover() { // The new engine automatically // recovers from crash by loading // its previous state HandsOffOutputLog(); _engine = CreateEngine(); }
protected void CrashRecover() { // The new engine automatically // recovers from crash by loading // its previous state HandsOffOutputLog(); _engine = CreateEngine(); }
/// <summary> /// To obtain the system instance, we obtain /// the engine id that holds this system and use the /// apropriate property /// </summary> /// <returns></returns> protected override object Instantiate() { String engineId = (String) Model.ExtendedProperties[PrevalenceFacility.EngineIdPropertyKey]; PrevalenceEngine engine = (PrevalenceEngine)Kernel[engineId]; return(engine.PrevalentSystem); }
/// <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); }
public static void Kernel_ComponentDestroyed(ComponentModel model, object instance) { if (instance is PrevalenceEngine) { PrevalenceEngine engine = (PrevalenceEngine)instance; engine.TakeSnapshot(); } }
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); }
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; }
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); }
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"]; }
protected void TakeSnapshotIfRequired(IConfiguration engineConfig) { float period = GetSnapshotInterval(engineConfig); if (RequiresSnapshots(period)) { PrevalenceEngine engine = (PrevalenceEngine)Kernel[engineConfig.Attributes[IdKey]]; engine.TakeSnapshot(); } }
/// <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); } }
void OnTimer(object state) { PrevalenceEngine engine = (PrevalenceEngine)state; try { engine.TakeSnapshot(); DeleteFiles(_cleanUpPolicy.SelectFiles(engine)); } catch (Exception /*ignored*/) { // a callback? } }
/// <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); }
/// <summary> /// Gets a configured engine. /// </summary> /// <param name="id">engine id</param> /// <exception cref="System.Configuration.ConfigurationException">in the case Bamboo.Prevalence /// was not correctly configured</exception> /// <exception cref="ArgumentException">if the engine was not found</exception> public PrevalenceEngine this[string id] { get { if (null == _engines) { throw new System.Configuration.ConfigurationException("Bamboo.Prevalence was not configured for this application!"); } PrevalenceEngine engine = (PrevalenceEngine)_engines[id]; if (null == engine) { throw new ArgumentException(string.Format("Engine {0} not found!", id), "id"); } return(engine); } }
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; }
static void Main(string[] args) { string prevalenceBase = Path.Combine(Environment.CurrentDirectory, "data"); PrevalenceEngine engine = PrevalenceActivator.CreateEngine(typeof(LibrarySystem), prevalenceBase); LibrarySystem library = engine.PrevalentSystem as LibrarySystem; IList titles = library.GetTitles(); XmlDocument data = new XmlDocument(); data.Load("titles.xml"); XmlNodeList expectedTitles = data.SelectNodes("//title"); AssertEquals("titles.Count", expectedTitles.Count, titles.Count); foreach (XmlElement expected in expectedTitles) { Title title = FindByName(titles, expected.GetAttribute("name") + "*"); AssertTitle(expected, title); } }
public static void Main(string[] args) { //ChannelServices.RegisterChannel(new TcpChannel(8080)); BinaryServerFormatterSinkProvider provider = new BinaryServerFormatterSinkProvider(); provider.TypeFilterLevel = TypeFilterLevel.Full; IDictionary props = new Hashtable(); props["port"] = 8080; ChannelServices.RegisterChannel(new TcpChannel(props, null, provider)); PrevalenceEngine engine = PrevalenceActivator.CreateTransparentEngine(typeof(AddressBook), Path.Combine(Environment.CurrentDirectory, "data")); AddressBook book = engine.PrevalentSystem as AddressBook; // Let's take a complete snapshot of the system // each 30 seconds... SnapshotTaker st = new SnapshotTaker(engine, 30000); ObjRef reference = RemotingServices.Marshal(book, "AddressBook", typeof(AddressBook)); Console.WriteLine("server running... press <ENTER> to finish"); Console.ReadLine(); RemotingServices.Unmarshal(reference); }
public PrevalentSubSystemProxy(PrevalenceEngine engine, MarshalByRefObject system, string fieldName) : base(engine, system) { _fieldName = fieldName; }
public RegistrationController(PrevalenceEngine engine) { _engine = engine; }
private void SetupEngine() { engine = PrevalenceActivator.CreateTransparentEngine(typeof(CacheSystem), dataDir); system = engine.PrevalentSystem as CacheSystem; taker = new SnapshotTaker(engine, TimeSpan.FromMinutes(5), CleanUpAllFilesPolicy.Default); }
/// <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);
public PrevalentSubSystemProxy(PrevalenceEngine engine, MarshalByRefObject system, string fieldName) : base(engine, system) { _fieldName = fieldName; }
/// <summary> /// Same as <see cref="PrevalenceBaseUtil.GetUnnecessaryPrevalenceFiles"/>. /// </summary> /// <param name="engine"></param> /// <returns></returns> public override FileInfo[] SelectFiles(PrevalenceEngine engine) { return(GetUnnecessaryPrevalenceFiles(engine)); }
public PrevalentSubSystemHolderProxy(PrevalenceEngine engine, MarshalByRefObject system) : base(engine, system) { }
protected void HandsOffFiles(IConfiguration engineConfig) { PrevalenceEngine engine = (PrevalenceEngine)Kernel[engineConfig.Attributes[IdKey]]; engine.HandsOffOutputLog(); }