Skip to content

Instantly share code, notes, and snippets.

@fearthecowboy
Created March 6, 2013 20:08
Show Gist options
  • Save fearthecowboy/5102603 to your computer and use it in GitHub Desktop.
Save fearthecowboy/5102603 to your computer and use it in GitHub Desktop.
public override ILocation GetLocation(string path) {
var parsedPath = Path.ParseWithContainer(path);
// strip off the azure:
/*
if (parsedPath.Scheme != string.Empty && parsedPath.Scheme != AzureDriveInfo.ProviderScheme) {
return AzureLocation.InvalidLocation;
}*/
// is this just a empty location?
if (string.IsNullOrEmpty(parsedPath.HostAndPort)) {
NamespaceProvider = NamespaceProvider ?? this;
return AzureNamespace;
}
var byAccount = AddingDrives.Union(Drives).Select(each => each as AzureDriveInfo).Where(each => each.HostAndPort == parsedPath.HostAndPort || each.ActualHostAndPort == parsedPath.HostAndPort);
if (!byAccount.Any()) {
return AzureLocation.UnknownLocation;
}
var byContainer = byAccount.Where(each => each.ContainerName == parsedPath.Container);
var byFolder = byContainer.Where(each => each.Path.IsSubpath(parsedPath)).OrderByDescending(each => each.RootPath.Length);
var result = byFolder.FirstOrDefault() ?? byContainer.FirstOrDefault() ?? byAccount.FirstOrDefault();
return new AzureLocation(result, parsedPath, null);
}
/*
private IEnumerable<AzureDriveInfo> GetByAccount(Path parsedPath) {
var drive = AddingDrives.Union(Drives).Select(each => each as AzureDriveInfo).First(e => string.IsNullOrEmpty(e.HostAndPort));
}*/
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment