Example #1
0
        public void Build(String filePath)
        {
            m_viewModel.GeneratePackageContent(); //it sets the root package source info
            m_viewModel.CurrentState = PackageBuilderWizardPage.FileViewer;

            PackageSourceInfo info = m_viewModel.PackageSourceInfo;
            bool noError           = true;

            TraceLab.Core.PackageSystem.Package pkg = null;

            // string pkgFilePath = GetFilePath(info.Name);
            string pkgFilePath = filePath;
            // HERZUM SPRINT 3: TLAB-206
            string pkgFileName = System.IO.Path.GetFileNameWithoutExtension(pkgFilePath);

            // END HERZUM SPRINT 3: TLAB-206
            if (pkgFilePath != null)
            {
                // string pkgFileName = System.IO.Path.GetFileNameWithoutExtension(pkgFilePath);
                string pkgTempDirectory = pkgFilePath + "~temp";

                try
                {
                    System.IO.Directory.CreateDirectory(pkgTempDirectory);

                    try
                    {
                        // HERZUM SPRINT 3: TLAB-206
                        // pkg = new TraceLab.Core.PackageSystem.Package(info.Name, pkgTempDirectory, false);
                        pkg = new TraceLab.Core.PackageSystem.Package(pkgFileName, pkgTempDirectory, false);
                        // END HERZUM SPRINT 3: TLAB-206
                    }
                    catch (TraceLab.Core.PackageSystem.PackageAlreadyExistsException)
                    {
                        ShowMessageDialog("Package already exists in: " + pkgTempDirectory,
                                          "Package Creation Error", Gtk.ButtonsType.Ok, Gtk.MessageType.Error);
                        noError = false;
                    }
                    catch (TraceLab.Core.PackageSystem.PackageException ex)
                    {
                        ShowMessageDialog("Error creating package: " + ex.Message,
                                          "Package Creation Error", Gtk.ButtonsType.Ok, Gtk.MessageType.Error);
                        noError = false;
                    }

                    if (pkg != null && noError)
                    {
                        foreach (PackageFileSourceInfo item in info.Files)
                        {
                            try
                            {
                                noError = noError && PackageCreator.AddItemToPackage(pkg, item, m_viewModel.IsExperimentPackage);
                            }
                            catch (TraceLab.Core.Exceptions.PackageCreationFailureException ex)
                            {
                                ShowMessageDialog("Error creating package: " + ex.Message,
                                                  "Package Creation Error", Gtk.ButtonsType.Ok, Gtk.MessageType.Error);
                                noError = false;
                            }
                        }

                        pkg.SaveManifest();

                        using (System.IO.FileStream stream = new System.IO.FileStream(pkgFilePath, System.IO.FileMode.Create))
                        {
                            pkg.Pack(stream);
                        }
                    }
                }
                catch (System.IO.IOException error)
                {
                    ShowMessageDialog("Unable to create package. Error: " + error.Message,
                                      "Package Creation Error", Gtk.ButtonsType.Ok, Gtk.MessageType.Error);
                    noError = false;
                }
                catch (System.UnauthorizedAccessException error)
                {
                    ShowMessageDialog("Unable to create package - Unauthorized access: " + error.Message,
                                      "Package Creation Error", Gtk.ButtonsType.Ok, Gtk.MessageType.Error);
                    noError = false;
                }

                try
                {
                    if (System.IO.Directory.Exists(pkgTempDirectory))
                    {
                        System.IO.Directory.Delete(pkgTempDirectory, true);
                    }
                }
                catch (System.IO.IOException error)
                {
                    ShowMessageDialog("Unable to cleanup after package creation. Error: " + error.Message,
                                      "After Package Cleanup Failure", Gtk.ButtonsType.Ok, Gtk.MessageType.Warning);
                }
                catch (System.UnauthorizedAccessException error)
                {
                    ShowMessageDialog("Unable to cleanup after package creation. Unauthorized access: " + error.Message,
                                      "After Package Cleanup Failure", Gtk.ButtonsType.Ok, Gtk.MessageType.Warning);
                }
            }

            if (noError && pkg != null)
            {
                // HERZUM SPRINT 3: TLAB-206
                // ShowMessageDialog("Package \"" + info.Name + "\" was built successfully.", "Package Created",
                ShowMessageDialog("Package \"" + pkgFileName + "\" was built successfully.", "Package Created",
                                  // END HERZUM SPRINT 3: TLAB-206
                                  Gtk.ButtonsType.Ok, Gtk.MessageType.Info);
            }
        }
        /// <summary>
        /// Handles the Click event of the Build Package Button
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.Windows.RoutedEventArgs"/> instance containing the event data.</param>
        private void BuildPkgButton_Click(object sender, RoutedEventArgs e)
        {
            MainBorder.Visibility = System.Windows.Visibility.Visible;

            var viewModel          = (PackageBuilderViewModel)DataContext;
            PackageSourceInfo info = viewModel.PackageSourceInfo;
            bool noError           = true;

            TraceLab.Core.PackageSystem.Package pkg = null;

            string pkgFilePath = GetFilePath(info.Name);

            if (pkgFilePath != null)
            {
                string pkgFileName      = System.IO.Path.GetFileNameWithoutExtension(pkgFilePath);
                string pkgTempDirectory = pkgFilePath + "~temp";

                try
                {
                    System.IO.Directory.CreateDirectory(pkgTempDirectory);

                    try
                    {
                        pkg = new TraceLab.Core.PackageSystem.Package(info.Name, pkgTempDirectory, false);
                    }
                    catch (TraceLab.Core.PackageSystem.PackageAlreadyExistsException)
                    {
                        MessageBox.Show("Package already exists in: " + pkgTempDirectory,
                                        "Package Creation Error", MessageBoxButton.OK, MessageBoxImage.Error);
                        noError = false;
                    }
                    catch (TraceLab.Core.PackageSystem.PackageException ex)
                    {
                        MessageBox.Show("Error creating package: " + ex.Message,
                                        "Package Creation Error", MessageBoxButton.OK, MessageBoxImage.Error);
                        noError = false;
                    }

                    if (pkg != null && noError)
                    {
                        foreach (PackageFileSourceInfo item in info.Files)
                        {
                            try
                            {
                                noError = noError && PackageCreator.AddItemToPackage(pkg, item, viewModel.IsExperimentPackage);
                            }
                            catch (TraceLab.Core.Exceptions.PackageCreationFailureException ex)
                            {
                                MessageBox.Show("Error creating package: " + ex.Message,
                                                "Package Creation Error", MessageBoxButton.OK, MessageBoxImage.Error);
                                noError = false;
                            }
                        }

                        pkg.SaveManifest();

                        using (System.IO.FileStream stream = new System.IO.FileStream(pkgFilePath, System.IO.FileMode.Create))
                        {
                            pkg.Pack(stream);
                        }
                    }
                }
                catch (System.IO.IOException error)
                {
                    MessageBox.Show("Unable to create package. Error: " + error.Message,
                                    "Package Creation Error", MessageBoxButton.OK, MessageBoxImage.Error);
                    noError = false;
                }
                catch (System.UnauthorizedAccessException error)
                {
                    MessageBox.Show("Unable to create package - Unauthorized access: " + error.Message,
                                    "Package Creation Error", MessageBoxButton.OK, MessageBoxImage.Error);
                    noError = false;
                }

                try
                {
                    if (System.IO.Directory.Exists(pkgTempDirectory))
                    {
                        System.IO.Directory.Delete(pkgTempDirectory, true);
                    }
                }
                catch (System.IO.IOException error)
                {
                    MessageBox.Show("Unable to cleanup after package creation. Error: " + error.Message,
                                    "After Package Cleanup Failure", MessageBoxButton.OK, MessageBoxImage.Exclamation);
                }
                catch (System.UnauthorizedAccessException error)
                {
                    MessageBox.Show("Unable to cleanup after package creation. Unauthorized access: " + error.Message,
                                    "After Package Cleanup Failure", MessageBoxButton.OK, MessageBoxImage.Warning);
                }
            }

            if (noError && pkg != null)
            {
                MessageBox.Show("Package \"" + info.Name + "\" was built successfully.", "Package Created",
                                MessageBoxButton.OK, MessageBoxImage.Information);
            }

            MainBorder.Visibility = System.Windows.Visibility.Hidden;
        }
Example #3
0
        protected void buildButtonClicked(object sender, EventArgs e)
        {
            PackageSourceInfo info = m_viewModel.PackageSourceInfo;
            bool noError           = true;

            TraceLab.Core.PackageSystem.Package pkg = null;

            string pkgFilePath = GetFilePath(info.Name);

            if (pkgFilePath != null)
            {
                string pkgFileName      = System.IO.Path.GetFileNameWithoutExtension(pkgFilePath);
                string pkgTempDirectory = pkgFilePath + "~temp";

                try
                {
                    System.IO.Directory.CreateDirectory(pkgTempDirectory);

                    // HERZUM SPRINT 4.2: TLAB-215
                    if (info.Name.Contains(" "))
                    {
                        ShowMessageDialog("Package name:" + info.Name + ", can not contain space characters: ",
                                          "Package Creation Error", Gtk.ButtonsType.Ok, Gtk.MessageType.Error);
                        noError = false;
                    }
                    // END HERZUM SPRINT 4.2: TLAB-215

                    try
                    {
                        pkg = new TraceLab.Core.PackageSystem.Package(info.Name, pkgTempDirectory, false);
                    }
                    catch (TraceLab.Core.PackageSystem.PackageAlreadyExistsException)
                    {
                        ShowMessageDialog("Package already exists in: " + pkgTempDirectory,
                                          "Package Creation Error", Gtk.ButtonsType.Ok, Gtk.MessageType.Error);
                        noError = false;
                    }
                    catch (TraceLab.Core.PackageSystem.PackageException ex)
                    {
                        ShowMessageDialog("Error creating package: " + ex.Message,
                                          "Package Creation Error", Gtk.ButtonsType.Ok, Gtk.MessageType.Error);
                        noError = false;
                    }

                    if (pkg != null && noError)
                    {
                        foreach (PackageFileSourceInfo item in info.Files)
                        {
                            try
                            {
                                noError = noError && PackageCreator.AddItemToPackage(pkg, item, m_viewModel.IsExperimentPackage);
                            }
                            catch (TraceLab.Core.Exceptions.PackageCreationFailureException ex)
                            {
                                ShowMessageDialog("Error creating package: " + ex.Message,
                                                  "Package Creation Error", Gtk.ButtonsType.Ok, Gtk.MessageType.Error);
                                noError = false;
                            }
                        }

                        pkg.SaveManifest();

                        using (System.IO.FileStream stream = new System.IO.FileStream(pkgFilePath, System.IO.FileMode.Create))
                        {
                            pkg.Pack(stream);
                        }
                    }
                }
                catch (System.IO.IOException error)
                {
                    ShowMessageDialog("Unable to create package. Error: " + error.Message,
                                      "Package Creation Error", Gtk.ButtonsType.Ok, Gtk.MessageType.Error);
                    noError = false;
                }
                catch (System.UnauthorizedAccessException error)
                {
                    ShowMessageDialog("Unable to create package - Unauthorized access: " + error.Message,
                                      "Package Creation Error", Gtk.ButtonsType.Ok, Gtk.MessageType.Error);
                    noError = false;
                }

                try
                {
                    if (System.IO.Directory.Exists(pkgTempDirectory))
                    {
                        System.IO.Directory.Delete(pkgTempDirectory, true);
                    }
                }
                catch (System.IO.IOException error)
                {
                    ShowMessageDialog("Unable to cleanup after package creation. Error: " + error.Message,
                                      "After Package Cleanup Failure", Gtk.ButtonsType.Ok, Gtk.MessageType.Warning);
                }
                catch (System.UnauthorizedAccessException error)
                {
                    ShowMessageDialog("Unable to cleanup after package creation. Unauthorized access: " + error.Message,
                                      "After Package Cleanup Failure", Gtk.ButtonsType.Ok, Gtk.MessageType.Warning);
                }
            }

            if (noError && pkg != null)
            {
                ShowMessageDialog("Package \"" + info.Name + "\" was built successfully.", "Package Created",
                                  Gtk.ButtonsType.Ok, Gtk.MessageType.Info);
            }
        }