예제 #1
0
    public static string[] HtmlRowsForMakes(string szRestrict, int skip, int pageSize)
    {
        List <string> lst = new List <string>();

        // We have no Page, so things like Page_Load don't get called.
        // We fix this by faking a page and calling Server.Execute on it.  This sets up the form and - more importantly - causes Page_load to be called on loaded controls.
        using (Page p = new FormlessPage())
        {
            p.Controls.Add(new HtmlForm());
            using (StringWriter sw1 = new StringWriter(CultureInfo.CurrentCulture))
                HttpContext.Current.Server.Execute(p, sw1, false);

            ModelQuery mq = JsonConvert.DeserializeObject <ModelQuery>(szRestrict);
            mq.Skip  = skip;
            mq.Limit = pageSize;

            foreach (MakeModel m in MakeModel.MatchingMakes(mq))
            {
                Controls_mfbMakeListItem mli = (Controls_mfbMakeListItem)p.LoadControl("~/Controls/mfbMakeListItem.ascx");
                HtmlTableRow             tr  = new HtmlTableRow();
                p.Form.Controls.Add(tr);
                HtmlTableCell tc = new HtmlTableCell();
                tr.Cells.Add(tc);
                tc.VAlign = "top";
                tc.Controls.Add(mli);
                // Now, write it out.
                StringBuilder sb = new StringBuilder();
                StringWriter  sw = null;
                try
                {
                    sw = new StringWriter(sb, CultureInfo.CurrentCulture);
                    using (HtmlTextWriter htmlTW = new HtmlTextWriter(sw))
                    {
                        sw = null;
                        try
                        {
                            mli.SortMode = mq.SortMode;
                            mli.Model    = m;
                            mli.ModelLink.NavigateUrl = VirtualPathUtility.ToAbsolute(mli.ModelLink.NavigateUrl);
                            tr.RenderControl(htmlTW);
                            lst.Add(sb.ToString());
                        }
                        catch (ArgumentException ex) when(ex is ArgumentOutOfRangeException)
                        {
                        }                                                                         // don't write bogus or incomplete HTML
                    }
                }
                finally
                {
                    if (sw != null)
                    {
                        sw.Dispose();
                    }
                }
            }
        }

        return(lst.ToArray());
    }
예제 #2
0
    public static string PopulateClub(int idClub)
    {
        StringBuilder sb = new StringBuilder();

        try
        {
            // We have no Page, so things like Page_Load don't get called.
            // We fix this by faking a page and calling Server.Execute on it.  This sets up the form and - more importantly - causes Page_load to be called on loaded controls.
            using (Page p = new FormlessPage())
            {
                p.Controls.Add(new HtmlForm());
                using (StringWriter sw1 = new StringWriter(CultureInfo.InvariantCulture))
                    HttpContext.Current.Server.Execute(p, sw1, false);

                HttpRequest r = HttpContext.Current.Request;
                if (!r.IsLocal && !r.UrlReferrer.Host.EndsWith(Branding.CurrentBrand.HostName, StringComparison.OrdinalIgnoreCase))
                {
                    throw new MyFlightbookException("Unauthorized attempt to populate club! {0}, {1}");
                }

                Club c = Club.ClubWithID(idClub);
                if (c == null)
                {
                    return(string.Empty);
                }

                Controls_ClubControls_ViewClub vc = (Controls_ClubControls_ViewClub)p.LoadControl("~/Controls/ClubControls/ViewClub.ascx");
                vc.LinkToDetails = true;
                vc.ActiveClub    = c;
                p.Form.Controls.Add(vc);

                // Now, write it out.
                StringWriter sw = null;
                try
                {
                    sw = new StringWriter(sb, CultureInfo.InvariantCulture);
                    using (HtmlTextWriter htmlTW = new HtmlTextWriter(sw))
                    {
                        sw = null;
                        vc.RenderControl(htmlTW);
                    }
                }
                finally
                {
                    if (sw != null)
                    {
                        sw.Dispose();
                    }
                }
            }
        }
        catch (MyFlightbookException ex)
        {
            sb.Append(ex.Message);
        }

        return(sb.ToString());
    }
예제 #3
0
        public static FlightRow[] HtmlRowsForFlights(string szUser, int skip, int pageSize)
        {
            System.Threading.Thread.CurrentThread.CurrentCulture = util.SessionCulture ?? CultureInfo.CurrentCulture;
            // We have no Page, so things like Page_Load don't get called.
            // We fix this by faking a page and calling Server.Execute on it.  This sets up the form and - more importantly - causes Page_load to be called on loaded controls.
            using (Page p = new FormlessPage())
            {
                p.Controls.Add(new HtmlForm());
                using (StringWriter sw = new StringWriter(CultureInfo.CurrentCulture))
                    HttpContext.Current.Server.Execute(p, sw, false);

                IEnumerable <LogbookEntry> rgle = Array.Empty <LogbookEntry>();
                if (String.IsNullOrEmpty(szUser))
                {
                    List <LogbookEntry> lst = new List <LogbookEntry>(FlightStats.GetFlightStats().RecentPublicFlights);
                    if (skip > 0)
                    {
                        lst.RemoveRange(0, Math.Min(skip, lst.Count));
                    }
                    if (lst.Count > pageSize)
                    {
                        lst.RemoveRange(pageSize, lst.Count - pageSize);
                    }
                    rgle = lst;
                }
                else
                {
                    rgle = GetFlights(szUser, skip, pageSize);
                }

                List <FlightRow> lstRows = new List <FlightRow>();
                foreach (LogbookEntry le in rgle)
                {
                    Controls_mfbPublicFlightItem pfe = (Controls_mfbPublicFlightItem)p.LoadControl("~/Controls/mfbPublicFlightItem.ascx");
                    p.Form.Controls.Add(pfe);

                    pfe.Entry = le;

                    // Now, write it out.
                    System.Text.StringBuilder sb = new System.Text.StringBuilder();
                    using (StringWriter sw = new StringWriter(sb, CultureInfo.CurrentCulture))
                    {
                        using (HtmlTextWriter htmlTW = new HtmlTextWriter(sw))
                            pfe.RenderControl(htmlTW);
                    }

                    lstRows.Add(new FlightRow()
                    {
                        HTMLRowText = sb.ToString(), FBDivID = string.Empty
                    });
                }

                return(lstRows.ToArray());
            }
        }
예제 #4
0
    public void ProcessRequest(HttpContext context)
    {
        context.Response.ContentType = "text/plain";
        context.Response.Cache.SetCacheability(HttpCacheability.NoCache);
        FormlessPage   page = new FormlessPage();
        Control        ctrl = page.LoadControl("~/RepeaterHoster.ascx");
        StringWriter   sw   = new StringWriter();
        HtmlTextWriter hw   = new HtmlTextWriter(sw);

        page.Controls.Add(ctrl);
        page.RenderControl(hw);
        context.Server.Execute(page, hw, false);
        context.Response.Write(sw.ToString());
    }
예제 #5
0
  public static string LoadControl(string UserControlPath)
  {
    FormlessPage page = new FormlessPage();
     page.EnableViewState = false;
     // Create instance of the user control
     UserControl userControl = (UserControl)page.LoadControl(UserControlPath);
     page.Controls.Add(userControl);
     //Write the control Html to text writer
     StringWriter textWriter = new StringWriter();
 
     //execute page on server
     HttpContext.Current.Server.Execute(page, textWriter, false);
 
     // Clean up code and return html
     return textWriter.ToString();
    }
예제 #6
0
    private static string LoadControl(string UserControlPath, params object[] constructorParameters)
    {
        if (!File.Exists(HttpContext.Current.Server.MapPath(UserControlPath)))
        {
            return("Invalid Short Codes!");
        }

        FormlessPage page = new FormlessPage();

        page.EnableViewState = false;

        List <Type> constParamTypes = new List <Type>();

        foreach (object constParam in constructorParameters)
        {
            constParamTypes.Add(constParam.GetType());
        }

        UserControl userControl = (UserControl)page.LoadControl(UserControlPath);

        ConstructorInfo constructor = userControl.GetType().BaseType.GetConstructor(constParamTypes.ToArray());

        if (constructor == null)
        {
            return("The requested constructor was not found on : " + userControl.GetType().BaseType.ToString());
        }
        else
        {
            constructor.Invoke(userControl, constructorParameters);
        }

        page.Controls.Add(userControl);

        StringWriter textWriter = new StringWriter();

        HttpContext.Current.Server.Execute(page, textWriter, false);
        return(textWriter.ToString());
    }