本文整理汇总了C#中Logging.Emit方法的典型用法代码示例。如果您正苦于以下问题:C# Logging.Emit方法的具体用法?C# Logging.Emit怎么用?C# Logging.Emit使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Logging
的用法示例。
在下文中一共展示了Logging.Emit方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: NotePathAdded
/// <summary>Used to inform manager about the addition of another file or diretory which should be monitored by the manager (and which should eventually be pruned).</summary>
public void NotePathAdded(string pathToAdd, Logging.IMesgEmitter issueEmitter)
{
try
{
string fullPathToAdd = System.IO.Path.GetFullPath(pathToAdd);
string workingRootPath = treeRootEntry.Path;
string relativePathPart = String.Empty;
string [] relativePathSegments = null;
if (fullPathToAdd.StartsWith(workingRootPath))
{
relativePathPart = System.IO.Path.Combine(@".", fullPathToAdd.Substring(workingRootPath.Length));
relativePathSegments = relativePathPart.Split(new char [] {System.IO.Path.DirectorySeparatorChar, System.IO.Path.AltDirectorySeparatorChar});
}
string regeneratedFullPath = System.IO.Path.GetFullPath(System.IO.Path.Combine(workingRootPath, relativePathPart));
if (!String.IsNullOrEmpty(relativePathPart) && (regeneratedFullPath == fullPathToAdd))
treeRootEntry.AddRelativePath(relativePathSegments, issueEmitter);
else
issueEmitter.Emit("NotePathAdded '{0}' failed: given path is a proper subpath under under the monitored path '{1}'", pathToAdd, workingRootPath);
treeRootEntry.UpdateTree(issueEmitter);
}
catch (System.Exception ex)
{
issueEmitter.Emit("NotePathAdded '{0}' failed: error:'{1}'", pathToAdd, ex.ToString());
}
}
示例2: DeletePrunedItems
/// <summary>
/// Attempts to delete files/directories given in the list of DirectoryEntryInfo items to prune.
/// <para/>returns the number of items that were successfully deleted.
/// </summary>
/// <param name="pruneItemList">Gives the list of DirectoryEntryInfo items that are to be removed from the file system.</param>
/// <param name="deleteEmitter">Gives the IMesgEmitter that will recieve messages about the successfull deletions</param>
/// <param name="issueEmitter">Gives the IMesgEmitter that will receive any messages about failures while attempting to delete each item.</param>
/// <returns>The number of items that were successfully deleted.</returns>
public int DeletePrunedItems(List<DirectoryEntryInfo> pruneItemList, Logging.IMesgEmitter deleteEmitter, Logging.IMesgEmitter issueEmitter)
{
int deletedItemCount = 0; // actually the count of the number of items that we have attempted to delete
for (int idx = 0; idx < pruneItemList.Count; idx++)
{
DirectoryEntryInfo entryToDelete = pruneItemList[idx];
double ageInDays = entryToDelete.CreationAge.TotalDays;
if (entryToDelete.IsFile)
{
try
{
System.IO.File.Delete(entryToDelete.Path);
deletedItemCount++;
deleteEmitter.Emit("Pruned file:'{0}', size:{1}, age:{2:f3} days", entryToDelete.Path, entryToDelete.Length, ageInDays);
}
catch (System.Exception ex)
{
issueEmitter.Emit("Prune failed to delete file:'{0}', error:'{1}'", entryToDelete.Path, ex.Message);
}
}
else if (entryToDelete.IsDirectory)
{
try
{
System.IO.Directory.Delete(entryToDelete.Path);
deletedItemCount++;
deleteEmitter.Emit("Pruned directory:'{0}', size:{1}, age:{2:f3} days", entryToDelete.Path, entryToDelete.Length, ageInDays);
}
catch (System.Exception ex)
{
issueEmitter.Emit("Prune failed to delete directory:'{0}', error:'{1}'", entryToDelete.Path, ex.Message);
}
}
else
{
issueEmitter.Emit("Prune cannot delete unknown tree node at path:'{0}'", entryToDelete.Path);
}
}
return deletedItemCount;
}
示例3: AppendAndRemoveOldestTreeDirectory
/// <summary>
/// Appends a list of the DirectoryEntryInfo items for the tree item's that have been removed from the memory copy of the tree.
/// Caller is expected to attempt to delete the actual files/directories.
/// Performs UpdateTree prior to returning.
/// </summary>
public void AppendAndRemoveOldestTreeDirectory(List<DirectoryEntryInfo> pruneItemList, int maxEntriesToDeletePerIteration, Logging.IMesgEmitter issueEmitter)
{
List<DirectoryTreeEntryInfoStackItem> stack = new List<DirectoryTreeEntryInfoStackItem>();
DirectoryTreeEntryNode currentEntry = this;
// create a stack of the entries from the root down to the oldest leaf (file or directory).
// Each level in the stack retains the current entry at that level, the parent entry and the index in the parent entries content vector at which you will find the current entry
while (currentEntry != null)
{
if (currentEntry.OldestDirEntryIdx >= 0)
{
int indexOfNextEntryInCurrent = currentEntry.OldestDirEntryIdx;
DirectoryTreeEntryNode nextEntryDown = currentEntry.DirContentsNodeList[indexOfNextEntryInCurrent];
stack.Add(new DirectoryTreeEntryInfoStackItem() { Node = nextEntryDown, Parent = currentEntry, ItemIdxInParentList = indexOfNextEntryInCurrent });
currentEntry = nextEntryDown;
}
else if (!currentEntry.IsRootNode)
{
break; // reached the bottom of the search path
}
else
{
// we can never remove the root item - there is nothing further to prune.
return;
}
}
// start at the bottom of the stack and determine if that entry can be removed (or not). If so then:
// A) added it to the list of entries to remove
// B) remove it from its parrent's entry content vector
// and then repeate for the each level up in the stack until an entry is encountered that cannot be deleted (is not an empty directory after the sub item has been removed.)
while (stack.Count != 0)
{
DirectoryTreeEntryInfoStackItem stackBack = stack[stack.Count - 1];
bool removeIt = false;
bool skipIt = false;
if (!stackBack.IsValid)
break;
{
DirectoryTreeEntryNode stackBackCurrentItem = stackBack.Node;
DirectoryTreeEntryNode stackBackParentItem = stackBack.Parent;
bool isFile = stackBackCurrentItem.IsFile;
bool isNormalFile = stackBackCurrentItem.IsExistingFile;
bool isNormalDirectory = stackBackCurrentItem.IsExistingDirectory;
bool isEmptyDirectory = stackBackCurrentItem.IsEmptyDirectory;
string skipReason = null;
if (!isNormalFile && !isNormalDirectory)
skipReason = Fcns.CheckedFormat("Skipping non-normal node at path:'{0}'", Path);
skipIt = skipReason != null;
if (skipIt)
issueEmitter.Emit(skipReason);
removeIt = (isNormalFile || isEmptyDirectory) && !skipIt;
if (!removeIt && !skipIt)
break; // once we have reached a level where nothing more can be removed (ie it is not an empty directory), we stop iterating up the stack.
if (removeIt)
pruneItemList.Add(stackBackCurrentItem); // append a copy of the backEntry as a DirectoryEntryInfo object onto the removeItemVect
stackBackParentItem.DirContentsNodeList.RemoveAt(stackBack.ItemIdxInParentList);
stackBackParentItem.SetTreeUpdateNeeded(true);
if (isFile && maxEntriesToDeletePerIteration > 1)
{
// identify the other n oldest items in this directory and add them to the delte list
while (pruneItemList.Count < maxEntriesToDeletePerIteration)
{
stackBackParentItem.UpdateTree(issueEmitter);
int indexOfNextEntryInCurrentDir = stackBackParentItem.OldestDirEntryIdx;
if (indexOfNextEntryInCurrentDir < 0)
break;
DirectoryTreeEntryNode nextEntryInCurrentDir = stackBackParentItem.DirContentsNodeList[indexOfNextEntryInCurrentDir];
if (nextEntryInCurrentDir == null)
break;
// stop adding to the current list of items to delete once we reach any non-normal file - special cases will be covered on the next go around.
if (!nextEntryInCurrentDir.IsExistingFile)
break;
//.........这里部分代码省略.........
示例4: BuildTree
/// <summary>Requests the node to build the tree and allows the caller to indicate if it should be updated after being built.</summary>
public void BuildTree(bool updateAtEnd, Logging.IMesgEmitter issueEmitter)
{
try
{
// If the tree has already need built and does not have its IsTreeBuildNeeded flag set then do not (re)build this node
if (!IsTreeBuildNeeded) // this flag should only be set for directories
return;
if (!IsDirectory)
{
issueEmitter.Emit("BuildTree failed: Tree Path '{0}' is neither a normal file nor a normal directory.", Path);
}
ClearSubTreeInformation();
foreach (string fsiPath in System.IO.Directory.GetFileSystemEntries(Path))
{
DirContentsNodeList.Add(new DirectoryTreeEntryNode(fsiPath, this));
}
SetTreeUpdateNeeded(true);
int size = DirContentsNodeList.Count;
for (int idx = 0; idx < size; idx++)
{
DirectoryTreeEntryNode entry = DirContentsNodeList[idx];
if (entry == null)
continue;
if (entry.IsExistingDirectory)
entry.BuildTree(issueEmitter);
else if (!entry.IsExistingFile)
issueEmitter.Emit("BuildTree issue: Sub Tree Path '{0}' is neither a normal file nor a normal directory.", entry.Path);
}
// we have completed the tree build for this level and the levels below it
IsTreeBuildNeeded = false;
// update the tree to update our summary fields - only scan the top level as the
if (updateAtEnd)
UpdateTree(issueEmitter);
}
catch (System.Exception ex)
{
issueEmitter.Emit("BuiltTree failed at path:'{0}' error:{1}", path, ex.ToString());
}
}
示例5: AddRelativePath
/// <summary>
/// Addes a new node in the tree at the relative location under the given node produced by iteratavely concactinating the given list of relative path elements
/// onto the full path to this node and treversing downward until the relative path elements have been used up.
/// Performs UpdateTree prior to returning.
/// </summary>
public void AddRelativePath(IList<String> relativePathElementList, Logging.IMesgEmitter issueEmitter)
{
int relativePathElementListSize = relativePathElementList.Count;
if (relativePathElementListSize <= 0)
{
issueEmitter.Emit("AddRelativePath failed at node:'{0}': given relative path list is empty", Path);
return;
}
DirectoryTreeEntryNode treeScanEntry = this;
for (int rPathElemIdx = 0; ((treeScanEntry != null) && (rPathElemIdx < relativePathElementListSize)); rPathElemIdx++)
{
bool onLastRPathElement = (rPathElemIdx == (relativePathElementListSize - 1));
string leafName = relativePathElementList[rPathElemIdx];
int subLeafIdx = treeScanEntry.FindSubLeafName(leafName);
if (subLeafIdx < 0)
{
subLeafIdx = (treeScanEntry.DirContentsNodeList.Count);
string newEntryPath = System.IO.Path.Combine(treeScanEntry.Path, leafName);
DirectoryTreeEntryNode newEntry = new DirectoryTreeEntryNode(newEntryPath, treeScanEntry);
treeScanEntry.DirContentsNodeList.Add(newEntry);
if (newEntry == null)
{
issueEmitter.Emit("Allocation Failure while attempting to added entry path:{0}", newEntryPath);
}
else
{
if (newEntry.IsExistingDirectory)
{
// generally should be a noop
newEntry.BuildTree(issueEmitter);
}
else if (newEntry.IsExistingFile)
{
// nothing more to do here
}
else
{
issueEmitter.Emit("Added entry path:{0} is neither a known file or directory object", newEntry.Path);
}
}
treeScanEntry.SetTreeUpdateNeeded(true);
}
else
{
DirectoryTreeEntryNode foundEntry = treeScanEntry.DirContentsNodeList[subLeafIdx];
if (foundEntry == null)
{
issueEmitter.Emit("Null pointer encountered while traversing tree to add new entry for leaf:'{0}' under path:'{1}'", leafName, Path);
break; // cannot continue to go lower from this point down
}
else
{
if (foundEntry.IsFile)
foundEntry.Refresh();
if (!foundEntry.IsExistingDirectory && !onLastRPathElement)
{
issueEmitter.Emit("Add relative path traverse error: partial path is not a directory at {0}", foundEntry.Path);
break; // cannot continue to go lower from this point down
}
}
treeScanEntry.SetTreeUpdateNeeded(true);
}
treeScanEntry = treeScanEntry.DirContentsNodeList[subLeafIdx];
}
UpdateTree(issueEmitter);
}