151 lines
3.6 KiB
C#
151 lines
3.6 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
|
|
namespace Intel.Management.PSModule
|
|
{
|
|
class ChildWriter
|
|
{
|
|
List<DriveItem> _list;
|
|
// bool _cachResults;
|
|
DriveProvider _provider;
|
|
DriveContainer _parent;
|
|
string _path;
|
|
bool _recurse;
|
|
|
|
|
|
public ChildWriter(DriveContainer parent, string path, bool recurse,DriveProvider provider)
|
|
{
|
|
_list = new List<DriveItem>();
|
|
//_cachResults = true;
|
|
_provider = provider;
|
|
_parent = parent;
|
|
_path = path;
|
|
_recurse = recurse;
|
|
}
|
|
|
|
public ChildWriter()
|
|
{
|
|
//_cachResults = true;
|
|
}
|
|
|
|
public void SetParent(DriveContainer newParent)
|
|
{
|
|
if (_path !=null || ( newParent != null && _parent != null))
|
|
throw new InvalidOperationException();
|
|
|
|
_parent = newParent;
|
|
if (_parent == null)
|
|
{
|
|
_list.Clear();
|
|
_list = null;
|
|
_path = null;
|
|
//_cachResults = true;
|
|
_recurse = false;
|
|
|
|
}
|
|
else
|
|
{
|
|
_list = new List<DriveItem>();
|
|
}
|
|
}
|
|
|
|
public void Add(DriveItem[] items)
|
|
{
|
|
_list.AddRange(items);
|
|
}
|
|
|
|
public void Add(DriveItem item)
|
|
{
|
|
_list.Add(item);
|
|
}
|
|
|
|
public DriveItem FindItem(string name)
|
|
{
|
|
foreach (DriveItem item in _list)
|
|
{
|
|
if (string.Compare(item.Name, name) == 0)
|
|
return item;
|
|
}
|
|
return null;
|
|
}
|
|
|
|
public DriveProvider Provider
|
|
{
|
|
get
|
|
{
|
|
return _provider;
|
|
}
|
|
set
|
|
{
|
|
_provider = value;
|
|
}
|
|
}
|
|
|
|
/* public bool CacheResults
|
|
{
|
|
get { return _cachResults; }
|
|
set { _cachResults = value; }
|
|
}*/
|
|
|
|
public DriveItem[] Children
|
|
{
|
|
get { return _list.ToArray(); }
|
|
}
|
|
|
|
public void Flush()
|
|
{
|
|
WriteChildren(_parent, _path);
|
|
_list.Clear();
|
|
}
|
|
|
|
public bool Force
|
|
{
|
|
get
|
|
{
|
|
if (_provider != null)
|
|
return _provider.Force.IsPresent;
|
|
return false;
|
|
}
|
|
}
|
|
|
|
private void WriteChildren(DriveContainer parent, string parentPath)
|
|
{
|
|
DriveItem[] items = items=parent.GetChildItems();
|
|
|
|
if (items == null || Force ) //items have not been retrieved
|
|
{
|
|
if (_list.Count==0)
|
|
parent.GetChildItems(this); // get items into the writer
|
|
items = _list.ToArray();
|
|
_list.Clear();
|
|
parent.SetChildItems(items);
|
|
}
|
|
|
|
if (parentPath != null)
|
|
{
|
|
foreach (DriveItem item in items)
|
|
{
|
|
WriteItem(item, parentPath + "\\" + item.Name);
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
private void WriteItem(DriveItem item,string childPath)
|
|
{
|
|
if (_path != null)
|
|
{
|
|
_provider.WriteItemObject(item.GetReturnObject(),childPath, item is DriveContainer);
|
|
}
|
|
|
|
if (item is DriveContainer && _recurse)
|
|
{
|
|
WriteChildren((DriveContainer)item, childPath);
|
|
}
|
|
}
|
|
}//End ChildWriter
|
|
|
|
}//End Namespace
|