Esempio n. 1
0
        private void LoadMessageBundles(GadgetMaster gm, string gadgetFile)
        {
            string filePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, GadgetFileList.GADGET_DIRECTORY + "\\" + gadgetFile);

            if (File.Exists(filePath))
            {
                string gadgetString = null;
                using (StreamReader sr = new StreamReader(filePath))
                {
                    gadgetString = sr.ReadToEnd();
                }
                if (!string.IsNullOrEmpty(gadgetString))
                {
                    gm.LoadConsolidatedMessageBundles(gadgetString);
                }
            }
        }
Esempio n. 2
0
        public void RoundTripConsolidatedMessages()
        {
            GadgetMaster master = new GadgetMaster(ControlFactory.GetControlFactory(TEST_FACTORY_KEY));

            Locale locale;

            locale            = new Locale(null, master);
            locale.Lang       = "en";
            locale.MessageSrc = "http://foo.com/en.xml";
            locale.LoadMessageBundle(MessageBundleData.Source_EN);

            master.ModulePrefs.AddControl(locale);

            locale            = new Locale(null, master);
            locale.Lang       = "de";
            locale.MessageSrc = "http://foo.com/de.xml";
            locale.LoadMessageBundle(MessageBundleData.Source_DE);

            master.ModulePrefs.AddControl(locale);

            string allMessages = master.GetConsolidatedMessageBundles();

            string testString = @"<msg name=""blue"">Blau</msg>";

            Assert.IsTrue(allMessages.Contains(testString), "First pass missing message");

            Assert.IsFalse(allMessages.Contains(">>"), "Consolidated contains illegal >> chars");
            Assert.IsFalse(allMessages.Contains("<<"), "Consolidated contains illegal << chars");

            GadgetMaster master2 = new GadgetMaster(ControlFactory.GetControlFactory(TEST_FACTORY_KEY));

            master2.LoadConsolidatedMessageBundles(allMessages);

            string roundTripMessages = master2.GetConsolidatedMessageBundles(true);

            Assert.IsTrue(roundTripMessages.Contains(testString), "Second pass missing message");

            GadgetMaster master3 = new GadgetMaster(ControlFactory.GetControlFactory(TEST_FACTORY_KEY));

            master3.LoadConsolidatedMessageBundles(roundTripMessages);

            Assert.IsTrue(master3.GetConsolidatedMessageBundles(true).Contains(testString), "Third pass missing message");
        }
Esempio n. 3
0
        public void ReloadSerializedMessages()
        {
            GadgetMaster master = new GadgetMaster(ControlFactory.GetControlFactory(TEST_FACTORY_KEY));

            Locale locale;

            locale            = new Locale(null, master);
            locale.Lang       = "en";
            locale.MessageSrc = "http://foo.com/en.xml";
            locale.LoadMessageBundle(MessageBundleData.Source_EN);

            master.ModulePrefs.AddControl(locale);

            locale            = new Locale(null, master);
            locale.Lang       = "de";
            locale.MessageSrc = "http://foo.com/de.xml";
            locale.LoadMessageBundle(MessageBundleData.Source_DE);

            master.ModulePrefs.AddControl(locale);

            string allMessages = master.GetConsolidatedMessageBundles();

            Assert.IsFalse(allMessages.Contains(">>"), "Consolidated contains illegal >> chars");
            Assert.IsFalse(allMessages.Contains("<<"), "Consolidated contains illegal << chars");

            GadgetMaster master2 = new GadgetMaster(ControlFactory.GetControlFactory(TEST_FACTORY_KEY));

            master2.LoadConsolidatedMessageBundles(allMessages);

            Assert.IsTrue(master2.ModulePrefs.Locales.Count > 1, "Locales not created after messagebundle load");

            string testString = "${Msg.blue}";

            string result;

            result = master2.MasterDataContext.ResolveMessageBundleVariables(testString, "de");
            Assert.AreEqual("Blau", result, "DE string failed");
            result = master2.MasterDataContext.ResolveMessageBundleVariables(testString, "en");
            Assert.AreEqual("blue", result, "EN string failed");
        }