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)); } }
private HttpResponseMessage Operation(String StationName, String DeviceName, String CommandName, String Value, String SessionID) { XmlDocument myXml = new XmlDocument(); XPathNavigator xNav = myXml.CreateNavigator(); if (UserSessionHandler.VerifyTimeout(SessionID)) { STATIONNAME ThisStation = HostingHelper.ConvertStationNameStrToSTATIONNAME(StationName); DEVICENAME ThisDeviceName = HostingHelper.ConvertDevicecNameStrToDEVICENAME(DeviceName); DEVICECATEGORY ThisDeviceCategory = HostingHelper.ConvertDeviceNameToDeviceCategory(ThisStation, ThisDeviceName); if (ThisStation == STATIONNAME.NULL) { return(HostingHelper.ReturnError("Invalid station name. Please check.", myXml, xNav)); } if (ThisDeviceName == DEVICENAME.NULL) { return(HostingHelper.ReturnError("Invalid device name. Please check.", myXml, xNav)); } ReturnKnowType VerificationResult = CommandDefinition.VerifyCommand(ThisStation, ThisDeviceCategory, CommandName, HostingHelper.SplitValue(Value)); if (VerificationResult.ReturnType == ReturnStatus.SUCESSFUL) { dynamic ThisCommandName = CommandDefinition.GetCommandNameENUM(CommandName); XmlSerializer xmlSerializer2 = new XmlSerializer(typeof(ReturnMessage)); ReturnKnowType CommandResult = AstroData.SetCommandHandler(ThisStation, ThisDeviceCategory, ThisDeviceName, ThisCommandName.Value, CommandDefinition.ValueConvertion(HostingHelper.SplitValue(Value)), DateTime.UtcNow); XmlSerializer xmlSerializer3 = new XmlSerializer(typeof(ReturnKnowType)); using (var xs = xNav.AppendChild()) { xmlSerializer3.Serialize(xs, CommandResult); } return(new HttpResponseMessage() { Content = new StringContent(myXml.OuterXml, Encoding.UTF8, "text/xml") }); } return(HostingHelper.ReturnError(VerificationResult.ReturnMessage, myXml, xNav)); } else { return(HostingHelper.ReturnError("Session is timeout. Please login to the system.", myXml, xNav)); } }