public string getContent() { ParamExtractor extractor = new ParamExtractor(this.method); string ret = string.Empty; if (extractor.validate()) { ret = string.Format("{0}\n{1}", this.content.getContent(), extractor.getTagValue()); } else { ret = this.content.getContent(); } return(ret); }
public ActionResult Category(int id, int?country, int?manufacturerId, int?packId, object specs, SortCriterion?sort, List <List <int> > catFilter = null, int?minPrice = null, int?maxPrice = null, string query = null) { bool exists = _shopCategoryService.CategoryExists(id); if (!exists) { throw new HttpException(404, "Not found"); } var cat = _shopCategoryService.GetCategory(id); var routeValues = ParamExtractor.ExtractParamsForSEF(Request); var args = new RouteValueDictionary(routeValues); args.Add("relativeUrl", cat.CanonicalUrl); args.Remove("id"); return(RedirectPermanent(Url.RouteUrl(typeof(Category).FullName, args))); }
private static IEnumerable <CommandDefinition> YieldBulkInsertCommands <TCommon, TInsert>(Match valuesClauseMatch, string sql, TCommon commonParam, IEnumerable <TInsert> insertParams, IDbTransaction transaction = null, int?batchSize = null, CancellationToken cancellationToken = default(CancellationToken)) { // identify SQL parts Group tupleMatch = valuesClauseMatch.Groups[1]; int sqlPrefixLength = tupleMatch.Index; int sqlSuffixIndex = valuesClauseMatch.Index + valuesClauseMatch.Length; string tupleSql = tupleMatch.Value; // get common names and values string[] commonNames = ParamExtractor <TCommon> .GetNames(); object[] commonValues = ParamExtractor <TCommon> .GetValues(commonParam); // get insert names and find insert parameters in tuple string[] insertNames = ParamExtractor <TInsert> .GetNames(); var pastEndTupleSqlIndices = s_parameterRegex.Matches(tupleSql).Cast <Match>() .Where(match => insertNames.Any(name => string.Compare(match.Value, 1, name, 0, match.Value.Length, StringComparison.OrdinalIgnoreCase) == 0)) .Select(match => match.Index + match.Length) .ToList(); // calculate batch size (999 is SQLite's maximum and works well with MySql.Data) const int maxParamsPerBatch = 999; int actualBatchSize = batchSize ?? Math.Max(1, (maxParamsPerBatch - commonNames.Length) / Math.Max(1, insertNames.Length)); // insert one batch at a time string batchSql = null; int lastBatchCount = 0; StringBuilder batchSqlBuilder = null; foreach (var insertParamBatch in EnumerateBatches(insertParams, actualBatchSize)) { // build the SQL for the batch int batchCount = insertParamBatch.Count; if (batchSql == null || batchCount != lastBatchCount) { if (batchSqlBuilder == null) { batchSqlBuilder = new StringBuilder(sqlPrefixLength + batchCount * (1 + tupleSql.Length + pastEndTupleSqlIndices.Count * 4) + (sql.Length - sqlSuffixIndex)); } else { batchSqlBuilder.Clear(); } batchSqlBuilder.Append(sql, 0, sqlPrefixLength); for (int rowIndex = 0; rowIndex < batchCount; rowIndex++) { if (rowIndex != 0) { batchSqlBuilder.Append(','); } int tupleSqlIndex = 0; foreach (int pastEndTupleSqlIndex in pastEndTupleSqlIndices) { batchSqlBuilder.Append(tupleSql, tupleSqlIndex, pastEndTupleSqlIndex - tupleSqlIndex); batchSqlBuilder.Append('_'); batchSqlBuilder.Append(rowIndex.ToString(CultureInfo.InvariantCulture)); tupleSqlIndex = pastEndTupleSqlIndex; } batchSqlBuilder.Append(tupleSql, tupleSqlIndex, tupleSql.Length - tupleSqlIndex); } batchSqlBuilder.Append(sql, sqlSuffixIndex, sql.Length - sqlSuffixIndex); batchSql = batchSqlBuilder.ToString(); lastBatchCount = batchCount; } // add the parameters for the batch var batchParameters = new DynamicParameters(); for (int commonIndex = 0; commonIndex < commonNames.Length; commonIndex++) { batchParameters.Add(commonNames[commonIndex], commonValues[commonIndex]); } // enumerate rows to insert for (int rowIndex = 0; rowIndex < insertParamBatch.Count; rowIndex++) { var insertParam = insertParamBatch[rowIndex]; var insertValues = ParamExtractor <TInsert> .GetValues(insertParam); for (int insertIndex = 0; insertIndex < insertNames.Length; insertIndex++) { batchParameters.Add(insertNames[insertIndex] + "_" + rowIndex.ToString(CultureInfo.InvariantCulture), insertValues[insertIndex]); } } // return command definition yield return(new CommandDefinition(batchSql, batchParameters, transaction, default(int?), default(CommandType?), CommandFlags.Buffered, cancellationToken)); } }