/// <summary>Sets the vibration.</summary> /// <param name="vibration">The vibration.</param> /// <returns></returns> public Result SetVibration(Vibration vibration) { Result result = ErrorCodeHelper.ToResult(xinput.XInputSetState((int)this.userIndex, vibration)); result.CheckError(); return(result); }
public BatteryInformation GetBatteryInformation(BatteryDeviceType batteryDeviceType) { BatteryInformation batteryInformationRef; ErrorCodeHelper.ToResult(XInput.XInputGetBatteryInformation((int)this.userIndex, batteryDeviceType, out batteryInformationRef)).CheckError(); return(batteryInformationRef); }
/// <summary>Reloads settings from INI file.</summary> public static Result Reset() { var result = ErrorCodeHelper.ToResult(xinput.Reset()); result.CheckError(); return(result); }
public BatteryInformation GetBatteryInformation(BatteryDeviceType batteryDeviceType) { BatteryInformation information; ErrorCodeHelper.ToResult(SharpDX.XInput.XInput.XInputGetBatteryInformation((int)this.userIndex, batteryDeviceType, out information)).CheckError(); return(information); }
public void InstallHook(Form window) { if (this.State == HookState.Uninstalled) { if (window != null) { NativeExports.SetLastError(0); IntPtr nextWindow = NativeExports.SetClipboardViewer(window.Handle); if (nextWindow == IntPtr.Zero) { var errorCode = NativeExports.GetLastError(); if (errorCode == 0) { OnSuccessfullHook(window.Handle, nextWindow); } else { var message = ErrorCodeHelper.GetMessage(errorCode); throw new Exception(message); } } else { OnSuccessfullHook(window.Handle, nextWindow); } } } }
public Capabilities GetCapabilities(DeviceQueryType deviceQueryType) { Capabilities capabilities; ErrorCodeHelper.ToResult(SharpDX.XInput.XInput.XInputGetCapabilities((int)this.userIndex, deviceQueryType, out capabilities)).CheckError(); return(capabilities); }
public void SyncServicePullFileTest() { Device device = GetFirstDevice(); FileListingService fileListingService = new FileListingService(device); using (ISyncService sync = device.SyncService) { String rfile = "/sdcard/bootanimations/bootanimation-cm.zip"; FileEntry rentry = fileListingService.FindFileEntry(rfile); String lpath = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory); String lfile = Path.Combine(lpath, LinuxPath.GetFileName(rfile)); FileInfo lfi = new FileInfo(lfile); SyncResult result = sync.PullFile(rfile, lfile, new FileSyncProgressMonitor()); Assert.IsTrue(lfi.Exists); Assert.IsTrue(ErrorCodeHelper.RESULT_OK == result.Code, ErrorCodeHelper.ErrorCodeToString(result.Code)); lfi.Delete(); result = sync.PullFile(rentry, lfile, new FileSyncProgressMonitor()); Assert.IsTrue(lfi.Exists); Assert.IsTrue(ErrorCodeHelper.RESULT_OK == result.Code, ErrorCodeHelper.ErrorCodeToString(result.Code)); lfi.Delete(); } }
/// <summary> /// Gets the keystroke. /// </summary> /// <param name="deviceQueryType">The flag.</param> /// <param name="keystroke">The keystroke.</param> /// <returns></returns> /// <unmanaged>unsigned int XInputGetKeystroke([In] XUSER_INDEX dwUserIndex,[In] unsigned int dwReserved,[Out] XINPUT_KEYSTROKE* pKeystroke)</unmanaged> public Result GetKeystroke(DeviceQueryType deviceQueryType, out Keystroke keystroke) { var result = ErrorCodeHelper.ToResult(XInput.XInputGetKeystroke((int)userIndex, (int)deviceQueryType, out keystroke)); result.CheckError(); return(result); }
//api/lms/GetGoodstype public Response <List <GoodsTypeModel> > GetGoodstype() { var model = new Response <List <GoodsTypeModel> > { Item = null, ResultCode = ErrorCodeHelper.GetErrorCode(ErrorCode.Error0000), ResultDesc = Resource.Error0000 }; model.Item = new List <GoodsTypeModel>(); if (_orderService.GetGoodsTypes().Count > 1) { _orderService.GetGoodsTypes().ForEach(p => model.Item.Add(new GoodsTypeModel() { GoodsTypeID = p.GoodsTypeID, GoodsTypeName = p.GoodsTypeName })); } if (model.Item.Count < 1) { model.ResultDesc = ErrorCodeHelper.GetErrorCode(ErrorCode.Error1006); model.ResultDesc = Resource.Error1006; } return(model); }
//api/lms/GetCountry //[HttpGet] public Response <List <CountryModel> > GetCountry() { //if (Cache.Get("GetCountryList") != null) //{ // var list = Cache.Get("GetCountryList") as Response<List<CountryModel>>; // return list; //} //else //{ var model = new Response <List <CountryModel> > { Item = null, ResultCode = ErrorCodeHelper.GetErrorCode(ErrorCode.Error0000), ResultDesc = Resource.Error0000 }; model.Item = new List <CountryModel>(); GetCountrys().ForEach(p => model.Item.Add(new CountryModel() { CountryCode = p.CountryCode, EName = p.EName, CName = p.CName })); if (model.Item.Count < 1) { model.ResultDesc = ErrorCodeHelper.GetErrorCode(ErrorCode.Error1006); model.ResultDesc = Resource.Error1006; } //else //{ // Cache.Add("GetCountryList", model, 120); //} return(model); //} }
public void LoadMessage_Test() { ErrorCodeHelper.LoadErrorMessage(); ErrorCodeHelper.ErrorMessages.ShouldNotBeNull(); ErrorCodeHelper.ErrorMessages.Count.ShouldBe(15); }
// Due to https://bugzilla.xamarin.com/show_bug.cgi?id=20082 we can't use dynamic deserialization. private static async Task <JObject> MakeAuthRequestAsync(HttpMethod method, Uri uri, IDictionary <string, object> body) { var request = new HttpRequestMessage(method, uri); request.Content = new StringContent(JsonConvert.SerializeObject(body), Encoding.UTF8, "application/json"); request.Headers.Accept.ParseAdd(_applicationJsonUtf8MediaType.MediaType); request.Headers.Accept.ParseAdd(_applicationProblemJsonUtf8MediaType.MediaType); var response = await _client.Value.SendAsync(request).ConfigureAwait(continueOnCapturedContext: false); if (response.IsSuccessStatusCode && response.Content.Headers.ContentType.Equals(_applicationJsonUtf8MediaType)) { var json = await response.Content.ReadAsStringAsync().ConfigureAwait(continueOnCapturedContext: false); return(JObject.Parse(json)); } var errorJson = await response.Content.ReadAsStringAsync().ConfigureAwait(continueOnCapturedContext: false); if (response.Content.Headers.ContentType.Equals(_applicationProblemJsonUtf8MediaType)) { var problem = JObject.Parse(errorJson); var code = ErrorCodeHelper.GetErrorCode(problem["code"].Value <int>()) ?? ErrorCode.Unknown; throw new AuthenticationException(code, response.StatusCode, response.ReasonPhrase, errorJson, problem["title"].Value <string>()); } throw new HttpException(response.StatusCode, response.ReasonPhrase, errorJson); }
/// <summary>Gets the state.</summary> /// <returns>The state of this controller.</returns> public State GetState() { State stateRef; ErrorCodeHelper.ToResult(xinput.XInputGetState((int)this.userIndex, out stateRef)).CheckError(); return(stateRef); }
/// <summary> /// Sets the vibration. /// </summary> /// <param name="vibration">The vibration.</param> /// <returns></returns> public Result SetVibration(Vibration vibration) { var result = ErrorCodeHelper.ToResult(XInputSetState((int)userIndex, vibration)); result.CheckError(); return(result); }
public Result GetKeystroke(DeviceQueryType deviceQueryType, out Keystroke keystroke) { return(ErrorCodeHelper.ToResult( openXinput ? NativeOpenXinput.XInputGetKeystroke(userIndex, (int)deviceQueryType, out keystroke) : NativeXinput.XInputGetKeystroke(userIndex, (int)deviceQueryType, out keystroke) )); }
public Result SetVibration(Vibration vibration) { Result result = ErrorCodeHelper.ToResult(openXinput ? NativeOpenXinput.XInputSetState(userIndex, vibration) : NativeXinput.XInputSetState(userIndex, vibration)); result.CheckError(); return(result); }
public State GetState() { State temp; ErrorCodeHelper.ToResult( openXinput ? NativeOpenXinput.XInputGetState(userIndex, out temp) : NativeXinput.XInputGetState(userIndex, out temp)).CheckError(); return(temp); }
/// <summary> /// Gets the battery information. /// </summary> /// <param name="batteryDeviceType">Type of the battery device.</param> /// <returns></returns> /// <unmanaged>unsigned int XInputGetBatteryInformation([In] XUSER_INDEX dwUserIndex,[In] BATTERY_DEVTYPE devType,[Out] XINPUT_BATTERY_INFORMATION* pBatteryInformation)</unmanaged> public BatteryInformation GetBatteryInformation(BatteryDeviceType batteryDeviceType) { BatteryInformation temp; var result = ErrorCodeHelper.ToResult(xinput.XInputGetBatteryInformation((int)userIndex, batteryDeviceType, out temp)); result.CheckError(); return(temp); }
/// <summary> /// Gets the capabilities. /// </summary> /// <param name="deviceQueryType">Type of the device query.</param> /// <returns></returns> /// <unmanaged>unsigned int XInputGetCapabilities([In] XUSER_INDEX dwUserIndex,[In] XINPUT_DEVQUERYTYPE dwFlags,[Out] XINPUT_CAPABILITIES* pCapabilities)</unmanaged> public Capabilities GetCapabilities(DeviceQueryType deviceQueryType) { Capabilities temp; var result = ErrorCodeHelper.ToResult(xinput.XInputGetCapabilities((int)userIndex, deviceQueryType, out temp)); result.CheckError(); return(temp); }
/// <summary> /// Gets the state. /// </summary> /// <returns>The state of this controller.</returns> public State GetState() { State temp; var result = ErrorCodeHelper.ToResult(xinput.XInputGetState((int)userIndex, out temp)); result.CheckError(); return(temp); }
//api/lms/Get?countryCode= public Response <List <ShippingMethodModel> > Get(string countryCode) { if (string.IsNullOrWhiteSpace(countryCode)) { return(Get()); } //if (Cache.Get("GetShippingMethodList") != null && Cache.Get("countryCode") == countryCode && Cache.Get("CustomerCode") == CustomerCode) //{ // return Cache.Get("GetShippingMethodList") as Response<List<ShippingMethodModel>>; //} //else //{ var model = new Response <List <ShippingMethodModel> > { Item = null, ResultCode = ErrorCodeHelper.GetErrorCode(ErrorCode.Error0000), ResultDesc = Resource.Error0000 }; model.Item = new List <ShippingMethodModel>(); int customerTypeId; Guid customerId = new Guid(); var customer = _customerService.GetCustomer(CustomerCode); if (customer != null) { customerTypeId = customer.CustomerTypeID ?? 0; customerId = customer.CustomerID; } else { customerTypeId = 0; } GetShippingMethodes(customerId, customerTypeId, countryCode).ForEach(p => model.Item.Add(new ShippingMethodModel { Code = p.Code, EnglishName = p.EnglishName, FullName = p.FullName, DisplayName = p.DisplayName, HaveTrackingNum = p.HaveTrackingNum })); if (model.Item.Count < 1) { model.ResultDesc = ErrorCodeHelper.GetErrorCode(ErrorCode.Error1006); model.ResultDesc = Resource.Error1006; } //else //{ // Cache.Add("CustomerCode",CustomerCode,60); // Cache.Add("countryCode", countryCode, 60); // Cache.Add("GetShippingMethodList", model, 60); //} return(model); //} }
// Due to https://bugzilla.xamarin.com/show_bug.cgi?id=20082 we can't use dynamic deserialization. public static async Task <JObject> MakeAuthRequestAsync(HttpMethod method, Uri uri, IDictionary <string, object> body = null, string authHeader = null) { HttpResponseMessage response; using (var request = new HttpRequestMessage(method, uri)) { if (body != null) { request.Content = new StringContent(JsonConvert.SerializeObject(body), Encoding.UTF8, "application/json"); } request.Headers.Accept.ParseAdd(_applicationJsonUtf8MediaType.MediaType); request.Headers.Accept.ParseAdd(_applicationProblemJsonUtf8MediaType.MediaType); if (!string.IsNullOrEmpty(authHeader)) { request.Headers.TryAddWithoutValidation("Authorization", authHeader); } response = await _client.Value.SendAsync(request).ConfigureAwait(continueOnCapturedContext: false); } if (response.IsSuccessStatusCode && response.Content.Headers.ContentType.Equals(_applicationJsonUtf8MediaType)) { var json = await response.Content.ReadAsStringAsync().ConfigureAwait(continueOnCapturedContext: false); return(JObject.Parse(json)); } var errorJson = await response.Content.ReadAsStringAsync().ConfigureAwait(continueOnCapturedContext: false); Exception ex; string helpLink = null; string errorMessage; ErrorCode errorCode; try { var problem = JObject.Parse(errorJson); errorCode = ErrorCodeHelper.GetErrorCode(problem["code"].Value <int>()) ?? ErrorCode.Unknown; errorMessage = problem["title"].Value <string>(); helpLink = problem["type"].Value <string>(); } catch { errorCode = ErrorCode.Unknown; errorMessage = "An HTTP exception has occurred."; } ex = new HttpException(response.StatusCode, response.ReasonPhrase, errorJson, errorMessage, errorCode) { HelpLink = helpLink }; throw ex; }
public BatteryInformation GetBatteryInformation(BatteryDeviceType batteryDeviceType) { BatteryInformation temp; ErrorCodeHelper.ToResult( openXinput ? NativeOpenXinput.XInputGetBatteryInformation((int)this.userIndex, batteryDeviceType, out temp) : NativeXinput.XInputGetBatteryInformation((int)this.userIndex, batteryDeviceType, out temp) ).CheckError(); return(temp); }
public Capabilities GetCapabilities(DeviceQueryType deviceQueryType) { Capabilities temp; ErrorCodeHelper.ToResult( openXinput ? NativeOpenXinput.XInputGetCapabilities(userIndex, deviceQueryType, out temp) : NativeXinput.XInputGetCapabilities(userIndex, deviceQueryType, out temp) ).CheckError(); return(temp); }
/// <summary> /// 使用 <see cref="LogLevel.Warning"/> 级别打印错误日志,并记录异常堆栈。 /// </summary> /// <param name="logger">日志记录器的实例。</param> /// <param name="exception">错误码异常实例。</param> public static void LogWarningInfo(this ILogger logger, ErrorCodeException exception) { if (exception.ErrorCode < 50000) { throw exception; } var sb = new StringBuilder(); sb.Append($"错误代码: {exception.ErrorCode},信息: {ErrorCodeHelper.GetMessage(exception.ErrorCode)}"); sb.Append($"\n附加信息:\n {JsonConvert.SerializeObject(exception.AttachObject)}"); logger.LogWarning(sb.ToString()); }
public async Task OnDispatchCompleteAsync(OutputResult outputResult) { // If dispatch failed, upate the telemetry if (!outputResult.Delivered && outputResult.Targets != null && outputResult.Targets.Count > 0) { // Update record detail var details = outputResult.Targets.Select(t => new ReportDetail { PhoneNumber = t, MessageId = outputResult.MessageId.ToString(), State = ErrorCodeHelper.ConvertMessageStateFromRequestOutcome(outputResult.DeliveryResponse.DeliveryOutcome), StateDetail = outputResult.DeliveryResponse.DeliveryDetail }).ToList(); var updated = await this.UpdateReportAndDetails(details, outputResult.ConnectorIdentifier); // Update agent meta if agent exist var key = this.GetAgentKey(outputResult.ConnectorIdentifier); if (updated > 0 && !string.IsNullOrEmpty(key) && this.agents.TryGetValue(key, out ReportAgent agent)) { var meta = await this.store.GetAgentMetadataAsync(outputResult.ConnectorIdentifier); if (meta != null) { meta.PendingReceive -= Math.Min(outputResult.Targets.Count, meta.PendingReceive); await this.store.CreateOrUpdateAgentMetadataAsync(meta); if (meta.PendingReceive <= 0) { SmsProviderEventSource.Current.Info(SmsProviderEventSource.EmptyTrackingId, this, nameof(this.OnDispatchCompleteAsync), OperationStates.Succeeded, $"Report agent stopping (complete). connectorName={agent.Credential.ConnectorName} connectorKey={agent.Credential.ConnectorId}"); agent.UnSubscribe(); } } } } // If succeed with custom message Id, update the summary else if (outputResult.Delivered && !string.IsNullOrEmpty(outputResult.DeliveryResponse.CustomMessageId)) { await this.telemetryManager.OnMessageDispatchedAsync( outputResult.EngagementAccount, outputResult.MessageId.ToString(), outputResult.DeliveryResponse.CustomMessageId, outputResult.Targets.ToList(), outputResult.ConnectorIdentifier); } await this.telemetryManager.InsertMessageBatchRecordAsync(outputResult); }
public void RemoveHook() { if (this.State == HookState.Installed) { if (NativeExports.UnhookWindowsHookEx(this.handle)) { this.OnSuccessfullUnhook(); } else { var errorCode = NativeExports.GetLastError(); throw new Exception(ErrorCodeHelper.GetMessage(errorCode)); } } }
protected override Task <HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken) { bool _isValid = (GlobalConfig.IsValidCustomer == "true"); var response = new HttpResponseMessage(HttpStatusCode.Forbidden); if (_isValid) { var result = false; if (request.Headers.Authorization != null && request.Headers.Authorization.Parameter != null) { try { string[] userInfo = Encoding.UTF8.GetString(Convert.FromBase64String(request.Headers.Authorization.Parameter)) .Split('&'); if (userInfo.Length >= 2) { var _customerService = GlobalConfiguration.Configuration.DependencyResolver.BeginScope().GetService(typeof(ICustomerService)) as CustomerService; var customer = _customerService.GetCustomer(userInfo[0]); if (customer != null && customer.ApiSecret == userInfo[1]) { result = true; } } } catch (Exception) { ; } } if (!result) { response = new HttpResponseMessage(HttpStatusCode.Unauthorized) { Content = new StringContent(SerializeUtil.SerializeToXml(new Response <Item>() { ResultCode = ErrorCodeHelper.GetErrorCode(ErrorCode.Error1003), ResultDesc = Resource.Error1003 })) }; var tsc = new TaskCompletionSource <HttpResponseMessage>(); tsc.SetResult(response); return(tsc.Task); } } return(base.SendAsync(request, cancellationToken)); }
public void RemoveHook() { if (this.State == HookState.Installed) { NativeExports.SetLastError(0); NativeExports.ChangeClipboardChain(this.clipboard.Handle, this.clipboard.NextWindow); var errorCode = NativeExports.GetLastError(); if (errorCode == 0) { this.OnSuccessfullUnhook(); } else { var message = ErrorCodeHelper.GetMessage(errorCode); throw new Exception(message); } } }
public void InstallHook(Form window) { if (this.State == HookState.Uninstalled) { this.keyboardProcessor = new KeyboardMessageEventHandler(KeyboardProc); this.handle = NativeExports.SetWindowsHookEx(NativeConstants.WH_KEYBOARD_LL, this.keyboardProcessor, IntPtr.Zero, 0); if (this.handle == IntPtr.Zero) { this.keyboardProcessor = null; var errorCode = NativeExports.GetLastError(); throw new Exception(ErrorCodeHelper.GetMessage(errorCode)); } else { this.OnStateChanged(new StateChangedEventArgs(this.State)); } } }