mirror of
https://dev.azure.com/TeilRad/sharee.bike%20App/_git/Code
synced 2025-04-24 13:46:30 +02:00
Version 3.0.381
This commit is contained in:
parent
f963c0a219
commit
3a363acf3a
1525 changed files with 60589 additions and 125098 deletions
|
@ -0,0 +1,11 @@
|
|||
namespace ShareeBike.Model.Bikes.BikeInfoNS.BluetoothLock
|
||||
{
|
||||
public interface ILockInfo
|
||||
{
|
||||
/// <summary> Identification number of bluetooth lock.</summary>
|
||||
int Id { get; }
|
||||
|
||||
/// <summary> Gets the user key.</summary>
|
||||
byte[] UserKey { get; }
|
||||
}
|
||||
}
|
124
LockIt.BusinessLogic/Model/Bikes/Bike/BluetoothLock/LockInfo.cs
Normal file
124
LockIt.BusinessLogic/Model/Bikes/Bike/BluetoothLock/LockInfo.cs
Normal file
|
@ -0,0 +1,124 @@
|
|||
using System;
|
||||
using System.Runtime.Serialization;
|
||||
using Newtonsoft.Json;
|
||||
using ShareeBike.Model.Connector;
|
||||
|
||||
namespace ShareeBike.Model.Bikes.BikeInfoNS.BluetoothLock
|
||||
{
|
||||
/// <summary> Locking states. </summary>
|
||||
public enum LockingState
|
||||
{
|
||||
/// <summary> App is not connected to lock.</summary>
|
||||
UnknownDisconnected,
|
||||
|
||||
/// <summary> Lock might be open, closed or something in between.</summary>
|
||||
/// <remarks>
|
||||
/// Under certain circumstances lock reports/ is known to be in this state (genuine ILOCKIT locking state LockitLockingState.Unknown).
|
||||
/// Example: If bold is blocked it might happen that opening or closing lock leads to state unknown, i.e. might be open, closed or inbetween.
|
||||
/// </remarks>
|
||||
UnknownFromHardwareError,
|
||||
|
||||
/// <summary> Lock is closed. </summary>
|
||||
Closed,
|
||||
|
||||
/// <summary> Lock is open. </summary>
|
||||
Open
|
||||
}
|
||||
|
||||
[DataContract]
|
||||
public class LockInfo : ILockInfo, IEquatable<LockInfo>
|
||||
{
|
||||
/// <summary> Identification number of bluetooth lock, 6-digits, second part of advertisement name.</summary>
|
||||
[DataMember]
|
||||
public int Id { get; private set; } = TextToLockItTypeHelper.INVALIDLOCKID;
|
||||
|
||||
/// <summary> Identification GUID of bluetooth lock.</summary>
|
||||
[DataMember]
|
||||
public Guid Guid { get; private set; } = TextToLockItTypeHelper.INVALIDLOCKGUID;
|
||||
|
||||
[DataMember]
|
||||
public byte[] UserKey { get; private set; }
|
||||
|
||||
[DataMember]
|
||||
public byte[] AdminKey { get; private set; }
|
||||
|
||||
[DataMember]
|
||||
public byte[] Seed { get; private set; }
|
||||
|
||||
/// <summary> Locking state of bluetooth lock. </summary>
|
||||
[DataMember]
|
||||
public LockingState State { get; private set; } = LockingState.UnknownDisconnected;
|
||||
|
||||
public bool IsIdValid => Id != TextToLockItTypeHelper.INVALIDLOCKID;
|
||||
|
||||
public bool IsGuidValid => Guid != TextToLockItTypeHelper.INVALIDLOCKGUID;
|
||||
|
||||
public override bool Equals(object obj)
|
||||
=> Equals(obj as LockInfo);
|
||||
|
||||
public bool Equals(LockInfo other)
|
||||
{
|
||||
if (ReferenceEquals(other, null)) return false;
|
||||
if (ReferenceEquals(this, other)) return true;
|
||||
if (GetType() != other.GetType()) return false;
|
||||
|
||||
return ToString() == other.ToString();
|
||||
}
|
||||
|
||||
public override int GetHashCode() => ToString().GetHashCode();
|
||||
|
||||
public override string ToString() => JsonConvert.SerializeObject(this);
|
||||
|
||||
public static bool operator ==(LockInfo lhs, LockInfo rhs)
|
||||
{
|
||||
if (ReferenceEquals(lhs, null))
|
||||
return ReferenceEquals(rhs, null) ? true /*null == null = true*/: false;
|
||||
|
||||
return lhs.Equals(rhs);
|
||||
}
|
||||
|
||||
public static bool operator !=(LockInfo lhs, LockInfo rhs)
|
||||
=> !(lhs == rhs);
|
||||
|
||||
public class Builder
|
||||
{
|
||||
public Builder(LockInfo lockInfo = null)
|
||||
{
|
||||
if (lockInfo == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
LockInfo = JsonConvert.DeserializeObject<LockInfo>(JsonConvert.SerializeObject(lockInfo));
|
||||
}
|
||||
|
||||
private readonly LockInfo LockInfo = new LockInfo();
|
||||
|
||||
public byte[] UserKey { get => LockInfo.UserKey; set => LockInfo.UserKey = value; }
|
||||
|
||||
public byte[] AdminKey { get => LockInfo.AdminKey; set => LockInfo.AdminKey = value; }
|
||||
|
||||
public byte[] Seed { get => LockInfo.Seed; set => LockInfo.Seed = value; }
|
||||
|
||||
public int Id { get => LockInfo.Id; set => LockInfo.Id = value; }
|
||||
|
||||
public Guid Guid { get => LockInfo.Guid; set => LockInfo.Guid = value; }
|
||||
|
||||
public LockingState State { get => LockInfo.State; set => LockInfo.State = value; }
|
||||
|
||||
public LockInfo Build()
|
||||
{
|
||||
// Ensure consistency.
|
||||
if ((UserKey?.Length > 0 || Seed?.Length > 0)
|
||||
&& (UserKey?.Length == 0 || Seed?.Length == 0 || !LockInfo.IsIdValid))
|
||||
throw new ArgumentException($"Can not build {typeof(LockInfo).Name}. Lock parameters must either be all know or all unknown.");
|
||||
|
||||
if (UserKey == null) UserKey = new byte[0];
|
||||
if (AdminKey == null) AdminKey = new byte[0];
|
||||
if (Seed == null) Seed = new byte[0];
|
||||
|
||||
return LockInfo;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,8 @@
|
|||
namespace ShareeBike.Model.Bikes.BikeInfoNS.CopriLock
|
||||
{
|
||||
public interface ILockInfo
|
||||
{
|
||||
/// <summary> Locking state of backend lock. </summary>
|
||||
LockingState State { get; }
|
||||
}
|
||||
}
|
88
LockIt.BusinessLogic/Model/Bikes/Bike/CopriLock/LockInfo.cs
Normal file
88
LockIt.BusinessLogic/Model/Bikes/Bike/CopriLock/LockInfo.cs
Normal file
|
@ -0,0 +1,88 @@
|
|||
using System;
|
||||
using System.Runtime.Serialization;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace ShareeBike.Model.Bikes.BikeInfoNS.CopriLock
|
||||
{
|
||||
/// <summary> Locking states. </summary>
|
||||
public enum LockingState
|
||||
{
|
||||
/// <summary> App is not connected to lock.</summary>
|
||||
UnknownDisconnected,
|
||||
|
||||
/// <summary> Lock is closed. </summary>
|
||||
Closed,
|
||||
|
||||
/// <summary> Lock is closing. </summary>
|
||||
Closing,
|
||||
|
||||
/// <summary> Lock is open. </summary>
|
||||
Open,
|
||||
|
||||
/// <summary> Lock is opening. </summary>
|
||||
Opening
|
||||
}
|
||||
|
||||
[DataContract]
|
||||
public class LockInfo : ILockInfo
|
||||
{
|
||||
/// <summary> Locking state of bluetooth lock. </summary>
|
||||
[DataMember]
|
||||
public LockingState State { get; private set; } = LockingState.UnknownDisconnected;
|
||||
|
||||
public override bool Equals(object obj) => this.Equals(obj as LockInfo);
|
||||
|
||||
public bool Equals(LockInfo other)
|
||||
{
|
||||
if (Object.ReferenceEquals(other, null)) return false;
|
||||
if (Object.ReferenceEquals(this, other)) return true;
|
||||
if (this.GetType() != other.GetType()) return false;
|
||||
|
||||
return ToString() == other.ToString();
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return ToString().GetHashCode();
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return JsonConvert.SerializeObject(this);
|
||||
}
|
||||
|
||||
public static bool operator ==(LockInfo lhs, LockInfo rhs)
|
||||
{
|
||||
if (Object.ReferenceEquals(lhs, null))
|
||||
return Object.ReferenceEquals(rhs, null) ? true /*null == null = true*/: false;
|
||||
|
||||
return lhs.Equals(rhs);
|
||||
}
|
||||
|
||||
public static bool operator !=(LockInfo lhs, LockInfo rhs)
|
||||
{
|
||||
return !(lhs == rhs);
|
||||
}
|
||||
|
||||
public class Builder
|
||||
{
|
||||
public Builder(LockInfo lockInfo = null)
|
||||
{
|
||||
if (lockInfo == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
LockInfo = JsonConvert.DeserializeObject<LockInfo>(JsonConvert.SerializeObject(lockInfo));
|
||||
}
|
||||
|
||||
private readonly LockInfo LockInfo = new LockInfo();
|
||||
|
||||
|
||||
public LockingState State { get => LockInfo.State; set => LockInfo.State = value; }
|
||||
|
||||
public LockInfo Build() => LockInfo;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue