Пример #1
0
        private void RenderField()
        {
            var update = new DisplayUpdate
            {
                FieldSize    = new System.Windows.Size(SimOpt.SimOpts.FieldWidth, SimOpt.SimOpts.FieldHeight),
                RobotUpdates = _robotsManager.Robots.Select(r => new RobotUpdate
                {
                    Position = r.Position,
                    Radius   = r.GetRadius(SimOpt.SimOpts.FixedBotRadii),
                    Color    = r.Color
                }).ToList().AsReadOnly(),
                TieUpdates = _robotsManager.Robots.SelectMany(r => r.Ties.Where(t => !t.BackTie).Select(t => new TieUpdate
                {
                    Color      = t.Color ?? r.Color,
                    StartPoint = r.OffsetPosition,
                    EndPoint   = t.OtherBot.OffsetPosition,
                    Width      = Math.Max(10, t.Last > 0 ? r.GetRadius(SimOpt.SimOpts.FixedBotRadii) / 20 : r.GetRadius(SimOpt.SimOpts.FixedBotRadii) / 40),
                })).ToList().AsReadOnly(),
                ShotUpdates = _shotsManager.Shots.Select(r => new ShotUpdate
                {
                    Position = r.Position,
                    Color    = r.Color
                }).ToList().AsReadOnly()
            };

            UpdateAvailable?.Invoke(this, new UpdateAvailableArgs {
                Update = update
            });
        }
        void OnTimerElapsed(object sender, ElapsedEventArgs e)
        {
            string output = null;

            if (Cache.concurrentDisplayUpdate.Count > 0)
            {
                DisplayUpdate d = Cache.concurrentDisplayUpdate[0];
                output = HelperMethods.Serialize <DisplayUpdate>(d);
            }
            else
            {
                output = "no data";
            }


            callBack.DisplayNotification(string.Format("Response: {0}\t Date: {1}", output, DateTime.Now.Ticks.ToString()));
        }
Пример #3
0
        public override void StartWatching()
        {
            var actualPath = Path.GetDirectoryName(Path.GetFullPath(Watch.Path));
            var binPath    = CsprojHelper.GetBinaryPath(actualPath);
            var outputDir  = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString()) + "\\";

            // Run Process Delegate
            WaitCallback runProcess = (o) =>
            {
                var process = new ProcessStartInfo()
                {
                    CreateNoWindow         = false,
                    WorkingDirectory       = actualPath,
                    UseShellExecute        = false,
                    RedirectStandardOutput = true,
                    RedirectStandardInput  = true,
                    RedirectStandardError  = true
                };

                if (Path.GetExtension(binPath) == ".exe")
                {
                    process.FileName = Path.Combine(outputDir, Path.GetFileName(binPath));
                }
                else
                {
                    process.FileName  = "dotnet";
                    process.Arguments = Path.Combine(outputDir, Path.GetFileName(binPath));
                }

                foreach (var env in Watch.Environment)
                {
                    process.Environment[env.Key] = env.Value;
                }

                if (!string.IsNullOrWhiteSpace(Watch.Args))
                {
                    process.Arguments = string.Join(" ", process.Arguments, Watch.Args);
                }

                var proc = Process.Start(process);
                proc.EnableRaisingEvents = true;
                RunningProcesses.GetOrAdd(Watch, proc);
                DisplayUpdate?.Invoke();
                proc.WaitForExit();
                RunningProcesses.TryRemove(Watch, out proc);

                if (Directory.Exists(outputDir))
                {
                    Directory.Delete(outputDir, true);
                }

                DisplayUpdate?.Invoke();
            };

            Watcher = new FileSystemWatcher(Path.GetDirectoryName(binPath), Path.GetFileName(binPath))
            {
                NotifyFilter = NotifyFilters.LastWrite
            };

            Watcher.Changed += (sender, e) =>
            {
                if (ShouldSkip?.Invoke() ?? false)
                {
                    return;
                }

                InvokeCallback?.Invoke();

                if (RunningProcesses.ContainsKey(Watch))
                {
                    RunningProcesses[Watch].Kill();
                }

                Thread.Sleep(500);
                Extensions.CloneDirectory(Path.GetDirectoryName(binPath), outputDir);
                ThreadPool.QueueUserWorkItem(runProcess);
            };

            Watcher.EnableRaisingEvents = true;

            if (!RunningProcesses.ContainsKey(Watch))
            {
                // Initial Run - we want to run at startup
                Extensions.CloneDirectory(Path.GetDirectoryName(binPath), outputDir);
                ThreadPool.QueueUserWorkItem(runProcess);
            }
        }
Пример #4
0
        } //validated

        private void Update()
        {
            this.ListAll();
            DisplayUpdate displayUpdate = new DisplayUpdate();
        }  //validated