示例#1
0
        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();
        }
示例#2
0
        public void ProcessRequest(HttpContext context)
        {
            string gadgetFile     = context.Request["gadget"];
            string gadgetString   = null;
            string controlFactory = "gadget_v1.0";

            if (!string.IsNullOrEmpty(gadgetFile))
            {
                string filePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, GadgetFileList.GADGET_DIRECTORY + "\\" + gadgetFile);
                if (File.Exists(filePath))
                {
                    using (StreamReader sr = new StreamReader(filePath))
                    {
                        gadgetString = sr.ReadToEnd();
                    }
                    GadgetMaster gm = GadgetMaster.CreateGadget(controlFactory, gadgetString);

                    if (gm.HasExternalMessageBundles())
                    {
                        LoadMessageBundles(gm, gadgetFile);
                    }

                    if (gm.HasExternalTemplateLibraries())
                    {
                        LoadTemplates(gm, gadgetFile);
                    }

                    context.Response.StatusCode  = 200;
                    context.Response.ContentType = "text/html";
                    StreamWriter writer = new StreamWriter(context.Response.OutputStream);
                    gm.Render(writer);                     //or  context.Response.Write(gm.RenderToString());
                }
                else
                {
                    context.Response.ContentType = "text/plain";
                    context.Response.StatusCode  = 400;
                    context.Response.Write("File not found: " + gadgetFile);
                }
            }
            else if (context.Request.HttpMethod.Equals("post", StringComparison.InvariantCultureIgnoreCase))
            {
                //check for form post
                gadgetString = context.Request.Form["source"];
                if (string.IsNullOrEmpty(gadgetString))
                {
                    context.Response.ContentType = "text/plain";
                    context.Response.StatusCode  = 400;
                    context.Response.Write("No content posted to render");
                }
                else
                {
                    //gadgetString = gadgetString.Trim();
                    string tmp = context.Request.Form["parser"];
                    if (!string.IsNullOrEmpty(tmp))
                    {
                        controlFactory = tmp;
                    }
                    ControlFactory cf = ControlFactory.GetControlFactory(controlFactory);

                    RootElementMaster rm = cf.BuildControlTree(gadgetString);
                    rm.MyDataResolver            = new SimpleDataPipelineResolver();
                    context.Response.StatusCode  = 200;
                    context.Response.ContentType = "text/html";

                    if (rm.Errors.HasParseErrors())
                    {
                        context.Response.Write("<div style='border:2px solid red;'><ul>");
                        foreach (var err in rm.Errors.ParseErrors)
                        {
                            context.Response.Write("<li>");
                            context.Response.Write(err.ToString());
                            context.Response.Write("</li>");
                        }
                        context.Response.Write("</ul></div>");
                    }

                    StreamWriter writer = new StreamWriter(context.Response.OutputStream);
                    writer.AutoFlush = true;
                    rm.Render(writer);
                }
            }
            else
            {
                context.Response.StatusCode  = 200;
                context.Response.ContentType = "text/html";
                context.Response.Write("[No content specified]");
            }
        }
示例#3
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());
            }
        }