Пример #1
0
        public MotorStateManager(ITranslater ist, MotorSignalSettings settings)
        {
            _name        = "MOTOR_2";
            _description = "Á½ÂÖĦÍгµÈÆ׮״̬";

            Settings = settings;

            regobj = new ArrayList();

            MotorSignalTranslator st = (MotorSignalTranslator)ist;

            _idleState   = new IdleState(st, this);
            _ksState     = new KSState(st, this);
            _jsState     = new JSState(st, this);
            _y1State     = new Y1State(st, this);
            _z1State     = new Z1State(st, this);
            _yState      = new YState(st, this);
            _zState      = new ZState(st, this);
            _c5State     = new C5State(st, this);
            _z2State     = new Z2State(st, this);
            _zwksState   = new ZWKSState(st, this);
            _zwjsState   = new ZWJSState(st, this);
            _sampleState = new SampleState(st, this);

            ResetState();
        }
Пример #2
0
 /// <summary>
 ///     Creates a new <see cref="JsonStringLocalizer" />.
 /// </summary>
 /// <param name="type">The base name of the embedded resource in the <see cref="Assembly" /> that contains the strings.</param>
 /// <param name="cache"></param>
 /// <param name="logger"></param>
 /// <param name="options"></param>
 /// <param name="translater"></param>
 /// <summary>
 ///     Intended for testing purposes only.
 /// </summary>
 public JsonStringLocalizer(string type, IJsonLocalizationCache cache, ILogger<JsonStringLocalizer> logger, IOptions<DependencyInjection.LocalizationOptions> options, ITranslater translater)
 {
     _type = type;
     _cache = cache;
     _logger = logger;
     _option = options;
     _translater = translater;
     _defaultCulture = options.Value.MissingTranslation;
 }
        public static ITranslater Create(int number)
        {
            ITranslater result = null;
            int numberDigit = GetNumberDigits(number);

            //switch (numberDigit)
            //{
            //    case 2: return new Ten(number, numberDigit);
            //    case 3: return new Hundred(number, numberDigit);
            //    case 4: return new Thousand(number, numberDigit);
            //    default: return new Unit(number, numberDigit);
            //}

            double ONE_THOUSAND = Math.Pow(10, 3);
            double ONE_MILLION = Math.Pow(10, 6);
            double ONE_BILLION = Math.Pow(10, 9);
            double ONE_TRILLION = Math.Pow(10, 12);
            double ONE_QUADRILLION = (long)Math.Pow(10, 15);

            if (number < 20)
            {
                result = new Unit(number, numberDigit);
            }
            else if (number < 100)
            {
                result = new Ten(number, numberDigit);
            }
            else if (number < ONE_THOUSAND)
            {
                //int numberDivideByThousand = Math.Truncate(number / ONE_THOUSAND);

                //if (10 <= numberDivideByThousand)
                //{
                //    result = new Unit(numberDivideByThousand, GetNumberDigits(numberDivideByThousand));
                //}
                //else
                //{
                 
                //}
                result = new Hundred(number, numberDigit);
            }
            else if (number < ONE_MILLION)
            {
                result = new Thousand(number, numberDigit);
            }
            else if (number < 1000000000)
            {
                result = new Million(number, numberDigit);
            }
            else
            {
                throw new ArgumentException();
            }

            return result;

        }
 /// <summary>
 ///     Creates a new <see cref="JsonStringLocalizer" />.
 /// </summary>
 /// <param name="localizationOptions">The <see cref="IOptions{TOptions}" />.</param>
 /// <param name="cache">Used entries will be cached</param>
 /// <param name="logger"></param>
 /// <param name="translater">Missed entries will be added by asking the translater for a translation</param>
 public JsonStringLocalizerFactory(IOptions<DependencyInjection.LocalizationOptions> localizationOptions, 
     IJsonLocalizationCache cache, 
     ILogger<JsonStringLocalizer> logger,
     ITranslater translater)
 {
     _resourcesRelativePath = localizationOptions.Value.ResourcesPath ?? string.Empty;
     _cache = cache;
     _logger = logger;
     _option = localizationOptions;
     _translater = translater;
 }
Пример #5
0
        public void InitializeExamComponent(CSettings set, IMonitor mon, ITranslater trans, StateManager sm)
        {
            settings   = set;
            monitor    = mon;
            translator = trans;
            statemgr   = sm;

            monitor.HotKeyHandle = this.Parent.Handle;

            statemgr.RegExamObserver(this);

            monitor.Start();
        }
Пример #6
0
        public TranslaterModule(ITranslater <TranslateRequest, TranslateResponse> translater) : base("/translate")
        {
            _translaterService = translater;

            Post["/"] = (parameters) =>
            {
                var data = this.Bind <TranslateRequest>();
                if (data.Text == string.Empty)
                {
                    return new TranslateResponse {
                               Text = new string[] { "" }
                    }
                }
                ;
                var res = _translaterService.Translate(data).Result;

                return(res);
            };

            Get["/check"] = _ => ((ApiClientCommon)_translaterService).HealthCheck();
        }
    }
Пример #7
0
        private void ExamForm_Load(object sender, EventArgs e)
        {
            if (examType == ExamType.NULL)
            {
                throw new Exception("考试组件未被初始化!");
            }

            switch (examType)
            {
            case ExamType.MOTOR_2:
                this.Text  = "两轮摩托车考试";
                monitor    = new Signal.MotorSignal.MotorMonitor(settings);
                translator = new Exam.SignalTranslator.MotorSignalTranslator(monitor);
                statemgr   = new Exam.State.XA2WMotorState.MotorStateManager(translator, (Signal.MotorSignal.MotorSignalSettings)settings);
                break;

            case ExamType.MOTOR_3:
                this.Text  = "三轮摩托车考试";
                monitor    = new Signal.MotorSignal.MotorMonitor(settings);
                translator = new Exam.SignalTranslator.MotorSignalTranslator(monitor);
                statemgr   = new Exam.State.XA3WMotorState.MotorStateManager(translator, (Signal.MotorSignal.MotorSignalSettings)settings);
                break;
            }

            this.examStatusDisplayPanel.InitializeExamComponent(statemgr);

            this.motorModelDisplayPanel.InitializeExamComponent(settings, monitor, statemgr);

            //一定要将ExamCtrlPanel对象最后初始化
            this.examCtrlPanel.InitializeExamComponent(settings, monitor, translator, statemgr);

            this.localInputPanel.InitializeCandExamCtrlComponent(this.examCtrlPanel, settings);

            //考车类型
            localInputPanel.CarType = examType;
            this.localInputPanel.SetKSCXComBox();

            soundCtrl = new Modules.SoundModule.SoundCtrl(this.localInputPanel);
        }
Пример #8
0
 public void Initialize()
 {
     _translater = new DefaultTranslator();
 }
Пример #9
0
        /// <summary>
        /// 翻译资源
        /// </summary>
        private void onTranlateAssets()
        {
            string textPath = string.Format(OutPath, outArr[(int)targetLanguage]);

            if (!System.IO.File.Exists(textPath))
            {
                EditorUtility.DisplayDialog("错误", "找不到对应的翻译文件,目标语言:" + languageStrArr[(int)targetLanguage], "确定");
                return;
            }

            Dictionary <string, TranslateMapper> transMaps = new Dictionary <string, TranslateMapper>();

            //读取已翻译的内容
            string[]        lines     = File.ReadAllLines(textPath);
            string          fileStart = "-------";
            TranslateMapper tm        = null;

            for (int i = 0; i < lines.Length; i++)
            {
                if (lines[i].StartsWith(fileStart))
                {
                    string filePath = lines[i].Replace("-", "").Trim();
                    tm = new TranslateMapper(filePath);
                    transMaps[tm.FilePath] = tm;
                }
                else
                {
                    string[] worlds = lines[i].Trim().Split('=');
                    if (worlds.Length > 1)
                    {
                        tm.SetTranslate(worlds[0].Trim(), worlds[1].Trim());
                    }
                }
            }

            //翻译转换资源
            List <string> files = searchSelectFiles();

            for (int i = 0; i < files.Count; i++)
            {
                string      file       = files[i];
                ITranslater translater = getTranslater(file);
                if (translater == null)
                {
                    continue;
                }

                string filePath = file.Replace("\\", "/");
                if (!transMaps.ContainsKey(filePath))
                {
                    transMaps[filePath] = new TranslateMapper(filePath);
                }
                translater.Translater(transMaps[filePath]);

                EditorUtility.DisplayProgressBar("翻译", "正在翻译文件...", i / (float)files.Count);
            }
            EditorUtility.ClearProgressBar();

            AssetDatabase.SaveAssets();
            AssetDatabase.Refresh();

            EditorUtility.DisplayDialog("提示", "已经完成翻译转换", "确定");
        }
Пример #10
0
        /// <summary>
        /// 导出源语言
        /// </summary>
        private void exportSourcesLanguage()
        {
            if (curLanguage == targetLanguage || targetLanguage == Language.SimpleChinese)
            {
                return;
            }

            List <TranslateMapper> transMaps = new List <TranslateMapper>();
            List <string>          files     = searchSelectFiles();

            for (int i = 0; i < files.Count; i++)
            {
                string file = files[i];

                ITranslater translater = getTranslater(file);
                if (translater == null)
                {
                    continue;
                }

                transMaps.Add(translater.Export(file.Replace("\\", "/")));

                EditorUtility.DisplayProgressBar("匹配", "正在匹配中文...", i / (float)files.Count);
            }
            EditorUtility.ClearProgressBar();

            //最终把提取的中文生成出来
            string textPath = string.Format(OutPath, outArr[(int)targetLanguage]);

            if (System.IO.File.Exists(textPath))
            {
                //读取已翻译的内容
                string[]        lines     = File.ReadAllLines(textPath);
                string          fileStart = "-------";
                TranslateMapper tm        = null;
                for (int i = 0; i < lines.Length; i++)
                {
                    if (lines[i].StartsWith(fileStart))
                    {
                        string          filePath = lines[i].Replace("-", "").Trim();
                        TranslateMapper hasTm    = null;
                        for (int j = 0; j < transMaps.Count; j++)
                        {
                            if (transMaps[j].FilePath.Equals(filePath))
                            {
                                hasTm = transMaps[j];
                                tm    = hasTm;
                                break;
                            }
                        }

                        if (hasTm == null)
                        {
                            //没找到文件,保留原翻译记录
                            tm = new TranslateMapper(filePath);
                            transMaps.Add(tm);
                        }
                    }
                    else
                    {
                        string[] worlds = lines[i].Trim().Split('=');
                        if (worlds.Length > 1)
                        {
                            tm.SetTranslate(worlds[0].Trim(), worlds[1].Trim());
                        }
                    }
                }
            }

            // 去掉多文件重复
            HashSet <string> map             = new HashSet <string>();
            float            totalWorldCount = 0;

            for (int i = 0, count = transMaps.Count; i < count; i++)
            {
                TranslateMapper tm = transMaps[i];
                for (int j = tm.Worlds.Count - 1; j >= 0; j--)
                {
                    TranslatorWorld transWorld = tm.Worlds[j];
                    if (map.Contains(transWorld.Source))
                    {
                        tm.Worlds.RemoveAt(j);
                    }
                    else
                    {
                        totalWorldCount += 1;
                        map.Add(transWorld.Source);
                    }
                }
            }

            StringBuilder buf             = new StringBuilder();
            int           totalWorldIndex = 0;

            for (int i = 0, count = transMaps.Count; i < count; i++)
            {
                TranslateMapper tm = transMaps[i];
                if (tm.Worlds.Count == 0)
                {
                    continue;
                }

                buf.AppendLine(string.Format("--------------------{0}", tm.FilePath));
                for (int j = 0, worldCount = tm.Worlds.Count; j < worldCount; j++)
                {
                    TranslatorWorld transWorld = tm.Worlds[j];

                    buf.AppendLine(string.Format("{0} = {1}", transWorld.Source, transWorld.Dest));

                    totalWorldIndex++;
                    EditorUtility.DisplayProgressBar("翻译", "正在导出文件...", totalWorldIndex / totalWorldCount);
                }
            }

            using (StreamWriter writer = new StreamWriter(textPath, false, System.Text.Encoding.UTF8))
            {
                writer.Write(buf.ToString());
            }
            EditorUtility.ClearProgressBar();

            string assetFilePath = textPath.Replace(Application.dataPath, "Assets");

            AssetDatabase.ImportAsset(assetFilePath);

            Selection.activeObject = AssetDatabase.LoadAssetAtPath <UnityEngine.Object>(assetFilePath);
            EditorUtility.DisplayDialog("提示", "已经成功导出为:" + languageStrArr[(int)targetLanguage], "确定");
        }
 /// <summary>
 ///     Creates a new <see cref="WithCultureJsonStringLocalizer" />.
 /// </summary>
 /// <param name="type">The base name of the embedded resource in the <see cref="Assembly" /> that contains the strings.</param>
 /// <param name="cache"></param>
 /// <param name="culture">The specific <see cref="CultureInfo" /> to use.</param>
 public WithCultureJsonStringLocalizer(string type, IJsonLocalizationCache cache, CultureInfo culture, ILogger<JsonStringLocalizer> logger, IOptions<DependencyInjection.LocalizationOptions> options, ITranslater translate)
     : base(type, cache, logger, options, translate)
 {
     _culture = culture;
 }
Пример #12
0
 public void Initialize()
 {
     _translater = new DefaultTranslator();
 }