mirror of
https://github.com/esiur/esiur-dotnet.git
synced 2025-06-27 05:23:13 +00:00
Updated to support IIP v3.3
This commit is contained in:
@ -28,6 +28,11 @@ namespace Esiur.Resource.Template
|
||||
return BinaryList.ToBytes((byte)0x40, (byte)name.Length, name);
|
||||
}
|
||||
|
||||
public EventTemplate() { Type = MemberType.Event; }
|
||||
|
||||
public EventTemplate(ResourceTemplate template, byte index, string name, string expansion)
|
||||
:base(template, MemberType.Property, index, name)
|
||||
{
|
||||
this.Expansion = expansion;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -37,6 +37,11 @@ namespace Esiur.Resource.Template
|
||||
}
|
||||
|
||||
|
||||
public FunctionTemplate() { Type = MemberType.Function; }
|
||||
public FunctionTemplate(ResourceTemplate template, byte index, string name,bool isVoid, string expansion)
|
||||
:base(template, MemberType.Property, index, name)
|
||||
{
|
||||
this.IsVoid = isVoid;
|
||||
this.Expansion = expansion;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -16,9 +16,26 @@ namespace Esiur.Resource.Template
|
||||
Event = 2,
|
||||
}
|
||||
|
||||
public byte Index { get; set; }
|
||||
public string Name { get; set; }
|
||||
public MemberType Type { get; set; }
|
||||
public byte Index => index;
|
||||
public string Name => name;
|
||||
public MemberType Type => type;
|
||||
|
||||
ResourceTemplate template;
|
||||
string name;
|
||||
MemberType type;
|
||||
byte index;
|
||||
|
||||
public ResourceTemplate Template => template;
|
||||
|
||||
public MemberTemplate(ResourceTemplate template, MemberType type, byte index, string name)
|
||||
{
|
||||
this.template = template;
|
||||
this.type = type;
|
||||
this.index = index;
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public string Fullname => template.ClassName + "." + Name;
|
||||
|
||||
public virtual byte[] Compose()
|
||||
{
|
||||
|
@ -16,13 +16,27 @@ namespace Esiur.Resource.Template
|
||||
ReadWrite
|
||||
}
|
||||
|
||||
|
||||
//bool ReadOnly;
|
||||
//IIPTypes::DataType ReturnType;
|
||||
public PropertyPermission Permission {
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
public bool Recordable
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}*/
|
||||
|
||||
public StorageMode Storage
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
public string ReadExpansion
|
||||
{
|
||||
get;
|
||||
@ -35,37 +49,46 @@ namespace Esiur.Resource.Template
|
||||
set;
|
||||
}
|
||||
|
||||
/*
|
||||
public bool Storable
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
}*/
|
||||
|
||||
|
||||
public override byte[] Compose()
|
||||
{
|
||||
var name = base.Compose();
|
||||
var pv = ((byte)(Permission) << 1) | (Storage == StorageMode.Recordable ? 1 : 0);
|
||||
|
||||
if (WriteExpansion != null && ReadExpansion != null)
|
||||
{
|
||||
var rexp = DC.ToBytes(ReadExpansion);
|
||||
var wexp = DC.ToBytes(WriteExpansion);
|
||||
return BinaryList.ToBytes((byte)(0x38 | (byte)Permission), wexp.Length, wexp, rexp.Length, rexp, (byte)name.Length, name);
|
||||
return BinaryList.ToBytes((byte)(0x38 | pv), wexp.Length, wexp, rexp.Length, rexp, (byte)name.Length, name);
|
||||
}
|
||||
else if (WriteExpansion != null)
|
||||
{
|
||||
var wexp = DC.ToBytes(WriteExpansion);
|
||||
return BinaryList.ToBytes((byte)(0x30 | (byte)Permission), wexp.Length, wexp, (byte)name.Length, name);
|
||||
return BinaryList.ToBytes((byte)(0x30 | pv), wexp.Length, wexp, (byte)name.Length, name);
|
||||
}
|
||||
else if (ReadExpansion != null)
|
||||
{
|
||||
var rexp = DC.ToBytes(ReadExpansion);
|
||||
return BinaryList.ToBytes((byte)(0x28 | (byte)Permission), rexp.Length, rexp, (byte)name.Length, name);
|
||||
return BinaryList.ToBytes((byte)(0x28 | pv), rexp.Length, rexp, (byte)name.Length, name);
|
||||
}
|
||||
else
|
||||
return BinaryList.ToBytes((byte)(0x20 | (byte)Permission), (byte)name.Length, name);
|
||||
return BinaryList.ToBytes((byte)(0x20 | pv), (byte)name.Length, name);
|
||||
}
|
||||
|
||||
public PropertyTemplate() { Type = MemberType.Property; }
|
||||
public PropertyTemplate(ResourceTemplate template, byte index, string name, string read, string write, StorageMode storage)
|
||||
:base(template, MemberType.Property, index, name)
|
||||
{
|
||||
//this.Recordable = recordable;
|
||||
this.Storage = storage;
|
||||
this.ReadExpansion = read;
|
||||
this.WriteExpansion = write;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -155,12 +155,8 @@ namespace Esiur.Resource.Template
|
||||
var ps = (ResourceProperty[])pi.GetCustomAttributes(typeof(ResourceProperty), true);
|
||||
if (ps.Length > 0)
|
||||
{
|
||||
var pt = new PropertyTemplate();
|
||||
pt.Name = pi.Name;
|
||||
pt.Index = i++;
|
||||
pt.ReadExpansion = ps[0].ReadExpansion;
|
||||
pt.WriteExpansion = ps[0].WriteExpansion;
|
||||
properties.Add(pt);
|
||||
var pt = new PropertyTemplate(this, i++, pi.Name, ps[0].ReadExpansion, ps[0].WriteExpansion, ps[0].Storage);
|
||||
properties.Add(pt);
|
||||
}
|
||||
}
|
||||
|
||||
@ -171,10 +167,7 @@ namespace Esiur.Resource.Template
|
||||
var es = (ResourceEvent[])ei.GetCustomAttributes(typeof(ResourceEvent), true);
|
||||
if (es.Length > 0)
|
||||
{
|
||||
var et = new EventTemplate();
|
||||
et.Name = ei.Name;
|
||||
et.Index = i++;
|
||||
et.Expansion = es[0].Expansion;
|
||||
var et = new EventTemplate(this, i++, ei.Name, es[0].Expansion);
|
||||
events.Add(et);
|
||||
}
|
||||
}
|
||||
@ -185,11 +178,7 @@ namespace Esiur.Resource.Template
|
||||
var fs = (ResourceFunction[])mi.GetCustomAttributes(typeof(ResourceFunction), true);
|
||||
if (fs.Length > 0)
|
||||
{
|
||||
var ft = new FunctionTemplate();
|
||||
ft.Name = mi.Name;
|
||||
ft.Index = i++;
|
||||
ft.IsVoid = mi.ReturnType == typeof(void);
|
||||
ft.Expansion = fs[0].Expansion;
|
||||
var ft = new FunctionTemplate(this, i++, mi.Name, mi.ReturnType == typeof(void), fs[0].Expansion);
|
||||
functions.Add(ft);
|
||||
}
|
||||
}
|
||||
@ -258,69 +247,76 @@ namespace Esiur.Resource.Template
|
||||
|
||||
if (type == 0) // function
|
||||
{
|
||||
var ft = new FunctionTemplate();
|
||||
ft.Index = functionIndex++;
|
||||
var expansion = ((data[offset] & 0x10) == 0x10);
|
||||
ft.IsVoid = ((data[offset++] & 0x08) == 0x08);
|
||||
ft.Name = data.GetString(offset + 1, data[offset]);// Encoding.ASCII.GetString(data, (int)offset + 1, data[offset]);
|
||||
string expansion = null;
|
||||
var hasExpansion = ((data[offset] & 0x10) == 0x10);
|
||||
var isVoid = ((data[offset++] & 0x08) == 0x08);
|
||||
var name = data.GetString(offset + 1, data[offset]);// Encoding.ASCII.GetString(data, (int)offset + 1, data[offset]);
|
||||
offset += (uint)data[offset] + 1;
|
||||
|
||||
if (expansion) // expansion ?
|
||||
|
||||
if (hasExpansion) // expansion ?
|
||||
{
|
||||
var cs = data.GetUInt32(offset);
|
||||
offset += 4;
|
||||
ft.Expansion = data.GetString(offset, cs);
|
||||
expansion = data.GetString(offset, cs);
|
||||
offset += cs;
|
||||
}
|
||||
|
||||
var ft = new FunctionTemplate(od, functionIndex++, name, isVoid, expansion);
|
||||
|
||||
od.functions.Add(ft);
|
||||
}
|
||||
else if (type == 1) // property
|
||||
{
|
||||
|
||||
var pt = new PropertyTemplate();
|
||||
pt.Index = propertyIndex++;
|
||||
var readExpansion = ((data[offset] & 0x8) == 0x8);
|
||||
var writeExpansion = ((data[offset] & 0x10) == 0x10);
|
||||
pt.Permission = (PropertyTemplate.PropertyPermission)((data[offset++] >> 1) & 0x3);
|
||||
pt.Name = data.GetString(offset + 1, data[offset]);// Encoding.ASCII.GetString(data, (int)offset + 1, data[offset]);
|
||||
string readExpansion = null, writeExpansion = null;
|
||||
|
||||
var hasReadExpansion = ((data[offset] & 0x8) == 0x8);
|
||||
var hasWriteExpansion = ((data[offset] & 0x10) == 0x10);
|
||||
var recordable = ((data[offset] & 1) == 1);
|
||||
var permission = (PropertyTemplate.PropertyPermission)((data[offset++] >> 1) & 0x3);
|
||||
var name = data.GetString(offset + 1, data[offset]);// Encoding.ASCII.GetString(data, (int)offset + 1, data[offset]);
|
||||
|
||||
offset += (uint)data[offset] + 1;
|
||||
|
||||
if (readExpansion) // expansion ?
|
||||
if (hasReadExpansion) // expansion ?
|
||||
{
|
||||
var cs = data.GetUInt32(offset);
|
||||
offset += 4;
|
||||
pt.ReadExpansion = data.GetString(offset, cs);
|
||||
readExpansion = data.GetString(offset, cs);
|
||||
offset += cs;
|
||||
}
|
||||
|
||||
if (writeExpansion) // expansion ?
|
||||
if (hasWriteExpansion) // expansion ?
|
||||
{
|
||||
var cs = data.GetUInt32(offset);
|
||||
offset += 4;
|
||||
pt.WriteExpansion = data.GetString(offset, cs);
|
||||
writeExpansion = data.GetString(offset, cs);
|
||||
offset += cs;
|
||||
}
|
||||
|
||||
var pt = new PropertyTemplate(od, propertyIndex++, name, readExpansion, writeExpansion, recordable ? StorageMode.Recordable : StorageMode.Volatile);
|
||||
|
||||
od.properties.Add(pt);
|
||||
}
|
||||
else if (type == 2) // Event
|
||||
{
|
||||
var et = new EventTemplate();
|
||||
et.Index = eventIndex++;
|
||||
var expansion = ((data[offset++] & 0x10) == 0x10);
|
||||
|
||||
et.Name = data.GetString(offset + 1, data[offset]);// Encoding.ASCII.GetString(data, (int)offset + 1, (int)data[offset]);
|
||||
string expansion = null;
|
||||
var hasExpansion = ((data[offset++] & 0x10) == 0x10);
|
||||
|
||||
var name = data.GetString(offset + 1, data[offset]);// Encoding.ASCII.GetString(data, (int)offset + 1, (int)data[offset]);
|
||||
offset += (uint)data[offset] + 1;
|
||||
|
||||
if (expansion) // expansion ?
|
||||
if (hasExpansion) // expansion ?
|
||||
{
|
||||
var cs = data.GetUInt32(offset);
|
||||
offset += 4;
|
||||
et.Expansion = data.GetString(offset, cs);
|
||||
expansion = data.GetString(offset, cs);
|
||||
offset += cs;
|
||||
}
|
||||
|
||||
var et = new EventTemplate(od, eventIndex++, name, expansion);
|
||||
|
||||
od.events.Add(et);
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user