コード例 #1
0
        private void initializeLearningTab()
        {
            // read key name mapping table
            KeyName[] keys = SettingFiles.LoadKeyListFromFile();
            foreach (KeyName key in keys)
            {
                mKeyNameTable.Add(key.Id, key);
            }

            // init key name list view
            lvKeyList.Columns.Add(Resources.TITLE_KEY_ID, 200);
            lvKeyList.Columns.Add(Resources.TITLE_KEY_NAME, 100);
            lvKeyList.Columns.Add(Resources.TITLE_FORMAT_ID, 200);
            lvKeyList.Columns.Add(Resources.TITLE_CUSTOM_CODE, 100);
            lvKeyList.Columns.Add(Resources.TITLE_KEY_CODE, 100);

            progressBarLearning.Visible = false;   // hide initially

            // init learning result list view
            lvResultList.Columns.Add(Resources.TITLE_FORMAT_ID, 150);
            lvResultList.Columns.Add(Resources.TITLE_CUSTOM_CODE, 80);
            lvResultList.Columns.Add(Resources.TITLE_KEY_CODE, -2);

            // add default keys
            AddDefaultLearningKeys();
            if (lvKeyList.Items.Count > 0 && lvKeyList.SelectedIndices.Count == 0)
            {
                lvKeyList.Items[0].Selected = true;
            }

            mMyIrReader = Kit.createIRReader(Settings.Default.ALWAYS_PULL_DATA_FROM_CLOUD);
        }
コード例 #2
0
        /// <summary>
        /// The main method that the system performs.  It is responsible for directing the
        /// operation of the entire compiler.
        /// </summary>
        /// <param name="input"> The input path that needs to be used. </param>
        /// <param name="output" The output path that needs to be used. ></param>
        /// <returns></returns>
        public static bool Compile(string @input, string @output)
        {
            // Try to validate that input path.
            try
            {
                ValidatePath(@input);
            }
            catch (FileNotFoundException exception)
            {
                // Show the exception and return with a flag of false.
                Console.WriteLine(exception);
                return(SuccessFlag);
            }

            // Instantiate the frontend and backends for the compiler,
            // this is where a programmer would add their own implementations.
            IFrontend frontend = new TinySvgFrontend();
            IBackend  backend  = new HpglBackend();

            // Get the statements from the input file using the appropriate reader.
            var statements = frontend.Read(input);

            // Tokenise the statements.
            var lexemes = frontend.Lex(statements);

            // Parse the tokens to an intermediate representation.
            frontend.Parse(lexemes);

            // Read the tokens from the IR file and pass it to the appropriate
            // backend writer file.
            JsonRoot s = IRReader.Read();

            backend.WriteFile(s, output);

            // If all this has happened with no errors set the successflag to true.
            SuccessFlag = true;
            return(SuccessFlag);
        }
コード例 #3
0
        private void DoInitDownload(object sender, DoWorkEventArgs e)
        {
            BackgroundWorker worker = (BackgroundWorker)sender;

            String languageCode = (String)e.Argument;

            int currentProgress = 0;

            worker.ReportProgress(currentProgress, Resources.I_DOWNLOADING_TYPES);

            if (worker.CancellationPending)
            {
                e.Cancel = true;
                return;
            }

            // get types
            TypeItem[] types = Web.getTypeList(languageCode, mGetNew, null);
            SettingFiles.SaveTypeListToFile(types);

            // get brands
            int progressPartForBrand    = 40 / types.Length;
            int progressPartForKey      = 40 / types.Length;
            int progressPartForIrReader = 20;

            BrandItem[] brands;
            Dictionary <String, KeyName> keyMap = new Dictionary <String, KeyName>();

            for (int i = 0; i < types.Length; i++)
            {
                if (worker.CancellationPending)
                {
                    e.Cancel = true;
                    return;
                }

                currentProgress += progressPartForBrand;
                worker.ReportProgress(currentProgress,
                                      String.Format(Resources.I_DOWNLOADING_BRANDS + " {0}/{1}", i + 1, types.Length));

                brands = Web.getBrandList(types[i].Id, 0, 2000, languageCode, null, mGetNew, null);
                if (null != brands)
                {
                    SettingFiles.SaveBrandListToFile(types[i].Id, brands);
                }
                else
                {
                    e.Result = false;
                    return;
                }

                if (worker.CancellationPending)
                {
                    e.Cancel = true;
                    return;
                }

                currentProgress += progressPartForKey;
                worker.ReportProgress(currentProgress,
                                      String.Format(Resources.I_DOWNLOADING_KEYS + "  {0}/{1}", i + 1, types.Length));

                KeyName[] keys = Web.getKeyName(types[i].Id, languageCode, mGetNew, null);
                if (null != keys)
                {
                    foreach (KeyName key in keys)
                    {
                        if (!keyMap.ContainsKey(key.Id))
                        {
                            keyMap.Add(key.Id, key);
                        }
                    }
                }
                else
                {
                    e.Result = false;
                    return;
                }
            }

            if (worker.CancellationPending)
            {
                e.Cancel = true;
                return;
            }

            currentProgress += progressPartForIrReader / 2;
            worker.ReportProgress(currentProgress, Resources.I_DOWNLOADING_FORMATS);
            // IRReader
            IRReader irReader = Kit.createIRReader(mGetNew);

            if (null == irReader)
            {
                e.Result = false;
                return;
            }
            worker.ReportProgress(100, Resources.COMPLETED);

            List <KeyName> keyList = new List <KeyName>();

            foreach (KeyValuePair <String, KeyName> entry in keyMap)
            {
                keyList.Add(entry.Value);
            }

            if (keyList.Count > 0)
            {
                SettingFiles.SaveKeyListToFile(keyList.ToArray());
            }
            else
            {
                e.Result = false;
                return;
            }

            e.Result = true;
        }