Exemple #1
0
        void CreateLinesIfNeeded()
        {
            if (settings.NumberOfLines != numberOfLines &&
                (settings.NumberOfLines > 0 && settings.NumberOfLines <= MaxHandleLines))
            {
                numberOfLines = settings.NumberOfLines;

                // Constructing array of handle lines

                var deltaAngle = (float)(2 * Math.PI) / numberOfLines;
                int i          = 0;

                for (float d = 0; d < 2 * Math.PI; d += deltaAngle)
                {
                    var handleLine = new HandleLine(d);

                    // Mark already visited lines
                    if (d < angle)
                    {
                        handleLine.timesVisited = timesCircled;
                    }

                    lines[i++] = handleLine;
                }
            }
        }
Exemple #2
0
        private void CreateHandlers(IModel shape)
        {
            if (LastShape != null)
            {
                LastShape.RemoveHandle();
            }

            HandleCursor    cursor    = new HandleCursor();
            HandlePencil    pencil    = new HandlePencil();
            HandleLine      line      = new HandleLine();
            HandleEllipse   ellipse   = new HandleEllipse();
            HandleRectangle rectangle = new HandleRectangle();
            HandleBezier    bezier    = new HandleBezier();

            HandleFill fill = new HandleFill();

            HandleImage image = new HandleImage();

            cursor.Successor    = pencil;
            pencil.Successor    = line;
            line.Successor      = ellipse;
            ellipse.Successor   = rectangle;
            rectangle.Successor = bezier;
            bezier.Successor    = fill;
            fill.Successor      = image;

            cursor.Handle(shape);
        }
        private HttpHeader Request(Uri uri, Uri referrer, string method, HandleLine lineHandler)
        {
            if (uri == null)
                return null;

            TcpClient client = new TcpClient();
            IPAddress ip = DNSHelper.ResolveUri(DNSResolver, uri).First();

            try
            {
                client.Connect(ip, uri.Port);
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                return null;
            }

            //Send Request
            TextWriter tw = new StreamWriter(client.GetStream());
            tw.WriteLine(method + " " + uri.AbsolutePath + " " + ProtocolString);
            tw.WriteLine("Host: " + uri.Host);
            tw.WriteLine("User-Agent: " + UserAgent);
            tw.WriteLine("Connection: close");
            if (referrer != null)
            {
                tw.WriteLine("Referer: " + referrer.AbsoluteUri);
            }
            tw.WriteLine();
            tw.Flush();


            TextReader document = new StreamReader(client.GetStream());
            var header = ParseHeader(document);

            if (lineHandler != null)
            {
                string line;
                try
                {
                    while ((line = document.ReadLine()) != null)
                    {
                        lineHandler.Invoke(line, uri);
                    }
                }
                catch (Exception e)
                {
                    Console.WriteLine(e);
                }
            }

            client.Close();
            return header;
        }
 public HttpHeader GetDocument(Uri uri, Uri referrer = null, HandleLine lineHandler = null)
 {
     return Request(uri, referrer, "GET", lineHandler);
 }