예제 #1
0
 public WorkerArg(TiaPortal portal,
                  IEngineeringCompositionOrObject top,
                  ParseCtxt ctxt)
 {
     this.portal = portal;
     this.top    = top;
     this.ctxt   = ctxt;
 }
예제 #2
0
        public PresetGenerate(TiaPortal portal, IEngineeringCompositionOrObject top, List <HmiTarget> hmiTargets, string culture)
        {
            InitializeComponent();
            tiaPortal    = portal;
            FormClosing += FormClosingEventHandler;
            presetListView.AutoGenerateColumns = false;
            presetList = new PresetTagList
            {
                Culture = culture
            };
            presetListView.DataSource = presetList;

            writeButton.Enabled  = false;
            exportButton.Enabled = false;
            parser            = new TagParser(portal);
            parser.HandleTag += HandleTag;
            parser.ParseDone += ParseDone;
            parser.ParseAsync(top, log);

            IEngineeringCompositionOrObject node = top;

            while (node.Parent is PlcBlockGroup)
            {
                node = node.Parent;
            }
            PlcBlockGroup top_group = (PlcBlockGroup)node;

            resultGroup = top_group.Groups.Find("Preset");
            if (resultGroup == null)
            {
                resultGroup = top_group.Groups.Create("Preset");
            }
            while (node != null && !(node is PlcSoftware))
            {
                node = node.Parent;
            }
            if (node == null)
            {
                throw new Exception("No PlcSoftware node found");
            }
            plcSoftware = (PlcSoftware)node;
            typeGroup   = plcSoftware.TypeGroup.Groups.Find("Preset");
            if (typeGroup == null)
            {
                typeGroup = plcSoftware.TypeGroup.Groups.Create("Preset");
            }
            this.hmiTargets = hmiTargets;

            Project             proj  = tiaPortal.Projects[0];
            LanguageAssociation langs = proj.LanguageSettings.ActiveLanguages;

            cultureComboBox.Items.Clear();
            cultureComboBox.Items.AddRange(langs.Select(l => l.Culture.Name).ToArray());
            cultureComboBox.SelectedItem = culture;
        }
예제 #3
0
        public void Parse(IEngineeringCompositionOrObject top, MessageLog log = null, Options options = 0)
        {
            ParseCtxt parse = new ParseCtxt(OnHandleTag, options);

            parse.Log = log;
            lock (portal)
            {
                if (top is PlcBlockGroup)
                {
                    parse.HandleBlockFolder((PlcBlockGroup)top);
                }
                else
                {
                    parse.HandleDataBlock((PlcBlock)top);
                }
            }
        }
예제 #4
0
        public void ParseAsync(IEngineeringCompositionOrObject top, MessageLog log = null, Options options = 0)
        {
            if (worker != null && worker.IsBusy)
            {
                return;
            }

            worker = new BackgroundWorker();
            worker.WorkerSupportsCancellation = true;
            worker.DoWork             += DoWork;
            worker.RunWorkerCompleted += RunWorkerCompleted;
            callback_ctxt              = SynchronizationContext.Current;
            ParseCtxt parse = new ParseCtxt(HandleTagAsync, options);

            parse.Log = log;
            WorkerArg arg = new WorkerArg(portal, top, parse);

            worker.RunWorkerAsync(arg);
        }
예제 #5
0
        /// <summary>
        /// Exports the selected structure including subdirectories. Missing folders will be created.
        /// </summary>
        /// <param name="elementToExport">Project, station or folder to export</param>
        /// <param name="exportOptions">The export options.</param>
        /// <param name="exportPath">Folder path in which to export</param>
        /// <exception cref="System.ArgumentNullException">Parameter is null;elementToExport</exception>
        /// <exception cref="System.ArgumentException">Parameter is null or empty;exportPath</exception>
        /// <exception cref="System.IO.IOException"></exception>
        /// <exception cref="System.UnauthorizedAccessException"></exception>
        /// <exception cref="System.IO.DirectoryNotFoundException"></exception>
        public static void ExportStructure(IEngineeringCompositionOrObject elementToExport, ExportOptions exportOptions, string exportPath)
        {
            if (elementToExport == null)
            {
                throw new ArgumentNullException(nameof(elementToExport), "Parameter is null");
            }
            if (String.IsNullOrEmpty(exportPath))
            {
                throw new ArgumentException("Parameter is null or empty", nameof(exportPath));
            }


            if (elementToExport is PlcBlock || elementToExport is PlcTagTable || elementToExport is PlcType || elementToExport is PlcExternalSource ||
                elementToExport is ScreenOverview || elementToExport is ScreenGlobalElements || elementToExport is TagTable || elementToExport is Screen ||
                elementToExport is Cycle || elementToExport is Connection || elementToExport is MultiLingualGraphic || elementToExport is ScreenTemplate ||
                elementToExport is VBScript || elementToExport is TextList || elementToExport is ScreenPopup || elementToExport is ScreenSlidein)
            {
                ExportItem(elementToExport as IEngineeringObject, exportOptions, exportPath);
                return;
            }

            var folderName = GetObjectName(elementToExport);

            var newPath = Path.Combine(exportPath, folderName);

            Directory.CreateDirectory(newPath);

            foreach (var item in GetSubItem(elementToExport))
            {
                if (!(item is Cycle && (item as Cycle).IsSystemObject))
                {
                    //add if for inconsistence
                    ExportItem(item as IEngineeringObject, exportOptions, newPath);
                }
            }

            foreach (var folder in GetSubFolder(elementToExport))
            {
                ExportStructure(folder as IEngineeringCompositionOrObject, exportOptions, newPath);
            }
        }
예제 #6
0
 /// <summary>
 /// Exports the selected structure including subdirectories. Missing folders will be created.
 /// </summary>
 /// <param name="elementToExport">Project, station or folder to export</param>
 /// <param name="exportPath">Folder path in which to export</param>
 /// <exception cref="System.ArgumentException"></exception>
 /// <exception cref="System.ArgumentNullException"></exception>
 /// <exception cref="System.IO.IOException"></exception>
 /// <exception cref="System.UnauthorizedAccessException"></exception>
 /// <exception cref="System.IO.DirectoryNotFoundException"></exception>
 public static void ExportStructure(IEngineeringCompositionOrObject elementToExport, string exportPath)
 {
     ExportStructure(elementToExport, (ExportOptions.WithDefaults | ExportOptions.WithReadOnly), exportPath);
 }
예제 #7
0
        /// <summary>
        /// Imports a file under the given TIA object with the given import options
        /// </summary>
        /// <param name="destination">TIA object under which the file will be imported.</param>
        /// <param name="filePath">Path to the file</param>
        /// <param name="importOption">TIA import options</param>
        /// <exception cref="System.ArgumentNullException">Parameter is null;destination</exception>
        /// <exception cref="System.ArgumentException">Parameter is null or empty;filePath</exception>
        /// <exception cref="System.IO.IOException"></exception>
        /// <exception cref="System.UnauthorizedAccessException"></exception>
        /// <exception cref="System.IO.DirectoryNotFoundException"></exception>
        public static void ImportItem(IEngineeringCompositionOrObject destination, string filePath, ImportOptions importOption)
        {
            if (destination == null)
            {
                throw new ArgumentNullException(nameof(destination), "Parameter is null");
            }
            if (string.IsNullOrEmpty(filePath))
            {
                throw new ArgumentException("Parameter is null or empty", nameof(filePath));
            }

            var fileInfo = new FileInfo(filePath);

            filePath = fileInfo.FullName;

            if (destination is CycleComposition || destination is ConnectionComposition || destination is MultiLingualGraphicComposition ||
                destination is GraphicListComposition || destination is TextListComposition)
            {
                var parameter = new Dictionary <Type, object>();
                parameter.Add(typeof(string), filePath);
                parameter.Add(typeof(ImportOptions), importOption);
                // Export prüfen
                (destination as IEngineeringComposition).Invoke("Import", parameter);
            }
            else if (destination is PlcBlockGroup)
            {
                if (Path.GetExtension(filePath).Equals(".xml"))
                {
                    (destination as PlcBlockGroup).Blocks.Import(fileInfo, importOption);
                }
                else
                {
                    var currentDestination = destination as IEngineeringObject;
                    while (!(currentDestination is PlcSoftware))
                    {
                        currentDestination = currentDestination.Parent;
                    }
                    var col = (currentDestination as PlcSoftware).ExternalSourceGroup.ExternalSources;

                    var sourceName = Path.GetRandomFileName();
                    sourceName = Path.ChangeExtension(sourceName, ".src");
                    var src = col.CreateFromFile(sourceName, filePath);
                    src.GenerateBlocksFromSource();
                    src.Delete();
                }
            }
            else if (destination is PlcTagTableGroup)
            {
                (destination as PlcTagTableGroup).TagTables.Import(fileInfo, importOption);
            }
            else if (destination is PlcTypeGroup)
            {
                (destination as PlcTypeGroup).Types.Import(fileInfo, importOption);
            }
            else if (destination is PlcExternalSourceGroup)
            {
                var temp = (destination as PlcExternalSourceGroup).ExternalSources.Find(Path.GetFileName(filePath));
                if (temp != null)
                {
                    temp.Delete();
                }
                (destination as PlcExternalSourceGroup).ExternalSources.CreateFromFile(Path.GetFileName(filePath), filePath);
            }
            else if (destination is TagFolder)
            {
                (destination as TagFolder).TagTables.Import(fileInfo, importOption);
            }
            else if (destination is ScreenFolder)
            {
                (destination as ScreenFolder).Screens.Import(fileInfo, importOption);
            }
            else if (destination is ScreenTemplateFolder)
            {
                (destination as ScreenTemplateFolder).ScreenTemplates.Import(fileInfo, importOption);
            }
            else if (destination is ScreenPopupFolder)
            {
                (destination as ScreenPopupFolder).ScreenPopups.Import(fileInfo, importOption);
            }
            else if (destination is ScreenSlideinSystemFolder)
            {
                (destination as ScreenSlideinSystemFolder).ScreenSlideins.Import(fileInfo, importOption);
            }
            else if (destination is VBScriptFolder)
            {
                (destination as VBScriptFolder).VBScripts.Import(fileInfo, importOption);
            }
            else if (destination is ScreenGlobalElements)
            {
                (destination.Parent as HmiTarget)?.ImportScreenGlobalElements(fileInfo, importOption);
            }
            else if (destination is ScreenOverview)
            {
                (destination.Parent as HmiTarget)?.ImportScreenOverview(fileInfo, importOption);
            }
        }