public void test_WHEN_list_of_expressions_is_null_THEN_exception_is_thrown() { Camlex.Query().WhereAny((IEnumerable <string>)null).ToString(); }
public void test_WHEN_list_of_expressions_is_empty_THEN_exception_is_thrown() { Camlex.Query().WhereAny(new string[] {}).ToString(); }
public void test_WHEN_expressions_list_is_empty_THEN_exception_is_thrown() { var expressions = new List <Expression <Func <SPListItem, bool> > >(); Camlex.Query().WhereAny(expressions).ToString(); }
public void test_WHEN_expressions_list_is_null_THEN_exception_is_thrown() { Camlex.Query().WhereAny((IEnumerable <Expression <Func <SPListItem, bool> > >)null).ToString(); }
public List <ProductsServicesMenu> get_ProductsServicesMenu(SPWeb web) { var pList = web.Lists[web.Language == 1033 ? Constants.ProductionServices.ListNameEnglish : Constants.ProductionServices.ListName]; var productsServicesMenu = new List <ProductsServicesMenu>(); var query = Camlex.Query() .Where(c => (Boolean)c[Constants.ProductionServicesGroup.InternalFields.Activate]) .OrderBy(c => c[Constants.ProductionServicesGroup.InternalFields.Order] as Camlex.Asc).ToSPQuery(); var list = web.Lists[listName]; var items = list.GetItems(query); if (items.Count > 0) { foreach (SPListItem item in items) { var menu = new ProductsServicesMenu() { Title = item.Title, Id = item.ID, level = 1, subTitle = string.Empty, Url = "#" }; productsServicesMenu.Add(menu); var level2 = get_Level2(web, pList, item.ID.ToString()); foreach (SPListItem subItem in level2) { menu = new ProductsServicesMenu() { Title = subItem.Title, Id = subItem.ID, level = 2, subTitle = string.Empty, ParrentId = item.ID, Url = web.Language == 1033? string.Format("{0}/for customers/{1}/{2}-{3}-{4}.html", web.Url, Utilities.ConvertToUnsign(item.Title), Utilities.ConvertToUnsign(subItem.Title), item.ID, subItem.ID):string.Format("{0}/san-pham-dich-vu/{1}/{2}/{3}-{4}-{5}.html", web.Url, Utilities.ConvertToUnsign(item.Title), Utilities.ConvertToUnsign(subItem.Title), "Thong-tin-san-pham-dich-vu", item.ID, subItem.ID), }; productsServicesMenu.Add(menu); var level3 = get_Level3(web, pList, subItem.ID.ToString()); foreach (SPListItem l3 in level3) { var sTitle = new SPFieldLookupValue(Convert.ToString(l3[Constants.ProductionServices.InternalFields.SubService])); menu = new ProductsServicesMenu() { Title = l3.Title, Id = l3.ID, level = 3, subTitle = sTitle.LookupValue, ParrentId = subItem.ID, Url = web.Language == 1033 ? string.Format("{0}/for customers/{1}/{2}-{3}-{4}.html", web.Url, Utilities.ConvertToUnsign(item.Title), Utilities.ConvertToUnsign(l3.Title), item.ID, l3.ID) : string.Format("{0}/san-pham-dich-vu/{1}/{2}/{3}-{4}-{5}.html", web.Url, Utilities.ConvertToUnsign(item.Title), Utilities.ConvertToUnsign(l3.Title), "Thong-tin-san-pham-dich-vu", item.ID, l3.ID), }; productsServicesMenu.Add(menu); } } } } return(productsServicesMenu); }
public ProductServiceInfo get_ProductSeviceInfoById(SPWeb web, string id) { if (!string.IsNullOrEmpty(id)) { var query = Camlex.Query() .Where( c => (int)c[Constants.CommonField.ID] == Convert.ToInt32(id) && (Boolean)c[Constants.ProductionServices.InternalFields.Activate]) .ToSPQuery(); query.ViewFields = Camlex.Query().ViewFields(x => new[] { x[Constants.ProductionServices.InternalFields.Content], x[Constants.ProductionServices.InternalFields.Content1], x[Constants.ProductionServices.InternalFields.Content2], x[Constants.ProductionServices.InternalFields.Content3], x[Constants.ProductionServices.InternalFields.Content4], x[Constants.ProductionServices.InternalFields.Partner1], x[Constants.ProductionServices.InternalFields.Partner2], x[Constants.ProductionServices.InternalFields.Partner3], x[Constants.ProductionServices.InternalFields.SubService], x[Constants.ProductionServices.InternalFields.ProductsServices], x[Constants.ProductionServices.InternalFields.IsShowVenders], x[Constants.ProductionServices.InternalFields.Tranformer], x[Constants.ProductionServices.InternalFields.Retail], x[Constants.ProductionServices.InternalFields.Communication], x[Constants.ProductionServices.InternalFields.Ensurance], x[Constants.ProductionServices.InternalFields.Game], x[Constants.ProductionServices.InternalFields.Digital], x[Constants.ProductionServices.InternalFields.ElectronicWallet], x[Constants.ProductionServices.InternalFields.AnotherServices], x[Constants.CommonField.Title], x[Constants.CommonField.ID] }); var list = web.Lists[listName]; var items = list.GetItems(query); if (items.Count > 0) { var item = items[0]; return(new ProductServiceInfo() { Id = item.ID, Title = item.Title, WebUrl = web.Url, Language = web.Language, Content = Convert.ToString(item[Constants.ProductionServices.InternalFields.Content]), Content1 = Convert.ToString(item[Constants.ProductionServices.InternalFields.Content1]), Content2 = Convert.ToString(item[Constants.ProductionServices.InternalFields.Content2]), Content3 = Convert.ToString(item[Constants.ProductionServices.InternalFields.Content3]), Content4 = Convert.ToString(item[Constants.ProductionServices.InternalFields.Content4]), Partner1 = new SPFieldLookupValueCollection(Convert.ToString(item[Constants.ProductionServices.InternalFields.Partner1])), Partner2 = new SPFieldLookupValueCollection(Convert.ToString(item[Constants.ProductionServices.InternalFields.Partner2])), Partner3 = new SPFieldLookupValueCollection(Convert.ToString(item[Constants.ProductionServices.InternalFields.Partner3])), SubServiceValue = new SPFieldLookupValue(Convert.ToString(item[Constants.ProductionServices.InternalFields.SubService])), FullCat = Convert.ToString(item[Constants.ProductionServices.InternalFields.ProductsServices]), HasVenders = Convert.ToBoolean(item[Constants.ProductionServices.InternalFields.IsShowVenders]), Tranformer = new SPFieldLookupValueCollection(Convert.ToString(item[Constants.ProductionServices.InternalFields.Tranformer])), Retail = new SPFieldLookupValueCollection(Convert.ToString(item[Constants.ProductionServices.InternalFields.Retail])), Communication = new SPFieldLookupValueCollection(Convert.ToString(item[Constants.ProductionServices.InternalFields.Communication])), Ensurance = new SPFieldLookupValueCollection(Convert.ToString(item[Constants.ProductionServices.InternalFields.Ensurance])), Game = new SPFieldLookupValueCollection(Convert.ToString(item[Constants.ProductionServices.InternalFields.Game])), Digital = new SPFieldLookupValueCollection(Convert.ToString(item[Constants.ProductionServices.InternalFields.Digital])), ElectronicWallet = new SPFieldLookupValueCollection(Convert.ToString(item[Constants.ProductionServices.InternalFields.ElectronicWallet])), Other = new SPFieldLookupValueCollection(Convert.ToString(item[Constants.ProductionServices.InternalFields.AnotherServices])), List = list, }); } } return(new ProductServiceInfo()); }
public void test_WHEN_expressions_list_is_null_THEN_exception_is_thrown() { Assert.Throws <EmptyExpressionsListException>(() => Camlex.Query().WhereAny((IEnumerable <Expression <Func <SPListItem, bool> > >)null).ToString()); }
public void test_WHEN_array_of_ids_is_null_THEN_exception_is_thrown() { Camlex.Query().ViewFields((IEnumerable <Guid>)null); }
public void test_WHEN_order_by_list_is_empty_THEN_exception_is_thrown() { var orderByList = new List <Expression <Func <SPListItem, object> > >(); Assert.Throws <EmptyExpressionsListException>(() => Camlex.Query().OrderBy(orderByList).ToString()); }
public string GetQueryByFilters() { Dictionary <string, FieldFilterOperator> operators = operatorsLayer.GetOperatorsDict(); var conditions = new List <Expression <Func <SPListItem, bool> > >(); var allKeys = this.queryString.Keys.Cast <string>(); foreach (string fKey in allKeys.Where(x => x.StartsWith("FilterField"))) { // get field info string fldIntName = queryString[fKey]; SPField fld = this.list.Fields.GetFieldByInternalName(fldIntName); string fldFilterVal = System.Web.HttpUtility.UrlDecode(queryString[fKey.Replace("Field", "Value")]); bool isLookupIdFilter = false; if (allKeys.Contains(fKey.Replace("Field", "LookupId"))) { isLookupIdFilter = (System.Web.HttpUtility.UrlDecode(queryString[fKey.Replace("Field", "LookupId")]) == "1"); // FilterLookupId{0}=1 } bool isMultiValueFilter = fKey.Contains("s"); bool isFieldOperExists = operators.ContainsKey(fldIntName) && (operators[fldIntName] != FieldFilterOperator.None); bool isFieldHasNOToperator = isFieldOperExists && (operators[fldIntName] == FieldFilterOperator.NOT); if (string.IsNullOrEmpty(fldFilterVal)) { // empty filter value if (isFieldHasNOToperator) { conditions.Add(x => x[fldIntName] != null); // IsNotNull } else { conditions.Add(x => x[fldIntName] == null); // IsNull } } else if (isLookupIdFilter) { // LookupId Filter string[] values = fldFilterVal.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries); if (!isFieldOperExists || (operators[fldIntName] == FieldFilterOperator.OR)) { // standart IN operator: a OR b OR c OR d conditions.Add(CamlQueryHealper.GetOperation_OrEqLookupId(fld, values)); // In operator } else if (isFieldHasNOToperator) { // sample: (NOT a) AND (NOT b) conditions.Add(CamlQueryHealper.GetOperation_AndNeqLookupId(fld, values)); } else { // sample: a AND b AND c conditions.Add(CamlQueryHealper.GetOperation_AndEqLookupId(fld, values)); } } else if (!isMultiValueFilter) { // single-value Filter if (isFieldHasNOToperator) { conditions.Add(CamlQueryHealper.GetOperation_Neq(fld, fldFilterVal)); // Neq } else { conditions.Add(CamlQueryHealper.GetOperation_Eq(fld, fldFilterVal)); // Eq } } else { // multi-value filter string[] values = fldFilterVal.Split(new string[] { ";#" }, StringSplitOptions.RemoveEmptyEntries); if (!isFieldOperExists || (operators[fldIntName] == FieldFilterOperator.OR)) { // standart IN operator: a OR b OR c OR d conditions.Add(CamlQueryHealper.GetOperation_In(fld, values)); // In operator } else if (isFieldHasNOToperator) { // sample: (NOT a) AND (NOT b) conditions.Add(CamlQueryHealper.GetOperation_AndNeq(fld, values)); } else { // sample: a AND b AND c conditions.Add(CamlQueryHealper.GetOperation_AndEq(fld, values)); } } } IQuery query = Camlex.Query(); if (this.queryString.Keys.Cast <string>().Contains("SortField")) { if (this.queryString["SortDir"] == "Desc") { query.OrderBy(x => x[this.queryString["SortField"]] as Camlex.Desc); } else { query.OrderBy(x => x[this.queryString["SortField"]] as Camlex.Asc); } } if (conditions.Count > 0) { query.WhereAll(conditions); } return(query.ToString()); }
public void test_WHEN_expression_with_nested_argument_THEN_exception_is_thrown() { string caml = Camlex.Query().Where(x => (string)x[(string)x["Title"]] == "foo").ToString(); }
public void test_WHEN_integer_indexer_param_is_used_THEN_exception_is_thrown() { string caml = Camlex.Query().Where(x => (string)x[1] == "testValue").ToString(); }
public void test_WHEN_eq_expression_with_null_variable_casted_to_string_based_syntax_THEN_exception_is_thrown() { string val = null; Camlex.Query().Where(x => x["Title"] == (DataTypes.Text)val).ToString(); }
public static List <Tuple <int, ExpandoObject> > ListItemsByCriteria(this SPList list, string key, string fields, bool valueAsObject, List <Tuple <string, string> > whereCriteria) { var result = new List <Tuple <int, ExpandoObject> >(); var fldId = key.IsGuid() ? list.FieldById(key.ToGuid()) : list.FieldByName(key); IQuery camlQuery = Camlex.Query(); var conditions = new List <Expression <Func <SPListItem, bool> > >(); if (!whereCriteria.IsEmpty()) { whereCriteria.ForEach(item => { var fieldCriteria = item.Item1.IsGuid() ? list.FieldById(item.Item1.ToGuid()) : list.FieldByName(item.Item1); if (fieldCriteria != null) { conditions.Add(CamlQueryHealper.GetOperation_Eq(fieldCriteria, item.Item2)); } }); camlQuery.WhereAll(conditions); } var viewFields = new List <Guid>(); fields.Split('$').ToList().ForEach(item => { var fldTitle = item.IsGuid() ? list.FieldById(item.ToGuid()) : list.FieldByName(item); if (fldTitle != null) { viewFields.Add(fldTitle.Id); } }); var query = new SPQuery { ExpandRecurrence = true, DatesInUtc = true, ViewFields = Camlex.Query().ViewFields(viewFields), Query = camlQuery.ToString() }; var itemCollection = list.GetItems(query); for (var i = 0; i < itemCollection.Count; i++) { var id = itemCollection[i][fldId.InternalName].ToInt(); var value = (IDictionary <string, object>) new ExpandoObject(); fields.Split('$').ToList().ForEach(item => { var fldTitle = item.IsGuid() ? list.FieldById(item.ToGuid()) : list.FieldByName(item); var spListItem = itemCollection[i]; if (fldTitle != null && spListItem != null) { object spItemValue; try { spItemValue = valueAsObject ? spListItem.GetObjectValue(fldTitle) : fldTitle.GetFieldValueAsText(spListItem[fldTitle.Id]); } catch { spItemValue = string.Empty; } value.Add(item, spItemValue); } }); result.Add(new Tuple <int, ExpandoObject>(id, (ExpandoObject)value)); } return(result); }
public void test_WHEN_list_of_expressions_is_null_THEN_exception_is_thrown() { Assert.Throws <EmptyExpressionsListException>(() => Camlex.Query().WhereAny((IEnumerable <string>)null).ToString()); }
public void test_WHEN_at_least_one_name_is_null_THEN_exception_is_thrown() { var items = new[] { "Title", null }; Camlex.Query().ViewFields(items); }
public void test_WHEN_list_of_expressions_is_empty_THEN_exception_is_thrown() { Assert.Throws <EmptyExpressionsListException>(() => Camlex.Query().WhereAny(new string[] {}).ToString()); }
static void Main(string[] args) { var url = "https://meusite.sharepoint.com/"; using (ClientContext context = new ClientContext(url)) { context.Credentials = new SharePointOnlineCredentials(Credenciais.UserName, Credenciais.Password()); var web = context.Web; var lstAlunos = web.GetList("/Lists/Alunos"); context.Load(lstAlunos); context.ExecuteQuery(); var query = Camlex.Query(); //Filtrar por nome var filtroNome = FiltroAlunos.PorNome("Pedro"); var pedros = lstAlunos.GetItems(query.Where(filtroNome).ToCamlQuery()); //Filtrar os alunos que começam com a letra M var filtroAlunosLetraM = FiltroAlunos.InicioNome("M"); var alunosLetraM = lstAlunos.GetItems(query.Where(filtroAlunosLetraM).ToCamlQuery()); //Filtrar alunos pelo curso de Administração var filtroCurso = FiltroAlunos.Curso("Administração - Manhã"); var alunosAdm = lstAlunos.GetItems(query.Where(filtroCurso).ToCamlQuery()); //Filtrar alunos que não estão matriculados var filtroNaoMatriculados = FiltroAlunos.Matriculados(false); var alunosNaoMatriculados = lstAlunos.GetItems(query.Where(filtroNaoMatriculados).ToCamlQuery()); //Filtrar alunos pelos nomes string[] nomes = { "Joaquina", "Samara" }; var filtroNomes = FiltroAlunos.Nomes(nomes); var alunosDiversosNomes = lstAlunos.GetItems(query.Where(filtroNomes).ToCamlQuery()); //Filtrar pelo campo Cidade = Nova Lima var filtroTexto = FiltroAlunos.FiltroTexto("Cidade", "Nova Lima"); var alunosNovaLima = lstAlunos.GetItems(query.Where(filtroTexto).ToCamlQuery()); //Filtrar os alunos que se chamam pedro ou começam com a letra M var filtroPedroM = new List <Expression <Func <ListItem, bool> > >(); filtroPedroM.Add(FiltroAlunos.PorNome("Pedro")); filtroPedroM.Add(FiltroAlunos.InicioNome("M")); var alunosPedroOuM = lstAlunos.GetItems(query.WhereAny(filtroPedroM).ToCamlQuery()); //Filtrar os alunos que começam com a letra M e que estão matriculados var filtroMEMatriculados = new List <Expression <Func <ListItem, bool> > >(); filtroMEMatriculados.Add(FiltroAlunos.InicioNome("m")); filtroMEMatriculados.Add(FiltroAlunos.Matriculados(true)); var alunosMeMatriculados = lstAlunos.GetItems(query.WhereAll(filtroMEMatriculados).ToCamlQuery()); context.Load(pedros); context.Load(alunosLetraM); context.Load(alunosPedroOuM); context.Load(alunosNaoMatriculados); context.Load(alunosAdm); context.Load(alunosDiversosNomes); context.Load(alunosNovaLima); context.Load(alunosMeMatriculados); context.ExecuteQuery(); ExibeTitulo("Apenas Pedros"); FiltroAlunos.ExibirResultado(pedros); ExibeTitulo("Apenas alunos que começam com a letra M"); FiltroAlunos.ExibirResultado(alunosLetraM); ExibeTitulo("Apenas alunos de administração manhã"); FiltroAlunos.ExibirResultado(alunosAdm); ExibeTitulo("Apenas alunos matriculados"); FiltroAlunos.ExibirResultado(alunosNaoMatriculados); ExibeTitulo("Apenas alunos com os nomes Samara ou Joaquina"); FiltroAlunos.ExibirResultado(alunosDiversosNomes); ExibeTitulo("Filtro por campo dinâmico (Cidade = Nova Lima)"); FiltroAlunos.ExibirResultado(alunosNovaLima); ExibeTitulo("Apenas alunos que se chamam Pedro ou começam com a letra M"); FiltroAlunos.ExibirResultado(alunosPedroOuM); ExibeTitulo("Apenas alunos que começam com a letra M e que estejam matriculados"); FiltroAlunos.ExibirResultado(alunosMeMatriculados); } }
private void btnSave_Click(object sender, EventArgs e) { int orderNo = 0; int.TryParse(txtOrderNo.Text, out orderNo); if (orderNo != 0) { string listId = Request.QueryString["ListId"]; string itemId = Request.QueryString["ID"]; string sourceUrl = Request.QueryString["Source"]; SPSecurity.RunWithElevatedPrivileges(delegate { using (SPSite site = new SPSite(SPContext.Current.Site.ID)) { using (SPWeb web = site.OpenWeb(SPContext.Current.Web.ID)) { web.AllowUnsafeUpdates = true; try { SPList curList = web.Lists[new Guid(listId)]; SPListItem curItem = curList.Items.GetItemById(Convert.ToInt32(itemId)); string caml = string.Empty; var expressionsAnd = new List <Expression <Func <SPListItem, bool> > >(); expressionsAnd.Add(x => ((int)x[Constants.ORDER_NUMBER_COLUMN]) >= orderNo); expressionsAnd.Add(x => (x["ID"]) != (DataTypes.Counter)itemId); caml = Camlex.Query().WhereAll(expressionsAnd).OrderBy(x => x[Constants.ORDER_NUMBER_COLUMN] as Camlex.Asc).ToString(); SPQuery spQuery = new SPQuery(); spQuery.Query = caml; SPListItemCollection items = curList.GetItems(spQuery); using (DisableItemEvent scope = new DisableItemEvent()) { curItem[Constants.ORDER_NUMBER_COLUMN] = orderNo; curItem.SystemUpdate(false); } foreach (SPListItem item in items) { orderNo++; using (DisableItemEvent scope = new DisableItemEvent()) { item[Constants.ORDER_NUMBER_COLUMN] = orderNo; item.SystemUpdate(false); } } } catch (Exception ex) { } finally { web.AllowUnsafeUpdates = false; } } } }); } ClosePopup(); }