void NewItem( string path, bool isParentPathNodeFactory, INodeFactory factory, string itemTypeName, object newItemValue )
{
var @new = factory as INewItem;
if (null == factory || null == @new)
{
WriteCmdletNotSupportedAtNodeError(path, ProviderCmdlet.NewItem, NewItemNotSupportedErrorID);
return;
}
var fullPath = path;
var parentPath = fullPath;
var child = isParentPathNodeFactory ? GetChildName(path) : null;
if( null != child )
{
parentPath = GetParentPath(fullPath, GetRootPath());
}
if (!ShouldProcess(fullPath, ProviderCmdlet.NewItem))
{
return;
}
try
{
var item = @new.NewItem(CreateContext(fullPath), child, itemTypeName, newItemValue);
PathNode node = item as PathNode;
WritePathNode(parentPath, node);
}
catch (Exception e)
{
WriteGeneralCmdletError(e, NewItemInvokeErrorID, fullPath);
}
}