예제 #1
0
        /// <summary>
        /// Exports the Material Definition Properties to an xml file
        /// </summary>
        /// <param name="filename">The filename to write to</param>
        public void ExportProperties(string filename)
        {
            System.Xml.XmlWriterSettings xws = new System.Xml.XmlWriterSettings();
            xws.CloseOutput = true;
            xws.Indent      = true;
            xws.Encoding    = System.Text.Encoding.UTF8;
            System.Xml.XmlWriter xw = System.Xml.XmlWriter.Create(filename, xws);

            try
            {
                xw.WriteStartElement("materialDefinition");
                xw.WriteComment("Source: " + this.Parent.FileDescriptor.ExportFileName);
                xw.WriteComment("Block name: " + this.BlockName);
                xw.WriteComment("File description: " + this.FileDescription);
                xw.WriteComment("Material Type: " + this.MatterialType);
                foreach (MaterialDefinitionProperty p in this.properties)
                {
                    xw.WriteStartElement("materialDefinitionProperty");
                    xw.WriteAttributeString("name", p.Name);
                    xw.WriteValue(p.Value);
                    xw.WriteEndElement();
                }
                xw.WriteEndElement();
            }
            finally { xw.Close(); xw = null; }
        }
예제 #2
0
 /// <summary>
 /// 向XML书写器输出对象数据
 /// </summary>
 /// <remarks>若设置了OwnerDocument.WriteOptions.ScriptWriteCData
 /// 则脚本代码放置在 CDATA 块中</remarks>
 /// <param name="myWriter">XML书写器</param>
 /// <returns>操作是否成功</returns>
 protected override bool InnerWrite(System.Xml.XmlWriter myWriter)
 {
     if (HTMLTextReader.isBlankString(strText))
     {
         myWriter.WriteString(" ");
     }
     else
     {
         if (myOwnerDocument.WriteOptions.ScriptWriteCData)
         {
             string vText = strText.Replace("<![CDATA[", "");
             vText = vText.Replace("]]", "");
             myWriter.WriteString("//");
             myWriter.WriteCData(vText + "//");
         }
         else
         {
             string vText = strText + " ";
             if (vText.IndexOf("--") >= 0)
             {
                 vText = "因保存需要,将所有的\"--\"转换为 \"@@\"符号\r\n" + vText.Replace("--", "@@");
             }
             myWriter.WriteComment(vText);
         }
         //myWriter.WriteString( strText );
     }
     return(true);
 }
예제 #3
0
 /// <summary>
 /// 将注释文本填写到一个XML书写器中
 /// </summary>
 /// <remarks>
 /// 若 OwnerDocument.WriteOptions.CommentOutput设置为false则不输出注释
 /// 若设置了OwnerDocument.WriteOptions.CommentOutputXSL则对象输出为
 /// [xsl:comment]对象文本[/xsl:comment]
 /// </remarks>
 /// <param name="myWriter">XML书写器</param>
 /// <returns>操作是否成功</returns>
 public override bool Write(System.Xml.XmlWriter myWriter)
 {
     if (myOwnerDocument.WriteOptions.CommentOutput)
     {
         if (strText != null && strText.Length > 0)
         {
             string vText = strText + " ";
             if (vText.IndexOf("--") >= 0)
             {
                 vText = "因保存需要,将所有的\"- -\"转换为 \"@@\"符号\r\n" + vText.Replace("--", "@@");
             }
             if (myOwnerDocument.WriteOptions.CommentOutputXSL)
             {
                 myWriter.WriteStartElement(StringConstXSLT.Comment);
                 myWriter.WriteCData(vText);
                 myWriter.WriteEndElement();
             }
             else
             {
                 myWriter.WriteComment(vText);
             }
         }
     }
     return(true);
 }
예제 #4
0
 public override void AddComments(string comments)
 {
     if (comments != null && comments.Length > 0)
     {
         output.WriteComment(comments);
     }
 }
예제 #5
0
        public void WriteParams(System.Xml.XmlWriter writer, Dictionary <HavokClassNode, int> classNodes)
        {
            writer.WriteStartElement("hkobject");
            {
                writer.WriteStartElement("hkparam");
                writer.WriteAttributeString("name", "name");
                writer.WriteString(Name);
                writer.WriteEndElement();

                HavokClassNode c = string.IsNullOrEmpty(_class) ? null : HavokNode.GetClassNode(_class);
                writer.WriteStartElement("hkparam");
                writer.WriteAttributeString("name", "class");
                writer.WriteString(c != null ? HavokXML.GetObjectName(classNodes, c) : "null");
                writer.WriteEndElement();

                HavokClassNode e = string.IsNullOrEmpty(_enum) ? null : HavokNode.GetClassNode(_enum);
                writer.WriteStartElement("hkparam");
                writer.WriteAttributeString("name", "enum");
                writer.WriteString(e != null ? HavokXML.GetObjectName(classNodes, e) : "null");
                writer.WriteEndElement();

                writer.WriteStartElement("hkparam");
                writer.WriteAttributeString("name", "type");
                string type = Type.ToString();
                if (type == "TYPE_CSTRING")
                {
                    type = "TYPE_STRINGPTR";
                }

                writer.WriteString(type);
                writer.WriteEndElement();

                writer.WriteStartElement("hkparam");
                writer.WriteAttributeString("name", "subtype");
                writer.WriteString(SubType.ToString());
                writer.WriteEndElement();

                writer.WriteStartElement("hkparam");
                writer.WriteAttributeString("name", "cArraySize");
                writer.WriteString(ArraySize.ToString(CultureInfo.InvariantCulture));
                writer.WriteEndElement();

                writer.WriteStartElement("hkparam");
                writer.WriteAttributeString("name", "flags");
                writer.WriteString(((int)Flags).ToString(CultureInfo.InvariantCulture));
                writer.WriteEndElement();

                writer.WriteStartElement("hkparam");
                writer.WriteAttributeString("name", "offset");
                writer.WriteString(OffsetInStruct.ToString(CultureInfo.InvariantCulture));
                writer.WriteEndElement();

                writer.WriteComment(" attributes SERIALIZE_IGNORED ");
            }
            writer.WriteEndElement();
        }
예제 #6
0
        private void WriteCommentBlock()
        {
            StringBuilder sb = new StringBuilder();

            foreach (var commentRow in _commentBlock)
            {
                sb.AppendLine(commentRow.Value);
            }
            _writer.WriteComment(sb.ToString());
            _commentBlock.Clear();
        }
예제 #7
0
파일: Rem.cs 프로젝트: xsharper/xsharper
 /// <summary>
 /// Write element to the output stream
 /// </summary>
 /// <param name="writer">Where to write</param>
 /// <param name="nameOverride">Local name to be used, or null if name should be retirevent from <see cref="XsTypeAttribute"/> of the type.</param>
 public override void WriteXml(System.Xml.XmlWriter writer, string nameOverride)
 {
     if (Text != null && (Text.Contains("---") || Text.IndexOfAny("<>&".ToCharArray()) != -1))
     {
         writer.WriteProcessingInstruction("rem", Text);
     }
     else
     {
         writer.WriteComment(Text);
     }
 }
예제 #8
0
        private async Task <bool> SaveData()
        {
            await Task.Factory.StartNew(() =>
            {
                try
                {
                    System.Xml.Serialization.XmlSerializer serializer = new System.Xml.Serialization.XmlSerializer(typeof(System.Collections.ObjectModel.ObservableCollection <Collector>));

                    System.Xml.XmlWriterSettings settings = new System.Xml.XmlWriterSettings();
                    settings.Encoding           = new UTF8Encoding(false, false); // no BOM in a .NET string
                    settings.Indent             = true;
                    settings.OmitXmlDeclaration = false;

                    using (System.IO.FileStream fs = System.IO.File.Open(MainViewModel.Instance.DataFileName, System.IO.FileMode.Create))
                        using (System.IO.Compression.GZipStream gzip = new System.IO.Compression.GZipStream(fs, System.IO.Compression.CompressionMode.Compress, false))
                            using (System.Xml.XmlWriter xmlWriter = System.Xml.XmlWriter.Create(gzip, settings))
                            {
                                xmlWriter.WriteComment("Список систем дистанционного съема показаний:");
                                xmlWriter.WriteComment(" * подразделение: " + MainViewModel.Instance.SelectedDepartament);
                                switch (MainViewModel.Instance.ProfileType)
                                {
                                case ProfileType.Current:
                                    xmlWriter.WriteComment(" * параметр: текущие показания");
                                    break;

                                case ProfileType.Days:
                                    xmlWriter.WriteComment(" * параметр: показания на начало суток");
                                    break;

                                case ProfileType.Months:
                                    xmlWriter.WriteComment(" * параметр: показания на начало месяца");
                                    break;
                                }
                                xmlWriter.WriteComment(" * начало периода: " + MainViewModel.Instance.StartDate.ToString("dd.MM.yyyy"));
                                xmlWriter.WriteComment(" * конец периода: " + MainViewModel.Instance.EndDate.ToString("dd.MM.yyyy"));
                                xmlWriter.WriteComment("********************************************");

                                TMP.Shared.GenericSerializer.Serialize(MainViewModel.Instance.Collectors, xmlWriter);
                            }
                }
                catch (Exception ex)
                {
                    logger.TraceEvent(System.Diagnostics.TraceEventType.Error, 0, String.Format(ERROR_MESSAGE_TO_LOG, ex.Message, ex.StackTrace));
                }
            });

            return(true);
        }
예제 #9
0
 public override void WriteParams(System.Xml.XmlWriter writer, Dictionary <HavokClassNode, int> classNodes)
 {
     foreach (ClassMemberInstanceNode i in Children)
     {
         if (!i.SerializedAsZero)
         {
             writer.WriteStartElement("hkparam");
             writer.WriteAttributeString("name", i.Name);
             i.WriteParams(writer, classNodes);
             writer.WriteEndElement();
         }
         else
         {
             writer.WriteComment($" {i.Name} SERIALIZE_IGNORED ");
         }
     }
 }
예제 #10
0
        public override void WriteParams(System.Xml.XmlWriter writer, Dictionary <HavokClassNode, int> classNodes)
        {
            writer.WriteStartElement("hkparam");
            writer.WriteAttributeString("name", "name");
            writer.WriteString(Name);
            writer.WriteEndElement();

            writer.WriteStartElement("hkparam");
            writer.WriteAttributeString("name", "parent");
            writer.WriteString(_parent is HavokClassNode
                ? HavokXML.GetObjectName(classNodes, _parent as HavokClassNode)
                : "null");
            writer.WriteEndElement();

            writer.WriteStartElement("hkparam");
            writer.WriteAttributeString("name", "objectSize");
            writer.WriteString(Size.ToString(CultureInfo.InvariantCulture));
            writer.WriteEndElement();

            writer.WriteStartElement("hkparam");
            writer.WriteAttributeString("name", "numImplementedInterfaces");
            writer.WriteString(InterfaceCount.ToString(CultureInfo.InvariantCulture));
            writer.WriteEndElement();

            ResourceNode enums = FindChild("Enums", false);

            writer.WriteStartElement("hkparam");
            writer.WriteAttributeString("name", "declaredEnums");
            writer.WriteAttributeString("numelements", enums == null ? "0" : enums.Children.Count.ToString());
            {
                if (enums != null)
                {
                    foreach (hkClassEnumNode e in enums.Children)
                    {
                        e.WriteParams(writer, classNodes);
                    }
                }
            }
            writer.WriteEndElement();

            ResourceNode members = FindChild("Members", false);

            writer.WriteStartElement("hkparam");
            writer.WriteAttributeString("name", "declaredMembers");
            writer.WriteAttributeString("numelements", members == null ? "0" : members.Children.Count.ToString());
            {
                if (members != null)
                {
                    foreach (hkClassMemberNode e in members.Children)
                    {
                        e.WriteParams(writer, classNodes);
                    }
                }
            }
            writer.WriteEndElement();

            writer.WriteComment(" defaults SERIALIZE_IGNORED ");
            writer.WriteComment(" attributes SERIALIZE_IGNORED ");

            writer.WriteStartElement("hkparam");
            writer.WriteAttributeString("name", "flags");
            writer.WriteString(Flags.ToString(CultureInfo.InvariantCulture));
            writer.WriteEndElement();

            writer.WriteStartElement("hkparam");
            writer.WriteAttributeString("name", "describedVersion");
            writer.WriteString(Version.ToString(CultureInfo.InvariantCulture));
            writer.WriteEndElement();
        }
        public static void XmlReaderClone(System.Xml.XmlReader reader, System.Xml.XmlWriter writer)
        {
            if (reader == null)
            {
                throw new ArgumentNullException("System.Xml.XmlReader");
            }

            if (writer == null)
            {
                throw new ArgumentNullException("System.Xml.XmlWriter");
            }

            switch (reader.NodeType)
            {
            case System.Xml.XmlNodeType.Element:

                writer.WriteStartElement(reader.Prefix, reader.LocalName, reader.NamespaceURI);

                writer.WriteAttributes(reader, true);

                if (reader.IsEmptyElement)
                {
                    writer.WriteEndElement();
                }

                break;

            case System.Xml.XmlNodeType.Text:

                writer.WriteString(reader.Value);

                break;

            case System.Xml.XmlNodeType.Whitespace:

            case System.Xml.XmlNodeType.SignificantWhitespace:

                writer.WriteWhitespace(reader.Value);

                break;

            case System.Xml.XmlNodeType.CDATA:

                writer.WriteCData(reader.Value);

                break;

            case System.Xml.XmlNodeType.EntityReference:

                writer.WriteEntityRef(reader.Name);

                break;

            case System.Xml.XmlNodeType.XmlDeclaration:

            case System.Xml.XmlNodeType.ProcessingInstruction:

                writer.WriteProcessingInstruction(reader.Name, reader.Value);

                break;

            case System.Xml.XmlNodeType.DocumentType:

                writer.WriteDocType(reader.Name, reader.GetAttribute("PUBLIC"), reader.GetAttribute("SYSTEM"), reader.Value);

                break;

            case System.Xml.XmlNodeType.Comment:

                writer.WriteComment(reader.Value);

                break;

            case System.Xml.XmlNodeType.EndElement:

                writer.WriteFullEndElement();

                break;
            }

            if (reader.Read())
            {
                XmlReaderClone(reader, writer);
            }
        }