private void Page_Load(object sender, System.EventArgs e)
        {
            // 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.
            ResourceManager resourceManager = new ResourceManager(Server, Cache);
            SectorMap       map             = SectorMap.FromName(SectorMap.DefaultSetting, resourceManager);

            Location loc = new Location(map.FromName("Spinward Marches").Location, 1910);

            // Accept either sector [& hex] or sx,sy [& hx,hy]
            if (HasOption("sector"))
            {
                string sectorName = GetStringOption("sector");
                Sector sector     = map.FromName(sectorName);
                if (sector == null)
                {
                    SendError(404, "Not Found", "Sector not found.");
                    return;
                }

                int hex = GetIntOption("hex", 0);
                loc = new Location(sector.Location, hex);
            }
            else if (HasOption("sx") && HasOption("sy"))
            {
                int sx = GetIntOption("sx", 0);
                int sy = GetIntOption("sy", 0);
                int hx = GetIntOption("hx", 0);
                int hy = GetIntOption("hy", 0);
                loc = new Location(map.FromLocation(sx, sy).Location, hx * 100 + hy);
            }
            else
            {
                SendError(404, "Not Found", "Must specify either sector name (and optional hex) or sx, sy (and optional hx, hy).");
                return;
            }

            Point coords = Astrometrics.LocationToCoordinates(loc);

            Result result = new Result();

            result.sx = loc.SectorLocation.X;
            result.sy = loc.SectorLocation.Y;
            result.hx = loc.HexLocation.X;
            result.hy = loc.HexLocation.Y;
            result.x  = coords.X;
            result.y  = coords.Y;
            SendResult(result);
        }
Beispiel #2
0
        private void Page_Load(object sender, System.EventArgs e)
        {
            if (!ServiceConfiguration.CheckEnabled("jumpworlds", Response))
            {
                return;
            }

            // 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.
            ResourceManager resourceManager = new ResourceManager(Server, Cache);

            //
            // Jump
            //
            int jump = Util.Clamp(GetIntOption("jump", 6), 0, 12);

            //
            // Coordinates
            //
            SectorMap map = SectorMap.FromName(SectorMap.DefaultSetting, resourceManager);
            Location  loc = new Location(map.FromName("Spinward Marches").Location, 1910);

            if (HasOption("sector") && HasOption("hex"))
            {
                string sectorName = GetStringOption("sector");
                int    hex        = GetIntOption("hex", 0);
                loc = new Location(map.FromName(sectorName).Location, hex);
            }
            else if (HasOption("sx") && HasOption("sy") && HasOption("hx") && HasOption("hy"))
            {
                int sx = GetIntOption("sx", 0);
                int sy = GetIntOption("sy", 0);
                int hx = GetIntOption("hx", 0);
                int hy = GetIntOption("hy", 0);
                loc = new Location(map.FromLocation(sx, sy).Location, hx * 100 + hy);
            }
            else if (HasOption("x") && HasOption("y"))
            {
                loc = Astrometrics.CoordinatesToLocation(GetIntOption("x", 0), GetIntOption("y", 0));
            }

            Selector selector = new HexSelector(map, resourceManager, loc, jump);

            Result data = new Result();

            data.Worlds.AddRange(selector.Worlds);
            SendResult(data);
        }
Beispiel #3
0
        private void Page_Load(object sender, System.EventArgs e)
        {
            if (!AdminAuthorized())
            {
                return;
            }

            ResourceManager resourceManager = new ResourceManager(Server, Cache);

            MapOptions options = MapOptions.SectorGrid | MapOptions.FilledBorders;

            Stylesheet.Style style = Stylesheet.Style.Poster;
            ParseOptions(ref options, ref style);

            double x        = -0.5;
            double y        = -0.5;
            double scale    = 2;
            Size   tileSize = new Size(1000, 1000);

            RectangleF tileRect = new RectangleF();

            tileRect.X      = (float)(x * tileSize.Width / (scale * Astrometrics.ParsecScaleX));
            tileRect.Y      = (float)(y * tileSize.Height / (scale * Astrometrics.ParsecScaleY));
            tileRect.Width  = (float)(tileSize.Width / (scale * Astrometrics.ParsecScaleX));
            tileRect.Height = (float)(tileSize.Height / (scale * Astrometrics.ParsecScaleY));

            DateTime dt = DateTime.Now;

            Render.RenderContext ctx = new Render.RenderContext();
            ctx.resourceManager = resourceManager;
            ctx.selector        = new RectSelector(
                SectorMap.FromName(SectorMap.DefaultSetting, resourceManager),
                resourceManager,
                tileRect);
            ctx.tileRect = tileRect;
            ctx.scale    = scale;
            ctx.options  = options;
            ctx.styles   = new Stylesheet(scale, options, style);
            ctx.tileSize = tileSize;
            ctx.silly    = false;
            ctx.tiling   = true;

            ctx.styles.microRoutes.visible       = true;
            ctx.styles.macroRoutes.visible       = false;
            ctx.styles.macroBorders.visible      = false;
            ctx.styles.microBorders.visible      = true;
            ctx.styles.capitals.visible          = false;
            ctx.styles.worlds.visible            = true;
            ctx.styles.worldDetails              = WorldDetails.Dotmap;
            ctx.styles.showAllSectorNames        = false;
            ctx.styles.showSomeSectorNames       = false;
            ctx.styles.macroNames.visible        = false;
            ctx.styles.pseudoRandomStars.visible = false;
            ctx.styles.fillMicroBorders          = true;

            ProduceResponse("Overview", ctx, tileSize);
        }
        private void Page_Load(object sender, System.EventArgs e)
        {
            if (!ServiceConfiguration.CheckEnabled("msec", Response))
            {
                return;
            }

            // 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.
            ResourceManager resourceManager = new ResourceManager(Server, Cache);
            SectorMap       map             = SectorMap.FromName(SectorMap.DefaultSetting, resourceManager);
            Sector          sector;

            if (HasOption("sx") && HasOption("sy"))
            {
                int sx = GetIntOption("sx", 0);
                int sy = GetIntOption("sy", 0);

                sector = map.FromLocation(sx, sy);

                if (sector == null)
                {
                    SendError(404, "Not Found", String.Format("The sector at {0},{1} was not found.", sx, sy));
                    return;
                }
            }
            else if (HasOption("sector"))
            {
                string sectorName = GetStringOption("sector");
                sector = map.FromName(sectorName);

                if (sector == null)
                {
                    SendError(404, "Not Found", String.Format("The specified sector '{0}' was not found.", sectorName));
                    return;
                }
            }
            else
            {
                SendError(404, "Not Found", "No sector specified.");
                return;
            }

            string data;

            using (var writer = new StringWriter())
            {
                new MSECSerializer().Serialize(writer, sector);
                data = writer.ToString();
            }

            SendResult(data);
        }
        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;
        }
        private void Page_Load(object sender, System.EventArgs e)
        {
            ResourceManager resourceManager = new ResourceManager(Server, Cache);

            MapOptions options = MapOptions.SectorGrid | MapOptions.BordersMajor | MapOptions.NamesMajor | MapOptions.NamesMinor;

            Stylesheet.Style style = Stylesheet.Style.Poster;
            ParseOptions(ref options, ref style);

            double x      = GetDoubleOption("x", 0);
            double y      = GetDoubleOption("y", 0);
            double scale  = Util.Clamp(GetDoubleOption("scale", 0), MinScale, MaxScale);
            int    width  = Util.Clamp(GetIntOption("w", NormalTileWidth), MinDimension, MaxDimension);
            int    height = Util.Clamp(GetIntOption("h", NormalTileHeight), MinDimension, MaxDimension);

            Size tileSize = new Size(width, height);

            RectangleF tileRect = new RectangleF();

            tileRect.X      = (float)(x * tileSize.Width / (scale * Astrometrics.ParsecScaleX));
            tileRect.Y      = (float)(y * tileSize.Height / (scale * Astrometrics.ParsecScaleY));
            tileRect.Width  = (float)(tileSize.Width / (scale * Astrometrics.ParsecScaleX));
            tileRect.Height = (float)(tileSize.Height / (scale * Astrometrics.ParsecScaleY));

            DateTime dt    = DateTime.Now;
            bool     silly = (Math.Abs((int)x % 2) == Math.Abs((int)y % 2)) && (dt.Month == 4 && dt.Day == 1);

            silly = GetBoolOption("silly", silly);

            Render.RenderContext ctx = new Render.RenderContext();
            ctx.resourceManager = resourceManager;
            ctx.selector        = new RectSelector(
                SectorMap.FromName(SectorMap.DefaultSetting, resourceManager),
                resourceManager,
                tileRect);
            ctx.tileRect = tileRect;
            ctx.scale    = scale;
            ctx.options  = options;
            ctx.styles   = new Stylesheet(scale, options, style);
            ctx.tileSize = tileSize;
            ctx.silly    = silly;
            ctx.tiling   = true;
            ProduceResponse("Tile", ctx, tileSize);
        }
        private void Page_Load(object sender, System.EventArgs e)
        {
            if (!AdminAuthorized())
            {
                return;
            }

            ResourceManager resourceManager = new ResourceManager(Server, Cache);

            // 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 map = SectorMap.FromName(SectorMap.DefaultSetting, resourceManager);

            Response.ContentType = MediaTypeNames.Text.Plain;

            foreach (Sector sector in map.Sectors)
            {
                WorldCollection worlds = sector.GetWorlds(resourceManager);
                if (worlds == null)
                {
                    continue;
                }
                foreach (World world in worlds)
                {
                    List <string> list = new List <string> {
                        sector.Names[0].Text,
                        sector.X.ToString(),
                        sector.Y.ToString(),
                        world.X.ToString(),
                        world.Y.ToString(),
                        world.Name,
                        world.UWP,
                        world.Bases,
                        world.Remarks,
                        world.PBG,
                        world.Allegiance,
                        world.Stellar
                    };
                    WriteCSV(list);
                }
            }
        }
Beispiel #8
0
        private void Page_Load(object sender, System.EventArgs e)
        {
            if (!ServiceConfiguration.CheckEnabled("universe", Response))
            {
                return;
            }

            ResourceManager resourceManager = new ResourceManager(Server, Cache);

            // 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 map = SectorMap.FromName(SectorMap.DefaultSetting, resourceManager);

            // Filter parameters
            string era         = GetStringOption("era");
            bool   requireData = GetBoolOption("requireData", defaultValue: false);

            Result data = new Result();

            foreach (Sector sector in map.Sectors)
            {
                if (requireData && sector.DataFile == null)
                {
                    continue;
                }

                if (era != null && (sector.DataFile == null || sector.DataFile.Era != era))
                {
                    continue;
                }

                SectorBase sb = new SectorBase(sector);
                data.Sectors.Add(sb);
            }

            SendResult(data);
        }
        private void Page_Load(object sender, System.EventArgs e)
        {
            if (!ServiceConfiguration.CheckEnabled("jumpmap", Response))
            {
                return;
            }

            // 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.
            ResourceManager resourceManager = new ResourceManager(Server, Cache);

            //
            // Jump
            //
            int jump = Util.Clamp(GetIntOption("jump", 6), 0, 12);

            //
            // Content & Coordinates
            //
            Selector selector;
            Location loc;

            if (Request.HttpMethod == "POST")
            {
                Sector sector;
                try
                {
                    sector = GetPostedSector();
                }
                catch (Exception ex)
                {
                    SendError(400, "Invalid request", ex.Message);
                    return;
                }

                if (sector == null)
                {
                    SendError(400, "Invalid request", "Either file or data must be supplied in the POST data.");
                    return;
                }

                int hex = GetIntOption("hex", Astrometrics.SectorCentralHex);
                loc      = new Location(new Point(0, 0), hex);
                selector = new HexSectorSelector(resourceManager, sector, loc.HexLocation, jump);
            }
            else
            {
                SectorMap map = SectorMap.FromName(SectorMap.DefaultSetting, resourceManager);

                if (HasOption("sector") && HasOption("hex"))
                {
                    string sectorName = GetStringOption("sector");
                    int    hex        = GetIntOption("hex", 0);
                    loc = new Location(map.FromName(sectorName).Location, hex);
                }
                else if (HasOption("sx") && HasOption("sy") && HasOption("hx") && HasOption("hy"))
                {
                    int sx = GetIntOption("sx", 0);
                    int sy = GetIntOption("sy", 0);
                    int hx = GetIntOption("hx", 0);
                    int hy = GetIntOption("hy", 0);
                    loc = new Location(map.FromLocation(sx, sy).Location, hx * 100 + hy);
                }
                else if (HasOption("x") && HasOption("y"))
                {
                    loc = Astrometrics.CoordinatesToLocation(GetIntOption("x", 0), GetIntOption("y", 0));
                }
                else
                {
                    loc = new Location(map.FromName("Spinward Marches").Location, 1910);
                }
                selector = new HexSelector(map, resourceManager, loc, jump);
            }


            //
            // Scale
            //
            double scale = Util.Clamp(GetDoubleOption("scale", 64), MinScale, MaxScale);

            //
            // Options & Style
            //
            MapOptions options = MapOptions.BordersMajor | MapOptions.BordersMinor | MapOptions.ForceHexes;

            Stylesheet.Style style = Stylesheet.Style.Poster;
            ParseOptions(ref options, ref style);

            //
            // Border
            //
            bool border = GetBoolOption("border", defaultValue: true);

            //
            // Clip
            //
            bool clip = GetBoolOption("clip", defaultValue: true);

            //
            // What to render
            //

            RectangleF tileRect = new RectangleF();

            Point coords = Astrometrics.LocationToCoordinates(loc);

            tileRect.X      = coords.X - jump - 1;
            tileRect.Width  = jump + 1 + jump;
            tileRect.Y      = coords.Y - jump - 1;
            tileRect.Height = jump + 1 + jump;

            // Account for jagged hexes
            tileRect.Y += (coords.X % 2 == 0) ? 0 : 0.5f;
            tileRect.Inflate(0.35f, 0.15f);

            Size tileSize = new Size((int)Math.Floor(tileRect.Width * scale * Astrometrics.ParsecScaleX), (int)Math.Floor(tileRect.Height * scale * Astrometrics.ParsecScaleY));


            // Construct clipping path
            List <Point> clipPath = new List <Point>(jump * 6 + 1);
            Point        cur      = coords;

            for (int i = 0; i < jump; ++i)
            {
                // Move J parsecs to the upper-left (start of border path logic)
                cur = Astrometrics.HexNeighbor(cur, 1);
            }
            clipPath.Add(cur);
            for (int dir = 0; dir < 6; ++dir)
            {
                for (int i = 0; i < jump; ++i)
                {
                    cur = Astrometrics.HexNeighbor(cur, (dir + 3) % 6); // Clockwise from upper left
                    clipPath.Add(cur);
                }
            }

            Stylesheet styles = new Stylesheet(scale, options, style);

            // If any names are showing, show them all
            if (styles.worldDetails.HasFlag(WorldDetails.KeyNames))
            {
                styles.worldDetails |= WorldDetails.AllNames;
            }

            // Compute path
            float[] edgeX, edgeY;
            RenderUtil.HexEdges(styles.microBorderStyle == MicroBorderStyle.Square ? PathUtil.PathType.Square : PathUtil.PathType.Hex,
                                out edgeX, out edgeY);
            PointF[] boundingPathCoords;
            byte[]   boundingPathTypes;
            PathUtil.ComputeBorderPath(clipPath, edgeX, edgeY, out boundingPathCoords, out boundingPathTypes);

            Render.RenderContext ctx = new Render.RenderContext();
            ctx.resourceManager = resourceManager;
            ctx.selector        = selector;
            ctx.tileRect        = tileRect;
            ctx.scale           = scale;
            ctx.options         = options;
            ctx.styles          = styles;
            ctx.tileSize        = tileSize;
            ctx.border          = border;

            ctx.clipPath = clip ? new XGraphicsPath(boundingPathCoords, boundingPathTypes, XFillMode.Alternate) : null;
            ProduceResponse("Jump Map", ctx, tileSize, transparent: clip);
        }
Beispiel #10
0
        private void Page_Load(object sender, System.EventArgs e)
        {
            if (!ServiceConfiguration.CheckEnabled("sec", Response))
            {
                return;
            }

            // 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.
            ResourceManager resourceManager = new ResourceManager(Server, Cache);
            SectorMap       map             = SectorMap.FromName(SectorMap.DefaultSetting, resourceManager);
            Sector          sector;

            if (HasOption("sx") && HasOption("sy"))
            {
                int sx = GetIntOption("sx", 0);
                int sy = GetIntOption("sy", 0);

                sector = map.FromLocation(sx, sy);

                if (sector == null)
                {
                    SendError(404, "Not Found", String.Format("The sector at {0},{1} was not found.", sx, sy));
                    return;
                }
            }
            else if (HasOption("sector"))
            {
                string sectorName = GetStringOption("sector");
                sector = map.FromName(sectorName);

                if (sector == null)
                {
                    SendError(404, "Not Found", String.Format("The specified sector '{0}' was not found.", sectorName));
                    return;
                }
            }
            else
            {
                SendError(404, "Not Found", "No sector specified.");
                return;
            }

            WorldFilter filter = null;

            if (HasOption("subsector"))
            {
                string ss = GetStringOption("subsector");
                filter = (World world) => (world.SS == ss);
            }

            bool includeMetadata = GetBoolOption("metadata", defaultValue: true);
            bool includeHeader   = GetBoolOption("header", defaultValue: true);

            string   mediaType = GetStringOption("type");
            Encoding encoding;;

            switch (mediaType)
            {
            case "SecondSurvey":
            case "TabDelimited":
                encoding = Util.UTF8_NO_BOM;
                break;

            default:
                encoding = Encoding.GetEncoding(1252);
                break;
            }


            string data;

            using (var writer = new StringWriter())
            {
                // Content
                //
                sector.Serialize(resourceManager, writer, mediaType, includeMetadata: includeMetadata, includeHeader: includeHeader, filter: filter);
                data = writer.ToString();
            }
            SendResult(data, encoding);
        }
        private void Page_Load(object sender, System.EventArgs e)
        {
            if (!ServiceConfiguration.CheckEnabled("credits", Response))
            {
                return;
            }

            ResourceManager resourceManager = new ResourceManager(Server, Cache);

            // 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 map = SectorMap.FromName(SectorMap.DefaultSetting, resourceManager);
            Location  loc = new Location(map.FromName("Spinward Marches").Location, 1910);

            if (HasOption("sector"))
            {
                string sectorName = GetStringOption("sector");
                Sector sec        = map.FromName(sectorName);
                if (sec == null)
                {
                    SendError(404, "Not Found", "Sector not found.");
                    return;
                }

                int hex = GetIntOption("hex", Astrometrics.SectorCentralHex);
                loc = new Location(sec.Location, hex);
            }
            else if (HasOption("sx") && HasOption("sy"))
            {
                int sx = GetIntOption("sx", 0);
                int sy = GetIntOption("sy", 0);
                int hx = GetIntOption("hx", 0);
                int hy = GetIntOption("hy", 0);
                loc = new Location(map.FromLocation(sx, sy).Location, hx * 100 + hy);
            }
            else if (HasOption("x") && HasOption("y"))
            {
                loc = Astrometrics.CoordinatesToLocation(GetIntOption("x", 0), GetIntOption("y", 0));
            }

            if (loc.HexLocation.IsEmpty)
            {
                loc.HexLocation = new Point(Astrometrics.SectorWidth / 2, Astrometrics.SectorHeight / 2);
            }

            Sector sector = map.FromLocation(loc.SectorLocation.X, loc.SectorLocation.Y);

            Result data = new Result();

            if (sector != null)
            {
                // TODO: Multiple names
                foreach (var name in sector.Names.Take(1))
                {
                    data.SectorName = name.Text;
                }

                // Raw HTML credits
                data.Credits = sector.Credits == null ? null : sector.Credits.Trim();

                // Product info
                if (sector.Products.Count > 0)
                {
                    data.ProductPublisher = sector.Products[0].Publisher;
                    data.ProductTitle     = sector.Products[0].Title;
                    data.ProductAuthor    = sector.Products[0].Author;
                    data.ProductRef       = sector.Products[0].Ref;
                }

                //
                // Sector Credits
                //
                if (sector.DataFile != null)
                {
                    data.SectorAuthor    = sector.DataFile.Author;
                    data.SectorSource    = sector.DataFile.Source;
                    data.SectorPublisher = sector.DataFile.Publisher;
                    data.SectorCopyright = sector.DataFile.Copyright;
                    data.SectorRef       = sector.DataFile.Ref;
                    data.SectorEra       = sector.DataFile.Era;
                }

                //
                // Subsector Credits
                //
                int       ssx = (loc.HexLocation.X - 1) / Astrometrics.SubsectorWidth;
                int       ssy = (loc.HexLocation.Y - 1) / Astrometrics.SubsectorHeight;
                int       ssi = ssx + ssy * 4;
                Subsector ss  = sector[ssi];
                if (ss != null)
                {
                    data.SubsectorIndex = ss.Index;
                    data.SubsectorName  = ss.Name;
                }

                //
                // Routes Credits
                //


                //
                // World Data
                //
                WorldCollection worlds = sector.GetWorlds(resourceManager);
                if (worlds != null)
                {
                    World world = worlds[loc.HexLocation.X, loc.HexLocation.Y];
                    if (world != null)
                    {
                        data.WorldName       = world.Name;
                        data.WorldHex        = world.Hex.ToString("0000", CultureInfo.InvariantCulture);
                        data.WorldUwp        = world.UWP;
                        data.WorldRemarks    = world.Remarks;
                        data.WorldIx         = world.Importance;
                        data.WorldEx         = world.Economic;
                        data.WorldCx         = world.Cultural;
                        data.WorldPbg        = world.PBG;
                        data.WorldAllegiance = world.Allegiance;
                    }
                }
            }

            SendResult(data);
        }
Beispiel #12
0
        private void Page_Load(object sender, System.EventArgs e)
        {
            if (!ServiceConfiguration.CheckEnabled("poster", Response))
            {
                return;
            }

            // 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.
            ResourceManager resourceManager = new ResourceManager(Server, Cache);

            Selector   selector;
            RectangleF tileRect = new RectangleF();
            MapOptions options  = MapOptions.SectorGrid | MapOptions.SubsectorGrid | MapOptions.BordersMajor | MapOptions.BordersMinor | MapOptions.NamesMajor | MapOptions.NamesMinor | MapOptions.WorldsCapitals | MapOptions.WorldsHomeworlds;

            Stylesheet.Style style = Stylesheet.Style.Poster;
            ParseOptions(ref options, ref style);
            string title;

            if (HasOption("x1") && HasOption("x2") &&
                HasOption("y1") && HasOption("y2"))
            {
                // Arbitrary rectangle

                int x1 = GetIntOption("x1", 0);
                int x2 = GetIntOption("x1", 0);
                int y1 = GetIntOption("x1", 0);
                int y2 = GetIntOption("x1", 0);

                tileRect.X      = Math.Min(x1, x2);
                tileRect.Y      = Math.Min(y1, y2);
                tileRect.Width  = Math.Max(x1, x2) - tileRect.X;
                tileRect.Height = Math.Max(y1, y2) - tileRect.Y;

                SectorMap map = SectorMap.FromName(SectorMap.DefaultSetting, resourceManager);
                selector      = new RectSelector(map, resourceManager, tileRect);
                selector.Slop = false;

                tileRect.Offset(-1, -1);
                tileRect.Width  += 1;
                tileRect.Height += 1;

                title = String.Format("Poster ({0},{1}) - ({2},{3})", x1, y1, x2, y2);
            }
            else
            {
                // Sector - either POSTed or specified by name
                Sector sector = null;
                options = options & ~MapOptions.SectorGrid;

                if (Request.HttpMethod == "POST")
                {
                    try
                    {
                        sector = GetPostedSector();
                    }
                    catch (Exception ex)
                    {
                        SendError(400, "Invalid request", ex.Message);
                        return;
                    }

                    if (sector == null)
                    {
                        SendError(400, "Invalid request", "Either file or data must be supplied in the POST data.");
                        return;
                    }

                    title = "User Data";
                }
                else
                {
                    string sectorName = GetStringOption("sector");
                    if (sectorName == null)
                    {
                        SendError(404, "Not Found", "No sector specified.");
                        return;
                    }

                    SectorMap map = SectorMap.FromName(SectorMap.DefaultSetting, resourceManager);

                    sector = map.FromName(sectorName);
                    if (sector == null)
                    {
                        SendError(404, "Not Found", String.Format("The specified sector '{0}' was not found.", sectorName));
                        return;
                    }

                    title = sector.Names[0].Text;
                }

                if (HasOption("subsector") && GetStringOption("subsector").Length > 0)
                {
                    options = options & ~MapOptions.SubsectorGrid;
                    char ss = GetStringOption("subsector").ToUpperInvariant()[0];
                    if (ss < 'A' || ss > 'P')
                    {
                        SendError(400, "Invalid subsector", String.Format("The subsector index '{0}' is not valid (must be A...P).", ss));
                        return;
                    }

                    int index = (int)(ss) - (int)('A');
                    selector = new SubsectorSelector(resourceManager, sector, index);

                    tileRect = sector.SubsectorBounds(index);

                    options &= ~(MapOptions.SectorGrid | MapOptions.SubsectorGrid);

                    title = String.Format("{0} - Subsector {1}", title, ss);
                }
                else
                {
                    selector = new SectorSelector(resourceManager, sector);
                    tileRect = sector.Bounds;

                    options &= ~(MapOptions.SectorGrid);
                }

                // Account for jagged hexes
                tileRect.X      -= 0.25f;
                tileRect.Width  += 0.5f;
                tileRect.Height += 0.5f;

                if (style == Stylesheet.Style.Candy)
                {
                    tileRect.Width += 0.75f;
                }
            }

            const double NormalScale = 64; // pixels/parsec - standard subsector-rendering scale
            double       scale       = Util.Clamp(GetDoubleOption("scale", NormalScale), MinScale, MaxScale);

            int rot = GetIntOption("rotation", 0) % 4;

            Size tileSize = new Size((int)Math.Floor(tileRect.Width * scale * Astrometrics.ParsecScaleX), (int)Math.Floor(tileRect.Height * scale * Astrometrics.ParsecScaleY));

            int   bitmapWidth = tileSize.Width, bitmapHeight = tileSize.Height;
            float translateX = 0, translateY = 0, angle = rot * 90;

            switch (rot)
            {
            case 1:     // 90 degrees clockwise
                bitmapWidth = tileSize.Height; bitmapHeight = tileSize.Width;
                translateX  = bitmapWidth;
                break;

            case 2:     // 180 degrees
                translateX = tileSize.Width; translateY = tileSize.Height;
                break;

            case 3:     // 270 degrees clockwise
                bitmapWidth = tileSize.Height; bitmapHeight = tileSize.Width;
                translateY  = bitmapHeight;
                break;
            }

            Render.RenderContext ctx = new Render.RenderContext();
            ctx.resourceManager = resourceManager;
            ctx.selector        = selector;
            ctx.tileRect        = tileRect;
            ctx.scale           = scale;
            ctx.options         = options;
            ctx.styles          = new Stylesheet(scale, options, style);
            ctx.tileSize        = tileSize;
            ProduceResponse(title, ctx, new Size(bitmapWidth, bitmapHeight), rot, translateX, translateY);
        }
Beispiel #13
0
        private void BtnSearch_Click(object sender, System.EventArgs e)
        {
            // ViewState should be pay-for-play - it's enabled on first search
            Form1.EnableViewState = true;

            string query = TextBoxSearch.Text;

            if (String.IsNullOrEmpty(query))
            {
                return;
            }

            ResourceManager resourceManager = new ResourceManager(Server, Cache);
            SectorMap       map             = SectorMap.FromName(SectorMap.DefaultSetting, resourceManager);

            IEnumerable <ItemLocation> results = SearchEngine.PerformSearch(query, resourceManager, SearchEngine.SearchResultsType.Default, 20);

            DataTable dt = new DataTable();

            dt.Locale = CultureInfo.InvariantCulture;
            dt.Columns.Add(new DataColumn("Name", typeof(string)));
            dt.Columns.Add(new DataColumn("Details", typeof(string)));
            dt.Columns.Add(new DataColumn("Data", typeof(string)));

            if (results != null)
            {
                foreach (object o in results)
                {
                    StringWriter sw = new StringWriter(CultureInfo.InvariantCulture);
                    // NOTE: Serialize explicitly using base class, so deserialization handles heterogenous types
                    XmlSerializer xs = new XmlSerializer(typeof(ItemLocation));
                    xs.Serialize(sw, o);
                    string xml = sw.ToString();

                    DataRow dr = dt.NewRow();
                    if (o is WorldLocation)
                    {
                        Sector sector;
                        World  world;
                        ((WorldLocation)o).Resolve(map, resourceManager, out sector, out world);

                        dr[0] = world.Name;
                        dr[1] = String.Format(CultureInfo.InvariantCulture, "{0} {1}", sector.Names[0].Text, world.Hex.ToString("0000", CultureInfo.InvariantCulture));
                        dr[2] = xml;
                    }
                    else if (o is SubsectorLocation)
                    {
                        Sector    sector;
                        Subsector subsector;
                        ((SubsectorLocation)o).Resolve(map, out sector, out subsector);

                        dr[0] = subsector.Name;
                        dr[1] = String.Format(CultureInfo.InvariantCulture, "Subsector {1} of {0}", sector.Names[0].Text, subsector.Index);
                        dr[2] = xml;
                    }
                    else if (o is SectorLocation)
                    {
                        Sector sector = ((SectorLocation)o).Resolve(map);

                        dr[0] = sector.Names[0].Text;
                        dr[1] = "Sector";
                        dr[2] = xml;
                    }
                    dt.Rows.Add(dr);
                }

                LabelNoResults.Visible = false;
            }
            else
            {
                LabelNoResults.Visible = true;
                LabelNoResults.Text    = "No matches found";
            }

            this.ResultsDataList.DataSource = new DataView(dt);
            this.ResultsDataList.DataBind();
        }
        private void Page_Load(object sender, System.EventArgs e)
        {
            if (!ServiceConfiguration.CheckEnabled("search", Response))
            {
                return;
            }

            string query = Request.QueryString["q"];

            if (query == null)
            {
                return;
            }

            // Look for special searches
            var index = Array.FindIndex(SpecialSearchTerms, s => String.Compare(s, query, ignoreCase: true, culture: CultureInfo.InvariantCulture) == 0);

            if (index != -1)
            {
                if (Request.QueryString["jsonp"] != null)
                {
                    // TODO: Does this include the JSONP headers?
                    SendFile(JsonConstants.MediaType, SpecialSearchResultsJson[index]);
                    return;
                }

                foreach (var type in AcceptTypes)
                {
                    if (type == JsonConstants.MediaType)
                    {
                        SendFile(JsonConstants.MediaType, SpecialSearchResultsJson[index]);
                        return;
                    }
                    if (type == MediaTypeNames.Text.Xml)
                    {
                        SendFile(MediaTypeNames.Text.Xml, SpecialSearchResultsXml[index]);
                        return;
                    }
                }
                SendFile(MediaTypeNames.Text.Xml, SpecialSearchResultsXml[index]);
                return;
            }

            //
            // Do the search
            //
            ResourceManager resourceManager = new ResourceManager(Server, Cache);
            SectorMap       map             = SectorMap.FromName(SectorMap.DefaultSetting, resourceManager);

            query = query.Replace('*', '%'); // Support * and % as wildcards
            query = query.Replace('?', '_'); // Support ? and _ as wildcards

            if (UWP_REGEXP.IsMatch(query))
            {
                query = "uwp:" + query;
            }

            var searchResults = SearchEngine.PerformSearch(query, resourceManager, SearchEngine.SearchResultsType.Default, 160);

            Results resultsList = new Results();

            if (searchResults != null)
            {
                resultsList.AddRange(searchResults
                                     .Select(loc => Results.LocationToSearchResult(map, resourceManager, loc))
                                     .OfType <Results.SearchResultItem>());
            }

            SendResult(resultsList);
        }
Beispiel #15
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("");
            }
        }