示例#1
0
        public bool EndSearch(string token)
        {
            SearchSession session = GetSession(token);

            if (session != null)
            {
                Sessions.Remove(session);
            }
            return(session != null);
        }
示例#2
0
        public SearchSession GetSession(string token)
        {
            SearchSession session = Sessions.Where(S => S.Token == token).FirstOrDefault();

            if (session != null)
            {
                // expired
                if (session.LastRequest.AddSeconds(session.KeepAlive) < System.DateTime.Now)
                {
                    Sessions.Remove(session);
                    return(null);
                }

                session.LastRequest = System.DateTime.Now;
            }
            return(session);
        }
        public override FindPTZPositionResultList GetPTZPositionSearchResults(string SearchToken, int MinResults, bool MinResultsSpecified, int MaxResults, bool MaxResultsSpecified, string WaitTime)
        {
            SearchSession session = SearchSessionManager.Instance.GetSession(SearchToken);

            if (session != null)
            {
                List <FindPTZPositionResult> data = (List <FindPTZPositionResult>)session.Data;

                FindPTZPositionResultList list = new FindPTZPositionResultList();

                Random rnd = new Random();
                int    cnt = Math.Min(rnd.Next(1, 4), data.Count);

                rnd = new Random();
                int sleep = rnd.Next(1, 3);
                System.Threading.Thread.Sleep(400 * sleep + 450);

                list.Result = new FindPTZPositionResult[cnt];
                for (int i = 0; i < cnt; i++)
                {
                    list.Result[i] = data[0];
                    data.RemoveAt(0);
                }
                session.ResultsSent = session.ResultsSent + cnt;
                list.SearchState    = data.Count > 0 ? SearchState.Searching : SearchState.Completed;

                if (data.Count == 0)
                {
                    SearchSessionManager.Instance.Sessions.Remove(session);
                }
                return(list);
            }
            else
            {
                CommonUtils.ReturnFault(new string[] { "Sender", "InvalidArgVal", "InvalidToken" });
                return(null);
            }
        }
        public override string FindPTZPosition(System.DateTime StartPoint, System.DateTime EndPoint, bool EndPointSpecified, SearchScope Scope, PTZPositionFilter SearchFilter, int MaxMatches, bool MaxMatchesSpecified, string KeepAliveTime)
        {
            string token = SearchSessionManager.Instance.GetNextToken();

            int    keepAliveTime = 0;
            string strKeepAlive  = KeepAliveTime.Substring(2, KeepAliveTime.Length - 3);

            keepAliveTime = int.Parse(strKeepAlive);
            if (KeepAliveTime.EndsWith("M"))
            {
                keepAliveTime = keepAliveTime * 60;
            }

            SearchSession session = new SearchSession()
            {
                KeepAlive   = keepAliveTime,
                Token       = token,
                Started     = System.DateTime.Now,
                LastRequest = System.DateTime.Now
            };

            bool ascending = true;

            if (EndPointSpecified)
            {
                if (EndPoint < StartPoint)
                {
                    ascending = false;
                }
            }

            List <FindPTZPositionResult> filtered = SearchStorage.Instance.PtzPositions;

            if (ascending)
            {
                filtered =
                    filtered.Where(E => (E.Time >= StartPoint &&
                                         (E.Time <= EndPoint || !EndPointSpecified))).OrderBy(E => E.Time).ToList();
            }
            else
            {
                filtered =
                    filtered.Where(E => (E.Time <= StartPoint &&
                                         (E.Time >= EndPoint || !EndPointSpecified))).OrderByDescending(E => E.Time).ToList();
            }

            List <FindPTZPositionResult> list;

            if (MaxMatchesSpecified)
            {
                list = new List <FindPTZPositionResult>();
                for (int i = 0; i < Math.Min(MaxMatches, filtered.Count); i++)
                {
                    list.Add(filtered[i]);
                }
            }
            else
            {
                list = new List <FindPTZPositionResult>(filtered);
            }


            session.Data = list;

            SearchSessionManager.Instance.Sessions.Add(session);
            return(token);
        }