Пример #1
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,Text,LabelText,IsFirstOption,IsSecondaryOption,GroupProviderId")] ProviderOption providerOption)
        {
            if (id != providerOption.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(providerOption);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!ProviderOptionExists(providerOption.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["GroupProviderId"] = new SelectList(_context.GroupProviders, "Id", "BackColor", providerOption.GroupProviderId);
            return(View(providerOption));
        }
        protected string[] FormatInsertParamsAndValues <T>(T entity)
        {
            var paramSqlBuilder = new StringBuilder(64);
            var valueSqlBuilder = new StringBuilder(64);

            var properties = entity.GetProperties();

            var isAppend = false;

            foreach (var propertiy in properties)
            {
                if (isAppend)
                {
                    paramSqlBuilder.Append(",");
                    valueSqlBuilder.Append(",");
                }

                var columnName   = propertiy.GetColumnAttributeName();
                var paramterName = ProviderOption.ParameterPrefix + columnName;
                paramSqlBuilder.Append(ProviderOption.CombineFieldName(columnName));
                valueSqlBuilder.Append(paramterName);

                Params.Add(paramterName, propertiy.GetValue(entity));

                isAppend = true;
            }

            return(new[] { paramSqlBuilder.ToString(), valueSqlBuilder.ToString() });
        }
Пример #3
0
        /// <summary>
        /// 获取表名称
        /// </summary>
        /// <param name="isNeedFrom"></param>
        /// <param name="isAsName"></param>
        /// <param name="tableType">连接查询时会用到</param>
        /// <returns></returns>

        public string FormatTableName(bool isNeedFrom = true, bool isAsName = true, Type tableType = null)
        {
            var    entity   = EntityCache.QueryEntity(tableType == null ? Context.Set.TableType : tableType);
            string schema   = string.IsNullOrEmpty(entity.Schema) ? "" : ProviderOption.CombineFieldName(entity.Schema) + ".";
            string fromName = entity.Name;
            //函数AsTableName优先级大于一切
            string asTableName;

            if (AsTableNameDic.TryGetValue(entity.Type, out asTableName))
            {
                fromName = asTableName;
            }
            //是否存在实体特性中的AsName标记
            if (isAsName)
            {
                fromName = entity.AsName.Equals(fromName) ? ProviderOption.CombineFieldName(fromName) : $"{ProviderOption.CombineFieldName(fromName)} {entity.AsName}";
            }
            else
            {
                fromName = ProviderOption.CombineFieldName(fromName);
            }
            SqlString = $" {schema}{fromName} ";
            if (isNeedFrom)
            {
                SqlString = " FROM " + SqlString;
            }

            return(SqlString);
        }
 public VidorBinaryDataProvider(ProviderOption providerOption)
 {
     _providerOption = providerOption.ManualProviderOption;
     if (_providerOption == null)
     {
         throw new ArgumentNullException(providerOption.Name);
     }
 }
 /// <inheritdoc />
 /// <summary>
 /// 执行解析
 /// </summary>
 /// <param name="obj"></param>
 /// <returns></returns>
 public UpdateEntityWhereExpression(object obj, ProviderOption providerOption)
 {
     _sqlCmd          = new StringBuilder(100);
     Param            = new DynamicParameters();
     _providerOption  = providerOption;
     _parameterPrefix = _providerOption.ParameterPrefix;
     _obj             = obj;
 }
Пример #6
0
 public ProviderSettings GetProviderSettings(ProviderOption providerOption)
 {
     return(providerOption switch
     {
         ProviderOption.Console => GetConsoleProviderSettings(),
         ProviderOption.File => GetFileProviderSettings(),
         ProviderOption.Database => GetDatabaseProviderSettings(),
         _ => throw new NotImplementedException()
     });
        /// <inheritdoc />
        /// <summary>
        /// 执行解析
        /// </summary>
        /// <param name="expression"></param>
        /// <returns></returns>
        public UpdateExpression(LambdaExpression expression, ProviderOption providerOption)
        {
            _sqlCmd          = new StringBuilder(100);
            _providerOption  = providerOption;
            _parameterPrefix = _providerOption.ParameterPrefix;
            Param            = new DynamicParameters();

            Visit(expression);
        }
Пример #8
0
 private ProviderSettings(ProviderOption providerOption,
                          string?connectionString   = null,
                          DatabaseType?databaseType = null,
                          string?fileName           = null)
 {
     ProviderOption   = providerOption;
     ConnectionString = connectionString;
     DatabaseType     = databaseType;
     FileName         = fileName;
 }
Пример #9
0
        public async Task <IActionResult> Create([Bind("Id,Text,LabelText,IsFirstOption,IsSecondaryOption,GroupProviderId")] ProviderOption providerOption)
        {
            if (ModelState.IsValid)
            {
                _context.Add(providerOption);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["GroupProviderId"] = new SelectList(_context.GroupProviders, "Id", "BackColor", providerOption.GroupProviderId);
            return(View(providerOption));
        }
        private ViewRuleRequestModelWrapper _currentRequest;  // Созданный запрос, после подготовки данных.

        #endregion



        #region ctor

        public ByRulesDataProvider(ProviderOption providerOption)
        {
            var option = providerOption.ByRulesProviderOption;

            if (option == null)
            {
                throw new ArgumentNullException(providerOption.Name);
            }

            ProviderName = providerOption.Name;
            _rules       = option.Rules.Select(opt => new Rule(opt)).ToList();
        }
Пример #11
0
        public static Command Create(Delegate executor = null)
        {
            var cmd = new Command("update", "Download and update local database.");

            cmd.AddAlias("force");

            cmd.Handler = CommandHandler.Create(executor ?? new Action <DataSource, string, string, string>(Execute));

            cmd.AddOption(ProviderOption.Create());
            cmd.AddOption(RepoOption.Create());
            cmd.AddOption(PathOption.Create());

            return(cmd);
        }
        protected string FormatTableName(bool isNeedFrom = true)
        {
            var typeOfTableClass = TableType;

            var tableName = typeOfTableClass.GetTableAttributeName();

            SqlString = $" {ProviderOption.CombineFieldName(tableName)} ";
            if (isNeedFrom)
            {
                SqlString = " FROM " + SqlString;
            }

            return(SqlString);
        }
Пример #13
0
        public bool TryCreateUser(List <Claim> claims, ProviderOption provider, out User user)
        {
            var id      = claims.GetClaimValue(ClaimTypes.NameIdentifier) ?? claims.GetClaimValue(JwtClaimTypes.Subject);
            var name    = claims.GetClaimValue(ClaimTypes.GivenName);
            var surname = claims.GetClaimValue(ClaimTypes.Surname);
            var mail    = claims.GetClaimValue(ClaimTypes.Email);

            if (!string.IsNullOrEmpty(name) && !string.IsNullOrEmpty(surname) && !string.IsNullOrEmpty(mail))
            {
                var externalUser = _userRepository.GetExternalUserByEmailAsync(mail).GetAwaiter().GetResult();
                if (!externalUser.IsEmpty())
                {
                    user = new User
                    {
                        Id            = Guid.NewGuid(),
                        Name          = name,
                        Surname       = surname,
                        Mail          = mail,
                        Roles         = externalUser.Roles,
                        ExternalUsers = new List <ExternalUser>
                        {
                            new ExternalUser
                            {
                                Identifier = id,
                                Provider   = provider
                            }
                        },
                        HashPassword = "",
                        Salt         = "",
                        PhoneNumber  = "",
                        Language     = LanguageOption.En,
                        PhotoUrl     = ""
                    };

                    return(true);
                }
            }
            user = null;

            return(false);
        }
Пример #14
0
        public async Task RunAsync()
        {
            while (true)
            {
                ProviderOption   providerOption   = _providerSettingsProvider.GetProviderOption();
                ProviderSettings providerSettings = _providerSettingsProvider.GetProviderSettings(providerOption);

                SaverOption   saverOption   = _saverSettingsProvider.GetSaverOptions();
                SaverSettings saverSettings = _saverSettingsProvider.GetSaverSettings(saverOption);

                ProcessingOption processingOption = _processingSettingsProvider.GetProcessingOption();

                ITextProvider          provider  = GetTextProvider(providerSettings);
                ITextProcessor         processor = GetTextProcessor(processingOption);
                IProcessingResultSaver saver     = GetResultSaver(saverSettings);

                var text = provider.GetTextAsync(CancellationToken.None);
                IProcessingResult result = await processor.GetResultAsync(text, CancellationToken.None);

                await saver.SaveAsync(result, CancellationToken.None);
            }
        }
 public static void InitOption(ProviderOption providerOption)
 {
     ProviderOption = providerOption;
 }
Пример #16
0
 public MySqlProvider()
 {
     ProviderOption = new ProviderOption(OpenQuote, CloseQuote, ParameterPrefix);
     ResolveExpression.InitOption(ProviderOption);
 }
 public MsSqlProvider()
 {
     ProviderOption    = new ProviderOption(OpenQuote, CloseQuote, ParameterPrefix);
     ResolveExpression = new ResolveExpression(this);
 }
Пример #18
0
        //Scan through the well-known providerAssemblies folder to find the providers that met the condition.
        internal IEnumerable<string> ScanAllProvidersFromProviderAssembliesLocation(
            IHostApi request,
            string providerName,
            Version requiredVersion,
            Version minimumVersion,
            Version maximumVersion,
            ProviderOption providerOption = ProviderOption.LatestVersion) {

            //if provider is installed in providername\version format
            var providerFolder = ProviderAssembliesLocation.Distinct(new PathEqualityComparer(PathCompareOption.Full)).SelectMany(Directory.EnumerateDirectories);

            foreach (var providerNameFolder in providerFolder) {

                var name = Path.GetFileName(providerNameFolder);

                //check the providername folder
                if (!string.IsNullOrWhiteSpace(providerName)) {

                    if (string.IsNullOrWhiteSpace(providerNameFolder)) {
                        continue;
                    }
                   
                    if (string.IsNullOrWhiteSpace(name) || !name.IsWildcardMatch(providerName)) {
                        continue;
                    }
                }

                var selectedVersions = Directory.EnumerateDirectories(providerNameFolder).Select(versionFolder => {
                    //check if the version is in a valid format. Ver will be 0 if TryParse fails and it won't be selected
                    Version ver;
                    if (System.Version.TryParse(Path.GetFileName(versionFolder), out ver)) {
                        return new {
                            folder = versionFolder,
                            version = (FourPartVersion)ver
                        };
                    }
                    return null;
                }).Where(each => each != null && each.version > 0L);

                selectedVersions = selectedVersions.Where(eachVersion => {
                    if ((requiredVersion == null) || eachVersion.version == (FourPartVersion)requiredVersion) {
                        if ((minimumVersion == null) || eachVersion.version >= (FourPartVersion)minimumVersion) {
                            if ((maximumVersion == null) || eachVersion.version <= (FourPartVersion)maximumVersion) {
                                return true;
                            }
                        }
                    }
                    return false;
                });

                //Get the version folders
                var versionFolders = (providerOption == ProviderOption.AllProvider) ?
                    selectedVersions.Select(each => each.folder).Where(Directory.Exists) :
                    new[] {selectedVersions.OrderByDescending(each => each.version).Select(each => each.folder).FirstOrDefault(Directory.Exists)};

                foreach (var assemblyFolder in versionFolders.WhereNotNull()) {
                    //we reached the provider assembly file path now

                    var files = Directory.EnumerateFiles(assemblyFolder)
                        .Where(file => (file != null) && (Path.GetExtension(file).EqualsIgnoreCase(".dll") || Path.GetExtension(file).EqualsIgnoreCase(".exe"))).ToArray();

                    //if found more than one dll is installed under a version folder, this is not allowed. warning here as enumerating for providers should continue
                    if (files.Any() && files.Count() > 1) {
                        request.Warning(string.Format(CultureInfo.CurrentCulture, Resources.Messages.SingleAssemblyAllowed, files.JoinWithComma()));
                        continue;
                    }
                    // find modules that have the provider manifests
                    var filelist = files.Where(each => Manifest.LoadFrom(each).Any(manifest => Swidtag.IsSwidtag(manifest) && new Swidtag(manifest).IsApplicable(new Hashtable())));

                    if (!filelist.Any()) {
                        continue;
                    }
                    var version = Path.GetFileName(assemblyFolder);
                    var defaultPkgProvider = new DefaultPackageProvider(name, version);
                    var providerPath = files.FirstOrDefault();

                    var pkgProvider = new PackageProvider(defaultPkgProvider)
                    {
                        ProviderPath = providerPath,
                        Version = version,
                        IsLoaded = false
                    };

                    AddToProviderCacheTable(name, pkgProvider);
                    yield return providerPath;
                }
            }

            //check if assembly is installed at the top leverl folder.
            var providerFiles = ProviderAssembliesLocation.Distinct(new PathEqualityComparer(PathCompareOption.Full)).SelectMany(Directory.EnumerateFiles)
                .Where(each => each.FileExists() && (Path.GetExtension(each).EqualsIgnoreCase(".dll") || Path.GetExtension(each).EqualsIgnoreCase(".exe"))).ReEnumerable();

            // found the assemblies at the top level folder.
            // if a user is looking for a specific version & provider name, we are not be able to know the provider name or version without loading it.
            // Thus, for the top level providers, we just need to load them for the backward compatibility. 
            if (providerFiles.Any()) {
                request.Verbose(string.Format(CultureInfo.CurrentCulture, Resources.Messages.ProviderNameAndVersionNotAvailableFromFilePath, providerFiles.JoinWithComma()));
                foreach (var provider in providerFiles) {
                    //the provider is installed at the top level.

                    // find modules that have the provider manifests
                    if (Manifest.LoadFrom(provider).Any(manifest => Swidtag.IsSwidtag(manifest) && new Swidtag(manifest).IsApplicable(new Hashtable()))) {

                        yield return provider;
                    }
                }
            }
        }