Exemplo n.º 1
0
            public override string Export(ExportFormat exportFormat)
            {
                var ext = "udt";

                if (exportFormat == ExportFormat.Xml)
                {
                    ext = "xml";
                }

                var tmp  = Path.GetTempPath();
                var file = Path.Combine(tmp, "tmp_dnspt_" + Guid.NewGuid().ToString().Replace("{", "").Replace("}", "").Replace("-", "").Replace(" ", "") + "." + ext);

                if (ext == "xml")
                {
                    plcType.Export(new FileInfo(file), Siemens.Engineering.ExportOptions.None);
                }
                else
                {
                    var fld = this.ParentFolder;
                    while (!(fld is TIAOpennessControllerFolder))
                    {
                        fld = fld.Parent;
                    }
                    ((TIAOpennessControllerFolder)fld).plcSoftware.ExternalSourceGroup.GenerateSource(new[] { this.plcType }, new FileInfo(file), Siemens.Engineering.SW.ExternalSources.GenerateOptions.None);
                }
                var text = File.ReadAllText(file);

                File.Delete(file);

                return(text);
            }
Exemplo n.º 2
0
 //****************************Export_IMport_UDT**********************************************
 //Exports a user defined type
 private static void ExportUserDefinedType(PlcSoftware plcSoftware)
 {
     try
     {
         string             udtname = "udt";
         PlcTypeComposition types   = plcSoftware.TypeGroup.Types;
         PlcType            udt     = types.Find(udtname);
         udt.Export(new FileInfo(string.Format(@"C:\testUDT\" + udt.Name + ".xml")), ExportOptions.WithDefaults);
     }
     catch (Exception ex)
     {
         MessageBox.Show("Chyba: " + ex.Message);
     }
 }
Exemplo n.º 3
0
        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);
                }
            }
        }
Exemplo n.º 4
0
 protected override void DoWork()
 {
     lock (portal)
     {
         try
         {
             Stack <string>     group_names = new Stack <string>();
             IEngineeringObject obj         = fromType.Parent;
             while (obj is PlcTypeUserGroup)
             {
                 group_names.Push(((PlcTypeGroup)obj).Name);
                 obj = obj.Parent;
             }
             PlcTypeGroup group = toPlc.TypeGroup;
             foreach (string group_name in group_names)
             {
                 PlcTypeUserGroup child = group.Groups.Find(group_name);
                 if (child != null)
                 {
                     group = child;
                 }
                 else
                 {
                     group = group.Groups.Create(group_name);
                 }
             }
             FileInfo file = TempFile.File("copy_type_", "xml");
             fromType.Export(file, ExportOptions.None);
             group.Types.Import(file, overwrite ? ImportOptions.Override : ImportOptions.None);
         } catch (Exception ex)
         {
             LogMessage(MessageLog.Severity.Error, "Failed to copy from " + fromType.Name + " to " + toPlc.Name + ":\n" + ex.Message);
             return;
         }
     }
 }