示例#1
0
        public NpcSystem(TimelineHandler handler)
        {
            _log.Trace($"Handling NpcSystem call: {handler}");

            foreach (var timelineEvent in handler.TimeLineEvents)
            {
                if (string.IsNullOrEmpty(timelineEvent.Command))
                {
                    continue;
                }

                Timeline timeline;

                switch (timelineEvent.Command.ToLower())
                {
                case "start":
                    timeline        = TimelineBuilder.GetLocalTimeline();
                    timeline.Status = Timeline.TimelineStatus.Run;
                    TimelineBuilder.SetLocalTimeline(timeline);
                    break;

                case "stop":
                    timeline        = TimelineBuilder.GetLocalTimeline();
                    timeline.Status = Timeline.TimelineStatus.Stop;

                    StartupTasks.CleanupProcesses();

                    TimelineBuilder.SetLocalTimeline(timeline);
                    break;
                }
            }
        }
示例#2
0
        private static void GetServerUpdates()
        {
            if (!Program.Configuration.ClientUpdates.IsEnabled)
            {
                return;
            }

            var machine = new ResultMachine();

            Thread.Sleep(Program.Configuration.ClientUpdates.CycleSleep);

            while (true)
            {
                try
                {
                    string s = string.Empty;
                    using (var client = WebClientBuilder.Build(machine))
                    {
                        try
                        {
                            using (var reader =
                                       new StreamReader(client.OpenRead(Program.Configuration.ClientUpdates.PostUrl)))
                            {
                                s = reader.ReadToEnd();
                                _log.Debug($"{DateTime.Now} - Received new configuration");
                            }
                        }
                        catch (WebException wex)
                        {
                            if (((HttpWebResponse)wex.Response).StatusCode == HttpStatusCode.NotFound)
                            {
                                _log.Debug($"{DateTime.Now} - No new configuration found");
                            }
                        }
                        catch (Exception e)
                        {
                            _log.Error(e);
                        }
                    }

                    if (!string.IsNullOrEmpty(s))
                    {
                        var update = JsonConvert.DeserializeObject <UpdateClientConfig>(s);

                        switch (update.Type)
                        {
                        case UpdateClientConfig.UpdateType.Timeline:
                            TimelineBuilder.SetLocalTimeline(update.Update.ToString());
                            break;

                        case UpdateClientConfig.UpdateType.TimelinePartial:
                            try
                            {
                                var timeline = JsonConvert.DeserializeObject <Timeline>(update.Update.ToString());

                                foreach (var timelineHandler in timeline.TimeLineHandlers)
                                {
                                    _log.Trace($"PartialTimeline found: {timelineHandler.HandlerType}");

                                    foreach (var timelineEvent in timelineHandler.TimeLineEvents)
                                    {
                                        if (string.IsNullOrEmpty(timelineEvent.TrackableId))
                                        {
                                            timelineEvent.TrackableId = Guid.NewGuid().ToString();
                                        }
                                    }

                                    var orchestrator = new Orchestrator();
                                    orchestrator.RunCommand(timelineHandler);
                                }
                            }
                            catch (Exception exc)
                            {
                                _log.Debug(exc);
                            }

                            break;

                        case UpdateClientConfig.UpdateType.Health:
                        {
                            var newTimeline = JsonConvert.DeserializeObject <Ghosts.Domain.ResultHealth>(update.Update.ToString());
                            //save to local disk
                            using (var file = File.CreateText(ApplicationDetails.ConfigurationFiles.Health))
                            {
                                var serializer = new JsonSerializer();
                                serializer.Formatting = Formatting.Indented;
                                serializer.Serialize(file, newTimeline);
                            }

                            break;
                        }

                        default:
                        {
                            _log.Debug($"Update {update.Type} has no handler, ignoring...");
                            break;
                        }
                        }
                    }
                }
                catch (Exception e)
                {
                    _log.Debug("Problem polling for new configuration");
                    _log.Error(e);
                }

                Thread.Sleep(Program.Configuration.ClientUpdates.CycleSleep);
            }
        }
示例#3
0
        private static void GetServerUpdates()
        {
            if (!Program.Configuration.ClientUpdates.IsEnabled)
            {
                return;
            }

            // ignore all certs
            ServicePointManager.ServerCertificateValidationCallback += (sender, cert, chain, sslPolicyErrors) => true;

            var machine = new ResultMachine();

            GuestInfoVars.Load(machine);

            Thread.Sleep(ProcessManager.Jitter(Program.Configuration.ClientUpdates.CycleSleep));

            while (true)
            {
                try
                {
                    string s = string.Empty;
                    using (var client = WebClientBuilder.Build(machine))
                    {
                        try
                        {
                            using (var reader =
                                       new StreamReader(client.OpenRead(Program.Configuration.ClientUpdates.PostUrl)))
                            {
                                s = reader.ReadToEnd();
                                _log.Debug($"{DateTime.Now} - Received new configuration");
                            }
                        }
                        catch (WebException wex)
                        {
                            if (((HttpWebResponse)wex.Response).StatusCode == HttpStatusCode.NotFound)
                            {
                                _log.Debug($"{DateTime.Now} - No new configuration found");
                            }
                        }
                        catch (Exception e)
                        {
                            _log.Error(e);
                        }
                    }

                    if (!string.IsNullOrEmpty(s))
                    {
                        var update = JsonConvert.DeserializeObject <UpdateClientConfig>(s);

                        if (update.Type == UpdateClientConfig.UpdateType.Timeline)
                        {
                            TimelineBuilder.SetLocalTimeline(update.Update.ToString());
                        }
                        else if (update.Type == UpdateClientConfig.UpdateType.Health)
                        {
                            var newTimeline = JsonConvert.DeserializeObject <Domain.ResultHealth>(update.Update.ToString());
                            //save to local disk
                            using (var file = File.CreateText(ApplicationDetails.ConfigurationFiles.Health))
                            {
                                var serializer = new JsonSerializer();
                                serializer.Formatting = Formatting.Indented;
                                serializer.Serialize(file, newTimeline);
                            }
                        }
                    }
                }
                catch (Exception e)
                {
                    _log.Debug("Problem polling for new configuration");
                    _log.Error(e);
                }

                Thread.Sleep(ProcessManager.Jitter(Program.Configuration.ClientUpdates.CycleSleep));
            }
        }