-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
totaly rework the app logic by removing the callback principe
implement entityinfo
- Loading branch information
Showing
11 changed files
with
248 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
namespace RustPlusApi.Data | ||
{ | ||
public class AlarmInfo | ||
{ | ||
public bool Value { get; set; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
namespace RustPlusApi.Data.Events | ||
{ | ||
public class SmartSwitchEventArg : SmartSwitchInfo | ||
{ | ||
public uint Id { get; set; } | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
RustPlusApi/RustPlusApi/Data/Events/StorageMonitorEventArg.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
namespace RustPlusApi.Data.Events | ||
{ | ||
public class StorageMonitorEventArg : StorageMonitorInfo | ||
{ | ||
public uint Id { get; set; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
namespace RustPlusApi.Data | ||
{ | ||
public class SmartSwitchInfo | ||
{ | ||
public bool Value { get; set; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
namespace RustPlusApi.Data | ||
{ | ||
public class StorageMonitorInfo | ||
{ | ||
public int? Capacity { get; set; } | ||
public bool? HasProtection { get; set; } | ||
public uint? ProtectionExpiry { get; set; } | ||
public List<StorageMonitorItemInfo>? Items { get; set; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
namespace RustPlusApi.Data | ||
{ | ||
public class StorageMonitorItemInfo | ||
{ | ||
public int Id { get; set; } | ||
public int? Quantity { get; set; } | ||
public bool? IsItemBlueprint { get; set; } | ||
} | ||
} |
62 changes: 62 additions & 0 deletions
62
RustPlusApi/RustPlusApi/Extensions/AppEntityInfoToModel.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
using RustPlusApi.Data; | ||
|
||
using RustPlusContracts; | ||
|
||
namespace RustPlusApi.Extensions | ||
{ | ||
public static class AppEntityInfoToModel | ||
{ | ||
public static object ToEntityInfo(this AppEntityInfo entity) | ||
{ | ||
return entity.Type switch | ||
{ | ||
AppEntityType.Switch => entity.ToSmartSwitchInfo(), | ||
AppEntityType.Alarm => entity.ToAlarmInfo(), | ||
AppEntityType.StorageMonitor => entity.ToStorageMonitorInfo(), | ||
_ => throw new ArgumentException($"The given type is not possible: {entity.Type}") | ||
}; | ||
} | ||
|
||
public static SmartSwitchInfo ToSmartSwitchInfo(this AppEntityInfo entity) | ||
{ | ||
return new SmartSwitchInfo | ||
{ | ||
Value = entity.Payload.Value | ||
}; | ||
} | ||
|
||
public static AlarmInfo ToAlarmInfo(this AppEntityInfo entity) | ||
{ | ||
return new AlarmInfo | ||
{ | ||
Value = entity.Payload.Value | ||
}; | ||
} | ||
|
||
public static StorageMonitorInfo ToStorageMonitorInfo(this AppEntityInfo entity) | ||
{ | ||
return new StorageMonitorInfo | ||
{ | ||
Capacity = entity.Payload.Capacity, | ||
HasProtection = entity.Payload.HasProtection, | ||
ProtectionExpiry = entity.Payload.ProtectionExpiry, | ||
Items = entity.Payload.Items.ToStorageMonitorItemsInfo().ToList() | ||
}; | ||
} | ||
|
||
public static StorageMonitorItemInfo ToStorageMonitorItemInfo(this AppEntityPayload.Types.Item item) | ||
{ | ||
return new StorageMonitorItemInfo | ||
{ | ||
Id = item.ItemId, | ||
Quantity = item.Quantity, | ||
IsItemBlueprint = item.ItemIsBlueprint, | ||
}; | ||
} | ||
|
||
public static IEnumerable<StorageMonitorItemInfo> ToStorageMonitorItemsInfo(this IEnumerable<AppEntityPayload.Types.Item> items) | ||
{ | ||
return items.Select(ToStorageMonitorItemInfo); | ||
} | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
RustPlusApi/RustPlusApi/Extensions/EntityChangedToModel.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
using RustPlusApi.Data.Events; | ||
|
||
using RustPlusContracts; | ||
|
||
namespace RustPlusApi.Extensions | ||
{ | ||
public static class EntityChangedToModel | ||
{ | ||
public static SmartSwitchEventArg ToSmartSwitchEvent(this AppEntityChanged entityChanged) | ||
{ | ||
return new SmartSwitchEventArg | ||
{ | ||
Id = entityChanged.EntityId, | ||
Value = entityChanged.Payload.Value | ||
}; | ||
} | ||
|
||
public static StorageMonitorEventArg ToStorageMonitorEvent(this AppEntityChanged entityChanged) | ||
{ | ||
return new StorageMonitorEventArg | ||
{ | ||
Id = entityChanged.EntityId, | ||
Capacity = entityChanged.Payload.Capacity, | ||
HasProtection = entityChanged.Payload.HasProtection, | ||
ProtectionExpiry = entityChanged.Payload.ProtectionExpiry, | ||
Items = entityChanged.Payload.Items.ToStorageMonitorItemsInfo().ToList() | ||
}; | ||
} | ||
} | ||
} |
Oops, something went wrong.