Esempio n. 1
0
        public AuthorityUtility(ILogManagerFactory loggerFactory, IConfigurationManagerFactory configFactory)
        {
            logger = loggerFactory.CreateManager <AuthorityUtility>();
            config = configFactory.CreateManager("Authority");

            administrator = config.Get("AdministratorAuthority", administrator);
            initial       = config.Get("InitialAuthorityValue", initial);
        }
Esempio n. 2
0
        public EncryptUtility(ILogManagerFactory loggerFactory, IConfigurationManagerFactory configFactory)
        {
            logger = loggerFactory.CreateManager <EncryptUtility>();
            config = configFactory.CreateManager("PBKDF2Encrypt");

            saltSize   = config.Get("SaltSize", saltSize);
            type       = config.Get("PRF", type);
            iteration  = config.Get("IterationTimes", iteration);
            resultSize = config.Get("SizeRequested", resultSize);
        }
        /// <param name="fileName">Full path to the Excel spreadsheet</param>
        /// <param name="logManagerFactory">
        /// Factory that facilitates the creation of an external log manager (i.e. log4net) to
        /// allow internal methods of LinqToExcel to perform diagnostic logging.
        /// </param>
        public ExcelQueryFactory(string fileName, ILogManagerFactory logManagerFactory)
        {
            FileName = fileName;

            if (logManagerFactory != null)
            {
                _logManagerFactory = logManagerFactory;
                _log = _logManagerFactory.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
            }
        }
Esempio n. 4
0
        public CreditUtility(ILogManagerFactory loggerFactory, IConfigurationManagerFactory configFactory)
        {
            logger = loggerFactory.CreateManager <CreditUtility>();
            config = configFactory.CreateManager("Credit");

            accredit         = config.Get("AccreditRule", accredit);
            creditPunishment = config.Get("CreditReduceRule", creditPunishment);
            creditReward     = config.Get("CreditIncreaseRule", creditReward);
            changeMinLimit   = config.Get("ChangeCreditOnlyWhenBorrowTimeOver", changeMinLimit);
            initial          = config.Get("InitialCreditValue", initial);
        }
Esempio n. 5
0
        /// <param name="fileName">Full path to the Excel spreadsheet</param>
        /// <param name="logManagerFactory">
        /// Factory that facilitates the creation of an external log manager (i.e. log4net) to
        /// allow internal methods of LinqToExcel to perform diagnostic logging.
        /// </param>
        public ExcelQueryFactory(string fileName, ILogManagerFactory logManagerFactory)
        {
            FileName       = fileName;
            DatabaseEngine = ExcelUtilities.DefaultDatabaseEngine();

            if (logManagerFactory != null)
            {
                _logManagerFactory = logManagerFactory;
                _log = _logManagerFactory.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
            }
        }
Esempio n. 6
0
 // This constructor is called by users, create a new IQueryExecutor.
 internal ExcelQueryable(ExcelQueryArgs args, ILogManagerFactory logManagerFactory)
     : base(CreateExecutor(args, logManagerFactory))
 {
     foreach (var property in typeof(T).GetProperties())
     {
         ExcelColumnAttribute att = (ExcelColumnAttribute)Attribute.GetCustomAttribute(property, typeof(ExcelColumnAttribute));
         if (att != null && !args.ColumnMappings.ContainsKey(property.Name))
         {
             args.ColumnMappings.Add(property.Name, att.ColumnName);
         }
     }
 }
Esempio n. 7
0
 /// <summary>
 /// Enables Linq queries against an Excel worksheet
 /// </summary>
 /// <param name="worksheetIndex">Worksheet index ordered by name, not position in the workbook</param>
 /// <param name="fileName">Full path to the Excel spreadsheet</param>
 public static ExcelQueryable <Row> Worksheet(int worksheetIndex, string fileName,
                                              ILogManagerFactory logManagerFactory)
 {
     return(new ExcelQueryable <Row>(
                new ExcelQueryArgs(
                    new ExcelQueryConstructorArgs {
         FileName = fileName
     })
     {
         WorksheetIndex = worksheetIndex
     }));
 }
Esempio n. 8
0
 /// <summary>
 /// Enables Linq queries against an Excel worksheet
 /// </summary>
 /// <typeparam name="TSheetData">Class type to return row data as</typeparam>
 /// <param name="worksheetName">Name of the worksheet</param>
 /// <param name="fileName">Full path to the Excel spreadsheet</param>
 public static ExcelQueryable <TSheetData> Worksheet <TSheetData>(string worksheetName, string fileName,
                                                                  ILogManagerFactory logManagerFactory)
 {
     return(new ExcelQueryable <TSheetData>(
                new ExcelQueryArgs(
                    new ExcelQueryConstructorArgs {
         FileName = fileName
     })
     {
         WorksheetName = worksheetName
     }));
 }
Esempio n. 9
0
 /// <summary>
 /// Enables Linq queries against an Excel worksheet
 /// </summary>
 /// <typeparam name="TSheetData">Class type to return row data as</typeparam>
 /// <param name="worksheetIndex">Worksheet index ordered by name, not position in the workbook</param>
 /// <param name="fileName">Full path to the Excel spreadsheet</param>
 public static ExcelQueryable <TSheetData> Worksheet <TSheetData>(int worksheetIndex, string fileName,
                                                                  ILogManagerFactory logManagerFactory)
 {
     return(new ExcelQueryable <TSheetData>(
                new ExcelQueryArgs(
                    new ExcelQueryConstructorArgs()
     {
         FileName = fileName
     })
     {
         WorksheetIndex = worksheetIndex
     }, logManagerFactory));
 }
Esempio n. 10
0
 /// <summary>
 /// Enables Linq queries against an Excel worksheet
 /// </summary>
 /// <param name="worksheetName">Name of the worksheet</param>
 /// <param name="fileName">Full path to the Excel spreadsheet</param>
 public static ExcelQueryable <Row> Worksheet(string worksheetName, string fileName,
                                              ILogManagerFactory logManagerFactory)
 {
     return(new ExcelQueryable <Row>(
                new ExcelQueryArgs(
                    new ExcelQueryConstructorArgs()
     {
         FileName = fileName
     })
     {
         WorksheetName = worksheetName
     }, logManagerFactory));
 }
Esempio n. 11
0
 /// <summary>
 /// Enables Linq queries against an Excel worksheet
 /// </summary>
 /// <typeparam name="TSheetData">Class type to return row data as</typeparam>
 /// <param name="worksheetIndex">Worksheet index ordered by name, not position in the workbook</param>
 /// <param name="fileName">Full path to the Excel spreadsheet</param>
 /// <param name="columnMappings">Column to property mappings</param>
 public static ExcelQueryable <TSheetData> Worksheet <TSheetData>(int worksheetIndex, string fileName,
                                                                  Dictionary <string, string> columnMappings,
                                                                  ILogManagerFactory logManagerFactory)
 {
     return(new ExcelQueryable <TSheetData>(
                new ExcelQueryArgs(
                    new ExcelQueryConstructorArgs {
         FileName = fileName, ColumnMappings = columnMappings
     })
     {
         WorksheetIndex = worksheetIndex
     }));
 }
Esempio n. 12
0
 /// <summary>
 /// Enables Linq queries against an Excel worksheet
 /// </summary>
 /// <param name="worksheetName">Name of the worksheet</param>
 /// <param name="fileName">Full path to the Excel spreadsheet</param>
 /// <param name="columnMappings">Column to property mappings</param>
 public static ExcelQueryable <Row> Worksheet(string worksheetName, string fileName,
                                              Dictionary <string, string> columnMappings,
                                              ILogManagerFactory logManagerFactory)
 {
     return(new ExcelQueryable <Row>(
                new ExcelQueryArgs(
                    new ExcelQueryConstructorArgs {
         FileName = fileName, ColumnMappings = columnMappings
     })
     {
         WorksheetName = worksheetName
     }));
 }
        // This constructor is called by users, create a new IQueryExecutor.
        internal ExcelQueryable(ExcelQueryArgs args, ILogManagerFactory logManagerFactory)
            : base(QueryParser.CreateDefault(), CreateExecutor(args, logManagerFactory))
        {
            foreach (var property in typeof(T).GetProperties())
            {
                ExcelColumnAttribute att = (ExcelColumnAttribute)Attribute.GetCustomAttribute(property, typeof(ExcelColumnAttribute));
                if (att != null && !args.ColumnMappings.ContainsKey(property.Name))
                {
                    var columnNames = ExcelUtilities.GetColumnNames(args);

                    args.ColumnMappings.Add(property.Name, !att.IsForced ?
                                            att.ColumnName :
                                            columnNames.ToList().Find(x => att.HasSimilarColumn(x)) ?? att.ColumnName);
                }
            }
        }
Esempio n. 14
0
        public HTTPISBNInfoService(ILogManagerFactory loggerFactory, IConfigurationManagerFactory configFactory)
        {
            client = new HttpClient();
            logger = loggerFactory.CreateManager <HTTPISBNInfoService>();
            config = configFactory.CreateManager("ISBNAPI");

            url      = config.Get("", url);
            interval = config.Get("", interval);
            IConfigurationManager jsonPathConfig = config.CreateSubManager("JsonPath");

            isbnJsonPath            = jsonPathConfig.Get("ISBN", isbnJsonPath);
            titleJsonPath           = jsonPathConfig.Get("Title", titleJsonPath);
            authorJsonPath          = jsonPathConfig.Get("Author", authorJsonPath);
            publishingHouseJsonPath = jsonPathConfig.Get("PublishingHouse", publishingHouseJsonPath);
            labelsJsonPath          = jsonPathConfig.Get("Labels", labelsJsonPath);
            coverUrlJsonPath        = jsonPathConfig.Get("CoverUrl", coverUrlJsonPath);
            abstractJsonPath        = jsonPathConfig.Get("Abstract", abstractJsonPath);
        }
Esempio n. 15
0
        internal ExcelQueryExecutor(ExcelQueryArgs args, ILogManagerFactory logManagerFactory)
        {
            ValidateArgs(args);
            _args = args;

            if (logManagerFactory != null)
            {
                _logManagerFactory = logManagerFactory;
                _log = _logManagerFactory.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
            }

            if (_log != null && _log.IsDebugEnabled == true)
            {
                _log.DebugFormat("Connection String: {0}", ExcelUtilities.GetConnection(args).ConnectionString);
            }

            GetWorksheetName();
        }
Esempio n. 16
0
 public BorrowService(ICreditUtility credit, IDatabaseModelManager database, ILogManagerFactory loggerFactory)
 {
     this.credit   = credit;
     this.database = database;
     logger        = loggerFactory.CreateManager <BorrowService>();
 }
Esempio n. 17
0
 /// <param name="logManagerFactory">
 /// Factory that facilitates the creation of an external log manager (i.e. log4net) to
 /// allow internal methods of LinqToExcel to perform diagnostic logging.
 /// </param>
 public ExcelQueryFactory(ILogManagerFactory logManagerFactory)
     : this(null, logManagerFactory)
 {
 }
Esempio n. 18
0
 public ExcelFactory(string fileName, ILogManagerFactory logManagerFactory) : base(fileName, logManagerFactory)
 {
 }
Esempio n. 19
0
 public BookService(IDatabaseModelManager database, ILogManagerFactory loggerFactory)
 {
     this.database = database;
     logger        = loggerFactory.CreateManager <BookService>();
 }
Esempio n. 20
0
 private static IQueryExecutor CreateExecutor(ExcelQueryArgs args, ILogManagerFactory logManagerFactory)
 {
     return(new ExcelQueryExecutor(args, logManagerFactory));
 }
Esempio n. 21
0
 public CachedHTTPISBNInfoService(ILogManagerFactory loggerFactory, IDatabaseModelManager database, HTTPISBNInfoService httpISBNInfo)
 {
     logger            = loggerFactory.CreateManager <CachedHTTPISBNInfoService>();
     this.database     = database;
     this.httpISBNInfo = httpISBNInfo;
 }
Esempio n. 22
0
 public UserService(ICreditUtility credit, IEncryptUtility encrypt, IAuthorityUtility authority, IDatabaseModelManager database, ILogManagerFactory loggerFactory)
 {
     this.credit    = credit;
     this.encrypt   = encrypt;
     this.authority = authority;
     this.database  = database;
     logger         = loggerFactory.CreateManager <UserService>();
 }
Esempio n. 23
0
        public UserInfoViewModel(IUserService userService, ICreditUtility creditUtility, IAuthorityUtility authorityUtility, ILogManagerFactory loggerFactory)
        {
            this.userService      = userService;
            this.creditUtility    = creditUtility;
            this.authorityUtility = authorityUtility;
            logger = loggerFactory.CreateManager <UserInfoViewModel>();

            LoggedOut = new Interaction <Unit, Unit>();
            Activator = new ViewModelActivator();
            this.WhenActivated(disposableRegistration =>
            {
                userName = this.WhenAnyValue <UserInfoViewModel, string, User>(vm => vm.ParentViewModel.Account, account => account == null ? "游小客" : account.UserName)
                           .ToProperty(this, vm => vm.UserName)
                           .DisposeWith(disposableRegistration);
                name = this.WhenAnyValue <UserInfoViewModel, string, User>(vm => vm.ParentViewModel.Account, account => account == null ? "游客" : account.Name)
                       .ToProperty(this, vm => vm.Name)
                       .DisposeWith(disposableRegistration);
                nationalIdentificationNumber = this.WhenAnyValue <UserInfoViewModel, string, User>(vm => vm.ParentViewModel.Account, account => account == null ? "---" : account.NationalIdentificationNumber)
                                               .ToProperty(this, vm => vm.NationalIdentificationNumber)
                                               .DisposeWith(disposableRegistration);
                creditValue = this.WhenAnyValue <UserInfoViewModel, int, User>(vm => vm.ParentViewModel.Account, account => account == null ? -1 : account.CreditValue)
                              .ToProperty(this, vm => vm.CreditValue)
                              .DisposeWith(disposableRegistration);
                accreditedDays = this.WhenAnyValue(vm => vm.ParentViewModel.Account, account => this.creditUtility.GetAccreditedDays(account))
                                 .ToProperty(this, vm => vm.AccreditedDays)
                                 .DisposeWith(disposableRegistration);
                authorityLevel = this.WhenAnyValue(vm => vm.ParentViewModel.Account, account => this.authorityUtility.GetLevel(account))
                                 .Select(al =>
                {
                    return(al switch
                    {
                        Utilities.AuthorityLevel.Visitor => "游客",
                        Utilities.AuthorityLevel.Member => "会员",
                        Utilities.AuthorityLevel.Administrator => "管理员",
                        _ => "外星人",
                    });
                })
                                 .ToProperty(this, vm => vm.AuthorityLevel)
                                 .DisposeWith(disposableRegistration);
                RefreshCommand = ReactiveCommand.CreateFromTask(RefreshAsync, outputScheduler: RxApp.MainThreadScheduler)
                                 .DisposeWith(disposableRegistration);
                RefreshCommand.BindTo(ParentViewModel, pvm => pvm.Account);
                RefreshCommand.ThrownExceptions.Subscribe(ex => logger.Error(ex, "查询账户信息时出错"));
                LogoutCommand = ReactiveCommand.Create <User>(() => null)
                                .DisposeWith(disposableRegistration);
                LogoutCommand.Subscribe(u =>
                {
                    ParentViewModel.Account = u;
                    LoggedOut.Handle(Unit.Default).Subscribe();
                });
                LogoutCommand.ThrownExceptions.Subscribe(ex => logger.Error(ex, "退出账户时出错"));
            });
        public FreeSQLDatabaseModelManager(ILogManagerFactory loggerFactory, IConfigurationManagerFactory configFactory)
        {
            logger = loggerFactory.CreateManager <FreeSQLDatabaseModelManager>();
            config = configFactory.CreateManager("Database");

            type = config.Get("Type", type);
            autoSyncStructure = config.Get("AutoSyncStructure", autoSyncStructure);
            parameterized     = config.Get("ParameterizedQuery", parameterized);
            sqlToVerbose      = config.Get("OutPutSqlToVerbose", sqlToVerbose);
            warnOnOverTime    = config.Get("WarnOnOverTime", sqlToVerbose);
            overTime          = config.Get("OverTimeMilliseconds", overTime);
            switch (type)
            {
            case DataType.MySql:
                IConfigurationManager mySqlConfig = config.CreateSubManager("MySql");
                mySqlDataSource     = mySqlConfig.Get("DataSource", mySqlDataSource);
                mySqlPort           = mySqlConfig.Get("Port", mySqlPort);
                mySqlUserId         = mySqlConfig.Get("UserId", mySqlUserId);
                mySqlPassword       = mySqlConfig.Get("Password", mySqlPassword);
                mySqlInitialCatlog  = mySqlConfig.Get("InitialCatlog", mySqlInitialCatlog);
                mySqlCharset        = mySqlConfig.Get("Charset", mySqlCharset);
                mySqlSslMode        = mySqlConfig.Get("SslMode", mySqlSslMode);
                mySqlMinPoolSize    = mySqlConfig.Get("MinPoolSize", mySqlMinPoolSize);
                sqlConnectionString = $"Data Source={mySqlDataSource};Port={mySqlPort};User ID={mySqlUserId};Password={mySqlPassword}; Initial Catalog={mySqlInitialCatlog};Charset={mySqlCharset}; SslMode={mySqlSslMode};Min pool size={mySqlMinPoolSize}";
                break;

            case DataType.SqlServer:
                IConfigurationManager sqlServerConfig = config.CreateSubManager("SqlServer");
                sqlServerDataSource         = sqlServerConfig.Get("DataSource", sqlServerDataSource);
                sqlServerIntegratedSecurity = sqlServerConfig.Get("IntegratedSecurity", sqlServerIntegratedSecurity);
                sqlServerInitialCatlog      = sqlServerConfig.Get("InitialCatlog", sqlServerInitialCatlog);
                sqlServerPooling            = sqlServerConfig.Get("Pooling", sqlServerPooling);
                sqlServerMinPoolSize        = sqlServerConfig.Get("PoolSize", sqlServerMinPoolSize);
                sqlConnectionString         = $"Data Source={sqlServerDataSource};Integrated Security={sqlServerIntegratedSecurity};Initial Catalog={sqlServerInitialCatlog};Pooling={sqlServerPooling};Min Pool Size={sqlServerMinPoolSize}";
                break;

            case DataType.PostgreSQL:
                IConfigurationManager postgreSqlConfig = config.CreateSubManager("PostgreSql");
                postgreSqlHost        = postgreSqlConfig.Get("Host", postgreSqlHost);
                postgreSqlPort        = postgreSqlConfig.Get("Port", postgreSqlPort);
                postgreSqlUserName    = postgreSqlConfig.Get("UserName", postgreSqlUserName);
                postgreSqlPassword    = postgreSqlConfig.Get("Password", postgreSqlPassword);
                postgreSqlDatabase    = postgreSqlConfig.Get("Database", postgreSqlDatabase);
                postgreSqlPooling     = postgreSqlConfig.Get("Pooling", postgreSqlPooling);
                postgreSqlMinPoolSize = postgreSqlConfig.Get("MinPoolSize", postgreSqlMinPoolSize);
                sqlConnectionString   = $"Host={postgreSqlHost};Port={postgreSqlPort};Username={postgreSqlUserName};Password={postgreSqlPassword}; config.Database={postgreSqlDatabase};Pooling={postgreSqlPooling};Minimum Pool Size={postgreSqlMinPoolSize}";
                break;

            case DataType.Oracle:
                IConfigurationManager oracleConfig = config.CreateSubManager("Oracle");
                oracleDataSource    = oracleConfig.Get("DataSource", oracleDataSource);
                oracleUserId        = oracleConfig.Get("UserId", oracleUserId);
                oraclePassword      = oracleConfig.Get("Password", oraclePassword);
                oraclePooling       = oracleConfig.Get("Pooling", oraclePooling);
                oracleMinPoolSize   = oracleConfig.Get("MinPoolSize", oracleMinPoolSize);
                sqlConnectionString = $"user id={oracleUserId};password={oraclePassword}; data source={oracleDataSource};Pooling={oraclePooling};Min Pool Size={oracleMinPoolSize}";
                break;

            default:
            case DataType.Sqlite:
                IConfigurationManager sqliteConfig = config.CreateSubManager("Sqlite");
                sqliteDataSource    = sqliteConfig.Get("DataSource", sqliteDataSource);
                sqliteAttachs       = sqliteConfig.Get("Attachs", sqliteAttachs);
                sqlitePooling       = sqliteConfig.Get("Pooling", sqlitePooling);
                sqliteMinPoolSize   = sqliteConfig.Get("MinPoolSize", sqliteMinPoolSize);
                sqlConnectionString = $"Data Source={sqliteDataSource}; Attachs={sqliteAttachs}; Pooling={sqlitePooling};Min Pool Size={sqliteMinPoolSize}";
                break;

            case DataType.MsAccess:
                IConfigurationManager msAccessConfig = config.CreateSubManager("MsAccess");
                msAccessDataSource  = msAccessConfig.Get("DataSource", msAccessDataSource);
                msAccessProvider    = msAccessConfig.Get("Provider", msAccessProvider);
                msAccessMaxPoolSize = msAccessConfig.Get("MaxPoolSize", msAccessMaxPoolSize);
                sqlConnectionString = $"Provider={msAccessProvider};Data Source={msAccessDataSource};max pool size={msAccessMaxPoolSize}";
                break;
            }
            sql = new FreeSqlBuilder()
                  .UseConnectionString(type, sqlConnectionString)
                  .UseAutoSyncStructure(autoSyncStructure)
                  .UseGenerateCommandParameterWithLambda(parameterized)
                  .Build();
            if (sqlToVerbose)
            {
                sql.Aop.CurdBefore += (s, e) =>
                {
                    logger.Verbose("执行SQL:\n{SQL}", e.Sql);
                };
            }

            if (warnOnOverTime)
            {
                sql.Aop.CurdAfter += (s, e) =>
                {
                    if (e.ElapsedMilliseconds >= overTime)
                    {
                        logger.Warn("执行SQL超时({Time}ms):\n{SQL}", e.ElapsedMilliseconds, e.Sql);
                    }
                };
            }
        }