blob: e92acf72fdbc1db337b3d5588ff50572e104c7c5 [file] [log] [blame]
Constantin Ziesche857c7ab2020-02-25 11:24:51 +01001/*******************************************************************************
2* Copyright (c) 2020 Robert Bosch GmbH
3* Author: Constantin Ziesche (constantin.ziesche@bosch.com)
4*
5* This program and the accompanying materials are made available under the
6* terms of the Eclipse Public License 2.0 which is available at
7* http://www.eclipse.org/legal/epl-2.0
8*
9* SPDX-License-Identifier: EPL-2.0
10*******************************************************************************/
11using BaSyx.Models.Core.AssetAdministrationShell.Identification;
12using BaSyx.Models.Extensions;
13using BaSyx.Utils.ResultHandling;
14using Newtonsoft.Json;
15using System;
16using System.Collections.Generic;
17
18namespace BaSyx.Models.Core.Common
19{
Constantin Ziesche08215502020-09-21 19:08:32 +020020 public interface ICrudContainer<TIdentifier, TElement>
Constantin Ziesche857c7ab2020-02-25 11:24:51 +010021 {
Constantin Ziesche857c7ab2020-02-25 11:24:51 +010022 IResult<T> Create<T>(T element) where T : class, TElement;
23
24 IResult<TElement> Retrieve(TIdentifier id);
25
26 IResult<T> Retrieve<T>(TIdentifier id) where T : class, TElement;
27
Constantin Ziesche7b6d4792020-08-18 17:15:11 +020028 IResult<IQueryableElementContainer<T>> RetrieveAll<T>() where T : class, TElement;
Constantin Ziesche857c7ab2020-02-25 11:24:51 +010029
Constantin Ziesche7b6d4792020-08-18 17:15:11 +020030 IResult<IQueryableElementContainer<T>> RetrieveAll<T>(Predicate<T> predicate) where T : class, TElement;
31
32 IResult<TElement> CreateOrUpdate(TIdentifier id, TElement element);
Constantin Ziesche857c7ab2020-02-25 11:24:51 +010033
34 IResult<TElement> Update(TIdentifier id, TElement element);
35
36 IResult Delete(TIdentifier id);
Constantin Ziesche08215502020-09-21 19:08:32 +020037
Constantin Ziesche7b6d4792020-08-18 17:15:11 +020038 }
39
Constantin Ziesche857c7ab2020-02-25 11:24:51 +010040 [JsonConverter(typeof(ElementContainerConverter))]
Constantin Ziesche08215502020-09-21 19:08:32 +020041 public interface IElementContainer<TElement> : ICrudContainer<string, TElement>, IEnumerable<TElement>
Constantin Ziesche857c7ab2020-02-25 11:24:51 +010042 {
Constantin Ziesche08215502020-09-21 19:08:32 +020043 TElement this[int i] { get; }
44 TElement this[string idShort] { get; }
45
Constantin Ziesche7b6d4792020-08-18 17:15:11 +020046 IResult<IQueryableElementContainer<TElement>> RetrieveAll();
47 IResult<IQueryableElementContainer<TElement>> RetrieveAll(Predicate<TElement> predicate);
Constantin Ziesche857c7ab2020-02-25 11:24:51 +010048
Constantin Ziesche08215502020-09-21 19:08:32 +020049 IEnumerable<IElementContainer<TElement>> Children { get; }
50 IEnumerable<TElement> Values { get; }
51 IElementContainer<TElement> ParentContainer { get; set; }
52
53 IReferable Parent { get; set; }
54 TElement Value { get; set; }
55 string Path { get; set; }
56 string IdShort { get; }
57 bool IsRoot { get; }
58
59 bool HasChildren();
60 bool HasChild(string idShort);
61 bool HasChildPath(string idShortPath);
62 void Traverse(Action<TElement> action);
63 IEnumerable<TElement> Flatten();
64 IElementContainer<TElement> GetChild(string idShortPath);
65 void AppendRootPath(string rootPath);
66 void Add(TElement element);
67 void Remove(string idShort);
68 void AddRange(IEnumerable<TElement> elements);
Constantin Ziesche857c7ab2020-02-25 11:24:51 +010069 }
70}