public ActionResult SaveProductRoute(int productId, ProductRoute data)
        {
            ProductRoute route   = null;
            bool         success = false;
            string       msg     = string.Empty;

            Product product = Product.GetProduct(productId);

            route = product.Routes.AddRoute(data.RouteId);
            if (!product.IsValid)
            {
                msg = product.BrokenRulesCollection.ToString();
            }
            try
            {
                product = ImportWizard.PrepareProductSave(product);
                product = (Product)product.Save();
                success = true;
            }
            catch (Exception e)
            {
                msg = msg + ", " + e.Message;
            }

            return(this.Direct(new
            {
                success = success,
                data = route,
                msg = msg
            }));
        }
        public void PerformImportActionJsonFormatMoreThanOneThread()
        {
            var entityRepository = new Mock <IEntityRepository>();

            entityRepositoryService.Setup(x => x.InstantiateEntityRepository(true))
            .Returns(entityRepository.Object)
            .Verifiable();

            using (var systemUnderTest = new ImportWizard())
            {
                using (var tokenSource = new CancellationTokenSource())
                {
                    string importSchemaFilePath = "TestData\\ImportConfig.json";
                    int    maxThreads           = 2;
                    bool   jsonFormat           = true;

                    FluentActions.Invoking(() =>
                                           systemUnderTest.PerformImportAction(
                                               importSchemaFilePath,
                                               maxThreads,
                                               jsonFormat,
                                               logger.Object,
                                               entityRepositoryService.Object,
                                               importConfig,
                                               tokenSource))
                    .Should()
                    .NotThrow();
                }
            }

            entityRepositoryService.VerifyAll();
        }
        public void WizardNavigationwizardPage2AndSourceDataLocationTextBoxHasText()
        {
            using (var selectedPage = new AeroWizard.WizardPage())
            {
                selectedPage.Name = "wizardPage2";
                using (var pageContainer = new AeroWizard.WizardPageContainer())
                {
                    using (var folderPathValidationLabel = new System.Windows.Forms.Label())
                    {
                        using (var sourceDataLocationTextBox = new System.Windows.Forms.TextBox())
                        {
                            sourceDataLocationTextBox.Text = "Sample text";
                            using (var systemUnderTest = new ImportWizard())
                            {
                                using (var tokenSource = new CancellationTokenSource())
                                {
                                    FluentActions.Invoking(() => systemUnderTest.WizardNavigation(folderPathValidationLabel, sourceDataLocationTextBox, selectedPage, pageContainer))
                                    .Should()
                                    .Throw <NullReferenceException>()
                                    .WithMessage("Object reference not set to an instance of an object.");
                                }
                            }
                        }

                        folderPathValidationLabel.Visible.Should().BeFalse();
                    }
                }
            }
        }
Beispiel #4
0
        protected override void Execute()
        {
            try
            {
                _projectsController       = SdlTradosStudio.Application?.GetController <ProjectsController>();
                _projectControllerService = new ProjectsControllerService(_projectsController);

                var fileDialog = new OpenFileDialog {
                    Filter = @"Transit Project Package Files (*.ppf)|*.ppf;"
                };
                var dialogResult = fileDialog.ShowDialog();
                if (dialogResult != DialogResult.OK)
                {
                    return;
                }

                var pathToTempFolder = CreateTempPackageFolder();
                var wizardModel      = new WizardModel
                {
                    TransitFilePathLocation = fileDialog.FileName,
                    PathToTempFolder        = pathToTempFolder
                };
                var pages = CreatePages(wizardModel);

                using (var wizard = new ImportWizard(pages, _eventAggregatorService, _projectControllerService))
                {
                    wizard.ShowDialog();
                }
            }

            catch (Exception ex)
            {
                _logger.Error($"{ex.Message}\n {ex.StackTrace}");
            }
        }
        public void WizardNavigationwizardPage2AndSourceDataLocationTextBoxHasNoText()
        {
            using (var selectedPage = new AeroWizard.WizardPage())
            {
                selectedPage.Name = "wizardPage2";
                using (var pageContainer = new AeroWizard.WizardPageContainer())
                {
                    using (var folderPathValidationLabel = new System.Windows.Forms.Label())
                    {
                        using (var sourceDataLocationTextBox = new System.Windows.Forms.TextBox())
                        {
                            using (var systemUnderTest = new ImportWizard())
                            {
                                using (var tokenSource = new CancellationTokenSource())
                                {
                                    FluentActions.Invoking(() => systemUnderTest.WizardNavigation(folderPathValidationLabel, sourceDataLocationTextBox, selectedPage, pageContainer))
                                    .Should()
                                    .NotThrow();
                                }
                            }
                        }

                        folderPathValidationLabel.Visible.Should().BeTrue();
                    }
                }
            }
        }
Beispiel #6
0
        private void btnWizard_Click(object sender, EventArgs e)
        {
            ImportWizard wizard = new ImportWizard();

            if (wizard.ShowDialog(this) == DialogResult.OK)
            {
                tableSource.Import(wizard.GetTable(), wizard.GetColumns());
            }
        }
        public ActionResult SaveNewProduct(ImportInfo info)
        {
            ImportInfoList list = ImportInfoList.NewProductImportInfoList();

            list.Add(info);

            ImportWizard.ImportProductList(list);
            Product product = Product.GetProductByName(string.Empty);

            return(this.Direct(new {}));
        }
        public void HandleFileDialogOpenDialogResultOk()
        {
            using (var systemUnderTest = new ImportWizard())
            {
                var dialogResult = System.Windows.Forms.DialogResult.OK;

                FluentActions.Invoking(() =>
                                       systemUnderTest.HandleFileDialogOpen(dialogResult))
                .Should()
                .NotThrow();
            }
        }
        ///-------------------------------------------------------------------------------
        /// <summary>
        /// When the Source button is clicked, display the import wizard.
        /// </summary>
        ///-------------------------------------------------------------------------------
        private void btnSource_Click(object sender, System.EventArgs e)
        {
            using (ImportWizard importWizard = new ImportWizard(m_scr.Cache.ProjectId.Name,
                                                                m_scr, m_StyleSheet, m_helpTopicProvider, m_app))
            {
                using (NonUndoableUnitOfWorkHelper undoHelper = new NonUndoableUnitOfWorkHelper(ActionHandler))
                {
                    if (importWizard.ShowDialog() == DialogResult.Cancel)
                    {
                        // Ditch any in-memory changes made to the settings. Reload from the DB.
                        m_importSettings.RevertToSaved();
                    }
                    else
                    {
                        undoHelper.RollBack = false;
                    }
                }

                // If there are no files after showing the wizard, close the import dialog
                if (InitBookNameList() == 0)
                {
                    MessageBox.Show(this, DlgResources.ResourceString("kstidImportFilesUnavailable"),
                                    m_app.ApplicationName, MessageBoxButtons.OK, MessageBoxIcon.Information);
                    Close();
                    return;
                }

                // The default set of settings may have changed.
                m_importSettings = m_scr.DefaultImportSettings;

                // Update the file ranges for import because they may have changed.
                InitializeStartAndEndRefControls();

                // Update the passage controls to reflect the new range of files available
                // Only make changes that do not expand the available range of books since a
                // range may have been specified before the wizard was run that we do not
                // want to overwrite
                if (!scrPsgFrom.IsReferenceValid(scrPsgFrom.ScReference))
                {
                    SetStartRefToFirstImportableBook();
                }

                if (!scrPsgTo.IsReferenceValid(scrPsgTo.ScReference))
                {
                    SetEndRefToLastImportableBook();
                }
            }
            btnOK.Focus();
        }
Beispiel #10
0
        ///-------------------------------------------------------------------------------
        /// <summary>
        /// When the Source button is clicked, display the import wizard.
        /// </summary>
        ///-------------------------------------------------------------------------------
        private void btnSource_Click(object sender, System.EventArgs e)
        {
            ILangProject lp  = m_cache.LangProject;
            Scripture    scr = (Scripture)lp.TranslatedScriptureOA;

            using (ImportWizard importWizard = new ImportWizard(lp.Name.AnalysisDefaultWritingSystem,
                                                                scr, m_StyleSheet, m_cache, m_helpFile))
            {
                if (importWizard.ShowDialog() == DialogResult.Cancel)
                {
                    // Ditch any in-memory changes made to the settings. Reload from the DB.
                    m_importSettings.RevertToSaved();
                }

                // If there are no files after showing the wizard, close the import dialog
                if (InitBookNameList() == 0)
                {
                    MessageBox.Show(this, DlgResources.ResourceString("kstidImportFilesUnavailable"),
                                    Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Information);
                    Close();
                    return;
                }

                // Update the file ranges for import because they may have changed. The default
                // set of settings may also have changed, so we re-retrieve them from the DB.
                m_importSettings = (ScrImportSet)scr.DefaultImportSettings;
                scrPsgFrom.Initialize(new ScrReference(StartRef, scr.Versification), scr,
                                      m_importSettings.BooksForProject.ToArray());
                scrPsgTo.Initialize(new ScrReference(EndRef, scr.Versification), scr,
                                    m_importSettings.BooksForProject.ToArray());

                // Update the passage controls to reflect the new range of files available
                // Only make changes that do not expand the available range of books since a
                // range may have been specified before the wizard was run that we do not
                // want to overwrite
                if (!scrPsgFrom.IsReferenceValid(scrPsgFrom.ScReference))
                {
                    SetStartRefToFirstImportableBook();
                }

                if (!scrPsgTo.IsReferenceValid(scrPsgTo.ScReference))
                {
                    SetEndRefToLastImportableBook();
                }
            }
            btnOK.Focus();
        }
Beispiel #11
0
        public static void Main(string[] args)
        {
            Application.Init();
            var wizard = new ImportWizard();

            wizard.DeleteEvent += (o, e) => {
                Application.Quit();
                e.RetVal = true;
            };
            wizard.Cancel += (sender, e) =>
            {
                Application.Quit();
            };

            wizard.ShowAll();
            Application.Run();
        }
        public ActionResult SaveProductSubstance(ProductSubstance productSubstance)
        {
            bool             success   = false;
            string           msg       = string.Empty;
            ProductSubstance substance = null;

            if (Product.Exists(new Product.ExistCriteria(productSubstance.ProductId)))
            {
                Product product = Product.GetProduct(productSubstance.ProductId);
                if (product.HasSubstance(productSubstance.SubstanceName))
                {
                    substance = product.Substances.GetSubstanceByName(productSubstance.SubstanceName);
                }
                else
                {
                    substance = product.Substances.AddNew();
                }

                if (substance != null)
                {
                    Csla.Data.DataMapper.Map(productSubstance, substance, "ProductId");
                    if (product.IsSavable)
                    {
                        try
                        {
                            product   = ImportWizard.PrepareProductSave(product);
                            product   = (Product)product.Save();
                            substance = product.Substances.GetSubstanceByName(productSubstance.SubstanceName);
                            success   = true;
                        }
                        catch (Exception e)
                        {
                            msg = e.Message;
                        }
                    }
                }
            }

            return(this.Direct(new
            {
                success = success,
                data = substance,
                msg = msg
            }));
        }
Beispiel #13
0
		///-------------------------------------------------------------------------------
		/// <summary>
		/// When the Source button is clicked, display the import wizard.
		/// </summary>
		///-------------------------------------------------------------------------------
		private void btnSource_Click(object sender, System.EventArgs e)
		{
			ILangProject lp = m_cache.LangProject;
			Scripture scr = (Scripture)lp.TranslatedScriptureOA;
			using (ImportWizard importWizard = new ImportWizard(lp.Name.AnalysisDefaultWritingSystem,
				scr, m_StyleSheet, m_cache, m_helpFile))
			{
				if (importWizard.ShowDialog() == DialogResult.Cancel)
				{
					// Ditch any in-memory changes made to the settings. Reload from the DB.
					m_importSettings.RevertToSaved();
				}

				// If there are no files after showing the wizard, close the import dialog
				if (InitBookNameList() == 0)
				{
					MessageBox.Show(this, DlgResources.ResourceString("kstidImportFilesUnavailable"),
						Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Information);
					Close();
					return;
				}

				// Update the file ranges for import because they may have changed. The default
				// set of settings may also have changed, so we re-retrieve them from the DB.
				m_importSettings = (ScrImportSet)scr.DefaultImportSettings;
				scrPsgFrom.Initialize(new ScrReference(StartRef, scr.Versification), scr,
					m_importSettings.BooksForProject.ToArray());
				scrPsgTo.Initialize(new ScrReference(EndRef, scr.Versification), scr,
					m_importSettings.BooksForProject.ToArray());

				// Update the passage controls to reflect the new range of files available
				// Only make changes that do not expand the available range of books since a
				// range may have been specified before the wizard was run that we do not
				// want to overwrite
				if (!scrPsgFrom.IsReferenceValid(scrPsgFrom.ScReference))
					SetStartRefToFirstImportableBook();

				if (!scrPsgTo.IsReferenceValid(scrPsgTo.ScReference))
					SetEndRefToLastImportableBook();
			}
			btnOK.Focus();
		}
Beispiel #14
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Get the settings for Import, either from database or from wizard
        /// </summary>
        /// <returns>Import settings, or <c>null</c> if user canceled dialog.</returns>
        /// ------------------------------------------------------------------------------------
        protected ScrImportSet GetImportSettings()
        {
            ILangProject proj           = m_cache.LangProject;
            Scripture    scr            = (Scripture)proj.TranslatedScriptureOA;
            ScrImportSet importSettings = new ScrImportSet(m_cache, scr.DefaultImportSettingsHvo,
                                                           m_styleSheet, FwApp.App.HelpFile);

            importSettings.OverlappingFileResolver = new ConfirmOverlappingFileReplaceDialog();
            if (!importSettings.BasicSettingsExist)
            {
                // REVIEW DavidO: Should I use AnalysisDefaultWritingSystem or
                // VernacularDefaultWritingSystem or something else.
                using (ImportWizard importWizard = new ImportWizard(proj.Name.UserDefaultWritingSystem,
                                                                    scr, m_styleSheet, m_cache, FwApp.App.HelpFile))
                {
                    if (importWizard.ShowDialog() == DialogResult.Cancel)
                    {
                        return(null);
                    }
                    // Scripture reference range may have changed
                    ImportDialog.ClearDialogReferences(m_cache);
                    importSettings = (ScrImportSet)scr.DefaultImportSettings;
                }
            }
            else
            {
                StringCollection sInvalidFiles;
                bool             fCompletedWizard = false;
                while (!importSettings.ImportProjectIsAccessible(out sInvalidFiles))
                {
                    // Display the "Project Not Found" message box
                    using (ScrImportSetMessage dlg = new ScrImportSetMessage())
                    {
                        string[] files = new string[sInvalidFiles.Count];
                        sInvalidFiles.CopyTo(files, 0);
                        dlg.InvalidFiles       = files;
                        dlg.HelpURL            = FwApp.App.HelpFile;
                        dlg.HelpTopic          = "/Beginning_Tasks/Import_Standard_Format/Project_Files_Unavailable.htm";
                        dlg.DisplaySetupOption = true;
                        switch (dlg.ShowDialog())
                        {
                        case DialogResult.OK:                                 // Setup...
                        {
                            using (ImportWizard importWizard = new ImportWizard(
                                       proj.Name.UserDefaultWritingSystem, scr, m_styleSheet, m_cache,
                                       FwApp.App.HelpFile))
                            {
                                if (importWizard.ShowDialog() == DialogResult.Cancel)
                                {
                                    return(null);
                                }
                                // Scripture reference range may have changed
                                ImportDialog.ClearDialogReferences(m_cache);
                                importSettings   = (ScrImportSet)scr.DefaultImportSettings;
                                fCompletedWizard = true;
                            }
                            break;
                        }

                        case DialogResult.Cancel:
                            return(null);

                        case DialogResult.Retry:
                            // Loop around until user gets tired.
                            break;
                        }
                    }
                }
                if (!fCompletedWizard)
                {
                    if (ParatextProjHasUnmappedMarkers(importSettings))
                    {
                        // TODO: Show message box and then bring up import wizard
                    }
                }
            }

            return(importSettings);
        }
Beispiel #15
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Get the settings for Import, either from database or from wizard
        /// </summary>
        /// <returns>Import settings, or <c>null</c> if user canceled dialog.</returns>
        /// ------------------------------------------------------------------------------------
        protected IScrImportSet GetImportSettings()
        {
            ILangProject  proj           = m_cache.LangProject;
            IScripture    scr            = proj.TranslatedScriptureOA;
            IScrImportSet importSettings = null;

            NonUndoableUnitOfWorkHelper.Do(m_cache.ActionHandlerAccessor, () =>
            {
                importSettings =
                    scr.FindOrCreateDefaultImportSettings(TypeOfImport.Unknown);
            });
            importSettings.StyleSheet = m_styleSheet;

            importSettings.OverlappingFileResolver = new ConfirmOverlappingFileReplaceDialog(m_helpTopicProvider);
            if (!importSettings.BasicSettingsExist)
            {
                using (NonUndoableUnitOfWorkHelper undoHelper = new NonUndoableUnitOfWorkHelper(
                           m_cache.ServiceLocator.GetInstance <IActionHandler>()))
                {
                    using (ImportWizard importWizard = new ImportWizard(m_cache.ProjectId.Name,
                                                                        scr, m_styleSheet, m_helpTopicProvider, m_app))
                    {
                        if (importWizard.ShowDialog() == DialogResult.Cancel)
                        {
                            return(null);
                        }
                        // Scripture reference range may have changed
                        ImportDialog.ClearDialogReferences();
                        importSettings = scr.DefaultImportSettings;
                    }
                    undoHelper.RollBack = false;
                }
            }
            else
            {
                StringCollection sInvalidFiles;
                bool             fCompletedWizard = false;
                while (!importSettings.ImportProjectIsAccessible(out sInvalidFiles))
                {
                    // Display the "Project Not Found" message box
                    using (ScrImportSetMessage dlg = new ScrImportSetMessage())
                    {
                        string[] files = new string[sInvalidFiles.Count];
                        sInvalidFiles.CopyTo(files, 0);
                        dlg.InvalidFiles       = files;
                        dlg.HelpURL            = m_helpTopicProvider.HelpFile;
                        dlg.HelpTopic          = "/Beginning_Tasks/Import_Standard_Format/Project_Files_Unavailable.htm";
                        dlg.DisplaySetupOption = true;
                        switch (dlg.ShowDialog())
                        {
                        case DialogResult.OK:                                 // Setup...
                        {
                            using (NonUndoableUnitOfWorkHelper undoHelper = new NonUndoableUnitOfWorkHelper(
                                       m_cache.ServiceLocator.GetInstance <IActionHandler>()))
                            {
                                using (ImportWizard importWizard = new ImportWizard(
                                           m_cache.ProjectId.Name, scr, m_styleSheet, m_helpTopicProvider, m_app))
                                {
                                    if (importWizard.ShowDialog() == DialogResult.Cancel)
                                    {
                                        return(null);
                                    }
                                    // Scripture reference range may have changed
                                    ImportDialog.ClearDialogReferences();
                                    importSettings   = scr.DefaultImportSettings;
                                    fCompletedWizard = true;
                                }
                                undoHelper.RollBack = false;
                            }
                            break;
                        }

                        case DialogResult.Cancel:
                            return(null);

                        case DialogResult.Retry:
                            // Loop around until user gets tired.
                            break;
                        }
                    }
                }
                if (!fCompletedWizard)
                {
                    if (ParatextProjHasUnmappedMarkers(importSettings))
                    {
                        // TODO: Show message box and then bring up import wizard
                    }
                }
            }

            return(importSettings);
        }
 /// <summary>
 /// 開始一個新的匯入作業
 /// </summary>
 /// <param name="wizard">處理這次匯入的精靈</param>
 public abstract void InitializeImport(ImportWizard wizard);
Beispiel #17
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Get the settings for Import, either from database or from wizard
		/// </summary>
		/// <returns>Import settings, or <c>null</c> if user canceled dialog.</returns>
		/// ------------------------------------------------------------------------------------
		protected ScrImportSet GetImportSettings()
		{
			ILangProject proj = m_cache.LangProject;
			Scripture scr = (Scripture)proj.TranslatedScriptureOA;
			ScrImportSet importSettings = new ScrImportSet(m_cache, scr.DefaultImportSettingsHvo,
				m_styleSheet, FwApp.App.HelpFile);

			importSettings.OverlappingFileResolver = new ConfirmOverlappingFileReplaceDialog();
			if (!importSettings.BasicSettingsExist)
			{
				// REVIEW DavidO: Should I use AnalysisDefaultWritingSystem or
				// VernacularDefaultWritingSystem or something else.
				using (ImportWizard importWizard = new ImportWizard(proj.Name.UserDefaultWritingSystem,
					scr, m_styleSheet, m_cache, FwApp.App.HelpFile))
				{
					if (importWizard.ShowDialog() == DialogResult.Cancel)
						return null;
					// Scripture reference range may have changed
					ImportDialog.ClearDialogReferences(m_cache);
					importSettings = (ScrImportSet)scr.DefaultImportSettings;
				}
			}
			else
			{
				StringCollection sInvalidFiles;
				bool fCompletedWizard = false;
				while (!importSettings.ImportProjectIsAccessible(out sInvalidFiles))
				{
					// Display the "Project Not Found" message box
					using (ScrImportSetMessage dlg = new ScrImportSetMessage())
					{
						string[] files = new string[sInvalidFiles.Count];
						sInvalidFiles.CopyTo(files, 0);
						dlg.InvalidFiles = files;
						dlg.HelpURL = FwApp.App.HelpFile;
						dlg.HelpTopic = "/Beginning_Tasks/Import_Standard_Format/Project_Files_Unavailable.htm";
						dlg.DisplaySetupOption = true;
						switch(dlg.ShowDialog())
						{
							case DialogResult.OK: // Setup...
							{
								using (ImportWizard importWizard = new ImportWizard(
									proj.Name.UserDefaultWritingSystem, scr, m_styleSheet, m_cache,
									FwApp.App.HelpFile))
								{
									if (importWizard.ShowDialog()== DialogResult.Cancel)
										return null;
									// Scripture reference range may have changed
									ImportDialog.ClearDialogReferences(m_cache);
									importSettings = (ScrImportSet)scr.DefaultImportSettings;
									fCompletedWizard = true;
								}
								break;
							}
							case DialogResult.Cancel:
								return null;
							case DialogResult.Retry:
								// Loop around until user gets tired.
								break;
						}
					}
				}
				if (!fCompletedWizard)
				{
					if (ParatextProjHasUnmappedMarkers(importSettings))
					{
						// TODO: Show message box and then bring up import wizard
					}
				}
			}

			return importSettings;
		}