Created
January 31, 2013 20:29
-
-
Save nairdo/4686159 to your computer and use it in GitHub Desktop.
Opening a NuGet package...
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// From NuGetPackageExplorer's MainWindow OpenLocalPackageCore(string packagePath) | |
/// | |
private bool OpenLocalPackageCore(string packagePath) | |
{ | |
IPackage package = null; | |
try | |
{ | |
string extension = Path.GetExtension(packagePath); | |
if (extension.Equals(Constants.PackageExtension, StringComparison.OrdinalIgnoreCase)) | |
{ | |
package = new ZipPackage(packagePath); | |
} | |
else if (extension.Equals(Constants.ManifestExtension, StringComparison.OrdinalIgnoreCase)) | |
{ | |
var builder = new PackageBuilder(packagePath); | |
package = builder.Build(); | |
} | |
} | |
catch (Exception ex) | |
{ | |
UIServices.Show(ex.Message, MessageLevel.Error); | |
return false; | |
} | |
if (package != null) | |
{ | |
// LocalPackage is below... | |
LoadPackage(package, packagePath, PackageType.LocalPackage); | |
return true; | |
} | |
return false; | |
} | |
/// | |
/// This is from the same class, but it's doing ViewModel stuff we don't have to worry about... | |
/// | |
private void LoadPackage(IPackage package, string packagePath, PackageType packageType) | |
{ | |
DisposeViewModel(); | |
if (package != null) | |
{ | |
if (!HasLoadedContent<PackageViewer>()) | |
{ | |
var packageViewer = new PackageViewer(UIServices, PackageChooser); | |
var binding = new Binding | |
{ | |
Converter = new NullToVisibilityConverter(), | |
FallbackValue = Visibility.Collapsed | |
}; | |
packageViewer.SetBinding(VisibilityProperty, binding); | |
MainContentContainer.Children.Add(packageViewer); | |
// HACK HACK: set the Export of IPackageMetadataEditor here | |
EditorService = packageViewer.PackageMetadataEditor; | |
} | |
PackageViewModel packageViewModel = PackageViewModelFactory.CreateViewModel(package, packagePath); | |
packageViewModel.PropertyChanged += OnPackageViewModelPropertyChanged; | |
DataContext = packageViewModel; | |
if (!String.IsNullOrEmpty(packagePath)) | |
{ | |
_mruManager.NotifyFileAdded(package, packagePath, packageType); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment