-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
140 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,94 @@ | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text.RegularExpressions; | ||
using Terradue.Stars.Interface; | ||
|
||
namespace Terradue.Stars.Services.Supplier | ||
{ | ||
public class AssetFilters : Dictionary<string, AssetFilter> | ||
public class AssetFilters : List<IAssetFilter> | ||
{ | ||
|
||
public static AssetFilters None => new AssetFilters(); | ||
|
||
public static AssetFilters SkipRelative | ||
{ | ||
get | ||
{ | ||
var af = new AssetFilters(); | ||
af.Add("absoluteUri", new AssetFilter() { UriRegex = new Regex(@"^(?:[a-z]+:)?//") }); | ||
af.Add(new UriAssetFilter(new Regex(@"^(?:[a-z]+:)?//"))); | ||
return af; | ||
} | ||
} | ||
} | ||
|
||
public class AssetFilter | ||
public interface IAssetFilter | ||
{ | ||
bool IsMatch(KeyValuePair<string, IAsset> asset); | ||
} | ||
|
||
public class UriAssetFilter : IAssetFilter | ||
{ | ||
public UriAssetFilter(Regex uriRegex) | ||
{ | ||
UriRegex = uriRegex; | ||
} | ||
|
||
public Regex UriRegex { get; set; } | ||
|
||
public bool IsMatch(KeyValuePair<string, IAsset> asset) | ||
{ | ||
return UriRegex.IsMatch(asset.Value.Uri.ToString()); | ||
} | ||
} | ||
|
||
|
||
|
||
public class RolesAssetFilter : IAssetFilter | ||
{ | ||
|
||
public Regex RolesRegex { get; set; } | ||
|
||
public RolesAssetFilter(Regex rolesRegex) | ||
{ | ||
RolesRegex = rolesRegex; | ||
} | ||
|
||
public bool IsMatch(KeyValuePair<string, IAsset> asset) | ||
{ | ||
return asset.Value.Roles.Any(role => RolesRegex.IsMatch(role)); | ||
} | ||
} | ||
|
||
public class KeyAssetFilter : IAssetFilter | ||
{ | ||
|
||
public Regex KeyRegex { get; set; } | ||
|
||
public KeyAssetFilter(Regex keyRegex) | ||
{ | ||
KeyRegex = keyRegex; | ||
} | ||
|
||
public bool IsMatch(KeyValuePair<string, IAsset> asset) | ||
{ | ||
return KeyRegex.IsMatch(asset.Key); | ||
} | ||
} | ||
|
||
public class PropertyAssetFilter : IAssetFilter | ||
{ | ||
|
||
public KeyValuePair<string, Regex> PropertyRegexPattern { get; set; } | ||
|
||
public PropertyAssetFilter(string key, Regex valuePattern) | ||
{ | ||
PropertyRegexPattern = new KeyValuePair<string, Regex>(key, valuePattern); | ||
} | ||
|
||
public bool IsMatch(KeyValuePair<string, IAsset> asset) | ||
{ | ||
return asset.Value.Properties.ContainsKey(PropertyRegexPattern.Key) && | ||
PropertyRegexPattern.Value.IsMatch(asset.Value.Properties[PropertyRegexPattern.Key].ToString()); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters