Beispiel #1
0
        /// <summary>
        /// We're about to render the page - search for the soils and write names to the
        /// response. The iPad soil app uses this method.
        /// </summary>
        protected void Page_PreRender(object sender, EventArgs e)
        {
            Response.Clear();
            Response.ContentType     = "text/plain";
            Response.ContentEncoding = System.Text.Encoding.UTF8;

            if (Request.QueryString["Name"] != null)
            {
                string SoilName = Request.QueryString["Name"];

                ApsoilWeb.Service SoilsDB = new Apsoil.ApsoilWeb.Service();
                XmlDocument       Doc     = new XmlDocument();
                Doc.LoadXml(SoilsDB.SoilXML(SoilName));

                MemoryStream MemStream = new MemoryStream(10000);
                Doc.Save(MemStream);
                if (MemStream.ToArray() != null)
                {
                    Response.BinaryWrite(MemStream.ToArray());
                }
            }
            else if (Request.QueryString["NameJSON"] != null)
            {
                string SoilName = Request.QueryString["NameJSON"];

                ApsoilWeb.Service SoilsDB = new Apsoil.ApsoilWeb.Service();
                Response.Write(SoilsDB.SoilAsJson(SoilName));
            }
            Response.End();
        }
Beispiel #2
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Request.QueryString["Name"] != null)
            {
                string FileName = Path.GetFileName(Request.QueryString["Name"]);

                Response.Clear();
                Response.AppendHeader("Content-Disposition", "inline; filename=" + FileName + ".csv");
                //Response.AppendHeader("Content-Disposition", "csv; Soils.csv");
                Response.Buffer      = false;
                Response.ContentType = "application/vnd.ms-excel"; // text/plain

                string SoilName = Request.QueryString["Name"];

                ApsoilWeb.Service SoilsDB = new Apsoil.ApsoilWeb.Service();
                Soil Soil = Soil.Create(SoilsDB.SoilXML(SoilName));

                DataTable Data = new DataTable();
                SoilDataTable.SoilToTable(Soil, Data);

                Response.Write(DataTableUtility.DataTableToCSV(Data, 0));
                Response.Flush();                 // send our content to the client browser.
                Response.SuppressContent = true;  // stops .net from writing it's stuff.
            }
        }
Beispiel #3
0
        /// <summary>User has clicked on show XML button.</summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
        protected void ShowXMLClick(object sender, EventArgs e)
        {
            XmlDocument doc = new XmlDocument();

            doc.AppendChild(doc.CreateElement("folder"));
            XmlHelper.SetAttribute(doc.DocumentElement, "name", "Soils");
            using (ApsoilWeb.Service soilsDB = new Apsoil.ApsoilWeb.Service())
            {
                foreach (string path in GetSelectedItems())
                {
                    XmlDocument localXml = new XmlDocument();
                    localXml.LoadXml(soilsDB.SoilXML(path));
                    doc.DocumentElement.AppendChild(doc.ImportNode(localXml.DocumentElement, true));
                }
            }
            StringWriter writer = new StringWriter();

            writer.Write(XmlHelper.FormattedXML(doc.DocumentElement.OuterXml));
            ShowString(writer.ToString());
        }
Beispiel #4
0
        /// <summary>Check selected soils and show error messages.</summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void OnCheckSoilsClick(object sender, EventArgs e)
        {
            string labelText = string.Empty;

            using (ApsoilWeb.Service soilsDB = new Apsoil.ApsoilWeb.Service())
            {
                foreach (ListItem item in ListBox.Items)
                {
                    if (item.Selected)
                    {
                        string soilPath = item.Text;
                        Soil   soil     = Soil.Create(soilsDB.SoilXML(soilPath));
                        string messages = soil.Check(true);
                        if (messages != string.Empty)
                        {
                            labelText += soilPath + "\r\n";
                            labelText += messages + "\r\n";
                        }
                    }
                }
            }
            label3.Text = labelText.Replace("\r\n", "<br/>");
        }
Beispiel #5
0
        /// <summary>
        /// This is called directly by Google Earth when it wants KML data.
        /// </summary>
        private byte[] NetworkLinkData()
        {
            kml      KmlContent = new kml();
            Document KmlDoc     = new Document("Test", "");

            KmlContent.Documents.Add(KmlDoc);

            KML_22_Beta1.Style APSRUIcon = new KML_22_Beta1.Style();
            APSRUIcon.IconStyle.Icon.Href.Text = "http://apsimdev.apsim.info/ApsoilWeb/shovel.png";
            APSRUIcon.IconStyle.Scale.Value    = 0.7;
            APSRUIcon.LabelStyle.Scale.Value   = 0.7;
            APSRUIcon.id = "APSRUIconID";
            KmlDoc.StyleSelector.Style.Add(APSRUIcon);

            Dictionary <string, Folder> Folders = new Dictionary <string, Folder>();

            ApsoilWeb.Service SoilsDB = new Apsoil.ApsoilWeb.Service();
            foreach (string Name in SoilsDB.AllSoilNames(false))
            {
                string FolderName = Name;
                if (FolderName.Contains("/"))
                {
                    FolderName = FolderName.Substring(0, FolderName.LastIndexOf('/'));
                }

                Soil Soil = Soil.Create(SoilsDB.SoilXML(Name));
                if (Soil != null)
                {
                    string BalloonDescription = "<p><b>" + Soil.Name + "</b></p><p><i>"
                                                + Soil.Comments + "</i></p>";

                    string DataSourceComments = Soil.DataSource;
                    if (DataSourceComments != null && DataSourceComments != "")
                    {
                        BalloonDescription += "<p><i>Data source: " + DataSourceComments + "</i></p>";
                    }

                    BalloonDescription += "<img src=\"" + ourPath + "SoilChart.aspx?Name=" + Name + "\"/>";

                    BalloonDescription += "<p><a href=\"" + ourPath + "GetSoil.aspx?Name=" + Name + "\">Download soil in APSIM format (copy and paste contents to your simulation).</a></p>";
                    BalloonDescription += "<p><a name=\"link_id\" id=\"link_id\"  href=\"Download.html\" onclick=\"window.open('" + ourPath + "Excel.aspx?Name=" + Name + "');\">Download soil as an EXCEL spreadsheet</a></p>";

                    string SoilName = Soil.Name;
                    if (Soil.ApsoilNumber != "")
                    {
                        SoilName = Soil.ApsoilNumber;
                    }
                    Placemark plmMyPlaceMark = new Placemark(SoilName,
                                                             BalloonDescription,
                                                             Soil.Latitude,
                                                             Soil.Longitude,
                                                             0, altitudeModeEnum.clampToGround);
                    plmMyPlaceMark.Description.UseCDATA = true;
                    plmMyPlaceMark.Description.Text     = BalloonDescription;
                    plmMyPlaceMark.StyleUrl.Text        = "#APSRUIconID";

                    Folder F = GetFolder(FolderName, Folders, KmlDoc);
                    F.Features.Placemarks.Add(plmMyPlaceMark);
                }
            }

            KmlContent.NetworkLinkControl.Expires.Value        = DateTime.Now.AddDays(7);
            KmlContent.NetworkLinkControl.LinkDescription.Text = "Characterised sites - " + DateTime.Now.ToString("dd MMM yyyy HH:mm:ss");
            return(KmlContent.GetKMZ("NetworkData.kml"));
        }