Beispiel #1
0
        protected override void Process(System.Web.HttpContext context, ResourceManager resourceManager)
        {
            context.Response.ContentType = ContentTypes.Text.Plain;
            context.Response.StatusCode  = 200;

            string?sectorName = GetStringOption(context, "sector");
            string?type       = GetStringOption(context, "type");
            string?regex      = GetStringOption(context, "regex");
            string?milieu     = GetStringOption(context, "milieu");

            // NOTE: This (re)initializes a static data structure used for
            // resolving names into sector locations, so needs to be run
            // before any other objects (e.g. Worlds) are loaded.
            SectorMap.Flush();
            SectorMap map = SectorMap.GetInstance(resourceManager);

            var sectorQuery = from sector in map.Sectors
                              where (sectorName == null || sector.Names[0].Text.StartsWith(sectorName, ignoreCase: true, culture: CultureInfo.InvariantCulture)) &&
                              (sector.DataFile != null) &&
                              (type == null || sector.DataFile.Type == type) &&
                              (!sector.Tags.Contains("ZCR")) &&
                              (!sector.Tags.Contains("meta")) &&
                              (milieu == null || sector.CanonicalMilieu == milieu)
                              orderby sector.Names[0].Text
                              select sector;

            Dictionary <string, HashSet <string> > codes = new Dictionary <string, HashSet <string> >();

            Regex filter = new Regex(regex ?? ".*");

            foreach (var sector in sectorQuery)
            {
                WorldCollection?worlds = sector.GetWorlds(resourceManager, cacheResults: false);
                if (worlds == null)
                {
                    continue;
                }

                foreach (var code in worlds
                         .SelectMany(world => world.Codes)
                         .Where(code => filter.IsMatch(code) && !s_knownCodes.IsMatch(code)))
                {
                    if (!codes.ContainsKey(code))
                    {
                        codes.Add(code, new HashSet <string>());
                    }
                    codes[code].Add($"{sector.Names[0].Text} [{sector.CanonicalMilieu}]");
                }
            }

            foreach (var code in codes.Keys.OrderBy(s => s))
            {
                context.Response.Output.Write(code + " - ");
                foreach (var sector in codes[code].OrderBy(s => s))
                {
                    context.Response.Output.Write(sector + " ");
                }
                context.Response.Output.WriteLine("");
            }
        }
        private void Page_Load(object sender, System.EventArgs e)
        {
            if (!AdminAuthorized())
            {
                return;
            }

            Response.ContentType = MediaTypeNames.Text.Plain;

            ResourceManager resourceManager = new ResourceManager(Server, Cache);

            string sectorName = GetStringOption("sector");
            string type       = GetStringOption("type");

            // NOTE: This (re)initializes a static data structure used for
            // resolving names into sector locations, so needs to be run
            // before any other objects (e.g. Worlds) are loaded.
            SectorMap.Flush();
            SectorMap map = SectorMap.FromName(SectorMap.DefaultSetting, resourceManager);

            var sectorQuery = from sector in map.Sectors
                              where (sectorName == null || sector.Names[0].Text.StartsWith(sectorName, ignoreCase: true, culture: CultureInfo.InvariantCulture)) &&
                              (sector.DataFile != null) &&
                              (type == null || sector.DataFile.Type == type) &&
                              (sector.Tags.Contains("OTU"))
                              orderby sector.Names[0].Text
                              select sector;

            foreach (var sector in sectorQuery)
            {
                Response.Output.WriteLine(sector.Names[0].Text);
#if DEBUG
                WorldCollection worlds = sector.GetWorlds(resourceManager, cacheResults: false);

                if (worlds != null)
                {
                    Response.Output.WriteLine("{0} world(s)", worlds.Count());
                    foreach (string s in worlds.ErrorList.Where(s => candidate.IsMatch(s)))
                    {
                        Response.Output.WriteLine(s);
                    }
                }
                else
                {
                    Response.Output.WriteLine("{0} world(s)", 0);
                }
#endif
                Response.Output.WriteLine();
            }
            return;
        }
Beispiel #3
0
        private static void Flush(HttpContext context)
        {
            SectorMap.Flush();

            var enumerator = context.Cache.GetEnumerator();

            while (enumerator.MoveNext())
            {
                context.Cache.Remove(enumerator.Key.ToString());
            }

            Write(context.Response, "Sector map flushed.");
            Write(context.Response, "<b>&Omega;</b>");
        }
Beispiel #4
0
        protected override void Process(System.Web.HttpContext context)
        {
            context.Response.ContentType  = MediaTypeNames.Text.Plain;
            context.Response.BufferOutput = false;

            ResourceManager resourceManager = new ResourceManager(context.Server);

            string sectorName = GetStringOption(context, "sector");
            string type       = GetStringOption(context, "type");
            string milieu     = GetStringOption(context, "milieu");
            string tag        = GetStringOption(context, "tag");

            // NOTE: This (re)initializes a static data structure used for
            // resolving names into sector locations, so needs to be run
            // before any other objects (e.g. Worlds) are loaded.
            SectorMap.Flush();
            SectorMap map = SectorMap.GetInstance(resourceManager);

            var sectorQuery = from sector in map.Sectors
                              where (sectorName == null || sector.Names[0].Text.StartsWith(sectorName, ignoreCase: true, culture: CultureInfo.InvariantCulture)) &&
                              (sector.DataFile != null) &&
                              (type == null || sector.DataFile.Type == type) &&
                              (milieu == null || sector.CanonicalMilieu == milieu) &&
                              (tag == null || sector.Tags.Contains(tag)) &&
                              (sector.Tags.Contains("OTU") || sector.Tags.Contains("Apocryphal") || sector.Tags.Contains("Faraway"))
                              orderby sector.Names[0].Text
                              select sector;

            foreach (var sector in sectorQuery)
            {
                context.Response.Output.WriteLine(sector.Names[0].Text);
#if DEBUG
                WorldCollection worlds = sector.GetWorlds(resourceManager, cacheResults: false);

                if (worlds != null)
                {
                    double pop = worlds.Select(w => w.Population).Sum();
                    if (pop > 0)
                    {
                        context.Response.Output.WriteLine($"{worlds.Count()} world(s) - population: {pop / 1e9:#,###.##} billion");
                    }
                    else
                    {
                        context.Response.Output.WriteLine($"{worlds.Count()} world(s) - population: N/A");
                    }
                    worlds.ErrorList.Report(context.Response.Output);
                }
                else
                {
                    context.Response.Output.WriteLine("0 world(s)");
                }

                foreach (IAllegiance item in sector.Borders.AsEnumerable <IAllegiance>()
                         .Concat(sector.Routes.AsEnumerable <IAllegiance>())
                         .Concat(sector.Labels.AsEnumerable <IAllegiance>()))
                {
                    if (string.IsNullOrWhiteSpace(item.Allegiance))
                    {
                        continue;
                    }
                    if (sector.GetAllegianceFromCode(item.Allegiance) == null)
                    {
                        context.Response.Output.WriteLine($"Undefined allegiance code: {item.Allegiance} (on {item.GetType().Name})");
                    }
                }

                foreach (var route in sector.Routes)
                {
                    System.Drawing.Point startSector = sector.Location, endSector = sector.Location;
                    startSector.Offset(route.StartOffset);
                    endSector.Offset(route.EndOffset);

                    Location startLocation = new Location(startSector, route.Start);
                    Location endLocation   = new Location(endSector, route.End);
                    int      distance = Astrometrics.HexDistance(Astrometrics.LocationToCoordinates(startLocation),
                                                                 Astrometrics.LocationToCoordinates(endLocation));
                    if (distance == 0)
                    {
                        context.Response.Output.WriteLine($"Error: Route length {distance}: {route.ToString()}");
                    }
                    else if (distance > 4)
                    {
                        context.Response.Output.WriteLine($"Warning: Route length {distance}: {route.ToString()}");
                    }

                    /*
                     * This fails because of routes that use e.g. 3341-style coordinates
                     * It will also be extremely slow due to loading world lists w/o caching
                     *                  {
                     *                      var w = map.FromLocation(startSector).GetWorlds(resourceManager, cacheResults: false);
                     *                      if (w != null)
                     *                      {
                     *                          if (w[route.StartPoint.X, route.StartPoint.Y] == null)
                     *                              context.Response.Output.WriteLine($"Route start empty hex: {route.ToString()}");
                     *                      }
                     *                  }
                     *                  {
                     *                      var w = map.FromLocation(endSector).GetWorlds(resourceManager, cacheResults: false);
                     *                      if (w != null)
                     *                      {
                     *                          if (w[route.EndPoint.X, route.EndPoint.Y] == null)
                     *                              context.Response.Output.WriteLine($"Route end empty hex: {route.ToString()}");
                     *                      }
                     *                  }
                     */
                }
#endif
                context.Response.Output.WriteLine();
            }
            return;
        }
        protected override void Process(System.Web.HttpContext context, ResourceManager resourceManager)
        {
            context.Response.ContentType  = ContentTypes.Text.Plain;
            context.Response.BufferOutput = false;

            string sectorName   = GetStringOption(context, "sector");
            string type         = GetStringOption(context, "type");
            string milieu       = GetStringOption(context, "milieu");
            string tag          = GetStringOption(context, "tag");
            bool   hide_tl      = GetBoolOption(context, "hide-tl");
            bool   hide_gov     = GetBoolOption(context, "hide-gov");
            bool   hide_stellar = GetBoolOption(context, "hide-stellar");

            ErrorLogger.Severity severity = GetBoolOption(context, "warnings", true) ? 0 : ErrorLogger.Severity.Error;

            // NOTE: This (re)initializes a static data structure used for
            // resolving names into sector locations, so needs to be run
            // before any other objects (e.g. Worlds) are loaded.
            SectorMap.Flush();
            SectorMap map = SectorMap.GetInstance(resourceManager);

            var sectorQuery = from sector in map.Sectors
                              where (sectorName == null || sector.Names[0].Text.StartsWith(sectorName, ignoreCase: true, culture: CultureInfo.InvariantCulture)) &&
                              (sector.DataFile != null) &&
                              (type == null || sector.DataFile.Type == type) &&
                              (milieu == null || sector.CanonicalMilieu == milieu) &&
                              (tag == null || sector.Tags.Contains(tag)) &&
                              (sector.Tags.Contains("OTU") || sector.Tags.Contains("Apocryphal") || sector.Tags.Contains("Faraway"))
                              orderby sector.Names[0].Text
                              select sector;

            foreach (var sector in sectorQuery)
            {
                context.Response.Output.WriteLine($"{sector.Names[0].Text} - {sector.Milieu}");
#if DEBUG
                int error_count   = 0;
                int warning_count = 0;

                try
                {
                    WorldCollection worlds = sector.GetWorlds(resourceManager, cacheResults: false);
                    if (worlds != null)
                    {
                        double pop = worlds.Select(w => w.Population).Sum();
                        if (pop > 0)
                        {
                            context.Response.Output.WriteLine($"{worlds.Count()} world(s) - population: {pop / 1e9:#,###.##} billion");
                        }
                        else
                        {
                            context.Response.Output.WriteLine($"{worlds.Count()} world(s) - population: N/A");
                        }
                        worlds.ErrorList.Report(context.Response.Output, severity, (ErrorLogger.Record record) =>
                        {
                            if (hide_gov && (record.message.StartsWith("UWP: Gov") || record.message.StartsWith("Gov")))
                            {
                                return(false);
                            }
                            if (hide_tl && record.message.StartsWith("UWP: TL"))
                            {
                                return(false);
                            }
                            if (hide_stellar && record.message.StartsWith("Invalid stellar data:"))
                            {
                                return(false);
                            }
                            return(true);
                        });
                        error_count   += worlds.ErrorList.CountOf(ErrorLogger.Severity.Error);
                        warning_count += worlds.ErrorList.CountOf(ErrorLogger.Severity.Warning);
                    }
                    else
                    {
                        context.Response.Output.WriteLine("0 world(s)");
                    }
                }
                catch (ParseException ex)
                {
                    context.Response.Output.WriteLine($"Bad data file: {ex.Message}");
                }

                foreach (IAllegiance item in sector.Borders.AsEnumerable <IAllegiance>()
                         .Concat(sector.Routes.AsEnumerable <IAllegiance>())
                         .Concat(sector.Labels.AsEnumerable <IAllegiance>()))
                {
                    if (string.IsNullOrWhiteSpace(item.Allegiance))
                    {
                        continue;
                    }
                    if (sector.GetAllegianceFromCode(item.Allegiance) == null)
                    {
                        context.Response.Output.WriteLine($"Undefined allegiance code: {item.Allegiance} (on {item.GetType().Name})");
                    }
                }

                foreach (var route in sector.Routes)
                {
                    System.Drawing.Point startSector = sector.Location, endSector = sector.Location;
                    startSector.Offset(route.StartOffset);
                    endSector.Offset(route.EndOffset);

                    int distance = Astrometrics.HexDistance(
                        Astrometrics.LocationToCoordinates(new Location(startSector, route.Start)),
                        Astrometrics.LocationToCoordinates(new Location(endSector, route.End)));
                    if (distance == 0)
                    {
                        context.Response.Output.WriteLine($"Error: Route length {distance}: {route.ToString()}");
                        ++error_count;
                    }
                    else if (distance > 4)
                    {
                        if (severity <= ErrorLogger.Severity.Warning)
                        {
                            context.Response.Output.WriteLine($"Warning: Route length {distance}: {route.ToString()}");
                        }
                        ++warning_count;
                    }

                    /*
                     * This fails because of routes that use e.g. 3341-style coordinates
                     * It will also be extremely slow due to loading world lists w/o caching
                     *                  {
                     *                      var w = map.FromLocation(startSector).GetWorlds(resourceManager, cacheResults: false);
                     *                      if (w != null)
                     *                      {
                     *                          if (w[route.StartPoint.X, route.StartPoint.Y] == null)
                     *                              context.Response.Output.WriteLine($"Route start empty hex: {route.ToString()}");
                     *                      }
                     *                  }
                     *                  {
                     *                      var w = map.FromLocation(endSector).GetWorlds(resourceManager, cacheResults: false);
                     *                      if (w != null)
                     *                      {
                     *                          if (w[route.EndPoint.X, route.EndPoint.Y] == null)
                     *                              context.Response.Output.WriteLine($"Route end empty hex: {route.ToString()}");
                     *                      }
                     *                  }
                     */
                }
                context.Response.Output.WriteLine($"{error_count} errors, {warning_count} warnings.");
#endif
                context.Response.Output.WriteLine();
            }
            return;
        }
Beispiel #6
0
 private void Flush()
 {
     SectorMap.Flush();
     Write("Sector map flushed.");
     Write("<b>&Omega;</b>");
 }
Beispiel #7
0
        private void Page_Load(object sender, System.EventArgs e)
        {
            if (!AdminAuthorized())
            {
                return;
            }

            Response.ContentType = MediaTypeNames.Text.Plain;

            ResourceManager resourceManager = new ResourceManager(Server, Cache);

            string sectorName = GetStringOption("sector");
            string type       = GetStringOption("type");
            string regex      = GetStringOption("regex");

            // NOTE: This (re)initializes a static data structure used for
            // resolving names into sector locations, so needs to be run
            // before any other objects (e.g. Worlds) are loaded.
            SectorMap.Flush();
            SectorMap map = SectorMap.FromName(SectorMap.DefaultSetting, resourceManager);

            var sectorQuery = from sector in map.Sectors
                              where (sectorName == null || sector.Names[0].Text.StartsWith(sectorName, ignoreCase: true, culture: CultureInfo.InvariantCulture)) &&
                              (sector.DataFile != null) &&
                              (type == null || sector.DataFile.Type == type) &&
                              (!sector.DataFile.FileName.Contains(System.IO.Path.PathSeparator))    // Skip ZCR sectors
                              orderby sector.Names[0].Text
                              select sector;

            Dictionary <string, HashSet <string> > codes = new Dictionary <string, HashSet <string> >();

            Regex filter = (regex == null) ? new Regex(".*") : new Regex(regex);

            foreach (var sector in sectorQuery)
            {
                WorldCollection worlds = sector.GetWorlds(resourceManager, cacheResults: false);
                if (worlds == null)
                {
                    continue;
                }

                foreach (var code in worlds
                         .SelectMany(world => world.Codes)
                         .Where(code => filter.IsMatch(code) && !s_knownCodes.IsMatch(code)))
                {
                    if (!codes.ContainsKey(code))
                    {
                        HashSet <string> hash = new HashSet <string>();
                        hash.Add(sector.Names[0].Text);
                        codes.Add(code, hash);
                    }
                    else
                    {
                        codes[code].Add(sector.Names[0].Text);
                    }
                }
            }

            foreach (var code in codes.Keys.OrderBy(s => s))
            {
                Response.Output.Write(code + " - ");
                foreach (var sector in codes[code].OrderBy(s => s))
                {
                    Response.Output.Write(sector + " ");
                }
                Response.Output.WriteLine("");
            }
        }