Ejemplo n.º 1
0
        protected override void OnFormClosing(FormClosingEventArgs e)
        {
            if (MetadataSpecified && metadataVersion > metadataSaveVersion)
            {
                var result = MessageBox.Show(
                    this, Resources.SavePackageMetadata, Text,
                    MessageBoxButtons.YesNoCancel,
                    MessageBoxIcon.Warning);
                if (result == DialogResult.Cancel ||
                    result == DialogResult.Yes && !SaveMetadata())
                {
                    DialogResult = DialogResult.None;
                    e.Cancel     = true;
                }
            }

            if (DialogResult == DialogResult.OK)
            {
                var packageFileName =
                    packageBuilder.Id + "." +
                    packageBuilder.Version + global::NuGet.Constants.PackageExtension;
                saveFileDialog.FileName = packageFileName;
                if (entryPoint != null)
                {
                    RenamePackageFile(entryPoint, packageBuilder.Id);
                    if (entryPointLayout != null)
                    {
                        RenamePackageFile(entryPointLayout, packageBuilder.Id);
                    }
                }

                EnsureDirectory(saveFileDialog.InitialDirectory);
                if (saveFileDialog.ShowDialog() == DialogResult.OK)
                {
                    using (var dialog = new PackageOperationDialog())
                    {
                        ILogger logger = new EventLogger();
                        dialog.Text = Resources.ExportOperationLabel;
                        dialog.RegisterEventLogger((EventLogger)logger);
                        logger.Log(MessageLevel.Info,
                                   "Creating package '{0} {1}'.",
                                   packageBuilder.Id,
                                   packageBuilder.Version);
                        var dialogClosed = Observable.FromEventPattern <FormClosedEventHandler, FormClosedEventArgs>(
                            handler => dialog.FormClosed += handler,
                            handler => dialog.FormClosed -= handler);
                        var operation = Observable.Using(
                            () => Stream.Synchronized(File.Open(saveFileDialog.FileName, FileMode.Create)),
                            stream => Observable.Start(() => packageBuilder.Save(stream)).TakeUntil(dialogClosed));
                        using (var subscription = operation.ObserveOn(this).Subscribe(
                                   xs => dialog.Complete(),
                                   ex => logger.Log(MessageLevel.Error, ex.Message)))
                        {
                            if (dialog.ShowDialog() != DialogResult.OK)
                            {
                                e.Cancel = true;
                            }
                            else
                            {
                                SystemSounds.Asterisk.Play();
                                var message = string.Format(Resources.PackageExported, packageBuilder.Id, packageBuilder.Version);
                                MessageBox.Show(this, message, Text, MessageBoxButtons.OK, MessageBoxIcon.None);
                            }
                        }
                    }
                }
                else
                {
                    e.Cancel = true;
                }
            }

            base.OnFormClosing(e);
        }
Ejemplo n.º 2
0
 public void RegisterEventLogger(EventLogger logger)
 {
     ClearEventLogger();
     logger.Log += logger_Log;
     eventLogger = logger;
 }