diff --git a/mROA/Abstract/IContextRepository.cs b/mROA/Abstract/IContextRepository.cs index 9f064e1..7a3366e 100644 --- a/mROA/Abstract/IContextRepository.cs +++ b/mROA/Abstract/IContextRepository.cs @@ -8,8 +8,7 @@ namespace mROA.Abstract int HostId { get; set; } int ResisterObject(object o, IEndPointContext context); void ClearObject(ComplexObjectIdentifier id); - T GetObjectByShell(SharedObjectShellShell sharedObjectShellShell); - T? GetObject(ComplexObjectIdentifier id); + T GetObject(ComplexObjectIdentifier id); object GetSingleObject(Type type); int GetObjectIndex(object o, IEndPointContext context); } diff --git a/mROA/Implementation/Backend/MultiClientContextRepository.cs b/mROA/Implementation/Backend/MultiClientContextRepository.cs index 1647dbc..94af7d0 100644 --- a/mROA/Implementation/Backend/MultiClientContextRepository.cs +++ b/mROA/Implementation/Backend/MultiClientContextRepository.cs @@ -7,7 +7,7 @@ namespace mROA.Implementation.Backend public class MultiClientContextRepository : IContextRepository, IContextRepositoryHub { private readonly Func _produceRepository; - private Dictionary _repositories = new(); + private readonly Dictionary _repositories = new(); public MultiClientContextRepository(Func produceRepository) { @@ -31,14 +31,8 @@ namespace mROA.Implementation.Backend var repository = GetRepositoryByClientId(TransmissionConfig.OwnershipRepository.GetOwnershipId()); repository.ClearObject(id); } - - public T GetObjectByShell(SharedObjectShellShell sharedObjectShellShell) - { - var repository = GetRepository(sharedObjectShellShell.Identifier.OwnerId); - return repository.GetObject(sharedObjectShellShell.Identifier)!; - } - - public T? GetObject(ComplexObjectIdentifier id) + + public T GetObject(ComplexObjectIdentifier id) { var repository = GetRepositoryByClientId(TransmissionConfig.OwnershipRepository.GetOwnershipId()); return repository.GetObject(id); diff --git a/mROA/Implementation/ComplexObjectIdentifier.cs b/mROA/Implementation/ComplexObjectIdentifier.cs index a1004d3..35652ee 100644 --- a/mROA/Implementation/ComplexObjectIdentifier.cs +++ b/mROA/Implementation/ComplexObjectIdentifier.cs @@ -12,6 +12,7 @@ namespace mROA.Implementation { ContextId = contextId; OwnerId = ownerId; + } public static ComplexObjectIdentifier Null = new ComplexObjectIdentifier { ContextId = -2, OwnerId = -1 }; diff --git a/mROA/Implementation/ComplexRepository.cs b/mROA/Implementation/ComplexRepository.cs index 756969c..a46ae58 100644 --- a/mROA/Implementation/ComplexRepository.cs +++ b/mROA/Implementation/ComplexRepository.cs @@ -21,12 +21,7 @@ namespace mROA.Implementation throw new NotImplementedException(); } - public T GetObjectByShell(SharedObjectShellShell sharedObjectShellShell) - { - throw new NotImplementedException(); - } - - public T? GetObject(ComplexObjectIdentifier id) + public T GetObject(ComplexObjectIdentifier id) { throw new NotImplementedException(); } diff --git a/mROA/Implementation/RemoteContextRepository.cs b/mROA/Implementation/RemoteContextRepository.cs index 71097ed..e31ff0a 100644 --- a/mROA/Implementation/RemoteContextRepository.cs +++ b/mROA/Implementation/RemoteContextRepository.cs @@ -21,19 +21,7 @@ namespace mROA.Implementation throw new NotSupportedException(); } - public T GetObjectByShell(SharedObjectShellShell sharedObjectShellShell) - { - if (_representationProducer == null) - throw new NullReferenceException("representation producer is not initialized"); - - if (!RemoteTypes.TryGetValue(typeof(T), out var remoteType)) throw new NotSupportedException(); - var representationModule = _representationProducer.Produce(sharedObjectShellShell.Identifier.OwnerId); - var remote = (T)Activator.CreateInstance(remoteType, sharedObjectShellShell.Identifier.ContextId, - representationModule)!; - return remote; - } - - public T? GetObject(ComplexObjectIdentifier id) + public T GetObject(ComplexObjectIdentifier id) { if (_representationProducer == null) throw new NullReferenceException("representation producer is not initialized"); @@ -41,7 +29,7 @@ namespace mROA.Implementation if (!RemoteTypes.TryGetValue(typeof(T), out var remoteType)) throw new NotSupportedException(); var representationModule = _representationProducer.Produce(TransmissionConfig.OwnershipRepository.GetOwnershipId()); - var remote = (T)Activator.CreateInstance(remoteType, id, + var remote = (T)Activator.CreateInstance(remoteType, id.ContextId, representationModule)!; return remote; } diff --git a/mROA/Implementation/RemoteObjectBase.cs b/mROA/Implementation/RemoteObjectBase.cs index 3ee8774..225a010 100644 --- a/mROA/Implementation/RemoteObjectBase.cs +++ b/mROA/Implementation/RemoteObjectBase.cs @@ -10,6 +10,24 @@ namespace mROA.Implementation { public abstract class RemoteObjectBase : IDisposable { + protected bool Equals(RemoteObjectBase other) + { + return _identifier.Equals(other._identifier); + } + + public override bool Equals(object? obj) + { + if (obj is null) return false; + if (ReferenceEquals(this, obj)) return true; + if (obj.GetType() != GetType()) return false; + return Equals((RemoteObjectBase)obj); + } + + public override int GetHashCode() + { + return HashCode.Combine(_identifier.GetHashCode(), _identifier.ContextId); + } + private readonly ComplexObjectIdentifier _identifier; private readonly IRepresentationModule _representationModule; diff --git a/mROA/Implementation/SharedObjectShell.cs b/mROA/Implementation/SharedObjectShell.cs index 6073d66..6abd096 100644 --- a/mROA/Implementation/SharedObjectShell.cs +++ b/mROA/Implementation/SharedObjectShell.cs @@ -28,6 +28,7 @@ namespace mROA.Implementation } // ReSharper disable once UnusedMember.Global + // ReSharper disable once MemberCanBePrivate.Global public SharedObjectShellShell(T value) { Value = value; @@ -35,6 +36,7 @@ namespace mROA.Implementation [JsonIgnore] [SerializationIgnore] + // ReSharper disable once MemberCanBePrivate.Global public T Value { get => _value; @@ -74,7 +76,7 @@ namespace mROA.Implementation set { _identifier = value; - Value = GetDefaultContextRepository().GetObjectByShell(this); + Value = GetDefaultContextRepository().GetObject(Identifier); } }