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; |
Constantin Ziesche | 7b6d479 | 2020-08-18 17:15:11 +0200 | [diff] [blame] | 17 | using System.Linq; |
Constantin Ziesche | 857c7ab | 2020-02-25 11:24:51 +0100 | [diff] [blame] | 18 | |
| 19 | namespace BaSyx.Models.Core.Common |
| 20 | { |
| 21 | public interface IGenericElementContainer<TIdentifier, TElement> : IList<TElement> |
| 22 | { |
| 23 | TElement this[TIdentifier id] { get; } |
| 24 | |
| 25 | IResult<TElement> Create(TElement element); |
| 26 | |
| 27 | IResult<T> Create<T>(T element) where T : class, TElement; |
| 28 | |
| 29 | IResult<TElement> Retrieve(TIdentifier id); |
| 30 | |
| 31 | IResult<T> Retrieve<T>(TIdentifier id) where T : class, TElement; |
| 32 | |
Constantin Ziesche | 7b6d479 | 2020-08-18 17:15:11 +0200 | [diff] [blame] | 33 | IResult<IQueryableElementContainer<T>> RetrieveAll<T>() where T : class, TElement; |
Constantin Ziesche | 857c7ab | 2020-02-25 11:24:51 +0100 | [diff] [blame] | 34 | |
Constantin Ziesche | 7b6d479 | 2020-08-18 17:15:11 +0200 | [diff] [blame] | 35 | IResult<IQueryableElementContainer<T>> RetrieveAll<T>(Predicate<T> predicate) where T : class, TElement; |
| 36 | |
| 37 | IResult<TElement> CreateOrUpdate(TIdentifier id, TElement element); |
Constantin Ziesche | 857c7ab | 2020-02-25 11:24:51 +0100 | [diff] [blame] | 38 | |
| 39 | IResult<TElement> Update(TIdentifier id, TElement element); |
| 40 | |
| 41 | IResult Delete(TIdentifier id); |
| 42 | |
| 43 | void AddRange(IEnumerable<TElement> collection); |
| 44 | } |
Constantin Ziesche | 7b6d479 | 2020-08-18 17:15:11 +0200 | [diff] [blame] | 45 | |
| 46 | public interface IQueryableElementContainer<TElement> : IElementContainer<TElement>, IQueryable<TElement> |
| 47 | { |
| 48 | |
| 49 | } |
| 50 | |
Constantin Ziesche | 857c7ab | 2020-02-25 11:24:51 +0100 | [diff] [blame] | 51 | [JsonConverter(typeof(ElementContainerConverter))] |
| 52 | public interface IElementContainer<TElement> : IGenericElementContainer<string, TElement> |
| 53 | { |
Constantin Ziesche | 7b6d479 | 2020-08-18 17:15:11 +0200 | [diff] [blame] | 54 | IResult<IQueryableElementContainer<TElement>> RetrieveAll(); |
| 55 | IResult<IQueryableElementContainer<TElement>> RetrieveAll(Predicate<TElement> predicate); |
Constantin Ziesche | 857c7ab | 2020-02-25 11:24:51 +0100 | [diff] [blame] | 56 | |
| 57 | IElementContainer<TOutput> ConvertAll<TOutput>(Converter<TElement, TOutput> converter) where TOutput : IReferable, IModelElement; |
Constantin Ziesche | 857c7ab | 2020-02-25 11:24:51 +0100 | [diff] [blame] | 58 | IElementContainer<TModelElementType> Filter<TModelElementType>(ModelType modelType) where TModelElementType : IReferable, IModelElement, TElement; |
| 59 | IEnumerable<TModelElementType> FilterAsReference<TModelElementType>(ModelType modelType) where TModelElementType : IReferable, IModelElement, TElement; |
| 60 | } |
| 61 | } |