Exemplo n.º 1
0
    void Generate(ObjectMeta meta)
    {
        string prefabPath;

        switch (meta.type)
        {
        case ObjectsKey.block:
            prefabPath = "Prefabs/Block";
            break;

        case ObjectsKey.elixir:
            prefabPath = "Prefabs/Elixer";
            break;

        case ObjectsKey.empty:
            return;

        default:
            throw new System.Exception("Invalid object type: " + meta.type.ToString());
        }
        GameObject prefab = Resources.Load <GameObject>(prefabPath);
        GameObject obj    = Instantiate(prefab, meta.pos, Quaternion.identity);

        if (meta.type == ObjectsKey.block)
        {
            obj.GetComponent <Block>().__power = meta.power;
        }
    }
Exemplo n.º 2
0
        public List <ObjectMeta> GetObjectMetaData(string projectId, ObjectTypes objectTypes)
        {
            var entries = Query(projectId, objectTypes);
            var list    = new List <ObjectMeta>();

            foreach (var entry in entries)
            {
                var item = GetObject(entry.Link);
                switch (objectTypes)
                {
                case ObjectTypes.Dashboard:
                    list.Add(ObjectMeta.MapDashboard(item));
                    break;

                case ObjectTypes.Report:
                    list.Add(ObjectMeta.MapReport(item));
                    break;

                case ObjectTypes.UserFilter:
                    list.Add(ObjectMeta.MapUserFilter(item));
                    break;

                default:
                    list.Add(ObjectMeta.MapMetric(item));
                    break;
                }
            }
            return(list);
        }
Exemplo n.º 3
0
    /// <summary>
    /// 构造函数
    /// </summary>
    /// <param name="filePath"></param>
    public Metrics(string filePath)
    {
        var confData = JsonUtils.DecodeCps(filePath);

        if (confData.Metrics != null && confData.Metrics.Enable)
        {
            ns = Environment.GetEnvironmentVariable("GS_NAMESPACE");
            if (ns != null && ns.Length != 0)
            {
                enable     = true;
                svcName    = Environment.GetEnvironmentVariable("DIRECTORY_SVC_NAME");
                podName    = Environment.GetEnvironmentVariable("DIRECTORY_POD_NAME");
                remoteHost = Environment.GetEnvironmentVariable("EXPORTER_REMOTE_HOST");
                remotePort = int.Parse(Environment.GetEnvironmentVariable("EXPORTER_REMOTE_PORT"));
                userID     = CRC32Utils.GetCRC32(svcName + podName);

                meta = new ObjectMeta()
                {
                    Namespace = ns,
                    Name      = podName,
                };

                reporter = new Timer(this.ReportCoreMetrics, null, 0, 1000 * 60);
            }
        }
    }
Exemplo n.º 4
0
        static UnityEngine.Object _ReadXmlElement_UnityEngine_Object(XmlReader reader, System.Type elementType, ExtraData extraData = null)
        {
            var meta = new ObjectMeta();

            meta.ReadFromXml(reader);
            return(meta.Find(extraData));
        }
        public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
        {
            switch (reader.TokenType)
            {
            case JsonToken.StartObject:
                existingValue = existingValue ?? serializer.ContractResolver.ResolveContract(objectType).DefaultCreator();
                serializer.Populate(reader, existingValue);
                switch (existingValue)
                {
                case ObjectMeta om:
                    var nom = new ObjectMeta
                    {
                        Objects = om.Objects,
                        Meta    = om.Meta.Select(mt => ((JObject)mt).ToObject(GetOJtype(om.Objects.Type))).ToArray(),
                        Ticks   = om.Ticks
                    };
                    return(nom);

                case ObjectStateUpdate osu:
                    var nosu = new ObjectStateUpdate
                    {
                        Objects = osu.Objects,
                        States  = osu.States.Select(mt => ((JObject)mt).ToObject(GetOJtype(osu.Objects.Type)))
                                  .ToArray()
                    };
                    return(nosu);

                case ObjectData oda:
                {
                    var noda = new ObjectData
                    {
                        Objects = oda.Objects,
                        Data    = oda.Data.Select(mt => ((JObject)mt).ToObject(GetOJtype(oda.Objects.Type)))
                                  .ToArray(),
                        Ticks = oda.Ticks
                    };
                    return(noda);
                }

                case ObjectEvent oev:
                {
                    var noda = new ObjectEvent
                    {
                        Objects = oev.Objects,
                        Events  = oev.Events.Select(mt => ((JObject)mt).ToObject(GetOJtype(oev.Objects.Type)))
                                  .ToArray(),
                        Ticks = oev.Ticks
                    };
                    return(noda);
                }
                }
                return(null);

            case JsonToken.Null:
                return(null);

            default:
                throw new JsonSerializationException();
            }
        }
Exemplo n.º 6
0
        private async Task <Intersection> ReadIntersectionMetaAndSubscribeAsync(TLCFIClientSession session, TLCFIClientConfig config, TLCFIClientStateManager stateManager, CancellationToken token)
        {
            ObjectMeta intersectionMeta  = null;
            ObjectData intersectionState = null;
            var        iref = new ObjectReference
            {
                Ids  = new[] { config.RemoteIntersectionId },
                Type = TLCObjectType.Intersection
            };

            try
            {
                _logger.Info("Getting Intersection META data for intersection with id {0}", config.RemoteIntersectionId);
                intersectionMeta = await session.TLCProxy.ReadMetaAsync(iref, token);
            }
            catch (JsonRpcException e)
            {
                _logger.LogRpcException(e);
            }

            if (intersectionMeta == null || intersectionMeta.Meta.Length != 1)
            {
                var exmes = $"Error reading META of Intersection: received {intersectionMeta?.Meta.Length ?? 0} objects, expected 1";
                _logger.Warn(exmes);
                throw new InvalidMetaReceivedException(exmes);
            }

            _logger.Info("Succesfully obtained Intersection META data");
            var intersectionData = (Intersection)intersectionMeta.Meta[0];

            stateManager.InternalIntersections.Add(intersectionData);

            try
            {
                intersectionState = await session.TLCProxy.SubscribeAsync(iref, token);
            }
            catch (JsonRpcException e)
            {
                _logger.LogRpcException(e);
            }

            if (intersectionState == null || intersectionState.Data.Length != 1)
            {
                var exmes = $"Error reading STATE of Intersection: received {intersectionState?.Data.Length ?? 0} objects, expected 1";
                _logger.Warn(exmes);
                throw new InvalidMetaReceivedException(exmes);
            }

            var ins  = (Intersection)intersectionState.Data[0];
            var sins = stateManager.InternalIntersections.First(x => x.Id == intersectionState.Objects.Ids[0]);

            // Copy state
            sins.StateTicks = ins.StateTicks;
            sins.State      = ins.State;
            session.State.IntersectionControl = sins.State == IntersectionControlState.Control;

            return(intersectionData);
        }
Exemplo n.º 7
0
        private static ObjectMeta AddObjectMeta(Type type)
        {
            if (_objectMetas.TryGetValue(type, out var meta))
            {
                return(meta);
            }

            meta = new ObjectMeta();

            if (type.GetInterface("System.Collections.IDictionary") != null)
            {
                meta.IsDict = true;
            }

            meta.Properties = new Dictionary <string, PropertyMeta>();

            var properties = type.GetProperties(BindingFlags.Instance | BindingFlags.Public);

            foreach (var info in properties)
            {
                if (info.Name == "Item")
                {
                    var parameters = info.GetIndexParameters();
                    if (parameters.Length != 1)
                    {
                        continue;
                    }

                    meta.ElemType = parameters[0].ParameterType == typeof(string) ? info.PropertyType : typeof(object);

                    continue;
                }

                var prop = new PropertyMeta {
                    Info = info, Type = info.PropertyType
                };
                meta.Properties.Add(info.Name, prop);
            }

            var fields = type.GetFields(BindingFlags.Instance | BindingFlags.Public);

            foreach (var info in fields)
            {
                var data = new PropertyMeta {
                    Info = info, IsField = true, Type = info.FieldType
                };
                meta.Properties.Add(info.Name, data);
            }

            _objectMetas[type] = meta;
            return(meta);
        }
Exemplo n.º 8
0
        private async Task ReadFacilitiesMetaAsync(TLCFIClientSession session, TLCFIClientConfig config, TLCFIClientStateManager stateManager, CancellationToken token)
        {
            try
            {
                if (_facilitiesRef != null)
                {
                    ObjectMeta facilitiesMeta = null;
                    try
                    {
                        _logger.Info("Getting TLCFacilities META data");
                        facilitiesMeta = await session.TLCProxy.ReadMetaAsync(_facilitiesRef, token);
                    }
                    catch (JsonRpcException e)
                    {
                        _logger.LogRpcException(e);
                    }

                    if (facilitiesMeta != null && facilitiesMeta.Meta.Length == 1)
                    {
                        _logger.Info("Succesfully obtained TLCFacilities META data");
                        var facilitiesData = (TLCFacilities)facilitiesMeta.Meta[0];
                        stateManager.Facilities = facilitiesData;
                        if (!facilitiesData.Intersections.Contains(config.RemoteIntersectionId))
                        {
                            _logger.Error("Intersection with id {0} not found in TLCFacilities META data",
                                          config.RemoteIntersectionId);
                            throw new TLCObjectNotFoundException(config.RemoteIntersectionId, TLCObjectType.Intersection);
                        }
                    }
                    else
                    {
                        _logger.Fatal("Error reading META of TLCFacilities: received {0} objects, expected 1",
                                      facilitiesMeta?.Meta.Length ?? 0);
                        throw new ArgumentOutOfRangeException();
                    }
                }
                else
                {
                    _logger.Error(
                        "Error reading META of TLCFacilities: reference to facilities is null; was Register() succesfully called?");
                    throw new NullReferenceException();
                }
            }
            catch (Exception e)
            {
                _logger.Error(e, "Error reading META of TLCFacilities, canceling session; ");
                throw new TLCFISessionException("Error reading META of TLCFacilities, canceling session");
            }
        }
Exemplo n.º 9
0
        static void _WriteXmlValue_UnityEngine_Object(XmlWriter writer, object value, ExtraData extraData)
        {
            var meta = ObjectMeta.GetAt((UnityEngine.Object)value, extraData);

            if (extraData != null && extraData.objects != null && value != null)
            {
                meta.extraDataObjectIndex = extraData.objects.IndexOf((UnityEngine.Object)value);
                if (meta.extraDataObjectIndex < 0)
                {
                    meta.extraDataObjectIndex = extraData.objects.Count;
                    extraData.objects.Add((UnityEngine.Object)value);
                }
            }

            meta.WriteToXml(writer, extraData);
        }
Exemplo n.º 10
0
            public static GameServerResponse CreateMockResponse()
            {
                var mockResponseStatus = new Status
                {
                    Address = "127.0.0.1",
                    Ports   = new[] {
                        new PortInfo
                        {
                            Name = "http",
                            Port = 8080,
                        }
                    },
                    State = "Ready",
                };
                var mockResponseObjectMeta = new ObjectMeta
                {
                    Name              = "mock",
                    Namespace         = "default",
                    Generation        = "gen1",
                    ResourceVersion   = "v1",
                    Uid               = "0",
                    CreationTimestamp = new DateTime(2020, 1, 1, 0, 0, 0).ToString("yyyyMMdd_HHMMss"),
                    Annotations       = new[]
                    {
                        new Annotation
                        {
                            Key   = "key",
                            Value = "value",
                        },
                    },
                    Labels = new[]
                    {
                        new Label
                        {
                            Key   = "key",
                            Value = "value",
                        },
                    },
                };
                var response = new GameServerResponse()
                {
                    ObjectMeta = mockResponseObjectMeta,
                    Status     = mockResponseStatus,
                };

                return(response);
            }
        public ObjectMeta Upload_File(string filename, string dst_path)
        {
            ObjectMeta ret = new ObjectMeta();

            if (_stat_failed)
            {
                throw new Exception("操作失败");
            }

            try
            {
                //备份文件索引
                File.Copy(_repo_root_location + "/index/current.db", _repo_root_location + "/index/current.db.bak", true);
                File.Copy(_repo_root_location + "/index/file_usage.db", _repo_root_location + "/index/file_usage.db.bak", true);

                ret.Name      = _Get_File_Name(dst_path);
                ret.Extension = _Get_Extension(dst_path);
                ret.isDir     = false;
                ret.FullName  = dst_path;

                var fi = new FileInfo(filename);
                ret.Size = (ulong)fi.Length;

                //计算文件md5
                ret.MD5 = VBUtil.Utils.Others.Hex(_Get_File_MD5(filename));

                //不存在,复制
                if (!_File_Exists(ret.MD5))
                {
                    _Copy_File(fi.FullName, _repo_root_location + "/data/" + ret.MD5.Substring(0, 2) + "/" + ret.MD5);
                }

                //链接到文件目录系统
                #region Add Link

                #endregion
            }
            catch (Exception)
            {
                _stat_failed = true;
                Dispose();
                throw new Exception("上传文件错误");
            }

            return(ret);
        }
Exemplo n.º 12
0
    List <ObjectMeta> ToMetaMap(List <int> map, int power)
    {
        List <ObjectMeta> metaMap = new List <ObjectMeta>();
        int index = 0;

        foreach (int type in map)
        {
            ObjectMeta meta = new ObjectMeta();
            meta.type = type;
            meta.pos  = IndexToPos(index);

            int randPower = Random.Range(power - 5, power + 3);
            meta.power = Mathf.Clamp(randPower, 1, power + 5);

            metaMap.Add(meta);
            index++;
        }
        return(metaMap);
    }
Exemplo n.º 13
0
        public ObjectMeta Upload_File(string filename, string dst_path)
        {
            ObjectMeta ret = new ObjectMeta();
            if (_stat_failed) throw new Exception("操作失败");

            try
            {
                //备份文件索引
                File.Copy(_repo_root_location + "/index/current.db", _repo_root_location + "/index/current.db.bak", true);
                File.Copy(_repo_root_location + "/index/file_usage.db", _repo_root_location + "/index/file_usage.db.bak", true);

                ret.Name = _Get_File_Name(dst_path);
                ret.Extension = _Get_Extension(dst_path);
                ret.isDir = false;
                ret.FullName = dst_path;

                var fi = new FileInfo(filename);
                ret.Size = (ulong)fi.Length;

                //计算文件md5
                ret.MD5 = VBUtil.Utils.Others.Hex(_Get_File_MD5(filename));

                //不存在,复制
                if (!_File_Exists(ret.MD5))
                {
                    _Copy_File(fi.FullName, _repo_root_location + "/data/" + ret.MD5.Substring(0, 2) + "/" + ret.MD5);
                }

                //链接到文件目录系统
                #region Add Link

                #endregion
            }
            catch(Exception)
            {
                _stat_failed = true;
                Dispose();
                throw new Exception("上传文件错误");
            }

            return ret;
        }
Exemplo n.º 14
0
            public string transformPath;     // for Transform / GameObject

            public static ObjectMeta GetAt(UnityEngine.Object obj, ExtraData extraData)
            {
                ObjectMeta r = new ObjectMeta();

                if (obj != null)
                {
                    r.name                 = obj.name;
                    r.typeName             = obj.GetType().FullName;
                    r.extraDataObjectIndex = -1;
                    r.assetPath            = UnityEditor.AssetDatabase.GetAssetPath(obj);
                    if (!string.IsNullOrEmpty(r.assetPath))
                    {
                        r.guid = UnityEditor.AssetDatabase.AssetPathToGUID(r.assetPath);

                        if (!string.IsNullOrEmpty(extraData.rootDirectory))
                        {
                            r.relativeAssetPath = AssetPathHelper.GenerateRelativeAssetPath(extraData.rootDirectory, r.assetPath);
                        }
                    }

                    r.transformPath = "";
                    if (extraData != null && extraData.rootTransform != null)
                    {
                        Transform transform = null;
                        if (obj is GameObject)
                        {
                            transform = ((GameObject)obj).transform;
                        }
                        else if (obj is Transform)
                        {
                            transform = (Transform)obj;
                        }

                        if (transform != null && transform.IsChildOf(extraData.rootTransform))
                        {
                            r.transformPath = _GetTransformPath(extraData.rootTransform, transform);
                        }
                    }
                }

                return(r);
            }