public void HandleDataBlock(PlcBlock block) { if (block.ProgrammingLanguage != ProgrammingLanguage.DB) { return; } try { BlockType instance_of = (BlockType)block.GetAttribute("InstanceOfType"); if (instance_of != BlockType.UDT) { return; } } catch (EngineeringNotSupportedException) { } if (!block.IsConsistent) { Log?.LogMessage(MessageLog.Severity.Warning, "Skipped block " + block.Name + " because it is inconsistent. Compile block to make it consistent."); return; } FileInfo path = TempFile.File("block_", "xml"); try { Console.WriteLine("Exporting: " + block.Name); block.Export(path, ExportOptions.WithDefaults); ParseXML_DB(path); } catch (Siemens.Engineering.EngineeringTargetInvocationException e) { Log?.LogMessage(MessageLog.Severity.Error, "Failed to export block " + block.Name + ": " + e.Message); } finally { try { path.Delete(); } catch (IOException e) { Log?.LogMessage(MessageLog.Severity.Error, "Failed to delete temporary file: " + e.Message); } } }
static public XmlDocument ExportPlcTypeXML(PlcType type) { FileInfo path = TempFile.File("export_type_", "xml"); try { type.Export(path, ExportOptions.WithDefaults); XmlDocument doc = LoadDoc(path.ToString()); return(doc); } finally { try { path.Delete(); } catch (IOException e) { Console.WriteLine("Failed to delete temporary file: " + e.Message); } } }
static public void ImportPlcBlockXML(XmlDocument doc, PlcBlockGroup group) { FileInfo path = TempFile.File("import_block_", "xml"); try { XmlWriter writer = XmlWriter.Create(path.ToString()); doc.Save(writer); writer.Close(); group.Blocks.Import(path, ImportOptions.Override); } finally { try { path.Delete(); } catch (IOException e) { Console.WriteLine("Failed to delete temporary file: " + e.Message); } } }
static public void ImportTextListXML(XmlDocument doc, TextListComposition text_lists) { FileInfo path = TempFile.File("import_text_list_", "xml"); try { XmlWriter writer = XmlWriter.Create(path.ToString()); doc.Save(writer); writer.Close(); text_lists.Import(path, ImportOptions.Override); } finally { try { path.Delete(); } catch (IOException e) { Console.WriteLine("Failed to delete temporary file: " + e.Message); } } }
protected override void DoWork() { lock (portal) { try { Stack <string> group_names = new Stack <string>(); IEngineeringObject obj = fromBlock.Parent; while (obj is PlcBlockUserGroup) { group_names.Push(((PlcBlockGroup)obj).Name); obj = obj.Parent; } PlcBlockGroup group = toPlc.BlockGroup; foreach (string group_name in group_names) { PlcBlockUserGroup child = group.Groups.Find(group_name); if (child != null) { group = child; } else { group = group.Groups.Create(group_name); } } FileInfo file = TempFile.File("export_block_", "xml"); fromBlock.Export(file, ExportOptions.None); group.Blocks.Import(file, overwrite ? ImportOptions.Override : ImportOptions.None); } catch (Exception ex) { LogMessage(MessageLog.Severity.Error, "Failed to copy from " + fromBlock.Name + " to " + toPlc.Name + ":\n" + ex.Message); return; } } }
static public void ImportHMITagTableXML(XmlDocument doc, TagFolder folder) { FileInfo path = TempFile.File("import_tagtable_", "xml"); try { XmlWriter writer = XmlWriter.Create(path.ToString()); doc.Save(writer); writer.Close(); folder.TagTables.Import(path, ImportOptions.Override); } finally { try { path.Delete(); } catch (IOException e) { Console.WriteLine("Failed to delete temporary file: " + e.Message); } } }