public static async Task <Grain> New(Type concreteType, AbstractKey key, IGrainRuntime grainRuntime, IServiceProvider services, StorageCell storage, FakeSerializer serializer)
        {
            var creator = new GrainCreator(grainRuntime, services);

            var stateType = GetStateType(concreteType);

            var grain = stateType != null
                            ? creator.CreateGrainInstance(concreteType, key, stateType, new DummyStorageProvider()) //IStorage will be hackily assigned below      // new StorageProviderAdaptor(key, store))
                            : creator.CreateGrainInstance(concreteType, key);

            if (stateType != null)
            {
                var fnStateExtractor = _dStateExtractors.GetOrAdd(concreteType, t => BuildStateExtractor(t));
                var fnStorageAssign  = _dStorageAssigners.GetOrAdd(concreteType, t => BuildStorageAssigner(t));

                var grainState = fnStateExtractor(grain);

                var bridge = new GrainStorageBridge(storage, serializer, grainState);
                fnStorageAssign(grain, bridge);

                await bridge.ReadStateAsync();
            }

            return(grain);
        }
Beispiel #2
0
 public void Init(InputMappingController controller, AbstractKey key)
 {
     this.controller = controller;
     this.key        = key;
     UpdateText();
     RefreshColor();
 }
Beispiel #3
0
 public void Init(InputMappingController controller, string text, AbstractKey key)
 {
     this.controller = controller;
     label.text      = text;
     this.key        = key;
     RefreshColor();
 }
Beispiel #4
0
        protected Task <TResult> Dispatch <TResult>(MethodInfo method, object[] args)
        {
            var argData = new byte[args.Length][];

            for (int i = 0; i < args.Length; i++)
            {
                var arg = args[i];

                //BELOW SHOULD BE IN GENERAL SERIALIZER, RATHER THAN AD-HOC HERE !!!!!!!!!!!!!!!
                //so serializer will be sensitive to grains - seems reasonable...

                //proxify before passing to grain method
                if (arg is Grain && !(arg is GrainProxy))     //nb GrainProxy derives from Grain these days, oddly
                {
                    var argKey = ((IGrain)arg).GetGrainKey(); //NEED TO BURROW IN TO GRAINRUNTIME - WHICH WILL BE GRAINHARNESS

                    var param = method.GetParameters()[i];

                    var grainKey = new AbstractKey(param.ParameterType, argKey.Id);

                    arg = Proxify(Fixture, grainKey);
                }

                argData[i] = Fixture.Serializer.Serialize(arg);
            }

            return(Fixture.Dispatcher.Dispatch(Key, a => a.Invoke <TResult>(method, argData)));
        }
Beispiel #5
0
        public Placement Place(AbstractKey key)
        {
            var concreteType = _typeMapper(key.AbstractType);

            //var concreteKey = new ConcreteKey(concreteType, key.Id);
            return(new Placement(key, concreteType));
        }
Beispiel #6
0
 public bool GetKey(AbstractKey key)
 {
     if (!IsEnabled(key))
     {
         return(false);
     }
     return(keyStatus[key]);
 }
Beispiel #7
0
        public static GrainProxy Proxify(Fixture fx, AbstractKey key)
        {
            var proxifier = _dProxifiers.GetOrAdd(
                key.AbstractType,
                t => BuildProxifier(t));

            return(proxifier(fx, key));
        }
Beispiel #8
0
 public bool GetKeyUp(AbstractKey key)
 {
     if (!IsEnabled(key))
     {
         return(false);
     }
     return(keyStatusLastFrame[key] && !keyStatus[key]);
 }
Beispiel #9
0
        public Task <TResult> Dispatch <TResult>(AbstractKey key, Func <IGrainContext, Task <TResult> > fn)
        {
            var placement = _placer(key);

            // one too many dispatchers, surely
            //
            //

            return(_innerDispatcher.Dispatch(placement, fn));
        }
Beispiel #10
0
        public void GrainKey_ObtainableFromGrainProxy()
        {
            var key = new AbstractKey(typeof(ISomeGrain), Guid.NewGuid());

            var proxy = (ISomeGrain)GrainProxy.Proxify(_fx, key);

            var foundKey = proxy.GetGrainKey();

            Assert.That(foundKey, Is.EqualTo(key));
        }
Beispiel #11
0
        public void AbstractKey_ToString_RoundTrip()
        {
            var original = new AbstractKey(typeof(ISomeGrain), Guid.NewGuid());

            var stringified = AbstractKey.Stringify(original);

            var returned = AbstractKey.Parse(stringified);

            Assert.That(returned, Is.EqualTo(original));
        }
Beispiel #12
0
        public Reminder(Fixture fx, AbstractKey key, string name)   //BUT!!! don't reminders function against abstract type -
        {
            _fx   = fx;                                             //otherwise, how can we upgrade concrete types without ruining reminders???
            _key  = key;
            _name = name;

            _status            = ReminderState.Normal;
            _cancelTokenSource = new CancellationTokenSource();

            _tasks = new Queue <Task>();
        }
Beispiel #13
0
        public bool IsEnabled(AbstractKey key)
        {
#if !UNITY_EDITOR
            if (keyIsEditor[key])
            {
                return(false);
            }
#endif

            return(keyEnabled[key]);
        }
        public TGrainInterface GetGrain <TGrainInterface>(Guid primaryKey, string grainClassNamePrefix = null)
            where TGrainInterface : IGrainWithGuidKey
        {
            Require.That(grainClassNamePrefix == null);

            var tAbstract = typeof(TGrainInterface);

            var key = new AbstractKey(tAbstract, primaryKey);

            var proxy = _proxifier(key);

            return((TGrainInterface)proxy);
        }
        public void SetUp()
        {
            _key       = new AbstractKey(typeof(ITestGrain), Guid.NewGuid());
            _placement = new Placement(_key, typeof(TestGrain));

            _innerDisp = Substitute.For <IPlacementDispatcher>();

            _placer = Substitute.For <Func <AbstractKey, Placement> >();
            _placer(Arg.Is(_key)).Returns(_placement);

            _disp = new Dispatcher(_placer, _innerDisp);

            _fn = a => Task.FromResult(true);
        }
Beispiel #16
0
        public async Task GrainKey_ObtainableFromConcreteGrain()
        {
            var key = new AbstractKey(typeof(ISomeGrain), Guid.NewGuid());

            var grain = await GrainConstructor.New(
                typeof(SomeGrain),
                key,
                Substitute.For <IGrainRuntime>(),
                Substitute.For <IServiceProvider>(),
                new StorageCell(null),
                null
                );

            var foundKey = grain.GetGrainKey();

            Assert.That(foundKey, Is.EqualTo(key));
        }
Beispiel #17
0
 protected GrainProxy(Fixture fx, AbstractKey key)
 {
     Fixture = fx;
     Key     = key;
 }
Beispiel #18
0
 private static string AbstractKeyDisplayName(AbstractKey key) =>
 I18n.__($"config.key.{Enum.GetName(typeof(AbstractKey), key)}");
 public Placement(AbstractKey key, Type type)
 {
     GrainKey     = key;
     ConcreteType = type;
 }
Beispiel #20
0
 public bool IsEnabled(AbstractKey key)
 {
     return(keyEnabled[key]);
 }
Beispiel #21
0
 public void SetEnable(AbstractKey key, bool value)
 {
     keyEnabled[key] = value;
 }
Beispiel #22
0
 public MeasureAttributes(bool isVisible, AbstractClef clef, AbstractKey key, AbstractTime time) : base(isVisible, clef, key, time)
 {
 }
Beispiel #23
0
 public static Task Dispatch(this IDispatcher disp, AbstractKey key, Func <IGrainContext, Task> fn)
 => disp.Dispatch(key, async a => { await fn(a); return(default(VoidType)); });
Beispiel #24
0
 public List <CompoundKey> GetDefaultCompoundKeys(AbstractKey key)
 {
     return(defaultKeyboard.Data[key].Select(ck => new CompoundKey(ck)).ToList());
 }
Beispiel #25
0
 public void SetEnable(AbstractKey key, bool value)
 {
     keyEnabled[key]         = value;
     keyDownWhenEnabled[key] = false;
     keyDownToBeCleared[key] = false;
 }