Exemple #1
0
        public void GenerateColumns()
        {
            var errorSuffix = "columns in table " + this.Name.Name;
            var columns     = new Dictionary <string, IColumn>();

            void AddColumns(IEnumerable <IColumn> newColumns)
            {
                try
                {
                    columns.AddRange(newColumns, c => c.Name, c => c, errorSuffix);
                }catch (RepeatedElementsException ex) when(StartParameters.IgnoredCodeErrors != null)
                {
                    StartParameters.IgnoredCodeErrors.Add(ex);
                }
            }

            AddColumns(Fields.Values.SelectMany(c => c.Field.Columns()));

            if (Mixins != null)
            {
                AddColumns(Mixins.Values.SelectMany(m => m.Fields.Values).SelectMany(f => f.Field.Columns()));
            }

            if (this.SystemVersioned != null)
            {
                AddColumns(this.SystemVersioned.Columns());
            }

            Columns = columns;
            inserterDisableIdentity = new ResetLazy <InsertCacheDisableIdentity>(() => InsertCacheDisableIdentity.InitializeInsertDisableIdentity(this));
            inserterIdentity        = new ResetLazy <InsertCacheIdentity>(() => InsertCacheIdentity.InitializeInsertIdentity(this));
            updater         = new ResetLazy <UpdateCache>(() => UpdateCache.InitializeUpdate(this));
            saveCollections = new ResetLazy <CollectionsCache?>(() => CollectionsCache.InitializeCollections(this));
        }
		public void Dispose(Guid collectionID)
		{
			var enumerator = CollectionsCache.GetCollection(collectionID) as IDisposable;
			if (enumerator != null)
				enumerator.Dispose();

			CollectionsCache.DeleteCollection(collectionID);
		}
        private void ParseCollectionsCache(XPathNavigator navigator)
        {
            XPathNodeIterator xpni = navigator.Select(CfgXmlHelper.SessionFactoryCollectionsCacheExpression);

            while (xpni.MoveNext())
            {
                CollectionsCache.Add(new CollectionCacheConfiguration(xpni.Current));
            }
        }
        private Object ReplaceCollections(MemberInfo memberInfo, String peer, Object obj)
        {
            if (obj == null)
            {
                return(obj);
            }

            var type = obj.GetType();

            if (ReflectionUtil.IsBaseType(type))
            {
                return(obj);
            }

            var lazyAttr = Attribute.GetCustomAttribute(memberInfo, typeof(RpcLazyEnumerationAttribute)) as RpcLazyEnumerationAttribute;

            if (lazyAttr == null)
            {
                return(obj);
            }

            if (type == typeof(IEnumerable) || (type.IsGenericType && type.GetGenericTypeDefinition() == typeof(IEnumerable <>)))
            {
                var enumerable = (IEnumerable)obj;
                obj = enumerable.GetEnumerator();

                var lazyCollType = typeof(LazyRpcCollection <>);
                if (type.IsGenericType)
                {
                    var genericType = type.GetGenericArguments()[0];
                    lazyCollType = lazyCollType.MakeGenericType(genericType);
                }

                var collectionID = CollectionsCache.InsertCollection((IEnumerator)obj);

                var lazyCollection = Activator.CreateInstance(lazyCollType, peer, collectionID, lazyAttr.FullLoad);
                return(lazyCollection);
            }

            var properties = type.GetProperties();

            foreach (var propertyInfo in properties)
            {
                if (Attribute.IsDefined(propertyInfo, typeof(RpcLazyEnumerationAttribute)))
                {
                    var propertyValue = propertyInfo.GetValue(obj, null);
                    propertyValue = ReplaceCollections(propertyInfo, peer, propertyValue);

                    propertyInfo.SetValue(obj, propertyValue, null);
                }
            }

            return(obj);
        }
		public List<Object> LoadWhole(Guid collectionID)
		{
			var list = new List<Object>();
			
			var enumerator = CollectionsCache.GetCollection(collectionID);
			while (enumerator.MoveNext())
				list.Add(enumerator.Current);

			CollectionsCache.DeleteCollection(collectionID);

			return list;
		}
		public CollectionItemEntity Next(Guid collectionID)
		{
			var enumerator = CollectionsCache.GetCollection(collectionID);

			var entity = new CollectionItemEntity
			{
				Success = enumerator.MoveNext(),
				Item = enumerator.Current,
			};

			return entity;
		}
        public void GenerateColumns()
        {
            var errorSuffix = "columns in table " + this.Name.Name;

            var columns = Fields.Values.SelectMany(c => c.Field.Columns()).ToDictionaryEx(c => c.Name, errorSuffix);

            if (Mixins != null)
            {
                columns.AddRange(Mixins.Values.SelectMany(m => m.Fields.Values).SelectMany(f => f.Field.Columns()).ToDictionaryEx(c => c.Name, errorSuffix), errorSuffix);
            }

            Columns = columns;

            inserterDisableIdentity = new ResetLazy <InsertCacheDisableIdentity>(() => InsertCacheDisableIdentity.InitializeInsertDisableIdentity(this));
            inserterIdentity        = new ResetLazy <InsertCacheIdentity>(() => InsertCacheIdentity.InitializeInsertIdentity(this));
            updater         = new ResetLazy <UpdateCache>(() => UpdateCache.InitializeUpdate(this));
            saveCollections = new ResetLazy <CollectionsCache>(() => CollectionsCache.InitializeCollections(this));
        }
		public void Reset(Guid collectionID)
		{
			var enumerator = CollectionsCache.GetCollection(collectionID);
			enumerator.Reset();
		}