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);
        }
Exemplo n.º 2
0
        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));
            }
        }
Exemplo n.º 4
0
        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);
        }
Exemplo n.º 5
0
        public Application()
        {
            string prevalenceBase = Path.Combine(Environment.CurrentDirectory, "data");

            _engine = PrevalenceActivator.CreateTransparentEngine(typeof(ToDoList), prevalenceBase);
            _system = _engine.PrevalentSystem as ToDoList;
        }
Exemplo n.º 6
0
 public ProjectController(PestControlModel model,
                          PrevalenceEngine engine, SourceControlManager scm, BuildSystemManager bsm)
 {
     _engine = engine;
     _model  = model;
     _scm    = scm;
     _bsm    = bsm;
 }
Exemplo n.º 7
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);
        }
Exemplo n.º 8
0
 public SnapshotTaker(PrevalenceEngine engine, double interval)
 {
     _engine          = engine;
     _timer           = new Timer(interval);
     _timer.AutoReset = true;
     _timer.Elapsed  += new ElapsedEventHandler(Elapsed);
     _timer.Start();
 }
Exemplo n.º 9
0
 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();
		}
Exemplo n.º 11
0
        /// <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);
        }
Exemplo n.º 12
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);
 }
        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;
        }
Exemplo n.º 16
0
        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);
        }
Exemplo n.º 17
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"];
        }
Exemplo n.º 18
0
        protected void TakeSnapshotIfRequired(IConfiguration engineConfig)
        {
            float period = GetSnapshotInterval(engineConfig);

            if (RequiresSnapshots(period))
            {
                PrevalenceEngine engine = (PrevalenceEngine)Kernel[engineConfig.Attributes[IdKey]];

                engine.TakeSnapshot();
            }
        }
Exemplo n.º 19
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);
            }
        }
Exemplo n.º 20
0
        void OnTimer(object state)
        {
            PrevalenceEngine engine = (PrevalenceEngine)state;

            try
            {
                engine.TakeSnapshot();
                DeleteFiles(_cleanUpPolicy.SelectFiles(engine));
            }
            catch (Exception /*ignored*/)
            {
                // a callback?
            }
        }
Exemplo n.º 21
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);
        }
Exemplo n.º 22
0
        /// <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);
            }
        }
Exemplo n.º 23
0
        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;
        }
Exemplo n.º 24
0
        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);
            }
        }
Exemplo n.º 25
0
        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;
 }
Exemplo n.º 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);
 }
 /// <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);
Exemplo n.º 30
0
 public PrevalentSubSystemProxy(PrevalenceEngine engine, MarshalByRefObject system, string fieldName) : base(engine, system)
 {
     _fieldName = fieldName;
 }
Exemplo n.º 31
0
 /// <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)
		{
		}
Exemplo n.º 33
0
        protected void HandsOffFiles(IConfiguration engineConfig)
        {
            PrevalenceEngine engine = (PrevalenceEngine)Kernel[engineConfig.Attributes[IdKey]];

            engine.HandsOffOutputLog();
        }