public IBinaryDataListItem FetchScalar() { IBinaryDataListItem result = null; if (IsRecordset) { string error; return(TryFetchLastIndexedRecordsetUpsertPayload(out error)); } if (_internalObj.Count > 0) { var binaryDataListItems = _internalObj[0]; if (binaryDataListItems != null && binaryDataListItems.Count > 0) { result = binaryDataListItems[0]; } } if (result == null) { bool isSystemTag = TranslationConstants.systemTags.Cast <object>().Select((t, i) => TranslationConstants.systemTags.GetValue(i).ToString()).Any(key => Namespace.Contains(key)); result = isSystemTag ? new BinaryDataListItem("", Namespace) : new BinaryDataListItem(null, Namespace); // place miss into the collection _internalObj[0] = new List <IBinaryDataListItem> { result }; } return(result); }
public virtual bool DoesHandleRequest(Type type, IHttpRequest request, out double matchQuality, out string [] componentsMatched) { matchQuality = (this.Route.HasBlackSpace() ? 0 : 2) + (this.Namespace.HasBlackSpace() ? 0 : 1); var requestUrl = request.GetAbsoluteUri(); var path = requestUrl.AbsolutePath; while (path.Contains("//")) { path = path.Replace("//", "/"); } var pathParameters = path .Split('/'.AsArray()) .Where(v => v.HasBlackSpace()) .ToArray(); if (IsExcluded()) { componentsMatched = new string[] { }; return(false); } if (!IsNamespaceCorrect(out string [] nsComponents)) { componentsMatched = new string[] { }; return(false); } if (this.Route.HasBlackSpace()) { var doesMatch = DoesMatch(nsComponents.Length, this.Route, out string [] routeComponents); componentsMatched = nsComponents .Concat(routeComponents.NullToEmpty()) .ToArray(); return(doesMatch); } { //var route = pathParameters // .Skip(nsComponents.Length) // .First(); componentsMatched = nsComponents; //.Append(route) //.ToArray(); return(true); } bool DoesMatch(int index, string value, out string [] matchComponents) { var valueComponents = value.Split('/'); if (pathParameters.Length < index + valueComponents.Length) { matchComponents = default; // new string[] { }; return(false); } matchComponents = pathParameters.Skip(index).Take(valueComponents.Length).ToArray(); if (!valueComponents.SequenceEqual(matchComponents, StringComparison.OrdinalIgnoreCase)) { return(false); } return(true); } bool IsNamespaceCorrect(out string [] nsComponents) { if (this.Namespace.IsNullOrWhiteSpace()) { nsComponents = pathParameters.Take(1).ToArray(); return(true); } if (!Namespace.Contains(',')) { return(DoesMatch(0, this.Namespace, out nsComponents)); } bool doesAnyNamespaceMatch; (doesAnyNamespaceMatch, nsComponents) = Namespace .Split(',') .First( (ns, next) => { if (!DoesMatch(0, ns, out string[] nsInner)) { return(next()); } return(true, nsInner); }, () => (false, new string[] { })); return(doesAnyNamespaceMatch); }