Constantin Ziesche | 8b4a64d | 2020-06-25 11:52:09 +0200 | [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.Generics; |
| 12 | using BaSyx.Models.Core.AssetAdministrationShell.References; |
| 13 | using BaSyx.Models.Core.AssetAdministrationShell.Identification; |
| 14 | using Newtonsoft.Json; |
| 15 | using System.Collections.Generic; |
| 16 | using System.Runtime.Serialization; |
| 17 | using BaSyx.Models.Core.Common; |
| 18 | using System.Linq; |
| 19 | using System.Collections; |
Constantin Ziesche | 0821550 | 2020-09-21 19:08:32 +0200 | [diff] [blame^] | 20 | using BaSyx.Models.Core.AssetAdministrationShell; |
Constantin Ziesche | 8b4a64d | 2020-06-25 11:52:09 +0200 | [diff] [blame] | 21 | |
| 22 | namespace BaSyx.Models.Connectivity.Descriptors |
| 23 | { |
| 24 | [DataContract] |
| 25 | public class SubmodelRepositoryDescriptor : ISubmodelRepositoryDescriptor |
| 26 | { |
| 27 | [IgnoreDataMember] |
| 28 | public Identifier Identification { get; set; } |
| 29 | [IgnoreDataMember] |
| 30 | public AdministrativeInformation Administration { get; set; } |
| 31 | [IgnoreDataMember] |
| 32 | public string IdShort { get; set; } |
| 33 | [IgnoreDataMember] |
| 34 | public LangStringSet Description { get; set; } |
| 35 | public IEnumerable<IEndpoint> Endpoints { get; internal set; } |
| 36 | |
| 37 | [IgnoreDataMember] |
Constantin Ziesche | 0821550 | 2020-09-21 19:08:32 +0200 | [diff] [blame^] | 38 | public IReferable Parent { get; set; } |
Constantin Ziesche | 8b4a64d | 2020-06-25 11:52:09 +0200 | [diff] [blame] | 39 | [IgnoreDataMember] |
| 40 | public string Category => null; |
| 41 | |
| 42 | public ModelType ModelType => ModelType.AssetAdministrationShellRepositoryDescriptor; |
| 43 | |
| 44 | public IElementContainer<ISubmodelDescriptor> SubmodelDescriptors { get; set; } |
| 45 | |
| 46 | public SubmodelRepositoryDescriptor(IEnumerable<IEndpoint> endpoints) |
| 47 | { |
| 48 | Endpoints = endpoints ?? new List<IEndpoint>(); |
Constantin Ziesche | 0821550 | 2020-09-21 19:08:32 +0200 | [diff] [blame^] | 49 | SubmodelDescriptors = new ElementContainer<ISubmodelDescriptor>(this); |
Constantin Ziesche | 8b4a64d | 2020-06-25 11:52:09 +0200 | [diff] [blame] | 50 | } |
| 51 | |
| 52 | [JsonConstructor] |
| 53 | public SubmodelRepositoryDescriptor(IEnumerable<ISubmodel> submodels, IEnumerable<IEndpoint> endpoints) : this(endpoints) |
| 54 | { |
| 55 | if (submodels?.Count() > 0) |
| 56 | foreach (var submodel in submodels) |
| 57 | { |
| 58 | AddSubmodel(submodel); |
| 59 | } |
| 60 | } |
| 61 | |
| 62 | public void AddSubmodel(ISubmodel submodel) |
| 63 | { |
| 64 | SubmodelDescriptor submodelDescriptor = new SubmodelDescriptor(submodel, Endpoints.ToList()); |
| 65 | SubmodelDescriptors.Create(submodelDescriptor); |
| 66 | } |
| 67 | |
| 68 | public void AddEndpoints(IEnumerable<IEndpoint> endpoints) |
| 69 | { |
| 70 | foreach (var endpoint in endpoints) |
| 71 | { |
| 72 | (Endpoints as IList).Add(endpoint); |
| 73 | } |
| 74 | } |
| 75 | |
| 76 | public void SetEndpoints(IEnumerable<IEndpoint> endpoints) |
| 77 | { |
| 78 | Endpoints = endpoints; |
| 79 | } |
| 80 | } |
| 81 | } |