/// <summary>
        /// Initializes an instance of <see cref="EnumerableWrapperProvider"/>.
        /// </summary>
        /// <param name="sourceEnumerableOfT">Type of the original <see cref="IEnumerable{T}" />
        /// that is being wrapped.</param>
        /// <param name="elementWrapperProvider">The <see cref="IWrapperProvider"/> for the element type.
        /// Can be null.</param>
        public EnumerableWrapperProvider(
            Type sourceEnumerableOfT,
            IWrapperProvider elementWrapperProvider)
        {
            if (sourceEnumerableOfT == null)
            {
                throw new ArgumentNullException(nameof(sourceEnumerableOfT));
            }

            var enumerableOfT = ClosedGenericMatcher.ExtractGenericInterface(
                sourceEnumerableOfT,
                typeof(IEnumerable <>));

            if (!sourceEnumerableOfT.IsInterface || enumerableOfT == null)
            {
                throw new ArgumentException(
                          Resources.FormatEnumerableWrapperProvider_InvalidSourceEnumerableOfT(typeof(IEnumerable <>).Name),
                          nameof(sourceEnumerableOfT));
            }

            _wrapperProvider = elementWrapperProvider;

            var declaredElementType = enumerableOfT.GenericTypeArguments[0];
            var wrappedElementType  = elementWrapperProvider?.WrappingType ?? declaredElementType;

            WrappingType = typeof(DelegatingEnumerable <,>).MakeGenericType(wrappedElementType, declaredElementType);

            _wrappingTypeConstructor = WrappingType.GetConstructor(new[]
            {
                sourceEnumerableOfT,
                typeof(IWrapperProvider)
            });
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Initializes an instance of <see cref="EnumerableWrapperProvider"/>.
        /// </summary>
        /// <param name="sourceEnumerableOfT">Type of the original <see cref="IEnumerable{T}" />
        /// that is being wrapped.</param>
        /// <param name="elementWrapperProvider">The <see cref="IWrapperProvider"/> for the element type.
        /// Can be null.</param>
        public EnumerableWrapperProvider(
            [NotNull] Type sourceEnumerableOfT,
            IWrapperProvider elementWrapperProvider)
        {
            var enumerableOfT = ClosedGenericMatcher.ExtractGenericInterface(
                sourceEnumerableOfT,
                typeof(IEnumerable<>));
            if (!sourceEnumerableOfT.GetTypeInfo().IsInterface || enumerableOfT == null)
            {
                throw new ArgumentException(
                    Resources.FormatEnumerableWrapperProvider_InvalidSourceEnumerableOfT(typeof(IEnumerable<>).Name),
                    nameof(sourceEnumerableOfT));
            }

            _wrapperProvider = elementWrapperProvider;

            var declaredElementType = enumerableOfT.GenericTypeArguments[0];
            var wrappedElementType = elementWrapperProvider?.WrappingType ?? declaredElementType;
            WrappingType = typeof(DelegatingEnumerable<,>).MakeGenericType(wrappedElementType, declaredElementType);

            _wrappingTypeConstructor = WrappingType.GetConstructor(new[]
            {
                sourceEnumerableOfT,
                typeof(IWrapperProvider)
            });
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Initializes an instance of <see cref="EnumerableWrapperProvider"/>.
        /// </summary>
        /// <param name="sourceEnumerableOfT">Type of the original <see cref="IEnumerable{T}" />
        /// that is being wrapped.</param>
        /// <param name="elementWrapperProvider">The <see cref="IWrapperProvider"/> for the element type.
        /// Can be null.</param>
        public EnumerableWrapperProvider(
            Type sourceEnumerableOfT,
            IWrapperProvider elementWrapperProvider)
        {
            if (sourceEnumerableOfT == null)
            {
                throw new ArgumentNullException(nameof(sourceEnumerableOfT));
            }

            var enumerableOfT = ClosedGenericMatcher.ExtractGenericInterface(
                sourceEnumerableOfT,
                typeof(IEnumerable <>));

            if (!sourceEnumerableOfT.GetTypeInfo().IsInterface || enumerableOfT == null)
            {
                throw new ArgumentException($"The type must be an interface and must be or derive from '{typeof(IEnumerable<>).Name}'.",
                                            nameof(sourceEnumerableOfT));
            }

            _wrapperProvider = elementWrapperProvider;

            var declaredElementType = enumerableOfT.GenericTypeArguments[0];
            var wrappedElementType  = elementWrapperProvider?.WrappingType ?? declaredElementType;

            WrappingType = typeof(DelegatingEnumerable <,>).MakeGenericType(wrappedElementType, declaredElementType);

            _wrappingTypeConstructor = WrappingType.GetConstructor(new[]
            {
                sourceEnumerableOfT,
                typeof(IWrapperProvider)
            });
        }
Ejemplo n.º 4
0
    /// <summary>
    /// Initializes a <see cref="DelegatingEnumerable{TWrapped, TDeclared}"/> with the original
    ///  <see cref="IEnumerable{T}"/> and the wrapper provider for wrapping individual elements.
    /// </summary>
    /// <param name="source">The <see cref="IEnumerable{T}"/> instance to get the enumerator from.</param>
    /// <param name="elementWrapperProvider">The wrapper provider for wrapping individual elements.</param>
    public DelegatingEnumerable(IEnumerable <TDeclared> source, IWrapperProvider elementWrapperProvider)
    {
        if (source == null)
        {
            throw new ArgumentNullException(nameof(source));
        }

        _source          = source;
        _wrapperProvider = elementWrapperProvider;
    }
Ejemplo n.º 5
0
        /// <summary>
        /// Initializes a <see cref="DelegatingEnumerable{TWrapped, TDeclared}"/> which enumerates
        /// over the elements of the original enumerator and wraps them using the supplied
        /// <see cref="IWrapperProvider"/>.
        /// </summary>
        /// <param name="inner">The original enumerator.</param>
        /// <param name="wrapperProvider">The wrapper provider to wrap individual elements.</param>
        public DelegatingEnumerator(IEnumerator <TDeclared> inner, IWrapperProvider wrapperProvider)
        {
            if (inner == null)
            {
                throw new ArgumentNullException(nameof(inner));
            }

            _inner           = inner;
            _wrapperProvider = wrapperProvider;
        }
        public void SaveDatabase <T>(string path, T tracker)
        {
            IWrapperProvider wrapperProvider = trackerfactory.GetWrapperProvider();

            //check if path exist
            if (!Directory.Exists(Path.GetDirectoryName(path)))
            {
                Directory.CreateDirectory(Path.GetDirectoryName(path));
            }
            //make backup
            if (File.Exists(path))
            {
                BackupDatabase(wrapperProvider, path);
            }
            //standard serialization
            using (TextWriter writer = new StreamWriter(path))
            {
                var xml = new XmlSerializer(typeof(T));
                xml.Serialize(writer, tracker);
            }
        }
Ejemplo n.º 7
0
        public static dynamic GetAutoQuery <TEntity>(string queryString, Type entityType, IQueryable <TEntity> query, AutoQueryableProfile profile) where TEntity : class
        {
            // If query string empty select default entity properties.
            if (string.IsNullOrEmpty(queryString))
            {
                IColumnProvider            columnProvider = ProviderFactory.GetColumnProvider();
                IEnumerable <SelectColumn> selectColumns  = EntityColumnHelper.GetSelectableColumns(profile, entityType);
                if (profile.UseBaseType)
                {
                    return(query.Select(SelectHelper.GetSelector <TEntity, TEntity>(selectColumns, profile)));
                }
                return(query.Select(SelectHelper.GetSelector <TEntity, object>(selectColumns, profile)));
            }

            // Get criteria & clauses from choosen provider (AQ, OData, ...)
            string[]          queryStringParts = queryString.GetParts();
            ICriteriaProvider criteriaProvider = ProviderFactory.GetCriteriaProvider(profile?.ProviderType);
            IList <Criteria>  criterias        = profile.IsClauseAllowed(ClauseType.Filter) ? criteriaProvider.GetCriterias(entityType, queryStringParts, profile).ToList() : null;
            IClauseProvider   clauseProvider   = ProviderFactory.GetClauseProvider(profile?.ProviderType);
            Clauses           clauses          = clauseProvider.GetClauses(queryStringParts, profile);

            var countAllRows = false;
            IEnumerable <WrapperPartType> wrapperParts = null;

            if (clauses.WrapWith != null)
            {
                IWrapperProvider wrapperProvider = ProviderFactory.GetWrapperProvider();
                wrapperParts = wrapperProvider.GetWrapperParts(clauses.WrapWith.Value.Split(','), profile).ToList();
                countAllRows = wrapperParts.Contains(WrapperPartType.TotalCount);
            }

            QueryResult queryResult = QueryBuilder.Build(query, entityType, clauses, criterias, profile, countAllRows);

            if (clauses.WrapWith == null || !wrapperParts.Any())
            {
                return(queryResult.Result);
            }

            return(DefaultWrapperProvider.GetWrappedResult(wrapperParts, queryResult, clauses, queryString));
        }
        public void BackupDatabase(IWrapperProvider wrapperProvider, string path)
        {
            IPathWrapper      pathWrapper      = wrapperProvider.GetWrapper <IPathWrapper>();
            IDirectoryWrapper directoryWrapper = wrapperProvider.GetWrapper <IDirectoryWrapper>();
            IFileWrapper      fileWrapper      = wrapperProvider.GetWrapper <IFileWrapper>();
            //copy data.xml to data.xml.bak
            //copy data.xml to data_date.bak - it will override last dayily backup. first run of day will create new one
            string backupFileName = pathWrapper.GetFileNameWithoutExtension(path) + DateTime.Now.ToString("yyyyMMdd");
            string backupPath     = pathWrapper.Combine(
                pathWrapper.GetDirectoryName(path),
                backupFileName);

            backupPath = pathWrapper.ChangeExtension(backupPath, pathWrapper.GetExtension(path));

            bool backupExists = File.Exists(backupPath);

            File.Copy(path, backupPath, true);

            if (!backupExists)
            {
                ManageBackups(path, pathWrapper, directoryWrapper, fileWrapper);
            }
        }
Ejemplo n.º 9
0
 /// <summary>
 /// Initializes a <see cref="DelegatingEnumerable{TWrapped, TDeclared}"/> which enumerates
 /// over the elements of the original enumerator and wraps them using the supplied
 /// <see cref="IWrapperProvider"/>.
 /// </summary>
 /// <param name="inner">The original enumerator.</param>
 /// <param name="wrapperProvider">The wrapper provider to wrap individual elements.</param>
 public DelegatingEnumerator([NotNull] IEnumerator <TDeclared> inner, IWrapperProvider wrapperProvider)
 {
     _inner           = inner;
     _wrapperProvider = wrapperProvider;
 }
Ejemplo n.º 10
0
 /// <summary>
 /// Initializes a <see cref="DelegatingEnumerable{TWrapped, TDeclared}"/> with the original
 ///  <see cref="IEnumerable{T}"/> and the wrapper provider for wrapping individual elements.
 /// </summary>
 /// <param name="source">The <see cref="IEnumerable{T}"/> instance to get the enumerator from.</param>
 /// <param name="elementWrapperProvider">The wrapper provider for wrapping individual elements.</param>
 public DelegatingEnumerable([NotNull] IEnumerable <TDeclared> source, IWrapperProvider elementWrapperProvider)
 {
     _source          = source;
     _wrapperProvider = elementWrapperProvider;
 }