-
Notifications
You must be signed in to change notification settings - Fork 24
/
IResourceManagement.cs
110 lines (91 loc) · 3.79 KB
/
IResourceManagement.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
// Copyright (c) 2023, Phoenix Contact GmbH & Co. KG
// Licensed under the Apache License, Version 2.0
using System;
using System.Collections.Generic;
using Moryx.AbstractionLayer.Capabilities;
namespace Moryx.AbstractionLayer.Resources
{
/// <summary>
/// Resource management API used to interact with resources on an abstract level
/// </summary>
public interface IResourceManagement
{
/// <summary>
/// Get only resources of this type
/// </summary>
TResource GetResource<TResource>()
where TResource : class, IResource;
/// <summary>
/// Get typed resource by id
/// </summary>
TResource GetResource<TResource>(long id)
where TResource : class, IResource;
/// <summary>
/// Get typed resource by name
/// </summary>
TResource GetResource<TResource>(string name)
where TResource : class, IResource;
/// <summary>
/// Get the only resource that provides the required capabilities.
/// </summary>
/// <returns>Instance if only one match was found, otherwise <value>null</value></returns>
TResource GetResource<TResource>(ICapabilities requiredCapabilities)
where TResource : class, IResource;
/// <summary>
/// Get the only resource that matches the given predicate
/// </summary>
/// <returns>Instance if only one match was found, otherwise <value>null</value></returns>
TResource GetResource<TResource>(Func<TResource, bool> predicate)
where TResource : class, IResource;
/// <summary>
/// Get all resources of this type
/// </summary>
IEnumerable<TResource> GetResources<TResource>()
where TResource : class, IResource;
/// <summary>
/// Get all resources of this type that provide the required capabilities
/// </summary>
IEnumerable<TResource> GetResources<TResource>(ICapabilities requiredCapabilities)
where TResource : class, IResource;
/// <summary>
/// Get all resources of this type that match the predicate
/// </summary>
IEnumerable<TResource> GetResources<TResource>(Func<TResource, bool> predicate)
where TResource : class, IResource;
/// <summary>
/// Get all resources inluding the private ones of this type that match the predicate
/// </summary>
IEnumerable<TResource> GetAllResources<TResource>(Func<TResource, bool> predicate)
where TResource : class, IResource;
/// <summary>
/// Create and initialize a resource
/// </summary>
long Create(Type resourceType, Action<Resource> initializer);
/// <summary>
/// Read data from a resource
/// </summary>
TResult Read<TResult>(long id, Func<Resource, TResult> accessor);
/// <summary>
/// Modify the resource.
/// </summary>
/// <param name="id">Id of the resource</param>
/// <param name="modifier">Modifier delegate, must return <value>true</value> in order to save changes</param>
void Modify(long id, Func<Resource, bool> modifier);
/// <summary>
/// Create and initialize a resource
/// </summary>
bool Delete(long id);
/// <summary>
/// Event raised when a resource was added at runtime
/// </summary>
event EventHandler<IResource> ResourceAdded;
/// <summary>
/// Event raised when a resource was removed at runtime
/// </summary>
event EventHandler<IResource> ResourceRemoved;
/// <summary>
/// Raised when the capabilities have changed.
/// </summary>
event EventHandler<ICapabilities> CapabilitiesChanged;
}
}