/// <summary>
        /// Returns a <see cref="System.String" /> that represents this instance.
        /// </summary>
        /// <returns>A <see cref="System.String" /> that represents this instance.</returns>
        /// TODO Edit XML Comment Template for ToString
        public override string ToString()
        {
            var ret = "";
            var id  = 0;

            ret += "<?xml version=\"1.0\" encoding=\"utf-8\"?>" + Environment.NewLine;
            ret += "<Document>" + Environment.NewLine;
            ret += "<SW.PlcTagTable ID=\"" + id++ + "\">" + Environment.NewLine;
            ret += "<AttributeList>" + Environment.NewLine;
            ret += "<Name>" + AdjustNames.AdjustXmlStrings(Name) + "</Name>" + Environment.NewLine;
            ret += "</AttributeList>" + Environment.NewLine;
            ret += "<ObjectList>" + Environment.NewLine;
            foreach (var constant in _constants)
            {
                ret += constant.ToString(ref id);
            }
            foreach (var tag in _tags)
            {
                ret += tag.ToString(ref id);
            }
            ret += "</ObjectList>" + Environment.NewLine;
            ret += "</SW.PlcTagTable>" + Environment.NewLine;
            ret += "</Document>" + Environment.NewLine;

            return(ret);
        }
        /// <summary>
        /// Returns a <see cref="System.String" /> that represents this instance.
        /// </summary>
        /// <returns>A <see cref="System.String" /> that represents this instance.</returns>
        /// TODO Edit XML Comment Template for ToString
        public override string ToString()
        {
            var ret = "";

            var id = 0;

            ret += "<Member Name=\"" + AdjustNames.AdjustXmlStrings(MemberName) + "\" Datatype=\"" + AdjustNames.AdjustXmlStrings(MemberDatatype) + "\">" + Environment.NewLine;
            if (MemberComment.CompositionNameInXml != null)
            {
                ret += MemberComment.ToString(ref id);
            }

            ret += "<Sections>" + Environment.NewLine;
            foreach (var section in InterfaceSections)
            {
                ret += "<Section name=\"" + InterfaceSections[0].InterfaceSectionName + "\">" + Environment.NewLine;
                foreach (var member in section.InterfaceMember)
                {
                    ret += member.ToString();
                }
                ret += "</Section>" + Environment.NewLine;
            }
            ret += "</Sections>" + Environment.NewLine;

            if (!string.IsNullOrEmpty(MemberDefaultValue))
            {
                ret += "<StartValue>" + AdjustNames.AdjustXmlStrings(MemberDefaultValue) + "</StartValue>" + Environment.NewLine;
            }
            ret += "</Member>" + Environment.NewLine;

            return(ret);
        }
Esempio n. 3
0
        /// <summary>
        /// Returns a <see cref="System.String" /> that represents this instance.
        /// </summary>
        /// <param name="id">The identifier.</param>
        /// <returns>A <see cref="System.String" /> that represents this instance.</returns>
        /// TODO Edit XML Comment Template for ToString
        public string ToString(ref int id)
        {
            var ret = "";

            if (CompositionNameInXml != null)
            {
                if (CompositionNameInXml.Equals(""))
                {
                    ret += "<Comment>" + Environment.NewLine;
                    foreach (var entry in MultiLanguageTextItems)
                    {
                        ret += "<MultiLanguageText Lang=\"" + AdjustNames.AdjustXmlStrings(entry.Key) + "\">" + AdjustNames.AdjustXmlStrings(entry.Value) + "</MultiLanguageText>" + Environment.NewLine;
                    }
                    ret += "</Comment>" + Environment.NewLine;
                }

                else if (CompositionNameInXml.Equals("Comment") || CompositionNameInXml.Equals("Title"))
                {
                    ret += "<MultilingualText ID= \"" + id++ + "\"" + " CompositionName=\"" + AdjustNames.AdjustXmlStrings(CompositionNameInXml) + "\">" + Environment.NewLine;
                    ret += "<AttributeList>" + Environment.NewLine;
                    ret += "<TextItems>" + Environment.NewLine;

                    foreach (var entry in MultiLanguageTextItems)
                    {
                        ret += "<Value lang=\"" + AdjustNames.AdjustXmlStrings(entry.Key) + "\">" + AdjustNames.AdjustXmlStrings(entry.Value) + "</Value>" + Environment.NewLine;
                    }

                    ret += "</TextItems>" + Environment.NewLine;
                    ret += "</AttributeList>" + Environment.NewLine;
                    ret += "</MultilingualText>" + Environment.NewLine;
                }
            }

            return(ret);
        }
Esempio n. 4
0
        /// <summary>
        /// Returns a <see cref="System.String" /> that represents this instance.
        /// </summary>
        /// <returns>A <see cref="System.String" /> that represents this instance.</returns>
        /// TODO Edit XML Comment Template for ToString
        public override string ToString()
        {
            var ret = "";
            var id  = 0;

            ret += "<?xml version=\"1.0\" encoding=\"utf-8\"?>" + Environment.NewLine;
            ret += "<Document>" + Environment.NewLine;
            ret += "<SW.PlcType ID=\"" + id++ + "\">" + Environment.NewLine;
            ret += "<AttributeList>" + Environment.NewLine;
            ret += "<Interface>" + Environment.NewLine;
            ret += "<Sections xmlns=\"http://www.siemens.com/automation/Openness/SW/Interface/v1\">" + Environment.NewLine;
            ret += "<Section Name=\"None\">" + Environment.NewLine;
            foreach (var member in DatatypeMember)
            {
                ret += member + Environment.NewLine;
            }
            ret += "</Section>" + Environment.NewLine;
            ret += "</Sections>" + Environment.NewLine;
            ret += "</Interface>" + Environment.NewLine;
            ret += "<Name>" + AdjustNames.AdjustXmlStrings(Name) + "</Name>" + Environment.NewLine;
            ret += "</AttributeList>" + Environment.NewLine;

            ret += "<ObjectList>" + Environment.NewLine;
            ret += UdtComment.ToString(ref id) + Environment.NewLine;
            ret += UdtTitle.ToString(ref id) + Environment.NewLine;
            ret += "</ObjectList>" + Environment.NewLine;

            ret += "</SW.PlcType>" + Environment.NewLine;
            ret += "</Document>";

            return(ret);
        }
Esempio n. 5
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));
        }
Esempio n. 6
0
        /// <summary>
        /// Returns a <see cref="System.String" /> that represents this instance.
        /// </summary>
        /// <returns>A <see cref="System.String" /> that represents this instance.</returns>
        /// TODO Edit XML Comment Template for ToString
        public override string ToString()
        {
            var ret = "";

            ret += "<Section Name=\"" + AdjustNames.AdjustXmlStrings(InterfaceSectionName) + "\">" + Environment.NewLine;
            foreach (var member in InterfaceMember)
            {
                ret += member.ToString();
            }
            ret += "</Section>" + Environment.NewLine;

            return(ret);
        }
        /// <summary>
        /// Returns a <see cref="System.String" /> that represents this instance.
        /// </summary>
        /// <returns>A <see cref="System.String" /> that represents this instance.</returns>
        /// TODO Edit XML Comment Template for ToString
        public override string ToString()
        {
            var ret = "";
            var id  = 0;

            ret += "<Member Name=\"" + AdjustNames.AdjustXmlStrings(MemberName) + "\" Datatype=\"" + AdjustNames.AdjustXmlStrings(MemberDatatype) + "\">" + Environment.NewLine;
            if (MemberComment.CompositionNameInXml != null)
            {
                ret += MemberComment.ToString(ref id);
            }
            foreach (var member in NestedMembers)
            {
                ret += member.ToString();
            }
            ret += "</Member>" + Environment.NewLine;

            return(ret);
        }
Esempio n. 8
0
        /// <summary>
        /// Returns a <see cref="System.String" /> that represents this instance.
        /// </summary>
        /// <returns>A <see cref="System.String" /> that represents this instance.</returns>
        /// TODO Edit XML Comment Template for ToString
        public override string ToString()
        {
            var ret = "";
            var id  = 0;

            ret += "<Member Name=\"" + AdjustNames.AdjustXmlStrings(MemberName) + "\" Datatype=\"" + AdjustNames.AdjustXmlStrings(MemberDatatype) + "\">" + Environment.NewLine;
            if (MemberComment.CompositionNameInXml != null)
            {
                ret += MemberComment.ToString(ref id);
            }
            if (!string.IsNullOrEmpty(MemberDefaultValue))
            {
                ret += "<StartValue>" + AdjustNames.AdjustXmlStrings(MemberDefaultValue) + "</StartValue>" + Environment.NewLine;
            }
            ret += "</Member>" + Environment.NewLine;

            return(ret);
        }
Esempio n. 9
0
        /// <summary>
        /// Returns a <see cref="System.String" /> that represents this instance.
        /// </summary>
        /// <param name="id">The identifier.</param>
        /// <returns>A <see cref="System.String" /> that represents this instance.</returns>
        /// TODO Edit XML Comment Template for ToString
        public string ToString(ref int id)
        {
            var ret = "";

            ret += "<SW.ControllerConstant ID=\"" + id++ + "\" CompositionName=\"Constants\">" + Environment.NewLine;
            ret += "<AttributeList>" + Environment.NewLine;
            ret += "<Name>" + AdjustNames.AdjustXmlStrings(MemberName) + "</Name>" + Environment.NewLine;
            ret += "<Value>" + AdjustNames.AdjustXmlStrings(ConstantValue) + "</Value>" + Environment.NewLine;
            ret += "</AttributeList>" + Environment.NewLine;
            ret += "<LinkList>" + Environment.NewLine;
            ret += "<DataType TargetID=\"@OpenLink\">" + Environment.NewLine;
            ret += "<Name>" + AdjustNames.AdjustXmlStrings(MemberDatatype) + "</Name>" + Environment.NewLine;
            ret += "</DataType>" + Environment.NewLine;
            ret += "</LinkList>" + Environment.NewLine;
            ret += "<ObjectList>" + Environment.NewLine;
            ret += MemberComment.ToString(ref id);
            ret += "</ObjectList>" + Environment.NewLine;
            ret += "</SW.ControllerConstant>" + Environment.NewLine;

            return(ret);
        }
        /// <summary>
        /// Returns a <see cref="System.String" /> that represents this instance.
        /// </summary>
        /// <returns>A <see cref="System.String" /> that represents this instance.</returns>
        /// TODO Edit XML Comment Template for ToString
        public override string ToString()
        {
            var ret = "";
            var id  = 0;

            ret += "<?xml version=\"1.0\" encoding=\"utf-8\"?>" + Environment.NewLine;
            ret += "<Document>" + Environment.NewLine;
            ret += "<SW.DataBlock ID=\"" + id++ + "\">" + Environment.NewLine;
            ret += "<AttributeList>" + Environment.NewLine;
            ret += "<AutoNumber>" + AdjustNames.AdjustXmlStrings(BlockAutoNumber) + "</AutoNumber>" + Environment.NewLine;
            ret += "<DownloadWithoutReinit>" + AdjustNames.AdjustXmlStrings(DownloadWithoutReinit) + "</DownloadWithoutReinit>" + Environment.NewLine;
            ret += "<DatablockType>" + AdjustNames.AdjustXmlStrings(DbType.ToString()) + "</DatablockType>" + Environment.NewLine;
            ret += "<HeaderAuthor>" + AdjustNames.AdjustXmlStrings(BlockAuthor) + "</HeaderAuthor>" + Environment.NewLine;
            ret += "<HeaderFamily>" + AdjustNames.AdjustXmlStrings(BlockFamily) + "</HeaderFamily>" + Environment.NewLine;
            ret += "<HeaderName>" + AdjustNames.AdjustXmlStrings(BlockUserId) + "</HeaderName>" + Environment.NewLine;
            ret += "<HeaderVersion>" + AdjustNames.AdjustXmlStrings(BlockVersion) + "</HeaderVersion>" + Environment.NewLine;
            ret += "<InstanceOfName>" + AdjustNames.AdjustXmlStrings(InstanceOfName) + "</InstanceOfName>" + Environment.NewLine;
            ret += BlockInterface.ToString();
            ret += "<IsOnlyStoredInLoadMemory>" + AdjustNames.AdjustXmlStrings(IsOnlyStoredInLoadMemory) + "</IsOnlyStoredInLoadMemory>" + Environment.NewLine;
            ret += "<IsRetainMemResEnabled>" + AdjustNames.AdjustXmlStrings(IsRetainMemResEnabled) + "</IsRetainMemResEnabled>" + Environment.NewLine;
            ret += "<IsWriteProtectedInAS>" + AdjustNames.AdjustXmlStrings(IsWriteProtectedInAs) + "</IsWriteProtectedInAS>" + Environment.NewLine;
            ret += "<MemoryLayout>" + AdjustNames.AdjustXmlStrings(BlockMemoryLayout) + "</MemoryLayout>" + Environment.NewLine;
            ret += "<MemoryReserve>" + AdjustNames.AdjustXmlStrings(MemoryReserve) + "</MemoryReserve>" + Environment.NewLine;
            ret += "<Name>" + AdjustNames.AdjustXmlStrings(Name) + "</Name>" + Environment.NewLine;
            ret += "<Number>" + BlockNumber + "</Number>" + Environment.NewLine;
            ret += "<ProgrammingLanguage>DB</ProgrammingLanguage>" + Environment.NewLine;
            ret += "<Type>DB</Type>" + Environment.NewLine;
            ret += "</AttributeList>" + Environment.NewLine;
            ret += "<ObjectList>" + Environment.NewLine;
            ret += BlockComment.ToString(ref id);
            ret += BlockTitle.ToString(ref id);
            ret += "</ObjectList>" + Environment.NewLine;
            ret += "</SW.DataBlock>" + Environment.NewLine;
            ret += "</Document>" + Environment.NewLine;
            return(ret);
        }
Esempio n. 11
0
        /// <summary>
        /// Exports the given object with the give options to the defined path.
        /// </summary>
        /// <param name="exportItem">Object to export</param>
        /// <param name="exportOption">Export options</param>
        /// <param name="exportPath">Folder path in which to export</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 ExportItem(IEngineeringObject exportItem, ExportOptions exportOption, string exportPath)
        {
            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 is PlcBlock)
            {
                var    block     = exportItem as PlcBlock;
                string blockName = GetObjectName(exportItem);
                if (block.ProgrammingLanguage == ProgrammingLanguage.ProDiag || block.ProgrammingLanguage == ProgrammingLanguage.ProDiag_OB || block.ProgrammingLanguage == ProgrammingLanguage.SCL)
                {
                    return(null);
                }
                if (block.IsConsistent)
                {
                    blockName = XmlParser.RemoveWindowsUnallowedChars(blockName);

                    filePath = Path.Combine(filePath, blockName + ".xml");

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

                    (exportItem as PlcBlock).Export(new FileInfo(filePath), exportOption);

                    return(filePath);
                }
                else
                {
                    MessageBox.Show("Block: " + blockName + " is inconsistent! It will not be exported.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return(null);
                }
            }

            if (exportItem is PlcTagTable || exportItem is PlcType || exportItem is ScreenOverview || exportItem is ScreenGlobalElements ||
                exportItem is Screen || exportItem is TagTable || exportItem is Connection || exportItem is GraphicList ||
                exportItem is TextList || exportItem is Cycle || exportItem is MultiLingualGraphic || exportItem is ScreenTemplate ||
                exportItem is VBScript || exportItem is ScreenPopup || exportItem is ScreenSlidein)
            {
                Directory.CreateDirectory(filePath);
                filePath = Path.Combine(filePath, AdjustNames.AdjustFileName(GetObjectName(exportItem)) + ".xml");
                File.Delete(filePath);
                var parameter = new Dictionary <Type, object>();
                parameter.Add(typeof(FileInfo), new FileInfo(filePath));
                parameter.Add(typeof(ExportOptions), exportOption);
                exportItem.Invoke("Export", parameter);
                return(filePath);
            }

            if (exportItem is PlcExternalSource)
            {
                //Directory.CreateDirectory(filePath);
                //filePath = Path.Combine(filePath, AdjustNames.AdjustFileName(GetObjectName(exportItem)));
                //File.Delete(filePath);
                //File.Create(filePath);
                //return filePath;
            }
            return(null);
        }