Ejemplo n.º 1
0
        public IEnumerable <ITranslation> GetStringsFromDriveCustomization(IDriveCustomizationXmlProvider driveCustomizationXmlProvider)
        {
            XDocument doc = null;

            using (Stream stream = driveCustomizationXmlProvider.XmlStream)
            {
                doc = XDocument.Load(stream);
            }
            return(GetStringsFromXml(driveCustomizationXmlProvider.NameSpace, doc));
        }
        public CustomLanguageManager(IDeviceStringReader deviceStringReader, IDeviceXmlProvider deviceXmlProvider, IDriveCustomizationStringReader driveCustomizationStringReader, IDriveCustomizationXmlProvider driveCustomizationXmlProvider, ILanguageFileGenerator languageFileGenerator, IStringsChangedNotifier stringsChangedNotifier)
        {
            this.deviceStringReader             = deviceStringReader as IDeviceStringReader1;
            this.deviceXmlProvider              = deviceXmlProvider as IDeviceXmlProvider1;
            this.driveCustomizationStringReader = driveCustomizationStringReader;
            this.driveCustomizationXmlProvider  = driveCustomizationXmlProvider;
            this.languageFileGenerator          = languageFileGenerator;
            this.stringsChangedNotifier         = stringsChangedNotifier;

            currentProject = new CustomLanguageProject();
            SetSelectedLanguageAndReferenceLanguage();

            if (stringsChangedNotifier != null)
            {
                stringsChangedNotifier.DeviceChanged             += StringsChangedNotifier_DeviceChanged;
                stringsChangedNotifier.DriveCustomizationChanged += StringsChangedNotifier_DriveCustomizationChanged;
            }
        }
        public void ImportDriveCustomizationXmlFile(IDriveCustomizationStringReader driveCustomizationStringReader, IDriveCustomizationXmlProvider driveCustomizationXmlProvider)
        {
            SaveOriginalTranslations(true);

            ClearAllSoftTranslations();
            AddLanguageStringCollection(driveCustomizationStringReader, driveCustomizationXmlProvider);

            RestoreOriginalTranslations();
            DriveCustomizationSignature        = driveCustomizationStringReader.DriveCustomizationSignature;
            DriveCustomizationSignaturePre3570 = driveCustomizationStringReader.DriveCustomizationSignaturePre3570;
            CompilerWarning = driveCustomizationStringReader.CompilerWarning;
        }
        private void AddLanguageStringCollection(IDriveCustomizationStringReader driveCustomizationStringReader, IDriveCustomizationXmlProvider driveCustomizationXmlProvider)
        {
            try
            {
                List <ITranslation> softStrings = driveCustomizationStringReader.GetStringsFromDriveCustomization(driveCustomizationXmlProvider).ToList();
                int minId = softStrings.Min(t => t.StringId);
                int maxId = softStrings.Max(t => t.StringId);
                SoftStringCount = Convert.ToUInt16(maxId - minId + 1);// Convert.ToUInt16(softStrings.Count);

                LanguageStringCollections[0].Translations.AddRange(softStrings);
                //Find missing stringIds
                foreach (var als in LanguageStringCollections)
                {
                    var list   = als.Translations.Select(s => s.StringId).OrderBy(i => i);
                    var result = Enumerable.Range(minId, SoftStringCount).Except(list);
                    als.Translations.AddRange(
                        from missing in result
                        select new Translation()
                    {
                        IsSoftString = true,
                        StringId     = missing,
                        String       = String.Empty
                    }
                        );
                    als.Translations.Sort();
                }
                LanguageStringCollections.Sort();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }