本文整理汇总了C#中Branch.GetOrCreateBranch方法的典型用法代码示例。如果您正苦于以下问题:C# Branch.GetOrCreateBranch方法的具体用法?C# Branch.GetOrCreateBranch怎么用?C# Branch.GetOrCreateBranch使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Branch
的用法示例。
在下文中一共展示了Branch.GetOrCreateBranch方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ZipVault
public ZipVault(String fileName)
{
using (InternalExpose())
{
Zip = new ZipFile(fileName, Encoding.UTF8);
var zeIndex = Zip.Entries.ToDictionary(ze => ze.FileName, ze => ze);
Root = new Branch(this, null, null);
foreach (var value in Zip.Entries.Where(e => !e.IsDirectory && !e.FileName.EndsWith("$")))
{
var contentFile = value.FileName;
var metadataFile = contentFile + "$";
var valueNode = (Value)Root.CreateValue(value.FileName, ValueKind.RegularAndInternal);
valueNode.SetContent(() => zeIndex[contentFile].ExtractEager());
valueNode.RawSetMetadata(() => zeIndex.GetOrDefault(metadataFile).ExtractEager());
}
foreach (var branch in Zip.Entries.Where(e => e.IsDirectory && !e.FileName.EndsWith("$")))
{
// no need for slash, because dirname includes it
var metadataFile = branch.FileName + "$";
// some of those branches will already be created by this time
var branchNode = (Branch)Root.GetOrCreateBranch(branch.FileName);
branchNode.RawSetMetadata(() => zeIndex.GetOrDefault(metadataFile).ExtractEager());
}
// for backward compatibility (DO NOT REMOVE again, please)
var oldVersionStorage = Zip.Entries.SingleOrDefault(e => !e.IsDirectory &&
e.FileName == "version$" || e.FileName == "/version$" || e.FileName == "\\version$");
if (oldVersionStorage != null)
{
var matchingValue = Root.GetValue("version");
var possibleOverlap = Root.GetValue("$version");
if (matchingValue == null && possibleOverlap == null)
{
var versionHolder = Root.CreateValue("$version", ValueKind.Regular);
versionHolder.SetContent(() => zeIndex[oldVersionStorage.FileName].ExtractEager());
}
}
// root metadata requires special treatment since root doesn't get enumerated
Root.RawSetMetadata(() => (zeIndex.GetOrDefault("/$") ?? zeIndex.GetOrDefault("$")).ExtractEager());
Root.AfterLoad();
Root.GetBranchesRecursive().Cast<Branch>().ForEach(b => b.AfterLoad());
Root.GetValuesRecursive(ValueKind.RegularAndInternal).Cast<Value>().ForEach(v => v.AfterLoad());
(Id != Guid.Empty).AssertTrue();
(Revision is UInt64).AssertTrue();
}
}
示例2: FsVault
public FsVault(String dirName)
{
using (InternalExpose())
{
Dir = new DirectoryInfo(dirName);
var index = Entries.ToDictionary(e => e.RelPath, e => e);
Root = new Branch(this, null, null);
foreach (var value in Entries.Where(e => e.IsValue))
{
var contentFile = value;
var cfileUnbuxt = value.RelPath.Reverse().SkipWhile(c => c == '$').Reverse().StringJoin(String.Empty);
var metadataFile = index.GetOrDefault(cfileUnbuxt + "$");
var valueNode = (Value)Root.CreateValue(value.VPath, ValueKind.RegularAndInternal);
valueNode.SetContent(contentFile.ExtractEager);
if (metadataFile != null) valueNode.RawSetMetadata(metadataFile.ExtractEager);
}
foreach (var branch in Entries.Where(e => e.IsBranch))
{
// no need for slash since relpath already contains it
var metadataFile = index.GetOrDefault(branch.RelPath + "$");
// this permits duplicate directory entries
// it's ugly, but i'm cba to fix this at the moment
var branchNode = (Branch)Root.GetOrCreateBranch(branch.VPath);
if (metadataFile != null) branchNode.RawSetMetadata(metadataFile.ExtractEager);
}
// for backward compatibility (DO NOT REMOVE again, please)
var oldVersionStorage = Entries.SingleOrDefault(e => e.IsValue && e.VPath == "version$");
if (oldVersionStorage != null)
{
var matchingValue = Root.GetValue("version");
var possibleOverlap = Root.GetValue("$version");
if (matchingValue == null && possibleOverlap == null)
{
var versionHolder = Root.CreateValue("$version", ValueKind.Regular);
versionHolder.SetContent(oldVersionStorage.ExtractEager);
}
}
Root.AfterLoad();
Root.GetBranchesRecursive().Cast<Branch>().ForEach(b => b.AfterLoad());
Root.GetValuesRecursive(ValueKind.RegularAndInternal).Cast<Value>().ForEach(v => v.AfterLoad());
(Id != Guid.Empty).AssertTrue();
(Revision is UInt64).AssertTrue();
}
}