Ejemplo n.º 1
0
        protected Dictionary <string, object> CreateAttributeJson(Dictionary <string, object> data,
                                                                  AttributeMappingConfig <ColumnAttribute>[] configs)
        {
            Dictionary <string, object> dic = new Dictionary <string, object> ();

            foreach (AttributeMappingConfig <ColumnAttribute> config in configs)
            {
                if (Util.IsValueType(config.type))
                {
                    if (data.ContainsKey(config.name))
                    {
                        dic.Add(config.name, data [config.name]);
                    }
                }
                else
                {
                    if (!config.type.IsArray)
                    {
                        continue;
                    }

                    Type   type  = config.type.GetElementType();
                    string value = "";
                    if (config.t != null)
                    {
                        ColumnAttribute column = config.t as ColumnAttribute;
                        if (column != null)
                        {
                            if (column.Value == "" && column.Type != "")
                            {
                                value = config.name;
                            }
                            else if (joinType != null)
                            {
                                Type tempType = joinType(data [column.Type].ToString());
                                type  = tempType == null ? type : tempType;
                                value = column.Value;
                            }
                        }
                    }

                    Dictionary <string, object> join = new Dictionary <string, object> ();
                    AttributeMappingConfig <ColumnAttribute>[] tempConfigs = Reflection.FieldAMCRetrieve <ColumnAttribute> (config.type.GetElementType());
                    foreach (AttributeMappingConfig <ColumnAttribute> tempConfig in tempConfigs)
                    {
                        if (tempConfig.t != null)
                        {
                            ColumnAttribute column = tempConfig.t as ColumnAttribute;
                            if (column != null)
                            {
                                if (column.CheckConstraints(DataConstraints.PK))
                                {
                                    join.Add(tempConfig.name, data [value]);
                                    break;
                                }

                                if (data.ContainsKey(column.Value))
                                {
                                    join.Add(tempConfig.name, data [column.Value]);
                                }
                            }
                        }
                    }

                    if (join.Count > 0)
                    {
                        dic.Add(config.name, CreateAttributeJson(type, join));
                    }
                }
            }

            return(dic);
        }
Ejemplo n.º 2
0
        protected void CreateAttributeJson(int index)
        {
            Type           type  = listType [index];
            ExcelAttribute excel = type.GetAttributeValue <ExcelAttribute> ();
            List <Dictionary <string, object> > list = CreateAttributeJson(type);

            if (list == null || list.Count <= 0)
            {
                return;
            }

            if (excel.IndexFlag)
            {
                AttributeMappingConfig <ColumnAttribute>[] configs = Reflection.FieldAMCRetrieve <ColumnAttribute> (type);
                List <string> pks = new List <string> ();
                List <string> fks = new List <string> ();
                foreach (AttributeMappingConfig <ColumnAttribute> config in configs)
                {
                    if (config.t != null)
                    {
                        ColumnAttribute column = config.t as ColumnAttribute;
                        if (column != null)
                        {
                            if (column.CheckConstraints(DataConstraints.PK))
                            {
                                pks.Add(config.name);
                            }

                            if (column.CheckConstraints(DataConstraints.FK))
                            {
                                fks.Add(config.name);
                            }
                        }
                    }
                }

                if (pks.Count > 0)
                {
                    foreach (Dictionary <string, object> dic in list)
                    {
                        StringBuilder stringBuilder  = Append(pks, dic);
                        string        createFileName = string.Format("{0}{1}", excel.CreateFileName, stringBuilder.ToString());
                        EditorUtil.CreateJsonFile(createFileName, JsonUtil.ToJson(dic), outputJsonPath, false);
                    }
                }

                if (fks.Count > 0)
                {
                    List <string> fk = new List <string> ();
                    foreach (Dictionary <string, object> dic in list)
                    {
                        StringBuilder stringBuilder = Append(fks, dic);
                        fk.Add(stringBuilder.ToString());
                    }

                    fk = Util.GetDistinctValues <string> (fk);
                    foreach (string s in fk)
                    {
                        List <Dictionary <string, object> > fkList = new List <Dictionary <string, object> > ();
                        foreach (Dictionary <string, object> dic in list)
                        {
                            StringBuilder stringBuilder = Append(fks, dic);
                            if (s == stringBuilder.ToString())
                            {
                                fkList.Add(dic);
                            }
                        }

                        string createFileName = string.Format("{0}{1}", excel.CreateFileName, s);
                        EditorUtil.CreateJsonFile(createFileName, JsonUtil.ToJson(fkList), outputJsonPath, false);
                    }
                }
            }
            else
            {
                EditorUtil.CreateJsonFile(excel.CreateFileName, JsonUtil.ToJson(list), outputJsonPath, false);
            }
        }