Пример #1
0
        public static void SaveDefinitionStub(string file, DataHolderDefinition dataHolderDef)
        {
            XmlDataHolderDefinition holderDefinition = new XmlDataHolderDefinition()
            {
                Name          = dataHolderDef.Name,
                DefaultTables = new string[1] {
                    " "
                },
                Fields = new DataFieldDefinition[dataHolderDef.Fields.Count]
            };
            int num = 0;

            foreach (IDataField field in dataHolderDef.Fields.Values)
            {
                holderDefinition.Fields[num++] = LightDBMgr.DataFieldCreators[(int)field.DataFieldType](field);
            }
            LightRecordXmlConfig lightRecordXmlConfig = new LightRecordXmlConfig();

            lightRecordXmlConfig.FileName    = file;
            lightRecordXmlConfig.DataHolders = new XmlDataHolderDefinition[1]
            {
                holderDefinition
            };
            lightRecordXmlConfig.Save();
        }
        /// <summary>
        /// Make sure to call <see cref="LoadTableDefinitions"/> prior to this.
        /// </summary>
        /// <param name="dir"></param>
        public void LoadDataHolderDefinitions(DirectoryInfo dir)
        {
            var fieldMap = new Dictionary <string, List <SimpleDataColumn> >();

            foreach (var cfg in LightRecordXmlConfig.LoadAll(dir))
            {
                RegisterDefintion(cfg, fieldMap);
            }

            FinishLoading(fieldMap);
        }
Пример #3
0
        public static void SaveDefinitionStub(string file, DataHolderDefinition dataHolderDef)
        {
            var def = new XmlDataHolderDefinition {
                Name          = dataHolderDef.Name,
                DefaultTables = new[] { " " },
                Fields        = new DataFieldDefinition[dataHolderDef.Fields.Count]
            };

            int i = 0;

            foreach (var field in dataHolderDef.Fields.Values)
            {
                def.Fields[i++] = DataFieldCreators[(int)field.DataFieldType](field);
            }

            var cfg = new LightRecordXmlConfig {
                FileName    = file,
                DataHolders = new[] { def }
            };

            cfg.Save();
        }
        private void RegisterDefintion(LightRecordXmlConfig cfg, Dictionary<string, List<SimpleDataColumn>> fieldMap)
        {
            var dataHolders = DataHolderDefinitions;
            XmlDataHolderDefinition lastDef = null;
            foreach (XmlDataHolderDefinition dataRawDef in cfg)
            {
                try
                {
                    if (dataRawDef.Name == null)
                    {
                        throw new DataHolderException("Invalid DataHolder-definition has no name ({0}).",
                            lastDef == null ? "First in file" : "After: " + lastDef);
                    }

                    dataRawDef.EnsureFieldsNotNull();

                    var dataDef = dataHolders.Where(def =>
                        def.Name.Equals(dataRawDef.Name, StringComparison.InvariantCultureIgnoreCase)).FirstOrDefault();

                    if (dataDef == null)
                    {
                        LightDBMgr.OnInvalidData("Invalid DataHolder-definition refers to non-existing DataHolder: " + dataRawDef.Name);
                        continue;
                    }

                    TableDefinition[] oldTables, defaultTables;
                    // Set DefaultTable
                    //if (dataRawDef.DefaultTables == null)
                    //{
                    //    throw new DataHolderException("DataHolder-definition did not specify any DefaultTable(s): " + dataRawDef);
                    //}

                    if (DefaultTables.TryGetValue(dataDef.Name, out defaultTables))
                    {
                        oldTables = defaultTables;
                    }
                    else
                    {
                        oldTables = null;
                        if (dataRawDef.DefaultTables != null)
                        {
                            defaultTables = new TableDefinition[dataRawDef.DefaultTables.Length];
                        }
                        else
                        {
                            defaultTables = new TableDefinition[0];
                        }
                    }

                    for (var i = 0; i < defaultTables.Length; i++)
                    {
                        var tableName = dataRawDef.DefaultTables[i].Trim();

                        TableDefinition defaultTable;
                        if (!TableDefinitionMap.TryGetValue(tableName, out defaultTable))
                        {
                            throw new DataHolderException("DefaultTable \"{0}\" of DataHolder \"{1}\" is not defined - " +
                                                          "Make sure to define the table in the Table collection.", tableName, dataRawDef);
                        }
                        //if (DefaultTables.ContainsKey(dataDef.Name))
                        //{
                        //    throw new DataHolderException("Found duplicate DataHolder-definition: " + dataDef.Name + " ({0})", cfg.FileName);
                        //}

                        defaultTables[i] = defaultTable;
                        defaultTable.SetMainDataHolder(dataDef, true);
                    }

                    DefaultTables[dataDef.Name] = defaultTables;

                    if (dataRawDef.DataHolderName.Contains("Trainer"))
                    {
                        ToString();
                    }
                    AddFieldMappings(dataRawDef.Fields, dataDef.Fields, fieldMap);
                    if (oldTables != null)
                    {
                        var offset = oldTables.Length;
                        Array.Resize(ref oldTables, oldTables.Length + defaultTables.Length);
                        Array.Copy(defaultTables, 0, oldTables, offset, defaultTables.Length);
                        DefaultTables[dataDef.Name] = oldTables;
                    }
                    lastDef = dataRawDef;
                }
                catch (Exception e)
                {
                    throw new DataHolderException(e, "Failed to parse DataHolder-definition \"" + dataRawDef + "\" from {0}", cfg.FileName);
                }
            }
        }
Пример #5
0
		public static void SaveDefinitionStub(string file, DataHolderDefinition dataHolderDef)
		{
			var def = new XmlDataHolderDefinition {
				Name = dataHolderDef.Name,
				DefaultTables = new[] { " " },
				Fields = new DataFieldDefinition[dataHolderDef.Fields.Count]
			};

			int i = 0;
			foreach (var field in dataHolderDef.Fields.Values)
			{
				def.Fields[i++] = DataFieldCreators[(int)field.DataFieldType](field);
			}

			var cfg = new LightRecordXmlConfig {
				FileName = file,
				DataHolders = new[] { def }
			};
			cfg.Save();
		}
Пример #6
0
        private void RegisterDefintion(LightRecordXmlConfig cfg, Dictionary <string, List <SimpleDataColumn> > fieldMap)
        {
            DataHolderDefinition[]  holderDefinitions = DataHolderDefinitions;
            XmlDataHolderDefinition holderDefinition1 = null;

            foreach (XmlDataHolderDefinition holderDefinition2 in cfg)
            {
                XmlDataHolderDefinition dataRawDef = holderDefinition2;
                try
                {
                    if (dataRawDef.Name == null)
                    {
                        throw new DataHolderException("Invalid DataHolder-definition has no name ({0}).", holderDefinition1 == null
              ? (object)"First in file"
              : (object)("After: " + (object)holderDefinition1));
                    }
                    dataRawDef.EnsureFieldsNotNull();
                    DataHolderDefinition dataDef = holderDefinitions
                                                   .Where(def =>
                                                          def.Name.Equals(dataRawDef.Name, StringComparison.InvariantCultureIgnoreCase))
                                                   .FirstOrDefault();
                    if (dataDef == null)
                    {
                        LightDBMgr.OnInvalidData("Invalid DataHolder-definition refers to non-existing DataHolder: " +
                                                 dataRawDef.Name);
                    }
                    else
                    {
                        TableDefinition[] tableDefinitionArray;
                        TableDefinition[] array;
                        if (DefaultTables.TryGetValue(dataDef.Name, out tableDefinitionArray))
                        {
                            array = tableDefinitionArray;
                        }
                        else
                        {
                            array = null;
                            tableDefinitionArray = dataRawDef.DefaultTables == null
                ? new TableDefinition[0]
                : new TableDefinition[dataRawDef.DefaultTables.Length];
                        }

                        for (int index = 0; index < tableDefinitionArray.Length; ++index)
                        {
                            string          key = dataRawDef.DefaultTables[index].Trim();
                            TableDefinition tableDefinition;
                            if (!TableDefinitionMap.TryGetValue(key, out tableDefinition))
                            {
                                throw new DataHolderException(
                                          "DefaultTable \"{0}\" of DataHolder \"{1}\" is not defined - Make sure to define the table in the Table collection.",
                                          (object)key, (object)dataRawDef);
                            }
                            tableDefinitionArray[index] = tableDefinition;
                            tableDefinition.SetMainDataHolder(dataDef, true);
                        }

                        DefaultTables[dataDef.Name] = tableDefinitionArray;
                        if (dataRawDef.DataHolderName.Contains("Trainer"))
                        {
                            ToString();
                        }
                        AddFieldMappings(dataRawDef.Fields,
                                         dataDef.Fields, fieldMap);
                        if (array != null)
                        {
                            int length = array.Length;
                            Array.Resize(ref array, array.Length + tableDefinitionArray.Length);
                            Array.Copy(tableDefinitionArray, 0, array, length,
                                       tableDefinitionArray.Length);
                            DefaultTables[dataDef.Name] = array;
                        }

                        holderDefinition1 = dataRawDef;
                    }
                }
                catch (Exception ex)
                {
                    throw new DataHolderException(ex,
                                                  "Failed to parse DataHolder-definition \"" + dataRawDef + "\" from {0}", (object)cfg.FileName);
                }
            }
        }
        private void RegisterDefintion(LightRecordXmlConfig cfg, Dictionary <string, List <SimpleDataColumn> > fieldMap)
        {
            var dataHolders = DataHolderDefinitions;
            XmlDataHolderDefinition lastDef = null;

            foreach (XmlDataHolderDefinition dataRawDef in cfg)
            {
                try
                {
                    if (dataRawDef.Name == null)
                    {
                        throw new DataHolderException("Invalid DataHolder-definition has no name ({0}).",
                                                      lastDef == null ? "First in file" : "After: " + lastDef);
                    }

                    dataRawDef.EnsureFieldsNotNull();

                    var dataDef = dataHolders.Where(def =>
                                                    def.Name.Equals(dataRawDef.Name, StringComparison.InvariantCultureIgnoreCase)).FirstOrDefault();

                    if (dataDef == null)
                    {
                        LightDBMgr.OnInvalidData("Invalid DataHolder-definition refers to non-existing DataHolder: " + dataRawDef.Name);
                        continue;
                    }

                    TableDefinition[] oldTables, defaultTables;
                    // Set DefaultTable
                    //if (dataRawDef.DefaultTables == null)
                    //{
                    //    throw new DataHolderException("DataHolder-definition did not specify any DefaultTable(s): " + dataRawDef);
                    //}

                    if (DefaultTables.TryGetValue(dataDef.Name, out defaultTables))
                    {
                        oldTables = defaultTables;
                    }
                    else
                    {
                        oldTables = null;
                        if (dataRawDef.DefaultTables != null)
                        {
                            defaultTables = new TableDefinition[dataRawDef.DefaultTables.Length];
                        }
                        else
                        {
                            defaultTables = new TableDefinition[0];
                        }
                    }

                    for (var i = 0; i < defaultTables.Length; i++)
                    {
                        var tableName = dataRawDef.DefaultTables[i].Trim();

                        TableDefinition defaultTable;
                        if (!TableDefinitionMap.TryGetValue(tableName, out defaultTable))
                        {
                            throw new DataHolderException("DefaultTable \"{0}\" of DataHolder \"{1}\" is not defined - " +
                                                          "Make sure to define the table in the Table collection.", tableName, dataRawDef);
                        }
                        //if (DefaultTables.ContainsKey(dataDef.Name))
                        //{
                        //    throw new DataHolderException("Found duplicate DataHolder-definition: " + dataDef.Name + " ({0})", cfg.FileName);
                        //}

                        defaultTables[i] = defaultTable;
                        defaultTable.SetMainDataHolder(dataDef, true);
                    }

                    DefaultTables[dataDef.Name] = defaultTables;

                    if (dataRawDef.DataHolderName.Contains("Trainer"))
                    {
                        ToString();
                    }
                    AddFieldMappings(dataRawDef.Fields, dataDef.Fields, fieldMap);
                    if (oldTables != null)
                    {
                        var offset = oldTables.Length;
                        Array.Resize(ref oldTables, oldTables.Length + defaultTables.Length);
                        Array.Copy(defaultTables, 0, oldTables, offset, defaultTables.Length);
                        DefaultTables[dataDef.Name] = oldTables;
                    }
                    lastDef = dataRawDef;
                }
                catch (Exception e)
                {
                    throw new DataHolderException(e, "Failed to parse DataHolder-definition \"" + dataRawDef + "\" from {0}", cfg.FileName);
                }
            }
        }