Exemple #1
0
        List <GenClassPivot> FilterClassesPivot(List <GenClassPivot> aInput)
        {
            Queue <GenClassPivot> aTemp = new Queue <GenClassPivot>();
            List <GenClassPivot>  aRes  = new List <GenClassPivot>();

            string[] aTargetTypes = new string[] { "CT_PivotCacheDefinition", "CT_PivotCacheRecords", "CT_pivotTableDefinition" };
            //string[] aTargetTypes = new string[] { "CT_Workbook" };
            //string[] aTargetTypes = new string[] { "CT_Comments" };

            Dictionary <string, bool> mapTargetSubTypes = new Dictionary <string, bool>();
            Dictionary <string, bool> namspaces         = new Dictionary <string, bool>();

            Dictionary <string, GenClassPivot> mapAllClasses = new Dictionary <string, GenClassPivot>();

            for (int i = 0; i < aInput.Count; ++i)
            {
                GenClassPivot oGenClass = aInput[i];
                if (0 == aTargetTypes.Length || -1 != Array.IndexOf(aTargetTypes, oGenClass.sName))
                {
                    aTemp.Enqueue(oGenClass);
                }
                mapAllClasses[oGenClass.sName] = oGenClass;
            }
            while (aTemp.Count > 0)
            {
                GenClassPivot oGenClass = aTemp.Dequeue();
                if (!mapTargetSubTypes.ContainsKey(oGenClass.sName))
                {
                    mapTargetSubTypes.Add(oGenClass.sName, true);
                    aRes.Add(oGenClass);
                    for (int j = 0; j < oGenClass.aMembers.Count; ++j)
                    {
                        GenMemberPivot oGenMember = oGenClass.aMembers[j];

                        GenClassPivot oTempClass;
                        if (null != oGenMember.sType && mapAllClasses.TryGetValue(oGenMember.sType, out oTempClass))
                        {
                            namspaces[oTempClass.sNamespace] = true;

                            aTemp.Enqueue(oTempClass);
                        }
                        if (null != oGenMember.aArrayTypes)
                        {
                            for (int k = 0; k < oGenMember.aArrayTypes.Count; ++k)
                            {
                                GenMemberPivot oGenMemberArrayTypes = oGenMember.aArrayTypes[k];
                                if (null != oGenMemberArrayTypes.sType && mapAllClasses.TryGetValue(oGenMemberArrayTypes.sType, out oTempClass))
                                {
                                    aTemp.Enqueue(oTempClass);
                                }
                            }
                        }
                    }
                }
            }
            return(aRes);
        }
Exemple #2
0
        void ParseArguments(CodeAttributeArgumentCollection oArguments, GenMemberPivot oGenMember)
        {
            CodePrimitiveExpression oPrimitiveExpression = null;
            CodeTypeOfExpression    oTypeOfExpression    = null;
            string sNamespace = null;
            bool?  bForm      = null;

            foreach (CodeAttributeArgument argument in oArguments)
            {
                if ("" == argument.Name)
                {
                    if (argument.Value is CodePrimitiveExpression)
                    {
                        oPrimitiveExpression = argument.Value as CodePrimitiveExpression;
                    }
                    else if (argument.Value is CodeTypeOfExpression)
                    {
                        oTypeOfExpression = argument.Value as CodeTypeOfExpression;
                    }
                }
                else if ("Namespace" == argument.Name)
                {
                    sNamespace = ((CodePrimitiveExpression)argument.Value).Value.ToString();
                }
                else if ("Form" == argument.Name)
                {
                    string sValue = ((CodeFieldReferenceExpression)argument.Value).FieldName;
                    if ("Qualified" == sValue)
                    {
                        bForm = true;
                    }
                    else if ("Unqualified" == sValue)
                    {
                        bForm = false;
                    }
                }
            }
            if (null != oPrimitiveExpression)
            {
                oGenMember.sName = oPrimitiveExpression.Value.ToString();
            }
            if (null != oTypeOfExpression)
            {
                InitMemberType(oGenMember, oTypeOfExpression.Type.BaseType);
            }
            if (null != sNamespace)
            {
                oGenMember.sNamespace = sNamespace;
            }
            if (bForm.HasValue)
            {
                oGenMember.bQualified = bForm.Value;
            }
        }
Exemple #3
0
 void InitMemberType(GenMemberPivot oGenMember, string sBaseType)
 {
     if (-1 != sBaseType.IndexOf("System."))
     {
         oGenMember.oSystemType = Type.GetType(sBaseType);
         if (null == oGenMember.oSystemType)
         {
             oGenMember.oSystemType = typeof(string);
         }
     }
     else
     {
         oGenMember.sType = sBaseType;
     }
 }
Exemple #4
0
 public void merge(GenMemberPivot val)
 {
     if (string.IsNullOrEmpty(this.sName))
     {
         sName = val.sName;
     }
     if (string.IsNullOrEmpty(this.sNamespace))
     {
         sNamespace = val.sNamespace;
     }
     if (string.IsNullOrEmpty(this.sType))
     {
         sType = val.sType;
     }
     if (null == this.oSystemType)
     {
         oSystemType = val.oSystemType;
     }
     if (!this.bIsAttribute.HasValue)
     {
         bIsAttribute = val.bIsAttribute;
     }
     if (string.IsNullOrEmpty(this.sDefAttribute))
     {
         sDefAttribute = val.sDefAttribute;
     }
     if (!this.bQualified.HasValue)
     {
         bQualified = val.bQualified;
     }
     if (!this.nArrayRank.HasValue)
     {
         nArrayRank = val.nArrayRank;
     }
     if (!this.bIsArrayTypesHidden.HasValue)
     {
         bIsArrayTypesHidden = val.bIsArrayTypesHidden;
     }
 }
Exemple #5
0
        GenMemberPivot PreProcessProperty(List <GenClassPivot> aGenClasses, CodeMemberProperty codeMemberProperty, GenClassPivot oGenClass, ref int nItemsElementName)
        {
            GenMemberPivot oGenMember = new GenMemberPivot(codeMemberProperty.Name);
            bool           bIgnore    = false;

            InitMemberType(oGenMember, codeMemberProperty.Type.BaseType);
            if (null != codeMemberProperty.Type.ArrayElementType)
            {
                oGenMember.nArrayRank = codeMemberProperty.Type.ArrayElementType.ArrayRank;
            }
            bool bXmlElementAttribute           = false;
            List <GenMemberPivot> aTempMemebers = new List <GenMemberPivot>();

            for (int i = 0; i < codeMemberProperty.CustomAttributes.Count; i++)
            {
                CodeAttributeDeclaration attribute = codeMemberProperty.CustomAttributes[i];
                if (attribute.Name == "System.Xml.Serialization.XmlAttributeAttribute")
                {
                    oGenMember.bQualified   = false;
                    oGenMember.bIsAttribute = true;
                    ParseArguments(attribute.Arguments, oGenMember);
                    //todo могут быть повторы имен атрибутов и child nodes.
                }
                else if (attribute.Name == "System.ComponentModel.DefaultValueAttribute")
                {
                    if (attribute.Arguments.Count > 0)
                    {
                        CodeExpression oCodeExpression = attribute.Arguments[attribute.Arguments.Count - 1].Value;
                        //todo other
                        if (oCodeExpression is CodePrimitiveExpression)
                        {
                            oGenMember.sDefAttribute = ((oCodeExpression as CodePrimitiveExpression)).Value.ToString();
                        }
                        else if (oCodeExpression is CodeFieldReferenceExpression)
                        {
                            oGenMember.sDefAttribute = ((oCodeExpression as CodeFieldReferenceExpression)).FieldName;
                        }
                    }
                }
                else if (attribute.Name == "System.Xml.Serialization.XmlIgnoreAttribute")
                {
                    bIgnore = true;
                }
                else if (attribute.Name == "System.Xml.Serialization.XmlElementAttribute")
                {
                    bXmlElementAttribute = true;
                    GenMemberPivot oTemp = new GenMemberPivot(null);
                    ParseArguments(attribute.Arguments, oTemp);
                    aTempMemebers.Add(oTemp);
                }
                else if (attribute.Name == "System.Xml.Serialization.XmlArrayItemAttribute")
                {
                    GenMemberPivot oTemp = new GenMemberPivot(null);
                    ParseArguments(attribute.Arguments, oTemp);
                    aTempMemebers.Add(oTemp);
                }
                else if (attribute.Name == "System.Xml.Serialization.XmlArrayAttribute")
                {
                    ParseArguments(attribute.Arguments, oGenMember);
                }
                //todo не всегда прописан
                //else if (attribute.Name == "System.Xml.Serialization.XmlChoiceIdentifierAttribute")
                //{
                //    if (attribute.Arguments.Count > 0)
                //    {
                //        CodePrimitiveExpression oPrimitiveExpression = attribute.Arguments[0].Value as CodePrimitiveExpression;
                //        oGenMember.sChoiceIdentifier = oPrimitiveExpression.Value.ToString();
                //    }
                //}
            }
            if (bIgnore)
            {
                return(null);
            }
            else
            {
                if (aTempMemebers.Count > 0)
                {
                    if (1 == aTempMemebers.Count)
                    {
                        GenMemberPivot TempMember = aTempMemebers[0];
                        TempMember.merge(oGenMember);
                        TempMember.nArrayRank = null;
                    }
                    oGenMember.aArrayTypes = aTempMemebers;
                    if (bXmlElementAttribute)
                    {
                        oGenMember.bIsArrayTypesHidden = true;
                    }
                    else
                    {
                        oGenMember.bIsArrayTypesHidden = false;
                    }
                }
                else
                {
                    oGenMember.nArrayRank = null;
                }
                oGenMember.completeDefaults();
                return(oGenMember);
            }
        }
Exemple #6
0
        GenClassPivot PreProcessClass(List <GenClassPivot> aGenClasses, CodeTypeDeclaration type)
        {
            GenClassPivot oGenClass = null;
            //получаем xml namespace
            string sNamespace       = null;
            bool   bIncludeInSchema = true;
            string sRootName        = "";

            for (int i = 0; i < type.CustomAttributes.Count; i++)
            {
                CodeAttributeDeclaration attribute = type.CustomAttributes[i];
                if (attribute.Name == "System.Xml.Serialization.XmlTypeAttribute")
                {
                    foreach (CodeAttributeArgument argument in attribute.Arguments)
                    {
                        if (argument.Name == "Namespace")
                        {
                            sNamespace = ((CodePrimitiveExpression)argument.Value).Value.ToString();
                        }
                        else if (argument.Name == "IncludeInSchema")
                        {
                            bIncludeInSchema = Convert.ToBoolean(((CodePrimitiveExpression)argument.Value).Value);
                        }
                        //todo argument.Name == "TypeName"
                    }
                }
                else if (attribute.Name == "System.Xml.Serialization.XmlRootAttribute")
                {
                    foreach (CodeAttributeArgument argument in attribute.Arguments)
                    {
                        if (argument.Name == "Namespace")
                        {
                            sNamespace = ((CodePrimitiveExpression)argument.Value).Value.ToString();
                        }
                        else if ("" == argument.Name)
                        {
                            sRootName = ((CodePrimitiveExpression)argument.Value).Value.ToString();
                        }
                    }
                }
            }
            if (bIncludeInSchema)
            {
                oGenClass           = new GenClassPivot(type.Name, sNamespace);
                oGenClass.sRootName = sRootName;
                int nItemsElementName = 0;
                if (type.IsEnum)
                {
                    oGenClass.bIsEnum = true;
                    for (int i = 0; i < type.Members.Count; ++i)
                    {
                        CodeTypeMember member     = type.Members[i];
                        GenMemberPivot oGenMember = new GenMemberPivot(member.Name);
                        for (int j = 0; j < member.CustomAttributes.Count; j++)
                        {
                            CodeAttributeDeclaration attribute = member.CustomAttributes[j];
                            if (attribute.Name == "System.Xml.Serialization.XmlEnumAttribute")
                            {
                                ParseArguments(attribute.Arguments, oGenMember);
                            }
                        }
                        oGenClass.aMembers.Add(oGenMember);
                    }
                }
                else
                {
                    for (int i = 0; i < type.Members.Count; ++i)
                    {
                        CodeTypeMember member = type.Members[i];
                        //CodeMemberField пропускаем
                        CodeMemberProperty codeMemberProperty = member as CodeMemberProperty;
                        if (codeMemberProperty != null)
                        {
                            GenMemberPivot oNewGenMember = PreProcessProperty(aGenClasses, codeMemberProperty, oGenClass, ref nItemsElementName);
                            if (null != oNewGenMember)
                            {
                                oGenClass.aMembers.Add(oNewGenMember);
                            }
                        }
                    }
                }
            }
            return(oGenClass);
        }