mirror of
https://dev.azure.com/TeilRad/sharee.bike%20App/_git/Code
synced 2024-11-16 23:26:26 +01:00
89 lines
2.3 KiB
C#
89 lines
2.3 KiB
C#
|
using Newtonsoft.Json;
|
|||
|
using System;
|
|||
|
using System.Runtime.Serialization;
|
|||
|
|
|||
|
namespace TINK.Model.Bikes.Bike.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;
|
|||
|
}
|
|||
|
|
|||
|
}
|
|||
|
}
|