Esempio n. 1
0
        public static void GenerateFunctionBoxWithPreview(
            HttpContext context, 
            string functionTitle, 
            Bitmap previewImage,
            bool showEditButton, 
            Stream outputStream)
        {
            using (var header = new FunctionHeader(functionTitle, false, showEditButton))
            {
                var headerSize = header.HeaderSize;

                Size totalSize = new Size(Math.Max(header.HeaderSize.Width, previewImage.Width), headerSize.Height + previewImage.Height);

                using (var bitmap = new Bitmap(totalSize.Width, totalSize.Height))
                using (var graphics = Graphics.FromImage(bitmap))
                {
                    header.DrawHeader(bitmap, graphics, totalSize.Width);

                    Point previewImageOffset = new Point(
                        (Math.Max(totalSize.Width - 10, previewImage.Width) - previewImage.Width) / 2, headerSize.Height);

                    // Preview image
                    graphics.DrawImage(previewImage, previewImageOffset);

                    // Image outline
                    using (var brush = new HatchBrush(HatchStyle.LargeCheckerBoard, Color.FromArgb(190, 190, 190), Color.Transparent))
                    using (var pen = new Pen(brush))
                    {
                        graphics.DrawRectangle(pen, new Rectangle(previewImageOffset,
                            new Size(previewImage.Width - 1, previewImage.Height - 1)));
                    }

                    context.Response.ContentType = "image/png";
                    context.Response.Cache.SetExpires(DateTime.Now.AddDays(10));

                    string tempFileName = Path.GetTempFileName();

                    try
                    {
                        // Saving to a temporary file, as Image.Save() sometimes on a not seekable stream throws
                        // an "A generic error occurred in GDI+." exception
                        bitmap.Save(tempFileName, ImageFormat.Png);

                        context.Response.WriteFile(tempFileName);
                        context.Response.Flush();
                    }
                    finally
                    {
                        C1File.Delete(tempFileName);
                    }
                }
            }
        }
Esempio n. 2
0
        public void OnFunctionReady(FunctionHeader function_header)
        {
            var function = _functionRepository.Get(new[] { function_header }).FirstOrDefault();

            if (function == null)
            {
                _functionRepository.Subscribe(new[] { function_header }, OnFunctionReady);
            }
            else
            {
                if (_preparingCommands.TryGetValue(function_header.Token, out Command command))
                {
                    command.Function = function;
                    if (command.InputData.All(x => x.HasValue != null) && command.Function != null)
                    {
                        if (_preparingCommands.TryRemove(function_header.Token, out command))
                        {
                            OnPreparedCommand(command);
                        }
                    }
                }
            }
        }
Esempio n. 3
0
 public FunctionInfo(FunctionHeader header)
 {
     Signature  = header.Signature;
     ReturnType = header.ReturnType;
 }
        public static void GenerateFunctionBoxWithText(
            HttpContext context,
            string functionTitle,
            bool isWarning,
            bool showEditButton,
            ICollection <string> lines,
            Stream outputStream)
        {
            using (var header = new FunctionHeader(functionTitle, isWarning, showEditButton))
            {
                var headerSize = header.HeaderSize;

                const int minTextAreaWidth = 350;
                const int leftPadding = 14, rightPadding = 10, topPadding = 12, bottomPadding = 10;

                var linesTrimmed = lines.Take(20).ToList();

                using (var textFont = new Font("Helvetica", 9.5f, FontStyle.Regular))
                {
                    int lineHeight = MeasureText("Text", textFont).Height;

                    Size totalSize = new Size(Math.Max(headerSize.Width, minTextAreaWidth),
                                              headerSize.Height + topPadding + lineHeight * linesTrimmed.Count + bottomPadding);

                    using (var bitmap = new Bitmap(totalSize.Width, totalSize.Height))
                        using (var graphics = Graphics.FromImage(bitmap))
                        {
                            graphics.Clear(Color.White);

                            header.DrawHeader(bitmap, graphics, totalSize.Width);

                            using (var solidBrush = new SolidBrush(Color.Gray))
                                for (int i = 0; i < linesTrimmed.Count; i++)
                                {
                                    var line  = linesTrimmed[i];
                                    int lineY = headerSize.Height + topPadding + i * lineHeight;

                                    int maxLineWidth = totalSize.Width - leftPadding - rightPadding;

                                    string croppedLine = CropLineToFitMaxWidth(line, textFont, maxLineWidth);

                                    graphics.DrawString(croppedLine, textFont, solidBrush, leftPadding, lineY);
                                }

                            // Text outline
                            using (var pen = new Pen(isWarning ? Color.Red : Color.Gray))
                            {
                                graphics.DrawRectangle(pen, new Rectangle(0, headerSize.Height,
                                                                          totalSize.Width - 1, totalSize.Height - headerSize.Height - 1));
                            }

                            context.Response.ContentType = "image/png";
                            context.Response.Cache.SetExpires(DateTime.Now.AddDays(10));

                            string tempFileName = Path.GetTempFileName();

                            try
                            {
                                // Saving to a temporary file, as Image.Save() sometimes on a not seekable stream throws
                                // an "A generic error occurred in GDI+." exception
                                bitmap.Save(tempFileName, ImageFormat.Png);

                                context.Response.WriteFile(tempFileName);
                                context.Response.Flush();
                            }
                            finally
                            {
                                C1File.Delete(tempFileName);
                            }
                        }
                }
            }
        }
Esempio n. 5
0
 public Var <T> NewCommand(FunctionHeader fucntion_header, params IVarInterface[] input_data)
 {
     Id = _commandBuilder.NewCommand(fucntion_header, input_data.Select(x => x.Id));
     return(this);
 }
Esempio n. 6
0
        ExpressionizeResult CreateAtom()
        {
            if (currentToken == null)
            {
                return(ExpressionizeResult.NewError(ErrorInfo.ExpectExpression));
            }

            if (currentToken.Type == TokenType.Constant)
            {
                Constant constant = (Constant)currentToken;
                GetNextToken();

                // Create a new constant expression.
                ConstantExpression constantExpression = new ConstantExpression(constant.Value);
                return(ExpressionizeResult.NewSuccess(constantExpression));
            }
            else if (currentToken.Type == TokenType.Variable)
            {
                Variable variable = (Variable)currentToken;
                GetNextToken();

                // Create a new argument expression.
                VariableExpression argumentExpression = new VariableExpression(variable.Name);
                return(ExpressionizeResult.NewSuccess(argumentExpression));
            }
            else if (TokenType.UnaryOperator.HasFlag(currentToken.Type))
            {
                UnaryType unaryType = currentToken.Type.ToUnaryType();

                GetNextToken();
                // Since unary operator is left associative, we add 1 to the base precedence.
                ExpressionizeResult childResult = CreateExpression(unaryType.GetPrecedence() + 1);

                if (!childResult.Success)
                {
                    return(childResult);
                }

                Expression childExpression = childResult.CalculatedExpression;

                // Create a new unary expression.
                UnaryExpression unaryExpression = new UnaryExpression(childExpression, unaryType);
                return(ExpressionizeResult.NewSuccess(unaryExpression));
            }
            else if (currentToken.Type == TokenType.ParenLeft)
            {
                GetNextToken();
                // Try to make a sub-expression enclosed by this left parenthesis.
                ExpressionizeResult subResult = CreateExpression(MinOperatorPrecedence);

                if (!subResult.Success)
                {
                    return(subResult);
                }

                Expression subExpression = subResult.CalculatedExpression;

                // Expect a matching right parenthesis.
                if (currentToken != null && currentToken.Type == TokenType.ParenRight)
                {
                    GetNextToken();
                    return(ExpressionizeResult.NewSuccess(subExpression));
                }
                else
                {
                    return(ExpressionizeResult.NewError(ErrorInfo.ExpectRightParen));
                }
            }
            else if (currentToken.Type == TokenType.Function)
            {
                // A function has two parts:
                // - An identifier(name)
                // - Its arguments enclosed in a pair of parens.

                FunctionHeader    functionHeader = (FunctionHeader)currentToken;
                List <Expression> argumentsList  = new List <Expression>();

                GetNextToken();

                if (currentToken != null && currentToken.Type == TokenType.ParenLeft)
                {
                    GetNextToken();

                    // Only create expressions for each argument if the function requires any.
                    if (functionHeader.ArgumentCount > 0)
                    {
                        // NOTE: Handle multiple args here.
                        ExpressionizeResult argumentResult = CreateExpression(MinOperatorPrecedence);

                        if (!argumentResult.Success)
                        {
                            return(argumentResult);
                        }

                        argumentsList.Add(argumentResult.CalculatedExpression);
                    }

                    if (currentToken != null && currentToken.Type == TokenType.ParenRight)
                    {
                        GetNextToken();

                        // Create a function expression.
                        FunctionExpression functionExpression =
                            new FunctionExpression(
                                functionHeader.Name,
                                functionHeader.Target,
                                argumentsList);

                        return(ExpressionizeResult.NewSuccess(functionExpression));
                    }
                    else
                    {
                        return(ExpressionizeResult.NewError(ErrorInfo.ExpectRightParen));
                    }
                }
                else
                {
                    return(ExpressionizeResult.NewError(ErrorInfo.ExpectLeftParen));
                }
            }

            return(ExpressionizeResult.NewError(ErrorInfo.ExpectExpression));
        }
Esempio n. 7
0
 /// <summary>
 /// Запрос функции у другого узла.
 /// </summary>
 /// <param name="function_header"></param>
 /// <param name="ip_address"></param>
 /// <returns></returns>
 private Function GetFunctionRequest(FunctionHeader function_header, IPAddress ip_address)
 {
     throw new NotImplementedException("Запрос функций у других узлов ещё не реализован.");
 }
Esempio n. 8
0
 public TemplateFunctionRow NewCommand(FunctionHeader fucntion_header, params TemplateFunctionRow[] input_data)
 {
     return(NewCommand(fucntion_header, input_data.ToList()));
 }
Esempio n. 9
0
        public static void GenerateFunctionBoxWithText(
            HttpContext context, 
            string functionTitle, 
            bool isWarning, 
            bool showEditButton,
            ICollection<string> lines, 
            Stream outputStream)
        {
            using (var header = new FunctionHeader(functionTitle, isWarning, showEditButton))
            {
                var headerSize = header.HeaderSize;

                const int minTextAreaWidth = 350;
                const int leftPadding = 14, rightPadding = 10, topPadding = 12, bottomPadding = 10;

                var linesTrimmed = lines.Take(20).ToList();

                using (var textFont = new Font("Helvetica", 9.5f, FontStyle.Regular))
                {
                    int lineHeight = MeasureText("Text", textFont).Height;

                    Size totalSize = new Size(Math.Max(headerSize.Width, minTextAreaWidth),
                        headerSize.Height + topPadding + lineHeight * linesTrimmed.Count + bottomPadding);

                    using (var bitmap = new Bitmap(totalSize.Width, totalSize.Height))
                    using (var graphics = Graphics.FromImage(bitmap))
                    {
                        graphics.Clear(Color.White);

                        header.DrawHeader(bitmap, graphics, totalSize.Width);

                        using(var solidBrush = new SolidBrush(Color.Gray))
                        for (int i = 0; i < linesTrimmed.Count; i++)
                        {
                            var line = linesTrimmed[i];
                            int lineY = headerSize.Height + topPadding + i * lineHeight;

                            int maxLineWidth = totalSize.Width - leftPadding - rightPadding;

                            string croppedLine = CropLineToFitMaxWidth(line, textFont, maxLineWidth);

                            graphics.DrawString(croppedLine, textFont, solidBrush, leftPadding, lineY);
                        }

                        // Text outline
                        using (var pen = new Pen(isWarning ? Color.Red : Color.Gray))
                        {
                            graphics.DrawRectangle(pen, new Rectangle(0, headerSize.Height,
                                totalSize.Width - 1, totalSize.Height - headerSize.Height - 1));
                        }

                        context.Response.ContentType = "image/png";
                        context.Response.Cache.SetExpires(DateTime.Now.AddDays(10));

                        string tempFileName = Path.GetTempFileName();

                        try
                        {
                            // Saving to a temporary file, as Image.Save() sometimes on a not seekable stream throws
                            // an "A generic error occurred in GDI+." exception
                            bitmap.Save(tempFileName, ImageFormat.Png);

                            context.Response.WriteFile(tempFileName);
                            context.Response.Flush();
                        }
                        finally
                        {
                            C1File.Delete(tempFileName);
                        }
                    }

                }
            }
        }
Esempio n. 10
0
 protected Var <TResult> Exec <T, T_2, TResult>(FunctionHeader func, Var <T> input1, Var <T_2> input2)
 {
     return(new Var <TResult>(cmd).NewCommand(func, input1, input2));
 }