blob: 9cbe5d6cd15c4ff9b74cdcc12ef669ff1642a8b9 [file] [log] [blame]
Constantin Ziesche8b4a64d2020-06-25 11:52:09 +02001/*******************************************************************************
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.Generics;
12using BaSyx.Models.Core.AssetAdministrationShell.References;
13using BaSyx.Models.Core.AssetAdministrationShell.Identification;
14using Newtonsoft.Json;
15using System.Collections.Generic;
16using System.Runtime.Serialization;
17using BaSyx.Models.Core.Common;
18using System.Linq;
19using System.Collections;
Constantin Ziesche08215502020-09-21 19:08:32 +020020using BaSyx.Models.Core.AssetAdministrationShell;
Constantin Ziesche8b4a64d2020-06-25 11:52:09 +020021
22namespace 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 Ziesche08215502020-09-21 19:08:32 +020038 public IReferable Parent { get; set; }
Constantin Ziesche8b4a64d2020-06-25 11:52:09 +020039 [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 Ziesche08215502020-09-21 19:08:32 +020049 SubmodelDescriptors = new ElementContainer<ISubmodelDescriptor>(this);
Constantin Ziesche8b4a64d2020-06-25 11:52:09 +020050 }
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}