Skip to content

Commit 83e84c5

Browse files
committed
wip
1 parent f3c8ccd commit 83e84c5

14 files changed

Lines changed: 653 additions & 0 deletions

File tree

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
using System;
2+
using AXSharp.Connector;
3+
using AXSharp.Connector.ValueTypes;
4+
using System.Collections.Generic;
5+
using AXSharp.Connector.Localizations;
6+
using AXSharp.Abstractions.Presentation;
7+
8+
public partial class appTwinController : ITwinController
9+
{
10+
public AXSharp.Connector.Connector Connector { get; }
11+
public lib1.MyClass lib1_MyClass { get; }
12+
public lib2.MyClass lib2_MyClass { get; }
13+
14+
partial void PreConstruct(AXSharp.Connector.ITwinObject parent, string readableTail, string symbolTail);
15+
partial void PostConstruct(AXSharp.Connector.ITwinObject parent, string readableTail, string symbolTail);
16+
public appTwinController(AXSharp.Connector.ConnectorAdapter adapter, object[] parameters)
17+
{
18+
this.Connector = adapter.GetConnector(parameters);
19+
lib1_MyClass = new lib1.MyClass(this.Connector, "", "lib1_MyClass");
20+
lib2_MyClass = new lib2.MyClass(this.Connector, "", "lib2_MyClass");
21+
}
22+
23+
public appTwinController(AXSharp.Connector.ConnectorAdapter adapter)
24+
{
25+
this.Connector = adapter.GetConnector(adapter.Parameters);
26+
lib1_MyClass = new lib1.MyClass(this.Connector, "", "lib1_MyClass");
27+
lib2_MyClass = new lib2.MyClass(this.Connector, "", "lib2_MyClass");
28+
}
29+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
using System;
2+
using AXSharp.Connector;
3+
using AXSharp.Connector.ValueTypes;
4+
using System.Collections.Generic;
5+
using AXSharp.Connector.Localizations;
6+
using AXSharp.Abstractions.Presentation;
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
using System;
2+
using AXSharp.Connector;
3+
using AXSharp.Connector.ValueTypes;
4+
using System.Collections.Generic;
5+
using AXSharp.Connector.Localizations;
6+
using AXSharp.Abstractions.Presentation;
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
using System;
2+
using AXSharp.Abstractions.Presentation;
3+
using AXSharp.Connector;
4+
5+
namespace Pocos
6+
{
7+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
using System;
2+
using AXSharp.Abstractions.Presentation;
3+
using AXSharp.Connector;
4+
5+
namespace Pocos
6+
{
7+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
2+
using System.Reflection;
3+
using AXSharp.Connector.Localizations;
4+
5+
namespace app
6+
{
7+
public sealed class PlcTranslator : Translator
8+
{
9+
private static readonly PlcTranslator instance = new PlcTranslator();
10+
11+
public static PlcTranslator Instance
12+
{
13+
get
14+
{
15+
return instance;
16+
}
17+
}
18+
19+
private PlcTranslator()
20+
{
21+
var assembly = Assembly.GetAssembly(typeof(app.PlcTranslator));
22+
var resource = assembly.GetType("app.Resources.PlcStringResources");
23+
this.SetLocalizationResource(resource, assembly);
24+
}
25+
}
26+
}

src/AXSharp.compiler/tests/integration/expected/lib1/ix/.g/Configurations.g.cs

Whitespace-only changes.
Lines changed: 241 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,241 @@
1+
using System;
2+
using AXSharp.Connector;
3+
using AXSharp.Connector.ValueTypes;
4+
using System.Collections.Generic;
5+
using AXSharp.Connector.Localizations;
6+
using AXSharp.Abstractions.Presentation;
7+
8+
namespace lib1
9+
{
10+
public partial class MyClass : AXSharp.Connector.ITwinObject
11+
{
12+
public OnlinerString MyString { get; }
13+
public OnlinerInt MyInt { get; }
14+
15+
partial void PreConstruct(AXSharp.Connector.ITwinObject parent, string readableTail, string symbolTail);
16+
partial void PostConstruct(AXSharp.Connector.ITwinObject parent, string readableTail, string symbolTail);
17+
public MyClass(AXSharp.Connector.ITwinObject parent, string readableTail, string symbolTail)
18+
{
19+
Symbol = AXSharp.Connector.Connector.CreateSymbol(parent.Symbol, symbolTail);
20+
this.@SymbolTail = symbolTail;
21+
this.@Connector = parent.GetConnector();
22+
this.@Parent = parent;
23+
HumanReadable = AXSharp.Connector.Connector.CreateHumanReadable(parent.HumanReadable, readableTail);
24+
PreConstruct(parent, readableTail, symbolTail);
25+
MyString = @Connector.ConnectorAdapter.AdapterFactory.CreateSTRING(this, "MyString", "MyString");
26+
MyInt = @Connector.ConnectorAdapter.AdapterFactory.CreateINT(this, "MyInt", "MyInt");
27+
parent.AddChild(this);
28+
parent.AddKid(this);
29+
PostConstruct(parent, readableTail, symbolTail);
30+
}
31+
32+
public async virtual Task<T> OnlineToPlain<T>(eAccessPriority priority = eAccessPriority.Normal)
33+
{
34+
return await (dynamic)this.OnlineToPlainAsync(priority);
35+
}
36+
37+
public async Task<global::Pocos.lib1.MyClass> OnlineToPlainAsync(eAccessPriority priority = eAccessPriority.Normal)
38+
{
39+
global::Pocos.lib1.MyClass plain = new global::Pocos.lib1.MyClass();
40+
await this.ReadAsync<IgnoreOnPocoOperation>(priority);
41+
plain.MyString = MyString.LastValue;
42+
plain.MyInt = MyInt.LastValue;
43+
return plain;
44+
}
45+
46+
[Obsolete("This method should not be used if you indent to access the controllers data. Use `OnlineToPlain` instead.")]
47+
[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)]
48+
public async Task<global::Pocos.lib1.MyClass> _OnlineToPlainNoacAsync()
49+
{
50+
global::Pocos.lib1.MyClass plain = new global::Pocos.lib1.MyClass();
51+
plain.MyString = MyString.LastValue;
52+
plain.MyInt = MyInt.LastValue;
53+
return plain;
54+
}
55+
56+
[Obsolete("This method should not be used if you indent to access the controllers data. Use `OnlineToPlain` instead.")]
57+
[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)]
58+
protected async Task<global::Pocos.lib1.MyClass> _OnlineToPlainNoacAsync(global::Pocos.lib1.MyClass plain)
59+
{
60+
plain.MyString = MyString.LastValue;
61+
plain.MyInt = MyInt.LastValue;
62+
return plain;
63+
}
64+
65+
public async virtual Task PlainToOnline<T>(T plain, eAccessPriority priority = eAccessPriority.Normal)
66+
{
67+
await this.PlainToOnlineAsync((dynamic)plain, priority);
68+
}
69+
70+
public async Task<IEnumerable<ITwinPrimitive>> PlainToOnlineAsync(global::Pocos.lib1.MyClass plain, eAccessPriority priority = eAccessPriority.Normal)
71+
{
72+
#pragma warning disable CS0612
73+
MyString.LethargicWrite(plain.MyString);
74+
#pragma warning restore CS0612
75+
#pragma warning disable CS0612
76+
MyInt.LethargicWrite(plain.MyInt);
77+
#pragma warning restore CS0612
78+
return await this.WriteAsync<IgnoreOnPocoOperation>(priority);
79+
}
80+
81+
[Obsolete("This method should not be used if you indent to access the controllers data. Use `PlainToOnline` instead.")]
82+
[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)]
83+
public async Task _PlainToOnlineNoacAsync(global::Pocos.lib1.MyClass plain)
84+
{
85+
#pragma warning disable CS0612
86+
MyString.LethargicWrite(plain.MyString);
87+
#pragma warning restore CS0612
88+
#pragma warning disable CS0612
89+
MyInt.LethargicWrite(plain.MyInt);
90+
#pragma warning restore CS0612
91+
}
92+
93+
public async virtual Task<T> ShadowToPlain<T>()
94+
{
95+
return await (dynamic)this.ShadowToPlainAsync();
96+
}
97+
98+
public async Task<global::Pocos.lib1.MyClass> ShadowToPlainAsync()
99+
{
100+
global::Pocos.lib1.MyClass plain = new global::Pocos.lib1.MyClass();
101+
plain.MyString = MyString.Shadow;
102+
plain.MyInt = MyInt.Shadow;
103+
return plain;
104+
}
105+
106+
protected async Task<global::Pocos.lib1.MyClass> ShadowToPlainAsync(global::Pocos.lib1.MyClass plain)
107+
{
108+
plain.MyString = MyString.Shadow;
109+
plain.MyInt = MyInt.Shadow;
110+
return plain;
111+
}
112+
113+
public async virtual Task PlainToShadow<T>(T plain)
114+
{
115+
await this.PlainToShadowAsync((dynamic)plain);
116+
}
117+
118+
public async Task<IEnumerable<ITwinPrimitive>> PlainToShadowAsync(global::Pocos.lib1.MyClass plain)
119+
{
120+
MyString.Shadow = plain.MyString;
121+
MyInt.Shadow = plain.MyInt;
122+
return this.RetrievePrimitives();
123+
}
124+
125+
///<inheritdoc/>
126+
public async virtual Task<bool> AnyChangeAsync<T>(T plain)
127+
{
128+
return await this.DetectsAnyChangeAsync((dynamic)plain);
129+
}
130+
131+
///<summary>
132+
///Compares if the current plain object has changed from the previous object.This method is used by the framework to determine if the object has changed and needs to be updated.
133+
///[!NOTE] Any member in the hierarchy that is ignored by the compilers (e.g. when CompilerOmitAttribute is used) will not be compared, and therefore will not be detected as changed.
134+
///</summary>
135+
public async Task<bool> DetectsAnyChangeAsync(global::Pocos.lib1.MyClass plain, global::Pocos.lib1.MyClass latest = null)
136+
{
137+
if (latest == null)
138+
latest = await this._OnlineToPlainNoacAsync();
139+
var somethingChanged = false;
140+
return await Task.Run(async () =>
141+
{
142+
if (plain.MyString != MyString.LastValue)
143+
somethingChanged = true;
144+
if (plain.MyInt != MyInt.LastValue)
145+
somethingChanged = true;
146+
plain = latest;
147+
return somethingChanged;
148+
});
149+
}
150+
151+
public void Poll()
152+
{
153+
this.RetrievePrimitives().ToList().ForEach(x => x.Poll());
154+
}
155+
156+
public global::Pocos.lib1.MyClass CreateEmptyPoco()
157+
{
158+
return new global::Pocos.lib1.MyClass();
159+
}
160+
161+
private IList<AXSharp.Connector.ITwinObject> Children { get; } = new List<AXSharp.Connector.ITwinObject>();
162+
163+
public IEnumerable<AXSharp.Connector.ITwinObject> GetChildren()
164+
{
165+
return Children;
166+
}
167+
168+
private IList<AXSharp.Connector.ITwinElement> Kids { get; } = new List<AXSharp.Connector.ITwinElement>();
169+
170+
public IEnumerable<AXSharp.Connector.ITwinElement> GetKids()
171+
{
172+
return Kids;
173+
}
174+
175+
private IList<AXSharp.Connector.ITwinPrimitive> ValueTags { get; } = new List<AXSharp.Connector.ITwinPrimitive>();
176+
177+
public IEnumerable<AXSharp.Connector.ITwinPrimitive> GetValueTags()
178+
{
179+
return ValueTags;
180+
}
181+
182+
public void AddValueTag(AXSharp.Connector.ITwinPrimitive valueTag)
183+
{
184+
ValueTags.Add(valueTag);
185+
}
186+
187+
public void AddKid(AXSharp.Connector.ITwinElement kid)
188+
{
189+
Kids.Add(kid);
190+
}
191+
192+
public void AddChild(AXSharp.Connector.ITwinObject twinObject)
193+
{
194+
Children.Add(twinObject);
195+
}
196+
197+
protected AXSharp.Connector.Connector @Connector { get; }
198+
199+
public AXSharp.Connector.Connector GetConnector()
200+
{
201+
return this.@Connector;
202+
}
203+
204+
public string GetSymbolTail()
205+
{
206+
return this.SymbolTail;
207+
}
208+
209+
public AXSharp.Connector.ITwinObject GetParent()
210+
{
211+
return this.@Parent;
212+
}
213+
214+
public string Symbol { get; protected set; }
215+
216+
private string _attributeName;
217+
public System.String AttributeName { get => string.IsNullOrEmpty(_attributeName) ? SymbolTail : _attributeName.Interpolate(this).CleanUpLocalizationTokens(); set => _attributeName = value; }
218+
219+
public System.String GetAttributeName(System.Globalization.CultureInfo culture)
220+
{
221+
if (string.IsNullOrEmpty(_attributeName))
222+
{
223+
return SymbolTail;
224+
}
225+
226+
return this.Translate(_attributeName, culture).Interpolate(this);
227+
}
228+
229+
private string _humanReadable;
230+
public string HumanReadable { get => string.IsNullOrEmpty(_humanReadable) ? SymbolTail : _humanReadable.Interpolate(this).CleanUpLocalizationTokens(); set => _humanReadable = value; }
231+
232+
public System.String GetHumanReadable(System.Globalization.CultureInfo culture)
233+
{
234+
return this.Translate(_humanReadable, culture);
235+
}
236+
237+
protected System.String @SymbolTail { get; set; }
238+
protected AXSharp.Connector.ITwinObject @Parent { get; set; }
239+
public AXSharp.Connector.Localizations.Translator Interpreter => global::lib1.PlcTranslator.Instance;
240+
}
241+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
using System;
2+
using AXSharp.Abstractions.Presentation;
3+
using AXSharp.Connector;
4+
5+
namespace Pocos
6+
{
7+
namespace lib1
8+
{
9+
public partial class MyClass : AXSharp.Connector.IPlain
10+
{
11+
public MyClass()
12+
{
13+
}
14+
15+
public string MyString { get; set; } = string.Empty;
16+
public Int16 MyInt { get; set; }
17+
}
18+
}
19+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
2+
using System.Reflection;
3+
using AXSharp.Connector.Localizations;
4+
5+
namespace lib1
6+
{
7+
public sealed class PlcTranslator : Translator
8+
{
9+
private static readonly PlcTranslator instance = new PlcTranslator();
10+
11+
public static PlcTranslator Instance
12+
{
13+
get
14+
{
15+
return instance;
16+
}
17+
}
18+
19+
private PlcTranslator()
20+
{
21+
var assembly = Assembly.GetAssembly(typeof(lib1.PlcTranslator));
22+
var resource = assembly.GetType("lib1.Resources.PlcStringResources");
23+
this.SetLocalizationResource(resource, assembly);
24+
}
25+
}
26+
}

0 commit comments

Comments
 (0)