Modular Application Creator Use Case Based Documentation
Loading...
Searching...
No Matches
BaseMAC_use_casesEM.cs
1using Newtonsoft.Json;
2using Siemens.Automation.ModularApplicationCreator.Core;
3using Siemens.Automation.ModularApplicationCreator.Modules.UI;
4using Siemens.Automation.ModularApplicationCreator.Tia;
5using Siemens.Automation.ModularApplicationCreator.Tia.Helper;
6using Siemens.Automation.ModularApplicationCreator.Tia.Modules;
7using Siemens.Automation.ModularApplicationCreator.Tia.Openness;
8using Siemens.Automation.ModularApplicationCreator.Tia.TiaAttributeFuncs;
9using Siemens.Automation.ModularApplicationCreatorBasics.Logging;
10using System;
11using System.Collections.Generic;
12using System.IO;
13using System.Windows;
14using MAC_use_cases.TiaImports;
15using MAC_use_cases.UI;
16
18{
19 public abstract partial class BaseMAC_use_casesEM : TiaEquipmentModule, ITiaAttributeUser
20 {
21
22 private EquipmentModuleEditorProvider _editorProvider;
23
24 [JsonIgnore] public List<TiaAttribute> Attributes { get; } = new List<TiaAttribute>();
25
26 [JsonIgnore] public ResourceManagement ResourceManagement { get; private set; } = new ResourceManagement();
27
28 protected BaseMAC_use_casesEM()
29 {
30 // Add language resources
31 string resourceName = typeof(BaseMAC_use_casesEM).Assembly.ManifestModule.Name;
32 resourceName = System.IO.Path.GetFileNameWithoutExtension(resourceName);
33 ResourceDictionary dictionary_en = (ResourceDictionary)Application.LoadComponent(
34 new Uri(@"/" + resourceName + ";;;component/Resources/Lang_en.xaml", UriKind.Relative));
35 ResourceDictionary dictionary_de = (ResourceDictionary)Application.LoadComponent(
36 new Uri(@"/" + resourceName + ";;;component/Resources/Lang_de.xaml", UriKind.Relative));
37 ResourceDictionary dictionary_zh = (ResourceDictionary)Application.LoadComponent(
38 new Uri(@"/" + resourceName + ";;;component/Resources/Lang_zh.xaml", UriKind.Relative));
39
40 LanguageResources.Add("en", dictionary_en);
41 LanguageResources.Add("de", dictionary_de);
42 LanguageResources.Add("zh", dictionary_zh);
43 InitOnlineHelp();
44 }
45
46 public override IEnumerable<TiaLibraryInfo> GetLibraryInfos()
47 {
48 List<TiaLibraryInfo> libraryInfos = ResourceManagement.GetLibraryInfos();
49 foreach (var controlModule in ControlModules)
50 {
51 if (controlModule is TiaEquipmentModule tiaModule)
52 {
53 libraryInfos.AddRange(tiaModule.GetLibraryInfos());
54 }
55 }
56
57 return libraryInfos;
58 }
59
61 public override void InitModule()
62 {
63 base.InitModule();
64 RunGeneratedTasksInitModule();
65 }
66
68 public override void AfterEquipmentModuleLoad()
69 {
70 base.AfterEquipmentModuleLoad();
71 RunGeneratedTasksAfterEQMLoad();
72 }
73
75 public override void BeforeModuleDeleted()
76 {
77 base.BeforeModuleDeleted();
78 RunGeneratedBeforeDelete();
79 }
80
81 public override EquipmentModuleEditorProvider GetEditorProvider()
82 {
83 if (_editorProvider == null)
84 {
85 _editorProvider = new EquipmentModuleEditorProvider(new MultiPageFrame(this));
86 }
87
88 return _editorProvider;
89 }
90
91 protected string GetContentAdditionalResource(string name)
92 {
93 System.Reflection.Assembly asm = System.Reflection.Assembly.GetExecutingAssembly();
94 string returnString =
95 new StreamReader(asm.GetManifestResourceStream("MAC_use_cases.TiaImports.AdditionalResources." + name))
96 .ReadToEnd();
97
98 return returnString;
99 }
100
106 {
107 RunGeneratedTasksConstructor();
108 }
109
113 protected virtual void CreateControlModules()
114 {
118 }
119
120 protected PlcDevice GetPlcDevice(TiaTemplateContext tiaTemplateContext)
121 {
122 if (tiaTemplateContext == null)
123 {
124 throw new ArgumentNullException(nameof(tiaTemplateContext));
125 }
126
127 PlcDevice plcDevice = tiaTemplateContext.TiaDevice as PlcDevice;
128
129 if (plcDevice == null)
130 {
131 if (tiaTemplateContext.TiaDevice != null)
132 {
133 throw new ArgumentException(
134 $"{nameof(TiaTemplateContext.TiaDevice)} must be '{typeof(PlcDevice)}' but it was '{tiaTemplateContext.TiaDevice.GetType()}'");
135 }
136
137 throw new ArgumentNullException($"{nameof(TiaTemplateContext.TiaDevice)}");
138 }
139
140 if (plcDevice.Name != ParentDevice.Name)
141 {
142 throw new ArgumentException(
143 $"ParentDevice name: '{ParentDevice.Name}' of this module does not match with the name of the TiaDevice: '{plcDevice.Name}' in {nameof(TiaTemplateContext)}");
144 }
145
146 return plcDevice;
147 }
148
149 protected void LogGenerationWarning(string message, string source)
150 {
151 MacManagement.LoggingService.LogMessage(LogTypes.GenerationWarning, message, source);
152 }
153
160 protected void AddGsdFiles(string[] gsdFiles, string resourceDirPath = "Resources")
161 {
162 string dllDirectory = Path.GetDirectoryName(GetType().Assembly.Location);
163 var gsdFileInfos = new List<FileInfo>(gsdFiles.Length);
164
165 foreach (string gsdFile in gsdFiles)
166 {
167 var f = new FileInfo(Path.Combine(dllDirectory, resourceDirPath, gsdFile));
168 gsdFileInfos.Add(f);
169 }
170
171 AddGsdFileToTiaProject(gsdFileInfos);
172 }
173 }
174}
virtual void InitAfterFirstCreationOrDeserialization()
Every logic and setting must be here which is important at the first creation or deserialization of t...
void AddGsdFiles(string[] gsdFiles, string resourceDirPath="Resources")
Adds the GSD files to TIA Project in MAC project Generated directory. The GSD files must be added to ...
virtual void CreateControlModules()
Creates Control Modules and adds them to the project.