Ejemplo n.º 1
0
        public void Add(ILetter letter)
        {
            if((letter.Options & LetterOptions.Ack) == LetterOptions.Ack)
                _batchOptions = LetterOptions.Ack;

            _letters.Enqueue(letter);
        }
Ejemplo n.º 2
0
 public Letter(LetterOptions options, byte[] userPart)
     : this()
 {
     Type = LetterType.User;
     Options = options;
     Parts = new[] {userPart};
 }
Ejemplo n.º 3
0
        public void Add(ILetter letter)
        {
            if ((letter.Options & LetterOptions.Ack) == LetterOptions.Ack)
            {
                _batchOptions = LetterOptions.Ack;
            }

            _letters.Enqueue(letter);
        }
Ejemplo n.º 4
0
        public IAnswerable <TReply> Send <TRequest, TReply>(TRequest value, LetterOptions options = LetterOptions.None)
        {
            Guid    conversationId = Guid.NewGuid();
            ILetter letter         = CreateLetter(value, options, conversationId);
            var     outstanding    = new BlockingOutstanding <TReply>(this);

            _outstandings.Add(conversationId, outstanding);
            _socket.Send(letter);

            try {
                outstanding.Wait();
            } finally {
                _outstandings.Remove(conversationId);
            }

            return(outstanding.Result);
        }
Ejemplo n.º 5
0
        private ILetter CreateLetter <T>(T value, LetterOptions options, Guid conversationId)
        {
            var metadata = new Metadata(value.GetType())
            {
                ConversationId = conversationId
            };

            var parts = new byte[2][];

            parts[0] = Serializer.Serialize(metadata);
            parts[1] = Serializer.Serialize(value);

            var letter = new Letter.Letter(options)
            {
                Type = LetterType.User, Parts = parts
            };

            return(letter);
        }
Ejemplo n.º 6
0
        internal void Answer <TRequest, TReply>(TRequest value, AbstractAnswerable answerable, LetterOptions options, AnswerCallback <TRequest, TReply> callback)
        {
            ILetter letter      = CreateLetter(value, options | LetterOptions.Ack, answerable.ConversationId);
            var     outstanding = new DelegateOutstanding <TRequest, TReply>(this, value, callback);

            _outstandings.Add(answerable.ConversationId, outstanding);

            _socket.SendTo(letter, answerable.RemoteNodeId);
        }
Ejemplo n.º 7
0
 internal void Answer <T>(T value, AbstractAnswerable answerable, LetterOptions options)
 {
     _socket.SendTo(CreateLetter(value, options, answerable.ConversationId), answerable.RemoteNodeId);
 }
Ejemplo n.º 8
0
        public void Send <TRequest, TReply>(TRequest request, AnswerCallback <TRequest, TReply> callback, LetterOptions options = LetterOptions.None)
        {
            Guid    conversationId = Guid.NewGuid();
            ILetter letter         = CreateLetter(request, options, conversationId);
            var     outstanding    = new DelegateOutstanding <TRequest, TReply>(this, request, callback);

            _outstandings.Add(conversationId, outstanding);

            _socket.Send(letter);
        }
Ejemplo n.º 9
0
 public void Send <T>(T value, LetterOptions options = LetterOptions.None)
 {
     _socket.Send(CreateLetter(value, options, Guid.NewGuid()));
 }
Ejemplo n.º 10
0
        public Stream GetLetter(LetterOptions options)
        {
            _stream = new MemoryStream();
            using (var renderer = _renderer)
            {
                var result = renderer.Configure(o =>
                {
                    o.Width  = options.Width;
                    o.Height = options.Height;
                })
                             .Render(bitmap =>
                {
                    // Create a graphics object for drawing.
                    var g           = Graphics.FromImage(bitmap);
                    g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
                    var rect        = new RectangleF(0, 0, options.Width, options.Height);

                    // Fill in the background.

                    var backBrush = new System.Drawing.Drawing2D.LinearGradientBrush(
                        rect,
                        options.BackColor.ToColor(Color.CornflowerBlue),
                        options.BackColor.ToColor(Color.CornflowerBlue),
                        System.Drawing.Drawing2D.LinearGradientMode.Horizontal);
                    g.FillRectangle(backBrush, rect);

                    // create solid dark brush
                    var gradBrushDark = new System.Drawing.Drawing2D.LinearGradientBrush(rect, Color.Black,
                                                                                         Color.Gray,
                                                                                         System.Drawing.Drawing2D.LinearGradientMode.Horizontal);

                    // Set up the text font.
                    SizeF size;
                    float fontSize = 200;
                    Font font      = null;
                    // Adjust the font size until the text fits within the image.
                    do
                    {
                        fontSize -= 1;
                        font      = new Font(options.FontFamily, fontSize, FontStyle.Bold);
                        size      = g.MeasureString(options.Letter.ToString(), font);
                    } while (size.Width > rect.Width);

                    // Set up the text format.
                    var format           = new StringFormat();
                    format.Alignment     = StringAlignment.Center;
                    format.LineAlignment = StringAlignment.Center;

                    // Create a path using the text and warp it randomly - nice :)
                    var path = new System.Drawing.Drawing2D.GraphicsPath();
                    path.AddString(options.Letter.ToString(),
                                   font.FontFamily,
                                   System.Convert.ToInt32(font.Style),
                                   font.Size,
                                   rect,
                                   format);
                    float v         = 8f;
                    PointF[] points =
                    {
                        new PointF((Int32)rect.Width / v,              (Int32)rect.Height / v),
                        new PointF(rect.Width - (Int32)rect.Width / v, (Int32)rect.Height / v),
                        new PointF((Int32)rect.Width / v,              rect.Height - (Int32)rect.Height / v),
                        new PointF(rect.Width - (Int32)rect.Width / v, rect.Height - (Int32)rect.Height / v)
                    };

                    var matrix = new System.Drawing.Drawing2D.Matrix();
                    matrix.Translate(0f, 0f);
                    path.Warp(points, rect, matrix, System.Drawing.Drawing2D.WarpMode.Perspective, 0f);

                    // Draw the letter
                    var foreBrush = new System.Drawing.Drawing2D.LinearGradientBrush(
                        rect,
                        Color.White,
                        Color.White,
                        System.Drawing.Drawing2D.LinearGradientMode.Horizontal);
                    g.FillPath(foreBrush, path);
                });

                result.Save(_stream, ImageFormat.Png);
            }

            return(_stream);
        }
Ejemplo n.º 11
0
 public Letter(LetterOptions options, byte[] userPart) : this()
 {
     Type    = LetterType.User;
     Options = options;
     Parts   = new[] { userPart };
 }
Ejemplo n.º 12
0
 public void Answer <TValue, TReply>(TValue value, LetterOptions options, Action <IAnswerable <TReply> > callback)
 {
     _socket.Answer(value, this, options | AnswerDefaultOptions);
 }
Ejemplo n.º 13
0
 public void Answer <T>(T value, LetterOptions options)
 {
     _socket.Answer(value, this, options | AnswerDefaultOptions);
 }
Ejemplo n.º 14
0
 public Letter(LetterOptions options)
     : this()
 {
     Options = options;
 }
Ejemplo n.º 15
0
        internal IAnswerable <TReply> Answer <TValue, TReply>(TValue value, AbstractAnswerable answerable, LetterOptions options)
        {
            ILetter letter      = CreateLetter(value, options, answerable.ConversationId);
            var     outstanding = new BlockingOutstanding <TReply>(this);

            _outstandings.Add(answerable.ConversationId, outstanding);

            _socket.SendTo(letter, answerable.RemoteNodeId);

            try {
                outstanding.Wait();
            } finally {
                _outstandings.Remove(answerable.ConversationId);
            }

            return(outstanding.Result);
        }
Ejemplo n.º 16
0
 public IAnswerable <TReply> Answer <TValue, TReply>(TValue value, LetterOptions options)
 {
     return(_socket.Answer <TValue, TReply>(value, this, options | AnswerDefaultOptions));
 }
Ejemplo n.º 17
0
 public Letter(LetterOptions options) : this()
 {
     Options = options;
 }