Esempio n. 1
0
 /// <summary>
 /// Creates a new instance of SearchDescriptor using
 /// the provided propery values
 /// </summary>
 public SearchDescriptor(string targetField, SearchOperator searchOperator, object value, bool isCaseSensitive)
 {
     TargetField     = targetField;
     Operator        = searchOperator;
     Value           = value;
     IsCaseSensitive = isCaseSensitive;
 }
Esempio n. 2
0
        private List <Household> FilterByHouseholdSize(int size, SearchOperator oper, List <Household> lst)
        {
            List <Household> result;

            switch (oper)
            {
            case SearchOperator.GreaterThan:
                result = lst.Where(x => x.HouseholdSize > size).ToList();
                break;

            case SearchOperator.GreaterThanOrEqual:
                result = lst.Where(x => x.HouseholdSize >= size).ToList();
                break;

            case SearchOperator.LessThan:
                result = lst.Where(x => x.HouseholdSize < size).ToList();
                break;

            case SearchOperator.LessThanOrEqual:
                result = lst.Where(x => x.HouseholdSize <= size).ToList();
                break;

            case SearchOperator.NotEqual:
                result = lst.Where(x => x.HouseholdSize != size).ToList();
                break;

            default:     //defaults to Equals
                result = lst.Where(x => x.HouseholdSize == size).ToList();
                break;
            }

            return(result);
        }
Esempio n. 3
0
 /// <summary>
 /// Creates a new instance of SearchDescriptor using
 /// the provided propery values
 /// </summary>
 public SearchDescriptor(string targetField, SearchOperator searchOperator, object value, bool isCaseSensitive)
 {
     TargetField = targetField;
     Operator = searchOperator;
     Value = value;
     IsCaseSensitive = isCaseSensitive;
 }
Esempio n. 4
0
        private List <Household> FilterByAge(int age, SearchOperator oper, List <Household> lst)
        {
            List <Household> result;

            switch (oper)
            {
            case SearchOperator.GreaterThan:
                result = lst.Where(x => x.FamilyMembers.Any(f => f.Age > age)).ToList();
                break;

            case SearchOperator.GreaterThanOrEqual:
                result = lst.Where(x => x.FamilyMembers.Any(f => f.Age >= age)).ToList();
                break;

            case SearchOperator.LessThan:
                result = lst.Where(x => x.FamilyMembers.Any(f => f.Age < age)).ToList();
                break;

            case SearchOperator.LessThanOrEqual:
                result = lst.Where(x => x.FamilyMembers.Any(f => f.Age <= age)).ToList();
                break;

            case SearchOperator.NotEqual:
                result = lst.Where(x => x.FamilyMembers.Any(f => f.Age != age)).ToList();
                break;

            default:     //defaults to Equals
                result = lst.Where(x => x.FamilyMembers.Any(f => f.Age == age)).ToList();
                break;
            }



            return(result);
        }
Esempio n. 5
0
        public void interruptionScanDirTest()
        {
            try
            {
                var fs3 = new SearchOperator(dir2);
                try
                {
                    var ts  = new CancellationTokenSource();
                    var tsk = Task.Run(() => fs3.scanDir(null, ts.Token), ts.Token);
                    Thread.Sleep(1000);
                    fs3.CancelToken.Cancel();
                }
                catch (Exception e) {
                    Console.WriteLine(e.Message);
                    Assert.Fail();
                }
                var count = fs3.filesPath.Count;
                var res2  = Task.Run(() => fs3.scanDir());
                res2.Wait();

                Assert.IsTrue(count < fs3.filesPath.Count);
            }
            catch (Exception ex)
            {
                Console.Error.WriteLine(ex.Message);
                Assert.Fail();
            }
        }
Esempio n. 6
0
        public static SearchCriteria Create(string internalName, string displayName, SearchFieldType filterType, SearchOperator searchOperator, string value)
        {
            SearchCriteria criteria = null;
            if (CampaignSearchCriteria.IsCampaignSearchCriteria(internalName)) criteria = new CampaignSearchCriteria();
            else if (LocationSearchCriteria.IsLocationSearchCriteria(internalName)) criteria = new LocationSearchCriteria();
            else if (DonationSearchCriteria.IsDonationSearchCriteria(internalName)) criteria = new DonationSearchCriteria();
            else
            {
                if (internalName.StartsWith("freeTextFacet_"))
                {
                    int facetId;
                    if (int.TryParse(internalName.Substring(14), out facetId))
                    {
                        criteria = new FacetSearchCriteria {FacetId = facetId};
                    }
                }

            }

            if (criteria == null)
            {
                throw new InvalidOperationException("Could not parse search criteria");
            }

            criteria.InternalName = internalName;
            criteria.DisplayName = displayName;
            criteria.Type = filterType;
            criteria.SearchOperator = searchOperator;
            criteria.Value = value;

            return criteria;
        }
Esempio n. 7
0
        public static string OperatorPrefix(this SearchOperator searchOperator)
        {
            switch (searchOperator)
            {
            case SearchOperator.CONTAINS: return(" like ");

            case SearchOperator.ENDWITH: return(" like ");

            case SearchOperator.STARTWITH: return(" like ");

            case SearchOperator.ORCONTAINS: return(" like ");

            case SearchOperator.EQ: return(" = ");

            case SearchOperator.GT: return(" > ");

            case SearchOperator.GTE: return(" >= ");

            case SearchOperator.LT: return(" < ");

            case SearchOperator.LTE: return(" <= ");

            case SearchOperator.NCONTAINS: return(" not like ");

            case SearchOperator.NOTEQ: return(" != ");

            case SearchOperator.OR: return(" in ");

            case SearchOperator.BETWEEN: return(" between ");

            default: return(" = ");
            }
        }
Esempio n. 8
0
        public ISearchOperator AddOperator(SearchOperator oper)
        {
            SearchOperatorImpl so = new SearchOperatorImpl(oper);

            terms.Add(so);
            return(so);
        }
Esempio n. 9
0
            public string MakeFilter()
            {
                string oper;

                switch (this.oper)
                {
                case SearchOperator.Or:
                    oper = "OR";
                    break;

                case SearchOperator.And:
                    oper = "AND";
                    break;

                default:
                    throw new NotImplementedException();
                }

                string query = "";

                foreach (SearchTerm term in terms)
                {
                    if (query.Length > 0)
                    {
                        query += oper;
                    }
                    query += "(" + term.MakeFilter() + ")";
                }
                return(query);
            }
Esempio n. 10
0
        public void interruptionSearchFileTest()
        {
            var fs3 = new SearchOperator(@"C:\Program Files\Java");

            fs3.scanDir();
            ////chapter 1
            var count = fs3.filesPath.Count;
            var t     = new CancellationTokenSource();
            var ts    = Task.Run(() => fs3.searchFiles(".", ".", t.Token), t.Token);

            Thread.Sleep(400);
            t.Cancel();
            //ts.Wait();
            var c1 = count - fs3.filesPath.Count;

            ////chapter 2
            t  = new CancellationTokenSource();
            ts = Task.Run(() => fs3.searchFiles(".", ".", t.Token), t.Token);
            Thread.Sleep(400);
            t.Cancel();
            //ts.Wait();
            //t.Dispose();
            var c2 = count - fs3.filesPath.Count;

            //chapter3
            ts = Task.Run(() => fs3.searchFiles(".", "."));
            ts.Wait();
            var c3 = count - fs3.filesPath.Count - c1 - c2;

            Assert.AreEqual(count, c1 + c2 + c3);
            //Assert.AreEqual(fs3.filesPath.Count, 0);
        }
        /// <summary>
        /// Add an expression
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="field"></param>
        /// <param name="op"></param>
        /// <param name="value"></param>
        /// <param name="type"></param>
        /// <returns></returns>
        public FilterExpression Add <T>(String field, SearchOperator op, T value, SearchType type) where T : IConvertible
        {
            if (Request != null && Request.AvailableSearchFields.Length > 0)
            {
                if (!Array.Exists(Request.AvailableSearchFields, f => f == field))
                {
                    throw new MerchantAPIException(String.Format("Search field {0} does not exist. Available fields are {1}", field, String.Join(", ", Request.AvailableSearchFields)));
                }
            }

            if (this.Entries.Count == 0)
            {
                type = SearchType.search;
            }
            else if (this.Entries.Count > 0 && type == SearchType.search)
            {
                type = SearchType.search_OR;
            }

            this.Entries.Add(new FilterExpressionEntry(
                                 this,
                                 SearchType.search_AND,
                                 new FilterExpressionOperation(field, value.ToString(), op, type)
                                 ));

            return(this);
        }
Esempio n. 12
0
        public override bool Execute()
        {
            SearchOperator searchOp = new SearchOperator(Base.Document.Subtitles);

            replacedSubtitles = searchOp.ReplaceAll(regex, replacement);
            if (replacedSubtitles.Count == 0)
            {
                return(false);
            }

            TreePath[]    paths  = null;
            CommandTarget target = CommandTarget.Normal;

            GetCommandData(out paths, out target);

            SetCommandTarget(target);
            Paths = paths;
            if (Paths.Length > 0)
            {
                Focus = Paths[0];
            }

            Base.Ui.View.Selection.Select(Paths, Focus, true);
            return(true);
        }
Esempio n. 13
0
 /// <summary>
 /// 获取每个查询条件单元
 /// </summary>
 /// <param name="fieldName"></param>
 /// <param name="values"></param>
 /// <param name="param"></param>
 /// <returns></returns>
 public static Expression GetSearchItemExpression(SearchOperator op, string fieldName, string rightFieldName, object[] values, ParameterExpression param)
 {
     if (string.IsNullOrEmpty(fieldName))
     {
         return null;
     }
     if (values == null || values.Length == 0)
     {
         values = new object[] { null };
     }
     switch (op)
     {
         case SearchOperator.Like:
             return GetLikeExpression(param, fieldName, values[0].ToString());
         case SearchOperator.Equal:
             return GetEquelExpression(param, fieldName, rightFieldName, values[0]);
         case SearchOperator.NotEqual:
             return GetNotEquelExpression(param, fieldName, rightFieldName, values[0]);
         case SearchOperator.GreaterThan:
             return GetGreaterExpression(param, false, fieldName, values[0]);
         case SearchOperator.GreaterThanOrEqual:
             return GetGreaterExpression(param, true, fieldName, values[0]);
         case SearchOperator.LessThan:
             return GetLessExpression(param, false, fieldName, values[0]);
         case SearchOperator.LessThanOrEqual:
             return GetLessExpression(param, true, fieldName, values[0]);
         case SearchOperator.In:
             return GetInExpression(param, fieldName, values);
         case SearchOperator.NotIn:
             return GetNotInExpression(param, fieldName, values);
     }
     return null;
 }
Esempio n. 14
0
        private List <Household> FilterByHouseholdIncome(decimal income, SearchOperator oper, List <Household> lst)
        {
            List <Household> result;

            switch (oper)
            {
            case SearchOperator.GreaterThan:
                result = lst.Where(x => x.HouseholdIncome > income).ToList();
                break;

            case SearchOperator.GreaterThanOrEqual:
                result = lst.Where(x => x.HouseholdIncome >= income).ToList();
                break;

            case SearchOperator.LessThan:
                result = lst.Where(x => x.HouseholdIncome < income).ToList();
                break;

            case SearchOperator.LessThanOrEqual:
                result = lst.Where(x => x.HouseholdIncome <= income).ToList();
                break;

            case SearchOperator.NotEqual:
                result = lst.Where(x => x.HouseholdIncome != income).ToList();
                break;

            default:     //defaults to Equals
                result = lst.Where(x => x.HouseholdIncome == income).ToList();
                break;
            }

            return(result);
        }
 public static string GetString(SearchOperator aSearchOperator)
 {
     string lRet = "";
     switch (aSearchOperator)
     {
         case SearchOperator.CONTAINS:
             lRet = "包含";
             break;
         case SearchOperator.NOTCONTAINS:
             lRet = "不包含";
             break;
         case SearchOperator.EQUAL:
             lRet = "相等";
             break;
         case SearchOperator.NOEQUAL:
             lRet = "不相等";
             break;
         case SearchOperator.GREATER:
             lRet = "大于";
             break;
         case SearchOperator.LESS:
             lRet = "小于";
             break;
         case SearchOperator.GREATEREQUAL:
             lRet = "大于等于";
             break;
         case SearchOperator.LESSEQUAL:
             lRet = "小于等于";
             break;
     }
     return lRet;
 }
Esempio n. 16
0
        public IBlankQuery Search(Parameter searchWords, SearchOperator searchOperator, Node searchNodeType, params FieldResult[] searchFields)
        {
            SetType(PartType.Search);

            SearchWords    = searchWords;
            SearchOperator = searchOperator;
            Patterns       = new[] { searchNodeType };
            Fields         = searchFields;

            if ((object?)searchNodeType.NodeAlias is null)
            {
                throw new ArgumentException($"The searchNodeType does not have an alias. Rewite your query to: {Example()}");
            }

            foreach (FieldResult field in Fields)
            {
                if ((object?)field.Alias != searchNodeType.NodeAlias)
                {
                    throw new ArgumentException($"The searchfield should be retrieved from the searchNodeType it's alias. Rewite your query to: {Example()}");
                }

                if ((object?)field.Alias != searchNodeType.NodeAlias)
                {
                    throw new ArgumentException($"The searchfield '{field.FieldName}' is not supported for free text searching. Add it to the free text index in an upgrade script.");
                }
            }

            return(New);

            string Example()
            {
                return($"Search({SearchWordExample()}, {OperatorExample()}, {NodeTypeExample()}, {SearchFieldExample()}, ...)");
            }

            string SearchFieldExample()
            {
                return($"{AliasExample()}.{searchFields.FirstOrDefault().FieldName ?? "FieldName"}");
            }

            string NodeTypeExample()
            {
                return($"node.{searchNodeType.Neo4jLabel}.Alias(out var {AliasExample()})");
            }

            string AliasExample()
            {
                return(searchNodeType.Neo4jLabel.ToCamelCase());
            }

            string OperatorExample()
            {
                return($"SearchOperator.{searchOperator.ToString()}");
            }

            string SearchWordExample()
            {
                return($"Parameter.New<string>(\"{searchWords?.Name ?? "SearchWords"}\")");
            }
        }
Esempio n. 17
0
        public SearchProperty(string name, string value, SearchOperator searchOperator)
        {
            if (name == null)
                throw new ArgumentNullException("name");

            this.Name = name;
            this.Value = value;
            this.SearchOperator = searchOperator;
        }
Esempio n. 18
0
        public IBlankQuery UnionSearch(bool duplicates, Parameter searchWords, SearchOperator searchOperator, Node searchNodeType, out FloatResult scoreAlias, params FieldResult[] searchFields)
        {
            AliasResult scoreResult = new AliasResult();

            scoreAlias = new FloatResult(scoreResult, null, null, typeof(double));
            Aliases    = new[] { scoreResult };

            return(UnionSearch(duplicates, searchWords, searchOperator, searchNodeType, searchFields));
        }
 public void AddArgument(
     string propertyName,
     SearchMethod method,
     string value,
     SearchOperator combineWithOtherArgumentsAs = SearchOperator.And)
 {
     Arguments.Add(
         new SearchArgument(propertyName, method, value, combineWithOtherArgumentsAs));
 }
Esempio n. 20
0
 public IEnumerable <TodoItem> SearchItemsByName(string searchTerms, SearchOperator @operator = SearchOperator.Or)
 {
     using (var session = _store.OpenSession())
     {
         return(session.Advanced
                .DocumentQuery <TodoItem>()
                .Search(x => x.Name, searchTerms, @operator)
                .ToList());
     }
 }
Esempio n. 21
0
 public static WhereToken Search(string fieldName, string parameterName, SearchOperator op)
 {
     return(new WhereToken
     {
         FieldName = fieldName,
         ParameterName = parameterName,
         WhereOperator = WhereOperator.Search,
         SearchOperator = op
     });
 }
Esempio n. 22
0
        public void searchFilesTest()
        {
            var fs3 = new SearchOperator(dir2);

            fs3.scanDir();
            var cc = fs3.filesPath.Count;

            fs3.searchFiles(".", ".");
            Assert.AreEqual(0, fs3.filesPath.Count);
            Assert.AreEqual(cc, fs3.Result.Count);
        }
        /// <summary>
        /// Add criterium
        /// </summary>
        /// <param name="name">Name</param>
        /// <param name="value">Value</param>
        /// <param name="op">operator</param>
        public void AddCriterium(string name, string value, SearchOperator op)
        {
            SetType(SearchType.Find);

            m_items.Add(new FindItem
            {
                Name     = name,
                Value    = value,
                Operator = op
            });
        }
Esempio n. 24
0
        public void shallowSearchFilesTest()
        {
            var fs3 = new SearchOperator(dir);

            fs3.scanDir();
            Assert.AreEqual(fs3.filesPath.Count, 7);

            fs3.searchFiles("file12", "12$");
            Assert.AreEqual(fs3.Result.Count, 1);
            Assert.AreEqual(0, fs3.filesPath.Count);
        }
 public SearchArgument(
     string propertyName,
     SearchMethod method,
     string searchValue,
     SearchOperator addAsOperator = SearchOperator.And)
 {
     PropertyName = propertyName ?? throw new ArgumentNullException(nameof(propertyName));
     Method       = method;
     SearchValue  = searchValue ?? throw new ArgumentNullException(nameof(searchValue));
     Operator     = addAsOperator;
 }
Esempio n. 26
0
        public SearchProperty(string name, string value, SearchOperator searchOperator)
        {
            if (name == null)
            {
                throw new ArgumentNullException("name");
            }

            this.Name           = name;
            this.Value          = value;
            this.SearchOperator = searchOperator;
        }
Esempio n. 27
0
        internal static string ToFriendlyDisplayString(this SearchOperator searchOperator)
        {
            string searchOperatorStr = searchOperator.ToString();
            string displayText       = Resources.ResourceManager.GetString(searchOperatorStr);

            if (displayText == null)
            {
                // split on capital letters and add spaces - purely as a fallback in case the enum value is not localised
                Regex capitalLetterMatch = new Regex("\\B[A-Z]", RegexOptions.Compiled);
                displayText = capitalLetterMatch.Replace(searchOperatorStr, " $&").ToLower(Thread.CurrentThread.CurrentCulture);
            }

            return(displayText);
        }
Esempio n. 28
0
            public override void VisitSearchOperator(SearchOperator node)
            {
                base.VisitSearchOperator(node);

                if (_position >= node.Condition.TextStart)
                {
                    _binder._rowScope = _binder.GetSearchColumnsTable(node);
                }

                if (node.InClause != null && _position >= node.InClause.TextStart)
                {
                    // in clause arguments are all tables, no columns visible
                    _binder._rowScope = null;
                }
            }
        /// <summary>
        /// Translates the searchOption enumerator into the search operator string FMSA expects.
        /// </summary>
        /// <param name="o">SearchOption enumerator value</param>
        /// <returns>string</returns>
        private static String RealSearchCriterium(SearchOperator o)
        {
            string temp = "";

            switch (o)
            {
            case SearchOperator.beginsWith:
                temp = "bw";
                break;

            case SearchOperator.biggerOrEqualThan:
                temp = "gte";
                break;

            case SearchOperator.biggerThan:
                temp = "gt";
                break;

            case SearchOperator.contains:
                temp = "cn";
                break;

            case SearchOperator.endsWith:
                temp = "ew";
                break;

            case SearchOperator.equals:
                temp = "eq";
                break;

            case SearchOperator.omit:
                temp = "neq";
                break;

            case SearchOperator.lessOrEqualThan:
                temp = "lte";
                break;

            case SearchOperator.lessThan:
                temp = "lt";
                break;
            }

            return(temp);
        }
Esempio n. 30
0
        //Housing Type only filters by equal or not equal
        private List <Household> FilterByHousingType(string housingType, SearchOperator oper, List <Household> lst)
        {
            List <Household> result;


            switch (oper)
            {
            case SearchOperator.NotEqual:
                result = lst.Where(x => x.HousingType != housingType).ToList();
                break;

            default:     //defaults to equal
                result = lst.Where(x => x.HousingType.ToLower() == housingType.ToLower()).ToList();
                break;
            }

            return(result);
        }
        public static string GetString(SearchOperator aSearchOperator)
        {
            string lRet = "";

            switch (aSearchOperator)
            {
            case SearchOperator.CONTAINS:
                lRet = "包含";
                break;

            case SearchOperator.NOTCONTAINS:
                lRet = "不包含";
                break;

            case SearchOperator.EQUAL:
                lRet = "相等";
                break;

            case SearchOperator.NOEQUAL:
                lRet = "不相等";
                break;

            case SearchOperator.GREATER:
                lRet = "大于";
                break;

            case SearchOperator.LESS:
                lRet = "小于";
                break;

            case SearchOperator.GREATEREQUAL:
                lRet = "大于等于";
                break;

            case SearchOperator.LESSEQUAL:
                lRet = "小于等于";
                break;
            }
            return(lRet);
        }
Esempio n. 32
0
        public async Task <Page <UserSearchResponse> > Get(string searchText, string profilePropertyName = null,
                                                           int?profilePropertyId         = null, bool searchUsername = false, bool searchSubAccounts = false,
                                                           SearchOperator searchOperator = SearchOperator.Equals, int pageSize = 5, int pageOffset   = 0,
                                                           string sortField = null, bool sortAscending = true, bool includeAvatar = false)
        {
            var searchLogic = new SearchLogic(Cache, Context);

            var search = new UserSearch
            {
                SearchText          = searchText,
                ProfilePropertyName = profilePropertyName,
                ProfilePropertyId   = profilePropertyId,
                SearchUsername      = searchUsername,
                Operator            = searchOperator,
                PageSize            = pageSize,
                PageOffset          = pageOffset,
                IsAdmin             = IsAdmin,
                SortAscending       = sortAscending,
                SortField           = sortField,
                IncludeAvatar       = includeAvatar
            };

            return(await searchLogic.Search(search));
        }
Esempio n. 33
0
        /// <summary>Finds text in the subtitles using the specified direction and the options set in the Find dialog.</summary>
        /// <param name="backwards">Whether to search backwards.</param>
        /// <returns>Whether the text was found.</returns>
        private bool Find(bool backwards)
        {
            if (dialog == null)
            {
                return(false);
            }

            /* Get selection range */
            SubtitleTextType textType;
            int selectionStart, selectionEnd;

            GetTextContentSelectionIndexes(out selectionStart, out selectionEnd, out textType);

            /* Get remaining properties */
            int   subtitle = GetFocusedSubtitle();
            Regex regex    = (backwards ? dialog.BackwardRegex : dialog.ForwardRegex);
            int   index    = (backwards ? selectionStart : selectionEnd);

            /* Search */
            SubtitleSearchOptions options  = new SubtitleSearchOptions(regex, textType, subtitle, index, dialog.Wrap, backwards);
            SearchOperator        searchOp = new SearchOperator(Base.Document.Subtitles);
            SubtitleSearchResults results  = searchOp.Find(options);

            /* If no text was found, return */
            if (results == null)
            {
                return(false);
            }

            /* Text was found, selecting it */
            int start, end;

            GetIndexesToSelect(results.Index, results.Index + results.Length, backwards, out start, out end);
            Base.Ui.View.Selection.Select(Util.IntToPath(results.Subtitle), true, true, start, end, results.TextType);
            return(true);
        }
        /// <summary>
        /// Search user groups that user can access.
        /// </summary>
        /// <param name="userId"></param>
        /// <param name="userGroupId"></param>
        /// <returns></returns>
        static public List<GXAmiUserGroup> GetUserGroups(IDbConnection Db, long userId, string[] search, SearchOperator searchOperator, SearchType searchType)
        {
            string query = "SELECT " + GuruxAMI.Server.AppHost.GetTableName<GXAmiUserGroup>(Db) + ".* FROM " + GuruxAMI.Server.AppHost.GetTableName<GXAmiUserGroup>(Db);
            query += "INNER JOIN " + GuruxAMI.Server.AppHost.GetTableName<GXAmiUserGroupUser>(Db) + " ON " + GuruxAMI.Server.AppHost.GetTableName<GXAmiUserGroupUser>(Db) + ".UserGroupID = " + GuruxAMI.Server.AppHost.GetTableName<GXAmiUserGroup>(Db) + ".ID ";
            query += string.Format("WHERE " + GuruxAMI.Server.AppHost.GetTableName<GXAmiUserGroup>(Db) + ".Removed IS NULL AND " + GuruxAMI.Server.AppHost.GetTableName<GXAmiUserGroupUser>(Db) + ".Removed IS NULL AND UserID = {0}", userId);

            if (search != null)
            {
                List<string> searching = new List<string>();
                List<string> Filter = new List<string>();
                foreach (string it in search)
                {
                    if ((searchType & SearchType.Name) != 0)
                    {
                        string tmp = string.Format("{0}.Name Like('%{1}%')",
                            GuruxAMI.Server.AppHost.GetTableName<GXAmiUser>(Db), it);
                        searching.Add(tmp);
                    }
                }
                if ((searchOperator & SearchOperator.And) != 0)
                {
                    Filter.Add("(" + string.Join(" AND ", searching.ToArray()) + ")");
                }
                if ((searchOperator & SearchOperator.Or) != 0)
                {
                    Filter.Add("(" + string.Join(" OR ", searching.ToArray()) + ")");
                }
                query += string.Join(" AND ", Filter.ToArray());
            }

            List<GXAmiUserGroup> rows = Db.Select<GXAmiUserGroup>(query);
            return rows;
        }
Esempio n. 35
0
 /// <inheritdoc />
 IDocumentQuery <T> IFilterDocumentQueryBase <T, IDocumentQuery <T> > .Search <TValue>(Expression <Func <T, TValue> > propertySelector, string searchTerms, SearchOperator @operator)
 {
     Search(GetMemberQueryPath(propertySelector.Body), searchTerms, @operator);
     return(this);
 }
Esempio n. 36
0
        public static List<GXAmiUser> GetUsers(IAuthSession s, IDbConnection Db, long userId, long groupId, bool removed, bool distinct, string[] search, SearchOperator searchOperator, SearchType searchType)
        {            
            string id = s.Id;
            if (Convert.ToInt32(id) == 0)
            {
                throw new ArgumentException("Invalid session ID.");
            }
            bool admin = GuruxAMI.Server.GXBasicAuthProvider.IsSuperAdmin(s);
            string query;
            if (distinct)
            {
                query = "SELECT DISTINCT " + GuruxAMI.Server.AppHost.GetTableName<GXAmiUser>(Db) + ".* FROM " + GuruxAMI.Server.AppHost.GetTableName<GXAmiUser>(Db) + " ";
            }
            else
            {
                query = "SELECT " + GuruxAMI.Server.AppHost.GetTableName<GXAmiUser>(Db) + ".* FROM " + GuruxAMI.Server.AppHost.GetTableName<GXAmiUser>(Db) + " ";
            }
            
            List<string> Filter = new List<string>();
            if (!admin || groupId != 0)
            {
                query += "INNER JOIN " + GuruxAMI.Server.AppHost.GetTableName<GXAmiUserGroupUser>(Db) + " ON " + GuruxAMI.Server.AppHost.GetTableName<GXAmiUserGroupUser>(Db) + ".UserID = " + GuruxAMI.Server.AppHost.GetTableName<GXAmiUser>(Db) + ".ID ";
            }
            if (!removed)
            {
                Filter.Add("" + GuruxAMI.Server.AppHost.GetTableName<GXAmiUser>(Db) + ".Removed IS NULL");
                if (!admin)
                {
                    Filter.Add("" + GuruxAMI.Server.AppHost.GetTableName<GXAmiUserGroupUser>(Db) + ".Removed IS NULL ");
                }
            }
            if (userId != 0)
            {
                Filter.Add("" + GuruxAMI.Server.AppHost.GetTableName<GXAmiUser>(Db) + ".ID = " + userId.ToString());
            }
            if (groupId != 0)
            {
                Filter.Add("UserGroupID = " + groupId.ToString());
            }

            if (search != null)
            {
                List<string> searching = new List<string>();
                foreach (string it in search)
                {
                    if ((searchType & SearchType.Name) != 0)
                    {
                        string tmp = string.Format("{0}.Name Like('%{1}%')",
                            GuruxAMI.Server.AppHost.GetTableName<GXAmiUser>(Db), it);
                        searching.Add(tmp);
                    }
                }
                if ((searchOperator & SearchOperator.And) != 0)
                {
                    Filter.Add("(" + string.Join(" AND ", searching.ToArray()) + ")");
                }
                if ((searchOperator & SearchOperator.Or) != 0)
                {
                    Filter.Add("(" + string.Join(" OR ", searching.ToArray()) + ")");
                }
            }
            if (Filter.Count != 0)
            {
                query += "WHERE ";
                query += string.Join(" AND ", Filter.ToArray());
            }
            if (!admin && groupId == 0)
            {
                if (Filter.Count == 0)
                {
                    query += "WHERE ";
                }
                else
                {
                    query += " AND ";
                }
                query += "" + GuruxAMI.Server.AppHost.GetTableName<GXAmiUserGroupUser>(Db) + ".UserID IN (";
                query += "SELECT UserID FROM " + GuruxAMI.Server.AppHost.GetTableName<GXAmiUserGroupUser>(Db) + " WHERE " + GuruxAMI.Server.AppHost.GetTableName<GXAmiUserGroupUser>(Db) + ".UserGroupID IN";
                query += "(";
                query += "SELECT UserGroupID FROM " + GuruxAMI.Server.AppHost.GetTableName<GXAmiUserGroupUser>(Db) + " WHERE UserID = " + id;
                if (!removed)
                {
                    query += " AND Removed IS NULL";
                }
                query += "))";
            }
            query += string.Format(" ORDER BY {0}.ID", GuruxAMI.Server.AppHost.GetTableName<GXAmiUser>(Db));
            return Db.Select<GXAmiUser>(query);           
        }
    public ProfileInfoCollection FindProfilesByPropertyValue(SettingsProperty property, SearchOperator searchOperator, object value)
    {
        // instantiate an empty ProfileInfoCollection to use it for return
        ProfileInfoCollection pic = new ProfileInfoCollection();

        // try and open the connection and get the results
        try
        {
            // get the connection we're going to use
            using (SqlConnection conn = new SqlConnection(_connectionStringName))
            {

                // instantiate a SettingsPropertyValue from the property
                // to use it to serialize the value for comparison with the database
                SettingsPropertyValue spv = new SettingsPropertyValue(property);
                spv.PropertyValue = value;

                // set common parameters of the aspnet_Profile_FindProfiles stored procedure
                SqlCommand FindProfilesCommand = new SqlCommand("aspnet_Profile_FindProfiles", conn);
                FindProfilesCommand.CommandType = CommandType.StoredProcedure;
                FindProfilesCommand.CommandTimeout = _commandTimeout;
                FindProfilesCommand.Parameters.Add("@ApplicationName", System.Data.SqlDbType.NVarChar, 256).Value = base.ApplicationName;
                FindProfilesCommand.Parameters.Add("@PropertyName", System.Data.SqlDbType.NVarChar, 256).Value = property.Name;
                FindProfilesCommand.Parameters.Add("@OperatorType", System.Data.SqlDbType.Int).Value = (Int32)searchOperator;

                // if the serialized property value is of type string
                // carry on if the size is within allowed limits
                Boolean bTooBig = false;
                if (spv.SerializedValue is String)
                {
                    // if the serialized value is bigger than the PropertyValueString column's length
                    if (((String)spv.SerializedValue).Length > Int32.MaxValue)
                    {
                        bTooBig = true;
                    }
                    else
                    {
                        if (searchOperator == SearchOperator.Contains || searchOperator == SearchOperator.FreeText)
                        {
                            // if the searchOperator is a freetext operator then pass the value unaltered
                            FindProfilesCommand.Parameters.Add("@PropertyValueString",
                                System.Data.SqlDbType.NVarChar, Int32.MaxValue).Value = spv.PropertyValue;
                            FindProfilesCommand.Parameters.Add("@PropertyValueBinary",
                                System.Data.SqlDbType.VarBinary, Int32.MaxValue).Value = DBNull.Value;
                        }
                        else
                        {
                            // otherwise serialise the value before passing it
                            FindProfilesCommand.Parameters.Add("@PropertyValueString",
                                System.Data.SqlDbType.NVarChar, Int32.MaxValue).Value = spv.SerializedValue;
                            FindProfilesCommand.Parameters.Add("@PropertyValueBinary",
                                System.Data.SqlDbType.VarBinary, Int32.MaxValue).Value = DBNull.Value;
                        }

                        // set the parameter @PropertyType to indicate the property is a string
                        FindProfilesCommand.Parameters.Add("@PropertyType", System.Data.SqlDbType.Bit).Value = 0;
                    }
                }
                else
                {
                    if (((SqlBinary)spv.SerializedValue).Length > Int32.MaxValue)
                    {
                        bTooBig = true;
                    }
                    else
                    {
                        if (searchOperator == SearchOperator.Contains || searchOperator == SearchOperator.FreeText)
                        {
                            // if the searchOperator is a freetext operator then pass the value unaltered to the
                            // @PropertyValueString because we are passing a string anyway not a binary
                            FindProfilesCommand.Parameters.Add("@PropertyValueString",
                                System.Data.SqlDbType.NVarChar, Int32.MaxValue).Value = spv.PropertyValue;
                            FindProfilesCommand.Parameters.Add("@PropertyValueBinary",
                                System.Data.SqlDbType.VarBinary, Int32.MaxValue).Value = DBNull.Value;
                        }
                        else
                        {
                            // otherwise just serialise the value and pass it to the @PropertyBinaryValue
                            FindProfilesCommand.Parameters.Add("@PropertyValueString",
                                System.Data.SqlDbType.NVarChar, Int32.MaxValue).Value = DBNull.Value;
                            FindProfilesCommand.Parameters.Add("@PropertyValueBinary",
                                System.Data.SqlDbType.VarBinary, Int32.MaxValue).Value = spv.SerializedValue;
                        }

                        // set the parameter @PropertyType to indicate the property is a binary
                        FindProfilesCommand.Parameters.Add("@PropertyType", System.Data.SqlDbType.Bit).Value = 1;
                    }
                }

                if (bTooBig)
                {
                    // if the size is out of limits throw an exception
                    throw new ProviderException("Property value length is too big.");
                }

                // Open the database
                conn.Open();

                // Get a DataReader for the results we need
                using (SqlDataReader rdr = FindProfilesCommand.ExecuteReader(CommandBehavior.CloseConnection))
                {
                    while (rdr.Read())
                    {
                        // create a ProfileInfo with the data you got back from the current record of the SqlDataReader
                        ProfileInfo pi = new ProfileInfo(rdr.GetString(rdr.GetOrdinal("UserName")),
                            rdr.GetBoolean(rdr.GetOrdinal("IsAnonymous")),
                            DateTime.SpecifyKind(rdr.GetDateTime(rdr.GetOrdinal("LastActivityDate")), DateTimeKind.Utc),
                            DateTime.SpecifyKind(rdr.GetDateTime(rdr.GetOrdinal("LastUpdatedDate")), DateTimeKind.Utc), 0);

                        // add the ProfileInfo you just created to the ProfileInfoCollection that we will return
                        pic.Add(pi);
                    }
                }
            }
        }
        catch (Exception e)
        {
            // if anything went wrong, throw an exception
            throw new ProviderException("An error occured while finding profiles with your search criteria!", e);
        }

        return pic;
    }
        static public List<GXAmiDevice> GetDevices(IAuthSession s, IDbConnection Db, long userId, long userGroupId, ulong deviceGroupId, ulong deviceID, bool removed, string[] search, SearchOperator searchOperator, SearchType searchType)
        {
            string id = s.Id;
            bool admin = GuruxAMI.Server.GXBasicAuthProvider.IsSuperAdmin(s);
            List<string> Filter = new List<string>();
            string query = string.Format("SELECT DISTINCT {0}.* FROM {0} ", GuruxAMI.Server.AppHost.GetTableName<GXAmiDevice>(Db));
            if (!admin || deviceGroupId != 0 || userGroupId != 0 || userId != 0)
            {
                string tmp = "INNER JOIN {1} ON {0}.ID = {1}.DeviceID ";
                tmp += "INNER JOIN {2} ON {1}.DeviceGroupID = {2}.ID ";
                tmp += "INNER JOIN {3} ON {2}.ID = {3}.DeviceGroupID ";
                tmp += "INNER JOIN {4} ON {3}.UserGroupID = {4}.ID ";
                tmp += "INNER JOIN {5} ON {4}.ID = {5}.UserGroupID ";                
                query += string.Format(tmp,
                    GuruxAMI.Server.AppHost.GetTableName<GXAmiDevice>(Db),
                    GuruxAMI.Server.AppHost.GetTableName<GXAmiDeviceGroupDevice>(Db),
                    GuruxAMI.Server.AppHost.GetTableName<GXAmiDeviceGroup>(Db),
                    GuruxAMI.Server.AppHost.GetTableName<GXAmiUserGroupDeviceGroup>(Db),
                    GuruxAMI.Server.AppHost.GetTableName<GXAmiUserGroup>(Db),
                    GuruxAMI.Server.AppHost.GetTableName<GXAmiUserGroupUser>(Db));
                if (!removed)
                {
                    Filter.Add(string.Format("{0}.Removed IS NULL AND {1}.Removed IS NULL AND {2}.Removed IS NULL",
                        GuruxAMI.Server.AppHost.GetTableName<GXAmiDevice>(Db),
                        GuruxAMI.Server.AppHost.GetTableName<GXAmiDeviceGroup>(Db),
                        GuruxAMI.Server.AppHost.GetTableName<GXAmiUserGroup>(Db)));
                }
                if (userId != 0)
                {
                    Filter.Add("UserID = " + userId.ToString());
                }
                else if (!admin)
                {
                    Filter.Add("UserID = " + id.ToString());
                }
                if (userGroupId != 0)
                {
                    Filter.Add("UserGroupID = " + userGroupId.ToString());
                }
                if (deviceGroupId != 0)
                {
                    Filter.Add(GuruxAMI.Server.AppHost.GetTableName<GXAmiDeviceGroup>(Db) + ".ID = " + deviceGroupId.ToString());
                }
            }
            else if (!removed)
            {
                Filter.Add("Removed IS NULL");
            }

            if (search != null)
            {
                List<string> searching = new List<string>();
                //searchOperator, SearchType searchType
                foreach (string it in search)
                {
                    if ((searchType & SearchType.Name) != 0)
                    {
                        string tmp = string.Format("{0}.Name Like('%{1}%')",
                            GuruxAMI.Server.AppHost.GetTableName<GXAmiDevice>(Db), it);
                        searching.Add(tmp);
                    }
                    if ((searchType & SearchType.Description) != 0)
                    {
                        string tmp = string.Format("{0}.Description Like('%{1}%')",
                            GuruxAMI.Server.AppHost.GetTableName<GXAmiDevice>(Db), it);
                        searching.Add(tmp);
                    }
                }
                if ((searchOperator & SearchOperator.And) != 0)
                {
                    Filter.Add("(" + string.Join(" AND ", searching.ToArray()) + ")");
                }
                if ((searchOperator & SearchOperator.Or) != 0)
                {
                    Filter.Add("(" + string.Join(" OR ", searching.ToArray()) + ")");
                }
            }
            if (deviceID != 0)
            {
                Filter.Add(GuruxAMI.Server.AppHost.GetTableName<GXAmiDevice>(Db) + ".ID = " + deviceID.ToString());
            }
            if (Filter.Count != 0)
            {
                query += "WHERE ";
                query += string.Join(" AND ", Filter.ToArray());
            }
            List<GXAmiDevice> list = Db.Select<GXAmiDevice>(query);            
            return list;
        }