Constantin Ziesche | 857c7ab | 2020-02-25 11:24:51 +0100 | [diff] [blame] | 1 | /******************************************************************************* |
| 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 | *******************************************************************************/ |
| 11 | using BaSyx.Models.Core.AssetAdministrationShell.Identification; |
| 12 | using BaSyx.Models.Extensions; |
| 13 | using BaSyx.Utils.ResultHandling; |
| 14 | using Newtonsoft.Json; |
| 15 | using System; |
| 16 | using System.Collections.Generic; |
| 17 | |
| 18 | namespace BaSyx.Models.Core.Common |
| 19 | { |
Constantin Ziesche | 0821550 | 2020-09-21 19:08:32 +0200 | [diff] [blame^] | 20 | public interface ICrudContainer<TIdentifier, TElement> |
Constantin Ziesche | 857c7ab | 2020-02-25 11:24:51 +0100 | [diff] [blame] | 21 | { |
Constantin Ziesche | 857c7ab | 2020-02-25 11:24:51 +0100 | [diff] [blame] | 22 | 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 Ziesche | 7b6d479 | 2020-08-18 17:15:11 +0200 | [diff] [blame] | 28 | IResult<IQueryableElementContainer<T>> RetrieveAll<T>() where T : class, TElement; |
Constantin Ziesche | 857c7ab | 2020-02-25 11:24:51 +0100 | [diff] [blame] | 29 | |
Constantin Ziesche | 7b6d479 | 2020-08-18 17:15:11 +0200 | [diff] [blame] | 30 | IResult<IQueryableElementContainer<T>> RetrieveAll<T>(Predicate<T> predicate) where T : class, TElement; |
| 31 | |
| 32 | IResult<TElement> CreateOrUpdate(TIdentifier id, TElement element); |
Constantin Ziesche | 857c7ab | 2020-02-25 11:24:51 +0100 | [diff] [blame] | 33 | |
| 34 | IResult<TElement> Update(TIdentifier id, TElement element); |
| 35 | |
| 36 | IResult Delete(TIdentifier id); |
Constantin Ziesche | 0821550 | 2020-09-21 19:08:32 +0200 | [diff] [blame^] | 37 | |
Constantin Ziesche | 7b6d479 | 2020-08-18 17:15:11 +0200 | [diff] [blame] | 38 | } |
| 39 | |
Constantin Ziesche | 857c7ab | 2020-02-25 11:24:51 +0100 | [diff] [blame] | 40 | [JsonConverter(typeof(ElementContainerConverter))] |
Constantin Ziesche | 0821550 | 2020-09-21 19:08:32 +0200 | [diff] [blame^] | 41 | public interface IElementContainer<TElement> : ICrudContainer<string, TElement>, IEnumerable<TElement> |
Constantin Ziesche | 857c7ab | 2020-02-25 11:24:51 +0100 | [diff] [blame] | 42 | { |
Constantin Ziesche | 0821550 | 2020-09-21 19:08:32 +0200 | [diff] [blame^] | 43 | TElement this[int i] { get; } |
| 44 | TElement this[string idShort] { get; } |
| 45 | |
Constantin Ziesche | 7b6d479 | 2020-08-18 17:15:11 +0200 | [diff] [blame] | 46 | IResult<IQueryableElementContainer<TElement>> RetrieveAll(); |
| 47 | IResult<IQueryableElementContainer<TElement>> RetrieveAll(Predicate<TElement> predicate); |
Constantin Ziesche | 857c7ab | 2020-02-25 11:24:51 +0100 | [diff] [blame] | 48 | |
Constantin Ziesche | 0821550 | 2020-09-21 19:08:32 +0200 | [diff] [blame^] | 49 | 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 Ziesche | 857c7ab | 2020-02-25 11:24:51 +0100 | [diff] [blame] | 69 | } |
| 70 | } |