예제 #1
0
 protected async void Do(Func <Task> task)
 {
     try
     {
         canExecute = false;
         CanExecuteChanged?.Invoke(this, new EventArgs());
         await task();
     }
     catch (Exception ex)
     {
         await CommonDialog.ShowErrorDialogAsync(ex);
     }
     finally
     {
         canExecute = true;
         CanExecuteChanged?.Invoke(this, new EventArgs());
     }
 }
예제 #2
0
 protected async void Do(Action action)
 {
     try
     {
         canExecute = false;
         CanExecuteChanged?.Invoke(this, new EventArgs());
         await Task.Run(() =>
         {
             action();
         });
     }
     catch (Exception ex)
     {
         await CommonDialog.ShowErrorDialogAsync(ex);
     }
     finally
     {
         canExecute = true;
         CanExecuteChanged?.Invoke(this, new EventArgs());
     }
 }
예제 #3
0
        private async Task <bool> CheckAsync()
        {
            try
            {
                if (Rule.Name.Length == 0)
                {
                    T("名称为空");
                }
                if (Rule.Name.Length > 10)
                {
                    T("名称长度不可超过10");
                }
                if (Rule.LocalPort.Length == 0)
                {
                    T("本地端口为空");
                }
                if (Rule.RemotePort.Length == 0)
                {
                    T("远程端口为空");
                }
                if (Rule.LocalAddress.Length == 0)
                {
                    T("本地地址为空");
                }
                ushort[] localPort  = null;
                ushort[] remotePort = null;
                switch (Rule.Type)
                {
                case NetType.TCP:
                case NetType.UDP:
                    try
                    {
                        localPort = GetPorts(Rule.LocalPort);
                    }
                    catch (FormatException ex)
                    {
                        T("本地端口" + ex.Message);
                    }
                    try
                    {
                        remotePort = GetPorts(Rule.RemotePort);
                    }
                    catch (FormatException ex)
                    {
                        T("远程端口" + ex.Message);
                    }
                    if (localPort.Length != remotePort.Length)
                    {
                        T("本地端口和远程端口数量不同");
                    }
                    break;

                case NetType.HTTP:
                case NetType.HTTPS:
                case NetType.STCP:
                case NetType.STCP_Visitor:
                    if (!ushort.TryParse(Rule.LocalAddress, out _))
                    {
                        T("本地端口有误");
                    }
                    break;
                }
                if (Rule.Type is NetType.STCP or NetType.STCP_Visitor && string.IsNullOrWhiteSpace(Rule.STCPKey))
                {
                    T("STCP密钥为空");
                }
                if (Rule.Type is NetType.STCP_Visitor && string.IsNullOrWhiteSpace(Rule.STCPServerName))
                {
                    T("STCP服务名为空");
                }

                //暂不考虑端口不对应


                return(true);
            }
            catch (FormatException ex)
            {
                await CommonDialog.ShowErrorDialogAsync(ex.Message);

                return(false);
            }
        }