This commit is contained in:
Sina Blattmann 2023-07-13 10:18:00 +02:00
commit 84097b340b
13 changed files with 118 additions and 33 deletions

View File

@ -55,6 +55,8 @@ public static class SessionMethods
var installation = Db.GetInstallationById(installationId); var installation = Db.GetInstallationById(installationId);
var parent = Db.GetFolderById(parentId); var parent = Db.GetFolderById(parentId);
if(installation.ParentId == parentId) return false;
return user is not null return user is not null
&& installation is not null && installation is not null
&& user.HasWriteAccess && user.HasWriteAccess

View File

@ -46,8 +46,20 @@ public class S3Cmd
public async Task<Boolean> CreateBucket(String bucketName) public async Task<Boolean> CreateBucket(String bucketName)
{ {
var cors = @"<?xml version=""1.0"" ?>
<CORSConfiguration xmlns=""http://s3.amazonaws.com/doc/2006-03-01/"">
<CORSRule>
<AllowedOrigin>*</AllowedOrigin>
<AllowedMethod>GET</AllowedMethod>
<AllowedMethod>HEAD</AllowedMethod>
<AllowedHeader>*</AllowedHeader>
</CORSRule>
</CORSConfiguration>";
var result = await Run(bucketName, "mb"); var result = await Run(bucketName, "mb");
return result.ExitCode == 0; var setCors = await Run(bucketName, "PutBucketCors", cors);
return result.ExitCode == 0 && setCors.ExitCode == 0;
} }
public async Task<Boolean> DeleteBucket(String bucketName) public async Task<Boolean> DeleteBucket(String bucketName)

Binary file not shown.

View File

@ -1,7 +1,7 @@
#!/bin/bash #!/bin/bash
dotnet_version='net6.0' dotnet_version='net6.0'
salimax_ip= '10.2.3.104' salimax_ip='10.2.3.104'
username='ie-entwicklung' username='ie-entwicklung'
set -e set -e
@ -10,6 +10,7 @@ echo -e "\n============================ Build ============================\n"
dotnet publish \ dotnet publish \
./SaliMax.csproj \ ./SaliMax.csproj \
-p:PublishTrimmed=false \
-c Release \ -c Release \
-r linux-x64 -r linux-x64
@ -17,17 +18,17 @@ echo -e "\n============================ Deploy ============================\n"
rsync -v \ rsync -v \
./bin/Release/$dotnet_version/linux-x64/publish/* \ ./bin/Release/$dotnet_version/linux-x64/publish/* \
ie-entwicklung@10.2.3.104:~/salimax $username@$salimax_ip:~/salimax
echo -e "\n============================ Restart Salimax sevice ============================\n" echo -e "\n============================ Restart Salimax sevice ============================\n"
ssh -tt \ ssh -tt \
ie-entwicklung@10.2.3.104 \ $username@$salimax_ip \
sudo systemctl restart salimax.service sudo systemctl restart salimax.service
echo -e "\n============================ Print service output ============================\n" echo -e "\n============================ Print service output ============================\n"
ssh -tt \ ssh -tt \
ie-entwicklung@10.2.3.104 \ $username@$salimax_ip \
journalctl -f -u salimax.service journalctl -f -u salimax.service

View File

@ -0,0 +1,34 @@
#!/bin/bash
dotnet_version='net6.0'
salimax_ip='10.2.4.29'
username='ie-entwicklung'
set -e
echo -e "\n============================ Build ============================\n"
dotnet publish \
./SaliMax.csproj \
-p:PublishTrimmed=false \
-c Release \
-r linux-x64
echo -e "\n============================ Deploy ============================\n"
rsync -v \
./bin/Release/$dotnet_version/linux-x64/publish/* \
$username@$salimax_ip:~/salimax
echo -e "\n============================ Restart Salimax sevice ============================\n"
ssh -tt \
$username@$salimax_ip \
sudo systemctl restart salimax.service
echo -e "\n============================ Print service output ============================\n"
ssh -tt \
$username@$salimax_ip \
journalctl -f -u salimax.service

View File

@ -6,7 +6,7 @@ public class RelaysRecord
{ {
private readonly Adam6360DRegisters _Regs; private readonly Adam6360DRegisters _Regs;
public RelaysRecord(Adam6360DRegisters regs) => _Regs = regs; private RelaysRecord(Adam6360DRegisters regs) => _Regs = regs;
public Boolean K1GridBusIsConnectedToGrid => _Regs.DigitalInput6; public Boolean K1GridBusIsConnectedToGrid => _Regs.DigitalInput6;
public Boolean K2IslandBusIsConnectedToGridBus => !_Regs.DigitalInput4; public Boolean K2IslandBusIsConnectedToGridBus => !_Regs.DigitalInput4;

View File

@ -51,17 +51,9 @@ public class Config //TODO: let IE choose from config files (Json) and connect t
AmptIp = new() { Host = "localhost", Port = 5005}, AmptIp = new() { Host = "localhost", Port = 5005},
RelaysIp = new() { Host = "localhost", Port = 5006}, RelaysIp = new() { Host = "localhost", Port = 5006},
BatteryIp = new() { Host = "localhost", Port = 5007}, BatteryIp = new() { Host = "localhost", Port = 5007},
BatteryNodes = new []{ 2, 3, 4, 5, 6 }, BatteryNodes = new []{ 2, 3, 4, 5, 6 }
}, },
S3 = new() S3 = null
{
Bucket = "saliomameiringen",
Region = "sos-ch-dk-2",
Provider = "exo.io",
ContentType = "text/plain; charset=utf-8",
Key = "EXO2bf0cbd97fbfa75aa36ed46f",
Secret = "Bn1CDPqOG-XpDSbYjfIJxojcHTm391vZTc8z8l_fEPs"
}
}; };
#else #else
public static Config Default => new() public static Config Default => new()

View File

@ -0,0 +1,43 @@
#!/bin/bash
host=ie-entwicklung@10.2.4.29
tunnel() {
name=$1
ip=$2
rPort=$3
lPort=$4
echo -n "localhost:$lPort $name "
ssh -nNTL "$lPort:$ip:$rPort" "$host" 2> /dev/null &
until nc -vz 127.0.0.1 $lPort 2> /dev/null
do
echo -n .
sleep 0.3
done
echo "ok"
}
echo ""
tunnel "Trumpf Inverter (http) " 10.0.2.1 80 9001
tunnel "Trumpf DCDC (http) " 10.0.3.1 80 9002
tunnel "Ext Emu Meter (http) " 10.0.4.1 80 9003
tunnel "Int Emu Meter (http) " 10.0.4.2 80 9004
tunnel "AMPT (http) " 10.0.5.1 8080 9005
#tunnel "Trumpf Inverter (modbus)" 10.0.2.1 502 3001
#tunnel "Trumpf DCDC (modbus) " 10.0.3.1 502 3002
#tunnel "Ext Emu Meter (modbus) " 10.0.4.1 502 3003
#tunnel "Int Emu Meter " 10.0.4.2 502 3004
#tunnel "AMPT (modbus) " 10.0.5.1 502 3005
#tunnel "Batteries " 127.0.0.1 6855 3007
echo
echo "press any key to close the tunnels ..."
read -r -n 1 -s
kill $(jobs -p)
echo "done"

View File

@ -33,7 +33,7 @@ tunnel "Trumpf DCDC (modbus) " 10.0.3.1 502 3002
tunnel "Ext Emu Meter (modbus) " 10.0.4.1 502 3003 tunnel "Ext Emu Meter (modbus) " 10.0.4.1 502 3003
tunnel "Int Emu Meter " 10.0.4.2 502 3004 tunnel "Int Emu Meter " 10.0.4.2 502 3004
tunnel "AMPT (modbus) " 10.0.5.1 502 3005 tunnel "AMPT (modbus) " 10.0.5.1 502 3005
tunnel "Batteries " 127.0.0.1 6855 5007 tunnel "Batteries " 127.0.0.1 6855 3007
echo echo

View File

@ -9,5 +9,6 @@ public enum InverterState : UInt16
AcSyncToGrid = 4, AcSyncToGrid = 4,
AcCloseContactor = 5, AcCloseContactor = 5,
AcConnected = 6, AcConnected = 6,
AcOpenContactor = 7,
Alarm = 99 Alarm = 99
} }

View File

@ -17,7 +17,7 @@ public class TruConvertAcDcDevices
public TruConvertAcDcDevices(Channel transport) public TruConvertAcDcDevices(Channel transport)
{ {
var modbusClient = new ModbusTcpClient(transport, 0); var modbusClient = new ModbusTcpClient(transport, slaveId: 0);
_SystemControl = new ModbusDevice<SystemControlRegisters>(modbusClient); _SystemControl = new ModbusDevice<SystemControlRegisters>(modbusClient);
@ -56,22 +56,22 @@ public class TruConvertAcDcDevices
} }
public void Write(AcDcDevicesRecord r) public void Write(AcDcDevicesRecord r)
{
try
{ {
if (r.SystemControl is not null) if (r.SystemControl is not null)
_SystemControl.Write(r.SystemControl); // must run BEFORE the attached devices _SystemControl.Write(r.SystemControl); // must run BEFORE the attached devices
foreach (var (ctrl, device) in r.Devices.Zip(_AcDcs)) foreach (var (ctrl, device) in r.Devices.Zip(_AcDcs))
{
try
{ {
device.Write(ctrl); device.Write(ctrl);
} }
}
catch (Exception e) catch (Exception e)
{ {
Console.WriteLine(e); Console.WriteLine(e);
// TODO: log // TODO: log
} }
} }
}
} }

View File

@ -23,7 +23,7 @@ public class TextBlock
return new TextBlock(alignedLines); return new TextBlock(alignedLines);
} }
public static TextBlock AlignRight(IReadOnlyList<Object> things) private static TextBlock AlignRight(IReadOnlyList<Object> things)
{ {
var lines = things var lines = things
.SelectMany(GetLines) .SelectMany(GetLines)