InfoWindowLoader.loadInfoFromFile C# (CSharp) Method

loadInfoFromFile() public method

public loadInfoFromFile ( string filePath ) : LinkedList
filePath string
return LinkedList
  public LinkedList<StandardInfoWindowInfo> loadInfoFromFile(string filePath)
  {
    Logger.Log("InfoWindowLoader::loadInfoFromFile("+filePath+")", Logger.Level.INFO);

    LinkedList<StandardInfoWindowInfo> resultInfo = new LinkedList<StandardInfoWindowInfo>();

    XmlDocument xmlDoc = Tools.getXmlDocument(filePath);

    XmlNodeList infoList = xmlDoc.GetElementsByTagName(InfoWindowXMLTags.INFO);

    foreach (XmlNode infoNode in infoList)
    {
      reinitVars();
      //common info attributes
      try {
        _code = infoNode.Attributes[InfoWindowXMLTags.CODE].Value;
      }
      catch (NullReferenceException exc) {
        Logger.Log("InfoWindowLoader::loadInfoFromFile bad xml, missing field\n"+exc, Logger.Level.WARN);
        continue;
      }
      catch (Exception exc) {
        Logger.Log("InfoWindowLoader::loadInfoFromFile failed, got exc="+exc, Logger.Level.WARN);
        continue;
      }

      if (checkString(_code)) {
        foreach (XmlNode attr in infoNode){
          switch (attr.Name){
            case InfoWindowXMLTags.TEXTURE:
              _texture = attr.InnerText;
              break;
            case InfoWindowXMLTags.NEXT:
              _next = attr.InnerText;
                break;
            case InfoWindowXMLTags.CANCEL:
              _cancel = attr.InnerText;
              break;
            default:
                Logger.Log("InfoWindowLoader::loadInfoFromFile unknown attr "+attr.Name+" for info node", Logger.Level.WARN);
              break;
          }
        }
        if(
             checkString(_texture)
          && checkString(_next)
          //_cancel is optional, therefore no need to check it
          )
        {
          _info = new StandardInfoWindowInfo(_code, _texture, _next, _cancel);
        }
        if(null != _info)
        {
          resultInfo.AddLast(_info);
        }
      }
      else
      {
        Logger.Log("InfoWindowLoader::loadInfoFromFile Error : missing attribute code in info node", Logger.Level.WARN);
      }
    }
    return resultInfo;
  }

Usage Example

Beispiel #1
0
 private void loadDataIntoDico(string[] inputFiles, Dictionary<string, StandardInfoWindowInfo> dico)
 {      
   InfoWindowLoader iwLoader = new InfoWindowLoader();
   
   string loadedFiles = "";
   
   foreach (string file in inputFiles) {
     foreach (StandardInfoWindowInfo info in iwLoader.loadInfoFromFile(file)) {
       info._next = string.IsNullOrEmpty(info._next)?info._next:info._next+completeNameSuffix;
       info._cancel = string.IsNullOrEmpty(info._cancel)?info._cancel:info._cancel+completeNameSuffix;
       dico.Add(info._code, info);
     }
     if(!string.IsNullOrEmpty(loadedFiles)) {
       loadedFiles += ", ";
     }
     loadedFiles += file;
   }
   
   Logger.Log("ModalManager::loadDataIntoDico loaded "+loadedFiles, Logger.Level.DEBUG);
 }
All Usage Examples Of InfoWindowLoader::loadInfoFromFile