public IEnumerable <MusicRecord> FindDuration([FromQuery] FilterRecord filter) { //List<MusicRecord> list = new List<MusicRecord>(); //if (filter.High == 0) //{ // filter.High = int.MaxValue; //} //list.Add(Records.Find(r => r.Duration > filter.Low && r.Duration < filter.High)); //return list; List <MusicRecord> itemList = new List <MusicRecord>(); if (filter.High <= 0) { filter.High = int.MaxValue; } foreach (MusicRecord item in Get()) { if (item.Duration > filter.Low && item.Duration < filter.High) { itemList.Add(item); } } return(itemList); }
public void ResizeMediaUrl(dynamic Shape, dynamic Display, TextWriter Output, ContentItem ContentItem, string Path, int Width, int Height, string Mode, string Alignment, string PadColor) { var state = new Dictionary <string, string> { { "Width", Width.ToString(CultureInfo.InvariantCulture) }, { "Height", Height.ToString(CultureInfo.InvariantCulture) }, { "Mode", Mode }, { "Alignment", Alignment }, { "PadColor", PadColor }, }; var filter = new FilterRecord { Category = "Transform", Type = "Resize", State = FormParametersHelper.ToString(state) }; var profile = "Transform_Resize" + "_w_" + Convert.ToString(Width) + "_h_" + Convert.ToString(Height) + "_m_" + Convert.ToString(Mode) + "_a_" + Convert.ToString(Alignment) + "_c_" + Convert.ToString(PadColor); MediaUrl(Shape, Display, Output, profile, Path, ContentItem, filter); }
public QueryPart CreateWikiActivityStreamQuery() { var query = this.GetQuery(QueryNames.WikiActivityStreamQueryName); if (query != null) { return(query.As <QueryPart>()); } query = this.contentManager.Create("Query"); query.As <TitlePart>().Title = QueryNames.WikiActivityStreamQueryName; this.contentManager.Publish(query); QueryPart queryPart = query.As <QueryPart>(); var filterGroup = queryPart.Record.FilterGroups.FirstOrDefault(); // AttachToProject string state = string.Format(CultureInfo.InvariantCulture, "<Form><Description></Description><Project_Id>{0}</Project_Id></Form>", "{AttachToProject.ProjectId}"); FilterRecord attachToProjectFilterRecord = this.CreateFilter(AttachToProjectFilter.CategoryName, AttachToProjectFilter.IdFilterType, state, filterGroup); this.filterRepository.Flush(); // ContentType filter this.CreateContentTypeFilter(string.Join(",", new[] { ContentTypes.WikiItemType, ContentTypes.FolderContentType }), filterGroup); this.filterRepository.Flush(); return(queryPart); }
private ProjectionPart CreateProjection(string typeName, IEnumerable <string> properties) { var projectionItem = _contentManager.New("ProjectionPage"); var queryItem = _contentManager.New("Query"); var projectionPart = projectionItem.As <ProjectionPart>(); var queryPart = queryItem.As <QueryPart>(); _contentManager.Create(queryItem); projectionPart.Record.QueryPartRecord = queryPart.Record; _contentManager.Create(projectionItem); var layoutRecord = new LayoutRecord { Category = "Html", Type = "ngGrid" }; queryPart.Record.Layouts.Add(layoutRecord); projectionPart.Record.LayoutRecord = layoutRecord; var filterGroup = new FilterGroupRecord(); queryPart.Record.FilterGroups.Clear(); queryPart.Record.FilterGroups.Add(filterGroup); var filterRecord = new FilterRecord { Category = "Content", Type = "ContentTypes", Position = filterGroup.Filters.Count, State = string.Format("<Form><ContentTypes>{0}</ContentTypes></Form>", typeName) }; filterGroup.Filters.Add(filterRecord); UpdateLayoutProperties(typeName, layoutRecord, properties); return(projectionPart); }
public IEnumerable <record> GetByDuration([FromQuery] FilterRecord duration) { if (duration.LongDuration == 0) { duration.LongDuration = int.MaxValue; } return(recordList.FindAll(i => i.Duration > duration.ShortDuration && i.Duration < duration.LongDuration)); }
// the AdminService attribute prevents the PolicyFilter to check policies // when a file is called through this action. public RedirectResult Image(string Path, int?Width, int?Height, string Mode, string Alignment, string PadColor) { var httpContext = _httpContextAccessor.Current(); int n = 0; string url; bool isNumeric = int.TryParse(Path, out n); if (isNumeric) { MediaPart mediaPart = ((ContentItem)_orchardServices.ContentManager.Get(n)).As <MediaPart>(); Path = mediaPart.MediaUrl; } if (Width == null || Height == null) { var baseUrl = httpContext.Request.ToApplicationRootUrlString(); var applicationPath = httpContext.Request.ApplicationPath ?? String.Empty; if (Path.StartsWith(applicationPath, StringComparison.OrdinalIgnoreCase)) { Path = Path.Substring(applicationPath.Length); } url = String.Concat(baseUrl, Path); } else { int notNullWidth = Width.GetValueOrDefault(); int notNullHeight = Height.GetValueOrDefault(); var state = new Dictionary <string, string> { { "Width", notNullWidth.ToString(CultureInfo.InvariantCulture) }, { "Height", notNullHeight.ToString(CultureInfo.InvariantCulture) }, { "Mode", Mode }, { "Alignment", Alignment }, { "PadColor", PadColor }, }; var filter = new FilterRecord { Category = "Transform", Type = "Resize", State = FormParametersHelper.ToString(state) }; var profile = "Transform_Resize" + "_w_" + Convert.ToString(Width) + "_h_" + Convert.ToString(Height) + "_m_" + Convert.ToString(Mode) + "_a_" + Convert.ToString(Alignment) + "_c_" + Convert.ToString(PadColor); Path = HttpUtility.UrlDecode(Path); // url = _imageProfileManager.Value.GetImageProfileUrl(Path, profile, filter); url = _imageProfileManager.GetImageProfileUrl(Path, profile, filter); } if (url == null) { return(null); } return(Redirect(url)); }
public void RemoveRecord(string Operator, string ColumnName) { FilterRecord newRecord = new FilterRecord(); newRecord.Operator = Operator; newRecord.ColumnName = ColumnName; newRecord.Value = ""; this.Records.Remove(newRecord); }
public void AddRecord(string Operator, string ColumnName, string Value) { FilterRecord newRecord = new FilterRecord(); newRecord.Operator = Operator; newRecord.ColumnName = ColumnName; newRecord.Value = Value; this.Records.Add(newRecord); }
public ActionResult EditPost(int id, string category, string type, [DefaultValue(-1)] int filterId, FormCollection formCollection) { var profile = _profileService.GetImageProfile(id); var filter = _processingManager.DescribeFilters().SelectMany(x => x.Descriptors).FirstOrDefault(x => x.Category == category && x.Type == type); var model = new FilterEditViewModel(); TryUpdateModel(model); // validating form values _formManager.Validate(new ValidatingContext { FormName = filter.Form, ModelState = ModelState, ValueProvider = ValueProvider }); if (ModelState.IsValid) { var filterRecord = profile.Filters.FirstOrDefault(f => f.Id == filterId); // add new filter record if it's a newly created filter if (filterRecord == null) { filterRecord = new FilterRecord { Category = category, Type = type, Position = profile.Filters.Count }; profile.Filters.Add(filterRecord); } var dictionary = formCollection.AllKeys.ToDictionary(key => key, formCollection.Get); // save form parameters filterRecord.State = FormParametersHelper.ToString(dictionary); filterRecord.Description = model.Description; // set profile as updated profile.ModifiedUtc = DateTime.UtcNow; profile.FileNames.Clear(); _signals.Trigger("MediaProcessing_" + profile.Name + "_Saved"); return(RedirectToAction("Edit", "Admin", new { id })); } // model is invalid, display it again var form = _formManager.Build(filter.Form); _formManager.Bind(form, formCollection); var viewModel = new FilterEditViewModel { Id = id, Description = model.Description, Filter = filter, Form = form }; return(View(viewModel)); }
public void GetByDurationTest() { // arrange FilterRecord filter = new FilterRecord(250, 90); // action List <record> recordList = new List <record>(rntr.GetByDuration(filter)); // assert Assert.AreEqual(2, recordList.Count); }
protected FilterRecord CreateFilter(string category, string type, string state, FilterGroupRecord filterGroup) { FilterRecord filterRecord = new FilterRecord(); filterRecord.FilterGroupRecord = filterGroup; filterRecord.Category = category; filterRecord.Type = type; filterRecord.State = state; this.filterRepository.Create(filterRecord); return(filterRecord); }
public ActionResult EditPost(int id, string category, string type, [DefaultValue(-1)] int filterId, FormCollection formCollection) { var group = _groupRepository.Get(id); var filter = _projectionManager.DescribeFilters().SelectMany(x => x.Descriptors).Where(x => x.Category == category && x.Type == type).FirstOrDefault(); var model = new FilterEditViewModel(); TryUpdateModel(model); // validating form values _formManager.Validate(new ValidatingContext { FormName = filter.Form, ModelState = ModelState, ValueProvider = ValueProvider }); if (ModelState.IsValid) { var filterRecord = group.Filters.Where(f => f.Id == filterId).FirstOrDefault(); // add new filter record if it's a newly created filter if (filterRecord == null) { filterRecord = new FilterRecord { Category = category, Type = type, Position = group.Filters.Count }; group.Filters.Add(filterRecord); } var dictionary = formCollection.AllKeys.ToDictionary(key => key, formCollection.Get); // save form parameters filterRecord.State = FormParametersHelper.ToString(dictionary); filterRecord.Description = model.Description; return(RedirectToAction("Edit", "Admin", new { group.QueryPartRecord.Id })); } // model is invalid, display it again var form = _formManager.Build(filter.Form); _formManager.Bind(form, formCollection); var viewModel = new FilterEditViewModel { Id = id, Description = model.Description, Filter = filter, Form = form }; return(View(viewModel)); }
public IEnumerable <JObject> Post(string id, FilterViewModel model) { var pluralService = PluralizationService.CreateService(new CultureInfo("en-US")); if (pluralService.IsPlural(id)) { id = pluralService.Singularize(id); } var groupRecord = new FilterGroupRecord(); _filterGroupRepository.Create(groupRecord); _entityFilterRepository.Create(new EntityFilterRecord { EntityName = id, FilterGroupRecord = groupRecord, Title = model.Title }); foreach (var filter in model.Filters) { if (filter.FormData.Length == 0) { continue; } var record = new FilterRecord { Category = id + "ContentFields", Type = filter.Type, }; var dictionary = new Dictionary <string, string>(); foreach (var data in filter.FormData) { if (dictionary.ContainsKey(data.Name)) { dictionary[data.Name] += "&" + data.Value; } else { dictionary.Add(data.Name, data.Value); } } record.State = FormParametersHelper.ToString(dictionary); groupRecord.Filters.Add(record); } return(Get(id)); }
private int CreateQuery(string entityType) { var queryPart = _contentManager.New <QueryPart>("Query"); var filterGroup = new FilterGroupRecord(); queryPart.Record.FilterGroups.Add(filterGroup); var filterRecord = new FilterRecord { Category = "Content", Type = "ContentTypes", Position = filterGroup.Filters.Count, State = GetContentTypeFilterState(entityType) }; filterGroup.Filters.Add(filterRecord); _contentManager.Create(queryPart); return(queryPart.Id); }
public IEnumerable <Record> SearchByPublicationYear([FromQuery] FilterRecord filter) { if (filter.MinimumLength != 0 && filter.MaximumLength != 0) { return(_records.FindAll(i => i.PublicationYear > filter.MinimumLength && i.PublicationYear < filter.MaximumLength)); } else if (filter.MaximumLength != 0) { return(_records.FindAll(i => i.PublicationYear < filter.MaximumLength)); } else if (filter.MinimumLength != 0) { return(_records.FindAll(i => i.PublicationYear > filter.MinimumLength)); } else { return(null); } }
private string GetResizeUrl(string path, string width) { var state = new Dictionary <string, string> { { "Width", width.ToString(CultureInfo.InvariantCulture) }, { "Height", "0" } }; var filter = new FilterRecord { Category = "Transform", Type = "Resize", State = FormParametersHelper.ToString(state) }; var profile = "Transform_Resize" + "_w_" + Convert.ToString(width) + "_h_" + Convert.ToString(0); return(_imageProfileManager.Value.GetImageProfileUrl(path, profile, filter)); }
public QueryPart CreateProjectActivityStreamQuery() { var query = this.GetQuery(QueryNames.ProjectActivityStreamQueryName); if (query != null) { return(query.As <QueryPart>()); } query = this.contentManager.Create("Query"); query.As <TitlePart>().Title = QueryNames.ProjectActivityStreamQueryName; this.contentManager.Publish(query); QueryPart queryPart = query.As <QueryPart>(); var attachToProjectFilterGroup = queryPart.Record.FilterGroups.FirstOrDefault(); // AttachToProject string state = string.Format(CultureInfo.InvariantCulture, "<Form><Description></Description><Project_Id>{0}</Project_Id></Form>", "{AttachToProject.ProjectId}"); FilterRecord attachToProjectFilterRecord = this.CreateFilter(AttachToProjectFilter.CategoryName, AttachToProjectFilter.IdFilterType, state, attachToProjectFilterGroup); this.filterRepository.Flush(); var projectFilterGroup = new FilterGroupRecord { QueryPartRecord = queryPart.Record }; queryPart.Record.FilterGroups.Add(projectFilterGroup); this.filterGroupRepository.Create(projectFilterGroup); // project ContentType filter this.CreateContentTypeFilter(ContentTypes.ProjectContentType, projectFilterGroup); state = string.Format(CultureInfo.InvariantCulture, "<Form><Description></Description><Project_Id>{0}</Project_Id></Form>", "{Project.ProjectId}"); this.CreateFilter(ProjectFilter.CategoryName, ProjectFilter.IdFilterType, state, projectFilterGroup); this.filterGroupRepository.Flush(); this.filterRepository.Flush(); return(queryPart); }
private IList <FilterRecord> CreateFilters(string entityName, ListQueryModel model, out string filterDescription) { IList <FilterRecord> filterRecords; filterDescription = string.Empty; if (model.FilterGroupId == 0) { var filterDescriptors = _projectionManager.DescribeFilters() .Where(x => x.Category == entityName + "ContentFields") .SelectMany(x => x.Descriptors).ToList(); filterRecords = new List <FilterRecord>(); if (model.IsRelationList) { if (model.RelationType == "OneToMany") { var settings = new Dictionary <string, string> { { "Operator", "MatchesAny" }, { "Value", model.CurrentItem.ToString("D") } }; var relationFilter = new FilterRecord { Category = entityName + "ContentFields", Type = entityName + "." + model.RelationId + ".", State = FormParametersHelper.ToString(settings), Description = "Only show entries related to current item." }; filterRecords.Add(relationFilter); var descriptor = filterDescriptors.First(x => x.Type == relationFilter.Type); filterDescription += descriptor.Display(new FilterContext { State = FormParametersHelper.ToDynamic(relationFilter.State) }).Text; } } foreach (var filter in model.Filters) { if (filter.FormData.Length == 0) { continue; } var record = new FilterRecord { Category = entityName + "ContentFields", Type = filter.Type, }; var dictionary = new Dictionary <string, string>(); foreach (var data in filter.FormData) { if (dictionary.ContainsKey(data.Name)) { dictionary[data.Name] += "&" + data.Value; } else { dictionary.Add(data.Name, data.Value); } } record.State = FormParametersHelper.ToString(dictionary); filterRecords.Add(record); var descriptor = filterDescriptors.First(x => x.Type == filter.Type); filterDescription += descriptor.Display(new FilterContext { State = FormParametersHelper.ToDynamic(record.State) }).Text; } } else { filterRecords = _filterGroupRepository.Get(model.FilterGroupId).Filters; } return(filterRecords); }
public int EditPost(int id, ProjectionEditViewModel viewModel, IEnumerable <string> pickedFileds) { ListViewPart listViewPart; ProjectionPart projectionPart; QueryPart queryPart; if (id == 0) { listViewPart = _contentManager.New <ListViewPart>("ListViewPage"); listViewPart.ItemContentType = viewModel.ItemContentType; queryPart = _contentManager.New <QueryPart>("Query"); var layout = new LayoutRecord { Category = "Html", Type = "ngGrid", Description = "DefaultLayoutFor" + queryPart.Name, Display = 1 }; queryPart.Layouts.Add(layout); projectionPart = listViewPart.As <ProjectionPart>(); projectionPart.Record.LayoutRecord = layout; projectionPart.Record.QueryPartRecord = queryPart.Record; var filterGroup = new FilterGroupRecord(); queryPart.Record.FilterGroups.Add(filterGroup); var filterRecord = new FilterRecord { Category = "Content", Type = "ContentTypes", Position = filterGroup.Filters.Count, State = GetContentTypeFilterState(viewModel.ItemContentType) }; filterGroup.Filters.Add(filterRecord); _contentManager.Create(queryPart.ContentItem); _contentManager.Create(projectionPart.ContentItem); } else { listViewPart = _contentManager.Get <ListViewPart>(id, VersionOptions.Latest); projectionPart = listViewPart.As <ProjectionPart>(); var queryId = projectionPart.Record.QueryPartRecord.Id; queryPart = _contentManager.Get <QueryPart>(queryId, VersionOptions.Latest); } if (pickedFileds == null) { pickedFileds = new List <string>(); } listViewPart.VisableTo = viewModel.VisableTo; listViewPart.As <TitlePart>().Title = viewModel.DisplayName; listViewPart.IsDefault = viewModel.IsDefault; queryPart.Name = "Query for Public View"; projectionPart.Record.ItemsPerPage = viewModel.PageRowCount; //Post Selected Fields var layoutRecord = projectionPart.Record.LayoutRecord; layoutRecord.Properties.Clear(); var category = viewModel.ItemContentType + "ContentFields"; const string settingName = "CoeveryTextFieldSettings.IsDispalyField"; try { UpdateLayoutProperties(viewModel.ItemContentType, ref layoutRecord, category, settingName, pickedFileds); } catch (Exception exception) { Services.Notifier.Add(NotifyType.Error, T(exception.Message)); } layoutRecord.State = GetLayoutState(queryPart.Id, layoutRecord.Properties.Count, layoutRecord.Description); // sort queryPart.SortCriteria.Clear(); if (!string.IsNullOrEmpty(viewModel.SortedBy)) { var sortCriterionRecord = new SortCriterionRecord { Category = category, Type = viewModel.SortedBy, Position = queryPart.SortCriteria.Count, State = GetSortState(viewModel.SortedBy, viewModel.SortMode), Description = viewModel.SortedBy + " " + viewModel.SortMode }; queryPart.SortCriteria.Add(sortCriterionRecord); } return(listViewPart.Id); }
public string GetImageProfileUrl(string path, string profileName, FilterRecord customFilter, ContentItem contentItem) { var customFilters = customFilter != null ? new FilterRecord[] { customFilter } : null; return(GetImageProfileUrl(path, profileName, contentItem, customFilters)); }
public string GetImageProfileUrl(string path, string profileName, FilterRecord customFilter) { return(GetImageProfileUrl(path, profileName, customFilter, null)); }
private string GetProfileUrl(string Path, string Profile, FilterRecord CustomFilter, ContentItem ContentItem) { return(_imageProfileManager.Value.GetImageProfileUrl(Path, Profile, CustomFilter, ContentItem)); }
public string GetImageProfileUrl(string path, string profileName, FilterRecord customFilter, ContentItem contentItem) { // path is the publicUrl of the media, so it might contain url-encoded chars // try to load the processed filename from cache var filePath = _fileNameProvider.GetFileName(profileName, System.Web.HttpUtility.UrlDecode(path)); bool process = false; // if the filename is not cached, process it if (string.IsNullOrEmpty(filePath)) { Logger.Debug("FilePath is null, processing required, profile {0} for image {1}", profileName, path); process = true; } // the processd file doesn't exist anymore, process it else if (!_storageProvider.FileExists(filePath)) { Logger.Debug("Processed file no longer exists, processing required, profile {0} for image {1}", profileName, path); process = true; } // if the original file is more recent, process it else { DateTime pathLastUpdated; if (TryGetImageLastUpdated(path, out pathLastUpdated)) { var filePathLastUpdated = _storageProvider.GetFile(filePath).GetLastUpdated(); if (pathLastUpdated > filePathLastUpdated) { Logger.Debug("Original file more recent, processing required, profile {0} for image {1}", profileName, path); process = true; } } } // todo: regenerate the file if the profile is newer, by deleting the associated filename cache entries. if (process) { Logger.Debug("Processing profile {0} for image {1}", profileName, path); ImageProfilePart profilePart; if (customFilter == null) { profilePart = _profileService.GetImageProfileByName(profileName); if (profilePart == null) { return(String.Empty); } } else { profilePart = _services.ContentManager.New <ImageProfilePart>("ImageProfile"); profilePart.Name = profileName; profilePart.Filters.Add(customFilter); } // prevent two requests from processing the same file at the same time // this is only thread safe at the machine level, so there is a try/catch later // to handle cross machines concurrency lock (String.Intern(path)) { using (var image = GetImage(path)) { var filterContext = new FilterContext { Media = image, FilePath = _storageProvider.Combine("_Profiles", FormatProfilePath(profileName, System.Web.HttpUtility.UrlDecode(path))) }; if (image == null) { return(filterContext.FilePath); } var tokens = new Dictionary <string, object>(); // if a content item is provided, use it while tokenizing if (contentItem != null) { tokens.Add("Content", contentItem); } foreach (var filter in profilePart.Filters.OrderBy(f => f.Position)) { var descriptor = _processingManager.DescribeFilters().SelectMany(x => x.Descriptors).FirstOrDefault(x => x.Category == filter.Category && x.Type == filter.Type); if (descriptor == null) { continue; } var tokenized = _tokenizer.Replace(filter.State, tokens); filterContext.State = FormParametersHelper.ToDynamic(tokenized); descriptor.Filter(filterContext); } _fileNameProvider.UpdateFileName(profileName, System.Web.HttpUtility.UrlDecode(path), filterContext.FilePath); if (!filterContext.Saved) { try { var newFile = _storageProvider.OpenOrCreate(filterContext.FilePath); using (var imageStream = newFile.OpenWrite()) { using (var sw = new BinaryWriter(imageStream)) { if (filterContext.Media.CanSeek) { filterContext.Media.Seek(0, SeekOrigin.Begin); } using (var sr = new BinaryReader(filterContext.Media)) { int count; var buffer = new byte[8192]; while ((count = sr.Read(buffer, 0, buffer.Length)) != 0) { sw.Write(buffer, 0, count); } } } } } catch (Exception e) { Logger.Error(e, "A profile could not be processed: " + path); } } filterContext.Media.Dispose(); filePath = filterContext.FilePath; } } } // generate a timestamped url to force client caches to update if the file has changed var publicUrl = _storageProvider.GetPublicUrl(filePath); var timestamp = _storageProvider.GetFile(filePath).GetLastUpdated().Ticks; return(publicUrl + "?v=" + timestamp.ToString(CultureInfo.InvariantCulture)); }
public void MediaUrl(dynamic Shape, dynamic Display, TextWriter Output, string Profile, string Path, ContentItem ContentItem, FilterRecord CustomFilter) { try { Shape.IgnoreShapeTracer = true; Output.Write(_imageProfileManager.Value.GetImageProfileUrl(Path, Profile, CustomFilter, ContentItem)); } catch (Exception ex) { Logger.Error(ex, "An error occurred while rendering shape {0} for image {1}", Profile, Path); } }
public string GetImageProfileUrl(string path, string profileName, FilterRecord customFilter, ContentItem contentItem) { return(GetImageProfileUrl(path, profileName, contentItem, customFilter)); }