Beispiel #1
0
        public static TextSearchResult Search(string query, string module, int tenantId)
        {
            var result = new TextSearchResult();

            if (IsServiceProbablyNotAvailable() || string.IsNullOrEmpty(query))
            {
                return(result);
            }
            if (TextIndexCfg.MaxQueryLength < query.Length)
            {
                query = query.Substring(0, TextIndexCfg.MaxQueryLength);
            }
            query = query.Replace(":", "\\:");

            using (var service = new TextIndexServiceClient())
            {
                try
                {
                    var ids = service.Search(tenantId, query, module);
                    foreach (var id in ids)
                    {
                        result.AddIdentifier(id);
                    }
                    return(result);
                }
                catch (FaultException fe)
                {
                    LogError(fe);
                }
                catch (CommunicationException ce)
                {
                    LogError(ce);
                    lastErrorTime = DateTime.Now;
                }
                catch (TimeoutException te)
                {
                    LogError(te);
                    lastErrorTime = DateTime.Now;
                }
            }
            return(result);
        }
Beispiel #2
0
        private static object[] GetIdentifiers(TextSearchResult searchResult, int projectId, EntityType entryType)
        {
            var result = new List<object> { -1 };
            var ids = new List<string>();

            if (projectId != 0)
            {
                ids.AddRange(searchResult.GetIdentifierDetails(projectId.ToString(CultureInfo.InvariantCulture)));
            }
            else
            {
                ids.AddRange(searchResult.GetIdentifiers());
                foreach (var id in searchResult.GetIdentifiers())
                {
                    ids.AddRange(searchResult.GetIdentifierDetails(id));
                }
            }

            foreach (var id in ids)
            {
                if (entryType == EntityType.Project && char.IsDigit(id, id.Length - 1))
                {
                    result.Add(int.Parse(id));
                }
                else if (entryType == EntityType.Milestone && id.EndsWith("s"))
                {
                    result.Add(int.Parse(id.TrimEnd('s')));
                }
                else if (entryType == EntityType.Task && id.EndsWith("t"))
                {
                    result.Add(int.Parse(id.TrimEnd('t')));
                }
                else if (entryType == EntityType.Message && id.EndsWith("m"))
                {
                    result.Add(int.Parse(id.TrimEnd('m')));
                }
                else if (entryType == EntityType.File && id.EndsWith("f"))
                {
                    result.Add(id.TrimEnd('f'));
                }
            }

            return result.ToArray();
        }