public void ClonedGadgetHasExternalMessages()
        {
            GadgetMaster master = GadgetMaster.CreateGadget(TEST_FACTORY_KEY, testData.Source);

            //This takes a long time.  Manual add of info instead.
            //GadgetProvider.FetchExternalMessageBundles(master);

            MessageBundleData.LoadSampleMessageBundles(master);


            string[] cultures = master.MyDataContext.ResourceStringCatalog.GetDefinedCultures();
            string   cult     = "";

            for (int i = 0; i < cultures.Length; i++)
            {
                cult += "|" + cultures[i];
            }
            Assert.IsTrue(cult.Contains("ru"));
            Assert.IsTrue(cult.Contains("fr"));


            Assert.IsTrue(master.HasExternalMessageBundles(), "External bundles not defined in main gadget");
            Assert.Greater(master.MasterDataContext.ResourceStringCatalog.GetDefinedCultures().Length, 0, "No locales defined in main gadget");

            GadgetMaster target = master.Clone() as GadgetMaster;

            Assert.IsNotNull(target);
            Assert.IsTrue(target.HasExternalMessageBundles(), "Clone has no bundles");
            Assert.Greater(target.MasterDataContext.ResourceStringCatalog.GetDefinedCultures().Length, 0, "No locales defined in clone gadget");

            string allMessages = master.GetConsolidatedMessageBundles();
        }
        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");
        }
        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");
        }
        public void SerializeExternalMessages()
        {
            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[] cultures = master.MyDataContext.ResourceStringCatalog.GetDefinedCultures();
            string   cult     = "";

            for (int i = 0; i < cultures.Length; i++)
            {
                cult += "|" + cultures[i];
            }
            Assert.IsTrue(cult.Contains("en"));
            Assert.IsTrue(cult.Contains("de"));

            string allMessages = master.GetConsolidatedMessageBundles();

            Assert.IsNotNull(allMessages, "Serialized messages is null");
            Assert.IsTrue(allMessages.Contains("lang=\"en\""), "English culture flag not found in response");
            Assert.IsTrue(allMessages.Contains("lang=\"de\""));

            Assert.IsTrue(allMessages.Contains(@"<msg name=""blue"">Blau</msg>"), "missing german test string");
            Assert.IsTrue(allMessages.Contains(@"<msg name=""blue"">blue</msg>"), "Missing English test string");
        }
Exemple #5
0
        public ActionResult Create(FormCollection form)
        {
            try
            {
                var appToAdd = gadgetDB.CreateObject <App>(); //new SampleWeb.Models.App();

                // Deserialize (Include white list!)
                TryUpdateModel(appToAdd, new string[] { "Name", "SourceUrl" }, form.ToValueProvider());

                appToAdd.CreateDate = DateTime.UtcNow;
                appToAdd.UpdateDate = DateTime.UtcNow;
                // Validate
                if (String.IsNullOrEmpty(appToAdd.Name))
                {
                    ModelState.AddModelError("Name", "Name required!");
                }
                if (String.IsNullOrEmpty(appToAdd.SourceUrl))
                {
                    ModelState.AddModelError("SourceUrl", "SourceUrl is required!");
                }

                // If valid, save movie to database
                if (ModelState.IsValid)
                {
                    gadgetDB.AddToApps(appToAdd);
                    gadgetDB.SaveChanges();
                }
                else
                {
                    return(View(appToAdd));
                }

                Gadget gadget = gadgetDB.CreateObject <Gadget>();
                gadget.AppID      = appToAdd.AppId;
                gadget.SourceUrl  = appToAdd.SourceUrl;
                gadget.CreateDate = appToAdd.CreateDate;
                gadget.UpdateDate = appToAdd.UpdateDate;

                gadgetDB.AddToGadgets(gadget);
                gadgetDB.SaveChanges();

                appToAdd.LatestGadgetID = gadget.GadgetID;


                GadgetMaster gMaster = GadgetManager.FetchGadget(appToAdd.SourceUrl);

                GadgetContent gContent = gadgetDB.CreateObject <GadgetContent>();
                gContent.GadgetID     = gadget.GadgetID;
                gContent.CreateDate   = appToAdd.CreateDate;
                gContent.UpdateDate   = appToAdd.UpdateDate;
                gContent.RecordTypeID = RecordTypeValues.GadgetXML;
                gContent.Content      = gMaster.RawTag;

                gadgetDB.AddToGadgetContents(gContent);
                gadgetDB.SaveChanges();

                if (gMaster.HasExternalMessageBundles())
                {
                    gContent = gadgetDB.CreateObject <GadgetContent>();
                    gContent.RecordTypeID = RecordTypeValues.MessageBundle;
                    gContent.CreateDate   = appToAdd.CreateDate;
                    gContent.UpdateDate   = appToAdd.UpdateDate;
                    gContent.Content      = gMaster.GetConsolidatedMessageBundles();
                    gadgetDB.AddToGadgetContents(gContent);
                    gadgetDB.SaveChanges();
                }

                appToAdd.LatestGadgetID = gadget.GadgetID;
                gadgetDB.SaveChanges();

                return(RedirectToAction("Details/" + appToAdd.AppId.ToString()));
            }
            catch
            {
                return(View());
            }
        }