Esempio n. 1
0
        public override System.CodeDom.CodeExpression GCode_CodeDom_GetValue(CodeGenerateSystem.Base.LinkPinControl element, CodeGenerateSystem.Base.GenerateCodeContext_Method context, CodeGenerateSystem.Base.GenerateCodeContext_PreNode preNodeContext = null)
        {
            var value1        = new System.CodeDom.CodeVariableReferenceExpression("System.DateTime.Now.Millisecond");
            var value2        = new System.CodeDom.CodePrimitiveExpression(0.001f);
            var arithmeticExp = new System.CodeDom.CodeBinaryOperatorExpression();

            arithmeticExp.Left     = value1;
            arithmeticExp.Right    = value2;
            arithmeticExp.Operator = System.CodeDom.CodeBinaryOperatorType.Multiply;
            return(arithmeticExp);
        }
Esempio n. 2
0
 /// <summary>
 /// Convert string value to an escaped C# string literal.
 /// </summary>
 public static string ToLiteral(string input, string language = "JScript")
 {
     using (var writer = new StringWriter())
     {
         using (var provider = System.CodeDom.Compiler.CodeDomProvider.CreateProvider(language))
         {
             var exp = new System.CodeDom.CodePrimitiveExpression(input);
             System.CodeDom.Compiler.CodeGeneratorOptions options = null;
             provider.GenerateCodeFromExpression(exp, writer, options);
             var literal = writer.ToString();
             var rxLines = new Regex("\"\\s*[+]\\s*[\r\n]\"", RegexOptions.Multiline);
             literal = rxLines.Replace(literal, "");
             //literal = literal.Replace(string.Format("\" +{0}\t\"", Environment.NewLine), "");
             //literal = literal.Replace("\\r\\n", "\\r\\n\"+\r\n\"");
             return(literal);
         }
     }
 }
Esempio n. 3
0
        static System.Web.UI.PersistenceMode GetPersistenceMode(IProperty prop)
        {
            foreach (IAttribute att in prop.Attributes)
            {
                if (att.Name == "System.Web.UI.PersistenceModeAttribute")
                {
                    System.CodeDom.CodePrimitiveExpression expr = att.PositionalArguments[0] as System.CodeDom.CodePrimitiveExpression;
                    if (expr == null)
                    {
                        LoggingService.LogWarning("Unknown expression type {0} in IAttribute parameter", att.PositionalArguments[0]);
                        return(System.Web.UI.PersistenceMode.Attribute);
                    }

                    return((System.Web.UI.PersistenceMode)expr.Value);
                }
                else if (att.Name == "System.Web.UI.TemplateContainerAttribute")
                {
                    return(System.Web.UI.PersistenceMode.InnerProperty);
                }
            }
            return(System.Web.UI.PersistenceMode.Attribute);
        }
 string ExprToStr(System.CodeDom.CodeExpression expr)
 {
     System.CodeDom.CodePrimitiveExpression p = expr as System.CodeDom.CodePrimitiveExpression;
     return(p != null? p.Value as string : null);
 }
Esempio n. 5
0
        static bool AreChildrenAsProperties(IType type, out string defaultProperty)
        {
            bool childrenAsProperties = false;

            defaultProperty = "";

            IAttribute att = GetAttributes(type, "System.Web.UI.ParseChildrenAttribute").FirstOrDefault();

            if (att == null || att.PositionalArguments.Count == 0)
            {
                return(childrenAsProperties);
            }

            if (att.PositionalArguments.Count > 0)
            {
                System.CodeDom.CodePrimitiveExpression expr = att.PositionalArguments[0] as System.CodeDom.CodePrimitiveExpression;
                if (expr == null)
                {
                    LoggingService.LogWarning("Unknown expression type {0} in IAttribute parameter", att.PositionalArguments[0]);
                    return(false);
                }

                if (expr.Value is bool)
                {
                    childrenAsProperties = (bool)expr.Value;
                }
                else
                {
                    //TODO: implement this
                    LoggingService.LogWarning("ASP.NET completion does not yet handle ParseChildrenAttribute (Type)");
                    return(false);
                }
            }

            if (att.PositionalArguments.Count > 1)
            {
                System.CodeDom.CodePrimitiveExpression expr = att.PositionalArguments[1] as System.CodeDom.CodePrimitiveExpression;
                if (expr == null || !(expr.Value is string))
                {
                    LoggingService.LogWarning("Unknown expression '{0}' in IAttribute parameter", att.PositionalArguments[1]);
                    return(false);
                }
                defaultProperty = (string)expr.Value;
            }

            if (att.NamedArguments.Count > 0)
            {
                if (att.NamedArguments.ContainsKey("ChildrenAsProperties"))
                {
                    System.CodeDom.CodePrimitiveExpression expr = att.NamedArguments["ChildrenAsProperties"]
                                                                  as System.CodeDom.CodePrimitiveExpression;
                    if (expr == null)
                    {
                        LoggingService.LogWarning("Unknown expression type {0} in IAttribute parameter", att.PositionalArguments[0]);
                        return(false);
                    }
                    childrenAsProperties = (bool)expr.Value;
                }
                if (att.NamedArguments.ContainsKey("DefaultProperty"))
                {
                    System.CodeDom.CodePrimitiveExpression expr = att.NamedArguments["DefaultProperty"]
                                                                  as System.CodeDom.CodePrimitiveExpression;
                    if (expr == null)
                    {
                        LoggingService.LogWarning("Unknown expression type {0} in IAttribute parameter", att.PositionalArguments[0]);
                        return(false);
                    }
                    defaultProperty = (string)expr.Value;
                }
                if (att.NamedArguments.ContainsKey("ChildControlType"))
                {
                    //TODO: implement this
                    LoggingService.LogWarning("ASP.NET completion does not yet handle ParseChildrenAttribute (Type)");
                    return(false);
                }
            }

            return(childrenAsProperties);
        }
Esempio n. 6
0
 protected virtual new void GeneratePrimitiveExpression(System.CodeDom.CodePrimitiveExpression e)
 {
     Contract.Requires(e != null);
 }
Esempio n. 7
0
        public override async System.Threading.Tasks.Task GCode_CodeDom_GenerateCode(System.CodeDom.CodeTypeDeclaration codeClass, System.CodeDom.CodeStatementCollection codeStatementCollection, CodeGenerateSystem.Base.LinkPinControl element, CodeGenerateSystem.Base.GenerateCodeContext_Method context)
        {
            GetBezierPointsFromCtrl();

            if (!codeClass.Members.Contains(mBezierPointsField))
            {
                // code: private static System.Collections.Generic.List<EngineNS.BezierPointBase> mBezierPoints_XXX = new System.Collections.Generic.List<EngineNS.BezierPointBase>(new BezierPoint[] { new EngineNS.BezierPointBase(), new EngineNS.BezierPointBase() });
                mBezierPointsField.Type       = new System.CodeDom.CodeTypeReference(BezierPointsListType);
                mBezierPointsField.Name       = StaticBezierPointsName;
                mBezierPointsField.Attributes = System.CodeDom.MemberAttributes.Private;
                var arrayCreateExp = new System.CodeDom.CodeArrayCreateExpression();
                arrayCreateExp.CreateType = new System.CodeDom.CodeTypeReference(typeof(EngineNS.BezierPointBase));
                foreach (var bPt in mBezierPoints)
                {
                    var newBPT = new System.CodeDom.CodeObjectCreateExpression();
                    newBPT.CreateType = new System.CodeDom.CodeTypeReference(typeof(EngineNS.BezierPointBase));
                    newBPT.Parameters.Add(new System.CodeDom.CodeObjectCreateExpression(typeof(EngineNS.Vector2),
                                                                                        new System.CodeDom.CodeExpression[] {
                        new System.CodeDom.CodePrimitiveExpression(bPt.Position.X),
                        new System.CodeDom.CodePrimitiveExpression(bPt.Position.Y)
                    }));
                    newBPT.Parameters.Add(new System.CodeDom.CodeObjectCreateExpression(typeof(EngineNS.Vector2),
                                                                                        new System.CodeDom.CodeExpression[] {
                        new System.CodeDom.CodePrimitiveExpression(bPt.ControlPoint.X),
                        new System.CodeDom.CodePrimitiveExpression(bPt.ControlPoint.Y)
                    }));
                    arrayCreateExp.Initializers.Add(newBPT);
                }
                mBezierPointsField.InitExpression = new System.CodeDom.CodeObjectCreateExpression(BezierPointsListType, arrayCreateExp);
                codeClass.Members.Add(mBezierPointsField);
            }

            // 判断5个输入链接是否需要生成代码
            if (mCtrlValueInputHandle.HasLink)
            {
                if (!mCtrlValueInputHandle.GetLinkedObject(0, true).IsOnlyReturnValue)
                {
                    await mCtrlValueInputHandle.GetLinkedObject(0, true).GCode_CodeDom_GenerateCode(codeClass, codeStatementCollection, mCtrlValueInputHandle.GetLinkedPinControl(0, true), context);
                }
            }

            if (mCtrlValueYMaxInputHandle.HasLink)
            {
                if (!mCtrlValueYMaxInputHandle.GetLinkedObject(0, true).IsOnlyReturnValue)
                {
                    await mCtrlValueYMaxInputHandle.GetLinkedObject(0, true).GCode_CodeDom_GenerateCode(codeClass, codeStatementCollection, mCtrlValueYMaxInputHandle.GetLinkedPinControl(0, true), context);
                }
            }

            if (mCtrlValueYMinInputHandle.HasLink)
            {
                if (!mCtrlValueYMinInputHandle.GetLinkedObject(0, true).IsOnlyReturnValue)
                {
                    await mCtrlValueYMinInputHandle.GetLinkedObject(0, true).GCode_CodeDom_GenerateCode(codeClass, codeStatementCollection, mCtrlValueYMinInputHandle.GetLinkedPinControl(0, true), context);
                }
            }

            if (mCtrlValueXMaxInputHandle.HasLink)
            {
                if (!mCtrlValueXMaxInputHandle.GetLinkedObject(0, true).IsOnlyReturnValue)
                {
                    await mCtrlValueXMaxInputHandle.GetLinkedObject(0, true).GCode_CodeDom_GenerateCode(codeClass, codeStatementCollection, mCtrlValueXMaxInputHandle.GetLinkedPinControl(0, true), context);
                }
            }

            if (mCtrlValueXMinInputHandle.HasLink)
            {
                if (!mCtrlValueXMinInputHandle.GetLinkedObject(0, true).IsOnlyReturnValue)
                {
                    await mCtrlValueXMinInputHandle.GetLinkedObject(0, true).GCode_CodeDom_GenerateCode(codeClass, codeStatementCollection, mCtrlValueXMinInputHandle.GetLinkedPinControl(0, true), context);
                }
            }

            if (mCtrlValueXLoopHandle.HasLink)
            {
                if (!mCtrlValueXLoopHandle.GetLinkedObject(0, true).IsOnlyReturnValue)
                {
                    await mCtrlValueXLoopHandle.GetLinkedObject(0, true).GCode_CodeDom_GenerateCode(codeClass, codeStatementCollection, mCtrlValueXLoopHandle.GetLinkedPinControl(0, true), context);
                }
            }

            // 自身代码生成
            if (!context.Method.Statements.Contains(mVariableDeclaration))
            {
                // 声明
                mVariableDeclaration.Type           = new System.CodeDom.CodeTypeReference(typeof(double));
                mVariableDeclaration.Name           = GCode_GetValueName(null, context);
                mVariableDeclaration.InitExpression = CodeGenerateSystem.Program.GetDefaultValueExpressionFromType(typeof(double));
                context.Method.Statements.Insert(0, mVariableDeclaration);
            }

            var assignExp = new System.CodeDom.CodeAssignStatement();

            assignExp.Left = new System.CodeDom.CodeVariableReferenceExpression(GCode_GetValueName(null, context));
            var classType = mTemplateClassInstance.GetType();

            System.CodeDom.CodeExpression minXExp, maxXExp, minYExp, maxYExp, isXLoopExp;
            if (mCtrlValueXMinInputHandle.HasLink)
            {
                minXExp = mCtrlValueXMinInputHandle.GetLinkedObject(0, true).GCode_CodeDom_GetValue(mCtrlValueXMinInputHandle.GetLinkedPinControl(0, true), context);
            }
            else
            {
                var pro  = classType.GetProperty("XMin");
                var xMin = pro.GetValue(mTemplateClassInstance);
                minXExp = new System.CodeDom.CodePrimitiveExpression(xMin);
            }

            if (mCtrlValueXMaxInputHandle.HasLink)
            {
                maxXExp = mCtrlValueXMaxInputHandle.GetLinkedObject(0, true).GCode_CodeDom_GetValue(mCtrlValueXMaxInputHandle.GetLinkedPinControl(0, true), context);
            }
            else
            {
                var pro  = classType.GetProperty("XMax");
                var xMax = pro.GetValue(mTemplateClassInstance);
                maxXExp = new System.CodeDom.CodePrimitiveExpression(xMax);
            }

            if (mCtrlValueYMinInputHandle.HasLink)
            {
                minYExp = mCtrlValueYMinInputHandle.GetLinkedObject(0, true).GCode_CodeDom_GetValue(mCtrlValueYMinInputHandle.GetLinkedPinControl(0, true), context);
            }
            else
            {
                var pro  = classType.GetProperty("YMin");
                var yMin = pro.GetValue(mTemplateClassInstance);
                minYExp = new System.CodeDom.CodePrimitiveExpression(yMin);
            }

            if (mCtrlValueYMaxInputHandle.HasLink)
            {
                maxYExp = mCtrlValueYMaxInputHandle.GetLinkedObject(0, true).GCode_CodeDom_GetValue(mCtrlValueYMaxInputHandle.GetLinkedPinControl(0, true), context);
            }
            else
            {
                var pro  = classType.GetProperty("YMax");
                var yMax = pro.GetValue(mTemplateClassInstance);
                maxYExp = new System.CodeDom.CodePrimitiveExpression(yMax);
            }

            if (mCtrlValueXLoopHandle.HasLink)
            {
                isXLoopExp = mCtrlValueXLoopHandle.GetLinkedObject(0, true).GCode_CodeDom_GetValue(mCtrlValueXLoopHandle.GetLinkedPinControl(0, true), context);
            }
            else
            {
                var pro     = classType.GetProperty("XLoop");
                var isXLoop = pro.GetValue(mTemplateClassInstance);
                isXLoopExp = new System.CodeDom.CodePrimitiveExpression(isXLoop);
            }

            // code: EngineNS.BezierCalculate.ValueOnBezier(mBezierPoints_XXX, XPos);
            assignExp.Right = new CodeGenerateSystem.CodeDom.CodeMethodInvokeExpression(
                new System.CodeDom.CodeTypeReferenceExpression(typeof(EngineNS.BezierCalculate)),
                "ValueOnBezier",
                new System.CodeDom.CodeExpression[] {
                new System.CodeDom.CodeVariableReferenceExpression(StaticBezierPointsName),                                                         // bezierPtList
                mCtrlValueInputHandle.GetLinkedObject(0, true).GCode_CodeDom_GetValue(mCtrlValueInputHandle.GetLinkedPinControl(0, true), context), // xValue
                minXExp, maxXExp, minYExp, maxYExp,
                new System.CodeDom.CodePrimitiveExpression(0),                                                                                      // MinBezierX
                new System.CodeDom.CodePrimitiveExpression(mBezierWidth),                                                                           // MaxBezierX
                new System.CodeDom.CodePrimitiveExpression(0),                                                                                      // MinBezierY
                new System.CodeDom.CodePrimitiveExpression(mBezierHeight),                                                                          // MaxBezierY
                isXLoopExp                                                                                                                          // bLoopX
            });

            codeStatementCollection.Add(assignExp);

            // 收集用于调试的数据的代码
            var debugCodes = CodeDomNode.BreakPoint.BeginMacrossDebugCodeStatments(codeStatementCollection);

            CodeDomNode.BreakPoint.GetGatherDataValueCodeStatement(debugCodes, this.mCtrlValueInputHandle.GetLinkPinKeyName(),
                                                                   mCtrlValueInputHandle.GetLinkedObject(0, true).GCode_CodeDom_GetValue(mCtrlValueInputHandle.GetLinkedPinControl(0, true), context),
                                                                   mCtrlValueInputHandle.GetLinkedObject(0, true).GCode_GetTypeString(mCtrlValueInputHandle.GetLinkedPinControl(0, true), context), context);
            CodeDomNode.BreakPoint.GetGatherDataValueCodeStatement(debugCodes, mCtrlValueOutputHandle.GetLinkPinKeyName(),
                                                                   assignExp.Left, GCode_GetTypeString(null, context), context);
            CodeDomNode.BreakPoint.EndMacrossDebugCodeStatements(codeStatementCollection, debugCodes);
        }