New cmdline-option to insert computer names?

Topics: missing Features
Mar 25, 2015 at 10:04 AM
How do you think about a new cmdline-option to insert computer names? I got 2 ideas (code copied from "/Path"-option :-):

--- example 1: /List
// Usage: CMCollCtr /List:[COMPUTERNAME1],[COMPUTERNAME2],[COMPUTERNAME3]
if (sArg.StartsWith("/List:", true, System.Globalization.CultureInfo.CurrentCulture))
{
    var computerList = sArg.Remove(0, 6).Split(',');

    MainForm pForm = new MainForm();
    pForm.Show();
    System.Threading.Thread.Sleep(200);

    try
    {
        AnonymousDelegate clearbinding = delegate()
        {
            pForm.computerBindingSource.Clear();
        };
        pForm.Invoke(clearbinding);
    
        foreach (var computerName in computerList)
        {
            AnonymousDelegate updatecounts = delegate()
            {
                pForm.computerBindingSource.AllowNew = true;
                Computer oComp = new Computer()
                {
                    ComputerName = computerName
                };
                pForm.computerBindingSource.Add(oComp);
            };
            pForm.Invoke(updatecounts);
        }
    
        AnonymousDelegate updateBinding = delegate()
        {
            pForm.dataGridView1.DataSource = pForm.computerBindingSource;
        };
        pForm.Invoke(updateBinding);
    }
    catch (Exception ex)
    {
        MessageBox.Show(ex.Message, "Error");
    }
    
    Application.Run(pForm);
}
--- example 2: /File
// Usage: CMCollCtr /File:[Filename]
if (sArg.StartsWith("/File:", true, System.Globalization.CultureInfo.CurrentCulture))
{
    var fileName = sArg.Remove(0, 6);

    MainForm pForm = new MainForm();
    pForm.Show();
    System.Threading.Thread.Sleep(200);

    try
    {
        AnonymousDelegate clearbinding = delegate()
        {
            pForm.computerBindingSource.Clear();
        };
        pForm.Invoke(clearbinding);

        var sr = new System.IO.StreamReader(fileName);
        string computerName;
        while ((computerName = sr.ReadLine()) != null)
        {
            AnonymousDelegate updatecounts = delegate()
            {
                pForm.computerBindingSource.AllowNew = true;
                Computer oComp = new Computer()
                {
                    ComputerName = computerName
                };
                pForm.computerBindingSource.Add(oComp);
            };
            pForm.Invoke(updatecounts);
        }
    
        AnonymousDelegate updateBinding = delegate()
        {
            pForm.dataGridView1.DataSource = pForm.computerBindingSource;
        };
        pForm.Invoke(updateBinding);
    }
    catch (Exception ex)
    {
        MessageBox.Show(ex.Message, "Error");
    }
    
    Application.Run(pForm);
}
Coordinator
Apr 1, 2015 at 2:51 PM
This discussion has been copied to a work item. Click here to go to the work item and continue the discussion.
Marked as answer by rzander on 4/1/2015 at 7:54 AM