예제 #1
0
파일: base_item.cs 프로젝트: Zror/DatRepo
    // Use this for initialization
    void Start()
    {
        // Correct init logics

        if (GetComponent<CoinSpin>() != null)
        {
            coin = GetComponent<CoinSpin>();
        }

        if (GetComponent<AudioSource>() != null)
        {
            //Audi = GetComponent<AudioSource>();
        }
        this.tag = Globals.TAGS.Item;
        this.award_Flame = Mathf.Max(award_Flame, 0f);
        if (monitor == null)
        {
            monitor = Session_Monitor.Instance;
            Audi = ((AudioSource )monitor.gameObject.GetComponent<AudioSource>());
        }
        if (dragonSM == null)
        {
            dragonSM = FindObjectsOfType<HealthMonitor>().First(t => t.tag == Globals.TAGS.Player);
        }
        Audi = ((AudioSource)monitor.gameObject.GetComponent<AudioSource>());
        if(GetComponent<CoinSpin>() == null)
        {
            Audi = null;
        }
        p = FindObjectOfType<Perks>();
    }
 public void Setup()
 {
     _healthMonitor = new HealthMonitor();
 }
예제 #3
0
        public void Reload()
        {
            var     errors        = new List <ValidationResult>();
            JObject config        = null;
            object  updatedConfig = null;

            try
            {
                config = ConfigCache.CreateJsonConfig(ConfigPath) ?? Empty;

                if (JToken.DeepEquals(LatestNode, config))
                {
                    if (Latest != null)
                    {
                        ValidationErrors = null;
                    }

                    return;
                }
            }
            catch (Exception ex)
            {
                errors.Add(new ValidationResult("Failed to acquire config JObject: " + HealthMonitor.GetMessages(ex)));
            }

            if (config != null && errors.Any() == false)
            {
                try
                {
                    updatedConfig = config.ToObject(ObjectType);
                }
                catch (Exception ex)
                {
                    // It is not only JsonException, as sometimes a custom deserializer capable to throw god knows what (including ProgrammaticException)
                    errors.Add(new ValidationResult("Failed to deserialize config object: " + HealthMonitor.GetMessages(ex)));
                }

                if (updatedConfig != null)
                {
                    Validator.TryValidateObjectRecursive(updatedConfig, errors);
                }
            }

            if (errors.Any() == false)
            {
                ValidationErrors = null;
                UsageTracking.AddConfigObject(Latest, ConfigPath);
                if (isCreated)
                {
                    Log.Info(_ => _("A config object has been updated",
                                    unencryptedTags: new {
                        ConfigObjectType  = ObjectType.FullName,
                        ConfigObjectPath  = ConfigPath,
                        OverallModifyTime = ConfigCache.LatestConfigFileModifyTime,
                    },
                                    encryptedTags: new {
                        Changes = DiffJObjects(LatestNode, config, new StringBuilder(), new Stack <string>()).ToString(),
                    }));
                }
                else//It mean we are first time not need to send update messsage
                {
                    isCreated = true;
                }

                LatestNode = config;
                Latest     = updatedConfig;
                SendChangeNotification?.Invoke(Latest);
            }
            else
            {
                ValidationErrors = string.Join(" \n", errors.Select(a => a.ErrorMessage));

                Log.Error(_ => _("A config object has been updated but failed validation", unencryptedTags: new
                {
                    ConfigObjectType = ObjectType.FullName,
                    ConfigObjectPath = ConfigPath,
                    ValidationErrors
                }));
            }
        }
예제 #4
0
        private HealthCheckResult HealthCheck()
        {
            var failedQueries      = _failedQueries.ToArray();
            var nonExistQueries    = _existingServices.Where(_ => _.Value == false).Select(_ => _.Key).ToArray();
            var nonExistQueriesStr = nonExistQueries.Any() ? $"The following queries do not exist: {string.Join(", ", nonExistQueries)}" : string.Empty;

            if (failedQueries.Any() == false)
            {
                return(HealthCheckResult.Healthy(nonExistQueriesStr));
            }
            else
            {
                var failedQueriesStr = "The following queries failed: " + string.Join(", ", failedQueries.Select(q => $"\"{q.Key}\": {HealthMonitor.GetMessages(q.Value)}"));
                return(HealthCheckResult.Unhealthy(nonExistQueriesStr + "\r\n" + failedQueriesStr));
            }
        }
 public HealthMonitoringPartitionControllerDecorator(PartitionController inner, HealthMonitor monitor)
 {
     this.inner   = inner ?? throw new ArgumentNullException(nameof(inner));
     this.monitor = monitor ?? throw new ArgumentNullException(nameof(monitor));
 }
예제 #6
0
파일: Flight.cs 프로젝트: Zror/DatRepo
 // Use this for initialization
 public virtual void Start()
 {
     rigidbody = GetComponentInParent<Rigidbody2D>();
     health = GetComponentInParent<HealthMonitor>();
     Audi = GetComponentInParent<AudioSource>();
 }
예제 #7
0
        public ConsulClient(IEnvironmentVariableProvider environmentVariableProvider, ILog log, HealthMonitor healthMonitor)
        {
            Log        = log;
            DataCenter = environmentVariableProvider.DataCenter;
            var address = environmentVariableProvider.ConsulAddress ?? $"{CurrentApplicationInfo.HostName}:8500";

            ConsulAddress = new Uri($"http://{address}");
            _httpClient   = new HttpClient {
                BaseAddress = ConsulAddress, Timeout = TimeSpan.FromSeconds(5)
            };
            healthMonitor.SetHealthFunction("ConsulClient", HealthCheck);
        }
예제 #8
0
 // Use this for initialization
 public virtual void Start()
 {
     rigidbody = GetComponentInParent <Rigidbody2D>();
     health    = GetComponentInParent <HealthMonitor>();
     Audi      = GetComponentInParent <AudioSource>();
 }
예제 #9
0
        /// <summary>
        /// Loads the specified settings, overwriting existing settings.
        /// </summary>
        /// <param name="updatedEndPointsResult"></param>
        /// this <see cref="RemoteHostPool"/>.
        /// <exception cref="ArgumentNullException">Thrown when </exception>
        /// <exception cref="EnvironmentException"></exception>
        private void ReloadEndpoints(EndPointsResult updatedEndPointsResult)
        {
            lock (_lock)
            {
                try
                {
                    var updatedEndPoints = updatedEndPointsResult.EndPoints;
                    if (updatedEndPoints.Any() == false)
                    {
                        Health.SetHealthFunction(() =>
                        {
                            var config = GetConfig();
                            if (IsHealthCheckSuppressed(config))
                            {
                                return(new ValueTask <HealthCheckResult>(HealthCheckResult.Healthy(
                                                                             $"No endpoints were discovered from source '{config.Source}' but the remote service was not in use for more than {config.SuppressHealthCheckAfterServiceUnused.TotalSeconds} seconds.")));
                            }
                            else
                            {
                                return(new ValueTask <HealthCheckResult>(HealthCheckResult.Unhealthy(
                                                                             $"No endpoints were discovered from source '{config.Source}'.")));
                            }
                        });

                        EndPointsResult = updatedEndPointsResult;

                        ReachableHosts   = new List <RemoteHost>();
                        UnreachableHosts = new List <RemoteHost>();
                    }
                    else
                    {
                        if (EndPoints != null)
                        {
                            foreach (var removedEndPoint in EndPoints.Except(updatedEndPoints))
                            {
                                ReachableHosts.SingleOrDefault(h => h.Equals(removedEndPoint))?.StopMonitoring();
                                ReachableHosts.RemoveAll(h => h.Equals(removedEndPoint));
                                UnreachableHosts.RemoveAll(h => h.Equals(removedEndPoint));
                            }
                        }

                        var newHosts = updatedEndPoints
                                       .Except(EndPoints ?? Enumerable.Empty <EndPoint>())
                                       .Select(ep => new RemoteHost(ep.HostName, this, _lock, ep.Port));

                        ReachableHosts.AddRange(newHosts);

                        EndPointsResult = updatedEndPointsResult;

                        Counter = (ulong)_random.Next(0, ReachableHosts.Count);

                        Health.SetHealthFunction(CheckHealth);
                    }

                    _endPointsChanged.Post(EndPointsResult);
                }
                catch (Exception ex)
                {
                    Log.Warn("Failed to process newly discovered endpoints", exception: ex);
                    Health.SetHealthFunction(() =>
                                             new ValueTask <HealthCheckResult>(HealthCheckResult.Unhealthy("Failed to process newly discovered endpoints: " +
                                                                                                           HealthMonitor.GetMessages(ex))));
                }
            }
        }
예제 #10
0
 public void Tick_ShouldNotThrow_WhenUnconfigured()
 {
     HealthMonitor.Tick();
 }
예제 #11
0
    int m_bPlayerInstanceCount = 0;  //flag to disable multiple player instances
    void InitialiseInstance(Parser.Tr2Item tr2item)
    {
        GameObject go = tr2item.UnityObject;

        go.name += " " + tr2item.ObjectID;
        if (tr2item.ObjectID == 0)
        {
            if (m_bPlayerInstanceCount == 1)
            {
                GameObject.Destroy(tr2item.UnityObject);
                return;
            }
            //playable character found!
            m_Player                  = go;
            m_Player.layer            = UnityLayer.Player;
            m_PrevPlayPos             = m_Player.transform.position;
            m_Player.transform.parent = m_LevelRoot;

            if (m_leveldata.Camera != null)
            {
                m_leveldata.Camera.target = m_Player.transform;
            }
            LaraStatePlayer stateplayer = m_Player.AddComponent <LaraStatePlayer>();
            stateplayer.tranimations = m_DynamicPrefabs[0].AnimClips;
            m_Player.name            = "Lara";

            GameObject FlashLight = new GameObject("Fire Torch");
            FlashLight.AddComponent <FlashLightStatePlayer>();
            Light lt = FlashLight.AddComponent <Light>();
            lt.type      = LightType.Spot;
            lt.range     = 5;
            lt.spotAngle = 70;
            lt.intensity = 5;

            FlashLight.transform.parent   = m_Player.transform.Find("objPart:0");//.Find("objPart:7").Find("objPart:14");
            FlashLight.transform.position = FlashLight.transform.parent.position;
            FlashLight.transform.forward  = FlashLight.transform.parent.forward;
            lt.enabled = false;

            Player player = go.AddComponent <Player>();
            player.m_Tr2Item = tr2item;
            HealthMonitor          healthmon      = go.AddComponent <HealthMonitor>();
            PlayerCollisionHandler playercollider = go.AddComponent <PlayerCollisionHandler>();

            //Initialise Current Active Room for player
            player.m_AnimStatePlayer = stateplayer;
            player.m_Room            = SetRoomForPlayer();
            if (player.m_Room != null)
            {
                Debug.Log("Player Rooms: " + player.m_Room.name);
                player.SetSwimState(player.m_Room);
            }
            AICondition.SetActive(m_Player, true);

            //set every game object under player as player
            Transform[] objs = m_Player.GetComponentsInChildren <Transform>();
            foreach (Transform t in objs)
            {
                t.gameObject.layer = UnityLayer.Player;
            }

            //Add Charecter light
            GameObject LaraLight = new GameObject("Lara Light");
            Light      light     = LaraLight.AddComponent <Light>();
            light.transform.position = m_Player.transform.position;
            light.type = LightType.Directional;
            light.transform.forward = Vector3.Reflect(Vector3.one, -Vector3.up);
            light.transform.parent  = m_Player.transform;
            light.cullingMask       = MaskedLayer.Player;
            light.intensity         = 0.3f;
            light.gameObject.AddComponent <LaraLightStatePlayer>();

            m_bPlayerInstanceCount = 1;
        }
        //check if we have any custom behabiour  script for object
        else if (m_OnAttachBehabiourScript != null && !m_OnAttachBehabiourScript(tr2item.UnityObject, tr2item.ObjectID, m_Player, tr2item))
        {
            go.AddComponent <DefaultStatePlayer>(); // user did not attached any custom behabiour. so use default one
            AICondition.SetActive(go, true);        //Added default activation state active
        }
    }
예제 #12
0
        public void AddNotifier_ShouldAddNotifier(INotifier notifier)
        {
            HealthMonitor.AddNotifier(notifier).Should().BeTrue();

            HealthMonitor.Notifiers.Count.Should().Be(1);
        }
예제 #13
0
        public void AddCheck_ShouldAddCheck(IHealthCheck check)
        {
            HealthMonitor.AddCheck(check).Should().BeTrue();

            HealthMonitor.Checks.Count.Should().Be(1);
        }
예제 #14
0
    void GetStatMonitor()
    {
        if (hasStatMonitor == true) { return; }
        if (source == null)
        {
            // Get a source

            source = FindObjectsOfType<HealthMonitor>().First(t => t.tag == Globals.TAGS.Player);
            if (source == null)
            {
                // Thats bad!
                return;
            }

            if (Use_Stat_Number == 3)
            {
                // Use a debug mode which used SIN()
                max = 1;
            }
            else
            {
                max = source.GetLimitAtIndex(Use_Stat_Number);
            }

        }
        else
        {

            hasStatMonitor = true;
        }
    }
예제 #15
0
        private void Create()
        {
            var     errors        = new List <ValidationResult>();
            JObject config        = null;
            object  updatedConfig = null;

            try
            {
                config = ConfigCache.CreateJsonConfig(ConfigPath) ?? Empty;

                if (JToken.DeepEquals(LatestNode, config))
                {
                    if (Latest != null)
                    {
                        ValidationErrors = null;
                    }

                    return;
                }
            }
            catch (Exception ex)
            {
                errors.Add(new ValidationResult("Failed to acquire config JObject: " + HealthMonitor.GetMessages(ex)));
            }

            if (config != null && errors.Any() == false)
            {
                LatestNode = config;

                try
                {
                    updatedConfig = LatestNode.ToObject(ObjectType);
                }
                catch (JsonException ex)
                {
                    errors.Add(new ValidationResult("Failed to deserialize config object: " + HealthMonitor.GetMessages(ex)));
                }

                if (updatedConfig != null)
                {
                    Validator.TryValidateObjectRecursive(updatedConfig, errors);
                }
            }

            if (errors.Any() == false)
            {
                Latest           = updatedConfig;
                ValidationErrors = null;
                UsageTracking.AddConfigObject(Latest, ConfigPath);

                Log.Info(_ => _("A config object has been updated", unencryptedTags: new
                {
                    ConfigObjectType = ObjectType.FullName,
                    ConfigObjectPath = ConfigPath
                }));

                SendChangeNotification?.Invoke(Latest);
            }
            else
            {
                ValidationErrors = string.Join(" \n", errors.Select(a => a.ErrorMessage));

                Log.Error(_ => _("A config object has been updated but failed validation", unencryptedTags: new
                {
                    ConfigObjectType = ObjectType.FullName,
                    ConfigObjectPath = ConfigPath,
                    ValidationErrors
                }));
            }
        }
예제 #16
0
        private ValueTask <HealthCheckResult> CheckHealth()
        {
            var config = GetConfig();

            if (IsHealthCheckSuppressed(config))
            {
                return(new ValueTask <HealthCheckResult>(HealthCheckResult.Healthy($"Health check suppressed because service was not in use for more than {config.SuppressHealthCheckAfterServiceUnused.TotalSeconds} seconds.")));
            }

            int       reachableCount;
            int       unreachableCount;
            Exception exception;

            string[] unreachableHosts;

            lock (_lock)
            {
                reachableCount   = ReachableHosts.Count;
                unreachableHosts = UnreachableHosts.Select(x => $"{x.HostName}:{x.Port}").ToArray();
                unreachableCount = unreachableHosts.Length;
                exception        = UnreachableHosts.FirstOrDefault()?.LastException;
            }

            if (reachableCount == 0)
            {
                return(new ValueTask <HealthCheckResult>(HealthCheckResult.Unhealthy($"All of the {unreachableCount} hosts are unreachable: " +
                                                                                     $"{string.Join(",", unreachableHosts)}. Last exception: {HealthMonitor.GetMessages(exception)}")));
            }
            else
            {
                if (unreachableCount > 0)
                {
                    return(new ValueTask <HealthCheckResult>(HealthCheckResult.Unhealthy($"The following {unreachableCount} hosts " +
                                                                                         $"(out of {unreachableCount + reachableCount}) are unreachable: {string.Join(",", unreachableHosts)}. " +
                                                                                         $"Last exception: {HealthMonitor.GetMessages(exception)}")));
                }
                else
                {
                    return(new ValueTask <HealthCheckResult>(HealthCheckResult.Healthy($"All {reachableCount} hosts are reachable.")));
                }
            }
        }
예제 #17
0
 public MetricsInitializer(ILog log, IConfiguration configuration, IMetricsSettings metricsSettings, HealthMonitor healthMonitor, IEnvironmentVariableProvider envProvider, CurrentApplicationInfo appInfo)
 {
     Configuration   = configuration;
     MetricsSettings = metricsSettings;
     HealthMonitor   = healthMonitor;
     Log             = log;
     EnvProvider     = envProvider;
     AppInfo         = appInfo;
 }
예제 #18
0
 public MetricsInitializer(ILog log, IConfiguration configuration, IMetricsSettings metricsSettings, HealthMonitor healthMonitor, CurrentApplicationInfo appInfo)
 {
     Configuration   = configuration;
     MetricsSettings = metricsSettings;
     HealthMonitor   = healthMonitor;
     Log             = log;
     AppInfo         = appInfo;
 }