Esempio n. 1
0
        /// <summary>
        /// Returns zenon Logic project reference for the stated project name.
        /// </summary>
        /// <param name="zenonLogicProjectName">The zenon Logic project to load.</param>
        public LogicProject GetLogicProjectByName(string zenonLogicProjectName)
        {
            if (string.IsNullOrEmpty(zenonLogicProjectName))
            {
                throw new ArgumentNullException(
                          string.Format(Strings.ErrorGettingZenonProjektByNameArgumentNull, nameof(zenonLogicProjectName)));
            }

            IEnumerable <LazyLogicProject> foundLogicProjectsByName = LazyLogicProjects.Where(
                project => string.Equals(project.ProjectName, zenonLogicProjectName));

            if (!foundLogicProjectsByName.Any())
            {
                throw new NullReferenceException(string.Format(Strings.ErrorNoZenonLogicProjectFoundForName, zenonLogicProjectName));
            }

            if (foundLogicProjectsByName.Count() > 1)
            {
                throw new InvalidDataException(string.Format(Strings.ErrorDuplicateLogicProjectFoundForName, zenonLogicProjectName));
            }

            return(foundLogicProjectsByName.First().Value);
        }
Esempio n. 2
0
        /// <summary>
        ///   Imports the zenon Logic project with specified project name into zenon.
        /// </summary>
        /// <param name="zenonLogicProjectName">The name of the zenon Logic project.</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 projects into zenon.</param>
        public void ImportLogicProjectIntoZenonByName(
            string zenonLogicProjectName,
            bool reloadZenonProject = true,
            ImportOptions options   = ImportOptions.Default)
        {
            if (string.IsNullOrWhiteSpace(zenonLogicProjectName))
            {
                throw new ArgumentNullException(string.Format(Strings.MethodArgumentNullException,
                                                              nameof(zenonLogicProjectName), nameof(ImportLogicProjectIntoZenonByName)));
            }

            IEnumerable <LogicProject> logicProjectsWithSearchedNames
                = LazyLogicProjects
                  .Where(lazyLogicProject => lazyLogicProject.ProjectName?.Equals(zenonLogicProjectName) ?? false)
                  .Select(project => project.Value);

            if (!logicProjectsWithSearchedNames.Any())
            {
                throw new InstanceNotFoundException(
                          string.Format(Strings.LogicProjectWithSpecifiedProjectNameNotFound, zenonLogicProjectName));
            }

            ImportLogicProjectsIntoZenon(logicProjectsWithSearchedNames, reloadZenonProject, options);
        }