예제 #1
0
 private void resolveDataType()
 {
     if (this.ClassType == null)
     {
         if (ClassId != 0 && _methodId != 0 && _prj != null)
         {
             ClassPointer root = _prj.GetTypedData <ClassPointer>(ClassId);
             if (root != null)
             {
                 if (root.IsLoadingMethods())
                 {
                     //try read type from XML?
                 }
                 else
                 {
                     MethodClass mc = root.GetCustomMethodById(_methodId);
                     if (mc != null)
                     {
                         this.SetDataType(mc.ReturnValue);
                     }
                 }
             }
         }
     }
 }
 protected override void OnSetImage()
 {
     if (_method == null && Designer != null)
     {
         ClassPointer root = Designer.GetRootId();
         _method = root.GetCustomMethodById(MethodId);
     }
     if (_method != null)
     {
         if (_method.Project.IsWebApplication)
         {
             if (_method.RunAt == EnumWebRunAt.Client)
             {
                 SetIconImage(Resources._webClientMethod.ToBitmap());
             }
             else
             {
                 SetIconImage(Resources._webServerMethod.ToBitmap());
             }
         }
         else
         {
             SetIconImage(Resources._method.ToBitmap());
         }
     }
     else
     {
         SetIconImage(Resources._method.ToBitmap());
     }
 }
예제 #3
0
        public override void OnReadFromXmlNode(IXmlCodeReader serializer, XmlNode node)
        {
            base.OnReadFromXmlNode(serializer, node);
            MethodId = XmlUtil.GetAttributeUInt(node, XmlTags.XMLATT_handlerId);
            XmlObjectReader reader = (XmlObjectReader)serializer;
            ClassPointer    root   = reader.ObjectList.RootPointer as ClassPointer;
            MethodClass     mc     = root.GetCustomMethodById(MethodId);

            if (mc == null)
            {
                MathNode.LogError(string.Format(System.Globalization.CultureInfo.InvariantCulture,
                                                "Method {0} not found in class {1}", MethodId, root.ClassId));
            }
            else
            {
                _method = mc;
            }
        }
예제 #4
0
        /// <summary>
        /// called from the holding class
        /// </summary>
        /// <param name="reader"></param>
        /// <param name="node"></param>
        public void OnReadFromXmlNode(IXmlCodeReader reader0, XmlNode node)
        {
            XmlObjectReader reader = (XmlObjectReader)reader0;

            _xmlNode = node;
            //retrieve _holder, _method
            //method id
            UInt32 memberId = XmlUtil.GetAttributeUInt(node, XmlTags.XMLATT_MethodID);

            MemberId = memberId;             //method id
            //
            UInt32 varId = XmlUtil.GetAttributeUInt(node, XmlTags.XMLATT_varId);

            if (varId == 0)
            {
                //try backward compatible
                varId = XmlUtil.GetAttributeUInt(node, XmlTags.XMLATT_ComponentID);
                if (varId != 0)
                {
                    ClassPointer  root0 = reader.ObjectList.GetTypedData <ClassPointer>();
                    LocalVariable lv    = root0.GetLocalVariable(varId);
                    if (lv == null)
                    {
                        varId = 0;
                    }
                    else
                    {
                        _holder = lv;
                        ClassId = lv.ClassType.DefinitionClassId;
                        ClassPointer r = reader.ObjectList.Project.GetTypedData <ClassPointer>(ClassId);
                        _method = r.GetCustomMethodById(memberId);
                    }
                }
            }
            if (varId != 0)
            {
                ClassPointer  root0 = reader.ObjectList.GetTypedData <ClassPointer>();
                LocalVariable lv    = root0.GetLocalVariable(varId);
                _holder = lv;
                ClassId = lv.ClassType.DefinitionClassId;
                ClassPointer r = reader.ObjectList.Project.GetTypedData <ClassPointer>(ClassId);
                _method = r.GetCustomMethodById(memberId);
            }
            else
            {
                XmlNode nd = node.SelectSingleNode(XmlTags.XML_ClassInstance);
                if (nd != null)
                {
                    ClassInstancePointer cp = new ClassInstancePointer();
                    cp.OnPostSerialize(reader.ObjectList, nd, false, reader);
                    if (cp.Definition == null)
                    {
                        cp.ReplaceDeclaringClassPointer(ClassPointer.CreateClassPointer(cp.DefinitionClassId, reader.ObjectList.Project));
                    }
                    _method = cp.Definition.GetCustomMethodById(memberId);
                    _holder = cp;
                    ClassId = cp.DefinitionClassId;
                }
                else
                {
                    UInt32 cid = XmlUtil.GetAttributeUInt(node, XmlTags.XMLATT_ownerClassID);
                    if (cid != 0)
                    {
                        ClassPointer root0 = ClassPointer.CreateClassPointer(cid, reader.ObjectList.Project);
                        varId = XmlUtil.GetAttributeUInt(node, XmlTags.XMLATT_instanceId);
                        if (varId != 0)
                        {
                            ClassPointer root = reader.ObjectList.GetTypedData <ClassPointer>();
                            _holder = new ClassInstancePointer(root, root0, varId);
                            ClassId = root.ClassId;
                        }
                        else
                        {
                            _holder = root0;
                            ClassId = root0.ClassId;
                        }
                        _method = root0.GetCustomMethodById(memberId);
                    }
                    else
                    {
                        if (XmlUtil.GetAttributeUInt(node, XmlTags.XMLATT_ClassID) == 0)
                        {
                            ClassPointer root0 = reader.ObjectList.GetTypedData <ClassPointer>();
                            _holder = root0;
                            ClassId = root0.ClassId;
                            _method = root0.GetCustomMethodById(memberId);
                        }
                    }
                }
            }
            if (_method == null)
            {
                //===backward compatibility========================================
                UInt32 classId = XmlUtil.GetAttributeUInt(node, XmlTags.XMLATT_ClassID);
                ClassId = classId;
                UInt32 instId = XmlUtil.GetAttributeUInt(node, XmlTags.XMLATT_instanceId);
                if (instId != 0)
                {
                    if (classId != 0 && classId != reader.ObjectList.ClassId)
                    {
                        //it is a static instance from another class
                        //for a custom class the holder is a MemberComponentIdCustom
                        //for a library class the holder is a
                        ClassPointer cp0 = ClassPointer.CreateClassPointer(classId, reader.ObjectList.Project);
                        if (cp0 == null)
                        {
                            _error = string.Format(System.Globalization.CultureInfo.InvariantCulture, "Class {0} not found in the project", classId);
                        }
                        else
                        {
                            if (cp0.ObjectList.Count == 0)
                            {
                                //cp0 not loaded. load it now
                                cp0.ObjectList.LoadObjects();
                                if (cp0.ObjectList.Reader.HasErrors)
                                {
                                    MathNode.Log(cp0.ObjectList.Reader.Errors);
                                    cp0.ObjectList.Reader.ResetErrors();
                                }
                            }
                            IClassRef ic = cp0.ObjectList.GetClassRefById(instId);
                            if (ic == null)
                            {
                                _error = string.Format(System.Globalization.CultureInfo.InvariantCulture, "Instance {0} not found in Class {1}", instId, classId);
                            }
                            else
                            {
                                ClassInstancePointer vi = ic as ClassInstancePointer;
                                if (vi == null)
                                {
                                    _error = string.Format(System.Globalization.CultureInfo.InvariantCulture, "Instance {0},{1} in Class {2} is not a class-instance-pointer", instId, ic.GetType(), classId);
                                }
                                else
                                {
                                    MemberComponentIdCustom mc = new MemberComponentIdCustom(cp0, vi, instId);
                                    _holder = mc;
                                    _method = vi.Definition.GetCustomMethodById(memberId);
                                }
                            }
                        }
                    }
                    else
                    {
                        XmlNode nd = node.SelectSingleNode(XmlTags.XML_ClassInstance);
                        if (nd != null)
                        {
                            ClassInstancePointer cp = new ClassInstancePointer();
                            cp.OnPostSerialize(reader.ObjectList, nd, false, reader);
                            ClassInstancePointer            vi   = (ClassInstancePointer)cp.Definition.ObjectList.GetClassRefById(instId);
                            MemberComponentIdCustomInstance mcci = new MemberComponentIdCustomInstance(cp, vi, instId);
                            _holder = mcci;
                            _method = vi.Definition.GetCustomMethodById(memberId);
                            ClassId = vi.ClassId;
                        }
                        else
                        {
                            ClassPointer         root0 = reader.ObjectList.GetTypedData <ClassPointer>();
                            ClassInstancePointer cp    = (ClassInstancePointer)reader.ObjectList.GetClassRefById(instId);
                            if (cp != null)
                            {
                                MemberComponentIdCustom mcc = new MemberComponentIdCustom(root0, cp, instId);
                                _holder = mcc;
                                _method = cp.Definition.GetCustomMethodById(memberId);
                                ClassId = cp.ClassId;
                            }
                            else
                            {
                                //try to fix the error
                                foreach (object o in reader.ObjectList.Keys)
                                {
                                    cp = reader.ObjectList.GetClassRefByObject(o) as ClassInstancePointer;
                                    if (cp != null)
                                    {
                                        _method = cp.Definition.GetCustomMethodById(memberId);
                                        if (_method != null)
                                        {
                                            instId  = reader.ObjectList.GetObjectID(o);
                                            _holder = new MemberComponentIdCustom(root0, cp, instId);
                                            ClassId = cp.ClassId;
                                            //fix the instance id
                                            XmlUtil.SetAttribute(node, XmlTags.XMLATT_instanceId, instId);
                                            break;
                                        }
                                    }
                                }
                                if (_holder == null)
                                {
                                    _error = string.Format(System.Globalization.CultureInfo.InvariantCulture, "Component {0} is not a customer class instance in class {1}", instId, root0.ClassId);
                                }
                            }
                        }
                    }
                }
                else
                {
                    if (classId == 0)
                    {
                        ClassPointer root0 = reader.ObjectList.GetTypedData <ClassPointer>();
                        _holder = root0;
                        _method = root0.GetCustomMethodById(memberId);
                    }
                    else
                    {
                        ClassPointer root0 = ClassPointer.CreateClassPointer(classId, reader.ObjectList.Project);
                        if (root0 != null)
                        {
                            _holder = root0;
                            _method = root0.GetCustomMethodById(memberId);
                        }
                        if (_method == null)
                        {
                            //backward compatibility
                            UInt32       holderMemberId = XmlUtil.GetAttributeUInt(node, XmlTags.XMLATT_ComponentID);
                            ClassPointer root           = reader.ObjectList.GetTypedData <ClassPointer>();
                            UInt32       holderClassId  = XmlUtil.GetAttributeUInt(node.OwnerDocument.DocumentElement, XmlTags.XMLATT_ClassID);
                            if (holderClassId == classId)                             //holder is in the same class
                            {
                                _method = root.GetCustomMethodById(memberId);
                                if (holderMemberId == 0 || holderMemberId == reader.ObjectList.MemberId)                                        //not an instance
                                {
                                    _holder = root;
                                }
                                else
                                {
                                    _holder = (IClass)reader.ObjectList.GetClassRefById(holderMemberId);
                                }
                                if (_holder == null)
                                {
                                    _error = string.Format(System.Globalization.CultureInfo.InvariantCulture, "Invalid method holder Id [{0},{1}] for method [{2}.{3}]", classId, holderMemberId, _method.Owner, _method.Name);
                                }
                            }
                            else                             //holder and declarer are different classes
                            {
                                ClassPointer declarer = ClassPointer.CreateClassPointer(classId, reader.ObjectList.Project);
                                _method = declarer.GetCustomMethodById(memberId);
                                if (_method == null)
                                {
                                    _error = string.Format(System.Globalization.CultureInfo.InvariantCulture, "Method [{0}] not found in class [{1}]", memberId, classId);
                                }
                                else
                                {
                                    //holder an instance?
                                    object v = reader.ObjectList.GetObjectByID(holderMemberId);
                                    if (v != null)
                                    {
                                        if (v == reader.ObjectList.GetRootObject())
                                        {
                                            _holder = reader.ObjectList.GetTypedData <ClassPointer>();
                                        }
                                        else
                                        {
                                            _holder = reader.ObjectList.GetClassRefByObject(v) as IClass;
                                        }
                                    }
                                    if (_holder == null)
                                    {
                                        //holder is a local variable
                                        LocalVariable lv = root.GetLocalVariable(holderMemberId);
                                        _holder = lv;
                                    }
                                    if (_holder == null)
                                    {
                                        _error = string.Format(System.Globalization.CultureInfo.InvariantCulture, "Invalid method holder Id [{0},{1}] for method [{2}.{3}] from declaring class {4}", holderClassId, holderMemberId, _method.Owner, _method.Name, classId);
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
예제 #5
0
        protected virtual void OnRead(IXmlCodeReader reader, XmlNode node)
        {
            //get local variable from method component list based on _memberId
            XmlNode varNode = DesignUtil.GetMethodVariableNode(node.OwnerDocument.DocumentElement, _memberId);

            if (varNode == null)
            {
                LocalVariable v = LocalVariable.GetUnsavedLocalVariable(_classId, _memberId);
                if (v == null)
                {
                    //it can be a variable in an exception handler
                    //get method id
                    UInt32  methodId = 0;
                    XmlNode mn       = node;
                    while (mn != null)
                    {
                        methodId = XmlUtil.GetAttributeUInt(mn, XmlTags.XMLATT_ScopeId);
                        if (methodId != 0)
                        {
                            break;
                        }
                        mn = mn.ParentNode;
                    }
                    if (methodId != 0)
                    {
                        ClassPointer root = ((XmlObjectReader)reader).ObjectList.GetTypedData <ClassPointer>();
                        MethodClass  mc   = root.GetCustomMethodById(methodId);
                        if (mc != null)
                        {
                            v = mc.GetLocalVariable(_memberId);
                        }
                    }
                    else
                    {
                        DesignUtil.WriteToOutputWindowAndLog("Error reading local variable. Variable node not found [{0},{1}]", _classId, _memberId);
                    }
                }
                if (v != null)
                {
                    _name        = v.Name;
                    _type        = v.ClassType;
                    _owner       = v._owner;
                    _instance    = v._instance;
                    _nameChecker = v._nameChecker;
                    _debug       = v._debug;
                }
            }
            else
            {
                _name = XmlUtil.GetNameAttribute(varNode);
                Type t = XmlUtil.GetLibTypeAttribute(varNode);
                if (t != null)
                {
                    if (t.Equals(typeof(ParameterClass)))
                    {
                        MethodClass mc = _owner as MethodClass;
                        if (mc != null)
                        {
                            _type = (DataTypePointer)Activator.CreateInstance(t, mc);
                        }
                    }
                    else
                    {
                        _type = (DataTypePointer)Activator.CreateInstance(t);
                    }
                    reader.ReadObjectFromXmlNode(varNode, _type, t, this);
                }
                else
                {
                    UInt32 id = XmlUtil.GetAttributeUInt(node, XmlTags.XMLATT_ComponentID);
                    if (id != 0)
                    {
                        //try to get it from exception handler of a method
                        ClassPointer  root = ClassPointer.CreateClassPointer(((XmlObjectReader)reader).ObjectList);
                        LocalVariable v    = root.GetLocalVariable(id);
                        if (v != null)
                        {
                            _name        = v.Name;
                            _type        = v.ClassType;
                            _owner       = v._owner;
                            _instance    = v._instance;
                            _nameChecker = v._nameChecker;
                            _debug       = v._debug;
                        }
                    }
                    else
                    {
#if DEBUG
                        throw new DesignerException("Error reading local variable from class [{0}]. XPath:[{1}]", reader.ClassId, XmlUtil.GetPath(node));
#endif
                    }
                }
            }
        }
        public void OnDeserialize(object context)
        {
            string err;

            _root = context as ClassPointer;
            if (_root == null)
            {
                if (context == null)
                {
                    err = string.Format(System.Globalization.CultureInfo.InvariantCulture, "{0}.OnDeserialize(object context): context is null. MethodId:{1},BranchId:{2},ParameterId:{3},ParameterName:{4}", this.GetType().Name, MethodId, BranchId, ParameterId, ParameterName);
                }
                else
                {
                    err = string.Format(System.Globalization.CultureInfo.InvariantCulture, "{0}.OnDeserialize(object context): context {1} is not a ClassPointer. MethodId:{2},BranchId:{3},ParameterId:{4},ParameterName:{5}", this.GetType().Name, context.GetType().Name, MethodId, BranchId, ParameterId, ParameterName);
                }
                MathNode.LogError(err);
            }
            else
            {
                MethodClass mc = _root.GetCustomMethodById(MethodId);
                if (mc == null)
                {
                    if (_root.ActionInstances != null)
                    {
                        IAction a;
                        if (_root.ActionInstances.TryGetValue(MethodId, out a))
                        {
                            MethodActionForeach ma = a as MethodActionForeach;
                            if (ma != null)
                            {
                                mc = ma;
                            }
                        }
                    }
                }
                if (mc == null)
                {
                    err = string.Format(System.Globalization.CultureInfo.InvariantCulture, "{0}.OnDeserialize(object context): method [{1},{2}] is not found in ClassPointer.  MethodId:{2},BranchId:{3},ParameterId:{4},ParameterName:{5}", this.GetType().Name, _root.ClassId, MethodId, BranchId, ParameterId, ParameterName);
                    MathNode.LogError(err);
                }
                if (mc != null)
                {
                    ActionBranch ab = mc.SearchBranchById(BranchId);
                    if (ab == null)
                    {
                        //throw new DesignerException("{0}.OnDeserialize(object context): Action Branch [{1}] not found in method [{2},{3}][{4}]", this.GetType().Name, BranchId, _root.ClassId, MethodId, mc.Name);
                        mc.AddDeserializer(this);
                    }
                    else
                    {
                        AB_SubMethodAction sma = ab as AB_SubMethodAction;
                        if (sma != null)
                        {
                            _parameter = sma.GetParameterById(ParameterId);
                        }
                        if (_parameter == null)
                        {
                            _parameter = ab.GetActionBranchParameterByName(ParameterName);
                            if (_parameter != null)
                            {
                                _parameter.ParameterID = ParameterId;
                            }
                        }
                    }
                }
            }
        }
        public void Compile(ActionBranch currentAction, ActionBranch nextAction, ILimnorCodeCompiler compiler, IMethodCompile methodToCompile, CodeMemberMethod method, CodeStatementCollection statements, CodeExpressionCollection parameters, IObjectPointer returnReceiver, bool debug)
        {
            if (_method == null)
            {
                return;
            }
            IObjectPointer op = _method.VariablePointer;

            if (op == null)
            {
                return;
            }
            ClassPointer        cp  = op as ClassPointer;
            CustomMethodPointer cmp = null;
            MethodClass         mc  = null;

            if (cp != null)
            {
                mc = cp.GetCustomMethodById(_method.MethodId);
                if (mc != null)
                {
                    cmp = new CustomMethodPointer(mc, _holder);
                    cmp.SetParameterExpressions(_parameterExpressions);
                    cmp.Compile(currentAction, nextAction, compiler, methodToCompile, method, statements, parameters, returnReceiver, debug);
                    return;
                }
            }
            CodeExpression cmi = null;

            if (_method != null)
            {
                CodeMethodReferenceExpression mref = (CodeMethodReferenceExpression)_method.GetReferenceCode(methodToCompile, statements, false);
                CodeMethodInvokeExpression    cmim = new CodeMethodInvokeExpression();
                cmim.Method = mref;
                cmim.Parameters.AddRange(parameters);
                cmi = cmim;
            }
            bool useOutput = false;

            if (!NoReturn && nextAction != null && nextAction.UseInput)
            {
                CodeVariableDeclarationStatement output = new CodeVariableDeclarationStatement(
                    currentAction.OutputType.TypeString, currentAction.OutputCodeName, cmi);
                statements.Add(output);
                cmi       = new CodeVariableReferenceExpression(currentAction.OutputCodeName);
                useOutput = true;
            }
            if (_method.HasReturn && returnReceiver != null)
            {
                CodeExpression cr = returnReceiver.GetReferenceCode(methodToCompile, statements, true);
                if (_method.ReturnType != null)
                {
                    Type          target;
                    IClassWrapper wrapper = returnReceiver as IClassWrapper;
                    if (wrapper != null)
                    {
                        target = wrapper.WrappedType;
                    }
                    else
                    {
                        target = returnReceiver.ObjectType;
                    }
                    Type dt;
                    if (useOutput)
                    {
                        dt = currentAction.OutputType.BaseClassType;
                    }
                    else
                    {
                        dt = _method.ReturnType.BaseClassType;
                    }
                    CompilerUtil.CreateAssignment(cr, target, cmi, dt, statements, true);
                }
                else
                {
                    CodeAssignStatement cas = new CodeAssignStatement(cr, cmi);
                    statements.Add(cas);
                }
            }
            else
            {
                if (!useOutput)
                {
                    CodeExpressionStatement ces = new CodeExpressionStatement(cmi);
                    statements.Add(ces);
                }
            }
        }
        public void OnDelayedPostSerialize(ObjectIDmap objMap, XmlNode objectNode, XmlObjectReader reader)
        {
            UInt32 methodId = XmlUtil.GetAttributeUInt(objectNode, XmlTags.XMLATT_MethodID);

            if (methodId != 0)
            {
                ClassPointer root    = null;
                MethodClass  mc      = null;
                UInt32       paramId = XmlUtil.GetAttributeUInt(objectNode, XmlTags.XMLATT_ParamId);
                string       name    = XmlUtil.GetAttribute(objectNode, XmlTags.XMLATT_NAME);
                UInt32       classId = XmlUtil.GetAttributeUInt(objectNode, XmlTags.XMLATT_ClassID);
                if (classId != 0)
                {
                    root = objMap.Project.GetTypedData <ClassPointer>(classId);
                    if (root != null)
                    {
                        mc = root.GetCustomMethodById(methodId);
                    }
                }
                if (mc == null)
                {
                    classId = XmlUtil.GetAttributeUInt(objectNode.OwnerDocument.DocumentElement, XmlTags.XMLATT_ClassID);
                    root    = objMap.Project.GetTypedData <ClassPointer>(classId);
                    if (root != null)
                    {
                        mc = root.GetCustomMethodById(methodId);
                    }
                }
                if (mc == null)
                {
                    classId = objMap.ClassId;
                    root    = objMap.Project.GetTypedData <ClassPointer>(classId);
                    if (root != null)
                    {
                        mc = root.GetCustomMethodById(methodId);
                    }
                }
                if (mc == null)
                {
                    classId = reader.ClassId;
                    root    = objMap.Project.GetTypedData <ClassPointer>(classId);
                    if (root != null)
                    {
                        mc = root.GetCustomMethodById(methodId);
                    }
                }
                if (mc == null)
                {
                    Form f = null;
                    if (root != null)
                    {
                        Control c = root.ObjectInstance as Control;
                        if (c != null)
                        {
                            f = c.FindForm();
                        }
                    }
                    MathNode.Log(f, new DesignerException("CustomMethodParameterPointer.OnDelayedPostSerialize: Custom method not found [{0}]. Used in class [{1}]", methodId, XmlUtil.GetAttributeUInt(objectNode.OwnerDocument.DocumentElement, XmlTags.XMLATT_ClassID)));
                }
                else
                {
                    ParameterClass pc = mc.GetParameterByID(paramId);
                    if (pc == null)
                    {
                        pc = mc.GetParameterByName(name);
                    }
                    if (pc == null)
                    {
                        Form f = null;
                        if (root != null)
                        {
                            Control c = root.ObjectInstance as Control;
                            if (c != null)
                            {
                                f = c.FindForm();
                            }
                        }
                        MathNode.Log(f, new DesignerException("Parameter [{0}] for custom method not found [{1},{2}]", paramId, root.ClassId, methodId));
                    }
                    _parameter = pc;
                }
            }
        }