RunHook() private method

private RunHook ( string name, object data = null ) : dynamic,
name string
data object
return dynamic,
Ejemplo n.º 1
0
    public virtual object Edit(dynamic request)
    {
        var     newId = request.Form["Id"];
        dynamic item  = new ExpandoObject();

        item.Id      = request.Form["OldId"];
        item.Title   = request.Form["Title"];
        item.Content = request is HttpRequestBase?Validation.Unvalidated(request, "Content")
                           : request.Form["Content"];

        item = SiteEngine.RunHook(UPDATE_ITEM, item);

        if (string.IsNullOrEmpty(newId) || item.Id == newId)
        {
            item = this.Model.Update(item).Value;
        }
        else
        {
            item = this.Model.SaveAs(item, newId).Value;
        }

        if (this.Model.HasError)
        {
            item.Errors = Model.Errors;
            return(RenderView((ExpandoObject)item));
        }
        else
        {
            return(Redirect(item.Id));
        }
    }
Ejemplo n.º 2
0
    public object PageList(string[] urlData)
    {
        var data = new ExpandoObject();

        ((dynamic)data).List = SiteEngine.RunHook("get_pages_by_tag", urlData[0]);
        return(RenderView(data));
    }
Ejemplo n.º 3
0
    private static void HandleResult(dynamic page, dynamic val)
    {
        //Assert.IsTrue(val != null);
        if (val == null)
        {
            return;
        }

        if (val is string)
        {
            page.Page.Text = val;
        }
        else if (val is ExpandoObject)
        {
            if (((ExpandoObject)val).HasProperty("Redirect"))
            {
                page.Page.Redirect = val.Redirect;
            }
            else
            {
                page.Page.Model = val.Model;
                page.Page.Hook  = val.PageHook;
                page.Page.View  = SiteEngine.RunHook(val.ViewHook, val.DefaultView) as string;
                if (val.Model is ExpandoObject && ((ExpandoObject)val.Model).HasProperty("Title"))
                {
                    page.Page.Title = val.Model.Title;
                }
            }
        }
    }
Ejemplo n.º 4
0
    public void Edit_Post_Should_Handle_Error()
    {
        dynamic data = new ExpandoObject();

        data.Id = "id";

        dynamic model = new Mock();

        model.Setup("Update", new object[] { It.Is <dynamic>(item => item.Id == "id") }, model);
        model.SetupGet("Value", data);
        model.SetupGet("HasError", true); // this raises validation error
        model.SetupGet("Errors", "x");

        var form = new NameValueCollection();

        form["OldId"] = "id";

        dynamic page       = new MockPost(new string[] { "Pages", "Edit", "id" }, form);
        var     controller = new PageController();

        controller.Model = model;

        Mvc.Run(page, controller);

        var view = SiteEngine.RunHook("GET_Pages_Page_Edit_View", page.Page.View) as string;

        Assert.AreEqual(view, page.Page.View);        //stayed on edit page
        Assert.AreEqual("x", page.Page.Model.Errors); // pushed error message
        model.Verify();
    }
Ejemplo n.º 5
0
    private void Assert_ShowDefaultPage(MockWebPage page)
    {
        var view = SiteEngine.RunHook("GET_Pages_Page_Detail_View", page.Page.View) as string;

        Assert.AreEqual(view, page.Page.View);
        Assert.AreEqual("Default", page.Page.Model.Id);
    }
Ejemplo n.º 6
0
    public object EditMenu(NameValueCollection form)
    {
        dynamic menu = form["Menu"];

        return(RenderView(
                   SiteEngine.RunHook("get_menu_view", "Menu_Edit") as string,
                   SiteEngine.RunHook("save_menu", menu)));
    }
Ejemplo n.º 7
0
    public virtual object Delete(string id)
    {
        dynamic item = new ExpandoObject();

        item.Id = id;
        SiteEngine.RunHook(DELETE_ITEM, item);
        this.Model.Delete(item);
        return(Redirect("List"));
    }
Ejemplo n.º 8
0
    public static SiteSettings New()
    {
        dynamic value = new ExpandoObject();

        value = SiteEngine.RunHook("get_site_settings", value);
        return(new SiteSettings {
            Value = value
        });
    }
Ejemplo n.º 9
0
    public static SiteSettings Load()
    {
        var settings = new SiteSettings();

        settings.Value = new Repository("").Load(FileName);
        settings.Value = SiteEngine.RunHook("get_site_settings", settings.Value);
        //Log.Enabled = ((ExpandoObject)settings.Value).HasProperty("EnableLog", "on");
        return(settings);
    }
Ejemplo n.º 10
0
    public virtual object Create()
    {
        //check access
        dynamic newitem = new ExpandoObject();

        newitem.Id    = null as string;
        newitem.Title = string.Format("[New {0}]", this.ContentType);
        newitem       = SiteEngine.RunHook(NEW_ITEM, newitem);
        return(RenderView((ExpandoObject)newitem));
    }
Ejemplo n.º 11
0
    public virtual object List(string[] urlData)
    {
        int pageNo   = urlData.Length > 1 && int.TryParse(urlData[1], out pageNo) ? pageNo : 1;
        int pageSize = urlData.Length > 2 && int.TryParse(urlData[2], out pageSize) ? pageSize : 20;

        dynamic data = this.Model.List(pageNo, pageSize).Value;

        data.Title = this.ModuleName;
        data       = SiteEngine.RunHook(GET_LIST, data);
        return(RenderView((ExpandoObject)data));
    }
Ejemplo n.º 12
0
    protected ExpandoObject GetItemById(string id)
    {
        if (string.IsNullOrWhiteSpace(id))
        {
            return(null);
        }

        dynamic item = new ExpandoObject();

        item.Id = id;
        item    = Model.Load(item).Value;
        return(SiteEngine.RunHook(GET_ITEM, item));
    }
Ejemplo n.º 13
0
    public virtual object Create(dynamic request)
    {
        dynamic item = new ExpandoObject();

        item.Title   = request.Form["Title"];
        item.Content = request is HttpRequestBase?Validation.Unvalidated(request, "Content")
                           : request.Form["Content"];

        item = this.Model.Create(item).Value;
        item = SiteEngine.RunHook(UPDATE_ITEM, item);

        if (this.Model.HasError)
        {
            item.Errors = Model.Errors;
            return(RenderView((ExpandoObject)item));
        }
        else
        {
            return(Redirect(item.Id));
        }
    }
Ejemplo n.º 14
0
    public void Edit_Get()
    {
        dynamic data = new ExpandoObject();

        data.Id = "id";
        dynamic model = new Mock();

        model.Setup("Load", new object[] { It.Is <dynamic>(item => item.Id == "id") }, model);
        model.SetupGet("Value", data);

        dynamic page       = new MockGet(new string[] { "Pages", "Edit", "id" });
        var     controller = new PageController();

        controller.Model = model;

        Mvc.Run(page, controller);
        var view = SiteEngine.RunHook("GET_Pages_Page_Edit_View", page.Page.View) as string;

        Assert.AreEqual(view, page.Page.View);
        Assert.AreEqual("id", page.Page.Model.Id);
        model.Verify();
    }
Ejemplo n.º 15
0
 public object EditMenu()
 {
     return(RenderView(
                SiteEngine.RunHook("get_menu_view", "Menu_Edit") as string,
                SiteEngine.RunHook("get_menu", "")));
 }
Ejemplo n.º 16
0
    public void Get_Site_Settings_HookTest()
    {
        dynamic a = SiteEngine.RunHook("get_site_settings", new ExpandoObject());

        Assert.IsTrue(a.Template == "Default");
    }