public void Delete(string id) { SegmentId segId = new SegmentId(id); Site site = segId.SiteId == null ? null : SiteHelper.GetSite(segId.SiteId.Value); if (segId.SiteId != null && site == null) { Context.Response.StatusCode = (int)HttpStatusCode.NoContent; return; } HiddenSegment segment = HiddenSegmentsHelper.getSegments(site, segId.Path).Where(s => s.Segment.ToString().Equals(segId.Segment)).FirstOrDefault(); if (segment != null) { var section = RequestFilteringHelper.GetRequestFilteringSection(site, segId.Path, ManagementUnit.ResolveConfigScope()); HiddenSegmentsHelper.DeleteSegment(segment, section); ManagementUnit.Current.Commit(); } Context.Response.StatusCode = (int)HttpStatusCode.NoContent; return; }
public static void AddSegment(HiddenSegment segment, RequestFilteringSection section) { if (segment == null) { throw new ArgumentNullException("segment"); } if (segment.Segment == null) { throw new ArgumentNullException("extension.Segment"); } var collection = section.HiddenSegments; if (collection.Any(seg => seg.Segment.Equals(segment.Segment))) { throw new AlreadyExistsException("segment"); } try { collection.Add(segment); } catch (FileLoadException e) { throw new LockedException(section.SectionPath, e); } catch (DirectoryNotFoundException e) { throw new ConfigScopeNotFoundException(e); } }
public static object ToJsonModelRef(HiddenSegment segment, Site site, string path) { if (segment == null) { return(null); } SegmentId segmentId = new SegmentId(site?.Id, path, segment.Segment); var obj = new { segment = segment.Segment, id = segmentId.Uuid }; return(Core.Environment.Hal.Apply(Defines.HiddenSegmentsResource.Guid, obj, false)); }
internal static object ToJsonModel(HiddenSegment segment, Site site, string path) { if (segment == null) { return(null); } SegmentId segmentId = new SegmentId(site?.Id, path, segment.Segment); var obj = new { segment = segment.Segment, id = segmentId.Uuid, request_filtering = RequestFilteringHelper.ToJsonModelRef(site, path) }; return(Core.Environment.Hal.Apply(Defines.HiddenSegmentsResource.Guid, obj)); }
public object Post([FromBody] dynamic model) { HiddenSegment segment = null; Site site = null; RequestFilteringId reqId = null; if (model == null) { throw new ApiArgumentException("model"); } if (model.request_filtering == null) { throw new ApiArgumentException("request_filtering"); } if (!(model.request_filtering is JObject)) { throw new ApiArgumentException("request_filtering"); } string reqUuid = DynamicHelper.Value(model.request_filtering.id); if (reqUuid == null) { throw new ApiArgumentException("request_filtering.id"); } // Get the feature id reqId = new RequestFilteringId(reqUuid); site = reqId.SiteId == null ? null : SiteHelper.GetSite(reqId.SiteId.Value); string configPath = ManagementUnit.ResolveConfigScope(model); RequestFilteringSection section = RequestFilteringHelper.GetRequestFilteringSection(site, reqId.Path, configPath); segment = HiddenSegmentsHelper.CreateSegment(model, section); HiddenSegmentsHelper.AddSegment(segment, section); ManagementUnit.Current.Commit(); dynamic hidden_segment = HiddenSegmentsHelper.ToJsonModel(segment, site, reqId.Path); return(Created(HiddenSegmentsHelper.GetLocation(hidden_segment.id), hidden_segment)); }
public object Get(string id) { SegmentId segId = new SegmentId(id); Site site = segId.SiteId == null ? null : SiteHelper.GetSite(segId.SiteId.Value); if (segId.SiteId != null && site == null) { return(NotFound()); } HiddenSegment segment = HiddenSegmentsHelper.getSegments(site, segId.Path).Where(s => s.Segment.Equals(segId.Segment)).FirstOrDefault(); if (segment == null) { return(NotFound()); } return(HiddenSegmentsHelper.ToJsonModel(segment, site, segId.Path)); }
public static HiddenSegment CreateSegment(dynamic model, RequestFilteringSection section) { if (model == null) { throw new ApiArgumentException("model"); } string segmentName = DynamicHelper.Value(model.segment); if (string.IsNullOrEmpty(segmentName)) { throw new ApiArgumentException("segment"); } HiddenSegment segment = section.HiddenSegments.CreateElement(); segment.Segment = segmentName; return(segment); }
public static void DeleteSegment(HiddenSegment segment, RequestFilteringSection section) { if (segment == null) { return; } var collection = section.HiddenSegments; segment = collection.FirstOrDefault(s => s.Segment.Equals(segment.Segment)); if (segment != null) { try { collection.Remove(segment); } catch (FileLoadException e) { throw new LockedException(section.SectionPath, e); } catch (DirectoryNotFoundException e) { throw new ConfigScopeNotFoundException(e); } } }