I have a program that reads that from a server. The data returned consists of a multiline string. My requirement is to cast the containing substrings (for all the lines) to a Model then later save to a database table.
This is a sample of my data :
Filesystem 1024-blocks Used Available Capacity Mounted on
rpool/ROOT/solaris-0 47185886 39055271 6723316 86% /
rpool/ROOT/solaris-0/var 47185886 334036 6723316 5% /var
/dev 0 0 0 0% /dev
/u01 104857600 92783432 12074167 89% /u01
proc 0 0 0 0% /proc
ctfs 0 0 0 0% /system/contract
And for each line i want to cast all the containing substrings to the Model 's properties. The model (Weblogic.cs) is as below :
public String Filesystem { get; set; }
public string Blocks { get; set; }
public string Used { get; set; }
public string Available { get; set; }
public string Capacity { get; set; }
public string Mount { get; set; }
For now i have made all model properties strings and will do the conversion when saving the data.
My problem is that my logic only returns data from the first line i.e when i step through the code the
servers property has Count 1:
<pre> using (SshClient ssh = new SshClient("+ server +",
"+username+", "+password+"))
{
ssh.Connect();
var result = ssh.RunCommand("df -k");
var rss = result.Result;
string[] lines = rss.Split('\n');
lines = lines.Skip(1).ToArray();
Int32 count = 6;
String[] separator = { " " };
var servers = new List<Weblogic>();
List<string> infos = new List<string>();
for (int i = 0; i < lines.Length; i++)
{
String[] strlist = lines[i].Split(separator, count,
StringSplitOptions.RemoveEmptyEntries);
foreach (var value in strlist)
{
Weblogic ci = new Weblogic();
ci.Filesystem = strlist[0];
ci.Blocks = strlist[1];
ci.Used = strlist[2];
ci.Available = strlist[3];
ci.Capacity = strlist[4];
ci.Mount = strlist[5];
servers.Add(ci);
}
}
}
What I have tried:
When i try using this approach i am able to grab all substrings
from all the lines :
<pre> using (SshClient ssh = new SshClient("+server+",
"+username+", "+password+"))
{
ssh.Connect();
var result = ssh.RunCommand("df -k");
var rss = result.Result;
string[] lines = rss.Split('\n');
lines = lines.Skip(1).ToArray();
Int32 countt = 6;
String[] separator = { " " };
var servers = new List<Weblogic>();
for (int i = 0; i < lines.Length; i++)
{
String[] strlist = lines[i].Split(separator, countt,
StringSplitOptions.RemoveEmptyEntries);
for (int j = 0; j < strlist.Length; j++)
{
string s = strlist[j];
Console.WriteLine(s);
Console.ReadKey();
}
}
}