/// <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);
        }
示例#2
0
        public BatteryInformation GetBatteryInformation(BatteryDeviceType batteryDeviceType)
        {
            BatteryInformation batteryInformationRef;

            ErrorCodeHelper.ToResult(XInput.XInputGetBatteryInformation((int)this.userIndex, batteryDeviceType, out batteryInformationRef)).CheckError();
            return(batteryInformationRef);
        }
示例#3
0
        /// <summary>Reloads settings from INI file.</summary>
        public static Result Reset()
        {
            var result = ErrorCodeHelper.ToResult(xinput.Reset());

            result.CheckError();
            return(result);
        }
示例#4
0
        public BatteryInformation GetBatteryInformation(BatteryDeviceType batteryDeviceType)
        {
            BatteryInformation information;

            ErrorCodeHelper.ToResult(SharpDX.XInput.XInput.XInputGetBatteryInformation((int)this.userIndex, batteryDeviceType, out information)).CheckError();
            return(information);
        }
示例#5
0
 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);
             }
         }
     }
 }
示例#6
0
        public Capabilities GetCapabilities(DeviceQueryType deviceQueryType)
        {
            Capabilities capabilities;

            ErrorCodeHelper.ToResult(SharpDX.XInput.XInput.XInputGetCapabilities((int)this.userIndex, deviceQueryType, out capabilities)).CheckError();
            return(capabilities);
        }
示例#7
0
        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();
            }
        }
示例#8
0
        /// <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);
        }
示例#9
0
        //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);
        }
示例#10
0
        //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);
        }
示例#12
0
        // 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);
        }
示例#14
0
        /// <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);
        }
示例#18
0
        /// <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);
        }
示例#19
0
        /// <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);
        }
示例#20
0
        /// <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);
        }
示例#21
0
        //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);
        }
示例#25
0
        /// <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());
        }
示例#26
0
        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);
        }
示例#27
0
 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));
         }
     }
 }
示例#28
0
        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));
        }
示例#29
0
 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);
         }
     }
 }
示例#30
0
 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));
         }
     }
 }