private AuthResponse RunRequest(QueryMethod method, string url, string data) { if (string.IsNullOrEmpty(_consumerKey) && string.IsNullOrEmpty(_consumerSecret)) { string sessionId = ReadSessionFile(); if (!string.IsNullOrEmpty(sessionId) && ReUseSession) { if (!ValidateSession(sessionId)) { if (!GetTemporaryKeys()) { return(null); } } } else { if (!GetTemporaryKeys()) { return(null); } } } return(ExecuteRequest(method, url, data)); }
private int textureWaterTile(int x, int y, QueryMethod queryMethod) { int tex_num = 0; // 526 // 1 3 // 407 for (int n = 0; n < DirRemap.WRAPPED_DIR8.Length; n++) { if (IsBlocked(queryMethod, x, y, DirRemap.WRAPPED_DIR8[n])) { tex_num |= (0x1 << n); } } //if a cardinal direction does not pass, its adjacent diagonals do not either for (int n = 0; n < DirExt.DIR4_COUNT; n++) { if ((tex_num & (0x1 << n)) == 0x0) { Dir8 dir1 = DirExt.AddAngles(((Dir4)n).ToDir8(), Dir8.DownLeft); Dir8 dir2 = DirExt.AddAngles(((Dir4)n).ToDir8(), Dir8.DownRight); tex_num &= ~(0x1 << toWrappedInt(dir1)); tex_num &= ~(0x1 << toWrappedInt(dir2)); } } return(tex_num); }
/// <summary> /// Adds the specified field. /// </summary> /// <param name="field">The field.</param> /// <param name="method">The method.</param> /// <param name="val">The value.</param> /// <returns>SearchCondition.</returns> public SearchCondition Add(string field, QueryMethod method, object val) { ConditionItem item = new ConditionItem(field, method, val); this.Items.Add(item); return(this); }
public TestResult(QueryMethod method, QueryType type, List <double> times, bool loop) { Method = method; Type = type; Times = times; Loop = loop; }
/// <summary> /// 非逻辑关联规约 /// </summary> /// <param name="prop">实体属性名称</param> /// <param name="val">值</param> /// <param name="method">运算符</param> public void Or(string prop, object val, QueryMethod method, string Group) { ConditionItem conItem = new ConditionItem(prop, method, val); conItem.OrGroup = Group; _conItems.Add(conItem); }
/// <summary> /// Defines how to map a property to a entity framework property or any other type of object property /// </summary> /// <param name="objectType">Type this property maps too</param> /// <param name="propertyName">Property name this property should set</param> /// <param name="valueType">Type of the property this mapping represents</param> /// <param name="queryMethod">Type of query method to use if it's a enumerable</param> public MappingPropertyAttribute(Type objectType, string propertyName, Type valueType, QueryMethod queryMethod = QueryMethod.Any) { ObjectType = objectType; ValueType = valueType; PropertyNames.Add(propertyName); QueryMethod = queryMethod; }
public TimeTrackerRepository(DevHubContext context, QueryMethod query, GuidMethod guid, IMapper mapper, MethodLibrary method) { _context = context; _query = query; _guid = guid; _mapper = mapper; _method = method; }
public ConditionItem(string field, QueryMethod method, object val) { this._QueryDataType = WTF.Framework.QueryDataType.ObjectT; this._Prefix = "it"; this.Field = field; this.Method = method; this.Value = val; }
public Query(QueryMethod method, string serverMethod, string queryBody = "", IDictionary <string, string> parameters = null) { Method = method; QueryBody = queryBody; ServerMethod = serverMethod; NeededHeaders = new List <string>(); Parameters = parameters == null ? new Dictionary <string, string>() : parameters; }
/// <summary> /// 将Method转换成Dapper语法的查询语句 /// </summary> /// <param name="method">方法</param> /// <param name="value">值</param> /// <returns>条件</returns> protected virtual string ConvertMethodToSql(QueryMethod method, object value) { switch (method) { /* * sqlText += " and Name like @Name"; * p.Add("Name","%"+ model.Name+"%"); */ case QueryMethod.Contains: case QueryMethod.StartsWith: case QueryMethod.EndsWith: return("like " + value); /* * string sql = "SELECT * FROM SomeTable WHERE id IN @ids" * var results = conn.Query(sql, new { ids = new[] { 1, 2, 3, 4, 5 }}); */ case QueryMethod.StdIn: return("in " + value); case QueryMethod.StdNotIn: return("not in " + value); case QueryMethod.NotLike: return("not like " + value); ////数字类型处理 case QueryMethod.GreaterThan: return("> " + value); case QueryMethod.GreaterThanOrEqual: return(">= " + value); case QueryMethod.Equal: if (value == null) { return(" is null "); } return("= " + value); case QueryMethod.LessThan: return("< " + value); case QueryMethod.LessThanOrEqual: return("<= " + value); case QueryMethod.NotEqual: if (value == null) { return(" is not null "); } return("<> " + value); default: return(""); } }
private int Delete(QueryMethod method, dynamic items, string tag, string configId = null) { string url = makeUrl(tag, configId); string data = _serializer.Serialize(items); AuthResponse authResponse = RunRequest(method, url, data); return(ProcessPostResponse(authResponse)); }
/// <summary> /// </summary> /// <param name="prop"></param> /// <param name="val"></param> /// <param name="method"></param> /// <param name="group"></param> public void Or(string prop, object val, QueryMethod method, string @group) { ConditionItem conItem = new ConditionItem(prop, method, val) { OrGroup = @group }; this.conItems.Add(conItem); }
/// <summary> /// Sign a web request using Auth. /// </summary> /// <param name="method">Http method GET, POST or DELETE</param> /// <param name="url">The full url, including the querystring.</param> /// <param name="postData">Data to post in xml or json fromat</param> /// <returns>The web server response.</returns> protected AuthResponse AuthWebRequest(QueryMethod method, string url, string postData, bool isBinary) { Uri uri = new Uri(url); string nonce = this.GenerateNonce(); string timeStamp = this.GenerateTimeStamp(); string authheader = this.GenerateAuthorizationHeader(uri, method.ToString(), timeStamp, nonce); string querystringUri = this.GenerateQueryString(uri, method.ToString(), timeStamp, nonce); HttpWebRequest webRequest = (HttpWebRequest)System.Net.WebRequest.Create(querystringUri); webRequest.Method = method.ToString(); webRequest.Credentials = CredentialCache.DefaultCredentials; webRequest.Headers.Add("x-app-name", ApiKeys.AppName); webRequest.Headers.Add("x-api-version", ApiKeys.ApiVersion); webRequest.Headers.Add("Authorization", authheader); if (ApiKeys.UseCompression) { webRequest.Headers.Add("Accept-Encoding", "gzip,deflate"); webRequest.AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate; } if (method == QueryMethod.POST || method == QueryMethod.PUT || method == QueryMethod.DELETE) { webRequest.ContentType = "application/x-www-form-urlencoded"; //Write the data. StreamWriter requestWriter = new StreamWriter(webRequest.GetRequestStream()); try { requestWriter.Write(postData); } catch { throw; } finally { requestWriter.Close(); } } AuthResponse authResponse = WebResponseGet(webRequest, isBinary); authResponse.Method = method; return(authResponse); }
public BookLogRepository(DevHubContext context, IMapper mapper, MethodLibrary method, GuidMethod guid, QueryMethod query, EmailMethod email) { _context = context; _mapper = mapper; _method = method; _guid = guid; _query = query; _email = email; }
public Query(QueryMethod method, string serverMethod, string queryBody = "", IDictionary <string, string> parameters = null, IList <MultipartDataItem> multipartData = null) { Method = method; QueryBody = queryBody; ServerMethod = serverMethod; NeededHeaders = new List <string>(); Parameters = parameters == null ? new Dictionary <string, string>() : parameters; MultipartData = multipartData == null ? new List <MultipartDataItem>() : multipartData; }
private dynamic Update(QueryMethod method, dynamic items, string tag, string configId = null) { string url = makeUrl(tag, configId); string data = _serializer.Serialize(items); AuthResponse authResponse = RunRequest(method, url, data); dynamic obj = ProcessGetResponse(authResponse); return(obj); }
private AuthResponse RunRequest(QueryMethod method, string url, string data) { AuthRequest authRequest = new AuthRequest(_consumerKey, _consumerSecret, _appName); using (authRequest) { OnRequest(this, new RequestEventArgs(method.ToString(), url, data)); AuthResponse authResponse = authRequest.AuthWebRequest(method, url, data); OnResponse(this, new ResponseEventArgs(authResponse.Status, authResponse.Data)); return authResponse; } }
public void AddConditionItem(string field, QueryMethod method, QueryUnite queryUnite, QueryDataType queryDataType, object val) { ConditionItem item = new ConditionItem { Field = field, Method = method, Value = val, QueryUnite = queryUnite, QueryDataType = queryDataType }; this.Items.Add(item); }
private AuthResponse ExecuteRequest(QueryMethod method, string url, string data) { string appName = this.GetAppName(); AuthRequest authRequest = new AuthRequest(_consumerKey, _consumerSecret, appName, _useCompression, _apiVersion); using (authRequest) { OnRequest(this, new RequestEventArgs(method.ToString(), url, data)); AuthResponse authResponse = authRequest.AuthWebRequest(method, url, data); OnResponse(this, new ResponseEventArgs(authResponse.Status, authResponse.Data)); return(authResponse); } }
private int Delete(QueryMethod method, dynamic items, string tag, string configId = null) { string url = String.Format("{0}/{1}.{2}", _host, tag, _format); if (!String.IsNullOrEmpty(configId)) { url = String.Format("{0}/{1}.{2}?config_id={3}", _host, tag, _format, configId); } string data = _serializer.Serialize(items); AuthResponse authResponse = this.RunRequest(method, url, data); return(this.ProcessPostResponse(authResponse)); }
private AuthResponse WebRequest(QueryMethod method, string url, string postData, string authheader, bool isBinary) { HttpWebRequest webRequest = null; StreamWriter requestWriter = null; webRequest = (HttpWebRequest)System.Net.WebRequest.Create(url); webRequest.Method = method.ToString(); webRequest.Credentials = CredentialCache.DefaultCredentials; webRequest.Headers.Add("x-app-name", _appName); webRequest.Headers.Add("x-api-version", _apiVersion); webRequest.Headers.Add("Authorization", authheader); if (_useCompression == true) { webRequest.Headers.Add("Accept-Encoding", "gzip,deflate"); webRequest.AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate; } if (method == QueryMethod.POST || method == QueryMethod.PUT || method == QueryMethod.DELETE) { webRequest.ContentType = "application/x-www-form-urlencoded"; //Write the data. requestWriter = new StreamWriter(webRequest.GetRequestStream()); try { requestWriter.Write(postData); } catch { throw; } finally { requestWriter.Close(); requestWriter = null; } } AuthResponse authResponse = WebResponseGet(webRequest, isBinary); authResponse.Method = method; webRequest = null; return(authResponse); }
public void Write(string timeSpan, QueryMethod method) { if (!File.Exists(path)) { FileStream fs = new FileStream(path, FileMode.Create, FileAccess.Write, FileShare.Write); fs.Flush(); fs.Close(); fs = null; } StreamWriter writer = new StreamWriter(path, true, System.Text.Encoding.Default); writer.WriteLine(timeSpan + " " + method.ToString()); writer.Flush(); writer.Close(); writer.Dispose(); }
private int textureBlock(int x, int y, QueryMethod queryMethod) { // 2 // 1 3 // 0 bool[] blockedDirs = new bool[DirExt.DIR4_COUNT]; for (int n = 0; n < DirExt.DIR4_COUNT; n++) { blockedDirs[n] = IsBlocked(queryMethod, x, y, ((Dir4)n).ToDir8()); } // 1|2 // -+- // 0|3 bool[] blockedQuads = new bool[DirExt.DIR4_COUNT]; for (int n = 0; n < DirExt.DIR4_COUNT; n++) { if (blockedDirs[n] && blockedDirs[(n + 1) % DirExt.DIR4_COUNT]) { Dir8 diag = DirExt.AddAngles(((Dir4)n).ToDir8(), Dir8.DownLeft); if (IsBlocked(queryMethod, x, y, diag)) { blockedQuads[n] = true; } } } int tex_num = 0; if (blockedQuads[(int)Dir4.Down])//down and left are blocked { tex_num |= Convert.ToInt32("00010011", 2); } if (blockedQuads[(int)Dir4.Left])//left and up are blocked { tex_num |= Convert.ToInt32("00100110", 2); } if (blockedQuads[(int)Dir4.Up])//up and right are blocked { tex_num |= Convert.ToInt32("01001100", 2); } if (blockedQuads[(int)Dir4.Right])//right and down are blocked { tex_num |= Convert.ToInt32("10001001", 2); } return(tex_num); }
/// <summary> /// 将Method转换成sql语法的查询语句 /// </summary> /// <param name="method"></param> /// <param name="value"></param> /// <returns></returns> private string ConvertMethodToSql(QueryMethod method, object value) { switch (method) { ////字符串类型处理 case QueryMethod.Contains: return("like '%" + value + "%'"); case QueryMethod.StdIn: return("in ('" + string.Join("','", value as string[]) + "')"); case QueryMethod.NotLike: return("not like '%" + value + "%'"); ////数字类型处理 case QueryMethod.GreaterThan: return("> '" + value + "'"); case QueryMethod.GreaterThanOrEqual: return(">= '" + value + "'"); case QueryMethod.Equal: return("= '" + value + "'"); case QueryMethod.LessThan: return("< '" + value + "'"); case QueryMethod.LessThanOrEqual: return("<= '" + value + "'"); case QueryMethod.StdNotIn: return("not in ('" + string.Join("','", value as string[]) + "')"); case QueryMethod.NotEqual: return("<> '" + value + "'"); case QueryMethod.StartsWith: return("like '" + value + "%'"); case QueryMethod.EndsWith: return("like '%" + value + "'"); default: return(""); } }
public static (TimeSeriesRangeType Type, int Count) ParseCount(MethodExpression expression, string queryText, BlittableJsonReaderObject parameters = null) { TimeSeriesRangeType type; int count; switch (QueryMethod.GetMethodType(expression.Name.ToString())) { case MethodType.Last: type = TimeSeriesRangeType.Last; count = QueryMethod.TimeSeries.LastWithCount(expression, queryText, parameters); break; default: throw new InvalidQueryException($"Got invalid type {expression.Name}.", queryText, parameters); } return(type, count); }
private AuthResponse WebRequest(QueryMethod method, string url, string postData, string authheader) { HttpWebRequest webRequest = null; StreamWriter requestWriter = null; webRequest = (HttpWebRequest)System.Net.WebRequest.Create(url); webRequest.Method = method.ToString(); webRequest.Credentials = CredentialCache.DefaultCredentials; webRequest.Headers.Add("x-api-version", "2.1"); webRequest.Headers.Add("x-app-name", _appName); //Add authorization header webRequest.Headers.Add("Authorization", authheader); if (method == QueryMethod.POST) { webRequest.ContentType = "application/x-www-form-urlencoded"; //POST the data. requestWriter = new StreamWriter(webRequest.GetRequestStream()); try { requestWriter.Write(postData); } catch { throw; } finally { requestWriter.Close(); requestWriter = null; } } AuthResponse authResponse = WebResponseGet(webRequest); authResponse.Method = method; webRequest = null; return(authResponse); }
public SearchCondition Add(string field, QueryMethod method, object val, string orGroup = "", string baseOrGroup = "baseOrGroup") { //处理日期型数据 if (method == QueryMethod.LessThan || method == QueryMethod.LessThanOrEqual) { if (val.GetType() == typeof(DateTime)) { DateTime t = (DateTime)val; val = t.Date.AddHours(23).AddMinutes(59).AddSeconds(59).ToString("yyyy-MM-dd HH:mm:ss"); } } ConditionItem item = new ConditionItem(field, method, val); item.OrGroup = orGroup; item.BaseOrGroup = baseOrGroup; Items.Add(item); return(this); }
public static void ThrowIfInvalidMethodInvocationInWhere(this QueryExpression where, BlittableJsonReaderObject parameters, string queryText, string whereCollectionName = null) { if (where is MethodExpression me) { var methodType = QueryMethod.GetMethodType(me.Name.Value); switch (methodType) { case MethodType.Id: case MethodType.CompareExchange: case MethodType.Count: case MethodType.Sum: case MethodType.Spatial_Point: case MethodType.Spatial_Wkt: case MethodType.Spatial_Circle: ThrowInvalidMethod(parameters, me, queryText, whereCollectionName); break; } } }
private int Update <T>(QueryMethod method, List <T> items, string configId = null) { string tag = this.GetTag <T>(); string url = String.Format("{0}/{1}.{2}", _host, tag, _format); if (!String.IsNullOrEmpty(configId)) { url = String.Format("{0}/{1}.{2}?config_id={3}", _host, tag, _format, configId); } string data = null; if (method == QueryMethod.DELETE) { IStub <T> xstub = this.GetStub <T>(items) as IStub <T>; xstub.ToKeys(); if (_format == "xml") { data = _serializer.Serialize(xstub); data = xstub.ConvertTag(data); } else { data = _serializer.Serialize(xstub.Keys); } } else { object stub = items; if (_format == "xml") { stub = this.GetStub <T>(items); } data = _serializer.Serialize(stub); } AuthResponse authResponse = this.RunRequest(method, url, data); return(this.ProcessPostResponse <T>(authResponse)); }
/// <summary> /// 为当前表单元素添加搜索条件 /// </summary> /// <param name="str"></param> /// <param name="method">搜索方法</param> /// <param name="prefix">前缀</param> /// <param name="hasId">是否显示Id,默认false</param> /// <param name="orGroup">如果想要支援Or,请设置一个Or分组</param> /// <returns></returns> public static MvcHtmlWrapper ForSearch(this IHtmlString str, QueryMethod? method, string prefix = "", bool hasId = false, string orGroup = "") { var wrapper = MvcHtmlWrapper.Create(str); Contract.Assert(null != wrapper); if (!method.HasValue) return wrapper; var html = wrapper.HtmlString; #region 如果是CheckBox,则去掉hidden if (html.Contains("type=\"checkbox\"")) { var checkMatch = Regex.Match(html, "<input name=\"[^\"]+\" type=\"hidden\" [^>]+ />"); if (checkMatch.Success) { wrapper.Add(checkMatch.Groups[0].Value, string.Empty); } } #endregion #region 替换掉Name var match = Regex.Match(html, "name=\"(?<name>[^\"]+)\""); var strInsert = ""; if (!string.IsNullOrWhiteSpace(prefix)) { strInsert += string.Format("({0})", prefix); } if (!string.IsNullOrWhiteSpace(orGroup)) { strInsert += string.Format("{{{0}}}", orGroup); } if (match.Success) { wrapper.Add(match.Groups[0].Value, string.Format("name=\"[{1}]{2}{0}\"", match.Groups[1].Value, method, strInsert)); } #endregion return wrapper; }
private WebResponse RunRegularRequest(QueryMethod method, string url, string data) { WebRequest request = WebRequest.Create(url); request.Proxy = WebRequest.DefaultWebProxy; request.ContentType = "application/json"; request.Method = method.ToString(); if (method == QueryMethod.POST) { using (StreamWriter writter = new StreamWriter(request.GetRequestStream())) { writter.Write(data); } } HttpWebResponse response = null; try { response = (HttpWebResponse)request.GetResponse(); } catch (WebException e) { if (e.Status == WebExceptionStatus.ProtocolError) { using (HttpWebResponse exResponse = (HttpWebResponse)e.Response) { OnError(this, new ResponseErrorEventArgs(null, exResponse.StatusCode, exResponse.StatusDescription)); } } else { OnError(this, new ResponseErrorEventArgs(null, HttpStatusCode.BadRequest, e.Message)); } } return(response as WebResponse); }
/// <summary> /// Signut a web request using Auth. /// </summary> /// <param name="method">Http method GET, POST or DELETE</param> /// <param name="url">The full url, including the querystring.</param> /// <param name="postData">Data to post in xml or json fromat</param> /// <returns>The web server response.</returns> public AuthResponse AuthWebRequest(QueryMethod method, string url, string postData) { string querystring = ""; string authheader = ""; Uri uri = new Uri(url); string nonce = this.GenerateNonce(); string timeStamp = this.GenerateTimeStamp(); authheader = this.GenerateAuthorizationHeader(uri, method.ToString(), timeStamp, nonce); querystring = this.GenerateQueryString(uri, method.ToString(), timeStamp, nonce); AuthResponse authResponse = WebRequest(method, querystring, postData, authheader); return authResponse; }
private AuthResponse WebRequest(QueryMethod method, string url, string postData, string authheader) { HttpWebRequest webRequest = null; StreamWriter requestWriter = null; webRequest = (HttpWebRequest)System.Net.WebRequest.Create(url); webRequest.Method = method.ToString(); webRequest.Credentials = CredentialCache.DefaultCredentials; webRequest.Headers.Add("x-app-name", _appName); webRequest.Headers.Add("x-api-version", "4.0"); webRequest.Headers.Add("Authorization", authheader); if (_useCompression == true) { webRequest.Headers.Add("Accept-Encoding", "gzip,deflate"); webRequest.AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate; } if (method == QueryMethod.POST || method == QueryMethod.PUT || method == QueryMethod.DELETE) { webRequest.ContentType = "application/x-www-form-urlencoded"; //Write the data. requestWriter = new StreamWriter(webRequest.GetRequestStream()); try { requestWriter.Write(postData); } catch { throw; } finally { requestWriter.Close(); requestWriter = null; } } AuthResponse authResponse = WebResponseGet(webRequest); authResponse.Method = method; webRequest = null; return authResponse; }
/// <summary> /// Initializes a new instance of the <see cref="ConditionItem" /> class. /// </summary> /// <param name="field">The field.</param> /// <param name="method">The method.</param> /// <param name="val">The value.</param> public ConditionItem(string field, QueryMethod method, object val) { this.Field = field; this.Method = method; this.Value = val; }
public ConditionItem(string field, QueryMethod method, object val) { Field = field; Method = method; Value = val; }
/// <summary> /// Adds the specified field. /// </summary> /// <param name="field">The field.</param> /// <param name="method">The method.</param> /// <param name="val">The value.</param> /// <returns>SearchCondition.</returns> public SearchCondition Add(string field, QueryMethod method, object val) { ConditionItem item = new ConditionItem(field, method, val); this.Items.Add(item); return this; }
private AuthResponse WebRequest(QueryMethod method, string url, string postData, string authheader) { HttpWebRequest webRequest = null; StreamWriter requestWriter = null; webRequest = (HttpWebRequest)System.Net.WebRequest.Create(url); webRequest.Method = method.ToString(); webRequest.Credentials = CredentialCache.DefaultCredentials; webRequest.Headers.Add("x-api-version", "2.1"); webRequest.Headers.Add("x-app-name", _appName); //Add authorization header webRequest.Headers.Add("Authorization", authheader); if (method == QueryMethod.POST) { webRequest.ContentType = "application/x-www-form-urlencoded"; //POST the data. requestWriter = new StreamWriter(webRequest.GetRequestStream()); try { requestWriter.Write(postData); } catch { throw; } finally { requestWriter.Close(); requestWriter = null; } } AuthResponse authResponse = WebResponseGet(webRequest); authResponse.Method = method; webRequest = null; return authResponse; }
/// <summary> /// Construct a generic web query for genealogical records /// </summary> /// <param name="browser"><see cref="WebBrowser"/> control to display results in</param> /// <param name="queryMethod">HTML method (e.g. GET, POST) to invoke</param> protected WebQuery(WebBrowser browser, QueryMethod queryMethod) { _WebBrowser = browser; _QueryMethod = queryMethod; }
private AuthResponse ExecuteRequest(QueryMethod method, string url, string data) { string appName = this.GetAppName(); AuthRequest authRequest = new AuthRequest(_consumerKey, _consumerSecret, appName, _useCompression, _apiVersion); using (authRequest) { OnRequest(this, new RequestEventArgs(method.ToString(), url, data)); AuthResponse authResponse = authRequest.AuthWebRequest(method, url, data); OnResponse(this, new ResponseEventArgs(authResponse.Status, authResponse.Data)); return authResponse; } }
private dynamic Update(QueryMethod method, dynamic items, string tag, string configId = null) { string url = String.Format("{0}/{1}.{2}", _host, tag, _format); if (!String.IsNullOrEmpty(configId)) { url = String.Format("{0}/{1}.{2}?config_id={3}", _host, tag, _format, configId); } string data = null; data = _serializer.Serialize(items); AuthResponse authResponse = this.RunRequest(method, url, data); dynamic obj = this.ProcessGetResponse(authResponse); return obj; }
private AuthResponse RunRequest(QueryMethod method, string url, string data) { if (string.IsNullOrEmpty(_consumerKey) && string.IsNullOrEmpty(_consumerSecret)) { string sessionId = ReadSessionFile(); if (!string.IsNullOrEmpty(sessionId) && ReUseSession) { if (!ValidateSession(sessionId)) { if (!GetTemporaryKeys()) { return null; } } } else { if (!GetTemporaryKeys()) { return null; } } } return ExecuteRequest(method, url, data); }
private WebResponse RunRegularRequest(QueryMethod method, string url, string data) { WebRequest request = WebRequest.Create(url); request.Proxy = WebRequest.DefaultWebProxy; request.ContentType = "application/json"; request.Method = method.ToString(); if (method == QueryMethod.POST) { using (StreamWriter writter = new StreamWriter(request.GetRequestStream())) { writter.Write(data); } } HttpWebResponse response = null; try { response = (HttpWebResponse)request.GetResponse(); } catch (WebException e) { if (e.Status == WebExceptionStatus.ProtocolError) { using (HttpWebResponse exResponse = (HttpWebResponse)e.Response) { OnError(this, new ResponseErrorEventArgs(null, exResponse.StatusCode, exResponse.StatusDescription)); } } else { OnError(this, new ResponseErrorEventArgs(null, HttpStatusCode.BadRequest, e.Message)); } } return response as WebResponse; }