Example #1
0
        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));
            }
        }
Example #2
0
        private static Boolean VerifyScript(STATIONNAME StationName, List <ScriptStructureNew> ScriptCollection, out String Message)
        {
            foreach (ScriptStructureNew ThisScript in ScriptCollection)
            {
                //DUMMY ONLY
                //ThisScript.TargetID = "XXXXXX";

                if (String.IsNullOrEmpty(ThisScript.ScriptID))
                {
                    Message = "Invalid ScriptID can't be null or empty value. Please check.";
                    return(false);
                }

                if (String.IsNullOrEmpty(ThisScript.BlockID))
                {
                    Message = "Invalid BlockID can't be null or empty value at Script ID : " + ThisScript.ScriptID + ". Please check.";
                    return(false);
                }

                STATIONNAME ScriptStationName = TTCSHelper.StationStrConveter(ThisScript.StationName);

                if (StationName == STATIONNAME.NULL)
                {
                    Message = "Invalid station same at script ID : " + ThisScript.BlockID + ". Please check spelling.";
                    return(false);
                }

                if (StationName != ScriptStationName)
                {
                    Message = "Invalid station name not match in folder at script ID : " + ThisScript.BlockID + ". Please check spelling.";
                    return(false);
                }

                DEVICENAME DeviceName = TTCSHelper.DeviceNameStrConverter(ThisScript.DeviceName);
                if (DeviceName == DEVICENAME.NULL)
                {
                    Message = "Invalid device name at script ID : " + ThisScript.BlockID + ". Please check spelling.";
                    return(false);
                }

                DEVICECATEGORY DeviceCategory = TTCSHelper.ConvertDeviceNameToDeviceCategory(StationName, DeviceName);
                if (DeviceCategory == DEVICECATEGORY.NULL)
                {
                    Message = "Invalid devicecategory at script ID : " + ThisScript.BlockID + ". Please check spelling.";
                    return(false);
                }

                Object CommandName = TTCSHelper.CommandNameConverter(DeviceCategory, ThisScript.CommandName);
                if (CommandName == null)
                {
                    Message = "Invalid command name at script ID : " + ThisScript.BlockID + ". Please check spelling.";
                    return(false);
                }

                Int64 StartDateLong = 0;
                if (!Int64.TryParse(ThisScript.ExecutionTimeStart, out StartDateLong))
                {
                    Message = "Invalid start datetime at script ID : " + ThisScript.BlockID + ". Please check spelling.";
                    return(false);
                }

                Int64 EndDateLong = 0;
                if (!Int64.TryParse(ThisScript.ExecutionTimeEnd, out EndDateLong))
                {
                    Message = "Invalid end datetime at script ID : " + ThisScript.BlockID + ". Please check spelling.";
                    return(false);
                }

                int Life = 0;
                if (!int.TryParse(ThisScript.Life, out Life))
                {
                    Message = "Invalid life time at " + ThisScript.BlockID + ". Please check spelling.";
                    return(false);
                }

                if (String.IsNullOrEmpty(ThisScript.TargetID))
                {
                    Message = "Invalid TargetID can't be null or empty value at Script ID : " + ThisScript.BlockID + ". Please check.";
                    return(false);
                }

                if (String.IsNullOrEmpty(ThisScript.Owner))
                {
                    Message = "Invalid Owner can't be null or empty value at Script ID : " + ThisScript.BlockID + ". Please check.";
                    return(false);
                }

                ReturnKnowType CommandResult = CommandDefinition.VerifyCommand(StationName, DeviceCategory, CommandName, ThisScript.Parameters.ToArray());
                if (CommandResult.ReturnType == ReturnStatus.FAILED)
                {
                    Message = "Invalid parameter at script ID : " + ThisScript.ScriptID + " at Command " + CommandName + ". With: " + CommandResult.ReturnMessage + ". Please check spelling.";
                    return(false);
                }
            }

            Message = "All script verified.";
            return(true);
        }