コード例 #1
0
        private static void Main()
        {
            Util.Utils.ReleaseMemory();
            I18N.Register(Resources.cn);

            using (Mutex mutex = new Mutex(false, "Global\\" + "71981632-A427-497F-AB91-241CD227EC1F"))
            {
                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault(false);

                if (!mutex.WaitOne(0, false))
                {
                    Process[] oldProcesses = Process.GetProcessesByName("Shadowsocks");
                    if (oldProcesses.Length > 0)
                    {
                        Process oldProcess = oldProcesses[0];
                    }
                    MessageBox.Show("Shadowsocks is already running.\n\nFind Shadowsocks icon in your notify tray.");
                    return;
                }
                Directory.SetCurrentDirectory(Application.StartupPath);
#if !DEBUG
                Logging.OpenLogFile();
#endif
                ShadowsocksController controller = new ShadowsocksController();

                MenuViewController viewController = new MenuViewController(controller);

                //开始运行
                controller.Start();

                Application.Run();
            }
        }
コード例 #2
0
ファイル: Global.asax.cs プロジェクト: stepaside/i18n
        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();
            RegisterGlobalFilters(GlobalFilters.Filters);
            RegisterRoutes(RouteTable.Routes);

            I18N.Register();
        }
コード例 #3
0
        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();
            WebApiConfig.Register(GlobalConfiguration.Configuration);
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            BundleConfig.RegisterBundles(BundleTable.Bundles);

            I18N.Register();
        }
コード例 #4
0
        public static string GetMessageId(this IPropertyValidator propVal, bool includePropName = false)
        {
            var propValType = propVal.GetType();

            #region NotNullValidator
            if (propValType == typeof(NotNullValidator))
            {
                return(includePropName
                    ? I18N.Register("'{PropertyName}' is required.")
                    : I18N.Register("Is required."));
            }
            #endregion
            #region EmailValidator
            if (propValType == typeof(EmailValidator))
            {
                return(includePropName
                    ? I18N.Register("'{PropertyName}' is not a valid email address.")
                    : I18N.Register("Is not a valid email address."));
            }
            #endregion
            #region NotEmptyValidator
            if (propValType == typeof(NotEmptyValidator))
            {
                return(includePropName
                    ? I18N.Register("'{PropertyName}' should not be empty.")
                    : I18N.Register("Should not be empty."));
            }
            #endregion
            #region EqualValidator
            if (propValType == typeof(EqualValidator))
            {
                return(includePropName
                    ? I18N.Register("'{PropertyName}' should be equal to '{ComparisonValue}'.")
                    : I18N.Register("Should be equal to '{ComparisonValue}'."));
            }
            #endregion
            #region ExclusiveBetweenValidator
            if (propValType == typeof(ExclusiveBetweenValidator))
            {
                return(includePropName
                    ? I18N.Register("'{PropertyName}' must be between {From} and {To} (exclusive).")
                    : I18N.Register("Must be between {From} and {To} (exclusive)."));
            }
            #endregion
            #region InclusiveBetweenValidator
            if (propValType == typeof(InclusiveBetweenValidator))
            {
                return(includePropName
                    ? I18N.Register("'{PropertyName}' must be between {From} and {To}.")
                    : I18N.Register("Must be between {From} and {To}."));
            }
            #endregion
            #region LengthValidator
            if (propValType == typeof(LengthValidator))
            {
                var val = (LengthValidator)propVal;
                return((val.Min > 0)
                    ? (includePropName
                        ? I18N.Register("'{PropertyName}' must be between {Min} and {Max} characters.")
                        : I18N.Register("Must be between {Min} and {Max} characters."))
                    : (includePropName
                        ? I18N.Register("'{PropertyName}' must be less than or equal to {Max} characters.")
                        : I18N.Register("Must be less than or equal to {Max} characters.")));
            }
            #endregion
            #region NotEqualValidator
            if (propValType == typeof(NotEqualValidator))
            {
                return(includePropName
                    ? I18N.Register("'{PropertyName}' should not be equal to '{ComparisonValue}'.")
                    : I18N.Register("Should not be equal to '{ComparisonValue}'."));
            }
            #endregion
            #region RegularExpressionValidator
            if (propValType == typeof(RegularExpressionValidator))
            {
                return(includePropName
                    ? I18N.Register("'{PropertyName}' is not in the correct format.")
                    : I18N.Register("Is not in the correct format."));
            }
            #endregion
            #region CreditCardValidator
            if (propValType == typeof(CreditCardValidator))
            {
                return(includePropName
                    ? I18N.Register("'{PropertyName}' is not a valid credit card number.")
                    : I18N.Register("Is not a valid credit card number."));
            }
            #endregion
            #region ExactLengthValidator
            if (propValType == typeof(ExactLengthValidator))
            {
                return(includePropName
                    ? I18N.Register("'{PropertyName}' must be {Max} characters in length.")
                    : I18N.Register("Must be {Max} characters in length."));
            }
            #endregion
            #region GreaterThanValidator
            if (propValType == typeof(GreaterThanValidator))
            {
                return(includePropName
                    ? I18N.Register("'{PropertyName}' must be greater than '{ComparisonValue}'.")
                    : I18N.Register("Must be greater than '{ComparisonValue}'."));
            }
            #endregion
            #region GreaterThanOrEqualValidator
            if (propValType == typeof(GreaterThanOrEqualValidator))
            {
                return(includePropName
                    ? I18N.Register("'{PropertyName}' must be greater than or equal to '{ComparisonValue}'.")
                    : I18N.Register("Must be greater than or equal to '{ComparisonValue}'."));
            }
            #endregion
            #region LessThanOrEqualValidator
            if (propValType == typeof(LessThanOrEqualValidator))
            {
                return(includePropName
                    ? I18N.Register("'{PropertyName}' must be less than or equal to '{ComparisonValue}'.")
                    : I18N.Register("Must be less than or equal to '{ComparisonValue}'."));
            }
            #endregion
            #region LessThanValidator
            if (propValType == typeof(LessThanValidator))
            {
                return(includePropName
                    ? I18N.Register("'{PropertyName}' must be less than '{ComparisonValue}'.")
                    : I18N.Register("Must be less than '{ComparisonValue}'."));
            }
            #endregion
            #region ScalePrecisionValidator
            if (propValType == typeof(ScalePrecisionValidator))
            {
                return(includePropName
                    ? I18N.Register("'{PropertyName}' must have scale '{Scale}', precision '{Precision}'.")
                    : I18N.Register("Must have scale '{Scale}', precision '{Precision}'."));
            }
            #endregion
            throw new NotSupportedException(
                      string.Format(
                          "Validator of type '{0}' has not a predefined localized message. Pass the localized message as parameter",
                          propValType));
        }
コード例 #5
0
        public static string GetMessageId(this IPropertyValidator propVal, bool includePropName = false)
        {
            switch (propVal)
            {
            case EmailValidator _:
                return(includePropName
                        ? I18N.Register("'{PropertyName}' is not a valid email address.")
                        : I18N.Register("Is not a valid email address."));

            case GreaterThanOrEqualValidator _:
                return(includePropName
                        ? I18N.Register("'{PropertyName}' must be greater than or equal to '{ComparisonValue}'.")
                        : I18N.Register("Must be greater than or equal to '{ComparisonValue}'."));

            case GreaterThanValidator _:
                return(includePropName
                        ? I18N.Register("'{PropertyName}' must be greater than '{ComparisonValue}'.")
                        : I18N.Register("Must be greater than '{ComparisonValue}'."));

            case MinimumLengthValidator _:
                return(includePropName
                        ? I18N.Register("The length of '{PropertyName}' must be at least {MinLength} characters. You entered {TotalLength} characters.")
                        : I18N.Register("The length must be at least {MinLength} characters. You entered {TotalLength} characters."));

            case MaximumLengthValidator _:
                return(includePropName
                        ? I18N.Register("The length of '{PropertyName}' must be {MaxLength} characters or fewer. You entered {TotalLength} characters.")
                        : I18N.Register("The length must be {MaxLength} characters or fewer. You entered {TotalLength} characters."));

            case ExactLengthValidator _:
                return(includePropName
                        ? I18N.Register("'{PropertyName}' must be {MaxLength} characters in length. You entered {TotalLength} characters.")
                        : I18N.Register("Must be {MaxLength} characters in length. You entered {TotalLength} characters."));

            case LengthValidator _:
                return(includePropName
                        ? I18N.Register("'{PropertyName}' must be between {MinLength} and {MaxLength} characters. You entered {TotalLength} characters.")
                        : I18N.Register("Must be between {MinLength} and {MaxLength} characters. You entered {TotalLength} characters."));

            case LessThanOrEqualValidator _:
                return(includePropName
                        ? I18N.Register("'{PropertyName}' must be less than or equal to '{ComparisonValue}'.")
                        : I18N.Register("Must be less than or equal to '{ComparisonValue}'."));

            case LessThanValidator _:
                return(includePropName
                        ? I18N.Register("'{PropertyName}' must be less than '{ComparisonValue}'.")
                        : I18N.Register("Must be less than '{ComparisonValue}'."));

            case NotNullValidator _:
            case NotEmptyValidator _:
                return(includePropName
                        ? I18N.Register("'{PropertyName}' must not be empty.")
                        : I18N.Register("Must not be empty."));

            case NotEqualValidator _:
                return(includePropName
                        ? I18N.Register("'{PropertyName}' must not be equal to '{ComparisonValue}'.")
                        : I18N.Register("Must not be equal to '{ComparisonValue}'."));

            case AsyncPredicateValidator _:
            case PredicateValidator _:
                return(includePropName
                        ? I18N.Register("The specified condition was not met for '{PropertyName}'.")
                        : I18N.Register("The specified condition was not met."));

            case RegularExpressionValidator _:
                return(includePropName
                        ? I18N.Register("'{PropertyName}' is not in the correct format.")
                        : I18N.Register("Is not in the correct format."));

            case EqualValidator _:
                return(includePropName
                        ? I18N.Register("'{PropertyName}' must be equal to '{ComparisonValue}'.")
                        : I18N.Register("Must be equal to '{ComparisonValue}'."));

            case InclusiveBetweenValidator _:
                return(includePropName
                        ? I18N.Register("'{PropertyName}' must be between {From} and {To}. You entered {Value}.")
                        : I18N.Register("Must be between {From} and {To}. You entered {Value}."));

            case ExclusiveBetweenValidator _:
                return(includePropName
                        ? I18N.Register("'{PropertyName}' must be between {From} and {To} (exclusive). You entered {Value}.")
                        : I18N.Register("Must be between {From} and {To} (exclusive). You entered {Value}."));

            case CreditCardValidator _:
                return(includePropName
                        ? I18N.Register("'{PropertyName}' is not a valid credit card number.")
                        : I18N.Register("Is not a valid credit card number."));

            case ScalePrecisionValidator _:
                return(includePropName
                        ? I18N.Register("'{PropertyName}' must not be more than {ExpectedPrecision} digits in total, with allowance for {ExpectedScale} decimals. {Digits} digits and {ActualScale} decimals were found.")
                        : I18N.Register("Must not be more than {ExpectedPrecision} digits in total, with allowance for {ExpectedScale} decimals. {Digits} digits and {ActualScale} decimals were found."));

            case EmptyValidator _:
            case NullValidator _:
                return(includePropName
                        ? I18N.Register("'{PropertyName}' must be empty.")
                        : I18N.Register("Must be empty."));

            case EnumValidator _:
                return(includePropName
                        ? I18N.Register("'{PropertyName}' has a range of values which does not include '{PropertyValue}'.")
                        : I18N.Register("'Has a range of values which does not include '{PropertyValue}'."));

            default:
                throw new NotSupportedException($"Validator of type '{propVal}' has not a predefined localized message. Pass the localized message as parameter");
            }
        }