本文整理汇总了C#中BsonRegularExpression类的典型用法代码示例。如果您正苦于以下问题:C# BsonRegularExpression类的具体用法?C# BsonRegularExpression怎么用?C# BsonRegularExpression使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
BsonRegularExpression类属于命名空间,在下文中一共展示了BsonRegularExpression类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: Get
public LogSearchResponse Get(LogSearchRequest request)
{
request = request ?? new LogSearchRequest();
IFindFluent<BsonDocument, BsonDocument> cursor;
if (!request.IsEmpty)
{
List<FilterDefinition<BsonDocument>> queries = new List<FilterDefinition<BsonDocument>>();
if (!String.IsNullOrWhiteSpace(request.Query))
{
var queryExpr = new BsonRegularExpression(new Regex(request.Query, RegexOptions.IgnoreCase));
queries.Add(Builders< BsonDocument>.Filter.Or(
Builders< BsonDocument>.Filter.Regex(FieldNames.Message, queryExpr),
Builders<BsonDocument>.Filter.Regex(FieldNames.Loggername, queryExpr)
));
}
if (!String.IsNullOrWhiteSpace(request.Level))
{
var levels = request.Level.Split(',').Select(x => x.Trim()).ToArray();
queries.Add(Builders<BsonDocument>.Filter.In(FieldNames.Level, levels.Select(BsonValue.Create)));
}
cursor = Logs.Find(Builders<BsonDocument>.Filter.And(queries));
}
else
{
cursor = Logs.Find(Builders<BsonDocument>.Filter.Empty);
}
var response = new LogSearchResponse
{
Items = cursor
.Sort(Builders<BsonDocument>.Sort.Descending(FieldNames.Timestamp))
.Skip(request.LogsPerPage*(request.Page - 1))
.Limit(request.LogsPerPage)
.ToList()
.Select(x => x.ToDictionary()),
Count = cursor.Count()
};
return response;
}
开发者ID:ProximoSrl,项目名称:Jarvis.DocumentStore,代码行数:44,代码来源:LogController.cs
示例2: TestAsRegexOptionS
public void TestAsRegexOptionS()
{
BsonValue v = new BsonRegularExpression("xyz", "s");
BsonValue s = "";
var r = v.AsRegex;
Assert.AreEqual(RegexOptions.Singleline, r.Options);
Assert.Throws<InvalidCastException>(() => { var x = s.AsRegex; });
}
开发者ID:CloudMetal,项目名称:mongo-csharp-driver,代码行数:8,代码来源:BsonValueTests.cs
示例3: FindAll
/// <summary>
/// finds all files
/// </summary>
/// <param name="startsWithPath"></param>
/// <param name="includeTempFiles"></param>
/// <param name="skip"></param>
/// <param name="limit"></param>
/// <returns></returns>
public List<IStorageFile> FindAll(string startsWithPath = null, bool includeTempFiles = false, int? skip = null, int? limit = null)
{
//all filepaths are lowercase and all starts with folder separator
if (!string.IsNullOrWhiteSpace(startsWithPath))
{
startsWithPath = startsWithPath.ToLowerInvariant();
if (!startsWithPath.StartsWith(FOLDER_SEPARATOR))
startsWithPath = FOLDER_SEPARATOR + startsWithPath;
}
List<IMongoQuery> queries = new List<IMongoQuery>();
if (!includeTempFiles)
{
IMongoQuery tmpFolderQuery = Query.Matches("filename", new BsonRegularExpression("^(/" + TMP_FOLDER_NAME + "/)", "i"));
IMongoQuery tmpFolderExclideQuery = Query.Not(tmpFolderQuery);
queries.Add(tmpFolderExclideQuery);
}
if (!string.IsNullOrWhiteSpace(startsWithPath))
{
//TODO change to starts with - now is contains
var regex = new BsonRegularExpression(string.Format(".*{0}.*", startsWithPath), "i");
queries.Add(Query.Matches("filename", regex));
}
IMongoQuery finalQuery = queries.Count > 0 ? Query.And(queries) : Query.Null;
var cursor = gfs.Find(finalQuery);
if (skip.HasValue)
cursor.SetSkip(skip.Value);
if (limit.HasValue)
cursor.SetLimit(limit.Value);
IEnumerable<MongoGridFSFileInfo> files = cursor.ToList();
return cursor.AsQueryable().Select(f => (IStorageFile)(new MongoStorageFile(f))).ToList();
}
开发者ID:jango2015,项目名称:WebVella-ERP,代码行数:47,代码来源:MongoStorageFS.cs
示例4: Files
/// <summary>
/// Display all the files
/// </summary>
public ActionResult Files(string search)
{
var mongo = MongoServer.Create(MongoConnectionString);
var db = mongo.GetDatabase(MongoDatabase);
var gfs = db.GridFS;
var files = new List<MongoGridFSFileInfo>();
if (! string.IsNullOrEmpty(search)) {
var regex = new BsonRegularExpression(string.Format(".*{0}.*", search), "i");
files = gfs.Find(
Query.Or(
Query.Matches("metadata.title", regex),
Query.Matches("filename", regex)))
.ToList();
} else {
files = gfs.FindAll().ToList();
}
mongo.Disconnect();
return View(files);
}
开发者ID:markembling,项目名称:Experimental,代码行数:26,代码来源:HomeController.cs
示例5: GetRegularExpressionToken
private static JsonToken GetRegularExpressionToken(JsonBuffer buffer)
{
// opening slash has already been read
var start = buffer.Position - 1;
var state = RegularExpressionState.InPattern;
while (true)
{
var c = buffer.Read();
switch (state)
{
case RegularExpressionState.InPattern:
switch (c)
{
case '/': state = RegularExpressionState.InOptions; break;
case '\\': state = RegularExpressionState.InEscapeSequence; break;
default: state = RegularExpressionState.InPattern; break;
}
break;
case RegularExpressionState.InEscapeSequence:
state = RegularExpressionState.InPattern;
break;
case RegularExpressionState.InOptions:
switch (c)
{
case 'i':
case 'm':
case 'x':
case 's':
state = RegularExpressionState.InOptions;
break;
case ',':
case '}':
case ']':
case ')':
case -1:
state = RegularExpressionState.Done;
break;
default:
if (char.IsWhiteSpace((char)c))
{
state = RegularExpressionState.Done;
}
else
{
state = RegularExpressionState.Invalid;
}
break;
}
break;
}
switch (state)
{
case RegularExpressionState.Done:
buffer.UnRead(c);
var lexeme = buffer.Substring(start, buffer.Position - start);
var regex = new BsonRegularExpression(lexeme);
return new RegularExpressionJsonToken(lexeme, regex);
case RegularExpressionState.Invalid:
throw new FileFormatException(FormatMessage("Invalid JSON regular expression", buffer, start));
}
}
}
开发者ID:robinNode,项目名称:mongo-csharp-driver,代码行数:63,代码来源:JsonScanner.cs
示例6: RegularExpressionJsonToken
// constructors
/// <summary>
/// Initializes a new instance of the RegularExpressionJsonToken class.
/// </summary>
/// <param name="lexeme">The lexeme.</param>
/// <param name="value">The BsonRegularExpression value.</param>
public RegularExpressionJsonToken(string lexeme, BsonRegularExpression value)
: base(JsonTokenType.RegularExpression, lexeme)
{
this.value = value;
}
开发者ID:kamaradclimber,项目名称:mongo-csharp-driver,代码行数:11,代码来源:JsonToken.cs
示例7: GetUserByName
internal static kUser GetUserByName(string name)
{
var regex = new BsonRegularExpression(new Regex("^" + name + "$", RegexOptions.IgnoreCase));
var query = Query<kUser>.Matches(u => u.Name, regex);
return Db.GetCollection<kUser>("users").FindOne(query);
}
开发者ID:ScottKaye,项目名称:kreport-web,代码行数:6,代码来源:Mongo.cs
示例8: GetSession
private void GetSession(int sessionId)
{
// Get the database instance of mongo
var AuctionVehicles = ConnectToMongo();
// Get mongo Collection of documents, return them as a type of pre-made object (auction vehicle)
// param that is passed in is the string for the collection name (Vehicles)
var collection = AuctionVehicles.GetCollection<AuctionVehicle>("vehicles");
///
/// This searches for the searchsession 181
///
var query = new QueryDocument("_searchSession", 181);
///
/// This one gets all
var cursor = collection.FindAllAs<AuctionVehicle>();
///
/// This one gets one from using the above query.
///
// var cursor = collection.Find(query);
// Set returned cursor's sort params (sort by search session id decending).
cursor.SetSortOrder(SortBy.Descending("_searchSession"));
// Set limit of returned documents.
cursor.SetLimit(1);
// Convert the cursort to a list so can enumerate.
var list = cursor.ToList();
// Get the latest search session (first session in the list)
int latestSession = list[0]._searchSession;
// this one works for ANDS
var biggerQuery = Query.And(
Query.EQ("make", "TOYOTA"),
Query.EQ("model", "HIACE VAN")
);
// This one works for ORs
var queryOr = Query.Or(
Query.EQ("model", "SAFARI"),
Query.EQ("model", "ASTRO"),
Query.EQ("model", "CHEVYVAN")
);
// Create regex for mongo wildcard search
var regex = new BsonRegularExpression("/.*" + "USS Nagoya" + "*/");
// This one works for ands and regex
// This is my favourite way to query. each one is an And and finally a regex to do wildcard text search - remember the bsonregularexpression.
var biggerQueryDocumentStyle = new QueryDocument()
{
{"make", "TOYOTA"},
{"model", "HIACE VAN"},
{"htmlData.htmlRow", regex}
};
var cursor3 = collection.Find(biggerQueryDocumentStyle);
var cursor2 = collection.Find(biggerQuery);
var cursor3list = cursor3.ToList();
var cursor2list = cursor2.ToList();
/*
foreach (var item in cursor2list) {
Console.WriteLine(item.make + " " + item.model + " " + "Session ID = " + item._searchSession);
Console.ReadLine();
}
foreach (var item in cursor3list) {
Console.WriteLine(item.make + " " + item.model + " " + "Session ID = " + item._searchSession);
Console.ReadLine();
}
/*
*
foreach (var item in list)
{
Console.WriteLine(item.make + " " + item.model + " " + "Session ID = " + item._searchSession);
Console.ReadLine();
}
*/
}
开发者ID:CaptainClaypole,项目名称:seleniumscrapevehicles,代码行数:89,代码来源:MongoOps.cs
示例9: TestBsonRegularExpression
public void TestBsonRegularExpression()
{
var value = new BsonRegularExpression("pattern", "imxs");
Assert.AreSame(value, ((IConvertible)value).ToType(typeof(object), null));
Assert.Throws<InvalidCastException>(() => Convert.ToBoolean(value));
Assert.Throws<InvalidCastException>(() => Convert.ToByte(value));
Assert.Throws<InvalidCastException>(() => Convert.ToChar(value));
Assert.Throws<InvalidCastException>(() => Convert.ToDateTime(value));
Assert.Throws<InvalidCastException>(() => Convert.ToDecimal(value));
Assert.Throws<InvalidCastException>(() => Convert.ToDouble(value));
Assert.Throws<InvalidCastException>(() => Convert.ToInt16(value));
Assert.Throws<InvalidCastException>(() => Convert.ToInt32(value));
Assert.Throws<InvalidCastException>(() => Convert.ToInt64(value));
Assert.Throws<InvalidCastException>(() => Convert.ToSByte(value));
Assert.Throws<InvalidCastException>(() => Convert.ToSingle(value));
Assert.Throws<InvalidCastException>(() => Convert.ToString(value));
Assert.Throws<InvalidCastException>(() => Convert.ToUInt16(value));
Assert.Throws<InvalidCastException>(() => Convert.ToUInt32(value));
Assert.Throws<InvalidCastException>(() => Convert.ToUInt64(value));
}
开发者ID:niemyjski,项目名称:mongo-csharp-driver,代码行数:20,代码来源:BsonValueIConvertibleTests.cs
示例10: TestAsBsonRegularExpression
public void TestAsBsonRegularExpression()
{
BsonValue v = new BsonRegularExpression("pattern", "options");
BsonValue s = "";
var r = v.AsBsonRegularExpression;
Assert.AreEqual("pattern", r.Pattern);
Assert.AreEqual("options", r.Options);
Assert.Throws<InvalidCastException>(() => { var x = s.AsBsonRegularExpression; });
}
开发者ID:CloudMetal,项目名称:mongo-csharp-driver,代码行数:9,代码来源:BsonValueTests.cs
示例11: WriteRegularExpression
/// <summary>
/// Writes a BSON regular expression to the writer.
/// </summary>
/// <param name="regex">A BsonRegularExpression.</param>
public override void WriteRegularExpression(BsonRegularExpression regex)
{
if (Disposed) { throw new ObjectDisposedException("BsonDocumentWriter"); }
if (State != BsonWriterState.Value)
{
ThrowInvalidState("WriteRegularExpression", BsonWriterState.Value);
}
WriteValue(regex);
State = GetNextState();
}
开发者ID:einaregilsson,项目名称:mongo-csharp-driver,代码行数:15,代码来源:BsonDocumentWriter.cs
示例12: TestClass
public TestClass(
BsonRegularExpression value
)
{
this.B = value;
this.V = value;
}
开发者ID:vshlos,项目名称:mongo-csharp-driver,代码行数:7,代码来源:BsonValueSerializerTests.cs
示例13: WriteRegularExpression_should_have_expected_result
public void WriteRegularExpression_should_have_expected_result()
{
var subject = CreateSubject();
var value = new BsonRegularExpression("abc", "i");
WriteNested(subject, () => subject.WriteRegularExpression(value));
AssertBsonEquals(subject, "{ x : /abc/i }");
}
开发者ID:rstam,项目名称:mongo-csharp-driver-jsondotnet-original,代码行数:9,代码来源:JsonWriterAdapterTests.cs
示例14: TestBsonRegularExpressionConstructors
public void TestBsonRegularExpressionConstructors()
{
var regex = new BsonRegularExpression("pattern");
Assert.IsInstanceOf<BsonRegularExpression>(regex);
Assert.AreEqual("pattern", regex.Pattern);
Assert.AreEqual("", regex.Options);
regex = new BsonRegularExpression("/pattern/i");
Assert.IsInstanceOf<BsonRegularExpression>(regex);
Assert.AreEqual("pattern", regex.Pattern);
Assert.AreEqual("i", regex.Options);
regex = new BsonRegularExpression(@"/pattern\/withslash/i");
Assert.IsInstanceOf<BsonRegularExpression>(regex);
Assert.AreEqual("pattern/withslash", regex.Pattern);
Assert.AreEqual("i", regex.Options);
regex = new BsonRegularExpression("pattern", "i");
Assert.IsInstanceOf<BsonRegularExpression>(regex);
Assert.AreEqual("pattern", regex.Pattern);
Assert.AreEqual("i", regex.Options);
regex = new BsonRegularExpression(new Regex("pattern"));
Assert.IsInstanceOf<BsonRegularExpression>(regex);
Assert.AreEqual("pattern", regex.Pattern);
Assert.AreEqual("", regex.Options);
regex = new BsonRegularExpression(new Regex("pattern", RegexOptions.IgnoreCase | RegexOptions.Multiline | RegexOptions.IgnorePatternWhitespace | RegexOptions.Singleline));
Assert.IsInstanceOf<BsonRegularExpression>(regex);
Assert.AreEqual("pattern", regex.Pattern);
Assert.AreEqual("imxs", regex.Options);
regex = new BsonRegularExpression(new Regex("pattern", RegexOptions.IgnoreCase));
Assert.IsInstanceOf<BsonRegularExpression>(regex);
Assert.AreEqual("pattern", regex.Pattern);
Assert.AreEqual("i", regex.Options);
regex = new BsonRegularExpression(new Regex("pattern", RegexOptions.Multiline));
Assert.IsInstanceOf<BsonRegularExpression>(regex);
Assert.AreEqual("pattern", regex.Pattern);
Assert.AreEqual("m", regex.Options);
regex = new BsonRegularExpression(new Regex("pattern", RegexOptions.IgnorePatternWhitespace));
Assert.IsInstanceOf<BsonRegularExpression>(regex);
Assert.AreEqual("pattern", regex.Pattern);
Assert.AreEqual("x", regex.Options);
regex = new BsonRegularExpression(new Regex("pattern", RegexOptions.Singleline));
Assert.IsInstanceOf<BsonRegularExpression>(regex);
Assert.AreEqual("pattern", regex.Pattern);
Assert.AreEqual("s", regex.Options);
}
开发者ID:CloudMetal,项目名称:mongo-csharp-driver,代码行数:52,代码来源:BsonValueTests.cs
示例15: TestMapBsonRegularExpression
public void TestMapBsonRegularExpression() {
var value = new BsonRegularExpression("pattern", "options");
var bsonValue = (BsonRegularExpression) BsonTypeMapper.MapToBsonValue(value);
Assert.AreSame(value, bsonValue);
var bsonRegularExpression = (BsonRegularExpression) BsonTypeMapper.MapToBsonValue(value, BsonType.RegularExpression);
Assert.AreSame(value, bsonRegularExpression);
}
开发者ID:simi--,项目名称:mongo-csharp-driver,代码行数:7,代码来源:BsonTypeMapperTests.cs
示例16: TestAsRegexOptionI
public void TestAsRegexOptionI()
{
BsonValue v = new BsonRegularExpression("xyz", "i");
BsonValue s = "";
var r = v.AsRegex;
Assert.Equal(RegexOptions.IgnoreCase, r.Options);
Assert.Throws<InvalidCastException>(() => { var x = s.AsRegex; });
}
开发者ID:RavenZZ,项目名称:MDRelation,代码行数:8,代码来源:BsonValueTests.cs
示例17: TestAsRegexOptionX
public void TestAsRegexOptionX()
{
BsonValue v = new BsonRegularExpression("xyz", "x");
BsonValue s = "";
var r = v.AsRegex;
Assert.AreEqual(RegexOptions.IgnorePatternWhitespace, r.Options);
Assert.Throws<InvalidCastException>(() => { var x = s.AsRegex; });
}
开发者ID:CloudMetal,项目名称:mongo-csharp-driver,代码行数:8,代码来源:BsonValueTests.cs
示例18: TestAsRegexOptionAll
public void TestAsRegexOptionAll()
{
BsonValue v = new BsonRegularExpression("xyz", "imxs");
BsonValue s = "";
var r = v.AsRegex;
Assert.AreEqual(RegexOptions.IgnoreCase | RegexOptions.Multiline | RegexOptions.IgnorePatternWhitespace | RegexOptions.Singleline, r.Options);
Assert.Throws<InvalidCastException>(() => { var x = s.AsRegex; });
}
开发者ID:CloudMetal,项目名称:mongo-csharp-driver,代码行数:8,代码来源:BsonValueTests.cs
示例19: BuildStringQuery
private IMongoQuery BuildStringQuery(MethodCallExpression methodCallExpression)
{
if (methodCallExpression.Method.DeclaringType == typeof(string))
{
switch (methodCallExpression.Method.Name)
{
case "Contains":
case "EndsWith":
case "StartsWith":
var arguments = methodCallExpression.Arguments.ToArray();
if (arguments.Length == 1)
{
var serializationInfo = GetSerializationInfo(methodCallExpression.Object);
var valueExpression = arguments[0] as ConstantExpression;
if (serializationInfo != null && valueExpression != null)
{
var s = (string)valueExpression.Value;
BsonRegularExpression regex;
switch (methodCallExpression.Method.Name)
{
case "Contains": regex = new BsonRegularExpression(s); break;
case "EndsWith": regex = new BsonRegularExpression(s + "$"); break;
case "StartsWith": regex = new BsonRegularExpression("^" + s); break;
default: throw new InvalidOperationException("Unreachable code");
}
return Query.Matches(serializationInfo.ElementName, regex);
}
}
break;
}
}
return null;
}
开发者ID:ncipollina,项目名称:mongo-csharp-driver,代码行数:33,代码来源:SelectQuery.cs
示例20: WriteRegularExpression
public void WriteRegularExpression(string pattern, string options)
{
var regex = new BsonRegularExpression(pattern, options);
WriteRegularExpression(regex);
}
开发者ID:einaregilsson,项目名称:mongo-csharp-driver,代码行数:5,代码来源:BsonWriter.cs
注:本文中的BsonRegularExpression类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论