public void Init(IntPtr hInst, IntPtr mainHWND, APIType type, bool saveLog) { if (!MainInitialize) { string graphicsAPI = null; switch (type) { case APIType.DirectX9: graphicsAPI = "ACD3DEngine.dll"; break; case APIType.Direct3D10: graphicsAPI = "ACD3DEngine.dll"; break; case APIType.Direct3D11: graphicsAPI = "ACD3DEngine.dll"; break; case APIType.OpenGl2: graphicsAPI = "OpenGl2Engine.dll"; break; case APIType.OpenGl3: graphicsAPI = "OpenGl3Engine.dll"; break; case APIType.OpenGl4: graphicsAPI = "OpenGl4Engine.dll"; break; default: throw new Exception("Graphics API not supported."); } /* IntPtr hresult = __InitializeGraphicsDevice(hInst, graphicsAPI, mainHWND, saveLog); if (hresult.ToInt32() != 0) throw new Exception("Error on graphics device initializer."); MainInitialize = true; hWndList.Add(mainHWND);*/ } }
public UserSession(String apiKey, APIType apiType) { if (String.IsNullOrEmpty(apiKey)) { throw new ArgumentNullException("apiKey"); } APIKey = apiKey; APIType = apiType; }
protected MonitisAPIBase(String apiKey, APIType apiType, String requestUrl) { Validation.EmptyOrNull(apiKey, "apiKey"); Validation.EmptyOrNull(requestUrl, "requestUrl"); APIKey = apiKey; APIType = apiType; RequestUrl = requestUrl; }
protected Dictionary<string, string> GetTwitterAPIParams(APIType APICall, string tweetTarget) { Dictionary<string, string> tweetParams = new Dictionary<string, string>(); //Default Count tweetParams.Add(TweetAPIConstants.APICountString, TweetAPIConstants.APICountKey.ToString()); //Get URL appropriate for request needs and Get appropriate parameters switch (APICall) { case APIType.Home: tweetParams.Add(TweetAPIConstants.APIEntityIncludeString, "false"); //tweetParams.Add("since_id=", "1"); tweetParams.Remove(TweetAPIConstants.APICountString); tweetParams.Add(TweetAPIConstants.APICountString, "500"); break; case APIType.User: tweetParams.Add(TweetAPIConstants.APIEntityIncludeString, "false"); tweetParams.Add(TweetAPIConstants.APIScreenNameString, tweetTarget); break; case APIType.Search: tweetParams.Add(TweetAPIConstants.APIEntityIncludeString, "false"); tweetParams.Add(TweetAPIConstants.APISearchQueryString, tweetTarget); tweetParams.Add(TweetAPIConstants.APISearchResultTypeString, "mixed"); break; case APIType.Trend: if (tweetTarget == null) { tweetParams.Add(TweetAPIConstants.APITrendLocationWOEIDString, TweetAPIConstants.APITrendLocationWOEID); } else { tweetParams.Add(TweetAPIConstants.APITrendLocationWOEIDString, tweetTarget); } tweetParams.Remove(TweetAPIConstants.APICountString); break; case APIType.Follower: tweetParams.Add(TweetAPIConstants.APIEntityIncludeString, "false"); tweetParams.Add(TweetAPIConstants.APIScreenNameString, tweetTarget); tweetParams.Remove(TweetAPIConstants.APICountString); break; case APIType.UserInfo: tweetParams.Add(TweetAPIConstants.APIScreenNameString, tweetTarget); tweetParams.Add(TweetAPIConstants.APIEntityIncludeString, "false"); break; default: throw new ArgumentNullException("APIType", "API Call Type Required; Invalid or Null APIType passed"); } return tweetParams; }
protected string GetTwitterAPIUrl(APIType APICall) { string tweetUrl; //Get URL appropriate for request needs and Get appropriate parameters switch (APICall) { case APIType.Home: tweetUrl = TweetAPIConstants.HomeTimeLine; break; case APIType.User: tweetUrl = TweetAPIConstants.UserTimeLine; break; case APIType.Search: tweetUrl = TweetAPIConstants.TweetSearch; break; case APIType.Trend: tweetUrl = TweetAPIConstants.TrendSearch; break; case APIType.Follower: tweetUrl = TweetAPIConstants.UserFollowers; break; case APIType.UserInfo: tweetUrl = TweetAPIConstants.MultiUserLookup; break; default: throw new ArgumentNullException("APIType", "API Call Type Required; Invalid or Null APIType passed"); } return(tweetUrl); }
public string GetRedirectAddress(string function, APIType api, string pid) { pid = pid.Replace('_', ':'); string fednamespace = GetPrefixFromPid(pid); FederateRecord fr = mFederateRegister.GetFederateRecord(fednamespace); if (fr == null) { throw new System.Net.WebException("The prefix for this model is not recognized by the federation"); } if (fr.ActivationState == FederateState.Unapproved) { throw new System.Net.WebException("The account for this namespace is waiting to be approved. Please visit <a href=\"" + fr.OrganizationURL + "\">" + fr.OrganizationURL + "</a> for more information."); } if (fr.AllowFederatedSearch != true) { throw new System.Net.WebException("The account for this namespace is does not allow searching or downloading metadata through the federation. Please visit <a href=\"" + fr.OrganizationURL + "\">" + fr.OrganizationURL + "</a> for more information."); } if (fr.ActivationState == FederateState.Active && fr.AllowFederatedSearch == true) { string apibase = ""; if (api == APIType.REST) { apibase = fr.RESTAPI; } return(apibase + "/" + pid + "/" + function); } else { return(fr.OrganizationURL); } }
private async Task CheckAPI(APIType type) { APICheckResult result = new(); try { result.APIName = GetAPIName(type); (bool, string)testResult = type switch { APIType.RealTimeNote => await TestAPIService.TestRealTimeNoteAPI(Uid, Ltuid, Ltoken), APIType.RealTimeNoteSetting => await TestAPIService.TestRealTimeNoteSettingAPI(Ltuid, Ltoken), APIType.WishLog => await TestAPIService.TestWishLogAPI(AuthKey), _ => (false, string.Empty) }; result.IsPass = testResult.Item1; result.ResultDetail = testResult.Item2; } catch (Exception ex) { StringBuilder sb = new(); sb.AppendLine("API test function terminate :("); sb.AppendLine(""); sb.Append(ex.ToString()); result.ResultDetail = sb.ToString(); result.IsPass = false; } finally { await Task.Delay(1000); } ResultList.Add(result); }
/// <summary> /// Invia la richiesta all'URL API /// </summary> /// <param name="APIType">Tipologia di API da richiamare <see cref="APIType"/></param> /// <param name="APIMetodo">Metodo da richiamare</param> /// <param name="kvpList">Elenco dei parametri da passare al provider come parametri;</param> /// <returns>Restituisce una stringa in formato json</returns> private static string SendRequest(FidelitySettingsPart setPart, APIType APIType, string APIMetodo, List <KeyValuePair <string, string> > kvpList) { string responseString = string.Empty; try { using (var client = new HttpClient()) { // client.BaseAddress = new Uri(setPart.ApiURL + APIType.ToString() + "/" + setPart.DeveloperKey + "/" + APIMetodo); Uri address = new Uri(setPart.ApiURL + APIType.ToString() + "/" + setPart.DeveloperKey + "/" + APIMetodo); var content = new FormUrlEncodedContent(kvpList); HttpResponseMessage result = client.PostAsync(address, content).Result; if (result.StatusCode == HttpStatusCode.OK) { responseString = result.Content.ReadAsStringAsync().Result; if (responseString.Contains("\"success\":false")) { throw new Exception(responseString); } //TODO vedere se ha senso mantenere il lancio dell'eccezione qui e tutti i controlli sui metodi dopo } else if (result.StatusCode == HttpStatusCode.NotFound) { throw new Exception("Direttiva non valida"); } else { throw new Exception(result.Content.ReadAsStringAsync().Result); } } } catch (Exception ex) { throw ex; } return(responseString); }
/// <summary> /// A method that saves data after a provided request to API /// </summary> /// <param name="data">Data which sended to API server</param> /// <param name="type">Api type which would parsed to get correct url</param> /// <example> /// The sample code to get data from Vkursi's API /// <code> /// APIService api = APIService.getInstance(); /// api.GetData(new string[] { "00131305", "40073472" }, ApiType.GetOrganizationInfo); /// </code> /// </example> /// <returns> /// Return true if response with status OK and data saved, otherwise - false /// </returns> public async Task <object> GetData(object data, APIType type) { var response = (type != APIType.GetChanges ? await Helper.RequestForData(Helper.MakeJson(data), _baseUrl + type.DisplayName(), _bearer) : await Helper.RequestForData(null, _baseUrl + type.DisplayName() + "/" + ((string[])data)[0], _bearer)); if (string.IsNullOrWhiteSpace(response)) { return(null); } object result; if (type != APIType.GetChanges) { result = ((JArray)Helper.ParseJson(response)).ToObject <CompanyModel[]>(); } else { result = ((JArray)Helper.ParseJson(response)).ToObject <CompanyChanges[]>(); } return(result); }
public static void Create(DataBase db, string dir, APIType apiType) { CreateEnums(db, dir, apiType); CreateClasses(db, dir, apiType); }
/// <summary> /// Constructor with arguments /// </summary> public DoCancelRequestType(string cancelMsgSubID, APIType? aPIType) { this.CancelMsgSubID = cancelMsgSubID; this.APIType = aPIType; }
public string GetRedirectAddress(string function, APIType api, string pid) { pid = pid.Replace('_', ':'); string fednamespace = GetPrefixFromPid(pid); FederateRecord fr = mFederateRegister.GetFederateRecord(fednamespace); if (fr == null) throw new System.Net.WebException("The prefix for this model is not recognized by the federation"); if (fr.ActivationState == FederateState.Unapproved) { throw new System.Net.WebException("The account for this namespace is waiting to be approved. Please visit <a href=\"" + fr.OrganizationURL + "\">" + fr.OrganizationURL + "</a> for more information."); } if (fr.AllowFederatedSearch != true) { throw new System.Net.WebException("The account for this namespace is does not allow searching or downloading metadata through the federation. Please visit <a href=\"" + fr.OrganizationURL + "\">" + fr.OrganizationURL + "</a> for more information."); } if (fr.ActivationState == FederateState.Active && fr.AllowFederatedSearch == true) { string apibase = ""; if (api == APIType.REST) apibase = fr.RESTAPI; return apibase + "/" + pid + "/" + function ; } else { return fr.OrganizationURL; } }
internal GhostAPI(string host, string key, ExceptionLevel exceptionLevel, string baseUrl, APIType apiType) : this(host, exceptionLevel, baseUrl, apiType) { this.key = key; }
/// <summary> /// API client constructor /// </summary> /// <param name="apiType">Sandbox or live</param> /// <param name="apiKey">API key</param> /// <param name="requestUrl">Url of destination API</param> /// <param name="action">Action of API which need to call</param> /// <param name="authToken">Auth token for security request to API</param> public APIClient(APIType apiType, String apiKey, String requestUrl, String action, String authToken) : this(apiType, apiKey, requestUrl, action) { _authToken = authToken; }
private void UpdateCheckingStatusText(APIType type) { BusyStatusLabel.Text = $"{AppResources.APICheck_Status_Checking}({GetAPIName(type)})"; }
/// <summary> /// 设置调用参数并调用API /// </summary> /// <param name="paramsTable"></param> /// <returns></returns> public static string InvokeAPI(TopDictionary paramsTable, APIInvokeType invokeType) { #region 获取SessionKey string url = string.Empty; APIType apiType = APIType.Real; if (apiType == APIType.Real) { url = Constants.TOP_API_URL; } else { url = Constants.TOP_SANDBOX_API_URL; } #endregion #region 设置API调用系统级参数 string resBody = string.Empty; Dictionary <string, string> req_params = new Dictionary <string, string>(); req_params.Add("format", "json"); req_params.Add("timestamp", DateTime.Now.ToString(Constants.DATE_TIME_FORMAT)); req_params.Add("app_key", Constants.APP_KEY); req_params.Add("sign_method", "md5"); req_params.Add("v", "2.0"); #endregion #region 添加调用方法和参数 IDictionaryEnumerator enumerator = paramsTable.GetEnumerator(); while (enumerator.MoveNext()) { req_params.Add(enumerator.Key.ToString(), enumerator.Value.ToString()); } #endregion #region 方法签名 string sign = EncryptUtil.Signature(req_params, Constants.APP_SECRET); req_params.Add("sign", sign); #endregion #region 判定调用图片API或者普通API TopJsonRestClient client = new TopJsonRestClient(); string apiname = req_params.Where(m => m.Key == "method").First().Value; if (apiname == "taobao.item.img.upload" || apiname == "taobao.item.propimg.upload") { Byte[] picBytes = paramsTable.PictureBytes; resBody = client.InvokUpImageAPI(picBytes, req_params, url); } else { resBody = client.InvokeAPI(req_params, url); } #endregion #region API异常处理 if (resBody.Contains("error_response") || resBody.Contains("error_rsp")) { if (resBody.Contains("?xml")) { return(string.Empty); } int startIndex = resBody.IndexOf(":") + 1; /*截掉首尾的{},截取长度修改为resBody.LastIndexOf('}') - startIndex,不用resBody.Length,有可能统计不准*/ int length = resBody.LastIndexOf('}') - startIndex; resBody = resBody.Substring(startIndex, length); TopException exception = DeserializeObject <TopException>(resBody); throw new Exception(string.Format("错误代码:{0},错误信息:{1},错误子代码:{2},错误子信息:{3}", exception.Code, exception.Msg, exception.SubCode, exception.SubMsg)); } #endregion #region 获得API调用结果 if (!string.IsNullOrEmpty(resBody)) { int startIndex = resBody.IndexOf(":") + 1; /*截掉首尾的{},截取长度修改为resBody.LastIndexOf('}') - startIndex,不用resBody.Length,有可能统计不准*/ resBody = resBody.Substring(startIndex, resBody.LastIndexOf('}') - startIndex); } #endregion return(resBody); }
/// <summary> /// 获取预授权码。 /// 先从本地缓存获取,没有则从微信端获取。 /// </summary> /// <param name="manager"></param> /// <param name="suiteId"></param> /// <param name="appIds"></param> /// <param name="suiteAccessToken"></param> /// <returns></returns> public static string GetPreAuthCode(this TokenManager manager, string suiteId, IList <int> appIds, string suiteAccessToken, out string errMessage, APIType type) { errMessage = string.Empty; string cacheKey = string.Empty; appIds = appIds == null ? new List <int>() : appIds; if (appIds == null || appIds.Count() == 0) { cacheKey = string.Format("PREAUTHCODE:{0}:{1}:{2}:all", suiteId, suiteAccessToken, type); } else { cacheKey = string.Format("PREAUTHCODE:{0}:{1}:{2}:{3}", suiteId, suiteAccessToken, type, string.Join("-", appIds.OrderBy(p => p))); } string pre_auth_code = CacheManager.Instance().Get <string>(cacheKey); if (!string.IsNullOrEmpty(pre_auth_code)) { return(pre_auth_code); } var request = new GetPreAuthCodeReqeust(); request.suite_id = suiteId; request.appid = appIds.ToList(); var result = APIHelper.Instance().Qy().GetPreAuthCode(request, suiteAccessToken); if (result.errcode != 0) { errMessage = string.Format("GetPreAuthCode: errcode:{0},errmsg:{1}", result.errcode, result.errmsg); return(pre_auth_code); } //缓存pre_auth_code pre_auth_code = result.pre_auth_code; CacheManager.Instance().Set(cacheKey, pre_auth_code, result.expires_in); return(pre_auth_code); }
/// <summary> /// /// </summary> /// <param name="manager"></param> /// <param name="suiteId"></param> /// <param name="appIds"></param> /// <param name="suiteAccessToken"></param> /// <returns></returns> public static string GetPreAuthCode(this TokenManager manager, string suiteId, IList <int> appIds, string suiteAccessToken, APIType type) { string errMessage; return(manager.GetPreAuthCode(suiteId, appIds, suiteAccessToken, out errMessage, type)); }
/// <summary> /// 获取应用套件令牌。 /// 先从本地缓存获取,没有则从微信端获取。 /// </summary> /// <param name="manager"></param> /// <param name="suiteId"></param> /// <param name="suiteSecret"></param> /// <param name="suiteTicket"></param> /// <returns></returns> public static string GetSuiteToken(this TokenManager manager, string suiteId, string suiteSecret, string suiteTicket, out string errMessage, APIType type) { errMessage = string.Empty; string cacheKey = string.Format("SUITETOKEN:{0}:{1}:{2}:{3}", suiteId, suiteSecret, suiteTicket, type); string suite_access_token = CacheManager.Instance().Get <string>(cacheKey); if (!string.IsNullOrEmpty(suite_access_token)) { return(suite_access_token); } var request = new GetSuiteTokenRequest(); request.suite_id = suiteId; request.suite_secret = suiteSecret; request.suite_ticket = suiteTicket; var result = APIHelper.Instance().Qy().GetSuiteToken(request); if (result.errcode != 0) { errMessage = string.Format("GetSuiteToken: errcode:{0},errmsg:{1}", result.errcode, result.errmsg); return(suite_access_token); } //缓存suite_access_token suite_access_token = result.suite_access_token; CacheManager.Instance().Set(cacheKey, suite_access_token, result.expires_in); return(suite_access_token); }
/// <summary> /// /// </summary> /// <param name="manager"></param> /// <param name="suiteId"></param> /// <param name="suiteSecret"></param> /// <param name="suiteTicket"></param> /// <returns></returns> public static string GetSuiteToken(this TokenManager manager, string suiteId, string suiteSecret, string suiteTicket, APIType type) { string errMessage; return(manager.GetSuiteToken(suiteId, suiteSecret, suiteTicket, out errMessage, type)); }
/// <summary> /// 获取企业号access_token。 /// 先从本地缓存获取,没有则从微信端获取。 /// </summary> /// <param name="manager"></param> /// <param name="suiteId"></param> /// <param name="authCorpId">授权的企业号ID</param> /// <param name="permanentCode">永久授权码</param> /// <param name="suiteAccessToken"></param> /// <returns></returns> public static string GetCorpToken(this TokenManager manager, string suiteId, string authCorpId, string permanentCode, string suiteAccessToken, out string errMessage, APIType type) { errMessage = string.Empty; string cacheKey = string.Format("CORPTOKEN:{0}:{1}:{2}:{3}", suiteId, authCorpId, suiteAccessToken, type); string access_token = CacheManager.Instance().Get <string>(cacheKey); if (!string.IsNullOrEmpty(access_token)) { return(access_token); } var request = new GetCorpTokenRequest(); request.suite_id = suiteId; request.auth_corpid = authCorpId; request.permanent_code = permanentCode; var result = APIHelper.Instance().Qy(type).GetCorpToken(request, suiteAccessToken); if (result.errcode != 0) { errMessage = string.Format("GetCorpToken: errcode:{0},errmsg:{1}", result.errcode, result.errmsg); return(access_token); } //缓存corp_token access_token = result.access_token; CacheManager.Instance().Set(cacheKey, access_token, result.expires_in); return(access_token); }
/// <summary> /// /// </summary> /// <param name="manager"></param> /// <param name="suiteId"></param> /// <param name="authCorpId"></param> /// <param name="permanentCode"></param> /// <param name="suiteAccessToken"></param> /// <returns></returns> public static string GetCorpToken(this TokenManager manager, string suiteId, string authCorpId, string permanentCode, string suiteAccessToken, APIType type) { string errMessage; return(manager.GetCorpToken(suiteId, authCorpId, permanentCode, suiteAccessToken, out errMessage, type)); }
public IAPI Create(APIType type) { throw new NotImplementedException(); }
protected string GetTwitterAPIUrl(APIType APICall) { string tweetUrl; //Get URL appropriate for request needs and Get appropriate parameters switch (APICall) { case APIType.Home: tweetUrl = TweetAPIConstants.HomeTimeLine; break; case APIType.User: tweetUrl = TweetAPIConstants.UserTimeLine; break; case APIType.Search: tweetUrl = TweetAPIConstants.TweetSearch; break; case APIType.Trend: tweetUrl = TweetAPIConstants.TrendSearch; break; case APIType.Follower: tweetUrl = TweetAPIConstants.UserFollowers; break; case APIType.UserInfo: tweetUrl = TweetAPIConstants.MultiUserLookup; break; default: throw new ArgumentNullException("APIType", "API Call Type Required; Invalid or Null APIType passed"); } return tweetUrl; }
public APIManager(APIType type) { Type = type; }
/** * Constructor with arguments */ public DoCancelRequestType(string CancelMsgSubID, APIType? APIType) { this.CancelMsgSubID = CancelMsgSubID; this.APIType = APIType; }
protected override void OnMessage(MessageEventArgs e) { MESStationReturn StationReturn = null; // new MESStationReturn(); string[] Para = null; //add by LLF 2017-1-4 try { //處理JSON //Newtonsoft.Json.Linq.JObject Request = (Newtonsoft.Json.Linq.JObject) Newtonsoft.Json.JsonConvert.DeserializeObject( //"{ TOKEN:null, CLASS: \"MESStation.ApiHelper\", FUNCTION:\"GetApiClassList\", DATA:{ } }"); //Request = (Newtonsoft.Json.Linq.JObject)Newtonsoft.Json.JsonConvert.DeserializeObject("{ TOKEN:null, CLASS: \"MESStation.ApiHelper\", FUNCTION:\"GetApiFunctionsList\", DATA:{ CLASSNAME:\"MESStation.ApiHelper\" } }"); //Request = (Newtonsoft.Json.Linq.JObject)Newtonsoft.Json.JsonConvert.DeserializeObject( // "{ TOKEN:null, CLASS: \"MESStation.ApiHelper\", FUNCTION:\"GetApiFunctionsList\", DATA:{ CLASSNAME:\"MESStation.UserManager\" } }"); Newtonsoft.Json.Linq.JObject Request = (Newtonsoft.Json.Linq.JObject)Newtonsoft.Json.JsonConvert.DeserializeObject(e.Data); string CLASS = Request["Class"].ToString(); string FUNCTION = Request["Function"].ToString(); string TOKEN = Request["Token"].ToString(); string MsgID = Request["MessageID"]?.ToString(); string ClientID = Request["ClientID"]?.ToString(); Request.Add("IP", Newtonsoft.Json.Linq.JToken.Parse("{Value:\"" + this.ClientIP + "\"}")); StationReturn = new MESStationReturn(MsgID, ClientID); //反射加載 //ApiHelper api = new ApiHelper(); Type APIType; //加載類庫 Assembly assembly = Assembly.Load("MESStation"); APIType = assembly.GetType(CLASS); object API_CLASS = assembly.CreateInstance(CLASS); MesAPIBase API = (MesAPIBase)API_CLASS; if (!API.DBPools.ContainsKey("SFCDB")) { API.DBPools.Add("SFCDB", SFCDBPool); } if (!API.DBPools.ContainsKey("APDB")) { API.DBPools.Add("APDB", APDBPool); } //API.BU = "HWD"; //API.BU = "VERTIV"; ((MesAPIBase)API_CLASS).IP = this.ClientIP; API.Language = "CHINESE"; //CHINESE,CHINESE_TW,ENGLISH; //初始化異常類型的數據庫連接池 MESReturnMessage.SetSFCDBPool(SFCDBPool); //獲取調用函數 MethodInfo Function = APIType.GetMethod(FUNCTION); // bool CheckLogin = false; if (LoginUsers.ContainsKey(TOKEN)) { User lu = LoginUsers[TOKEN]; ((MesAPIBase)API_CLASS).LoginUser = lu; CheckLogin = true; API.BU = lu.BU; } else { if (FUNCTION != "Login" && ((MesAPIBase)API_CLASS).MastLogin) { StationReturn.Status = StationReturnStatusValue.Fail; StationReturn.Message = "No Login !"; } else { if (FUNCTION == "Login") { CheckLogin = true; } } } if (CheckLogin) { Function.Invoke(API_CLASS, new object[] { Request, Request["Data"], StationReturn }); if (FUNCTION == "Login") { if (StationReturn.Status == "Pass") { LoginReturn r = (LoginReturn)StationReturn.Data; User lu = ((MesAPIBase)API_CLASS).LoginUser; if (this.Token != null) { Report.LoginUsers.Remove(Token); MESStation.Stations.CallStation.logout(Token); } string NewToken = r.Token; Token = r.Token; if (LoginUsers.ContainsKey(NewToken)) { LoginUsers[NewToken] = lu; } else { LoginUsers.Add(NewToken, lu); } } } }//函數不要求登錄 else if (!((MesAPIBase)API_CLASS).MastLogin) { Function.Invoke(API_CLASS, new object[] { Request, Request["Data"], StationReturn }); if (FUNCTION == "Login") { if (StationReturn.Status == "Pass") { LoginReturn r = (LoginReturn)StationReturn.Data; User lu = ((MesAPIBase)API_CLASS).LoginUser; string NewToken = r.Token; if (LoginUsers.ContainsKey(NewToken)) { LoginUsers[NewToken] = lu; } else { LoginUsers.Add(NewToken, lu); } } } } //add by LLF 2017-12-27 if (StationReturn.MessageCode != null) { if (StationReturn.MessageCode.Length > 0) { if (StationReturn.MessagePara != null) { if (StationReturn.MessagePara.Count > 0) { Para = new string[StationReturn.MessagePara.Count]; for (int i = 0; i < StationReturn.MessagePara.Count; i++) { Para[i] = StationReturn.MessagePara[i].ToString(); } } } StationReturn.Message = MESReturnMessage.GetMESReturnMessage(StationReturn.MessageCode, Para); } } } catch (MESReturnMessage ee) { StationReturn.Status = StationReturnStatusValue.Fail; StationReturn.Message = ee.Message; if (ee.InnerException != null) { StationReturn.Data = ee.InnerException.Message; } } catch (Exception ee) { StationReturn.Status = StationReturnStatusValue.Fail; StationReturn.Message = ee.Message; if (ee.InnerException != null) { StationReturn.Data = ee.InnerException.Message; } } System.Web.Script.Serialization.JavaScriptSerializer JsonMaker = new System.Web.Script.Serialization.JavaScriptSerializer(); JsonMaker.MaxJsonLength = int.MaxValue; string json = JsonMaker.Serialize(StationReturn); //JavaScriptSerializer 實例在序列化對象的時候,遇到 DateTime 類型會序列化出不可讀的數據, //因此改用 Newtonsoft 的 JsonConvert 來進行序列化,序列化出來的 DateTime 形如 2017-12-06T11:14:37 //另外如果遇到無法將 System.DBNull 類型轉換成 string 類型的,可以手動檢測下值的類型, //如果是 System.DBNull,直接將值改為 null 即可。 //實在無法實現你所需要的功能,可將下面這句註釋掉。 // // modify by 張官軍 2017/12/06 //變更時間格式 modify by Wuq 2018/01/25 json = Newtonsoft.Json.JsonConvert.SerializeObject(StationReturn, Newtonsoft.Json.Formatting.Indented, new Newtonsoft.Json.Converters.IsoDateTimeConverter { DateTimeFormat = "yyyy-MM-dd HH:mm:ss" }); //json = Newtonsoft.Json.JsonConvert.SerializeObject(StationReturn); Send(json); }
public APIComboBoxItem(APIType apiType, string content) { APIType = apiType; Content = content; }
public CustomMonitorAPI(string apiKey, APIType apiType) : base(apiKey, apiType, APIResources.CustomMonitorsAPIPath) { }
public UserAPI(String apiKey, APIType apiType) : base(apiKey, apiType, APIResources.UserAPIPath) { }
private void InitializeSearchParams() { _searchParams = PHINVADSDevice.GetSearchParamInstanceForResource(_program.Plan, _fhirTableNode.ResourceType); _directParams = new Dictionary <String, Object>(); // Ignoring the search params on the plan for now, create search params for this execution here var restrictNode = _fhirTableNode.Node as RestrictNode; if (restrictNode != null) { _apiType = APIType.Find; // TODO: Generalize the stack offset here, this is safe because we know the only scenario we support is restriction of a base table var _program.Stack.Push(null); try { if (restrictNode.IsSeekable) { // Verify that there is only one condition and that it corresponds to a known search parameter for this resource foreach (ColumnConditions columnConditions in restrictNode.Conditions) { // A seekable condition will only have one column condition var searchParamName = GetSearchParamName(columnConditions.Column); var searchValue = GetSearchParamValue(columnConditions[0]); if (IsDirectSearch(columnConditions.Column.Name)) { _apiType = APIType.Direct; } SetSearchParam(searchParamName, searchValue); } } else if (restrictNode.IsScanable) { foreach (ColumnConditions columnConditions in restrictNode.Conditions) { // A scanable condition will always have equality as its instruction foreach (ColumnCondition condition in columnConditions) { var searchParamName = GetSearchParamName(columnConditions.Column); var searchValue = GetSearchParamValue(condition); if (IsDirectSearch(columnConditions.Column.Name)) { _apiType = APIType.Direct; } SetSearchParam(searchParamName, searchValue); } } } else { var searchParamNode = restrictNode.Nodes[1] as SatisfiesSearchParamNode; if (searchParamNode != null) { var columnName = (string)searchParamNode.Nodes[1].Execute(_program); var searchParamName = GetSearchParamName(columnName); var searchValue = (string)searchParamNode.Nodes[2].Execute(_program); if (IsDirectSearch(columnName)) { _apiType = APIType.Direct; } SetSearchParam(searchParamName, searchValue); } } } finally { _program.Stack.Pop(); } } }
internal GhostAPI(string host, ExceptionLevel exceptionLevel, string baseUrl, APIType apiType) { this.apiType = apiType; Client = new RestClient { BaseUrl = new Uri(new Uri(host), baseUrl) }; ExceptionLevel = exceptionLevel; }
public ControllerAttribute(String path, APIType type, String contentType) { this.path = path; this.type = type; this.contentType = contentType; }
public string GetRedirectAddressModelAdvanced(APIType api, string pid, string format, string options) { string fednamespace = GetPrefixFromPid(pid); FederateRecord fr = mFederateRegister.GetFederateRecord(fednamespace); if(fr == null) throw new System.Net.WebException("The prefix for this model is not recognized by the federation"); if (fr.ActivationState == FederateState.Unapproved) { throw new System.Net.WebException("The account for this namespace is waiting to be approved. Please visit <a href=\""+fr.OrganizationURL+"\">" +fr.OrganizationURL+"</a> for more information."); } if (fr.AllowFederatedDownload != true) { throw new System.Net.WebException("The account for this namespace is does not allow downloading through the federation. Please visit <a href=\"" + fr.OrganizationURL + "\">" + fr.OrganizationURL + "</a> for more information."); } if (fr.ActivationState == FederateState.Active && fr.AllowFederatedDownload == true) { string apibase = ""; if (api == APIType.REST) apibase = fr.RESTAPI; return apibase + "/"+ pid + "/Model/" + format + "/" + options; } //"should never reach here" return fr.OrganizationURL; }
public OverwatchClient(APIType apiType = APIType.Stats, Platform platform = Platform.PC, OverwatchRegion region = OverwatchRegion.EU) { Region = region; Platform = platform; APIType = apiType; string platformID; switch (Platform) { case Platform.PC: platformID = $@"pc"; break; case Platform.XBOX: platformID = $@"xbl"; break; case Platform.PS4: platformID = $@"psn"; break; default: platformID = $@"pc"; break; } string regionID; switch (Region) { case OverwatchRegion.EU: regionID = $@"eu"; break; case OverwatchRegion.KR: regionID = $@"kr"; break; case OverwatchRegion.US: regionID = $@"us"; break; default: regionID = $@"eu"; break; } if (APIType == APIType.Stats) { if (Platform == Platform.PC) { API_URL = $@"https://ovrstat.com/stats/pc/{regionID}/"; } else { API_URL = $@"https://ovrstat.com/stats/{platformID}/"; } } else if (APIType == APIType.Information) { API_URL = $@"https://overwatch-api.tekrop.fr/"; } API = new Overwatch(this, API_URL, regionID, platformID, User_Agent); }
public static void CreateClasses(DataBase db, string dir, APIType apiType) { foreach (var ct in db.Classes) { string filePath = Path.Combine(dir, $"{ct.ClassName}.cs"); if (File.Exists(filePath)) { throw new Exception($"File {filePath} already exists"); } using (StreamWriter writer = File.CreateText(filePath)) { writer.WriteLine("using JenkinsWebApi.Internal;"); switch (apiType) { case APIType.XML: writer.WriteLine("using System.Xml.Serialization;"); break; case APIType.JSON: writer.WriteLine("using System.Text.Json.Serialization;"); break; } writer.WriteLine(); writer.WriteLine("#pragma warning disable CS1591"); // disable warnings for no commented items writer.WriteLine(); writer.WriteLine("namespace JenkinsWebApi.Model"); writer.WriteLine("{"); writer.WriteLine($" [SerializableClass(\"{ct.Name}\")]"); if (apiType == APIType.XML && !string.IsNullOrEmpty(ct.Root)) { writer.WriteLine($" [XmlRoot(\"{ct.Root}\")]"); } writer.Write($" public partial class {ct.ClassName}"); writer.WriteLine(ct.HasBase ? $" : {ct.ClassBaseName}" : ""); writer.WriteLine(" {"); foreach (var e in ct.Items) { if (e.Name != "monitorData" && !(ct.Name == "hudson.maven.MavenModule" && e.Name == "displayName") // override base class ) { if (!string.IsNullOrEmpty(e.Description)) { writer.WriteLine(" /// <summary>"); writer.WriteLine($" /// {e.Description}"); writer.WriteLine(" /// </summary>"); } switch (apiType) { case APIType.XML: writer.WriteLine($" [XmlElement(\"{e.Name}\")]"); break; case APIType.JSON: writer.WriteLine($" [JsonPropertyName(\"{e.Name}\")]"); break; } switch (e.ItemType) { case ClassItem.ItemTypes.Single: writer.WriteLine($" public {e.DataType} {e.ItemName} {{ get; set; }}"); break; case ClassItem.ItemTypes.Bool: writer.WriteLine($" public {e.DataType} {e.ItemName} {{ get; set; }}"); break; case ClassItem.ItemTypes.List: writer.WriteLine($" public {e.DataType}[] {e.ItemName} {{ get; set; }}"); break; } writer.WriteLine(); } } if (ct.Items.Count == 0 && !ct.HasClassAttribut) { writer.WriteLine(" // empty"); } if (ct.HasClassAttribut) { writer.WriteLine(" /// <summary>"); writer.WriteLine(" /// Jenkins Java class name."); writer.WriteLine(" /// </summary>"); switch (apiType) { case APIType.XML: writer.WriteLine(" [XmlAttribute(\"_class\")]"); break; case APIType.JSON: writer.WriteLine(" [JsonPropertyName(\"_class\")]"); break; } writer.WriteLine(" public string Class { get; set; }"); } writer.WriteLine(" }"); writer.WriteLine("}"); } } }