public override void GenerateLines(ILineWriter output)
 {
     for (var i = 1; i < Points.Length; i++)
     {
         output.Write(Points[i - 1], Points[i]);
     }
 }
예제 #2
0
 private WriteRequest(bool flushSentinel)
 {
     FlushSentinel = flushSentinel;
     Writer        = new NullWriter();
     Args          = new object();
     Activity      = default;
     Timestamp     = default;
 }
예제 #3
0
 public WriteRequest(ILineWriter writer, object args, Activity activity = null, DateTimeOffset?timestamp = null)
 {
     Writer    = writer;
     Args      = args;
     Activity  = activity;
     Timestamp = timestamp.GetValueOrDefault(DateTimeOffset.UtcNow).ToUnixTimeMilliseconds();
     Flush     = false;
 }
예제 #4
0
        /// <summary>
        /// Appends a line to given string builder and outputs that line to the console.
        /// </summary>
        /// <param name="stringBuilder"><see cref="StringBuilder"/> to append the line to</param>
        /// <param name="text">Line of text to append and output.  Default null will append blank line.</param>
        /// <param name="lineWriter">Will use <see cref="System.Console"/> if none provided</param>
        /// <returns><paramref name="stringBuilder"/> with line appended.</returns>
        public static StringBuilder AddLine(this StringBuilder stringBuilder, string text = null, ILineWriter lineWriter = null)
        {
            Validate.Begin()
                .IsNotNull(stringBuilder, "stringBuilder")
                .CheckForExceptions();

            var lineWriterToUse = lineWriter ?? ConsoleLineWriter.GetWriter();

            return AddLineImplementation(stringBuilder, text, lineWriterToUse);
        }
        public void EnumerateObstructionLinesInBounds (Bounds bounds, ILineWriter output) {
            SpatialCollection<LightObstructionBase>.ItemInfo ii;

            using (var e = Obstructions.GetItemsFromBounds(bounds, false))
            while (e.GetNext(out ii)) {
                if (!ii.Bounds.Intersects(bounds))
                    continue;

                ii.Item.GenerateLines(output);
            }
        }
예제 #6
0
        private static StringBuilder AddLineImplementation(StringBuilder stringBuilder, string text, ILineWriter lineWriter)
        {
            Debug.Assert(stringBuilder != null, "stringBuilder != null");
            Debug.Assert(lineWriter != null, "lineWriter != null");

            if (text.IsNullOrEmpty())
            {
                lineWriter.WriteLine();
                return stringBuilder.AppendLine();
            }
            lineWriter.WriteLine(text);
            return stringBuilder.AppendLine(text);
        }
예제 #7
0
        public void EnumerateObstructionLinesInBounds(Bounds bounds, ILineWriter output)
        {
            SpatialCollection <LightObstructionBase> .ItemInfo ii;

            using (var e = Obstructions.GetItemsFromBounds(bounds, false))
                while (e.GetNext(out ii))
                {
                    if (!ii.Bounds.Intersects(bounds))
                    {
                        continue;
                    }

                    ii.Item.GenerateLines(output);
                }
        }
예제 #8
0
        public async Task RunAsync(ILineReader reader, ILineWriter writer)
        {
            await using var enumerator = GetProcessedLinesAsync(reader).GetAsyncEnumerator();

            if (!await enumerator.MoveNextAsync())
            {
                return;
            }

            await writer.WriteAsync(enumerator.Current);

            while (await enumerator.MoveNextAsync())
            {
                await writer.AppendLineAsync(enumerator.Current);
            }
        }
예제 #9
0
 static void PrintHello(ILineWriter write)
 {
     write.WriteLine("Hello");
 }
예제 #10
0
 public override void GenerateLines (ILineWriter output) {
     for (var i = 1; i < Points.Length; i++)
         output.Write(Points[i - 1], Points[i]);
 }
예제 #11
0
 public override void GenerateLines (ILineWriter output) {
     output.Write(A, B);
 }
예제 #12
0
 public abstract void GenerateLines (ILineWriter output);
예제 #13
0
 public SimpleParsingErrorPrinter(TextWriter errorWriter)
 {
     errorLineWriter = new LineWriter(errorWriter);
 }
예제 #14
0
        /// <summary>
        /// Updates the world model by one SD timeslice.
        /// </summary>
        /// <param name="exec">The executive under which this update is being done.</param>
        /// <param name="manualResetEvent1">The manual reset event1.</param>
        /// <param name="manualResetEvent2">The manual reset event2.</param>
        internal void Update(IExecutive exec, ManualResetEvent manualResetEvent1 = null, ManualResetEvent manualResetEvent2 = null)
        {
            ILineWriter console = Locator.Resolve<ILineWriter>("console");
            m_governments.ForEach(n=>n.UpdateDiseaseNodes());
            bool travelOnlyFromToApparentlyDiseaseFree = NoAirTravelFromToKnownInfected;
            manualResetEvent1?.WaitOne();
            manualResetEvent2?.WaitOne();
            //DateTime now = DateTime.Now;
            DiseaseNode[,] newNodes = new DiseaseNode[m_mapData.Width, m_mapData.Height];
            // Progress the simulation one time step.

            int count1 = 0, count2 = 0;

#if AUTO_INOCULATE
            if (m_nodes[0, 0].TimeSliceNdx == 10 && m_districtsOfInterest != null)
            {
                {
                    foreach (var tuple in m_districtsOfInterest)
                    {
                        console.WriteLine($"Inoculating at {tuple.Item1},{tuple.Item2} with patient zero.");
                        m_nodes[tuple.Item1, tuple.Item2].ContagiousAsymptomatic++;
                        console.WriteLine(m_nodes[tuple.Item1, tuple.Item2]);
                    }
                }
            }
#endif

#if USE_PARALLEL
            Parallel.For(0, m_mapData.Width, x =>
            {
#else
            for (int x = 0; x < m_data.Width; x++)
            {
#endif
                for (int y = 0; y < m_mapData.Height; y++)
                {
                    if (!m_mapData.CellData[x, y].CellState.Equals(CellState.Occupied))
                    {
                        if (m_mapData.CellData[x, y].DiseaseModel.Population > 0) Debugger.Break();
                        newNodes[x, y] = m_nodes[x, y];
                        newNodes[x, y].TimeSliceNdx++;
                        Interlocked.Increment(ref count1);
                    }
                    else
                    {
                        //EpidemicNode.m_debug = (x == 243 && y == 240);
                        //if ( x== 243 && y == 240 && m_nodes[x, y].TimeSliceNdx == 63) Debugger.Break();
                        DiseaseNode oldNode = m_nodes[x, y];
                        DiseaseNode newNode = Behavior<DiseaseNode>.RunOneTimeslice(m_nodes[x, y]);
                        newNodes[x, y] = newNode;
                        if (oldNode.ContagiousAsymptomatic < EPSILON && newNode.ContagiousAsymptomatic > EPSILON)
                        {
                            ReportNewlyInfectedNode(new Coordinates() {X=x, Y=y});
                        }
                        Interlocked.Increment(ref count2);
                    }
                }

#if USE_PARALLEL
            });
#else
            } // Non-parallel.
 public LineWriterToLoggerAdaptor(ILineWriter lineWriter, LogLevel level = LogLevel.Information)
 {
     LogLevelSwitch = new LogLevelSwitch(level);
     _lineWriter    = lineWriter;
 }
 public LineWriterToLoggerAdaptor(ILineWriter lineWriter, LogLevel level = LogLevel.Information)
 {
     Level       = level;
     _lineWriter = lineWriter;
 }
예제 #17
0
        public void EnumerateObstructionLinesInBounds(Bounds bounds, ILineWriter output, ref bool cancel)
        {
            SpatialCollection<LightObstructionBase>.ItemInfo ii;

            using (var e = Obstructions.GetItemsFromBounds(bounds, false))
            while (e.GetNext(out ii)) {
                ii.Item.GenerateLines(output);

                if (cancel)
                    return;
            }
        }
예제 #18
0
 public static ILineWriter AddLinePrefix(this ILineWriter writer, string linePrefix)
 {
     return(new PrefixedLineWriter(writer, linePrefix));
 }
예제 #19
0
 public static Task WriteLines(this ILineWriter writer, params string[] lines)
 {
     return(writer.WriteLines(lines.AsEnumerable()));
 }
예제 #20
0
 public static Task WriteLines(this ILineWriter writer, IEnumerable <string> lines)
 {
     return(lines.Select(writer.WriteLine).Serialize());
 }
 public override void GenerateLines(ILineWriter output)
 {
     output.Write(A, B);
 }
예제 #22
0
 public PrefixedLineWriter(ILineWriter wrapped, string prefix)
 {
     this.wrapped = wrapped;
     this.prefix  = prefix;
 }
예제 #23
0
        private void LoadNewDefaultModelAndExtraStuff()
        {
            m_console = new DockableConsole("Log");
            Locator.Register(() => m_console, "console");

            List <OutbreakResponseTeam> orts = new List <OutbreakResponseTeam>();

            Dictionary <string, Tuple <int, Color> > ortCounts = new Dictionary <string, Tuple <int, Color> >();
            string  json = File.ReadAllText(@"Data/Governments.dat");
            dynamic d    = JObject.Parse(json);

            foreach (dynamic govt in d["Governments"])
            {
                string cc           = govt["cc"];
                int    numberOfORTs = govt["ORTs"];
                Color  color        = Color.FromName(govt["Color"].ToString());
                ortCounts.Add(cc, new Tuple <int, Color> (numberOfORTs, color));
            }

            WorldModel = new WorldModel(MapData.LoadFrom("Data/MapData.dat"), SimCountryData.LoadFrom("Data/CountryData.dat"), ortCounts);
            WorldModel.Executive.ClockAboutToChange += exec =>
            {
                DateTime newTime = ((IExecEvent)exec.EventList[0]).When;
                double   howMuch = 100 * (newTime - WorldModel.ExecutionParameters.StartTime).TotalHours /
                                   (WorldModel.ExecutionParameters.EndTime - WorldModel.ExecutionParameters.StartTime).TotalHours;

                m_statusStrip.InvokeIfRequired(strip =>
                {
                    ((ToolStripProgressBar)strip.Items["Progress"]).Value      = (int)howMuch;
                    ((ToolStripStatusLabel)strip.Items["DateTimeStatus"]).Text = newTime.ToString("dd MMM yyy HH:mm:ss");
                });
            };
            WorldModel.Controller.StateChanged += HandleStateChange;

            m_map = new DockableMap();
            m_map.AssignWorldModel(WorldModel);
            DockableTrendChart dc1 = new DockableTrendChart("Mortality");

            dc1.Bind(WorldModel,
                     new[]
            {
                GetTotal(n => n.Killed),
                GetTotal(n => n.Dead)
            },
                     new[]
            {
                "Killed",
                "Dead"
            });

            DockableTrendChart dc2 = new DockableTrendChart("Disease Stages");

            dc2.Bind(WorldModel,
                     new[]
            {
                GetTotal(n => n.ContagiousAsymptomatic),
                GetTotal(n => n.ContagiousSymptomatic),
                GetTotal(n => n.NonContagiousInfected),
                GetTotal(n => n.Immune),
            },
                     new[]
            {
                "ContagiousAsymptomatic",
                "ContagiousSymptomatic",
                "NonContagiousInfected",
                "Immune"
            });

            DockableRegionPieChart drpc1 = new DockableRegionPieChart("Nepal");

            drpc1.Bind(WorldModel, "NPL");
            drpc1.Show(m_dockPanel, DockState.DockLeft);

            DockableRegionPieChart drpc2 = new DockableRegionPieChart("Ireland");

            drpc2.Bind(WorldModel, "IRL");
            drpc2.Show(m_dockPanel, DockState.DockLeft);

            DockablePropertyGrid dpg = new DockablePropertyGrid()
            {
                SelectedObject = WorldModel.ExecutionParameters,
                TabText        = "Simulation Timing"
            };

            dpg.Show(m_dockPanel, DockState.DockLeft);

            DockablePropertyGrid country = new DockablePropertyGrid()
            {
                SelectedObject = WorldModel.CountryForCode("USA"),
                TabText        = "Selected Country",
                ToolTipText    = "Selected Country",
            };

            country.ToolbarVisible = false;
            m_map.CountrySelected += data => country.SelectedObject = data;

            m_map.MdiParent = this;
            m_map.Show(m_dockPanel, DockState.Document);
            ((DockableConsole)m_console).Show(m_dockPanel, DockState.DockBottom);
            country.Show(dpg.Pane, DockAlignment.Bottom, 0.6);
            dc1.Show(m_dockPanel, DockState.DockRight);
            dc2.Show(dc1.Pane, DockAlignment.Bottom, 0.5);
        }
예제 #24
0
 public StringLineWriter(string delimiter)
 {
     _stringWriter = new StringWriter();
     _innerWriter  = new LineWriter(_stringWriter, delimiter);
 }
 public MessageEncrypter(ILineReader lineReader, ILineWriter lineWriter)
 {
     this.lineReader = lineReader;
     this.lineWriter = lineWriter;
 }
예제 #26
0
 public TestLogBuilder(ILineWriter lineWriter, MethodInfo methodInfo)
 {
     _lineWriter = lineWriter;
 }
예제 #27
0
        private void CreateAndAssignGovernments()
        {
            m_allORTs = new List<OutbreakResponseTeam>();
            ILineWriter console = Locator.Resolve<ILineWriter>("console");
            Dictionary<string, List<Coordinates>> nodeToCountryMapping = new Dictionary<string, List<Coordinates>>();

            for (int x = 0; x < m_mapData.Width; x++)
            {
                for (int y = 0; y < m_mapData.Height; y++)
                {
                    DiseaseNode dn = m_nodes[x, y];
                    string cc = dn.MapCell.CountryCode;
                    if (cc != null && !"--".Equals(cc))
                    {
                        List<Coordinates> diseaseNodeCoordinates;
                        if (!nodeToCountryMapping.TryGetValue(cc, out diseaseNodeCoordinates))
                        {
                            diseaseNodeCoordinates = new List<Coordinates>();
                            nodeToCountryMapping.Add(cc, diseaseNodeCoordinates);
                        }
                        diseaseNodeCoordinates.Add(new Coordinates {X = x, Y = y});
                    }
                }
            }

            Dictionary<string, NationalGovernment> govts = new Dictionary<string, NationalGovernment>();
            for (int x = 0; x < m_mapData.Width; x++)
            {
                for (int y = 0; y < m_mapData.Height; y++)
                {
                    DiseaseNode dn = m_nodes[x, y];
                    string countryCode = dn.MapCell.CountryCode;
                    if ("--".Equals(countryCode)) continue;
                    if (countryCode == null) continue;
                    if (!m_countryDataByCountryCodes.ContainsKey(countryCode))
                    {
                        //console.WriteLine($"No country data for country code \"{countryCode}\".");
                        continue;
                    }
                    SimCountryData simCountryData = m_countryDataByCountryCodes[countryCode];
                    if (nodeToCountryMapping.ContainsKey(dn.MapCell.CountryCode))
                    {
                        if (!govts.ContainsKey(countryCode))
                        {
                            NationalGovernment ng = new NationalGovernment(this)
                            {
                                WorldModel = this,
                                SimCountryData = m_countryDataByCountryCodes[countryCode],
                                DiseaseNodeCoordinates = nodeToCountryMapping[countryCode]
                            };

                            if (m_ortCounts.ContainsKey(simCountryData.CountryCode))
                            {
                                var ortCount = m_ortCounts[simCountryData.CountryCode];
                                int numberOfResponseTeams = ortCount.Item1;
                                for (int i = 0; i < numberOfResponseTeams; i++)
                                {
                                    int randomDiseaseNode = m_random.Next(0, ng.DiseaseNodeCoordinates.Count - 1);
                                    Coordinates initialCoordinates = ng.DiseaseNodeCoordinates[randomDiseaseNode];
                                    OutbreakResponseTeam ort = 
                                        new OutbreakResponseTeam(simCountryData.CountryCode, i, ortCount.Item2, this, initialCoordinates);
                                    ng.ResponseTeams.Add(ort);
                                    simCountryData.ResponseTeams.Add(ort);
                                    m_allORTs.Add(ort);
                                }
                            }

                            simCountryData.Government = ng;
                            govts.Add(countryCode, ng);
                            ng.UpdateDiseaseNodes(true);
                        }
                    }
                    else
                    {
                        console.WriteLine($"Could not find a list of nodes for country code {simCountryData.CountryCode}");
                    }

                }
            }
            m_governments.AddRange(govts.Values);
        }
 public SentimentController(SentimentService sentimentService, ILineWriter lineWriter)
 {
     _sentimentService = sentimentService;
     _lineWriter       = lineWriter;
 }
 public abstract void GenerateLines(ILineWriter output);