Beispiel #1
0
        /// <summary>
        /// Compiles the stated zenon Logic project.
        /// </summary>
        /// <param name="zenonLogicProjectToCompile"></param>
        /// <param name="compilerOutputText">
        /// Contains the output messages of the compilation process. Null if the if retrieving the compiler output failed.
        /// </param>
        public void CompileZenonLogicProject(LogicProject zenonLogicProjectToCompile, out IEnumerable <string> compilerOutputText)
        {
            if (!Directory.Exists(zenonLogicProjectToCompile.Path))
            {
                throw new DirectoryNotFoundException
                          ($"{Strings.ZenonLogicProjectDirectoryNotFound} {Strings.ZenonLogicHintForMissingDirectory}");
            }

            K5ToolSet k5ToolSet = new K5ToolSet(zenonLogicProjectToCompile.Path);

            k5ToolSet.CompileZenonLogicProject(zenonLogicProjectToCompile, out compilerOutputText);
        }
Beispiel #2
0
        /// <summary>
        /// Imports the stated zenon Logic projects into zenon Logic.
        /// As an import requires an existing project it tries to create a default project first.
        /// </summary>
        /// <param name="zenonLogicProjectsToImport">The zenon Logic projects to import.</param>
        /// <param name="reloadZenonProject">Specifies if the current zenon project shall be reloaded after the import.</param>
        /// <param name="options">Specifies options on how to import the <paramref name="zenonLogicProjectsToImport"/> into zenon.</param>
        private void ImportLogicProjectsIntoZenon(
            IEnumerable <LogicProject> zenonLogicProjectsToImport,
            bool reloadZenonProject,
            ImportOptions options)
        {
            EnsureSupportedVersion(options);
            foreach (LogicProject logicProject in zenonLogicProjectsToImport)
            {
                if (!logicProject.Path.Contains(this.ZenonProjectGuid))
                {
                    logicProject.ModifyStratonDirectoryPartOfPath(this.ZenonLogicDirectory);
                }

                K5ToolSet k5ToolSet = new K5ToolSet(logicProject.Path);

                // as there is no built in solution to check if a project exists this check is used to determine if a
                // certain project already exists in zenon Logic
                if (!Directory.Exists(logicProject.Path))
                {
                    // create default zenon Logic project as XML import requires a project to exist
                    k5ToolSet.CreateDefaultZenonLogicProject();

                    string nextFreeZenonLogicMainPort = GetNextFreeZenonLogicMainPort();
                    // free main port has to be used as parameter here as it is not yet set for the new zenon Logic project in the
                    // k5dbxs ini file.
                    string newStratonNgDriverId = CreateStratonNgDriverForZenonLogicProject(logicProject.ProjectName,
                                                                                            nextFreeZenonLogicMainPort);

                    uint mainPort = logicProject.MainPort;
                    K5DbxsIniFile.CreateK5DbxsIniFile
                    (
                        this.ZenonProjectGuid,
                        logicProject.K5DbxsIniFilePath,
                        mainPort != uint.MinValue ? mainPort.ToString() : nextFreeZenonLogicMainPort,
                        newStratonNgDriverId
                    );
                }

                k5ToolSet.ImportZenonLogicProject(logicProject, options);
                // Due to a change in zenon Logic 10, the compiler settings and further other options need to be set explicitly.
                k5ToolSet.TryApplyCompilerSettings(logicProject, options);
                k5ToolSet.TryApplyOnlineChangeSettings(logicProject, options);
            }

            if (reloadZenonProject)
            {
                // The following line is just necessary to force zenon to reload the logic projects within the displayed list.
                var workspace = ZenonProject.Parent.Parent.MyWorkspace;
                workspace.UnloadProject2(ZenonProjectGuid, true);
                workspace.LoadProject(ZenonProjectGuid);
            }
        }