public async Task <IEnumerable <ApiResource> > FindApiResourcesByScopeAsync(IEnumerable <string> scopeNames) { var scopes = string.Empty; if (scopeNames != null) { scopes = string.Join(',', scopeNames); } return(await base.GetAsync <IEnumerable <ApiResource> >("resources/api", UriParameter.Create("scopes", scopes))); }
public static string BuildPath(string path, UriParameter parameter) { path = NormalizePath(path); var start = path.IndexOf('{'); var end = path.IndexOf('}'); if (start < 0 || end < 0 || start > end) { throw new InvalidOperationException(); } var substitution = path.Substring(start, end - start + 1); return(path.ReplaceWithParameter(substitution, parameter)); }
/// <summary> /// Construct an instance of the Text URI data type. /// </summary> /// <param name="uriPath">Either the LocalPath or AbsolutePath from a "data:" URI (that does not contain "base64,"</param> /// <param name="otherParameters">Returns any additional, unrecognized URI parameters.</param> public Text(string uriPath, out List <UriParameter> otherParameters) { if (string.IsNullOrWhiteSpace(uriPath)) { throw new ArgumentNullException(nameof(uriPath)); } if (uriPath.NonQuotedIndexOf(SEPARATOR) < 0) { throw new ArgumentException(ParsingHelper.UriPathNotWellFormedMessage("text data"), nameof(uriPath)); } var pair = uriPath.NonQuotedSplitOnFirst(SEPARATOR); Data = pair.Item2; if (string.IsNullOrWhiteSpace(pair.Item1) || pair.Item1.NonQuotedIndexOf(';') < 0) { _mediaType = null; _charSet = null; otherParameters = null; return; } otherParameters = new List <UriParameter>(); foreach (string s in pair.Item1.NonQuotedSplit(';')) { UriParameter p = new UriParameter(s); if (string.IsNullOrWhiteSpace(p.Value)) { MediaType = p.Name; } else if (p.Is("charset")) { CharacterSet = p.Value; } else { otherParameters.Add(p); } } if (otherParameters.Count < 1) { otherParameters = null; } }
public ApiResultModel <DataSet> GetAllById(long dataBaseId, string tableName, string idName, long id) { var result = new ApiResultModel <DataSet>(); try { var _tableName = new ThamSoThuTuc { TEN = "pTableName".ToUpper(), GIA_TRI = tableName, KIEU_DU_LIEU = "VARCHAR2" }; var _id = new ThamSoThuTuc { TEN = idName, GIA_TRI = id.ToString(), KIEU_DU_LIEU = "NUMBER" }; var _listThamSoIn = new List <ThamSoThuTuc>(); _listThamSoIn.Add(_tableName); _listThamSoIn.Add(_id); var _listThamSoOut = new List <ThamSoThuTuc>(); _listThamSoOut.Add(new ThamSoThuTuc { TEN = "pData".ToUpper(), KIEU_DU_LIEU = "CURSOR" }); var paraInfo = new UriParameter { DatabaseId = dataBaseId, TenThuTuc = "PKG_COMMON.GetAllTableById", listThamSoIn = _listThamSoIn, listThamSoOut = _listThamSoOut }; result = GetData(paraInfo); } catch (Exception ex) { HandleDAOExceptions(ex); } return(result); }
public ApiResultModel <DataSet> GetData(UriParameter paraInfo) { //Gọi API để validate key using (var client = new HttpClient()) { client.BaseAddress = new Uri(ApiUrl.MainApiUrl); client.DefaultRequestHeaders.Accept.Clear(); client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); // New code: //var response = client.GetAsync("Authentication/ValidateTokenKeySSO?tokenkey=" + HttpUtility.UrlEncode(key)).Result; //Nếu sử dụng API để get phân quyền thì truyền thêm tham số var response = client.PostAsync("TraCuu/GetData", paraInfo, new JsonMediaTypeFormatter()).Result; if (!response.IsSuccessStatusCode) { return(null); } var result = response.Content.ReadAsAsync <ApiResultModel <DataSet> >().Result; return(result); } }
private ValidationResult GetValidationResult(UriParameter p) { ValidationResult result = new ValidationResult(); try { if (!File.Exists(p.Value) && !Directory.Exists(p.Value)) { throw new Exception("File or directory not exist."); } p.UriType = File.GetAttributes(p.Value).HasFlag(FileAttributes.Directory) ? UriType.Directory : UriType.File; p.URI = new Uri(p.Value); result.IsValid = true; } catch (Exception ex) { result.IsValid = false; result.Message = ex.Message; } return(result); }
/// <summary> /// Construct an instance of the Binary URI data type /// </summary> /// <param name="uriPath">Either the LocalPath or AbsolutePath from a "data:" URI</param> /// <param name="otherParameters">Returns any additional, unrecognized URI parameters</param> public Binary(string uriPath, out List <UriParameter> otherParameters) { if (string.IsNullOrWhiteSpace(uriPath)) { throw new ArgumentNullException(nameof(uriPath)); } if (!uriPath.Contains(SEPARATOR)) { throw new ArgumentException(ParsingHelper.UriPathNotWellFormedMessage("base-64 encoded"), nameof(uriPath)); } List <string> split = uriPath.NonQuotedSplit(';', StringSplitOptions.RemoveEmptyEntries, true); List <UriParameter> parms = new List <UriParameter>(); foreach (string s in split) { parms.AddIfNotNull(UriParameter.Parse(s)); } MediaType = parms[0].Name; UriParameter data = parms.Where(p => p.Name.StartsWith(SEPARATOR)).FirstOrDefault(); Data = Convert.FromBase64String(data.Name.Replace(SEPARATOR, string.Empty)); if (parms.Count < 2) { otherParameters = null; } else { otherParameters = new List <UriParameter>(); for (int i = 2; i < parms.Count; i++) { otherParameters.Add(parms[i]); } } }
public DefaultSynchronizer(IConsoleLogger consoleLogger, UriParameter gitHubUriParameter, OautTokenParameter OAuthTokenParameter) : base(consoleLogger, gitHubUriParameter, OAuthTokenParameter) { }
public static string ReplaceWithParameter(this string path, string substitution, UriParameter parameter) { var nameAndType = substitution.Trim('{', '}').Split(':'); if (nameAndType.Length == 0 || nameAndType.Length > 2) { throw new InvalidOperationException(); } var name = nameAndType[0].ToLower(); string type = null; if (nameAndType.Length == 2) { type = nameAndType[1].ToLower(); } if (!name.Equals(parameter.Name, StringComparison.OrdinalIgnoreCase)) { throw new InvalidOperationException(); } var uriValue = parameter.Value.ToUri(type); return(path.Replace(substitution, uriValue)); }
protected SynchronizerBase(IConsoleLogger logger, UriParameter gitHubUriParameter, OautTokenParameter OAuthTokenParameter) { GitHubClient = CreateCient(gitHubUriParameter.Value, OAuthTokenParameter.Value); _logger = logger; }
protected string BuildLinkWithParam(string path, UriParameter param) { var parsed = LinkBuilder.BuildPath(path, param); return(LinkBuilder.BuildLink(parsed)); }
/// <summary> /// Construct an instance of the GeoLoc URI data type /// </summary> /// <param name="uriPath">Either the LocalPath or AbsolutePath from a "geo:" URI</param> /// <param name="otherParameters">Returns any additional, unrecognized URI parameters</param> public GeoLoc(string uriPath, out List <UriParameter> otherParameters) { if (string.IsNullOrWhiteSpace(uriPath)) { throw new ArgumentNullException(nameof(uriPath)); } List <string> split1 = uriPath.NonQuotedSplit(';', StringSplitOptions.RemoveEmptyEntries, true); if (!split1[0].Contains(",")) { throw new ArgumentException(ParsingHelper.UriPathNotWellFormedMessage("geo-loc"), nameof(uriPath)); } List <string> coords = split1[0].NonQuotedSplit(',', false); if (coords.Count > 1) { if (float.TryParse(coords[0], out float a)) { Latitude = a; } else { throw new ArgumentException(ParsingHelper.UriPathEncodingError(nameof(Latitude), "float"), nameof(uriPath)); } if (float.TryParse(coords[1], out float b)) { Longitude = b; } else { throw new ArgumentException(ParsingHelper.UriPathEncodingError(nameof(Longitude), "float"), nameof(uriPath)); } } if (coords.Count > 2) { if (float.TryParse(coords[2], out float c)) { Altitude = c; } else { throw new ArgumentException(ParsingHelper.UriPathEncodingError(nameof(Altitude), "float"), nameof(uriPath)); } } else { Altitude = null; } Uncertainty = null; if (split1.Count > 1) { otherParameters = new List <UriParameter>(); for (int i = 1; i < split1.Count; i++) { UriParameter param; try { param = new UriParameter(split1[i]); if (param.Is("crs")) { CrsLabel = param.Value; } else if (param.Is("u")) { if (float.TryParse(param.Value, out float u)) { Uncertainty = u; } else { Uncertainty = null; } } else { otherParameters.Add(param); } } catch { } } if (otherParameters.Count < 1) { otherParameters = null; } } else { otherParameters = null; } }
public List <Parameter> GetParameters(string[] args) { List <Parameter> parameters = new List <Parameter>(); StringBuilder sb = new StringBuilder(); foreach (string str in args) { sb.AppendFormat($" {str}"); } string tempStr = string.Empty; string[] clauses = sb.ToString().Split('/', '\\'); foreach (string clause in clauses) { try { string[] strs = clause.Split(" ".ToArray(), 2); switch (strs[0]) { case Constants.ArgumentConstants.Input: UriParameter input = new UriParameter() { Key = Constants.ArgumentConstants.Input, Value = strs[1], IsActive = true, Name = Constants.Input }; parameters.Add(input); this.EssentialParameters.Input = input; break; case Constants.ArgumentConstants.Output: UriParameter output = new UriParameter() { Key = Constants.ArgumentConstants.Output, Value = strs[1], IsActive = true, Name = Constants.Output }; parameters.Add(output); this.EssentialParameters.Output = output; break; case Constants.ArgumentConstants.Strategy: UriParameter strategy = new UriParameter() { Key = Constants.ArgumentConstants.Strategy, Value = strs[1], IsActive = true, Name = Constants.Strategy }; parameters.Add(strategy); this.EssentialParameters.Strategy = strategy; break; case Constants.ArgumentConstants.Log: UriParameter log = new UriParameter() { Key = Constants.ArgumentConstants.Log, Value = strs[1], IsActive = true, Name = Constants.Log }; parameters.Add(log); this.EssentialParameters.Log = log; break; // function parameter case Constants.ArgumentConstants.Version: parameters.Add(new Parameter() { Key = Constants.ArgumentConstants.Version, Value = strs[1] }); break; case Constants.ArgumentConstants._Version: parameters.Add(new Parameter() { Key = Constants.ArgumentConstants._Version, Value = strs[1] }); break; default: break; } } catch (Exception ex) { Console.WriteLine(ex.Message); Environment.Exit(1); } } return(parameters); }