Esempio n. 1
0
        protected void LoadResource(string pluginName)
        {
            string path;

            try
            {
                path = HttpContext.Current.Server.MapPath("/").Replace("IUDICO.LMS", pluginName);
            }
            catch (Exception)
            {
                path = Path.Combine(Assembly.GetExecutingAssembly().CodeBase.Remove(0, 8) + @"\..\..\..\..\", pluginName) + @"\";
            }

            this.resource.Add(pluginName, new Dictionary<string, Dictionary<string, string>>());

            foreach (var culture in Cultures)
            {
                try
                {
                    var resourceReader = new ResXResourceReader(path + "Resource." + culture + ".resx");
                    var resourceEntries = resourceReader.Cast<DictionaryEntry>().ToDictionary(d => d.Key.ToString(), d => d.Value.ToString());

                    this.resource[pluginName].Add(culture, resourceEntries);
                }
                catch (Exception)
                {
                    
                }
            }
        }
Esempio n. 2
0
        public void AddDoubleKey()
        {
            PanelViewModel panelViewModel = new PanelViewModel(_model.RootPanel) { RuDescription = "Комент", FieldInDb = "Key1" };
            _model.RootPanel.Children.Add(panelViewModel);
            //Добавляем ключь, должны добавится в оба словаря
            _model.WriteResourses();
            //Проверяем
            ResXResourceReader reader = new ResXResourceReader(_model.ResourceFilePath);
            var dictionary = reader.Cast<DictionaryEntry>();
            Assert.AreEqual(1, dictionary.Count());
            reader.Close();

            reader = new ResXResourceReader(_model.ResourceFilePath.Replace(".resx", ".ru-RU.resx"));
            dictionary = reader.Cast<DictionaryEntry>();
            Assert.AreEqual(1, dictionary.Count());
            reader.Close();
        }
Esempio n. 3
0
        public void AddNewKeyTest()
        {
            PanelViewModel panelViewModel = new PanelViewModel(_model.RootPanel) { RuDescription = "Комент", FieldInDb = "Id1" };
            _model.RootPanel.Children.Add(panelViewModel);
            //Добавляем ключь, должны добавится в оба словаря
            _model.WriteResourses();
            //Проверяем
            ResXResourceReader reader = new ResXResourceReader(_model.ResourceFilePath);
            var dictionary = reader.Cast<DictionaryEntry>();
            Assert.AreEqual(2, dictionary.Count());
            Assert.IsNotNull(dictionary.FirstOrDefault(i => (string) i.Key == "Id1"));
            reader.Close();

            reader = new ResXResourceReader(_model.ResourceFilePath.Replace(".resx", ".ru-RU.resx"));
            dictionary = reader.Cast<DictionaryEntry>();
            Assert.AreEqual(2, dictionary.Count());
            Assert.IsNotNull(dictionary.FirstOrDefault(i => (string) i.Key == "Id1"));
            reader.Close();
        }
Esempio n. 4
0
 private static Dictionary<string, object> ReadAllResxEntries(Stream resxStream)
 {
     using (var reader = new ResXResourceReader(resxStream))
     {
         return reader
             .Cast<DictionaryEntry>()
             .ToDictionary(entry => (string)entry.Key, entry => entry.Value);
     }
 }
Esempio n. 5
0
        public void AddRecursiveKey()
        {
            PanelViewModel panel1 = new PanelViewModel(_model.RootPanel);
            panel1.FieldInDb = "fl1";
            _model.RootPanel.Children.Add(panel1);

            PanelViewModel panel2 = new PanelViewModel(panel1);
            panel2.FieldInDb = "fl2";
            panel1.Children.Add(panel2);

            PanelViewModel panel3 = new PanelViewModel(panel2);
            panel3.FieldInDb = "fl3";
            panel2.Children.Add(panel3);
            //Добавляем ключь, должны добавится в оба словаря
            _model.WriteResourses();
            //Проверяем
            ResXResourceReader reader = new ResXResourceReader(_model.ResourceFilePath);
            var dictionary = reader.Cast<DictionaryEntry>();
            Assert.IsNotNull(dictionary.FirstOrDefault(i => i.Key == "fl1"));
            Assert.IsNotNull(dictionary.FirstOrDefault(i => i.Key == "fl2"));
            Assert.IsNotNull(dictionary.FirstOrDefault(i => i.Key == "fl3"));
            Assert.AreEqual(4, dictionary.Count());
            reader.Close();

            reader = new ResXResourceReader(_model.ResourceFilePath.Replace(".resx", ".ru-RU.resx"));
            dictionary = reader.Cast<DictionaryEntry>();
            Assert.IsNotNull(dictionary.FirstOrDefault(i => i.Key == "fl1"));
            Assert.IsNotNull(dictionary.FirstOrDefault(i => i.Key == "fl2"));
            Assert.IsNotNull(dictionary.FirstOrDefault(i => i.Key == "fl3"));
            Assert.AreEqual(4, dictionary.Count());
            reader.Close();
        }
        private void TestWrite(
            Func<System.Data.Entity.Migrations.Utilities.MigrationWriter, ScaffoldedMigration, string> action,
            bool skipUserCodeVerification = false)
        {
            var command = CreateCommand(_projectDir);
            var writer = new System.Data.Entity.Migrations.Utilities.MigrationWriter(command);
            var scaffoldedMigration = new ScaffoldedMigration
                                          {
                                              MigrationId = MigrationId,
                                              Language = Language,
                                              Directory = MigrationsDirectory,
                                              UserCode = "The user code.",
                                              DesignerCode = "The designer code.",
                                              Resources =
                                                  {
                                                      { ResourceName, "The resource." }
                                                  }
                                          };

            var relativeUserCodePath = action(writer, scaffoldedMigration);

            Assert.Equal(UserCodePath, relativeUserCodePath);

            if (!skipUserCodeVerification)
            {
                var userCodePath = Path.Combine(_projectDir, UserCodePath);
                Assert.Equal("The user code.", File.ReadAllText(userCodePath));
            }

            var designerCodePath = Path.Combine(_projectDir, DesignerCodePath);
            Assert.Equal("The designer code.", File.ReadAllText(designerCodePath));

            var resourcesPath = Path.Combine(_projectDir, ResourcesPath);

            using (var reader = new ResXResourceReader(resourcesPath))
            {
                var resources = reader.Cast<DictionaryEntry>();

                Assert.Equal(1, resources.Count());
                Assert.Contains(new DictionaryEntry(ResourceName, "The resource."), resources);
            }
        }
Esempio n. 7
0
        public int AddOrUpdateResource(string key, string value, int forceupdate = 0)
        {
            int result = 0;

            var resx = new List<DictionaryEntry>();
            string resourceFilepath = "D:\\LC\\OCR\\Convertor\\Licence\\info.resx";
            using (var reader = new ResXResourceReader(resourceFilepath))
            {
                resx = reader.Cast<DictionaryEntry>().ToList();
                var existingResource = resx.Where(r => r.Key.ToString() == key).FirstOrDefault();
                if (existingResource.Key == null && existingResource.Value == null) // NEW!
                {
                    resx.Add(new DictionaryEntry() { Key = key, Value = value });
                    result = 1;
                }

                if (forceupdate == 0)
                {
                    if (existingResource.Key != null && (existingResource.Value == null || existingResource.Value == "")) // NEW!
                    {
                        var modifiedResx = new DictionaryEntry() { Key = existingResource.Key, Value = value };
                        resx.Remove(existingResource);  // REMOVING RESOURCE!
                        resx.Add(modifiedResx);  // AND THEN ADDING RESOURCE!
                        result = 1;
                    }
                }
                if (forceupdate == 1)
                {
                    if (existingResource.Key != null) // NEW!
                    {
                        var modifiedResx = new DictionaryEntry() { Key = existingResource.Key, Value = value };
                        resx.Remove(existingResource);  // REMOVING RESOURCE!
                        resx.Add(modifiedResx);  // AND THEN ADDING RESOURCE!
                        result = 1;
                    }

                }
            }
            if (result > 0)
            {
                using (var writer = new ResXResourceWriter(resourceFilepath))
                {
                    resx.ForEach(r =>
                    {
                        // Again Adding all resource to generate with final items
                        writer.AddResource(r.Key.ToString(), r.Value.ToString());
                    });
                    writer.Generate();
                }
            }
            return result;
        }
        /// <summary>
        /// Executes the Task
        /// </summary>
        /// <returns>True if success</returns>
        public bool Execute()
        {
            if (!this.EmbeddedResourcesItems.Any())
            {
                this.BuildEngine.LogMessageEvent(
                    new BuildMessageEventArgs(
                        string.Format(
							"Skipping conversion of Resource files to Pseudo-Loc, as there are no resource files found in the project. If your resx file is not being picked up, check if the file is marked for build action = 'Embedded Resource'"),
                        string.Empty,
						"PseudoLocResx",
                        MessageImportance.Normal));
            }

            var args = new BuildMessageEventArgs(
                "Started converting Resx To Pseudo-Loc",
                string.Empty,
				"PseudoLocResx",
                MessageImportance.Normal);

            this.BuildEngine.LogMessageEvent(args);
            foreach (var embeddedResourcesItem in this.EmbeddedResourcesItems)
            {
	            var lang = this.GetCultureInfo(embeddedResourcesItem.ItemSpec);
	            if (lang == null)
	            {
		            this.BuildEngine.LogMessageEvent(
			            new BuildMessageEventArgs(
							string.Format("Started converting Resx {0} to Pseudo-Loc", embeddedResourcesItem.ItemSpec),
							string.Empty,
							"PseudoLocResx",
							MessageImportance.Normal));


		            var outputFileName = Path.Combine(
			            Path.GetDirectoryName(embeddedResourcesItem.ItemSpec),
						Path.GetFileNameWithoutExtension(embeddedResourcesItem.ItemSpec) + string.Format(".{0}.resx", locale));

		            var strings = new Dictionary<string, object>();
		            using (var rsxr = new ResXResourceReader(embeddedResourcesItem.ItemSpec))
		            {
			            rsxr.UseResXDataNodes = true;
			            strings = rsxr.Cast<DictionaryEntry>()
									.ToDictionary(x => x.Key.ToString(), x => ((ResXDataNode)x.Value).GetValue((ITypeResolutionService)null));
		            }

		            using (ResXResourceWriter resourceWriter = new ResXResourceWriter(outputFileName))
		            {
			            foreach (var entry in strings)
			            {
				            if (entry.Value is string)
				            {
					            var value = entry.Value as string;
					            CultureInfo ci = null;

					            if (value.TryParse(out ci))
						            resourceWriter.AddResource(entry.Key, locale);
					            else
						            resourceWriter.AddResource(entry.Key, value.ToPseudo());
				            }
				            else
				            {
					            resourceWriter.AddResource(entry.Key, entry.Value);
				            }
			            }

			            this.BuildEngine.LogMessageEvent(
				            new BuildMessageEventArgs(
								string.Format("Generated pseudo-loc file {0}", outputFileName),
								string.Empty,
								"PseudoLocResx",
								MessageImportance.Normal));
			            resourceWriter.Generate();
		            }
	            }
            }

            return true;
        }
Esempio n. 9
0
 private void WriteResource(string path, bool ru)
 {
     using (ResXResourceReader reader = new ResXResourceReader(path))
     {
         var dictionary = reader.Cast<DictionaryEntry>();
         using (ResXResourceWriter writer = new ResXResourceWriter(path))
         {
             foreach (DictionaryEntry dictionaryEntry in dictionary)
                 writer.AddResource(dictionaryEntry.Key.ToString(), dictionaryEntry.Value.ToString());
             foreach (WebPageBaseViewModel webPageBaseViewModel in RootPanel.Children.Flatten(i => i.Children))
             {
                 writer.AddResource(webPageBaseViewModel.FieldInDb, ru ? webPageBaseViewModel.RuDescription : webPageBaseViewModel.EnDescription);
             }
             writer.Generate();
         }
     }
 }