コード例 #1
0
        /// <summary>Returns the name of the IEngineeringInstance</summary>
        /// <param name="item">The item.</param>
        /// <returns></returns>
        public static string GetObjectName(IEngineeringInstance item)
        {
            var itemName = "";

            if (item == null)
            {
                return(itemName);
            }
            try
            {
                itemName = ((IEngineeringObject)item).GetAttribute("Name") as string;
            }
            catch (Exception)
            {
                // ignored
            }

            if (string.IsNullOrEmpty(itemName))
            {
                if (item is CycleComposition)
                {
                    itemName = "Cycles";
                }
                else if (item is ConnectionComposition)
                {
                    itemName = "Connections";
                }
                else if (item is MasterCopySystemFolder)
                {
                    itemName = "Master copies";
                }
                else if (item is MultiLingualGraphicComposition)
                {
                    itemName = "Mulilingual graphics";
                }
                else if (item is ScreenOverview)
                {
                    itemName = "ScreenOverview";
                }
                else if (item is GraphicListComposition)
                {
                    itemName = "GraphicLists";
                }
                else if (item is TextListComposition)
                {
                    itemName = "TextLists";
                }
                else if (item is ScreenGlobalElements)
                {
                    itemName = "ScreenGlobalElements";
                }
                else if (item is PlcSystemBlockGroupComposition)
                {
                    itemName = "SystemBlocks";
                }
            }

            return(itemName);
        }
コード例 #2
0
        /// <summary>Generates a source file from the given PlcBlock</summary>
        /// <param name="exportItem">The export item.</param>
        /// <param name="exportPath">The export path.</param>
        /// <param name="options"></param>
        /// <returns>String</returns>
        /// <exception cref="System.ArgumentNullException">Parameter is null;exportItem</exception>
        /// <exception cref="System.ArgumentException">Parameter is null or empty;exportPath</exception>
        /// <exception cref="Siemens.Engineering.EngineeringException"></exception>
        /// <exception cref="System.IO.IOException"></exception>
        /// <exception cref="System.UnauthorizedAccessException"></exception>
        /// <exception cref="System.IO.DirectoryNotFoundException"></exception>
        public static string GenerateSourceFromBlock(PlcBlock exportItem, string exportPath, GenerateOptions options)
        {
            if (exportItem == null)
            {
                throw new ArgumentNullException(nameof(exportItem), "Parameter is null");
            }
            if (String.IsNullOrEmpty(exportPath))
            {
                throw new ArgumentException("Parameter is null or empty", nameof(exportPath));
            }

            var filePath = Path.GetFullPath(exportPath);

            if (!exportItem.IsKnowHowProtected)
            {
                Directory.CreateDirectory(filePath);
                switch (exportItem.ProgrammingLanguage)
                {
                case ProgrammingLanguage.DB:
                    filePath = Path.Combine(filePath, AdjustNames.AdjustFileName(exportItem.Name) + ".db");
                    break;

                case ProgrammingLanguage.SCL:
                    filePath = Path.Combine(filePath, AdjustNames.AdjustFileName(exportItem.Name) + ".scl");
                    break;

                case ProgrammingLanguage.STL:
                    filePath = Path.Combine(filePath, AdjustNames.AdjustFileName(exportItem.Name) + ".awl");
                    break;

                default:
                    return(null);
                }

                if (File.Exists(filePath))
                {
                    File.Delete(filePath);
                }

                IEngineeringInstance temp = exportItem;

                do
                {
                    temp = temp.Parent;
                }while (!(temp is PlcSoftware));

                (temp as PlcSoftware).ExternalSourceGroup.GenerateSource(new[] { exportItem }, new FileInfo(filePath), options);

                return(filePath);
            }
            throw new EngineeringException(string.Format(CultureInfo.InvariantCulture, "Block: '{0}' is Know-how protected! \r\n 'Generate source from block' is not possible on know how protected blocks!", exportItem.Name));
        }
コード例 #3
0
        /// <summary>
        /// Adds all objects in the provided folder as TreeViewItems to the provided treeViewItem
        /// </summary>
        /// <param name="folder">The folder.</param>
        /// <param name="treeViewItem">The tree view item.</param>
        private static void RecursiveGetTreeView(IEngineeringInstance folder, ref TreeViewItem treeViewItem)
        {
            treeViewItem.Header = OpennessHelper.GetObjectName(folder);
            treeViewItem.Tag    = folder;

            foreach (var item in OpennessHelper.GetSubItem(folder))
            {
                var sub = new TreeViewItem();
                sub.Header = OpennessHelper.GetObjectName(item as IEngineeringInstance);
                sub.Tag    = item;

                if (!(item is Cycle && (item as Cycle).IsSystemObject))
                {
                    treeViewItem.Items.Add(sub);
                }
            }

            foreach (var subfolder in OpennessHelper.GetSubFolder(folder))
            {
                var subView = new TreeViewItem();
                RecursiveGetTreeView(subfolder as IEngineeringInstance, ref subView);
                treeViewItem.Items.Add(subView);
            }
        }