예제 #1
0
        public override FindMetadataResultList GetMetadataSearchResults(string SearchToken, int MinResults, [System.Xml.Serialization.XmlIgnoreAttribute()] bool MinResultsSpecified, int MaxResults, [System.Xml.Serialization.XmlIgnoreAttribute()] bool MaxResultsSpecified, [System.Xml.Serialization.XmlElementAttribute(DataType = "duration")] string WaitTime)
        {
            RecordingEntitiesSearchSession session = SearchSessionManager.Instance.GetSession(SearchToken) as RecordingEntitiesSearchSession;

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

                FindMetadataResultList list = new FindMetadataResultList();

                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 FindMetadataResult[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);
            }
        }
예제 #2
0
        public override string FindMetadata(System.DateTime StartPoint,
                                            System.DateTime EndPoint,
                                            [System.Xml.Serialization.XmlIgnoreAttribute()] bool EndPointSpecified,
                                            SearchScope Scope,
                                            MetadataFilter MetadataFilter,
                                            int MaxMatches,
                                            [System.Xml.Serialization.XmlIgnoreAttribute()] bool MaxMatchesSpecified,
                                            [System.Xml.Serialization.XmlElementAttribute(DataType = "duration")] 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;
            }

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

            if (MaxMatchesSpecified)
            {
                session.MaxMatches = MaxMatches;
            }

            if (Scope != null && Scope.IncludedRecordings != null & Scope.IncludedRecordings.Length > 0)
            {
                session.RecordingToken = Scope.IncludedRecordings[0];
            }

            List <FindMetadataResult> resultsList = null;

            bool ascending = true;

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

            // to get different results from one search operation to another
            //SearchStorage.Instance.ClearMetadata();
            //SearchStorage.Instance.ChangeMetadataGeneration();

            IEnumerable <FindMetadataResult> filtered =
                SearchStorage.Instance.Metadata.Where(
                    E =>
                    E.RecordingToken == session.RecordingToken || string.IsNullOrEmpty(session.RecordingToken));


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

            if (session.MaxMatches.HasValue)
            {
                int cnt = Math.Min(session.MaxMatches.Value, resultsList.Count);
                List <FindMetadataResult> corrected = new List <FindMetadataResult>();
                for (int i = 0; i < cnt; i++)
                {
                    corrected.Add(resultsList[i]);
                }
                session.Data = corrected;
            }
            else
            {
                session.Data = resultsList;
            }

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