Example #1
0
        private HttpResponseMessage GetByCommandName(String StationName, String DeviceName, String FieldName, String SessionID)
        {
            XmlDocument    myXml = new XmlDocument();
            XPathNavigator xNav  = myXml.CreateNavigator();

            if (UserSessionHandler.VerifyTimeout(SessionID))
            {
                STATIONNAME ThisStation = HostingHelper.ConvertStationNameStrToSTATIONNAME(StationName);

                DEVICENAME ThisDevice    = HostingHelper.ConvertDevicecNameStrToDEVICENAME(DeviceName);
                dynamic    ThisFieldName = HostingHelper.ConvertFieldNameStrToFIELDNAME(FieldName);

                if (ThisStation == STATIONNAME.NULL)
                {
                    return(HostingHelper.ReturnError("Invalid station name. Please check.", myXml, xNav));
                }

                if (ThisDevice == DEVICENAME.NULL)
                {
                    return(HostingHelper.ReturnError("Invalid device name. Please check.", myXml, xNav));
                }

                if (ThisFieldName == null)
                {
                    return(HostingHelper.ReturnError("Invalid field name. Please check.", myXml, xNav));
                }

                OUTPUTSTRUCT InformationResult = AstroData.GetInformation(ThisStation, ThisDevice, FieldName);
                if (InformationResult != null)
                {
                    JavaScriptSerializer Serializer = new JavaScriptSerializer();
                    Serializer.MaxJsonLength = Int32.MaxValue;
                    var json = Serializer.Serialize(InformationResult);
                    return(new HttpResponseMessage()
                    {
                        Content = new StringContent(json, Encoding.UTF8, "application/json")
                    });
                }
                else
                {
                    return(HostingHelper.ReturnError("An error occur while getting information", myXml, xNav));
                }
            }
            else
            {
                return(HostingHelper.ReturnError("Session is timeout. Please login to the system.", myXml, xNav));
            }
        }
Example #2
0
        public static HttpResponseMessage ReturnSuccess(STATIONNAME StationName, String Message, XmlDocument myXml, XPathNavigator xNav)
        {
            OUTPUTSTRUCT ThisOutput = new OUTPUTSTRUCT();

            ThisOutput.StationName    = StationName;
            ThisOutput.DeviceCategory = DEVICECATEGORY.NULL;
            ThisOutput.FieldName      = "NULL";
            ThisOutput.Value          = Message;
            ThisOutput.DataType       = "Get_Success";
            ThisOutput.UpdateTime     = DateTime.UtcNow.ToString();

            var json = new JavaScriptSerializer().Serialize(ThisOutput);

            return(new HttpResponseMessage()
            {
                Content = new StringContent(json, Encoding.UTF8, "application/json")
            });
        }