Exemplo n.º 1
0
        public void OpenExistingFileExistTest()
        {
            Mock <IFileDialog> _IFileDialogMock = new Mock <IFileDialog>();

            _IFileDialogMock.Setup(x => x.ShowDialog()).Returns(false);
            Mock <IGraphicalUserInterface> _guiMock = new Mock <IGraphicalUserInterface>();

            _guiMock.SetupSet(x => x.UseWaitCursor = It.IsAny <bool>());
            _guiMock.SetupGet(x => x.OpenFileDialogFunc).Returns(() => _IFileDialogMock.Object);
            _guiMock.SetupGet(x => x.MessageBoxShowWarningAskYN).Returns(() => (x, y) => true);
            ISolutionConfigurationManagement    _instance      = null;
            SolutionConfigurationManagementRoot _freshInstance = null;

            SolutionConfigurationManagementRoot.GetInstance(c => _freshInstance = c);
            _freshInstance.AfterSolutionChange += (x, y) => _instance = y.Solution;
            SolutionConfigurationManagementRoot.OpenExisting(@"TestData\EmptySolution.uamdsl", _guiMock.Object);
            Assert.IsNotNull(_instance);
            Assert.IsFalse(_instance.ChangesArePresent);
            Assert.AreEqual <string>(Path.Combine(Directory.GetCurrentDirectory(), @"TestData\EmptySolution.uamdsl"), _instance.DefaultFileName);
            _IFileDialogMock.Verify(x => x.DefaultExt, Times.Never);
            _IFileDialogMock.Verify(x => x.Filter, Times.Never);
            _IFileDialogMock.Verify(x => x.Title, Times.Never);
            _IFileDialogMock.Verify(x => x.FileName, Times.Never);
            _IFileDialogMock.VerifySet(x => x.InitialDirectory = It.IsAny <string>(), Times.Never);
            _IFileDialogMock.Verify(x => x.ShowDialog(), Times.Never);
            _IFileDialogMock.Verify(x => x.Dispose(), Times.Never);
            _guiMock.Verify(x => x.MessageBoxShowWarningAskYN, Times.Never);
            _guiMock.VerifySet(x => x.UseWaitCursor = It.IsAny <bool>(), Times.Exactly(2));
        }
Exemplo n.º 2
0
        public void OpenExistingSkippedTest()
        {
            const string       DefaultExt       = "uamdsl";
            const string       Filter           = "UA Model Designer Solution File (* .uamdsl)|*.uamdsl|UA Model Designer Solution File (* .xml)|*.xml|All files(*.*)|*.*";
            const string       Title            = "UA Model Designer Solution Open/Save dialog window";
            Mock <IFileDialog> _IFileDialogMock = new Mock <IFileDialog>();

            _IFileDialogMock.SetupProperty(x => x.DefaultExt);
            _IFileDialogMock.SetupProperty(x => x.Filter);
            _IFileDialogMock.SetupProperty(x => x.Title);
            _IFileDialogMock.Setup(x => x.ShowDialog()).Returns(false);
            Mock <IGraphicalUserInterface> _guiMock = new Mock <IGraphicalUserInterface>();

            _guiMock.SetupGet(x => x.OpenFileDialogFunc).Returns(() => _IFileDialogMock.Object);
            _guiMock.SetupGet(x => x.MessageBoxShowWarningAskYN).Returns(() => (x, y) => true);
            ISolutionConfigurationManagement    _instance      = null;
            SolutionConfigurationManagementRoot _freshInstance = null;

            SolutionConfigurationManagementRoot.GetInstance(c => _freshInstance = c);
            _freshInstance.AfterSolutionChange += (x, y) => _instance = y.Solution;
            SolutionConfigurationManagementRoot.OpenExisting(null, _guiMock.Object);
            _IFileDialogMock.VerifySet(x => x.DefaultExt       = DefaultExt, Times.Never);
            _IFileDialogMock.VerifySet(x => x.Filter           = Filter, Times.Never);
            _IFileDialogMock.VerifySet(x => x.Title            = Title, Times.Never);
            _IFileDialogMock.VerifySet(x => x.FileName         = It.IsAny <string>(), Times.Never);
            _IFileDialogMock.VerifySet(x => x.InitialDirectory = It.IsAny <string>(), Times.Never);
            _IFileDialogMock.Verify(x => x.ShowDialog(), Times.Never);
            _IFileDialogMock.Verify(x => x.Dispose(), Times.Never);
        }
 private ProjectConfigurationManagement(bool newModel, UAModelDesignerProject uaModelDesignerProject, ISolutionConfigurationManagement solution, Tuple <OpcUaModelCompiler.ModelDesign, string> modelDesign, IGraphicalUserInterface gui) :
     base(modelDesign.Item2, newModel, gui)
 {
     m_UAModelDesignerProject           = uaModelDesignerProject;
     m_ISolutionConfigurationManagement = solution;
     this.m_ModelDesign = modelDesign.Item1;
     m_NewModel         = newModel;
 }
Exemplo n.º 4
0
 /// <summary>
 /// Initializes a new instance of the <see cref="SolutionTreeNode" /> class.
 /// </summary>
 /// <param name="messageBoxHandling">The Message Box instance to provide messages on the screen.</param>
 /// <param name="solution">The configuration.</param>
 /// <param name="OnChangeHandler">The on change handler.</param>
 /// <param name="creteLibraryTreeNode">The call back to create <see cref="LibraryTreeNode"/>.</param>
 /// <exception cref="ArgumentNullException">configuration
 /// or
 /// messageBoxHandling</exception>
 internal SolutionTreeNode(IMessageBoxHandling messageBoxHandling, ISolutionConfigurationManagement solution, EventHandler <EventArgs> OnChangeHandler, Action <LibraryTreeNode> creteLibraryTreeNode) :
     base(null, solution == null ? Guid.NewGuid().ToString() : solution.Name)
 {
     MessageBoxHandling = messageBoxHandling ?? throw new ArgumentNullException(nameof(messageBoxHandling));
     m_ISolutionConfigurationManagement = solution ?? throw new ArgumentNullException(nameof(solution), $"In constructor {nameof(SolutionTreeNode)} this argument must not be null.");
     Server.OnConfigurationChanged     += new EventHandler <UAServerConfigurationEventArgs>(Server_OnConfigurationChanged);
     //TODO OnDataChanged += OnChangeHandler;
     //TODO OnNameChanged += new EventHandler(configuration_OnNameChanged);
     AddProjectsNodes(solution.Projects);
     AssemblyTraceEvent.Tracer.TraceEvent(TraceEventType.Verbose, 325542572, "Creating Libraries");
     SolutionRoot = this;
     LibraryRoot.AddNodes(creteLibraryTreeNode);
 }
        /// <summary>
        /// Creates new model encapsulated by an instance of this class
        /// </summary>
        /// <param name="solution">The solution description.</param>
        /// <param name="gui">The graphical user interface.</param>
        /// <param name="projectName">Name of the project.</param>
        /// <returns><see cref="IProjectConfigurationManagement"/>.</returns>
        internal static IProjectConfigurationManagement CreateNew(ISolutionConfigurationManagement solution, IGraphicalUserInterface gui, string projectName)
        {
            if (solution == null)
            {
                throw new ArgumentNullException(nameof(solution));
            }
            if (gui == null)
            {
                throw new ArgumentNullException(nameof(gui));
            }
            UAModelDesignerProject _projectDescription = UAModelDesignerProject.CreateEmpty(projectName);
            //TODO Creating new project the existing one should not be overridden #174
            string _defFilePath = Path.ChangeExtension(RelativeFilePathsCalculator.CalculateAbsoluteFileName(solution.DefaultDirectory, projectName), Resources.Project_FileDialogDefaultExt);

            return(new ProjectConfigurationManagement(true, _projectDescription, solution, new Tuple <OpcUaModelCompiler.ModelDesign, string>(OpcUaModelCompilerModelDesigner.GetDefault(), _defFilePath), gui));
        }
        internal static IProjectConfigurationManagement ImportModelDesign(ISolutionConfigurationManagement solution, IGraphicalUserInterface gui, UAModelDesignerProject uaModelDesignerProject)
        {
            if (solution == null)
            {
                throw new ArgumentNullException(nameof(solution));
            }
            if (gui == null)
            {
                throw new ArgumentNullException(nameof(gui));
            }
            if (uaModelDesignerProject == null)
            {
                throw new ArgumentNullException(nameof(uaModelDesignerProject));
            }
            string _filePath = Path.Combine(solution.DefaultDirectory, uaModelDesignerProject.FileName);
            Tuple <OpcUaModelCompiler.ModelDesign, string> _modelDesign = new Tuple <OpcUaModelCompiler.ModelDesign, string>(TypeGenericConfigurationManagement <OpcUaModelCompiler.ModelDesign> .ReadConfiguration(Path.Combine(solution.DefaultDirectory, uaModelDesignerProject.FileName), gui), _filePath);

            return(new ProjectConfigurationManagement(false, uaModelDesignerProject, solution, _modelDesign, gui));
        }
        internal static IProjectConfigurationManagement ImportNodeSet(ISolutionConfigurationManagement solution, IGraphicalUserInterface graphicalUserInterface, Action <TraceMessage> traceEvent)
        {
            if (solution == null)
            {
                throw new ArgumentNullException(nameof(solution));
            }
            if (graphicalUserInterface == null)
            {
                throw new ArgumentNullException(nameof(graphicalUserInterface));
            }
            Tuple <OpcUaModelCompiler.ModelDesign, string> _modelDesign = IO.ImportNodeSet.Import(solution.DefaultDirectory, traceEvent);

            if (_modelDesign == null)
            {
                return(null);
            }
            UAModelDesignerProject _newProjctDesription = UAModelDesignerProject.CreateEmpty(_modelDesign.Item2);

            return(new ProjectConfigurationManagement(true, _newProjctDesription, solution, _modelDesign, graphicalUserInterface));
        }
        internal static IProjectConfigurationManagement ImportModelDesign(ISolutionConfigurationManagement solution, IGraphicalUserInterface gui)
        {
            if (solution == null)
            {
                throw new ArgumentNullException(nameof(solution));
            }
            if (gui == null)
            {
                throw new ArgumentNullException(nameof(gui));
            }
            Tuple <OpcUaModelCompiler.ModelDesign, string> _modelDesign = TypeGenericConfigurationManagement <OpcUaModelCompiler.ModelDesign> .ReadConfiguration(gui, SetupFileDialog);

            if (_modelDesign.Item1 == null)
            {
                return(null);
            }
            UAModelDesignerProject uaModelDesignerProject = UAModelDesignerProject.CreateEmpty(Path.GetFileNameWithoutExtension(_modelDesign.Item2));

            uaModelDesignerProject.FileName = CAS.CommServer.UA.ModelDesigner.Configuration.IO.RelativeFilePathsCalculator.TryComputeRelativePath(solution.DefaultDirectory, _modelDesign.Item2);
            return(new ProjectConfigurationManagement(false, uaModelDesignerProject, solution, _modelDesign, gui));
        }
Exemplo n.º 9
0
        public void NewSoliutionTest()
        {
            Mock <IGraphicalUserInterface> _gui = new Mock <IGraphicalUserInterface>();

            _gui.SetupGet(x => x.MessageBoxShowWarningAskYN).Returns(() => (x, y) => true);
            int _eventCounter = 0;
            ISolutionConfigurationManagement _newSolution = null;

            SolutionConfigurationManagementRoot.DefaultInstance.AfterSolutionChange += (x, y) => { _eventCounter++; _newSolution = y.Solution; Assert.AreSame(x, SolutionConfigurationManagementRoot.DefaultInstance); };
            SolutionConfigurationManagementRoot _freshInstance = null;

            SolutionConfigurationManagementRoot.GetInstance(c => _freshInstance = c);
            ISolutionConfigurationManagement _instance = null;

            _freshInstance.AfterSolutionChange += (x, y) => _instance = y.Solution;
            SolutionConfigurationManagementRoot.NewSoliution(_gui.Object);
            Assert.IsNotNull(_instance);
            Assert.IsTrue(_instance.ChangesArePresent);
            Assert.IsFalse(string.IsNullOrEmpty(_instance.DefaultDirectory));
            Assert.AreEqual <string>(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), _instance.DefaultDirectory);
            Assert.AreEqual <string>("UAModelDesignerSolution", Path.GetFileName(_instance.DefaultFileName));
        }
Exemplo n.º 10
0
 internal void Initialize(ISolutionConfigurationManagement solution)
 {
     m_Solution = solution;
 }
 public AfterSolutionChangeEventArgs(ISolutionConfigurationManagement solution)
 {
     Solution = solution;
 }
 private void OnSolutionChanged(ISolutionConfigurationManagement solution)
 {
     CurrentConfiguration = solution;
     OnSolutionChanged();
 }