コード例 #1
0
ファイル: AstroData.cs プロジェクト: pprasit/Project
        public static ReturnKnowType GRBHandler(String Ra, String Dec, String FOV, DateTime UpdateTIme)
        {
            StationHandler ThisSite = KeeperData.FirstOrDefault(Item => Item.StationName == STATIONNAME.TNO);

            if (ThisSite == null)
            {
                return(ReturnKnowType.DefineReturn(ReturnStatus.FAILED, "Station TNO 2.4 Meter Telescope is now offline. Please contact Pakawat Prasit", null));
            }

            try
            {
                //ReturnDeviceInformation OutHum = ThisSite.GetDataT07ByCommandName(DEVICENAME.T24WSC, InformationdName.WEATHER_ATTRIBUTE_DATA_OUTHUM);
                //ReturnDeviceInformation Temp = ThisSite.GetDataT07ByCommandName(DEVICENAME.T24WSC, InformationdName.WEATHER_ATTRIBUTE_DATA_TEMPOUT);
                //ReturnDeviceInformation DewPt = ThisSite.GetDataT07ByCommandName(DEVICENAME.T24WSC, InformationdName.WEATHER_ATTRIBUTE_DATA_DEWPT);
                //ReturnDeviceInformation InfoDate = ThisSite.GetDataT07ByCommandName(DEVICENAME.T24WSC, InformationdName.WEATHER_ATTRIBUTE_DATA_DATE);
                //ReturnDeviceInformation InfoTime = ThisSite.GetDataT07ByCommandName(DEVICENAME.T24WSC, InformationdName.WEATHER_ATTRIBUTE_DATA_TIME);

                //if (Convert.ToDouble(OutHum.ReturnValue.Value) > 85)
                //    return ReturnKnowType.DefineReturn(ReturnStatus.Failed, "We can not open the dome because the humidity is heighter than 85%. (Weather time is " + InfoDate.ReturnValue.Value.ToString() +
                //        " " + InfoTime.ReturnValue.Value.ToString() + ")", null);
                //else if (Convert.ToDouble(Temp.ReturnValue.Value) - Convert.ToDouble(DewPt.ReturnValue.Value) <= 2)
                //    return ReturnKnowType.DefineReturn(ReturnStatus.Failed, "We can not open the dome because the dew point is too height. (Weather time is " + InfoDate.ReturnValue.Value.ToString() +
                //        " " + InfoTime.ReturnValue.Value.ToString() + ")", null);
            }
            catch { }

            return(ThisSite.RelayGRB(Ra, Dec, FOV, UpdateTIme));
        }
コード例 #2
0
ファイル: Connection.cs プロジェクト: pprasit/Project
        public ReturnKnowType AstroCreateStation(STATIONNAME StationName, Double Version = 0)
        {
            try
            {
                if (Version != RequirePackageVersion)
                {
                    return(ReturnKnowType.DefineReturn(ReturnStatus.FAILED, "(#Co003) Failed to create " + StationName + ". Your client version is " + Version + " (Require version " + RequirePackageVersion + ")."));
                }
                else
                {
                    OperationContext context      = OperationContext.Current;
                    ServerCallBack   SiteCallBack = OperationContext.Current.GetCallbackChannel <ServerCallBack>();
                    CallBackHandler.AddSiteConnection(StationName, context.SessionId, SiteCallBack);

                    OperationContext.Current.Channel.Closed  += StationChannel_Closed;
                    OperationContext.Current.Channel.Faulted += StationChannel_Closed;

                    ReturnKnowType CreateSiteResult = AstroData.CreateStation(StationName, context.SessionId, SiteCallBack);
                    return(CreateSiteResult);
                }
            }
            catch (Exception e)
            {
                return(ReturnKnowType.DefineReturn(ReturnStatus.FAILED, "(#Co001) Failed to create site at TTCSCreateSite see. (" + e.Message + ")"));
            }
        }
コード例 #3
0
ファイル: AstroData.cs プロジェクト: pprasit/Project
 public static ReturnKnowType GetAllOnlineStation()
 {
     if (KeeperData != null)
     {
         return(ReturnKnowType.DefineReturn(ReturnStatus.SUCESSFUL, null, KeeperData));
     }
     else
     {
         return(ReturnKnowType.DefineReturn(ReturnStatus.FAILED, "(#TT017) Failed to get online station because all station is offline."));
     }
 }
コード例 #4
0
        public static ReturnKnowType DefineReturn(String Message, ReturnStatus Status, Object Value)
        {
            ReturnKnowType ThisReturn = new ReturnKnowType();

            ThisReturn.ReturnMessage  = Message;
            ThisReturn.ReturnType     = Status;
            ThisReturn.ReturnValue    = Value;
            ThisReturn.ReturnDateTime = DateTime.UtcNow;

            return(ThisReturn);
        }
コード例 #5
0
 public static ReturnKnowType RemoveInterfaceConnection(String InterfaceSessionID)
 {
     try
     {
         InterfaceConnectionList.RemoveAll(Item => Item.InterfaceSessionID == InterfaceSessionID);
         return(ReturnKnowType.DefineReturn(ReturnStatus.SUCESSFUL, null));
     }
     catch (Exception e)
     {
         return(ReturnKnowType.DefineReturn(ReturnStatus.FAILED, "Failed to remove interface connection see. (" + e.Message + ")"));
     }
 }
コード例 #6
0
ファイル: AstroData.cs プロジェクト: pprasit/Project
        public static ReturnKnowType CreateStation(STATIONNAME StationName, String StationSessionID, Object ServerCallBackObject)
        {
            StationHandler ThisStation      = KeeperData.FirstOrDefault(Item => Item.StationName == StationName);
            ReturnKnowType CreateSiteResult = ThisStation.CreateEngine(StationSessionID, ServerCallBackObject);

            if (ThisStation != null)
            {
                ThisStation.StationConnected();
            }

            TTCSLog.NewLogInformation(StationName, DateTime.UtcNow, "Station name : " + StationName.ToString() + " has been created, Status ready and waiting for command.", LogType.COMMUNICATION, null);
            return(CreateSiteResult);
        }
コード例 #7
0
        public static ReturnKnowType Loggout(String SessionID)
        {
            SessionStructure ThisSession = SessionList.FirstOrDefault(Item => Item.SessionID == SessionID);

            if (ThisSession != null)
            {
                SessionList.Remove(ThisSession);
                return(ReturnKnowType.DefineReturn(ReturnStatus.SUCESSFUL, "Successful loggout."));
            }
            else
            {
                return(ReturnKnowType.DefineReturn(ReturnStatus.FAILED, "Can not loggout. Invalid session ID."));
            }
        }
コード例 #8
0
        public HttpResponseMessage Operation(String SessionID)
        {
            XmlDocument    myXml = new XmlDocument();
            XPathNavigator xNav  = myXml.CreateNavigator();

            ReturnKnowType LoggoutResult = UserSessionHandler.Loggout(SessionID);
            XmlSerializer  xmlSerializer = new XmlSerializer(typeof(ReturnKnowType));

            using (var xs = xNav.AppendChild()) { xmlSerializer.Serialize(xs, LoggoutResult); }
            return(new HttpResponseMessage()
            {
                Content = new StringContent(myXml.OuterXml, Encoding.UTF8, "text/xml")
            });
        }
コード例 #9
0
        public static ReturnKnowType SubscribeByCommmanName(ServerCallBack ClientCallBack, String ClientSessionID, STATIONNAME StationName, DEVICECATEGORY DeviceName, String CommandName)
        {
            try
            {
                SubscribeStructure.SubscribeType SubscribeType = GetSubscribeType(StationName, DeviceName, CommandName);
                DuplicationSubscribeChecking(SubscribeType, ClientSessionID, StationName, DeviceName, CommandName);

                SubscribeStructure ThisSubscribe = SubscribeList.FirstOrDefault(Item => Item.StationName == StationName && Item.DeviceName == DeviceName && Item.CommandName == CommandName);

                if (ThisSubscribe == null)
                {
                    ClientSubscription ThisClient = new ClientSubscription();
                    ThisClient.ClientCallBack  = ClientCallBack;
                    ThisClient.ClientSessionID = ClientSessionID;

                    ThisSubscribe             = new SubscribeStructure();
                    ThisSubscribe.StationName = StationName;
                    ThisSubscribe.DeviceName  = DeviceName;
                    ThisSubscribe.CommandName = CommandName;
                    ThisSubscribe.Type        = SubscribeType;

                    ThisSubscribe.ClientList = new List <ClientSubscription>();
                    ThisSubscribe.ClientList.Add(ThisClient);
                }
                else
                {
                    ClientSubscription ThisClient = ThisSubscribe.ClientList.FirstOrDefault(Item => Item.ClientSessionID == ClientSessionID);

                    if (ThisClient == null)
                    {
                        ThisClient = new ClientSubscription();
                        ThisClient.ClientCallBack  = ClientCallBack;
                        ThisClient.ClientSessionID = ClientSessionID;

                        ThisSubscribe.ClientList.Add(ThisClient);
                    }
                    else
                    {
                        return(ReturnKnowType.DefineReturn(ReturnStatus.SUCESSFUL, "Your request is already exist in subscribe list. Please check."));
                    }
                }

                return(ReturnKnowType.DefineReturn(ReturnStatus.SUCESSFUL, null));
            }
            catch (Exception e)
            {
                return(ReturnKnowType.DefineReturn(ReturnStatus.FAILED, "Failed to subscribe information see. (" + e.Message + ")"));
            }
        }
コード例 #10
0
ファイル: AstroData.cs プロジェクト: pprasit/Project
        public static ReturnKnowType UpdateStationUser(String UserID, String UserName, String UserLoginName, String UserLoginPassword, String UserPermissionType, String USerStationPermission, String StationName, DATAACTION UserAction)
        {
            STATIONNAME    ThisStationName = TTCSHelper.StationStrConveter(StationName);
            StationHandler ThisSite        = KeeperData.FirstOrDefault(Item => Item.StationName == ThisStationName);

            if (ThisSite != null)
            {
                ReturnKnowType ThisResult = ThisSite.UpdateStationUser(UserID, UserName, UserLoginName, UserLoginPassword, UserPermissionType, USerStationPermission, UserAction);
                if (ThisResult.ReturnType == ReturnStatus.SUCESSFUL)
                {
                    return(ThisResult);
                }
            }

            return(ReturnKnowType.DefineReturn(ReturnStatus.FAILED, "(#TT004) Can not update user data to station. Will try again.", false));
        }
コード例 #11
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));
            }
        }
コード例 #12
0
ファイル: Connection.cs プロジェクト: pprasit/Project
        public ReturnKnowType AstroCreateClientInterface(String InterfaceName)
        {
            try
            {
                OperationContext context        = OperationContext.Current;
                ServerCallBack   ServerCallBack = OperationContext.Current.GetCallbackChannel <ServerCallBack>();
                CallBackHandler.AddInterfaceConnection(InterfaceName, context.SessionId, ServerCallBack);

                OperationContext.Current.Channel.Closed  += InterfaceChannel_Closed;
                OperationContext.Current.Channel.Faulted += InterfaceChannel_Closed;

                return(ReturnKnowType.DefineReturn(ReturnStatus.SUCESSFUL, null));;
            }
            catch (Exception e)
            {
                return(ReturnKnowType.DefineReturn(ReturnStatus.FAILED, "Failed to create client interface at TTCSCreateClientInterface see. (" + e.Message + ")"));
            }
        }
コード例 #13
0
        public static ReturnKnowType AddInterfaceConnection(String InterfaceName, String InterfaceSessionID, ServerCallBack SiteCallBack)
        {
            try
            {
                InterfaceConnection NewInterfaceConnection = new InterfaceConnection();
                NewInterfaceConnection.InterfaceName      = InterfaceName;
                NewInterfaceConnection.InterfaceSessionID = InterfaceSessionID;
                NewInterfaceConnection.SiteCallBack       = SiteCallBack;

                InterfaceConnectionList.Add(NewInterfaceConnection);

                return(ReturnKnowType.DefineReturn(ReturnStatus.SUCESSFUL, null));
            }
            catch (Exception e)
            {
                return(ReturnKnowType.DefineReturn(ReturnStatus.FAILED, "Failed to add interface connection see. (" + e.Message + ")"));
            }
        }
コード例 #14
0
        public static ReturnKnowType UserVerification(String UserLoginName, String UserLoginPassword, int SessionTimeout)
        {
            foreach (UserStrcture ThisUser in UserList)
            {
                if (ThisUser.UserLoginName == UserLoginName && ThisUser.UserLoginPassword == UserLoginPassword)
                {
                    SessionStructure ThisSession = new SessionStructure();
                    ThisSession.SessionID       = SessionGenerator(ThisUser.UserID, ThisUser.UserLoginPassword);
                    ThisSession.SessionLifeTime = SessionTimeout;

                    ThisUser.SessionID = ThisSession.SessionID;
                    SessionList.Add(ThisSession);

                    return(ReturnKnowType.DefineReturn(ReturnStatus.SUCESSFUL, null, ThisSession));
                }
            }

            return(ReturnKnowType.DefineReturn(ReturnStatus.FAILED, "Invalid UserLoginName and UserLoginPassword."));
        }
コード例 #15
0
        //http://192.168.70.210:8093/TTCS/Login?UserName=Pakawat&Password=P@ss3610a
        public Object Get(String UserName, String Password)
        {
            //return new HttpResponseMessage()
            //{
            //    Content = new JsonContent(new
            //    {
            //        Success = true, //error
            //        Message = "Success" //return exception
            //    })
            //};

            //return "Test";
            //Response.AppendHeader("Access-Control-Allow-Origin", "*");

            ReturnKnowType Object = Operation(UserName, Password);

            return(new JavaScriptSerializer().Serialize(Object));
            //return Operation(UserName, Password)
        }
コード例 #16
0
        private ReturnKnowType Operation(String UserName, String Password)
        {
            XmlDocument    myXml = new XmlDocument();
            XPathNavigator xNav  = myXml.CreateNavigator();

            ReturnKnowType ThisUser      = UserSessionHandler.UserVerification(UserName, Password);
            XmlSerializer  xmlSerializer = new XmlSerializer(typeof(SessionStructure));

            if (ThisUser.ReturnType == ReturnStatus.SUCESSFUL)
            {
                //using (var xs = xNav.AppendChild()) { xmlSerializer.Serialize(xs, ThisUser.ReturnValue); }
                //return new HttpResponseMessage() { Content = new StringContent(myXml.OuterXml, Encoding.UTF8, "text/xml") };
                return(ThisUser);
            }
            else
            {
                return(ThisUser);
            }
        }
コード例 #17
0
ファイル: CommandDefinition.cs プロジェクト: pprasit/Project
        private static ReturnKnowType VerifyParameter(TCSCommandStructure ThisCommand, Object[] Value)
        {
            String ParameterFormat = "";

            if (ThisCommand.Parameter != null)
            {
                ParameterFormat = String.Join(", ", ThisCommand.Parameter);
            }

            if ((Value == null || Value.Count() == 0) && ThisCommand.Parameter != null)
            {
                return(ReturnKnowType.DefineReturn(ReturnStatus.FAILED, "(#CD005) Missing parameter for Command name " + ThisCommand.Command + "(" + ParameterFormat + ")"));
            }
            else if ((Value == null || Value.Count() == 0) && ThisCommand.Parameter == null)
            {
                return(ReturnKnowType.DefineReturn(ReturnStatus.SUCESSFUL, null));
            }
            else if ((Value == null || Value.Count() == 0) && ThisCommand.Parameter == null)
            {
                return(ReturnKnowType.DefineReturn(ReturnStatus.FAILED, "(#CD006) Command name (" + ThisCommand.Command + ") has no parameter. Please check."));
            }

            if (ThisCommand.Parameter.Count() != Value.Count())
            {
                return(ReturnKnowType.DefineReturn(ReturnStatus.FAILED, "(#CD002) Command name (" + ThisCommand.Command + ") does not contain " + Value.Count() + " Parameters. Please cheange it to " + ThisCommand.Command + "(" + ParameterFormat + ")"));
            }
            else if (ThisCommand.Parameter.Count() == 0 && Value.Count() == 0)
            {
                return(ReturnKnowType.DefineReturn(ReturnStatus.SUCESSFUL, null));
            }

            for (int i = 0; i < Value.Count(); i++)
            {
                Type ParaType = VerifyDataType(Value[i], ThisCommand.Parameter[i]);
                if (ThisCommand.Parameter[i] != ParaType)
                {
                    return(ReturnKnowType.DefineReturn(ReturnStatus.FAILED, "(#CD003) Invalid parameter see. Command name " + ThisCommand.Command + "(" + ParameterFormat + ")"));
                }
            }

            return(ReturnKnowType.DefineReturn(ReturnStatus.SUCESSFUL, null));
        }
コード例 #18
0
ファイル: AstroData.cs プロジェクト: pprasit/Project
        public static ReturnKnowType GetOnlineStation(STATIONNAME StationName)
        {
            if (KeeperData != null)
            {
                StationHandler ThisStation = KeeperData.FirstOrDefault(Item => Item.StationName == StationName);

                if (ThisStation != null)
                {
                    return(ReturnKnowType.DefineReturn(ReturnStatus.SUCESSFUL, null, ThisStation));
                }
                else
                {
                    return(ReturnKnowType.DefineReturn(ReturnStatus.FAILED, "(#TT015) Failed to get online station because all station " + StationName + " is offline."));
                }
            }
            else
            {
                return(ReturnKnowType.DefineReturn(ReturnStatus.FAILED, "(#TT016) Failed to get online station because all station " + StationName + " is offline."));
            }
        }
コード例 #19
0
        private HttpResponseMessage RelayCommand(String Ra, String Dec, String FOV, String SessionID)
        {
            XmlDocument    myXml = new XmlDocument();
            XPathNavigator xNav  = myXml.CreateNavigator();

            if (UserSessionHandler.VerifyTimeout(SessionID))
            {
                ReturnKnowType CommandResult = AstroData.GRBHandler(Ra, Dec, FOV, 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")
                });
            }
            else
            {
                return(HostingHelper.ReturnError("Session is timeout. Please login to the system.", myXml, xNav));
            }
        }
コード例 #20
0
ファイル: AstroData.cs プロジェクト: pprasit/Project
        public static ReturnKnowType SetCommandHandler(STATIONNAME StationName, DEVICECATEGORY DeviceCategory, DEVICENAME DeviceName, dynamic CommandName, Object[] Values, DateTime CommandDateTime)
        {
            StationHandler ThisSite = KeeperData.FirstOrDefault(Item => Item.StationName == StationName);

            if (ThisSite != null)
            {
                Boolean AckState = false;

                if (StationName == STATIONNAME.ASTROSERVER)
                {
                    AckState = true;
                }
                else
                {
                    return(ThisSite.RelayCommandToStation(DeviceCategory, DeviceName, CommandName, Values));
                }

                return(ReturnKnowType.DefineReturn(ReturnStatus.SUCESSFUL, null, AckState));
            }

            return(ReturnKnowType.DefineReturn(ReturnStatus.FAILED, "(#TT003) Failed to relay set command to station.", false));
        }
コード例 #21
0
ファイル: AstroData.cs プロジェクト: pprasit/Project
        public static ReturnKnowType ScriptHandler(STATIONNAME StationDestination, ScriptStructure[] ThisScriptList)
        {
            StationHandler ThisSite = KeeperData.FirstOrDefault(Item => Item.StationName == StationDestination);

            if (ThisSite != null)
            {
                Boolean AckState = false;

                if (StationDestination == STATIONNAME.ASTROSERVER)
                {
                    AckState = true;
                }
                else
                {
                    return(ThisSite.SendScriptToStation(ThisScriptList));
                }

                return(ReturnKnowType.DefineReturn(ReturnStatus.SUCESSFUL, null, AckState));
            }

            return(ReturnKnowType.DefineReturn(ReturnStatus.FAILED, "(#TT003) Failed to relay set command to station.", false));
        }
コード例 #22
0
ファイル: CommandDefinition.cs プロジェクト: pprasit/Project
        public static ReturnKnowType VerifyCommand(STATIONNAME StationName, DEVICECATEGORY DeviceCategory, dynamic CommandName, Object[] Value)
        {
            if (CommandName == null)
            {
                return(ReturnKnowType.DefineReturn(ReturnStatus.FAILED, "(#CD001) Failed to get command name from list see. (Command name was not avaliable.)"));
            }

            TCSCommandStructure ThisCommand = CommandList.FirstOrDefault(Item => Item.StationOwner.Contains(StationName) && Item.DeviceCategory == DeviceCategory && Item.Command.ToString() == CommandName.ToString());

            if (ThisCommand != null)
            {
                List <String> ValueStr = new List <String>();
                foreach (Object ThisValue in Value)
                {
                    ValueStr.Add(ThisValue.ToString());
                }

                Object[]       Values     = ValueConvertion(ValueStr.ToArray());
                ReturnKnowType ThisReturn = VerifyParameter(ThisCommand, Values);
                return(ThisReturn);
            }

            return(ReturnKnowType.DefineReturn(ReturnStatus.FAILED, "(#CD004) Could not be found commmand (" + CommandName + ") that contain station name : (" + StationName + ") Device Name : (" + DeviceCategory + "). Please check station name or device name."));
        }
コード例 #23
0
ファイル: Connection.cs プロジェクト: pprasit/Project
 public ReturnKnowType AddImage(STATIONNAME StationName, DEVICENAME DeviceName, UInt16[][] Value, DateTime DataTimeStamp)
 {
     AstroData.NewIMAGINGInformation(StationName, DeviceName, IMAGING.IMAGING_CCD_IMAGEARRAY16, Value, DataTimeStamp);
     return(ReturnKnowType.DefineReturn(ReturnStatus.SUCESSFUL, null));
 }