Exemple #1
0
 public static IFile CreateFile(this IFolder folder,
                                AbsoluteFilePath path,
                                string utf8Contents,
                                CollisionStrategy collisionStrategy = CollisionStrategy.FailIfExists)
 {
     return(CreateFile(folder, path, Encoding.UTF8.GetBytes(utf8Contents), collisionStrategy));
 }
Exemple #2
0
        public bool CanReplyWith(Type requestType, Type responseType, CollisionStrategy collisionStrategy)
        {
            if (!TypesMatch(RequestType, requestType))
            {
                return(false);
            }

            if (TypesMatch(ResponseType, responseType))
            {
                return(true);
            }

            // The response type may be an awaitable!
            // (Task<TResponse>, ValueTask<TResponse>, ...)

            if (!ResponseType.IsAwaitableWithResult(out var awaitResponseType))
            {
                return(false);
            }

            if (TypesMatch(awaitResponseType, responseType))
            {
                return(true);
            }

            return(false);
        }
 public static IFile CreateFile(this IFileSystem fileSystem,
                                AbsoluteFilePath path,
                                string utf8Contents,
                                CollisionStrategy collisionStrategy = CollisionStrategy.FailIfExists)
 {
     return(fileSystem.CreateFolder(path.Folder)
            .CreateFile(path, utf8Contents, collisionStrategy));
 }
 public InstanceRecipientInvoker(
     TypeInspector inspector,
     IRecipientFactory factory,
     CollisionStrategy collisionStrategy)
 {
     _inspector         = inspector;
     _factory           = factory;
     _collisionStrategy = collisionStrategy;
 }
Exemple #5
0
 protected InstanceRecipient(
     object instance,
     IRecipientDescriptor descriptor,
     IRecipientInvoker invoker,
     string?name,
     CollisionStrategy collisionStrategy)
     : base(instance.GetType(), descriptor, invoker, name, Lifetime.Singleton, collisionStrategy)
 {
     _instance = instance;
 }
Exemple #6
0
        public static IFile Move(this IFile file, RelativeFilePath relativePath, CollisionStrategy collisionStrategy = CollisionStrategy.FailIfExists)
        {
            if (relativePath == null)
            {
                throw new ArgumentNullException("relativePath");
            }
            AbsoluteFilePath newPath = file.Path + relativePath;

            return(file.Move(newPath, collisionStrategy));
        }
 protected TypeRecipient(
     Type type,
     IRecipientDescriptor descriptor,
     IRecipientInvoker invoker,
     string?name,
     Lifetime lifetime,
     CollisionStrategy collisionStrategy)
     : base(descriptor, invoker, name, lifetime, collisionStrategy)
 {
     Type = type;
 }
Exemple #8
0
        public static IFile CreateFile(this IFolder folder,
                                       AbsoluteFilePath path,
                                       byte[] contents,
                                       CollisionStrategy collisionStrategy = CollisionStrategy.FailIfExists)
        {
            var file = folder.CreateFile(path, collisionStrategy);

            using (var writer = file.OpenToWrite()) {
                writer.Write(contents, 0, contents.Length);
            }
            return(file);
        }
 public void Deconstruct(
     out Guid id,
     out string?name,
     out Type?type,
     out Lifetime lifetime,
     out CollisionStrategy collisionStrategy)
 {
     id                = Id;
     name              = Name;
     type              = Type;
     lifetime          = Lifetime;
     collisionStrategy = CollisionStrategy;
 }
 internal RecipientDescription(
     Guid id,
     string?name,
     Type?type,
     Lifetime lifetime,
     CollisionStrategy collisionStrategy)
 {
     Id                = id;
     Name              = name;
     Type              = type;
     Lifetime          = lifetime;
     CollisionStrategy = collisionStrategy;
 }
        public Recipient(
            IRecipientDescriptor descriptor,
            IRecipientInvoker invoker,
            string?name,
            Lifetime lifetime,
            CollisionStrategy collisionStrategy)
        {
            _descriptor = descriptor;
            _invoker    = invoker;

            Name              = name;
            Lifetime          = lifetime;
            CollisionStrategy = collisionStrategy;
        }
        public static TypeRecipient Create <TRecipient>(
            TypeInspectorRegistry registry,
            Func <TRecipient> factoryMethod,
            string?name,
            Lifetime lifetime,
            CollisionStrategy collisionStrategy)
        {
            if (registry is null)
            {
                throw new ArgumentNullException(nameof(registry));
            }

            if (factoryMethod is null)
            {
                throw new ArgumentNullException(nameof(factoryMethod));
            }

            if (!lifetime.IsValid())
            {
                throw new ArgumentException($"Invalid {nameof(lifetime)} value: {lifetime}");
            }

            if (!collisionStrategy.IsValid())
            {
                throw new ArgumentException($"Invalid {nameof(collisionStrategy)} value: {collisionStrategy}");
            }

            var inspector = registry.For <TRecipient>();

            IRecipientFactory factory = new RecipientFactory(() => factoryMethod() !);

            if (lifetime != Lifetime.Transient)
            {
                factory = new SingletonRecipientFactory(factory);
            }

            return(new TypeRecipient(
                       typeof(TRecipient),
                       new TypeRecipientDescriptor(inspector),
                       new InstanceRecipientInvoker(inspector, factory, collisionStrategy),
                       name,
                       lifetime,
                       collisionStrategy));
        }
Exemple #13
0
        public static InstanceRecipient Create(
            TypeInspectorRegistry registry,
            object instance,
            string?name,
            CollisionStrategy collisionStrategy)
        {
            if (registry is null)
            {
                throw new ArgumentNullException(nameof(registry));
            }

            if (instance is null)
            {
                throw new ArgumentNullException(nameof(instance));
            }

            if (!collisionStrategy.IsValid())
            {
                throw new ArgumentException($"Invalid {nameof(collisionStrategy)} value: {collisionStrategy}");
            }

            var inspector  = registry.For(instance.GetType());
            var descriptor = new TypeRecipientDescriptor(inspector);

            var invoker = new InstanceRecipientInvoker(
                inspector,
                new SingletonRecipientFactory(instance),
                collisionStrategy);

            return(new InstanceRecipient(
                       instance,
                       descriptor,
                       invoker,
                       name,
                       collisionStrategy));
        }
Exemple #14
0
 public void HandleCollision(CollisionStrategy collisionStrategy, string elementId)
 {
     _state.Handle(collisionStrategy, this, elementId);
     //await collisionStrategy.ActionAsync(this, elementId);
 }
Exemple #15
0
 public abstract void Handle(CollisionStrategy collisionStrategy, PlayerObject playerObject, string elementId);
Exemple #16
0
        public bool CanAccept(Type requestType, CollisionStrategy collisionStrategy)
        {
            var requestTypeMatches = TypesMatch(RequestType, requestType);

            return(requestTypeMatches);
        }
Exemple #17
0
 public IFile CreateFile(string name, CollisionStrategy collisionStrategy = CollisionStrategy.FailIfExists)
 {
     throw new NotImplementedException("RamFolder.CreateFile");
 }
Exemple #18
0
 public IFile Rename(string newFilenameWithExtension, CollisionStrategy collisionStrategy = CollisionStrategy.FailIfExists)
 {
     //move?
     throw new NotImplementedException("SpotFile.Rename");
 }
Exemple #19
0
 public IFile Move(AbsoluteFilePath absolutePath, CollisionStrategy collisionStrategy = CollisionStrategy.FailIfExists)
 {
     //File.Move();
     throw new NotImplementedException("SpotFile.Move");
 }
 public CollisionSolver(CollisionStrategy strategy)
 {
     this.strategy = strategy;
 }
Exemple #21
0
 public override async void Handle(CollisionStrategy collisionStrategy, PlayerObject playerObject, string elementId)
 {
     StartProtectedTimer(playerObject);
     await collisionStrategy.ActionAsync(playerObject, elementId);
 }
Exemple #22
0
 public CollisionSolver(CollisionStrategy strategy)
 {
     this.strategy = strategy;
 }
Exemple #23
0
        public bool CanAccept(Type requestType, CollisionStrategy collisionStrategy)
        {
            var accepts = _inspector.HasMethodsAccepting(requestType, collisionStrategy);

            return(accepts);
        }
Exemple #24
0
        public bool CanReplyWith(Type requestType, Type responseType, CollisionStrategy collisionStrategy)
        {
            var repliesWith = _inspector.HasMethodsReturning(requestType, responseType, collisionStrategy);

            return(repliesWith);
        }
Exemple #25
0
        public override async void Handle(CollisionStrategy collisionStrategy, PlayerObject playerObject, string elementId)
        {
            await collisionStrategy.ActionAsync(playerObject, elementId);

            goNext(playerObject);
        }
 public override void Handle(CollisionStrategy collisionStrategy, PlayerObject playerObject, string elementId)
 {
 }