Exemplo n.º 1
0
        /// <summary>
        /// 格式化输出
        /// </summary>
        /// <param name="value"></param>
        /// <param name="clearErrorInfo">是否清空错误信息</param>
        /// <returns></returns>
        public override string Format(object value, bool clearErrorInfo = true)
        {
            try {
                if (clearErrorInfo) //清空错误信息
                {
                    ErrorInfos.Clear();
                }

                var str = value.ToSpecObject <string> ();
                if (!str.IsValid(false))
                {
                    return(string.Empty);
                }

                var orgStr = str;
                if (DateTime.TryParse(str, out DateTime dt))
                {
                    str = dt.ToString(FormatString);
                }
                else
                {
                    str = string.Empty;
                }

                if (!orgStr.Equals(str))
                {
                    ErrorInfos.Add($"日期时间格式应为 {GetReadableText(FormatString)}");
                }

                return(str);
            } catch (Exception ex) {
                return(ex.Message);
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// 格式化输出
        /// </summary>
        /// <param name="value"></param>
        /// <param name="clearErrorInfo">是否清空错误信息</param>
        /// <returns></returns>
        public override string Format(object value, bool clearErrorInfo = true)
        {
            try {
                if (clearErrorInfo) //清空错误信息
                {
                    ErrorInfos.Clear();
                }

                var str = value?.ToString();
                if (!str.IsValid(false))
                {
                    return(string.Empty);
                }

                var number    = Convert.ToDecimal(str);
                var orgNumber = number;

                var minValue = GetFormatString(FormatMinValue)?.ToDecimal();
                if (minValue != null)
                {
                    number = Math.Max(number, minValue.Value);
                }

                var maxValue = GetFormatString(FormatMaxValue)?.ToDecimal();
                if (maxValue != null)
                {
                    number = Math.Min(number, maxValue.Value);
                }

                if (number != orgNumber)
                {
                    if (minValue != null && maxValue != null)
                    {
                        ErrorInfos.Add($"只能输入 {minValue.Value} ~ {maxValue.Value} 之间的值");
                    }
                    else if (minValue != null)
                    {
                        ErrorInfos.Add($"只能输入大于或等于 {minValue.Value} 的值");
                    }
                    else if (maxValue != null)
                    {
                        ErrorInfos.Add($"只能输入小于或等于 {maxValue.Value} 的值");
                    }

                    return(number.ToString());
                }

                return(base.Format(value, false));
            } catch (FormatException fe) {
                ErrorInfos.Add("格式不正确");
                return(fe.Message);
            } catch (Exception ex) {
                ErrorInfos.Add(ex.Message);
                return(ex.Message);
            }
        }
Exemplo n.º 3
0
        private UIDInfo GetErrorInfo(int uid)
        {
            var info = ErrorInfos.FirstOrDefault(i => i.UID == uid);

            if (info == null)
            {
                info = new UIDInfo(uid);
                ErrorInfos.Add(info);
            }
            return(info);
        }
Exemplo n.º 4
0
        /// <summary>
        /// 格式化输出
        /// </summary>
        /// <param name="value"></param>
        /// <param name="clearErrorInfo">是否清空错误信息</param>
        /// <returns></returns>
        public override string Format(object value, bool clearErrorInfo = true)
        {
            try
            {
                if (clearErrorInfo) //清空错误信息
                {
                    ErrorInfos.Clear();
                }

                var str = value?.ToString();
                if (!str.IsValid(false))
                {
                    return(string.Empty);
                }

                var number = Convert.ChangeType(str, NumberType);
                var fmt    = GetFormatString(FormatFormat);
                if (!fmt.IsValid())
                {
                    return(base.Format(value, false));
                }

                var data = number.Invoke("ToString", new[] { fmt }, new Type[] { typeof(string) });
                if (!number.Equals(data))
                {
                    ErrorInfos.Add($"最多只能输入 {GetReadableText(fmt)} 位小数");
                }

                return(base.Format(data, false));
            }
            catch (FormatException fe)
            {
                ErrorInfos.Add("格式不正确");
                return(fe.Message);
            }
            catch (Exception ex)
            {
                ErrorInfos.Add(ex.Message);
                return(ex.Message);
            }
        }
Exemplo n.º 5
0
        async Task GetErrorInfosAsync(int machineId)
        {
            if (IsBusy)
            {
                return;
            }

            try
            {
                IsBusy = true;

                var json = await Client.GetStringAsync(string.Format(Host + SelectPayment, machineId));

                var errorInfos = ErrorInfo.FromJson(json);

                //Windows.ApplicationModel.Core.CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal,
                //() =>
                //    {
                //        ErrorInfos.Clear();
                //        foreach (var error in errorInfos)
                //            ErrorInfos.Add(error);
                //    }
                //);
                ErrorInfos.Clear();
                foreach (var error in errorInfos)
                {
                    ErrorInfos.Add(error);
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine($"Unable to get Errors: {ex.Message}");
                await Application.Current.MainPage.DisplayAlert("Error!", ex.Message, "OK");
            }
            finally
            {
                IsBusy = false;
            }
        }
Exemplo n.º 6
0
        public void ProcessIMAPFolder()
        {
            using (var imapClient = new IMAP_Client()) {
                _imapClient = imapClient;
                ConnectToIMAP();

                try {
                    var items    = Enumerable.Empty <IMAP_FetchItem>().ToArray();
                    var toDelete = new List <IMAP_FetchItem>();
                    do
                    {
                        toDelete.Clear();
                        ImapReader.PingReader();
                        items = FetchUIDs();
                        if (log.IsDebugEnabled)
                        {
                            log.DebugFormat("Получено {0} UIDs", items.Length);
                        }
                        //обрабатываем мисьма пачками что бы уменьшить вероятность появления дублей
                        //при остановке шатной или аварийной остановке
                        items = items.Take(100).ToArray();
                        ImapReader.PingReader();

                        foreach (var item in items)
                        {
                            if (log.IsDebugEnabled)
                            {
                                log.DebugFormat("Обработка {0} UID", item.UID);
                            }

                            IMAP_FetchItem[] OneItem = null;
                            try {
                                OneItem = FetchMessages(item.UID);

                                Message = Mime.Parse(OneItem[0].MessageData);

                                CurrentUID = item.UID;

                                ImapReader.PingReader();
                                ImapReader.ProcessMime(Message);
                                toDelete.Add(item);
                            }
                            catch (Exception ex) {
                                if (log.IsDebugEnabled)
                                {
                                    log.Debug(String.Format("Не удалось обработать письмо {0} UID", item.UID), ex);
                                }
                                Message = null;
                                var errorInfo = GetErrorInfo(item.UID);
                                if (UIDTimeout(errorInfo))
                                {
                                    ErrorInfos.Remove(errorInfo);
                                    toDelete.Add(item);
                                    ImapReader.ProcessBrokenMessage(item, OneItem, ex);
                                }
                            }
                        }

                        //Производим удаление писем
                        if (toDelete.Count > 0)
                        {
                            var sequence = new IMAP_SequenceSet();

                            sequence.Parse(String.Join(",", toDelete.Select(i => i.UID.ToString())), long.MaxValue);
                            imapClient.DeleteMessages(sequence, true);
                        }
                    } while (items.Length > 0 && toDelete.Count > 0);
                }
                finally {
                    Message = null;
                }
            }
        }
Exemplo n.º 7
0
 public HybridErrorViewModel(string error)
 {
     Error = new ErrorInfos {
         Error = error
     };
 }