public void ExcludeProblematicPaths() { // A normal path that will be backed up. string normalFilePath = Path.Combine(this.DATAFOLDER, "normal"); File.WriteAllBytes(normalFilePath, new byte[] { 0, 1, 2 }); // A long path to exclude. string longFile = SystemIO.IO_OS.PathCombine(this.DATAFOLDER, new string('y', 255)); WriteFile(longFile, new byte[] { 0, 1 }); // A folder that ends with a dot to exclude. string folderWithDot = Path.Combine(this.DATAFOLDER, "folder_with_dot."); SystemIO.IO_OS.DirectoryCreate(folderWithDot); // A folder that ends with a space to exclude. string folderWithSpace = Path.Combine(this.DATAFOLDER, "folder_with_space "); SystemIO.IO_OS.DirectoryCreate(folderWithSpace); // A file that ends with a dot to exclude. string fileWithDot = Path.Combine(this.DATAFOLDER, "file_with_dot."); WriteFile(fileWithDot, new byte[] { 0, 1 }); // A file that ends with a space to exclude. string fileWithSpace = Path.Combine(this.DATAFOLDER, "file_with_space "); WriteFile(fileWithSpace, new byte[] { 0, 1 }); FilterExpression filter = new FilterExpression(longFile, false); filter = FilterExpression.Combine(filter, new FilterExpression(Util.AppendDirSeparator(folderWithDot), false)); filter = FilterExpression.Combine(filter, new FilterExpression(Util.AppendDirSeparator(folderWithSpace), false)); filter = FilterExpression.Combine(filter, new FilterExpression(fileWithDot, false)); filter = FilterExpression.Combine(filter, new FilterExpression(fileWithSpace, false)); Dictionary <string, string> options = new Dictionary <string, string>(this.TestOptions); using (Controller c = new Controller("file://" + this.TARGETFOLDER, options, null)) { IBackupResults backupResults = c.Backup(new[] { this.DATAFOLDER }, filter); Assert.AreEqual(0, backupResults.Errors.Count()); Assert.AreEqual(0, backupResults.Warnings.Count()); } using (Controller c = new Controller("file://" + this.TARGETFOLDER, options, null)) { IListResults listResults = c.List("*"); Assert.AreEqual(0, listResults.Errors.Count()); Assert.AreEqual(0, listResults.Warnings.Count()); string[] backedUpPaths = listResults.Files.Select(x => x.Path).ToArray(); Assert.AreEqual(2, backedUpPaths.Length); Assert.Contains(Util.AppendDirSeparator(this.DATAFOLDER), backedUpPaths); Assert.Contains(normalFilePath, backedUpPaths); } }
public static IFilter Join(IFilter first, IFilter second) { if (first == null && second == null) { return(null); } else if (first == null) { return(second); } else if (second == null) { return(first); } else if (first.Empty) { return(second); } else if (second.Empty) { return(first); } else { if (first is FilterExpression && second is FilterExpression && ((FilterExpression)first).Result == ((FilterExpression)second).Result) { return(FilterExpression.Combine((FilterExpression)first, (FilterExpression)second)); } return(new JoinedFilterExpression(first, second)); } }
private async Task FilterBy(ICollectionView <object> collectionView, string query) { var itemType = collectionView.GetItemType(); var queryParts = TreatSpacesAsAndOperator ? query.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries) : new string[] { query }; FilterExpression filterExpression = null; foreach (var queryPart in queryParts) { var filterExpressions = new List <FilterExpression>(); foreach (var property in CollectionView.GetItemType().GetTypeInfo().DeclaredProperties) { try { var propType = property.PropertyType; if (propType == typeof(string) || IsNumeric(propType) && MatchNumbers) { filterExpressions.Add(new FilterUnaryExpression(property.Name, FilterOperation.Contains, queryPart)); } } catch { } } var fe = FilterExpression.Combine(FilterCombination.Or, filterExpressions.ToArray()); if (filterExpression == null) { filterExpression = fe; } else { filterExpression = new FilterBinaryExpression(FilterCombination.And, filterExpression, fe); } } await(collectionView as ISupportFiltering).FilterAsync(filterExpression); }
private async void OnFilterClicked(object sender, EventArgs e) { var filtering = grid.CollectionView as ISupportFiltering; if (filtering != null) { var filterForm = new FilterForm(); var currentFilters = GetCurrentFilters(filtering.FilterExpression); foreach (var column in grid.Columns) { if (column.DataType == typeof(string)) { var stringFilter = new StringFilter(); stringFilter.Field = column.Binding; stringFilter.FieldName = column.ActualHeader; var existingFilter = currentFilters.FirstOrDefault(f => f.FilterPath == column.Binding); if (existingFilter != null) { stringFilter.Operation = existingFilter.FilterOperation; stringFilter.Value = existingFilter.Value.ToString(); } else { stringFilter.Operation = FilterOperation.Contains; } filterForm.Filters.Add(stringFilter); } } try { await filterForm.ShowAsync(Navigation); var filters = new List <FilterExpression>(); foreach (var filter in filterForm.Filters) { if (!string.IsNullOrWhiteSpace(filter.Value)) { filters.Add(new FilterUnaryExpression(filter.Field, filter.Operation, filter.Value)); } } await filtering.FilterAsync(FilterExpression.Combine(FilterCombination.And, filters.ToArray())); } catch (OperationCanceledException) { } } }
public async void CloseFilterForm(UIStoryboardSegue segue) { var popup = segue.SourceViewController as FilterFormController; if (popup.Saved) { var filters = new List <FilterExpression>(); foreach (var filter in popup.Filters) { if (!string.IsNullOrWhiteSpace(filter.Value)) { filters.Add(new FilterUnaryExpression(filter.Field, filter.Operation, filter.Value)); } } await Grid.CollectionView.FilterAsync(FilterExpression.Combine(FilterCombination.And, filters.ToArray())); } }
public async Task FilterProductAndRegion(List <ProductFilterModel> productFilter, List <RegionFilterModel> regionFilter) { await _service.ProductWiseSaleCollection.RemoveFilterAsync(); var filterSource = _service.ProductWiseSaleCollection as ISupportFiltering; var filterExpressions = new List <FilterExpression>(); if (filterSource != null) { foreach (var region in regionFilter) { if (region.IsSelected) { filterExpressions.Add(new FilterOperationExpression("Region", FilterOperation.EqualText, region.RegionName)); } } if (filterExpressions.Count < 1) { filterExpressions.Add(new FilterOperationExpression("Region", FilterOperation.EqualText, "")); } var feRegion = FilterExpression.Combine(FilterCombination.Or, filterExpressions.ToArray()); filterExpressions = new List <FilterExpression>(); foreach (var product in productFilter) { if (product.IsSelected) { filterExpressions.Add(new FilterOperationExpression("Product", FilterOperation.EqualText, product.ProductName)); } } if (filterExpressions.Count < 1) { filterExpressions.Add(new FilterOperationExpression("Product", FilterOperation.EqualText, "")); } var feProduct = FilterExpression.Combine(FilterCombination.Or, filterExpressions.ToArray()); await filterSource.FilterAsync(new FilterBinaryExpression(FilterCombination.And, feRegion, feProduct)); OnPropertyChanged("RegionProductSales"); } }
protected override async void OnActivityResult(int requestCode, [GeneratedEnum] Result resultCode, Intent data) { if (requestCode == FilterFormRequest) { if (resultCode == Result.Ok) { var filters = new List <FilterExpression>(); CurrentFilters = GetFiltersFromText(data.Extras.GetString("filters")); foreach (var filter in CurrentFilters) { if (!string.IsNullOrWhiteSpace(filter.Value)) { filters.Add(new FilterOperationExpression(filter.Field, filter.Operation, filter.Value)); } } await Grid.DataCollection.FilterAsync(FilterExpression.Combine(FilterCombination.And, filters.ToArray())); } } base.OnActivityResult(requestCode, resultCode, data); }