Esempio n. 1
0
        /// <summary>
        /// Writes full model into output writer as STEP21 file
        /// </summary>
        /// <param name="model">Model to be serialized</param>
        /// <param name="output">Output writer</param>
        /// <param name="metadata">Metadata to be used for serialization</param>
        /// <param name="map">Optional map can be used to map occurrences in the file</param>
        private void Write(TextWriter output)
        {
            ExpressMetaData metadata       = Metadata;
            var             header         = Header ?? new StepFileHeader(StepFileHeader.HeaderCreationMode.InitWithXbimDefaults, this);
            string          fallBackSchema = EntityFactory.SchemasIds.FirstOrDefault();

            if (!header.FileSchema.Schemas.Any())
            {
                foreach (var id in EntityFactory.SchemasIds)
                {
                    header.FileSchema.Schemas.Add(id);
                }
            }

            Part21Writer.WriteHeader(header, output, fallBackSchema);

            foreach (var entity in Instances)
            {
                if (_comments.TryGetValue(entity.EntityLabel, out string comment))
                {
                    comment = comment.Trim('\r', '\n');
                    comment = comment.Replace("\r\n", "\r\n* ");
                    output.WriteLine();
                    output.WriteLine($"/**");
                    output.WriteLine("* " + comment);
                    output.WriteLine($"* {GetMetaComment(entity)}*/");
                }
                Part21Writer.WriteEntity(entity, output, metadata, null);
                output.WriteLine();
            }
            Part21Writer.WriteFooter(output);
        }
Esempio n. 2
0
        private string GetEntityString()
        {
            Part21Writer.WriteEntity(_entity, _writer, _entity.Model.Metadata, _dummy);
            var value = _writer.ToString();

            ClearWriter();
            return(value);
        }
Esempio n. 3
0
        public override string ToString()
        {
            ExpressMetaData md = null;

            if (Model != null)
            {
                md = Model.Metadata;
            }
            else
            {
                md = ExpressMetaData.GetMetadata(GetType().Module);
            }

            using (var sw = new StringWriter())
            {
                Part21Writer.WriteEntity(this, sw, md);
                return(sw.ToString());
            }
        }
        private static void WriteEntityRecursive(IPersistEntity entity, ExpressMetaData metadata, TextWriter writer, HashSet <int> written)
        {
            if (written.Contains(entity.EntityLabel))
            {
                return;
            }

            Part21Writer.WriteEntity(entity, writer, metadata);
            written.Add(entity.EntityLabel);

            var references = entity as IContainsEntityReferences;

            if (references == null)
            {
                return;
            }

            foreach (var item in references.References)
            {
                WriteEntityRecursive(item, metadata, writer, written);
            }
        }