Example #1
0
 private static async Task CallOneObjectFromAnother(ILogger logger)
 {
     var firstRealObject = new RealObject(logger);
     var secondRealObject = new RealObject(logger);
     Console.WriteLine($"Method calls between {firstRealObject.GetObjectRef()} and {secondRealObject.GetObjectRef()}");
     await firstRealObject.Send(secondRealObject, new PingMessage());
     Console.WriteLine();
 }
Example #2
0
 public async Task PingObjectAndRecievePong_missspell1()
 {
     var logger = new FakeTraceLogger();
     logger.FirstCall(str => str.ToString().Contains("call Ping"));
     var firstRealObject = new RealObject(logger);
     var secondRealObject = new RealObject(logger);
     await firstRealObject.Send(secondRealObject, new PingMessage());
 }
Example #3
0
 private static async Task UseMixinsToCreateFinalObject(ILogger logger)
 {
     Console.WriteLine("Create object using mixins and call methods");
     var obj = new RealObject();
     obj.Mixin<SquareDrawerObject>();
     obj.Mixin<TreeDrawerObject>();
     var deadletter = new DeadLetterObject(logger);
     await deadletter.Send(obj, new DrawTreeMessage(3));
     await deadletter.Send(obj, new DrawSquareMessage(3));
 }
Example #4
0
 public async Task PingObjectAndRecievePong()
 {
     var logger = new FakeTraceLogger();
     logger
         .FirstCall(str => str.ToString().Contains("calls Ping"))
         .AndThenCall(str => str.ToString().Contains("Received Ping"))
         .AndThenCall(str => str.ToString().Contains("calls Pong"))
         .AndThenCall(str => str.ToString().Contains("Received Pong"));
     var firstRealObject = new RealObject(logger);
     var secondRealObject = new RealObject(logger);
     await firstRealObject.Send(secondRealObject, new PingMessage());
     Assert.AreEqual(4, logger.NumberOfCalls);
 }
Example #5
0
        protected override object GetMissingPropertyValue(string jsPropertyName)
        {
            if (jsPropertyName.StartsWith("get_"))
            {
                var prop = jsPropertyName.Substring(4);
                if (RealObject.HasProperty(prop))
                {
                    return(LazyDefineMethod <string>(jsPropertyName, adapter =>
                    {
                        return adapter.GetPropertyValue(prop);
                    }));
                }
            }

            return(base.GetMissingPropertyValue(jsPropertyName));
        }
Example #6
0
        public virtual void OnEnterFree()
        {
            EntityComponent entityComponent = RealObject.GetComponent <EntityComponent>();

            if (entityComponent == null)
            {
                return;
            }
            Vector2 serverPos       = new Vector2(GOSyncInfo.BeginPos.x, GOSyncInfo.BeginPos.z);
            Vector2 objPos          = new Vector2(RealObject.transform.position.x, RealObject.transform.position.z);
            float   distToServerPos = Vector2.Distance(serverPos, objPos);

            if (distToServerPos > 10)
            {
                RealObject.transform.position = GOSyncInfo.BeginPos;
                entityComponent.PlayerFreeAnimation();
                RealObject.transform.rotation = Quaternion.LookRotation(EntityFSMDirection);
            }
        }
Example #7
0
        private static CallbackResult OnPickupRequest(byte[] data, CallbackResult prevResult)
        {
            lock (syncRoot) {
                switch (CurrentState)
                {
                case State.Ready:
                    break;

                case State.ClientDroppedItem:
                case State.MoveItem:
                    Core.SendToClient(PacketBuilder.PickupItemFailed(6));
                    UO.Print("Cannot pick up item now.");
                    return(CallbackResult.Eat);

                default:
                    Reset();
                    break;
                }

                Debug.Assert(CurrentState == State.Ready, "CurrentState is not Ready. Internal error.");

                PickedUpItem = ByteConverter.BigEndian.ToUInt32(data, 1);

                RealObject obj = World.FindRealObject(PickedUpItem);
                if (obj != null && obj.Name != null && obj.Name.Length > 0)
                {
                    pickedUpItemName = String.Format("\"{0}\"", obj.Name);
                }
                else
                {
                    pickedUpItemName = String.Format("0x{0:X8}", PickedUpItem);
                }

                CurrentState = State.ClientPickedUpItem;

                return(CallbackResult.Normal);
            }
        }
Example #8
0
        public override void OnExecuteMove()
        {
            EntityComponent entityComponent = RealObject.GetComponent <EntityComponent>();
            Quaternion      destQuaternion  = Quaternion.LookRotation(EntityFSMDirection);
            Quaternion      midQuater       = Quaternion.Lerp(entityComponent.transform.rotation, destQuaternion, 10 * Time.deltaTime);

            entityComponent.transform.rotation = midQuater;

            float timeSpan = Time.realtimeSinceStartup - GOSyncInfo.BeginTime;
            float moveDist = timeSpan * GOSyncInfo.Speed;

            GOSyncInfo.SyncPos = GOSyncInfo.BeginPos + GOSyncInfo.Dir * moveDist;
            entityComponent.PlayerRunAnimation();

            Vector3 serverPos2d = new Vector3(GOSyncInfo.SyncPos.x, 60, GOSyncInfo.SyncPos.z);
            Vector3 entityPos2d = new Vector3(entityComponent.transform.position.x, 60, entityComponent.transform.position.z);

            Vector3 syncDir = serverPos2d - entityPos2d;

            syncDir.Normalize();
            float distToServerPos = Vector3.Distance(serverPos2d, entityPos2d);

            if (distToServerPos > 5)
            {
                entityComponent.transform.position = GOSyncInfo.SyncPos;
                OnCameraUpdatePosition();
                return;
            }
            Vector3             pos        = entityPos2d + syncDir * EntityFSMMoveSpeed * Time.deltaTime;
            CharacterController controller = RealObject.GetComponent <CharacterController>();

            controller.Move(syncDir * EntityFSMMoveSpeed * Time.deltaTime);

            entityComponent.transform.position = new Vector3(entityComponent.transform.position.x, 60.0f, entityComponent.transform.position.z);
            OnCameraUpdatePosition();
        }
Example #9
0
        public override void OnExecuteFree()
        {
            EntityComponent entityComponent = RealObject.GetComponent <EntityComponent>();
            Vector3         synPos          = new Vector3(GOSyncInfo.SyncPos.x, 60, GOSyncInfo.SyncPos.z);
            Vector3         realPos         = new Vector3(RealObject.transform.position.x, 60, RealObject.transform.position.z);
            float           distToServerPos = Vector3.Distance(synPos, realPos);

            if (distToServerPos < 0.5f)
            {
            }
            else if (distToServerPos > 5)
            {
                RealObject.transform.position = GOSyncInfo.BeginPos;
            }
            else
            {
                Vector3 syncDir = synPos - realPos;
                syncDir.Normalize();
                entityComponent.GetComponent <CharacterController>().Move(syncDir * 2 * Time.deltaTime);
            }
            entityComponent.PlayerFreeAnimation();
            OnCameraUpdatePosition();
            TurnAngle();
        }
Example #10
0
        static void Main(string[] args)
        {
            Console.Title           = "Memento";
            Console.BackgroundColor = ConsoleColor.Gray;
            Console.ForegroundColor = ConsoleColor.Black;

            RealObject ro = new RealObject();
            Caretaker  cr = new Caretaker(ro);

            ro.State = 44;
            cr.Save();

            ro.State = 99;
            cr.Save();

            ro.State = 123445;

            cr.Undo();
            cr.Undo();

            Console.WriteLine($"After two undos state is '{ro.State}'");

            Console.Read();
        }
Example #11
0
 public virtual int CountOf(TGroup group) => RealObject.OfType <TGroup>().Count();
Example #12
0
 public virtual bool ContainsKey(TGroup group) => RealObject.ContainsKey(group);
Example #13
0
 public virtual void Clear(TGroup group)
 {
     RealObject.Clear(group);
 }
        public object CreateSecurityObject(IModel model, ISecurityObjectRepository securityObjectRepository)
        {
            Type targetType = RealObject.GetType();

            SecurityObject = Activator.CreateInstance(RealObject.GetType());
            IEntityType entityType = model.FindEntityType(targetType);
            IEnumerable <PropertyInfo> propertiesInfo = targetType.GetRuntimeProperties();
            IEnumerable <INavigation>  navigations    = entityType.GetNavigations();

            foreach (PropertyInfo propertyInfo in propertiesInfo)
            {
                object defaultValue = propertyInfo.GetValue(SecurityObject);
                defaultValueDictionary[propertyInfo.Name] = defaultValue;
                if (this.IsPropertyBlocked(propertyInfo.Name))
                {
                    if (navigations.Any(p => p.Name == propertyInfo.Name))
                    {
                        INavigation navigation = navigations.First(p => p.Name == propertyInfo.Name);
                        if (navigation.IsCollection())
                        {
                            if (propertyInfo.SetMethod != null)
                            {
                                propertyInfo.SetValue(SecurityObject, null);
                            }
                        }
                    }
                    continue;
                }
                if (navigations.Any(p => p.Name == propertyInfo.Name))
                {
                    INavigation navigation = navigations.First(p => p.Name == propertyInfo.Name);
                    if (navigation.IsCollection())
                    {
                        IClrCollectionAccessor collectionAccessor         = navigation.GetCollectionAccessor();
                        IEnumerable            objectRealListProperty     = (IEnumerable)propertyInfo.GetValue(RealObject);
                        IEnumerable            objectSecurityListProperty = (IEnumerable)propertyInfo.GetValue(SecurityObject);
                        List <object>          denyObject;
                        BlockedObjectsInListProperty.TryGetValue(propertyInfo.Name, out denyObject);
                        if (objectRealListProperty != null)
                        {
                            foreach (object objInList in objectRealListProperty)
                            {
                                if (denyObject != null && denyObject.Contains(objInList))
                                {
                                    continue;
                                }
                                object objectToAdd;
                                SecurityObjectBuilder metadata = securityObjectRepository.GetObjectMetaData(objInList);
                                if (metadata != null)
                                {
                                    if (metadata.SecurityObject != null)
                                    {
                                        objectToAdd = metadata.SecurityObject;
                                    }
                                    else
                                    {
                                        objectToAdd = metadata.CreateSecurityObject(model, securityObjectRepository);
                                    }
                                }
                                else
                                {
                                    throw new Exception();
                                }
                                collectionAccessor.Add(SecurityObject, objectToAdd);
                            }
                        }
                    }
                    else
                    {
                        object realValue = propertyInfo.GetValue(RealObject);
                        SecurityObjectBuilder metadata = securityObjectRepository.GetObjectMetaData(realValue);
                        if (metadata != null && realValue != null)
                        {
                            if (metadata.SecurityObject == null)
                            {
                                metadata.SecurityObject = metadata.CreateSecurityObject(model, securityObjectRepository);
                            }
                            if (propertyInfo.SetMethod != null)
                            {
                                propertyInfo.SetValue(SecurityObject, metadata.SecurityObject);
                            }
                        }
                        else
                        {
                            if (propertyInfo.SetMethod != null)
                            {
                                propertyInfo.SetValue(SecurityObject, realValue);
                            }
                        }
                    }
                }
                else
                {
                    if (propertyInfo.SetMethod != null)
                    {
                        object realValue = propertyInfo.GetValue(RealObject);
                        propertyInfo.SetValue(SecurityObject, realValue);
                    }
                }
            }
            foreach (PropertyInfo propertyInfo in propertiesInfo)
            {
                object originalValue = propertyInfo.GetValue(SecurityObject);
                originalValueSecurityObjectDictionary.Add(propertyInfo.Name, originalValue);
            }

            if (SecurityObject is ISecurityEntity)
            {
                ISecurityEntity securityEntity = (ISecurityEntity)SecurityObject;

                List <string> blockedMembers = new List <string>();
                blockedMembers.AddRange(BlockedProperties);
                blockedMembers.AddRange(BlockedNavigationProperties);

                securityEntity.BlockedMembers = blockedMembers;
            }

            return(SecurityObject);
        }
Example #15
0
 private static Task FireAndForget(ILogger logger, DeadLetterObject deadLetter)
 {
     Console.WriteLine("Sending async message to deadletter");
     var firstRealObject = new RealObject(logger);
     return firstRealObject.Send(deadLetter, new PingMessage());
 }
Example #16
0
 public virtual IEnumerator <TNew> GetEnumerator() => RealObject
 .OfType <TNew>()
 .GetEnumerator();
Example #17
0
 public virtual bool Contains(TNew item) => RealObject.Contains(item);
 public virtual int CountOf(TGroup group)
 {
     return(RealObject.OfType <TGroup>().Count());
 }
 public virtual bool ContainsKey(TGroup group)
 {
     return(RealObject.ContainsKey(group));
 }
 public virtual bool Remove(TGroup group)
 {
     return(RealObject.Remove(group));
 }
 IEnumerator IEnumerable.GetEnumerator()
 {
     return(RealObject
            .OfType <TNew>()
            .GetEnumerator());
 }
 public virtual IEnumerator <TNew> GetEnumerator()
 {
     return(RealObject
            .OfType <TNew>()
            .GetEnumerator());
 }
 public virtual bool Remove(TNew item)
 {
     return(RealObject.Remove(item));
 }
Example #24
0
 public virtual IEnumerable <TNew> AllOf(TGroup group) => RealObject
 .AllOf(group)
 .OfType <TNew>()
 .Where(_predicate);
Example #25
0
 public virtual void Add(TNew item)
 {
     RealObject.Add(item);
 }
 public virtual bool Contains(TNew item)
 {
     return(RealObject.Contains(item));
 }
Example #27
0
 public virtual bool Remove(TNew item) => RealObject.Remove(item);
Example #28
0
 public string GetInstanceId(string id)
 {
     return(RealObject.GetInstanceId(id));
 }
Example #29
0
 IEnumerator IEnumerable.GetEnumerator() => RealObject
 .OfType <TNew>()
 .GetEnumerator();
        public virtual string Get(string name)
        {
            var parameter = RealObject.FirstOrDefault(o => string.Equals(o.Name, name, StringComparison.Ordinal));

            return(parameter?.Value);
        }
        public virtual string Get(string name)
        {
            var parameter = RealObject.FirstOrDefault(o => o.Name == name);

            return(parameter?.Value);
        }
Example #32
0
 public Proxy()
 {
     RealObject = new RealObject();
 }
 public virtual void Add(string name, string value)
 {
     RealObject.Add(new CalendarParameter(name, value));
 }
Example #34
0
 public virtual bool Remove(TGroup group) => RealObject.Remove(group);
Example #35
0
 public Task Call(RealObject sender, object message = null)
 {
     return _action(sender);
 }
Example #36
0
 public Caretaker(RealObject ro)
 {
     RO      = ro;
     history = new List <Memento>();
 }