Ejemplo n.º 1
0
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            TBX_DeviceDescription.Text = "";
            TB_DeviceName.Text         = "";
            LBX_DeviceSensors.Items.Clear();

            if (!string.IsNullOrEmpty(Request.QueryString["device"]))
            {
                deviceSensors = PersistanceLayer.GetSensors(Request.QueryString["device"]);

                Device deviceInfo = PersistanceLayer.GetDeviceInfo(Request.QueryString["device"]);

                if (!string.IsNullOrEmpty(deviceInfo.deviceName))
                {
                    TBX_DeviceDescription.Text = deviceInfo.description;
                    TB_DeviceName.Text         = deviceInfo.deviceName;

                    foreach (Sensor sn in deviceSensors)
                    {
                        LBX_DeviceSensors.Items.Add(sn.sensorName);
                    }
                }
            }
            else
            {
            }
        }
    }
Ejemplo n.º 2
0
    protected override void OnInit(EventArgs e)
    {
        DropDownList_DisplayType.DataSource = PersistanceLayer.GetDisplays();
        DropDownList_DisplayType.DataBind();

        DDL_DeviceSelect.DataSource = PersistanceLayer.GetDevices();
        DDL_DeviceSelect.DataBind();
        base.OnInit(e);
    }
Ejemplo n.º 3
0
    /// <summary>
    /// Name:       Page_Load
    /// Purpose:    To handle the page load event and display device
    ///             sensor information if a device has been selected
    ///             to display
    /// </summary>
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!string.IsNullOrEmpty(Request.QueryString["device"]))
        {
            List <Sensor> deviceSensors = PersistanceLayer.GetSensors(Request.QueryString["device"]);

            //Check to make sure we don't have a null list returned, meaning there are no sensors
            //for this device.
            if (deviceSensors != null)
            {
                Session["displayDevice"]     = "";
                Session["displaySensorName"] = new List <string>();
                Session["displayCount"]      = 0;
                Session["displayDevice"]     = Request.QueryString["device"];
                //For every sensor we'll now process and display a graph.
                foreach (Sensor mSensor in deviceSensors)
                {
                    //So far only XMLSWFGraphs are working but there will be else if statements
                    //below this one once we implement other graph types, maps, etc
                    if (mSensor.displayType == "XMLSWFGraph")
                    {
                        //Here we create a session control or append to it, defining sensors that
                        //will be associated to this device. They will be caught in XMLSWFGraph.ascx
                        //And processed out.
                        ((List <string>)Session["displaySensorName"]).Add(mSensor.sensorName);
                        Session["startDate"] = "0";
                        Session["endDate"]   = "0";
                        //Now we actually load the controls, this is what will invoke XMLSWFGraph.asc
                        displays.Controls.Add(LoadControl("XMLSWFGraph.ascx"));
                    }
                }
            }
            //If we did get a null list put up an appropriate error message.
            else
            {
                Label errMessage = new Label();
                errMessage.Text = Request.QueryString["device"] + " Has no sensors to display.";
                displays.Controls.Add(errMessage);
            }
        }
        else
        {
        }
    }
Ejemplo n.º 4
0
    protected void LBX_DeviceSensors_SelectedIndexChanged(object sender, EventArgs e)
    {
        Sensor temp = deviceSensors.Find(delegate(Sensor t) { return(t.sensorName == LBX_DeviceSensors.SelectedItem.ToString()); });

        //TODO: BUG here with sensor display types etc or in PersistanceLayer.cs
        TB_DisplayType.Text = PersistanceLayer.GetDisplayInfo(temp.displayType);

        foreach (ListItem mItem in DropDownList_DisplayType.Items)
        {
            mItem.Selected = false;
            if (mItem.Text == temp.displayType)
            {
                mItem.Selected = true;
            }
        }

        if (temp != null)
        {
            TBX_SensorDescription.Text = temp.descript;
        }
    }
Ejemplo n.º 5
0
 protected override void OnInit(EventArgs e)
 {
     DDL_DeviceSelect.DataSource = PersistanceLayer.GetDevices();
     DDL_DeviceSelect.DataBind();
     base.OnInit(e);
 }
Ejemplo n.º 6
0
    //TODO: REFACTOR: Make this stream to stream
    public static void Parse(XmlDocument incoming, System.IO.Stream outstream)
    {
        //Create a XML Stream to the OutputStream
        XmlWriterSettings xwsOut = new XmlWriterSettings();

        xwsOut.Indent = true;
        XmlWriter outgoing = XmlWriter.Create(outstream);

        try
        {
            XmlNode xnWhitespace = incoming.SelectSingleNode("//@w | //@whitespace");
            bool    bWhitespace  = false;
            if (xnWhitespace != null && bool.TryParse(xnWhitespace.Value, out bWhitespace))
            {
                xwsOut.Indent = bWhitespace;
            }
            outgoing = XmlWriter.Create(outstream, xwsOut);

            //Begin the XML Responce
            outgoing.WriteStartDocument();
            outgoing.WriteStartElement(incoming.DocumentElement.Name);

            foreach (XmlNode item in incoming.DocumentElement.ChildNodes)
            {
                //DateTime Aquire
                DateTime dtItem    = DateTime.Now;
                long     timeStamp = 0;

                //Search for a datetime
                XmlNodeList xnlDate = item.SelectNodes("./@datetime | ./@d | ../@datetime | ../@d");

                //Search for a timestamp
                XmlNodeList xnlTime = item.SelectNodes("./@timestamp | ./@t | ../@timestamp | ../@t");

                //Check if we found a datetime and its parseable
                if (xnlDate.Count > 0 && DateTime.TryParse(xnlDate[xnlDate.Count - 1].Value, out dtItem))
                {
                    //Intentionally blank
                }
                //Otherwise use the timestamp and its parseable
                else if (xnlTime.Count > 0 && long.TryParse(xnlTime[xnlTime.Count - 1].Value, out timeStamp))
                {
                    dtItem = DateTime.Parse("1970-01-01 00:00:00").AddSeconds(timeStamp);
                }
                //Otherwise just use now.
                else
                {
                    dtItem = DateTime.Now;
                }

                //Process Acknowledgements or put them into the database
                if (item.SelectSingleNode("./@p | ./@process") != null)
                {
                    //TODO: Spawn new Thread() for each subelement
                    outgoing.WriteStartElement(item.Name);
                    outgoing.WriteString(item.InnerXml);
                    outgoing.WriteEndElement();
                }
                else
                {
                    //Place the item into the datebase
                    try
                    {
                        PersistanceLayer.InsertSensorData(incoming.DocumentElement.Name, item.Name, item.InnerXml, dtItem);
                    }
                    catch (Exception ex)
                    {
                        outgoing.WriteStartElement(item.Name);
                        outgoing.WriteString(ex.Message);
                        outgoing.WriteEndElement();
                    }
                }
            }
            //TODO: Wait for all Threads()
        }
        catch (XmlException ex)
        {
            outgoing.WriteStartElement("Exception");
            outgoing.WriteAttributeString("type", "XmlException");
            outgoing.WriteString(ex.Message);
            outgoing.WriteEndElement();
        }
        catch (Exception ex)
        {
            outgoing.WriteStartElement("Exception");
            outgoing.WriteAttributeString("type", "Exception");
            //outgoing.WriteString(ex.Source + ": " + ex.Message + ex.StackTrace);
            outgoing.WriteString(ex.Source + ": " + ex.Message);
            outgoing.WriteEndElement();
        }
        outgoing.WriteEndDocument();
        outgoing.Close();
    }