コード例 #1
0
ファイル: makes.aspx.cs プロジェクト: xmas25/MyFlightbookWeb
    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
ファイル: ShortCodes.cs プロジェクト: kboyparilla/Evolantis
    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());
    }
コード例 #7
0
        public static string AvailabilityMap(DateTime dtStart, int clubID, int limitAircraft = Aircraft.idAircraftUnknown, int cDays = 1)
        {
            if (!IsValidCaller(clubID, PrivilegeLevel.ReadOnly))
            {
                return(null);
            }

            int minutes                 = cDays == 1 ? 15 : cDays == 2 ? 60 : 180;
            int intervalsPerDay         = (24 * 60) / minutes;
            int cellsPerHeader          = (minutes < 60) ? (60 / minutes) : Math.Max(intervalsPerDay / 2, 1);
            int totalIntervals          = cDays * intervalsPerDay;
            IDictionary <int, bool[]> d = ScheduledEvent.ComputeAvailabilityMap(dtStart, clubID, out Club club, limitAircraft = Aircraft.idAircraftUnknown, cDays, minutes);
            DateTime dtStartLocal       = new DateTime(dtStart.Year, dtStart.Month, dtStart.Day, 0, 0, 0, DateTimeKind.Local);

            CultureInfo ciCurrent = 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 sw1 = new StringWriter(ciCurrent))
                    HttpContext.Current.Server.Execute(p, sw1, false);

                // Build the map, one day at a time in 15-minute increments.

                // Our map is created - iterate through it now.
                Table t = new Table()
                {
                    CssClass = "tblAvailablityMap"
                };
                p.Form.Controls.Add(t);

                // Header row
                // Date first
                TableHeaderRow thrDate = new TableHeaderRow();
                t.Rows.Add(thrDate);
                thrDate.Cells.Add(new TableHeaderCell());  // upper left corner is blank cell
                // Add days
                for (int i = 0; i < cDays; i++)
                {
                    DateTime dt = dtStartLocal.AddDays(i);
                    thrDate.Cells.Add(new TableHeaderCell()
                    {
                        Text = dt.ToString("d", ciCurrent), ColumnSpan = intervalsPerDay, CssClass = "dateHeader"
                    });
                }

                // Now times
                TableHeaderRow thrTimes = new TableHeaderRow();
                t.Rows.Add(thrTimes);
                thrTimes.Cells.Add(new TableHeaderCell());  // upper left corner is blank cell

                // We want the time minus any minutes, but keep it localized.
                string szTimeFormat = Regex.Replace(ciCurrent.DateTimeFormat.ShortTimePattern, ":m+", string.Empty);

                for (int iHeaderCol = 0; iHeaderCol < totalIntervals; iHeaderCol += cellsPerHeader)
                {
                    DateTime dt = dtStartLocal.AddMinutes(iHeaderCol * minutes);
                    thrTimes.Cells.Add(new TableHeaderCell()
                    {
                        Text          = (dt.Minute == 0) ? dt.ToString(szTimeFormat, ciCurrent) : String.Empty,
                        ColumnSpan    = cellsPerHeader,
                        VerticalAlign = VerticalAlign.Bottom,
                        CssClass      = "timeHeader"
                    });
                }

                // Sort the aircraft by tail
                List <Aircraft> lstAc = new List <Aircraft>(club.MemberAircraft);
                lstAc.Sort((ac1, ac2) => { return(String.Compare(ac1.DisplayTailnumber, ac2.DisplayTailnumber, true, ciCurrent)); });
                foreach (Aircraft aircraft in lstAc)
                {
                    if (!d.ContainsKey(aircraft.AircraftID))    // sanity check - but should not happen
                    {
                        continue;
                    }

                    TableRow trAircraft = new TableRow();
                    t.Rows.Add(trAircraft);
                    trAircraft.Cells.Add(new TableCell()
                    {
                        Text = aircraft.DisplayTailnumber, CssClass = "avmResource"
                    });

                    for (int i = 0; i < d[aircraft.AircraftID].Length; i++)
                    {
                        bool b = d[aircraft.AircraftID][i];
                        trAircraft.Cells.Add(new TableCell()
                        {
                            CssClass = b ? "avmBusy" : (i % cellsPerHeader == 0) ? "avmAvail" : "avmAvail avmSubHour"
                        });
                    }
                }

                // Now, write it out.
                StringBuilder sb = new StringBuilder();
                using (StringWriter sw = new StringWriter(sb, ciCurrent))
                {
                    using (HtmlTextWriter htmlTW = new HtmlTextWriter(sw))
                    {
                        try
                        {
                            t.RenderControl(htmlTW);
                            return(sb.ToString());
                        }
                        catch (ArgumentException ex) when(ex is ArgumentOutOfRangeException)
                        {
                        }                                                                         // don't write bogus or incomplete HTML
                    }
                }
            }
            return(String.Empty);
        }
コード例 #8
0
        public static string ViewFlights(int idAircraft)
        {
            if (!HttpContext.Current.User.Identity.IsAuthenticated || String.IsNullOrEmpty(HttpContext.Current.User.Identity.Name))
            {
                throw new MyFlightbookException("Unauthenticated call to ViewFlights");
            }

            Aircraft ac = new Aircraft(idAircraft);

            if (String.IsNullOrWhiteSpace(ac.TailNumber) || ac.AircraftID <= 0)
            {
                throw new MyFlightbookValidationException(String.Format(CultureInfo.CurrentCulture, "No aircraft with ID {0}", idAircraft));
            }

            using (Table t = new Table())
            {
                return(FormlessPage.RenderControlsToHTML(
                           (p) =>
                {
                    p.Form.Controls.Add(t);

                    DBHelper dbh = new DBHelper("SELECT *, IF(SignatureState = 0, '', 'Yes') AS sigState FROM flights f WHERE idAircraft=?id");
                    TableRow tr = new TableRow()
                    {
                        VerticalAlign = VerticalAlign.Top
                    };
                    t.Rows.Add(tr);
                    tr.Cells.Add(new TableCell()
                    {
                        Text = "Date"
                    });
                    tr.Cells.Add(new TableCell()
                    {
                        Text = "User"
                    });
                    tr.Cells.Add(new TableCell()
                    {
                        Text = "Grnd"
                    });
                    tr.Cells.Add(new TableCell()
                    {
                        Text = "Total"
                    });
                    tr.Cells.Add(new TableCell()
                    {
                        Text = "Signed?"
                    });
                    tr.Style["font-weight"] = "bold";

                    dbh.ReadRows((comm) => { comm.Parameters.AddWithValue("id", idAircraft); },
                                 (dr) =>
                    {
                        TableRow tr2 = new TableRow()
                        {
                            VerticalAlign = VerticalAlign.Top
                        };
                        t.Rows.Add(tr2);
                        TableCell tc = new TableCell();
                        tr2.Cells.Add(tc);
                        tc.Controls.Add(new HyperLink()
                        {
                            NavigateUrl = VirtualPathUtility.ToAbsolute(String.Format(CultureInfo.InvariantCulture, "~/Member/LogbookNew.aspx/{0}?a=1", dr["idFlight"])),
                            Text = Convert.ToDateTime(dr["date"], CultureInfo.InvariantCulture).ToShortDateString(),
                            Target = "_blank"
                        });

                        tr2.Cells.Add(new TableCell()
                        {
                            Text = (string)dr["username"]
                        });
                        tr2.Cells.Add(new TableCell()
                        {
                            Text = String.Format(CultureInfo.CurrentCulture, "{0:F2}", dr["groundSim"])
                        });
                        tr2.Cells.Add(new TableCell()
                        {
                            Text = String.Format(CultureInfo.CurrentCulture, "{0:F2}", dr["totalFlightTime"])
                        });
                        tr2.Cells.Add(new TableCell()
                        {
                            Text = (string)dr["sigState"]
                        });
                    });
                },
                           (tw) =>
                {
                    t.RenderControl(tw);
                }));
            }
        }