Beispiel #1
0
        /// <summary>
        /// Create a new font instance by loading it from a resource.  Fonts take a lot of
        /// memory, your app should only load them once.
        /// </summary>
        /// <param name="fontResource">The resource that contains this font.</param>
        public OledFont(Enum fontResource)
        {
            var resourceId = fontResource;

            ResourceManager resourceManager = SailboatComputer.Properties.Resources.ResourceManager;

            byte[] fontData = (byte[])ResourceUtility.GetObject(resourceManager, resourceId, 0, 16);

            if (fontData[0] != 'O' && fontData[1] != 'l' && fontData[2] != 'e' && fontData[3] != 'd' &&
                fontData[4] != 'F' && fontData[5] != 'o' && fontData[6] != 'n' && fontData[7] != 't')
            {
                throw new IOException("invalid font");
            }

            // check version
            if (fontData[8] != 0x01 && fontData[9] != 0x00 && fontData[10] != 0x00 && fontData[11] != 0x00)
            {
                throw new IOException("invalid font version");
            }

            // get the cell height
            if (fontData[13] != 0 && fontData[14] != 0 && fontData[15] != 0)
            {
                throw new IOException("font too tall, max 255 supported");
            }
            this.m_height = fontData[12];

            int offset = 16;

            // load the width table
            this.m_characterWidthTable = (byte[])ResourceUtility.GetObject(resourceManager, resourceId, offset, 256);
            offset += 256;

            // load each character bitmap
            this.m_charBitmaps = new byte[256][];
            for (int i = 0; i < 256; i++)
            {
                if (this.m_characterWidthTable[i] != 0)
                {
                    // round up to the nearest even number.  We don't support odd sized widths
                    // since there are two pixels per byte.
                    int width = this.m_characterWidthTable[i];
                    width = ((width % 2) == 1 ? width + 1 : width);

                    int length = width * this.m_height / 2;
                    this.m_charBitmaps[i] = (byte[])ResourceUtility.GetObject(resourceManager, resourceId, offset, length);
                    offset += length;
                }
            }
        }
Beispiel #2
0
        private void MainThreadHandler()
        {
            listener = new HttpListener("http");
            bool abortRequested = false;

            listener.Start();

            //TODO: Threading verhaal nog te bekijken !!
            while (!abortRequested)
            {
                try
                {
                    Debug.Print("Webserver while loop beginning");
                    var context = listener.GetContext();
                    var path    = context.Request.Url.OriginalString;
                    var method  = context.Request.HttpMethod.HttpMethodParse();
                    //Debug.Print("Webserver incoming request : '" + url + "'");

                    WebResponse response = new NotFoundResponse(path);

                    if (routeList.Contains(method, path))
                    {
                        var route = routeList.Find(method, path);
                        if (route.IsFileResponse)
                        {
                            string content = (string)ResourceUtility.GetObject(resourceManager, route.FileResource);
                            response = new FileResponse(content, route.ContentType);
                        }
                        else
                        {
                            var webRequest = new WebRequest(context.Request);
                            response = route.RequestHandler(webRequest);
                        }
                    }

                    response.Respond(context);
                    context.Close();
                }
                catch (Exception exception)
                {
                    listener.Stop();
                    listener.Close();
                    abortRequested = true;
                }
            }
        }