Ejemplo n.º 1
0
        /// <summary>
        /// Registers an object to the simulation.
        /// This method should only be called during initilization of the match
        /// to register players and scene objects, anything else should use the
        /// SpawnObject method.
        /// </summary>
        /// <param name="simObject"></param>
        public void RegisterObject(ISimObject simObject)
        {
            int spawnID = uRollbackSession.URollbackWorld.AddEntity(simObject.SaveData());

            simObject.SimID = spawnID;
            simObjects.Add(simObject);
        }
Ejemplo n.º 2
0
        private static string CreateCommand(ISimObject simObject)
        {
            StringBuilder sb = new StringBuilder();

            sb.Append("create ");

            Graph graph = simObject as Graph;

            // Go through relations
            for (int i = 0; i < graph.Relations.Count; i++)
            {
                string s = AnalyseRelation(graph.Relations.ElementAt(i));
                sb.Append(s);
                sb.Append(",");
            }
            sb = sb.Remove(sb.Length - 1, 1);
            // Go through nodes
            for (int i = 0; i < graph.Nodes.Count; i++)
            {
                string s = AnalyseNodeProperties(graph.Nodes.ElementAt(i));
                sb.Append(s);
                //sb.Append(",");
            }

            return(sb.ToString().Trim(','));
        }
Ejemplo n.º 3
0
        public static string CallScriptFunction(string pFunctionNamespace, string pFunctionName, object[] args,
                                                out bool found)
        {
            if (pFunctionNamespace != null)
            {
                ISimObject obj  = SimDictionary.Find(pFunctionNamespace);
                Type       type = GetObjectType(null, pFunctionNamespace, obj);

                if (type == null)
                {
                    found = false;
                    return(null);
                }

                return(CallNamespaceMethod(type, obj, pFunctionName, args, out found));
            }

            if (!FunctionDictionary.ContainsKey(pFunctionName))
            {
                found = false;
                return(null);
            }

            found = true;
            MethodInfo methodInfo = FunctionDictionary[pFunctionName];

            return(InvokeMethod(methodInfo, null, args, out found));
        }
Ejemplo n.º 4
0
 public DynamicFieldVector(ISimObject pSimObject, string pFieldName, int pCount, GetterFunction pGetterFunction, SetterFunction pSetterFunction)
 {
     _OwnerObject    = pSimObject;
     _FieldName      = pFieldName;
     _Count          = pCount;
     _GetterFunction = pGetterFunction;
     _SetterFunction = pSetterFunction;
 }
Ejemplo n.º 5
0
 public void SetPointerFromObject(ISimObject pObj)
 {
     if (!SimDictionary.Contains(pObj))
     {
         SimDictionary.RegisterObject(pObj);
     }
     ObjectPtr = pObj.ObjectPtr;
 }
Ejemplo n.º 6
0
        public void Update(ISimObject simObject)
        {
            var @object = Get(a => a.Equals(simObject)) ??
                          throw new OperationCanceledException($"{simObject} could not be found in the current repository",
                                                               new CancellationToken(true));

            Remove(@object);
            Add(simObject);
        }
Ejemplo n.º 7
0
        private static string InvokeMethod(MethodInfo callbackMethod, ISimObject obj, object[] args, out bool found)
        {
            if (obj != null &&
                !callbackMethod.DeclaringType.GetCustomAttributes <ConsoleClassAttribute>().Any())
            {
                found = false;
                return(null);
            }

            ParameterInfo[] parameterInfos = callbackMethod.GetParameters();
            object[]        _args          = new object[parameterInfos.Length];
            for (int i = 0; i < _args.Length; i++)
            {
                if (parameterInfos[i].GetCustomAttributes(typeof(ParamArrayAttribute), false).Length > 0)
                {
                    string[] parms = new string[Math.Max(args.Length - i, 0)];
                    for (int j = 0; j < args.Length - i; j++)
                    {
                        parms[j] = (string)args[i + j];
                    }

                    _args[i] = parms;
                    break;
                }

                if (i < args.Length)
                {
                    _args[i] = ConvertArgFromString(parameterInfos[i].ParameterType, (string)args[i]);
                }
                else if (parameterInfos[i].HasDefaultValue)
                {
                    _args[i] = parameterInfos[i].DefaultValue;
                }
                else
                {
                    throw new ArgumentException("Not enough arguments provided");
                }
            }

            found = true;

            if (callbackMethod.ReturnType == typeof(bool))
            {
                return((bool)callbackMethod.Invoke(obj, _args) ? "1" : "0");
            }
            if (callbackMethod.ReturnType == typeof(string))
            {
                return((string)callbackMethod.Invoke(obj, _args));
            }
            else if (callbackMethod.ReturnType != typeof(void))
            {
                return(callbackMethod.Invoke(obj, _args).ToString());
            }
            callbackMethod.Invoke(obj, _args);
            return(null);
        }
Ejemplo n.º 8
0
        public static IntPtr FindDataBlockPtrByName(string name)
        {
            ISimObject obj = SimDictionary.Find <ISimObject>(name);

            if (obj != null)
            {
                return(obj.ObjectPtr);
            }
            return(InternalUnsafeMethods.FindDataBlockByName(name));
        }
Ejemplo n.º 9
0
        public void Add(ISimObject simObject)
        {
            // Get all relation properties
            var relationProps = simObject.GetType().GetProperties()
                                .Where(a => a.PropertyType == typeof(Relation))
                                .Select(a => a.GetValue(simObject) as Relation);

            relationProps.Where(a => a != null).ToList().ForEach(a => Add(a));

            objects.Add(simObject);
        }
Ejemplo n.º 10
0
        public static IntPtr FindObjectPtrById(uint id)
        {
            InternalUnsafeMethods.FindObjectById_Struct idStruct =
                new InternalUnsafeMethods.FindObjectById_Struct
            {
                id = id
            };
            ISimObject obj = SimDictionary.Find <ISimObject>(id);

            if (obj != null)
            {
                return(obj.ObjectPtr);
            }
            return(InternalUnsafeMethods.FindObjectById(idStruct));
        }
Ejemplo n.º 11
0
        public static bool UnregisterObject(ISimObject obj)
        {
            bool isDead = IsDead(obj.ObjectPtr);

            UnregisterObjectPtr(obj.ObjectPtr);
            if (isDead)
            {
                return(true);
            }
            if (!ObjectDictionary.ContainsKey(obj.GetId()))
            {
                return(false);
            }

            ObjectDictionary.Remove(obj.GetId());
            return(true);
        }
Ejemplo n.º 12
0
        public static string Build(ISimObject simObject, CypherCommandType commandType)
        {
            switch (commandType)
            {
            case CypherCommandType.Create:
                return(CreateCommand(simObject));

            case CypherCommandType.Update:
                return(UpdateCommand(simObject));

            case CypherCommandType.Delete:
                return(DeleteCommand(simObject));

            default:
                return(null);
            }
        }
Ejemplo n.º 13
0
        public static object RegisterObject(ISimObject obj)
        {
            RegisterObjectPtr(obj.ObjectPtr);

            int id = obj.GetId();

            if (!ObjectDictionary.ContainsKey(id) ||
                ObjectDictionary[id].GetType().IsInstanceOfType(obj))
            {
                ObjectDictionary[id] = obj;
            }

            if (!string.IsNullOrEmpty(obj.Name))
            {
                ObjectNameDictionary[obj.Name] = id;
            }

            return(ObjectDictionary[id]);
        }
Ejemplo n.º 14
0
        private static string GetPropertyTypeFromCore(string type, ISimRepository simRepository)
        {
            System.Reflection.Assembly core = System.Reflection.Assembly.GetAssembly(typeof(Relation));
            Type typeFromCore = core.GetType(type);

            if (typeFromCore != null && typeFromCore.BaseType.Equals(typeof(Relation)))
            {
                return(typeFromCore.FullName);
            }
            else
            {
                ISimObject typeFromCurrentRepos = simRepository.Get(a => a is DynamicRelation && (a as DynamicRelation).Name.Equals(type, StringComparison.OrdinalIgnoreCase));
                if (typeFromCurrentRepos != null)
                {
                    return(string.Format("{0}.{1}", (typeFromCurrentRepos as DynamicRelation).Namespace, (typeFromCurrentRepos as DynamicRelation).Name));
                }
            }

            return(null);
        }
Ejemplo n.º 15
0
        public static object CreateInstance(Type type, ISimObject objectBaseWrapper)
        {
            if (!ObjectDictionary.ContainsKey(objectBaseWrapper.GetId()) ||
                !(type.IsInstanceOfType(ObjectDictionary[objectBaseWrapper.GetId()])))
            {
                ISimObject obj = (ISimObject)FormatterServices.GetUninitializedObject(type);
                obj.SetPointerFromObject(objectBaseWrapper);
                RegisterObject(obj);
                ObjectDictionary[objectBaseWrapper.GetId()] = obj;
            }

            ISimObject dicObjectBase = ObjectDictionary[objectBaseWrapper.GetId()];

            if (!string.IsNullOrEmpty(dicObjectBase.Name))
            {
                ObjectNameDictionary[dicObjectBase.Name] = dicObjectBase.GetId();
            }

            return(dicObjectBase);
        }
Ejemplo n.º 16
0
        private static string CallNamespaceMethod(Type namespaceClass, ISimObject objectBaseWrapper, string methodName,
                                                  object[] args, out bool found)
        {
            // TODO: Ensure callbackMethod is most recent override of method. (e.g. GameConnection re-defining delete)
            MethodInfo callbackMethod = namespaceClass
                                        .GetMethods(bindingFlags)
                                        .FirstOrDefault(x => x.Name.ToLowerInvariant().Equals(methodName.ToLowerInvariant()));

            if (callbackMethod != null)
            {
                ISimObject simObj = null;
                if (!callbackMethod.IsStatic)
                {
                    simObj = (ISimObject)SimDictionary.CreateInstance(namespaceClass, objectBaseWrapper);
                }
                return(InvokeMethod(callbackMethod, simObj, args, out found));
            }

            found = false;
            return(null);
        }
Ejemplo n.º 17
0
        public static Type GetObjectType(string className, string classNamespace, ISimObject objectBaseWrapper)
        {
            string objectName = objectBaseWrapper?.GetName();

            if (objectName != null && ClassTypeDictionary.ContainsKey(objectName))
            {
                return(ClassTypeDictionary[objectName]);
            }

            if (classNamespace != null && ClassTypeDictionary.ContainsKey(classNamespace))
            {
                return(ClassTypeDictionary[classNamespace]);
            }

            if (className != null && ClassTypeDictionary.ContainsKey(className))
            {
                return(ClassTypeDictionary[className]);
            }

            if (objectName != null && SimDictionary.Find(objectName) != null)
            {
                return(SimDictionary.Find(objectName).GetType());
            }

            if (objectBaseWrapper != null && SimDictionary.Find(objectBaseWrapper.GetId()) != null)
            {
                return(SimDictionary.Find(objectBaseWrapper.GetId()).GetType());
            }

            if (objectBaseWrapper != null && ClassTypeDictionary.ContainsKey(objectBaseWrapper.GetType().Name))
            {
                return(ClassTypeDictionary[objectBaseWrapper.GetType().Name]);
            }

            return(null);
        }
Ejemplo n.º 18
0
 public void Remove(ISimObject simObject)
 {
     _db.Remove(simObject);
 }
Ejemplo n.º 19
0
 public void Add(ISimObject simObject)
 {
     _client.Create(simObject);
 }
Ejemplo n.º 20
0
        public static string CallScriptMethod(string className, string classNamespace, ISimObject objectBaseWrapper,
                                              string methodName, object[] args, out bool found)
        {
            Type type = GetObjectType(className, classNamespace, objectBaseWrapper);

            if (type == null)
            {
                found = false;
                return(null);
            }

            return(CallNamespaceMethod(type, objectBaseWrapper, methodName, args, out found));
        }
Ejemplo n.º 21
0
 public static bool Contains(ISimObject pObj)
 {
     return(ObjectWrapperDictionary.ContainsKey(pObj.ObjectPtr));
 }
Ejemplo n.º 22
0
 public void Remove(ISimObject simObject)
 {
     objects.Remove(simObject);
 }
Ejemplo n.º 23
0
 public void Update(ISimObject simObject)
 {
     throw new NotImplementedException();
 }
Ejemplo n.º 24
0
 public void Add(ISimObject simObject)
 {
     _objects.Add(simObject);
 }
Ejemplo n.º 25
0
        public void Create(ISimObject simObject)
        {
            string cypher = CypherBuilder.Build(simObject, CypherCommandType.Create);

            CypherExecuter(cypher);
        }
Ejemplo n.º 26
0
 private void Print(ISimObject simObject)
 {
     // Get type
     var type = simObject.GetType();
 }
Ejemplo n.º 27
0
 public void Add(ISimObject simObject)
 {
     _db.Add(simObject);
 }
Ejemplo n.º 28
0
 private static string UpdateCommand(ISimObject simObject)
 {
     throw new NotImplementedException();
 }
Ejemplo n.º 29
0
 public void Update(ISimObject simObject)
 {
     Remove(simObject);
     Add(simObject);
 }
Ejemplo n.º 30
0
 protected override Task OnInitializedAsync()
 {
     Object = Activator.CreateInstance(TargetType) as ISimObject;
     return(base.OnInitializedAsync());
 }