Exemplo n.º 1
0
            public void Setup(PTZConfiguration config, PTZSpaces spaces)
            {
                absPanTiltPosition = GetDefaultSpace(
                    spaces.absolutePanTiltPositionSpace, s => s.uri,
                    config.defaultAbsolutePantTiltPositionSpace
                    );

                absZoomPosition = GetDefaultSpace(
                    spaces.absoluteZoomPositionSpace, s => s.uri,
                    config.defaultAbsoluteZoomPositionSpace
                    );

                relPanTiltTranslation = GetDefaultSpace(
                    spaces.relativePanTiltTranslationSpace, s => s.uri,
                    config.defaultRelativePanTiltTranslationSpace
                    );

                relZoomTranslation = GetDefaultSpace(
                    spaces.relativeZoomTranslationSpace, s => s.uri,
                    config.defaultRelativeZoomTranslationSpace
                    );

                contPanTiltVelocity = GetDefaultSpace(
                    spaces.continuousPanTiltVelocitySpace, s => s.uri,
                    config.defaultContinuousPanTiltVelocitySpace
                    );

                contZoomVelocity = GetDefaultSpace(
                    spaces.continuousZoomVelocitySpace, s => s.uri,
                    config.defaultContinuousZoomVelocitySpace
                    );

                absRelPanTiltSpeed = GetDefaultSpace(
                    spaces.panTiltSpeedSpace, s => s.uri,
                    config.IfNotNull(c => c.defaultPTZSpeed.IfNotNull(s => s.panTilt.IfNotNull(v => v.space)))
                    );

                absRelZoomSpeed = GetDefaultSpace(
                    spaces.zoomSpeedSpace, s => s.uri,
                    config.IfNotNull(c => c.defaultPTZSpeed.IfNotNull(s => s.zoom.IfNotNull(v => v.space)))
                    );
            }
        bool CheckConfigurationAndSpaces(PTZConfiguration configuration, PTZSpaces spaces, StringBuilder sb)
        {
            bool ok = true;

            if (!string.IsNullOrEmpty(configuration.DefaultAbsolutePantTiltPositionSpace))
            {
                bool supported = true;
                if (spaces.AbsolutePanTiltPositionSpace == null)
                {
                    supported = false;
                }
                else
                {
                    //DefaultAbsolutePanTiltPositionSpace from PTZConfiguration is not included in one of SupportedPTZSpaces.AbsolutePanTiltPositionSpace from GetNodesResponse.
                    if (spaces.AbsolutePanTiltPositionSpace.Where(
                            S => S.URI == configuration.DefaultAbsolutePantTiltPositionSpace).FirstOrDefault() == null)
                    {
                        supported = false;
                    }
                }

                if (!supported)
                {
                    ok = false;
                    sb.AppendLine(
                        string.Format("PanTiltPositionSpace with URI = '{0}' not found in SupportedPTZSpaces",
                                      configuration.DefaultAbsolutePantTiltPositionSpace));
                }
            }

            //	DefaultAbsoluteZoomPositionSpace from PTZConfiguration is not included in one of SupportedPTZSpaces.AbsoluteZoomPositionSpace from GetNodesResponse.
            if (!string.IsNullOrEmpty(configuration.DefaultAbsoluteZoomPositionSpace))
            {
                bool supported = true;
                if (spaces.AbsoluteZoomPositionSpace == null)
                {
                    supported = false;
                }
                else
                {
                    if (spaces.AbsoluteZoomPositionSpace.Where(
                            S => S.URI == configuration.DefaultAbsoluteZoomPositionSpace).FirstOrDefault() == null)
                    {
                        supported = false;
                    }
                }

                if (!supported)
                {
                    ok = false;
                    sb.AppendLine(
                        string.Format("AbsoluteZoomPositionSpace with URI = '{0}' not found in SupportedPTZSpaces",
                                      configuration.DefaultAbsoluteZoomPositionSpace));
                }
            }

            //	DefaultRelativePanTiltTranslationSpace from PTZConfiguration is not included in one of SupportedPTZSpaces.RelativePanTiltTranslationSpace from GetNodesResponse.
            if (!string.IsNullOrEmpty(configuration.DefaultRelativePanTiltTranslationSpace))
            {
                bool supported = true;
                if (spaces.RelativePanTiltTranslationSpace == null)
                {
                    supported = false;
                }
                else
                {
                    if (spaces.RelativePanTiltTranslationSpace.Where(
                            S => S.URI == configuration.DefaultRelativePanTiltTranslationSpace).FirstOrDefault() == null)
                    {
                        supported = false;
                    }
                }

                if (!supported)
                {
                    ok = false;
                    sb.AppendLine(
                        string.Format("RelativePanTiltTranslationSpace with URI = '{0}' not found in SupportedPTZSpaces",
                                      configuration.DefaultRelativePanTiltTranslationSpace));
                }
            }

            //	DefaultRelativeZoomTranslationSpace from PTZConfiguration is not included in one of SupportedPTZSpaces.RelativeZoomTranslationSpace from GetNodesResponse.
            if (!string.IsNullOrEmpty(configuration.DefaultRelativeZoomTranslationSpace))
            {
                bool supported = true;
                if (spaces.RelativeZoomTranslationSpace == null)
                {
                    supported = false;
                }
                else
                {
                    if (spaces.RelativeZoomTranslationSpace.Where(
                            S => S.URI == configuration.DefaultRelativeZoomTranslationSpace).FirstOrDefault() == null)
                    {
                        supported = false;
                    }
                }

                if (!supported)
                {
                    ok = false;
                    sb.AppendLine(
                        string.Format("RelativeZoomTranslationSpace with URI = '{0}' not found in SupportedPTZSpaces",
                                      configuration.DefaultRelativeZoomTranslationSpace));
                }
            }

            //	DefaultContinuousPanTiltVelocitySpace from PTZConfiguration is not included in one of SupportedPTZSpaces.ContinuousPanTiltVelocitySpacefrom GetNodesResponse.
            if (!string.IsNullOrEmpty(configuration.DefaultContinuousPanTiltVelocitySpace))
            {
                bool supported = true;
                if (spaces.ContinuousPanTiltVelocitySpace == null)
                {
                    supported = false;
                }
                else
                {
                    if (spaces.ContinuousPanTiltVelocitySpace.Where(
                            S => S.URI == configuration.DefaultContinuousPanTiltVelocitySpace).FirstOrDefault() == null)
                    {
                        supported = false;
                    }
                }

                if (!supported)
                {
                    ok = false;
                    sb.AppendLine(
                        string.Format("ContinuousPanTiltVelocitySpace with URI = '{0}' not found in SupportedPTZSpaces",
                                      configuration.DefaultContinuousPanTiltVelocitySpace));
                }
            }

            //	DefaultContinuousZoomVelocitySpace from PTZConfiguration is not included in one of SupportedPTZSpaces.ContinuousZoomVelocitySpace from GetNodesResponse.
            if (!string.IsNullOrEmpty(configuration.DefaultContinuousZoomVelocitySpace))
            {
                bool supported = true;
                if (spaces.ContinuousZoomVelocitySpace == null)
                {
                    supported = false;
                }
                else
                {
                    if (spaces.ContinuousZoomVelocitySpace.Where(
                            S => S.URI == configuration.DefaultContinuousZoomVelocitySpace).FirstOrDefault() == null)
                    {
                        supported = false;
                    }
                }

                if (!supported)
                {
                    ok = false;
                    sb.AppendLine(
                        string.Format("ContinuousZoomVelocitySpace with URI = '{0}' not found in SupportedPTZSpaces",
                                      configuration.DefaultContinuousZoomVelocitySpace));
                }
            }

            if (configuration.DefaultPTZSpeed != null)
            {
                if (configuration.DefaultPTZSpeed.PanTilt != null)
                {
                    bool supported = true;

                    //	DefaultPTZSpeed.PanTilt.space from PTZConfiguration is not included in one of PanTiltSpeedSpace.URI section from GetNodesResponse
                    Space1DDescription space = null;
                    if (spaces.PanTiltSpeedSpace == null)
                    {
                        supported = false;
                    }
                    else
                    {
                        space = spaces.PanTiltSpeedSpace.Where(
                            S => S.URI == configuration.DefaultPTZSpeed.PanTilt.space).FirstOrDefault();
                        if (space == null)
                        {
                            supported = false;
                        }
                    }
                    if (!supported)
                    {
                        ok = false;
                        sb.AppendLine(
                            string.Format(
                                "PanTiltSpeedSpace with URI = '{0}' not found in SupportedPTZSpaces",
                                configuration.DefaultPTZSpeed.PanTilt.space));
                    }

                    //	DefaultPTZSpeed.PanTilt.x is not between SupportedPTZSpaces.PanTiltSpeedSpace.XRange.Min and SupportedPTZSpaces.PanTiltSpeedSpace.XRange.Max for appropriate PanTiltSpeedSpace.URI from GetNodesResponse.
                    //	DefaultPTZSpeed.PanTilt.y is not between SupportedPTZSpaces.PanTiltSpeedSpace.YRange.Min and SupportedPTZSpaces.PanTiltSpeedSpace.YRange.Max for appropriate PanTiltSpeedSpace.URI from GetNodesResponse. (see Questions)
                    // see questions = PanTile.y not defined =(
                    if (space != null && space.XRange != null)
                    {
                        if (configuration.DefaultPTZSpeed.PanTilt.x < space.XRange.Min ||
                            configuration.DefaultPTZSpeed.PanTilt.x > space.XRange.Max)
                        {
                            ok = false;
                            sb.AppendLine(string.Format("DefaultPTZSpeed.PanTilt.x ({0}) is out of range ([{1},{2}])",
                                                        configuration.DefaultPTZSpeed.PanTilt.x, space.XRange.Min, space.XRange.Max));
                        }

                        if (configuration.DefaultPTZSpeed.PanTilt.y < space.XRange.Min ||
                            configuration.DefaultPTZSpeed.PanTilt.y > space.XRange.Max)
                        {
                            ok = false;
                            sb.AppendLine(string.Format("DefaultPTZSpeed.PanTilt.y ({0}) is out of range ([{1},{2}])",
                                                        configuration.DefaultPTZSpeed.PanTilt.y, space.XRange.Min, space.XRange.Max));
                        }
                    }
                }

                if (configuration.DefaultPTZSpeed.Zoom != null)
                {
                    bool supported = true;

                    //	DefaultPTZSpeed.Zoom.Space is not included in one of ZoomSpeedSpace.URI section of GetNodesResponse
                    Space1DDescription space = null;
                    if (spaces.ZoomSpeedSpace == null)
                    {
                        supported = false;
                    }
                    else
                    {
                        space = spaces.ZoomSpeedSpace.Where(
                            S => S.URI == configuration.DefaultPTZSpeed.Zoom.space).FirstOrDefault();
                        if (space == null)
                        {
                            supported = false;
                        }
                    }
                    if (!supported)
                    {
                        ok = false;
                        sb.AppendLine(
                            string.Format(
                                "PanTiltZoomSpace with URI = '{0}' not found in SupportedPTZSpaces",
                                configuration.DefaultPTZSpeed.Zoom.space));
                    }

                    //	DefaultPTZSpeed.Zoom.x is not between SupportedPTZSpaces.ZoomSpeedSpace.XRange.Min and SupportedPTZSpaces.ZoomSpeedSpace.XRange.Max for appropriate ZoomSpeedSpace.URI from GetNodesResponse.
                    if (space != null && space.XRange != null)
                    {
                        if (configuration.DefaultPTZSpeed.Zoom.x < space.XRange.Min ||
                            configuration.DefaultPTZSpeed.Zoom.x > space.XRange.Max)
                        {
                            ok = false;
                            sb.AppendLine(string.Format("DefaultPTZSpeed.Zoom.x ({0}) is out of range ([{1}, {2}])",
                                                        configuration.DefaultPTZSpeed.Zoom.x, space.XRange.Min, space.XRange.Max));
                        }
                    }
                }
            }

            return(ok);
        }