BamlLocalization.ResourceGenerator.Generate C# (CSharp) Метод

Generate() статический приватный Метод

Generates localized Baml from translations
static private Generate ( LocBamlOptions options, BamlLocalization.TranslationDictionariesReader dictionaries ) : void
options LocBamlOptions LocBaml options
dictionaries BamlLocalization.TranslationDictionariesReader the translation dictionaries
Результат void
        internal static void Generate(LocBamlOptions options, TranslationDictionariesReader dictionaries)
        {
            // base on the input, we generate differently
            switch(options.InputType)
            {
                case FileType.BAML :
                {
                    // input file name
                    string bamlName = Path.GetFileName(options.Input);

                    // outpuf file name is Output dir + input file name
                    string outputFileName = GetOutputFileName(options);

                    // construct the full path
                    string fullPathOutput = Path.Combine(options.Output, outputFileName);

                    options.Write(StringLoader.Get("GenerateBaml", fullPathOutput));

                    using (Stream input = File.OpenRead(options.Input))
                    {
                        using (Stream output = new FileStream(fullPathOutput, FileMode.Create))
                        {
                            BamlLocalizationDictionary dictionary = dictionaries[bamlName];

                            // if it is null, just create an empty dictionary.
                            if (dictionary == null)
                                dictionary = new BamlLocalizationDictionary();

                            GenerateBamlStream(input, output, dictionary, options);
                        }
                    }

                    options.WriteLine(StringLoader.Get("Done"));
                    break;
                }
                case FileType.RESOURCES :
                {
                    string outputFileName = GetOutputFileName(options);
                    string fullPathOutput = Path.Combine(options.Output, outputFileName);

                    using (Stream input = File.OpenRead(options.Input))
                    {
                        using (Stream output = File.OpenWrite(fullPathOutput))
                        {
                            // create a Resource reader on the input;
                            IResourceReader reader = new ResourceReader(input);

                            // create a writer on the output;
                            IResourceWriter writer = new ResourceWriter(output);

                            GenerateResourceStream(
                                options,         // options
                                options.Input,   // resources name
                                reader,          // resource reader
                                writer,          // resource writer
                                dictionaries);   // translations

                            reader.Close();

                            // now generate and close
                            writer.Generate();
                            writer.Close();
                        }
                    }

                    options.WriteLine(StringLoader.Get("DoneGeneratingResource", outputFileName));
                    break;
                }
            case FileType.EXE:
                case FileType.DLL:
                {
                    GenerateAssembly(options, dictionaries);
                    break;
                }
                default:
                {
                    Debug.Assert(false, "Can't generate to this type");
                    break;
                }
            }
        }

Usage Example

Пример #1
0
        /// <summary>
        /// Genereate localized baml
        /// </summary>
        private static void GenerateBamlResources(LocBamlOptions options)
        {
            Stream input = File.OpenRead(options.Translations);

            using (ResourceTextReader reader = new ResourceTextReader(options.TranslationFileType, input))
            {
                TranslationDictionariesReader dictionaries = new TranslationDictionariesReader(reader);
                ResourceGenerator.Generate(options, dictionaries);
            }
        }
All Usage Examples Of BamlLocalization.ResourceGenerator::Generate