예제 #1
0
 private void Load(string file, string delimiter, List <string> reloadLog)
 {
     using (StreamReader reader = new StreamReader(file))
     {
         int                    lineNumber = 0;
         string                 line;
         Type                   currentType     = null;
         IDenizenMetaType       currentMeta     = null;
         ISingleOrList <string> currentProperty = null;
         string                 propertyValue   = string.Empty;
         while ((line = reader.ReadLine()) != null)
         {
             lineNumber++;
             if (currentType == null)
             {
                 int index = line.IndexOf(delimiter + " <--[");
                 if (index >= 0)
                 {
                     string type = line.Substring(index + (delimiter + " <--[").Length);
                     index = type.IndexOf(']');
                     if (index >= 0)
                     {
                         type = type.Substring(0, index).ToLower();
                         if (KnownMetaTypes.TryGetValue(type, out currentType))
                         {
                             currentMeta = (IDenizenMetaType)MetaTypeConstructors[currentType].Invoke(NO_OBJECTS);
                         }
                         else
                         {
                             reloadLog.Add($"Unknown meta type on line {lineNumber} in file: {file}");
                             reloadLog.Add($"'{type}'");
                             reloadLog.Add(line);
                         }
                     }
                     else
                     {
                         reloadLog.Add($"Invalid opening meta formatting on line {lineNumber} in file: {file}");
                         reloadLog.Add(line);
                     }
                 }
             }
             else
             {
                 int  index = line.IndexOf(delimiter + " @");
                 bool isEnd = line.IndexOf(delimiter + " -->") >= 0;
                 if ((index >= 0 || isEnd) && currentProperty != null)
                 {
                     try
                     {
                         currentProperty.Add(propertyValue.Trim());
                     }
                     catch (InvalidOperationException)
                     {
                         reloadLog.Add($"Invalid multi-section meta on line {lineNumber} in file: {file}");
                         reloadLog.Add(line);
                     }
                     currentProperty = null;
                     propertyValue   = string.Empty;
                 }
                 if (isEnd)
                 {
                     KnownMeta[currentType].Add(currentMeta);
                     currentType = null;
                     currentMeta = null;
                 }
                 else if (index >= 0)
                 {
                     string property = line.Substring(index + (delimiter + " @").Length).Trim();
                     index = property.IndexOf(' ');
                     if (index >= 0)
                     {
                         propertyValue += property.Substring(index + 1) + "\n";
                         property       = property.Substring(0, index);
                     }
                     if (MetaTypeProperties[currentType].TryGetValue(property.ToLower(), out MetaPropertyAttribute propertyAttribute))
                     {
                         PropertyInfo propertyInfo = propertyAttribute.PropertyInfo;
                         currentProperty = (ISingleOrList <string>)propertyInfo.GetValue(currentMeta);
                         if (currentProperty == null)
                         {
                             currentProperty = (ISingleOrList <string>)propertyInfo.PropertyType.GetConstructor(NO_TYPES).Invoke(NO_OBJECTS);
                             propertyInfo.SetValue(currentMeta, currentProperty);
                         }
                     }
                     else
                     {
                         reloadLog.Add($"Unknown {currentType.Name} property on line {lineNumber} in file: {file}");
                         reloadLog.Add(line);
                         propertyValue = string.Empty;
                     }
                 }
                 else if (currentProperty != null)
                 {
                     index = line.IndexOf(delimiter + " ");
                     if (index >= 0)
                     {
                         propertyValue += line.Substring(index + (delimiter + " ").Length) + "\n";
                     }
                 }
             }
         }
     }
 }
예제 #2
0
 /// <summary>
 /// Creates a new message containing information about a Denizen meta type.
 /// </summary>
 /// <param name="meta">The meta information.</param>
 /// <param name="matchLevel">How well the meta matched search input.</param>
 public DenizenMetaMessage(IDenizenMetaType meta, SearchMatchLevel matchLevel)
 {
     Meta       = meta;
     MatchLevel = matchLevel;
 }