Exemple #1
0
        protected void PersistEntities <T, U>(Connection connection, Guid projectId, CSVFile file, string dtype = "")
            where T : BaseEntity
            where U : BaseDto
        {
            if (file == null)
            {
                return;
            }

            List <T> entities = new List <T>();
            CSVRow   header   = file.GetHeader();

            foreach (CSVRow row in file.GetValues())
            {
                CSVValue dtypeValue = file.GetValueToColumn(row, "DTYPE");
                if (dtypeValue != null && !string.IsNullOrEmpty(dtype))
                {
                    if (!dtype.Equals(dtypeValue.GetValue()))
                    {
                        continue;
                    }
                }
                entities.Add(CreateEntity <T, U>(file, row, projectId));
            }
            GenericRepository genericRepository = new GenericRepository(connection);

            genericRepository.PersistAsNews <T>(entities);
        }
Exemple #2
0
        public static CSVValue SafeGetValue(CSVValue val, CSVTable table, string key1, string key2)
        {
            if (table != null)
            {
                return(SafeGetValue(val, table[key1], key2));
            }

            return(val);
        }
Exemple #3
0
	public CSVRowItem(CSVValue[] values,Dictionary<string,int> indexForAttribName)
	{
		IndexForAttribName = indexForAttribName;
		Values = values;
//		for (int i = 0;i <values.Length;i++) {
//			QPrint.Warn (values [i]);
//
//		}
	}
Exemple #4
0
        //安全取得值
        public static CSVValue SafeGetValue(CSVValue val, CSVObject obj, string key2)
        {
            if (obj != null)
            {
                if (obj.HadKey(key2))
                {
                    return(obj[key2]);
                }
            }

            return(val);
        }
Exemple #5
0
		// 创建值
		private void CreateValues()
		{
			values = new CSVValue[itemCount][];

			for (int rowIndex = 0; rowIndex < itemCount; rowIndex++) {
				values[rowIndex] = new CSVValue[attribCount];

				for (int colIndex = 0; colIndex < attribCount; colIndex++) {
					values [rowIndex] [colIndex] = new CSVValue (heads[colIndex],strs[rowIndex + 1][colIndex],types[colIndex],rowIndex,colIndex);
				}
			}
		}
Exemple #6
0
        // 创建值
        private void CreateValues()
        {
            values = new CSVValue[itemCount][];

            for (int rowIndex = 0; rowIndex < itemCount; rowIndex++)
            {
                values[rowIndex] = new CSVValue[attribCount];

                for (int colIndex = 0; colIndex < attribCount; colIndex++)
                {
                    values [rowIndex] [colIndex] = new CSVValue(heads[colIndex], strs[rowIndex + 1][colIndex], types[colIndex], rowIndex, colIndex);
                }
            }
        }
        public void DoWork(Connection connection, ProjectDto projectDto)
        {
            GenericRepository genericRepository = new GenericRepository(connection);

            foreach (CSVRow row in projectDto.CsvDefaultPreset.GetValues())
            {
                CSVValue typeIdValue          = projectDto.CsvDefaultPreset.GetValueToColumn(row, "ID");
                CSVValue defaultPresetIdValue = projectDto.CsvDefaultPreset.GetValueToColumn(row, "DEFAULT_PRESET_ID");
                Guid     typeId          = Converter.ConvertValue <Guid>(typeIdValue.GetValue());
                Guid     defaultPresetId = Converter.ConvertValue <Guid>(defaultPresetIdValue.GetValue());

                CompositeType compositeType = genericRepository.Find <CompositeType>(typeId);
                compositeType.DefaultPresetId = defaultPresetId;
                genericRepository.Persist <CompositeType>(compositeType);
            }
        }
        public void DoWork(Connection connection, ProjectDto projectDto)
        {
            GenericRepository genericRepository = new GenericRepository(connection);

            foreach (CSVRow row in projectDto.CsvTypeType.GetValues())
            {
                CSVValue subTypeIdValue   = projectDto.CsvTypeType.GetValueToColumn(row, "SUB_TYPE_ID");
                CSVValue superTypeIdValue = projectDto.CsvTypeType.GetValueToColumn(row, "SUPER_TYPE_ID");
                Guid     subTypeId        = Converter.ConvertValue <Guid>(subTypeIdValue.GetValue());
                Guid     superTypeId      = Converter.ConvertValue <Guid>(superTypeIdValue.GetValue());

                CompositeType subCompositeType   = genericRepository.Find <CompositeType>(subTypeId);
                CompositeType superCompositeType = genericRepository.Find <CompositeType>(superTypeId);
                if (subCompositeType.SuperTypes == null)
                {
                    subCompositeType.SuperTypes = new List <CompositeType>();
                }
                subCompositeType.SuperTypes.Add(superCompositeType);
                genericRepository.Persist <CompositeType>(subCompositeType);
            }
        }
Exemple #9
0
        private T CreateEntity <T, U>(CSVFile file, CSVRow row, Guid projectId)
            where T : BaseEntity
            where U : BaseDto
        {
            T entity = Activator.CreateInstance <T>();

            if (typeof(IProjectAwareEntity).IsAssignableFrom(typeof(T)))
            {
                ((IProjectAwareEntity)entity).ProjectId = projectId;
            }
            if (typeof(IStateAwareEntity).IsAssignableFrom(typeof(T)))
            {
                ((IStateAwareEntity)entity).State = State.BUILTIN;
            }

            List <PropertyInfo> csvAttributePropertyInfos = typeof(U).GetProperties().Where(x => Attribute.IsDefined(x, typeof(CSVAttributeAttribute))).ToList();

            foreach (PropertyInfo csvAttributePropertyInfo in csvAttributePropertyInfos)
            {
                CSVAttributeAttribute csvAttribute = csvAttributePropertyInfo.GetCustomAttribute <CSVAttributeAttribute>();
                CSVValue currentValue = file.GetValueToColumn(row, csvAttribute.Name);
                if (currentValue == null)
                {
                    ValidationResult validationResult = new ValidationResult();
                    validationResult.Add(new ValidationMessage(ValidationType.ERROR, MessageKeyConstants.ERROR_MESSAGE_WRONG_CSV_FILE_ON_INPUT));
                    throw new ValidationException(validationResult);
                }
                object convertedValue = Converter.ConvertValue(csvAttributePropertyInfo.PropertyType, currentValue.GetValue());

                PropertyInfo entityPropertyInfo = entity.GetType().GetProperty(csvAttributePropertyInfo.Name);
                if (entityPropertyInfo != null)
                {
                    entityPropertyInfo.SetValue(entity, convertedValue);
                }
            }
            return(entity);
        }
Exemple #10
0
		public void SetValue(int index,CSVValue value)
		{
			values [index] = value;
			indexForValue [value.StrValue] = index;
		}
 public void SetValue(int index, CSVValue value)
 {
     values [index] = value;
     indexForValue [value.StrValue] = index;
 }
Exemple #12
0
    static void OnLoadCSVFile(string strs, string fileName)
    {
        string[] contents = strs.Replace("\r\n", "\r").Split('\r');

        //line 1, for word value type defined
        string[] wordTypeStr = contents[0].Split(',');
        //line 2, for word key defined
        string[] wordKeyNameStr = contents[1].Split(',');

        if (wordTypeStr.Length != wordKeyNameStr.Length)
        {
            Debuger.LogError("CSVTableLoader", "Load {0} csv file failed, because of word type length not equal to word key length", fileName);
            return;
        }

        //search the key word
        int keyWordHierarchyLevel = 0;

        foreach (string str in wordTypeStr)
        {
            if (str[0] == 'K' || str[0] == 'k')
            {
                keyWordHierarchyLevel = keyWordHierarchyLevel + 1;
            }
        }

        //hierarchy level should not be bigger than 2
        if (keyWordHierarchyLevel == 0 || keyWordHierarchyLevel > 2)
        {
            Debuger.LogError("CSVTableLoader", "Load {0} csv file failed, because of the incorrect key word count", fileName);
            return;
        }


        CSVTableContainer csvContainer = new CSVTableContainer(keyWordHierarchyLevel);

        //entry content
        for (int i = 2; i < contents.Length; i++)
        {
            if (string.IsNullOrEmpty(contents[i]))
            {
                continue;
            }

            Dictionary <string, CSVValue> rowDict = new Dictionary <string, CSVValue>();

            string[] rowContent = contents[i].Split(',');
            for (int j = 0; j < rowContent.Length; j++)
            {
                // column name as key                     //content string  //value type string
                rowDict[wordKeyNameStr[j]] = new CSVValue(rowContent[j], wordTypeStr[j]);
            }

            //store the entry to root dict
            if (keyWordHierarchyLevel == 1)
            {
                csvContainer.SetRow(rowContent[0], rowDict);
            }
            else if (keyWordHierarchyLevel == 2)
            {
                csvContainer.SetRow(rowContent[0], rowContent[1], rowDict);
            }
        }

        _CSVTableCache[fileName] = csvContainer;
    }