public IOwned <RpcObjectRef <TService> > PublishInstance <TService>(IOwned <TService> serviceInstance)
            where TService : class
        {
            if (serviceInstance is null)
            {
                throw new ArgumentNullException(nameof(serviceInstance));
            }
            var allServices = RpcBuilderUtil.GetAllServices(serviceInstance.Value.GetType(), true);

            this.TryRegisterServiceDefinitions(allServices, null);

            var connectionInfo = this.RetrieveConnectionInfo();

            lock (this.syncRoot)
            {
                var serviceInstanceId = RpcObjectId.NewId();

                var publishedServices = this.PublishInstanceCore_Locked(allServices, serviceInstance, serviceInstanceId, false);

                Func <ValueTask> disposeAction = () => this.UnpublishInstanceAsync(serviceInstanceId);

                return(OwnedObject.Create(new RpcObjectRef <TService>(
                                              connectionInfo, serviceInstanceId, publishedServices.ToArray()), disposeAction));
            }
        }
Exemple #2
0
 private void SetLastUser(IOwned <TOwner> result)
 {
     if (result is IOverriden <TOwner> previous)
     {
         previous.SetLastUser(owner);
     }
 }
        public void LifetimeScope_Resolves_IOwned()
        {
            IOwned <IInterface> ownedInstance = LifetimeScope.ResolveRequiredService <IOwned <IInterface> >();

            Assert.NotNull(ownedInstance);
            Assert.NotNull(ownedInstance.Value);
        }
 public bool CurrentPlayerOwns(IOwned owned)
 {
     Assert.IsTrue(IsValid);
     Assert.IsNotNull(owned);
     Assert.IsNotNull(owned.Owner);
     return(Agent.CurrentPlayerAgent.Value.Model == owned.Owner.Value);
 }
Exemple #5
0
 public static void SetNewOwner <TOwner> (this IOwned <TOwner> @this, TOwner owner)
 {
     if (!Equals(@this.Owner, default(TOwner)))
     {
         throw new InvalidOperationException("Cannot set owner. Item is already owned.");
     }
     @this.Owner = owner;
 }
Exemple #6
0
 public bool SameOwner(IOwned other)
 {
     if (other == null)
     {
         return(Owner.Value == null);
     }
     return(other.Owner.Value == Owner.Value);
 }
Exemple #7
0
 public static void ResetOwner <TOwner> (this IOwned <TOwner> @this)
 {
     if (Equals(@this.Owner, default(TOwner)))
     {
         throw new InvalidOperationException("Cannot reset owner. Item is not yet owned.");
     }
     @this.Owner = default(TOwner);
 }
Exemple #8
0
 public bool SameOwner(IOwned other)
 {
     if (other == null)
     {
         return(Owner.Value == null);
     }
     return(ReferenceEquals(other.Owner.Value, Owner.Value));
 }
        public void LifetimeScope_DoesNotDisposed_OwnedComponent()
        {
            IOwned <IDisposableInterface> disposable = LifetimeScope.ResolveRequiredService <IOwned <IDisposableInterface> >();

            Assert.False(disposable.Value.IsDisposed);

            LifetimeScope.Dispose();
            Assert.False(disposable.Value.IsDisposed);
        }
Exemple #10
0
 public bool Authorize(IOwned entity, UUID id)
 {
     if (id.Equals(_ownerID))
     {
         //Reset the timeout every time the user makes a change
         _updated = true;
         JM726.Lib.Static.Util.Wake(this);
         return(true);
     }
     return(false);
 }
Exemple #11
0
        public void Owned_Downcasts()
        {
            var builder = new ContainerBuilder();

            builder.RegisterTransient <Implementation>().As <IInterface>();
            var container = builder.Build();

            var instance = container.ResolveRequiredService <IOwned <IInterface> >();
            var e        = Record.Exception(() =>
            {
                IOwned <object> downcastOwned = instance;
            });

            Assert.Null(e);
        }
        public IOwned <RpcSingletonRef <TService> > PublishSingleton <TService>(IOwned <TService> singletonService) where TService : class
        {
            if (singletonService == null)
            {
                throw new ArgumentNullException(nameof(singletonService));
            }

            var allServices = RpcBuilderUtil.GetAllServices(typeof(TService), false);

            this.TryRegisterServiceDefinitions(allServices, null);

            var publishedServices = this.VerifyPublishedServices(allServices);

            var connectionInfo = this.RetrieveConnectionInfo();

            lock (this.syncRoot)
            {
                var instanceKey = new InstanceKey(singletonService.Value);

                foreach (var serviceType in publishedServices.ServiceTypes)
                {
                    if (this.singletonServiceTypeToServiceImpl.ContainsKey(serviceType) || this.singletonServiceTypeToFactory.ContainsKey(serviceType))
                    {
                        throw new RpcDefinitionException($"A singleton for the type '{serviceType}' has already been published.");
                    }
                }

                this.singletonTypeToPublishedServices.Add(typeof(TService), publishedServices);
                var publishedInstance = new PublishedInstance(singletonService);
                foreach (var serviceType in publishedServices.ServiceTypes)
                {
                    this.singletonServiceTypeToServiceImpl.Add(serviceType, publishedInstance);
                }
            }

            return(OwnedObject.Create(new RpcSingletonRef <TService>(
                                          connectionInfo),
                                      () => this.UnpublishSingletonAsync <TService>()));
        }
Exemple #13
0
 private void FailOwnership(IOwned obj)
 {
     throw new ArgumentException(obj + " is not owned by this Emit, and thus cannot be used");
 }
 public bool Authorize(IOwned entity, UUID id)
 {
     if (id.Equals(_ownerID)) {
         //Reset the timeout every time the user makes a change
         _updated = true;
         JM726.Lib.Static.Util.Wake(this);
         return true;
     }
     return false;
 }
 public bool Authorize(IOwned entity, OpenMetaverse.UUID id)
 {
     return _parent._ownerID.Equals(UUID.Zero) || id.Equals(_parent._ownerID);
 }
 public bool Authorize(IOwned entity, UUID id)
 {
     return true;
 }
Exemple #17
0
 public bool Authorize(IOwned entity, OpenMetaverse.UUID id)
 {
     return(_parent._ownerID.Equals(UUID.Zero) || id.Equals(_parent._ownerID));
 }
 public bool Authorize(IOwned entity, UUID id)
 {
     return _god.Equals(id);
 }
 public bool Authorize(IOwned entity, UUID id)
 {
     return(entity.Owner == id);
 }
Exemple #20
0
 public bool Authorize(IOwned entity, UUID id)
 {
     return(true);
 }
 public ServiceProviderServiceImpl(IRpcServicePublisher publisher)
 {
     this.simpleServiceScope = publisher.PublishInstance <ISimpleService>(new TestSimpleServiceImpl());
 }
 public bool Authorize(IOwned entity, UUID id)
 {
     return entity.Owner == id;
 }
Exemple #23
0
 public static IOwned <RpcObjectRef <TService> > PublishInstance <TService>(this IRpcServer server, IOwned <TService> serviceInstance) where TService : class
 {
     if (server is null)
     {
         throw new ArgumentNullException(nameof(server));
     }
     return(server.ServicePublisher.PublishInstance(serviceInstance));
 }
Exemple #24
0
 public bool SameOwner(IOwned other)
 {
     return(ReferenceEquals(Owner.Value, other));
 }
Exemple #25
0
 public bool SameOwner(IOwned other)
 => ReferenceEquals(Owner.Value, other.Owner.Value);
Exemple #26
0
 public static bool Owns(this ClaimsPrincipal user, IOwned obj)
 {
     return(user.Identity.Name == obj.OwnerLogin);
 }
 internal static T Resolve <T>(ref IOwned <T> factory) => (factory = factory ?? container.Resolve <Func <IOwned <T> > >()()).Value;
Exemple #28
0
 public bool Authorize(IOwned entity, UUID id)
 {
     return(_god.Equals(id));
 }