private static string GetCode(IQueryCollection queryStringParameters) { if (queryStringParameters == null || !queryStringParameters.Any()) { throw new ArgumentOutOfRangeException(nameof(queryStringParameters)); } // Maybe we have an error? if (queryStringParameters.ContainsKey("error")) { var errorMessage = string.Format("Reason: {0}. Error: {1}. Description: {2}.", queryStringParameters["error_reason"].ToString() ?? "-", queryStringParameters["error"], queryStringParameters["error_description"]); throw new NogginNetCoreAuthException(errorMessage); } if (!queryStringParameters.ContainsKey("code")) { throw new NogginNetCoreAuthException("No auth code returned by Facebook"); } return(queryStringParameters["code"].ToString()); }
private static bool MatchesFilter( string[] testTags, IQueryCollection query) { //If no tags were requested, then then it is a match if (!query.Any()) { return(true); } var includeTags = query.Where(t => string.Equals( t.Value.FirstOrDefault(), "true", StringComparison.OrdinalIgnoreCase)) .Select(t => t.Key) .ToArray(); var excludeTags = query.Where(t => string.Equals(t.Value.FirstOrDefault(), "false", StringComparison.OrdinalIgnoreCase)) .Select(t => t.Key) .ToArray(); return(!excludeTags.Intersect(testTags, StringComparer.OrdinalIgnoreCase).Any() && includeTags.Intersect(testTags, StringComparer.OrdinalIgnoreCase).Count() == includeTags.Length); }
private static IQueryCollection GetParameters(IQueryCollection parameters) { if (!parameters.Any()) { throw new ArgumentException($"{parameters.GetType().Name} does not contain any parameter."); } return(parameters); }
public string[] GetIds(IQueryCollection args) { if (args.Any(o => o.Key.Contains("ids"))) { List <string> idList = new List <string>(); var ids = args.Where(o => o.Key.Contains("ids")); foreach (var id in ids) { if (id.Value.Any()) { idList.Add(id.Value.ToString()); } } return(idList.ToArray()); } return(null); }
public FeedbackGetModel Create(IQueryCollection queryCol) { var model = new FeedbackGetModel(); if (queryCol != null && queryCol.Any() && queryCol.TryGetValue(RatingQueryParamName, out var queryParamValue)) { var strRating = queryParamValue.FirstOrDefault(); if (!String.IsNullOrEmpty(strRating)) { if (byte.TryParse(strRating, out var rating)) { model.Rating = rating; } } } return(model); }
public async Task <object> GetResultForTable(string table) { IQueryCollection query = _httpContextAccessor.HttpContext.Request.Query; var where = ""; if (query.Any()) { where += " WHERE "; } var parameters = new SortedDictionary <string, object>(); foreach (var(key, value) in query) { where += key + "=@" + key; var colSpec = _dbInspector.GetSchema().FindTableByName(table).FindColumn(key); parameters.Add(key, _dbMutator.Coerce(colSpec, value.SingleOrDefault())); } var tabInfo = _dbInspector.GetSchema().FindTableByName(table); var tab = tabInfo.SchemaOwner.Equals("auth") ? "auth." + table : table; var sql = $"select * from {tab}{where}"; var conn = await _dbConnectionProvider.Get(); var rs = await conn.QueryAsync(sql, parameters); var rs2 = rs .Cast <IDictionary <string, object> >() .Select(d => AddSelfLink(table, d)) // .Cast<IDictionary<string, object>>() .ToArray(); foreach (var o in rs2) { o["type"] = table; } return(new SearchResult { Items = rs2, Links = LinksForTable(table) }); }
private static StringBuilder BuildOrderedQueryString(IQueryCollection queryCollection) { var queryStringBuilder = new StringBuilder(); if (queryCollection.Any()) { var isFirstPair = true; queryStringBuilder = queryCollection.OrderBy(q => q.Key) .Aggregate(queryStringBuilder, (builder, currentPair) => { builder.Append(isFirstPair ? "?" : "&") .Append(currentPair.Key) .Append('=') .Append(currentPair.Value); isFirstPair = false; return(builder); }); } return(queryStringBuilder); }
private static string GetCode(IQueryCollection queryStringParameters) { if (queryStringParameters == null || !queryStringParameters.Any()) { throw new ArgumentOutOfRangeException(nameof(queryStringParameters)); } // Maybe we have an error? if (queryStringParameters.ContainsKey("error")) { var errorMessage = $"{queryStringParameters["error"]}: {queryStringParameters["error_description"]}"; throw new NogginNetCoreAuthException(errorMessage); } if (!queryStringParameters.ContainsKey("code")) { throw new NogginNetCoreAuthException("No auth code returned by GitHub"); } return(queryStringParameters["code"].ToString()); }
public bool HasFilter(IQueryCollection args) { return(args.Any(o => o.Key.Contains("filterModel"))); }
public bool HasIds(IQueryCollection args) { return(args.Any(o => o.Key.Contains("ids"))); }
Notification <TPrimitiveContent>?ParseNotification(string body, IHeaderDictionary headers, IQueryCollection query) { var notificationContent = Connection.DeserializeJson <NotificationContent <TPrimitiveContent> >(body); if (notificationContent == null) { return(null); } var notification = notificationContent.Notification; if (notification == null) { return(null); } var serializer = JsonSerializer.CreateDefault(Connection.JsonSettings); var representation = ((Newtonsoft.Json.Linq.JObject)notification.NotificationEvent.Representation).ToObject <TPrimitiveContent>(serializer); notification.NotificationEvent.PrimitiveRepresentation = representation; /* * var notificationPrimitive = notification.NotificationEvent.PrimitiveRepresentation = new ResponsePrimitive<ResponseContent<TPrimitiveContent>>//new RequestPrimitive<TPrimitiveContent> * { * From = headers["X-M2M-Origin"].FirstOrDefault(), * RequestIdentifier = headers["X-M2M-RI"].FirstOrDefault(), * //GroupRequestIdentifier = headers["X-M2M-GID"].FirstOrDefault(), * OriginatingTimestamp = headers["X-M2M-OT"].FirstOrDefault()?.ParseNullableDateTimeOffset(), * ResultExpirationTimestamp = headers["X-M2M-RST"].FirstOrDefault(), * //RequestExpirationTimestamp = headers["X-M2M-RET"].FirstOrDefault(), * //OperationExecutionTime = headers["X-M2M-OET"].FirstOrDefault(), * EventCategory = headers["X-M2M-EC"].FirstOrDefault(), * * PrimitiveContent = representation * }; */ if (query.Any()) { var notificationURI = headers["X-M2M-RTU"]; #if false var responseType = query["rt"]; if (notificationURI.Count > 0 || responseType.Count > 0) { requestPrimitive.ResponseType = new ResponseTypeInfo { ResponseTypeValue = responseType.FirstOrDefault()?.ParseNullableEnum <ResponseType>(), NotificationURI = notificationURI.Join("&")?.Split('&')?.ToArray(), }; } #endif #if false FilterCriteria?fc = null; FilterCriteria FC() => fc ??= new FilterCriteria(); if (DateTimeOffset.TryParse(query["crb"].FirstOrDefault(), out DateTimeOffset crb)) { FC().CreatedBefore = crb; } if (DateTimeOffset.TryParse(query["cra"].FirstOrDefault(), out DateTimeOffset cra)) { FC().CreatedAfter = cra; } if (DateTimeOffset.TryParse(query["ms"].FirstOrDefault(), out DateTimeOffset ms)) { FC().ModifiedSince = ms; } if (long.TryParse(query["sts"].FirstOrDefault(), out long sts)) { FC().StateTagSmaller = sts; } if (long.TryParse(query["stb"].FirstOrDefault(), out long stb)) { FC().StateTagBigger = stb; } if (DateTimeOffset.TryParse(query["exb"].FirstOrDefault(), out DateTimeOffset exb)) { FC().ExpireBefore = exb; } if (DateTimeOffset.TryParse(query["exa"].FirstOrDefault(), out DateTimeOffset exa)) { FC().ExpireAfter = exa; } var resourceTypes = query["ty"].SelectMany(str => str.Split(",")).Select(str => Enum.Parse <ResourceType>(str)).ToList(); if (resourceTypes.Count > 0) { FC().ResourceType = resourceTypes; } if (long.TryParse(query["sza"].FirstOrDefault(), out long sza)) { FC().SizeAbove = sza; } if (long.TryParse(query["szb"].FirstOrDefault(), out long szb)) { FC().SizeBelow = szb; } if (long.TryParse(query["lim"].FirstOrDefault(), out long lim)) { FC().Limit = lim; } if (Enum.TryParse <FilterUsage>(query["fu"].FirstOrDefault(), out FilterUsage fu)) { FC().FilterUsage = fu; } var fo = query["fo"].FirstOrDefault(); if (fo == "1" || "true".Equals(fo, StringComparison.InvariantCultureIgnoreCase)) { FC().FilterOperation = true; } else if (fo == "0" || "false".Equals(fo, StringComparison.InvariantCultureIgnoreCase)) { FC().FilterOperation = false; } if (Enum.TryParse <ContentFilterSyntax>(query["cfs"].FirstOrDefault(), out ContentFilterSyntax cfs)) { FC().ContentFilterSyntax = cfs; } if (query["cfq"].Count > 0) { FC().ContentFilterQuery = query["cfq"].FirstOrDefault(); } if (long.TryParse(query["lvl"].FirstOrDefault(), out long lvl)) { FC().Level = lvl; } if (long.TryParse(query["ofst"].FirstOrDefault(), out long ofst)) { FC().Offset = ofst; } /* TODO: * if (fc.Attribute != null) * foreach (var attr in fc.Attribute) * args.Add(attr.Name, attr.Value.ToString()); * * if (fc.SemanticsFilter != null) * args.AddRange("smf", fc.SemanticsFilter); * * if (fc.Labels != null) * args.AddRange("lbl", fc.Labels); * * if (fc.ContentType != null) * args.AddRange("cty", fc.ContentType); */ notificationPrimitive.FilterCriteria = fc; #endif } return(notification); }