public UnitOfWork(IStoreStrategy store)
 {
     context = new Context(store);
 }
        public CacheStorageStrategy(IStoreStrategy baseStore)
        {
            this.baseStore = baseStore;

        }
Beispiel #3
0
 public CacheStorageStrategy(IStoreStrategy baseStore)
 {
     this.baseStore = baseStore;
 }
 public FakeResourcePool(Func<IResourcePool, IResource> factory, IStoreStrategy storeStrategy)
 {
     _storeStrategy = storeStrategy;
     _factory = factory;
 }
 public Context(IStoreStrategy store):
     base("name=ContentItemContext",store)
 {
 }
        private void Init()
        {
            if (this.store == null)
            {
                this.store = new DefaultStoreStrategy();
            }

            //Assembly asm= Assembly.GetExecutingAssembly();
            var props = this.GetType().GetProperties();

            foreach (var prop in props)
            {
                var propType = prop.PropertyType;
                if (propType.GenericTypeArguments.Length == 0)
                {
                    continue;
                }
                var attribute = prop.GetCustomAttribute <FileSetUsePrefixPathAttribute>(true);
                var gen_type  = propType.GenericTypeArguments[0];
                var ret_type  = gen_type.GetType();
                if (ret_type.IsInstanceOfType(typeof(IFileSet)))
                {
                    bool isInit = false;
                    //load
                    var    prefix   = attribute == null ? null : this.PrefixPath;
                    string filename = store.GetFileName(gen_type, prefix);

                    if (File.Exists(filename))
                    {
                        //string contents = File.ReadAllText(filename);
                        string contents = store.PreLoad(gen_type, prefix);
                        //object o = XmlHelper.DeserializeObject(contents, prop.PropertyType);
                        object o = store.Load(contents, prop.PropertyType);
                        if (o != null)
                        {
                            prop.SetValue(this, o);
                            isInit = true;
                        }
                        //XmlHelper.SerializeObject(o, prop.PropertyType);
                    }
                    else if (string.IsNullOrEmpty(filename))
                    {
                        object o = store.Load(string.Empty, prop.PropertyType);
                        if (o != null)
                        {
                            var list = o as IEnumerable;
                            if (list != null)
                            {
                                var gtype    = prop.PropertyType.GenericTypeArguments.FirstOrDefault();
                                var instance = Activator.CreateInstance(prop.PropertyType);
                                foreach (var item in list)
                                {
                                    var method = item
                                                 .GetType()
                                                 .GetMethod("MakeDirty");

                                    if (method != null)
                                    {
                                        method.Invoke(item, new object[] { false });
                                    }

                                    prop.PropertyType
                                    .GetMethod("Add")
                                    .Invoke(instance, new object[] { item });
                                }
                                prop.SetValue(this, instance);
                                isInit = true;
                            }
                            o = null;
                        }
                        if (o != null)
                        {
                            prop.SetValue(this, o);
                            isInit = true;
                        }
                    }

                    if (!isInit)
                    {
                        //if empty = initial
                        var instance = Activator.CreateInstance(prop.PropertyType);
                        prop.SetValue(this, instance);
                    }
                }
                //Name: prop.Name
            }
        }
 public ConnectionPool(Func<IResourcePool, IResource> factory, IStoreStrategy storeStrategy)
 {
     _storeStrategy = storeStrategy;
     _factory = factory;
 }
 public FileContext(IStoreStrategy store)
 {
     this.store = store;
     Init();
 }
 public FileContext(string connectionname, IStoreStrategy store)
 {
     this.store = store;
     Init();
 }
Beispiel #10
0
 public Context(IStoreStrategy store) :
     base("name=ContentItemContext", store)
 {
     this.baseStore = store;
 }
 public void SetUp()
 {
     _store = new QueueStore();
 }
 public UnitOfWork(IStoreStrategy store)
 {
     context = new Context(store);
 }