void ISolutionConfigurationManagement.Save(bool prompt)
        {
            m_Server.Save(this);
            this.SelectSavePath(prompt, SetupFileDialog);
            List <UAModelDesignerProject> _projects = new List <UAModelDesignerProject>();

            foreach (IProjectConfigurationManagement _item in m_Projects)
            {
                UAModelDesignerProject _projectDescriptor = _item.UAModelDesignerProject;
                string _effectiveAbsolutePath             = _item.DefaultFileName;
                _projectDescriptor.FileName = RelativeFilePathsCalculator.TryComputeRelativePath(this.DefaultDirectory, _effectiveAbsolutePath);
            }
            string _codebaseRelativePathName      = string.Empty;
            string _configurationRelativePathName = string.Empty;

            ServerSelector.ServerDescriptor _plugin = m_Server.ServerConfiguration;
            if (_plugin != null)
            {
                _codebaseRelativePathName      = RelativeFilePathsCalculator.TryComputeRelativePath(this.DefaultDirectory, _plugin.Codebase);
                _configurationRelativePathName = RelativeFilePathsCalculator.TryComputeRelativePath(this.DefaultDirectory, _plugin.Configuration);
            }
            UAModelDesignerSolution _solutionDesription = new UAModelDesignerSolution()
            {
                Name          = this.m_Name,
                Projects      = m_Projects.Select <IProjectConfigurationManagement, UAModelDesignerProject>(x => x.UAModelDesignerProject).ToArray <UAModelDesignerProject>(),
                ServerDetails = new UAModelDesignerSolutionServerDetails {
                    codebase = _codebaseRelativePathName, configuration = _configurationRelativePathName
                }
            };

            this.Save(_solutionDesription);
        }
Пример #2
0
        static AppConfigManagement()
        {
            PLCNaN = ApplicationConfiguration.GetAppSetting("PLCNaN", PLCNaN);
            MinAvgMax_Tag_management             = ApplicationConfiguration.GetAppSetting("MinAvgMax_Tag_management", MinAvgMax_Tag_management);
            MinAvgMax_Group_management           = ApplicationConfiguration.GetAppSetting("MinAvgMax_Group_management", MinAvgMax_Group_management);
            MinAvgMax_Transaction_management     = ApplicationConfiguration.GetAppSetting("MinAvgMax_Transaction_management", MinAvgMax_Transaction_management);
            MinAvgMax_Group_Read_management      = ApplicationConfiguration.GetAppSetting("MinAvgMax_Group_Read_management", MinAvgMax_Group_Read_management);
            MinAvgMax_FrameResponse_management   = ApplicationConfiguration.GetAppSetting("MinAvgMax_FrameResponse_management", MinAvgMax_FrameResponse_management);
            MinAvgMax_CharacterGap_management    = ApplicationConfiguration.GetAppSetting("MinAvgMax_CharacterGap_management", MinAvgMax_CharacterGap_management);
            WaitForReconnectServerInSec          = ApplicationConfiguration.GetAppSetting("WaitForReconnectServerInSec", WaitForReconnectServerInSec);
            WaitForFirstGroupUpdateSendInMiliSec = ApplicationConfiguration.GetAppSetting("WaitForFirstGroupUpdateSendInMiliSec", WaitForFirstGroupUpdateSendInMiliSec);
            UseTimeStampToCheckForUpdate         = ApplicationConfiguration.GetAppSetting("UseTimeStampToCheckForUpdate", UseTimeStampToCheckForUpdate);
            UseLocalTime = ApplicationConfiguration.GetAppSetting("UseLocalTime", UseLocalTime);
            filename     = ApplicationConfiguration.GetAppSetting("configfile", "");
            FileInfo fi;

            if (filename == null || filename.Length < 3)
            {
                fi = RelativeFilePathsCalculator.GetAbsolutePathToFileInApplicationDataFolder("\\DemoConfiguration.oses");
            }
            else
            {
                fi = RelativeFilePathsCalculator.GetAbsolutePathToFileInApplicationDataFolder(filename);
            }
            filename = fi.FullName;
        } //static AppConfigManagement
Пример #3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ServerWrapper" /> class.
        /// </summary>
        /// <param name="plugin">he interface to get access to the plugin.</param>
        /// <param name="assembly">TAn assembly containing the plug-in.</param>
        /// <param name="userInterface">The user interaction interface that provides basic functionality to implement user interactivity.</param>
        /// <param name="solutionPath">The solution path.</param>
        /// <param name="configuration">The file path containing the configuration.</param>
        public ServerWrapper(IConfiguration plugin, Assembly assembly, IGraphicalUserInterface userInterface, string solutionPath, string configuration)
        {
            Initialize(plugin, assembly);
            FileInfo _file = null;

            if (!string.IsNullOrEmpty(configuration))
            {
                if (!RelativeFilePathsCalculator.TestIfPathIsAbsolute(configuration))
                {
                    _file = new FileInfo(Path.Combine(solutionPath, configuration));
                }
                else
                {
                    _file = new FileInfo(configuration);
                }
            }
            if (_file == null)
            {
                Configuration = new ConfigurationWrapper(null, m_Server, userInterface);
            }
            else
            {
                Configuration = new ConfigurationWrapper(_file, m_Server, userInterface);
            }
        }
Пример #4
0
 public void CalculateAbsoluteFileNameTest()
 {
     Assert.AreEqual <string>(m_AbsolutePath, RelativeFilePathsCalculator.CalculateAbsoluteFileName(m_AbsolutePath, m_AbsolutePath));
     Assert.AreEqual <string>(m_AbsoluteFilePath, RelativeFilePathsCalculator.CalculateAbsoluteFileName(m_AbsoluteFilePath, m_AbsolutePath));
     Assert.ThrowsException <ArgumentOutOfRangeException>(() => RelativeFilePathsCalculator.CalculateAbsoluteFileName(m_Relative1, m_AbsolutePath));
     Assert.ThrowsException <ArgumentOutOfRangeException>(() => RelativeFilePathsCalculator.CalculateAbsoluteFileName(m_Relative2, m_AbsolutePath));
     Assert.AreEqual <string>(Path.Combine(m_AbsolutePath, m_FileName), RelativeFilePathsCalculator.CalculateAbsoluteFileName(m_FileName, m_AbsolutePath));
 }
Пример #5
0
 public void TestIfPathIsAbsoluteTest()
 {
     Assert.IsTrue(RelativeFilePathsCalculator.TestIfPathIsAbsolute(m_AbsolutePath));
     Assert.ThrowsException <ArgumentOutOfRangeException>(() => RelativeFilePathsCalculator.TestIfPathIsAbsolute(m_Relative1));
     Assert.ThrowsException <ArgumentOutOfRangeException>(() => RelativeFilePathsCalculator.TestIfPathIsAbsolute(m_Relative2));
     Assert.IsFalse(RelativeFilePathsCalculator.TestIfPathIsAbsolute(m_Relative3));
     Assert.IsTrue(RelativeFilePathsCalculator.TestIfPathIsAbsolute(Path.Combine(m_Relative3, m_AbsolutePath)));
     Assert.IsTrue(RelativeFilePathsCalculator.TestIfPathIsAbsolute(Path.Combine(m_AbsolutePath, m_Relative3)));
 }
Пример #6
0
 private string GetRelativePath(string fileName)
 {
     if (!string.IsNullOrEmpty(m_SolutionHomeDirectory.GetBaseDirectory()) && !string.IsNullOrEmpty(fileName))
     {
         Directory.SetCurrentDirectory(m_SolutionHomeDirectory.GetBaseDirectory());
         string _fullPath = Path.GetFullPath(fileName);
         fileName = RelativeFilePathsCalculator.TryComputeRelativePath(m_SolutionHomeDirectory.GetBaseDirectory(), _fullPath);
     }
     return(fileName);
 }
Пример #7
0
 public void TryComputeRelativePathTest()
 {
     Assert.ThrowsException <ArgumentOutOfRangeException>(() => RelativeFilePathsCalculator.TryComputeRelativePath(m_Relative1, m_Relative3));
     Assert.ThrowsException <ArgumentOutOfRangeException>(() => RelativeFilePathsCalculator.TryComputeRelativePath(m_AbsolutePath, m_AbsolutePath));
     Assert.AreEqual <string>(m_FileName, RelativeFilePathsCalculator.TryComputeRelativePath(m_AbsolutePath, Path.Combine(m_AbsolutePath, m_FileName)));
     Assert.AreEqual <string>(m_Relative3, RelativeFilePathsCalculator.TryComputeRelativePath(m_AbsolutePath, m_Relative3));
     Assert.AreEqual <string>(m_Relative3, RelativeFilePathsCalculator.TryComputeRelativePath(m_AbsolutePath, Path.Combine(m_AbsolutePath, m_Relative3)));
     Assert.AreEqual <string>(@"..\x\FileName.txt", RelativeFilePathsCalculator.TryComputeRelativePath(m_AbsolutePath, m_AbsoluteFilePath));
     Assert.AreEqual <string>(@"..\..\..\a\b\x\FileName.txt", RelativeFilePathsCalculator.TryComputeRelativePath(@"C:\c\b\a\", m_AbsoluteFilePath));
     Assert.AreEqual <string>(@"C:\a\b\x\FileName.txt", RelativeFilePathsCalculator.TryComputeRelativePath(@"D:\c\b\a\", m_AbsoluteFilePath));
 }
Пример #8
0
        private string ReplaceTokenAndReturnFullPath(string nameToBeReturned)
        {
            string myName = nameToBeReturned.Replace(Resources.Token_ProjectFileName, Path.GetFileNameWithoutExtension(FileName));

            if (RelativeFilePathsCalculator.TestIfPathIsAbsolute(myName))
            {
                return(myName);
            }
            string directory = Path.GetDirectoryName(FilePath);

            return(Path.Combine(directory, myName));
        }
Пример #9
0
 private ProjectTreeNode(ISolutionDirectoryPathManagement solutionPath, string filePath, OPCFModelDesign model) : this(solutionPath, Path.GetFileNameWithoutExtension(filePath))
 {
     UAModelDesignerProject = new UAModelDesignerProject()
     {
         BuildOutputDirectoryName = Resources.DefaultOutputBuildDirectory,
         CSVFileName       = Resources.DefaultCSVFileName,
         FileName          = RelativeFilePathsCalculator.TryComputeRelativePath(solutionPath.BaseDirectory, filePath),
         ProjectIdentifier = Guid.NewGuid().ToString(),
         Name = m_GetNextUniqueProjectName
     };
     InitializeComponent(new ModelDesign(model, false));
 }
 public void CalculateAbsoluteFileNameTest()
 {
     Assert.ThrowsException <ArgumentOutOfRangeException>(() => RelativeFilePathsCalculator.CalculateAbsoluteFileName(m_AbsolutePath, m_AbsolutePath));
     Assert.AreEqual <string>(@"C:\VS.git\UAOOI\ASMD210\ModelDesigner.ModelsContainer\bin\Model_0.xml",
                              RelativeFilePathsCalculator.CalculateAbsoluteFileName(m_AbsolutePath, @"C:\VS.git\UAOOI\ASMD210\ModelDesigner.ModelsContainer\bin\Release\..\Model_0.xml"));
     Assert.AreEqual <string>(m_AbsoluteFilePath, RelativeFilePathsCalculator.CalculateAbsoluteFileName(m_AbsolutePath, m_AbsoluteFilePath));
     Assert.AreEqual <string>(Path.Combine(Directory.GetCurrentDirectory(), @"Documents"), RelativeFilePathsCalculator.CalculateAbsoluteFileName(m_AbsolutePath, m_Relative1));
     Assert.ThrowsException <ArgumentOutOfRangeException>(() => RelativeFilePathsCalculator.CalculateAbsoluteFileName(m_AbsolutePath, m_Relative2));
     Assert.AreEqual <string>(Path.Combine(m_AbsolutePath, m_FileName), RelativeFilePathsCalculator.CalculateAbsoluteFileName(m_AbsolutePath, m_FileName));
     Assert.AreEqual <string>(@"C:\VS.git\UAOOI\ASMD210\ModelDesigner.ModelsContainer\bin\Model_0.xml",
                              RelativeFilePathsCalculator.CalculateAbsoluteFileName(@"C:\VS.git\UAOOI\ASMD210\ModelDesigner.ModelsContainer\bin\Release\", @"..\Model_0.xml"));
     Assert.AreEqual <string>(String.Empty, RelativeFilePathsCalculator.CalculateAbsoluteFileName(m_AbsolutePath, String.Empty));
     Assert.AreEqual <string>(String.Empty, RelativeFilePathsCalculator.CalculateAbsoluteFileName(m_AbsolutePath, null));
 }
Пример #11
0
        /// <summary>
        /// Reads the configuration.
        /// </summary>
        /// <param name="fileName">The fully qualified name of the file, or the relative file name.</param>
        /// <exception cref="FileNotFoundException">The exception that is thrown when an attempt to access a file
        /// that does not exist on disk fails.
        /// </exception>
        public void ReadConfiguration(string fileName)
        {
            FileInfo info = RelativeFilePathsCalculator.GetAbsolutePathToFileInApplicationDataFolder(fileName);

            if (!info.Exists)
            {
                throw new FileNotFoundException(info.FullName);
            }
            m_Configuration.Clear();
            m_Configuration.EnforceConstraints = false;
            m_Configuration.ReadXml(info.FullName, System.Data.XmlReadMode.IgnoreSchema);
            m_Configuration.EnforceConstraints = true;
            m_SaveFileDialog.FileName          = m_OpenFileDialog.FileName = info.FullName;
            RaiseConfigurationChnged();
        }
Пример #12
0
        /// <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));
        }
        static AppConfigManagement()
        {
            ItemDsc_configfile = ApplicationConfiguration.GetAppSetting("ItemDsc_configfile", "");
            FileInfo fi = RelativeFilePathsCalculator.GetAbsolutePathToFileInApplicationDataFolder(ItemDsc_configfile);

            if (ItemDsc_configfile == null || ItemDsc_configfile.Length < 3)
            {
                FileInfo fiIfNull = RelativeFilePathsCalculator.GetAbsolutePathToFileInApplicationDataFolder(@"\item_dsc.xml");
                ItemDsc_configfile = fiIfNull.FullName;
            }
            else
            {
                ItemDsc_configfile = fi.FullName;
            }
            RemotingHTTPport        = ApplicationConfiguration.GetAppSetting("RemotingHTTPport", RemotingHTTPport);
            ConsoleRemotingHTTPport = ApplicationConfiguration.GetAppSetting("ConsoleRemotingHTTPport", ConsoleRemotingHTTPport);
        }
        /// <summary>
        /// Prepares the path based on base directory.
        /// </summary>
        /// <param name="sourcePath">The source path.</param>
        /// <returns>FileInfo.</returns>
        public static FileInfo PreparePathBasedOnBaseDirectory(string sourcePath)
        {
            FileInfo file = null;

            if (!string.IsNullOrEmpty(sourcePath))
            {
                if (!RelativeFilePathsCalculator.TestIfPathIsAbsolute(sourcePath))
                {
                    file = new FileInfo(Path.Combine(CurrentDirectory, sourcePath));
                }
                else
                {
                    file = new FileInfo(sourcePath);
                }
            }
            return(file);
        }
        internal SolutionConfigurationManagement(Tuple <UAModelDesignerSolution, string> solutionDescription, bool changesArePresent, IGraphicalUserInterface gui) : base(solutionDescription.Item2, changesArePresent, gui)
        {
            AssemblyTraceEvent.Tracer.TraceEvent(TraceEventType.Verbose, 335242041, "Creating new private solution using Empty model");
            m_Name = solutionDescription.Item1.Name;
            UAModelDesignerSolutionServerDetails _ServerDetails = solutionDescription.Item1.ServerDetails ?? throw new ArgumentNullException(nameof(UAModelDesignerSolution.ServerDetails));

            m_Projects = solutionDescription.Item1.Projects.Select <UAModelDesignerProject, IProjectConfigurationManagement>(x => ProjectConfigurationManagement.ImportModelDesign(this, base.GraphicalUserInterface, x)).ToList <IProjectConfigurationManagement>();
            string _codebase      = RelativeFilePathsCalculator.CalculateAbsoluteFileName(this.DefaultDirectory, _ServerDetails.codebase);
            string _configuration = RelativeFilePathsCalculator.CalculateAbsoluteFileName(this.DefaultDirectory, _ServerDetails.configuration);

            m_Server = new ServerSelector(base.GraphicalUserInterface, this, _codebase, _configuration);
            if (string.IsNullOrEmpty(Settings.Default.DefaultSolutionFileName))
            {
                Settings.Default.DefaultSolutionFileName = DefaultFileName;
                Settings.Default.Save();
            }
            AssemblyTraceEvent.Tracer.TraceEvent(TraceEventType.Verbose, 335242042, "Finished successfully CommonInitialization");
        }
Пример #16
0
        /// <summary>
        /// Reads the XML file.
        /// </summary>
        /// <param name="myData">My data.</param>
        /// <param name="filename">The filename.</param>
        /// <param name="open_readonly">if set to <c>true</c> file is opened as read-only.</param>
        public static void readXMLFile(DataSet myData, string filename, bool open_readonly)
        {
            //Processes.EventLogMonitor.WriteToEventLogInfo( "Reading: " + filename + " for CommServer configuration" );
            System.IO.FileStream myFileStream;
            FileInfo             fi = new FileInfo(filename);

            if (!fi.Exists)
            {
                fi = RelativeFilePathsCalculator.GetAbsolutePathToFileInApplicationDataFolder(filename);
            }
            if (open_readonly)
            {
                myFileStream = new System.IO.FileStream(fi.FullName, System.IO.FileMode.Open, System.IO.FileAccess.Read, System.IO.FileShare.Read);
            }
            else
            {
                myFileStream = new System.IO.FileStream(fi.FullName, System.IO.FileMode.Open);
            }
            System.Xml.XmlTextReader myXmlReader;
            //Create an XmlTextReader with the fileStream.
            myXmlReader = new System.Xml.XmlTextReader(myFileStream);
            myData.ReadXml(myXmlReader);
            myXmlReader.Close();
        }
Пример #17
0
 /// <summary>
 /// reading of configuration XML file
 /// </summary>
 /// <param name="myData">target data set</param>
 /// <param name="filename">filename</param>
 public void readXMLFile(DataSet myData, string filename)
 {
     if (string.IsNullOrEmpty(filename))
     {
         EventLogMonitor.WriteToEventLogInfo(itemdscHasNotBeenSet, 39);
         return;
     }
     else if (filename == "item_dsc.xml")
     {
         FileInfo fi          = RelativeFilePathsCalculator.GetAbsolutePathToFileInApplicationDataFolder(filename);
         string   itemdscPath = fi.FullName;
         if (!new FileInfo(itemdscPath).Exists)
         {
             EventLogMonitor.WriteToEventLog(itemdscDoesNotExists, EventLogEntryType.Warning);
             return;
         }
         else
         {
             filename = itemdscPath;
         }
     }
     else if (!new FileInfo(filename).Exists)
     {
         EventLogMonitor.WriteToEventLog(string.Format(itemdscDoesNotExists, filename), EventLogEntryType.Warning);
         return;
     }
     myData.Clear();
     try
     {
         myData.ReadXml(filename, XmlReadMode.IgnoreSchema);
     }
     catch (Exception)
     {
         EventLogMonitor.WriteToEventLog(itemdscCannotBeOpened, EventLogEntryType.Warning);
     }
 }
Пример #18
0
        private static string ReplaceTokenAndReturnFullPath(string fileNameToBeProcessed, string projectName, string solutionDirectory)
        {
            string _Name = fileNameToBeProcessed.Replace(Resources.Token_ProjectFileName, projectName);

            return(RelativeFilePathsCalculator.CalculateAbsoluteFileName(solutionDirectory, _Name));
        }
Пример #19
0
        /// <summary>
        /// Builds the model managed by this project using external compiler.
        /// </summary>
        /// <param name="traceMessage">Action to be used to trace the .</param>
        void IProjectConfigurationManagement.Build(Action <string> traceMessage)
        {
            string _filePath = RelativeFilePathsCalculator.CalculateAbsoluteFileName(this.m_ISolutionConfigurationManagement.DefaultDirectory, m_UAModelDesignerProject.FileName);

            if (!File.Exists(this.DefaultFileName))
            {
                string msg = string.Format(Resources.BuildError_Fie_DoesNotExist, _filePath);
                traceMessage(msg);
                GraphicalUserInterface.MessageBoxShowError(msg, Resources.Build_Caption);
                return;
            }
            (string CSVFileName, string OutputDirectory) = BuildCalculateFileNames();
            if (!Directory.Exists(OutputDirectory))
            {
                Directory.CreateDirectory(OutputDirectory);
            }
            if (!File.Exists(CSVFileName))
            {
                string msg = string.Format(Resources.BuildError_Fie_DoesNotExist_doyouwanttocreateone, CSVFileName);
                if (GraphicalUserInterface.MessageBoxShowWarningAskYN(msg, Resources.Build_Caption))
                {
                    using (StreamWriter myCsvFile = new StreamWriter(CSVFileName, false))//we are creating an blank file (one empty line inside)
                    {
                        myCsvFile.WriteLine(" ");
                        myCsvFile.Flush();
                    }
                }
                else
                {
                    traceMessage(string.Format(Resources.BuildError_Fie_DoesNotExist, CSVFileName));
                    return;
                }
            }
            string           _commandLine  = string.Format(Properties.Settings.Default.Build_ProjectCompilationString, _filePath, CSVFileName, OutputDirectory);
            string           _compilerPath = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), Properties.Settings.Default.ProjectCompilationExecutable);
            ProcessStartInfo myStartInfo   = new ProcessStartInfo(_compilerPath)
            {
                Arguments = _commandLine,
                RedirectStandardOutput = true,
                RedirectStandardError  = true,
                UseShellExecute        = false,
                CreateNoWindow         = true
            };

            traceMessage($"{_compilerPath}  ");
            traceMessage(_commandLine);
            traceMessage("");
            Process _buildProcess = new Process
            {
                StartInfo = myStartInfo
            };

            if (!_buildProcess.Start())
            {
                GraphicalUserInterface.MessageBoxShowWarning(Resources.Build_click_ok_when_build_has_finished, Resources.Build_Caption);
            }
            else
            {
                _buildProcess.WaitForExit();
                string _outputfrombuildprocess      = _buildProcess.StandardOutput.ReadToEnd();
                string _erroroutputfrombuildprocess = _buildProcess.StandardError.ReadToEnd();
                if (!string.IsNullOrEmpty(_erroroutputfrombuildprocess))
                {
                    _erroroutputfrombuildprocess = string.Format(Resources.BuildError_error_occured, _erroroutputfrombuildprocess);
                }
                else
                {
                    _erroroutputfrombuildprocess = Resources.Build_project_ok;
                }
                _outputfrombuildprocess += _erroroutputfrombuildprocess;
                if (!string.IsNullOrEmpty(_outputfrombuildprocess))
                {
                    traceMessage(_outputfrombuildprocess);
                }
            }
        }
Пример #20
0
 /// <summary>
 /// Calculates the effective absolute model file path.
 /// </summary>
 /// <returns>System.String.</returns>
 internal string CalculateEffectiveAbsoluteModelFilePath()
 {
     return(RelativeFilePathsCalculator.CalculateAbsoluteFileName(this.FileName, m_SolutionHomeDirectory.BaseDirectory));
 }
Пример #21
0
        static void Main()
        {
            string m_cmmdLine = Environment.CommandLine;

            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            if (m_cmmdLine.ToLower().Contains(str_debug_install_argument))
            {
                CASApplicationInstance.InstallServer(Assembly.GetExecutingAssembly().Location);
            }
            if (m_cmmdLine.ToLower().Contains(str_debug_uninstall_argument))
            {
                CASApplicationInstance.UnInstallServer(Assembly.GetExecutingAssembly().Location);
            }
            CASApplicationInstance  application = new CASApplicationInstance();
            ConfigurationEditorMain config      = new ConfigurationEditorMain();

            try
            {
                if (!Environment.UserInteractive)
                {
                    Directory.SetCurrentDirectory(new FileInfo(Assembly.GetExecutingAssembly().Location).DirectoryName);
                    if (application.ProcessCommandLine())
                    {
                        return;
                    }
                    application.StartAsService(new UAServer());
                    return;
                }
            }
            catch (Exception e)
            {
                Utils.Trace(e, "Unexpected error starting service.");
                return;
            }
#if DEBUG
            MessageBox.Show("Attach debug point");
#endif
            if (m_cmmdLine.ToLower().Contains(str_installic_argument))
            {
                try
                {
                    LibInstaller.InstallLicense(true);
                }
                catch (Exception ex)
                {
                    MessageBox.Show("License installation has failed, reason: " + ex.Message);
                }
            }
            UAServer server = new UAServer();
            try
            {
                FileInfo configFI = RelativeFilePathsCalculator.GetAbsolutePathToFileInApplicationDataFolder(Settings.Default.ConfigurationFilePath);
                config.ReadConfiguration(configFI);
                if (config.Configuration == null)
                {
                    throw new ArgumentNullException("Cannot read configuration");
                }
                BaseDirectoryHelper.Instance.SetBaseDirectoryProvider(new BaseDirectoryProvider(configFI.DirectoryName));
                ApplicationCertificate.CheckApplicationInstanceCertificate(config.Configuration, 1024, (x, y) => true, true); //TODO add logging function or user interface.
                ApplicationCertificate.OverrideUaTcpImplementation(config.Configuration);
                server.Start(config.Configuration);
                Application.Run(new ServerForm(server, config.Configuration, application));
            }
            catch (Exception e)
            {
                HandleException("UA Server", e);
            }
            finally
            {
                server.Stop();
            }
        }