Ejemplo n.º 1
0
 /// <summary>
 /// Get content of smb.conf file
 /// </summary>
 /// <exception cref="T:OSCommander.CommandResponseParsingException">If there is command response, but parsing will fail.</exception>
 public IEnumerable <SambaEntry> Get()
 {
     try
     {
         var text  = _sambaService.Get();
         var lines = text
                     .Split('\n')
                     .Where(c => c.Trim() != string.Empty &&
                            c[0] != '#' &&
                            c[0] != ';' &&
                            c[0] != '\r'); // skip comments and carriage returns
         var        result       = new List <SambaEntry>();
         SambaEntry currentEntry = null;
         foreach (var line in lines)
         {
             if (EntryCheck(line) is var entryCheck && entryCheck != null)
             {
                 if (currentEntry != null)
                 {
                     result.Add(currentEntry);
                 }
                 currentEntry = new SambaEntry(entryCheck);
                 continue;
             }
             if (ParamCheck(line) is var paramCheck && paramCheck.Key != null)
             {
                 currentEntry?.Params.Add(paramCheck);
             }
         }
         if (currentEntry != null)
         {
             result.Add(currentEntry);
         }
         return(result);
     }
     catch (Exception ex)
     {
         throw new CommandResponseParsingException(ex);
     }
 }