public void ReadXml(XmlReader reader) { string startElementName = reader.Name; string currentElementName, currentNodeName, currentItemName; this.sourceList.Clear(); this.indexList.Clear(); do { currentElementName = reader.Name; if (currentElementName == startElementName && (reader.MoveToContent() == XmlNodeType.EndElement || reader.IsEmptyElement)) { reader.Read(); break; } switch (currentElementName) { case "Source": #region Read Source Source source = new Source(); source.SourceName = SupportClass.FileUtil.GetXmlAttribute(reader, "Name", typeof(string)); do { currentNodeName = reader.Name; if (currentNodeName == currentElementName && (reader.MoveToContent() == XmlNodeType.EndElement || reader.IsEmptyElement)) { break; } switch (currentNodeName) { case "DbType": source.DBType = DbType.GetDbType(reader.ReadElementString()); break; case "HostName": source.HostName = reader.ReadElementString(); break; case "DataBase": source.DataBase = reader.ReadElementString(); break; case "UserName": source.UserName = reader.ReadElementString(); break; case "Password": source.Password = reader.ReadElementString(); break; case "Query": source.Query = reader.ReadElementString(); break; case "PrimaryKey": source.PrimaryKey = reader.ReadElementString(); break; case "Fields": List<IndexField> fpList = new List<IndexField>(); do { currentItemName = reader.Name; if (currentItemName == currentNodeName && (reader.MoveToContent() == XmlNodeType.EndElement || reader.IsEmptyElement)) { break; } switch (currentItemName) { case "Field": IndexField fp = new IndexField(); fp.Name = SupportClass.FileUtil.GetXmlAttribute(reader, "Name", typeof(string)); fp.Caption = SupportClass.FileUtil.GetXmlAttribute(reader, "Caption", typeof(string)); fp.Boost = float.Parse(SupportClass.FileUtil.GetXmlAttribute(reader, "Boost", typeof(float))); fp.IsTitle = bool.Parse(SupportClass.FileUtil.GetXmlAttribute(reader, "IsTitle", typeof(bool))); fp.Order = int.Parse(SupportClass.FileUtil.GetXmlAttribute(reader, "Order", typeof(int))); fpList.Add(fp); reader.Read(); break; default: reader.Read(); break; } } while (true); source.Fields=fpList; reader.Read(); break; default : reader.Read(); break; } } while (true); this.sourceList.Add(source); #endregion reader.Read(); break; case "Index": #region Read Index IndexSet indexSet = new IndexSet(); indexSet.IndexName = SupportClass.FileUtil.GetXmlAttribute(reader, "Name", typeof(string)); indexSet.Caption = SupportClass.FileUtil.GetXmlAttribute(reader, "Caption", typeof(string)); indexSet.Type = IndexType.GetIndexType(SupportClass.FileUtil.GetXmlAttribute(reader, "Type", typeof(string))); do { currentNodeName = reader.Name; if (currentNodeName == currentElementName && (reader.MoveToContent() == XmlNodeType.EndElement || reader.IsEmptyElement)) { break; } switch (currentNodeName) { case "Source": indexSet.SourceName= reader.ReadElementString(); break; case "Path": indexSet.Path = reader.ReadElementString(); break; default: reader.Read(); break; } } while (true); this.indexList.Add(indexSet); #endregion reader.Read(); break; case "FileIndex": #region Read FileIndex do { currentNodeName = reader.Name; if (currentNodeName == currentElementName && (reader.MoveToContent() == XmlNodeType.EndElement || reader.IsEmptyElement)) { break; } switch (currentNodeName) { case "Path": this.fileSet.Path = reader.ReadElementString(); break; case "Directories": List<string> dirList = new List<string>(); do { currentItemName = reader.Name; if (currentItemName == currentNodeName && (reader.MoveToContent() == XmlNodeType.EndElement || reader.IsEmptyElement)) { break; } switch (currentItemName) { case "Directory": dirList.Add(reader.ReadElementString()); break; default: reader.Read(); break; } } while (true); this.fileSet.BaseDirs =dirList; reader.Read(); break; default: reader.Read(); break; } } while (true); #endregion reader.Read(); break; case "Dictionary": #region Read Dictionary do { currentNodeName = reader.Name; if (currentNodeName == currentElementName && (reader.MoveToContent() == XmlNodeType.EndElement || reader.IsEmptyElement)) { break; } switch (currentNodeName) { case "BasePath": this.dictSet.BasePath = reader.ReadElementString(); break; case "NamePath": this.dictSet.NamePath = reader.ReadElementString(); break; case "NumberPath": this.dictSet.NumberPath = reader.ReadElementString(); break; case "FilterPath": this.dictSet.FilterPath = reader.ReadElementString(); break; case "CustomPaths": List<string> pathList = new List<string>(); do { currentItemName = reader.Name; if (currentItemName == currentNodeName && (reader.MoveToContent() == XmlNodeType.EndElement || reader.IsEmptyElement)) { break; } switch (currentItemName) { case "Path": pathList.Add(reader.ReadElementString()); break; default: reader.Read(); break; } } while (true); this.dictSet.CustomPaths = pathList; reader.Read(); break; default: reader.Read(); break; } } while (true); #endregion reader.Read(); break; case "Indexer": #region Read Indexer do { currentNodeName = reader.Name; if (currentNodeName == currentElementName && (reader.MoveToContent() == XmlNodeType.EndElement || reader.IsEmptyElement)) { break; } switch (currentNodeName) { case "MainIndexTime": this.indexer.MainIndexReCreateTime = DateTime.Parse(reader.ReadElementString()); break; case "MainIndexSpan": this.indexer.MainIndexReCreateTimeSpan = int.Parse(reader.ReadElementString()); break; case "IncrIndexSpan": this.indexer.IncrIndexReCreateTimeSpan = int.Parse(reader.ReadElementString()); break; case "RamBufferSize": this.indexer.RamBufferSize = double.Parse(reader.ReadElementString()); break; case "MaxBufferedDocs": this.indexer.MaxBufferedDocs = int.Parse(reader.ReadElementString()); break; case "MaxFieldLength": this.indexer.MaxFieldLength = int.Parse(reader.ReadElementString()); break; case "MergeFactor": this.indexer.MergeFactor = int.Parse(reader.ReadElementString()); break; default: reader.Read(); break; } } while (true); #endregion reader.Read(); break; case "Searchd": #region Read Searchd do { currentNodeName = reader.Name; if (currentNodeName == currentElementName && (reader.MoveToContent() == XmlNodeType.EndElement || reader.IsEmptyElement)) { break; } switch (currentNodeName) { case "Address": this.searchd.Address = reader.ReadElementString(); break; case "LogPath": this.searchd.LogPath = reader.ReadElementString(); break; case "MaxChildren": this.searchd.MaxChildren = int.Parse(reader.ReadElementString()); break; case "MaxMatches": this.searchd.MaxMatches = int.Parse(reader.ReadElementString()); break; case "MaxTrans": this.searchd.MaxTrans = int.Parse(reader.ReadElementString()); break; case "Port": this.searchd.Port = int.Parse(reader.ReadElementString()); break; case "TimeOut": this.searchd.TimeOut = int.Parse(reader.ReadElementString()); break; case "QueryLog": this.searchd.QueryLogPath = reader.ReadElementString(); break; case "MinScore": this.searchd.MinScore = float.Parse(reader.ReadElementString()); break; default: reader.Read(); break; } } while (true); #endregion reader.Read(); break; default: reader.Read(); break; } } while (true); }
public SearchField(Field field, IndexField properties) : this(field.Name(), properties.Caption, field.StringValue(), field.StringValue(), properties.Boost, properties.IsTitle, true, properties.Order) { }