Beispiel #1
0
        private void WriteEntity(SEntity o)
        {
            // sanity check
            if (this.m_indent > 100)
            {
                return;
            }

            if (o == null)
            {
                return;
            }

            Type t = o.GetType();

            string hyperlink = "../../schema/" + t.Namespace.ToLower() + "/lexical/" + t.Name.ToLower() + ".htm";

            this.WriteStartElementEntity(t.Name, hyperlink);
            bool close = this.WriteEntityAttributes(o);

            if (close)
            {
                this.WriteEndElementEntity(t.Name);
            }
            else
            {
                this.WriteCloseElementEntity();
            }
        }
Beispiel #2
0
        private void treeViewTemplate_AfterSelect(object sender, TreeViewEventArgs e)
        {
            this.m_attribute = null;
            this.m_selection = e.Node.Tag as SEntity;
            UpdateCommands();

            if (this.SelectionChanged != null)
            {
                this.SelectionChanged(this, EventArgs.Empty);
            }
        }
Beispiel #3
0
        private void CtlConcept_MouseMove(object sender, MouseEventArgs e)
        {
            Point pt = e.Location;

            pt.X -= this.AutoScrollPosition.X;
            pt.Y -= this.AutoScrollPosition.Y;

            DocAttribute attr;

            this.m_highlight = Pick(pt, out this.m_iHighlight, out attr, out this.m_rcHighlight);
            this.Invalidate();
        }
Beispiel #4
0
        private void WriteReference(XmlWriter writer, SEntity r)
        {
            writer.WriteStartElement(r.GetType().Name);

            writer.WriteStartAttribute("xsi", "nil", null);
            writer.WriteValue(true);
            writer.WriteEndAttribute();

            writer.WriteStartAttribute("ref");
            writer.WriteValue("i" + r.OID.ToString());
            writer.WriteEndAttribute();

            writer.WriteEndElement();
        }
Beispiel #5
0
        private void CtlConcept_MouseDown(object sender, MouseEventArgs e)
        {
            Point pt = e.Location;

            pt.X -= this.AutoScrollPosition.X;
            pt.Y -= this.AutoScrollPosition.Y;

            this.m_selection = Pick(pt, out this.m_iSelection, out this.m_attribute, out this.m_rcSelection);
            this.Invalidate();

            if (this.SelectionChanged != null)
            {
                this.SelectionChanged(this, EventArgs.Empty);
            }
        }
Beispiel #6
0
        public void Save()
        {
            // pass 1: (first time ever encountering for serialization) -- determine which entities require IDs -- use a null stream
            this.m_nextID = 0;
            this.m_indent = 0;
            this.m_writer = new StreamWriter(Stream.Null);
            this.m_saved  = new HashSet <SEntity>();
            this.m_idmap  = new Dictionary <SEntity, long>();
            this.m_queue  = new Queue <SEntity>();
            this.m_queue.Enqueue(this.m_instance);
            while (this.m_queue.Count > 0)
            {
                SEntity ent = this.m_queue.Dequeue();
                if (!this.m_saved.Contains(ent))
                {
                    this.WriteEntity(ent);
                }
            }

            // pass 2: write to file -- clear save map; retain ID map
            this.m_saved.Clear();
            this.m_indent = 0;
            this.m_writer = new StreamWriter(this.m_stream);

            this.WriteHeader();

            this.m_queue.Enqueue(this.m_instance);
            while (this.m_queue.Count > 0)
            {
                SEntity ent = this.m_queue.Dequeue();
                if (!this.m_saved.Contains(ent))
                {
                    this.WriteEntity(ent);
                }
            }

            this.WriteFooter();

            this.m_writer.Flush();
        }
Beispiel #7
0
        public string FormatData(DocPublication docPublication, DocExchangeDefinition docExchange, Dictionary <string, DocObject> map, Dictionary <long, SEntity> instances)
        {
            System.IO.MemoryStream stream = new System.IO.MemoryStream();
            if (instances.Count > 0)
            {
                SEntity rootproject = null;
                foreach (SEntity ent in instances.Values)
                {
                    if (ent.GetType().Name.Equals("IfcProject"))
                    {
                        rootproject = ent;
                        break;
                    }
                }

                if (rootproject != null)
                {
                    Type type = rootproject.GetType();

                    DataContractJsonSerializer contract = new DataContractJsonSerializer(type);

                    try
                    {
                        contract.WriteObject(stream, rootproject);
                    }
                    catch (Exception xx)
                    {
                        //...
                        xx.ToString();
                    }
                }
            }

            stream.Position = 0;
            System.IO.TextReader reader = new System.IO.StreamReader(stream);
            string content = reader.ReadToEnd();

            return(content);
        }
Beispiel #8
0
        private void DrawObjectBorder(Graphics g, SEntity obj, Pen pen)
        {
            if (obj is DocDefinition && ((DocDefinition)obj).DiagramRectangle != null)
            {
                DocRectangle docRect = ((DocDefinition)obj).DiagramRectangle;

                Rectangle rc = new Rectangle(
                    (int)(docRect.X * Factor),
                    (int)(docRect.Y * Factor),
                    (int)(docRect.Width * Factor),
                    (int)(docRect.Height * Factor));
                rc.Inflate(-2, -2);

                g.DrawRectangle(pen, rc);
            }
            else if (obj is DocAttribute)
            {
                DocAttribute docAttr = (DocAttribute)obj;
                if (docAttr.DiagramLine != null)
                {
                    for (int i = 0; i < docAttr.DiagramLine.Count - 1; i++)
                    {
                        g.DrawLine(pen,
                                   new Point((int)(docAttr.DiagramLine[i].X * Factor), (int)(docAttr.DiagramLine[i].Y * Factor)),
                                   new Point((int)(docAttr.DiagramLine[i + 1].X * Factor), (int)(docAttr.DiagramLine[i + 1].Y * Factor)));
                    }
                }
            }
            else if (obj is DocLine)
            {
                // tree point
                DocLine   docLine  = (DocLine)obj;
                DocPoint  docPoint = docLine.DiagramLine[docLine.DiagramLine.Count - 1];
                Rectangle rc       = new Rectangle((int)(docPoint.X * Factor), (int)(docPoint.Y * Factor), 0, 0);
                rc.Inflate(6, 6);
                g.DrawEllipse(pen, rc);
            }
        }
Beispiel #9
0
        /// <summary>
        /// Loads all instances from the database
        /// </summary>
        public void Load()
        {
            // first pass: load all entities and non-list attributes
            foreach (Type t in this.m_typemap.Values)
            {
                StringBuilder sb = new StringBuilder();
                sb.Append("SELECT * FROM ");
                sb.Append(t.Name);

                IList <FieldInfo> fields = SEntity.GetFieldsOrdered(t);

                // load scalar attributes
                using (OleDbCommand cmd = this.m_connection.CreateCommand())
                {
                    cmd.CommandText = sb.ToString();
                    using (OleDbDataReader reader = cmd.ExecuteReader())
                    {
                        while (reader.Read())
                        {
                            int oid = reader.GetInt32(0);

                            SEntity entity = null;
                            if (!this.Instances.TryGetValue(oid, out entity))
                            {
                                entity          = (SEntity)System.Runtime.Serialization.FormatterServices.GetUninitializedObject(t);
                                entity.Existing = true;
                                entity.OID      = oid;
                                this.Instances.Add(entity.OID, entity);

                                if (entity.OID > m_lastOID)
                                {
                                    this.m_lastOID = entity.OID;
                                }
                            }

                            int index = 0;
                            foreach (FieldInfo f in fields)
                            {
                                if (!f.FieldType.IsGenericType)
                                {
                                    // non-list attribute
                                    index++;
                                    object value = reader.GetValue(index);
                                    if (value != null && !(value is DBNull))
                                    {
                                        if (f.FieldType.IsEnum)
                                        {
                                            object eval = Enum.Parse(f.FieldType, value.ToString());
                                            f.SetValue(entity, eval);
                                        }
                                        else if (typeof(SEntity).IsAssignableFrom(f.FieldType))
                                        {
                                            if (value is Int32)
                                            {
                                                int     ival = (int)value;
                                                SEntity eval = null;
                                                if (this.Instances.TryGetValue(ival, out eval))
                                                {
                                                    f.SetValue(entity, eval);
                                                }
                                            }
                                        }
                                        else if (typeof(byte[]) == f.FieldType)
                                        {
                                            string strval = (string)value;
                                            int    len    = strval.Length / 2;

                                            Byte[] valuevector = new byte[len];
                                            for (int i = 0; i < len; i++)
                                            {
                                                char hi = strval[i * 2 + 0];
                                                char lo = strval[i * 2 + 1];

                                                byte val = (byte)(
                                                    ((hi >= 'A' ? +(int)(hi - 'A' + 10) : (int)(hi - '0')) << 4) +
                                                    ((lo >= 'A' ? +(int)(lo - 'A' + 10) : (int)(lo - '0'))));

                                                valuevector[i] = val;
                                            }

                                            f.SetValue(entity, valuevector);
                                        }
                                        else
                                        {
                                            f.SetValue(entity, value);
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }

            // second pass: load lists (now that all entities are loaded)
            foreach (Type t in this.m_typemap.Values)
            {
                StringBuilder sb = new StringBuilder();
                sb.Append("SELECT * FROM ");
                sb.Append(t.Name);
                sb.Append(";");

                IList <FieldInfo> fields = SEntity.GetFieldsOrdered(t);

                // load vector attributes
                using (OleDbCommand cmd = this.m_connection.CreateCommand())
                {
                    cmd.CommandText = sb.ToString();
                    using (OleDbDataReader reader = cmd.ExecuteReader())
                    {
                        while (reader.Read())
                        {
                            long    oid    = (long)reader.GetInt32(0);
                            SEntity entity = this.Instances[oid];

                            foreach (FieldInfo f in fields)
                            {
                                if (f.FieldType.IsGenericType)
                                {
                                    // list
                                    System.Collections.IList list = (System.Collections.IList)f.GetValue(entity);
                                    if (list == null)
                                    {
                                        list = (System.Collections.IList)Activator.CreateInstance(f.FieldType);
                                        f.SetValue(entity, list);
                                    }

                                    using (OleDbCommand cmdList = this.m_connection.CreateCommand())
                                    {
                                        StringBuilder sbl = new StringBuilder();
                                        sbl.Append("SELECT * FROM ");
                                        sbl.Append(t.Name);
                                        sbl.Append("_");
                                        sbl.Append(f.Name);
                                        sbl.Append(" WHERE source=");
                                        sbl.Append(entity.OID.ToString());
                                        sbl.Append(" ORDER BY sequence;");
                                        cmdList.CommandText = sbl.ToString();
                                        using (OleDbDataReader readerList = cmdList.ExecuteReader())
                                        {
                                            while (readerList.Read())
                                            {
                                                long    refid  = (long)readerList.GetInt32(2);
                                                SEntity target = this.Instances[refid];
                                                list.Add(target);
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
Beispiel #10
0
        /// <summary>
        /// Creates database table(s) for type
        /// </summary>
        /// <param name="t"></param>
        public void InitType(Type t)
        {
            StringBuilder sb = new StringBuilder();

            sb.Append("CREATE TABLE ");
            sb.Append(t.Name);
            sb.Append(" (oid INTEGER");
            IList <FieldInfo> fields = SEntity.GetFieldsOrdered(t);

            foreach (FieldInfo f in fields)
            {
                if (!f.FieldType.IsGenericType)                 // don't deal with lists
                {
                    sb.Append(", ");

                    sb.Append(f.Name);
                    sb.Append(" ");

                    if (typeof(SEntity).IsAssignableFrom(f.FieldType))
                    {
                        sb.Append(" INTEGER");                         // oid
                    }
                    else if (f.FieldType.IsEnum)
                    {
                        sb.Append(" VARCHAR");
                    }
                    else if (typeof(string) == f.FieldType)
                    {
                        //if (f.Name.Equals("_Documentation") || f.Name.Equals("_Description") || f.Name.Equals("_Expression"))
                        if (f.Name.Equals("_Name"))
                        {
                            // for name, indexable
                            sb.Append(" VARCHAR");
                        }
                        else
                        {
                            // all others unlimited text
                            sb.Append(" TEXT");
                        }
                    }
                    else if (typeof(bool) == f.FieldType)
                    {
                        sb.Append(" BIT");
                    }
                    else if (typeof(int) == f.FieldType)
                    {
                        sb.Append(" INTEGER");
                    }
                    else if (typeof(double) == f.FieldType)
                    {
                        sb.Append(" FLOAT");
                    }
                    else if (typeof(byte[]) == f.FieldType)
                    {
                        sb.Append(" TEXT");
                    }
                    else
                    {
                        System.Diagnostics.Debug.WriteLine("FormatMDB::InitType() - incompatible field type");
                    }
                }
            }
            sb.Append(");");
            Execute(sb.ToString());

            // populate relationships for LISTs
            foreach (FieldInfo f in fields)
            {
                if (f.FieldType.IsGenericType && f.FieldType.GetGenericTypeDefinition() == typeof(List <>))
                {
                    sb = new StringBuilder();
                    sb.Append("CREATE TABLE ");
                    sb.Append(t.Name);
                    sb.Append("_");
                    sb.Append(f.Name);
                    sb.Append(" (source INTEGER, sequence INTEGER, target INTEGER);");
                    Execute(sb.ToString());
                }
            }
        }
Beispiel #11
0
 public void Register(SEntity entity)
 {
     this.m_lastOID++;
     entity.OID = this.m_lastOID;
     this.Instances.Add(this.m_lastOID, entity);
 }
Beispiel #12
0
        [DataMember(Order = 3)] private string _Description; // IfcText? : simplify

        public IfcRoot()
        {
            this._GlobalId = SGuid.New().ToString();
            this._OwnerHistory = null;
        }
Beispiel #13
0
        /// <summary>
        /// Gets value referenced by path.
        /// </summary>
        /// <param name="target">The relative object to retrieve the value.</param>
        /// <param name="parameters">Optional parameters for substitution.</param>
        /// <returns>The value on the object along the expression path.</returns>
        public object GetValue(SEntity target, Dictionary<string, SEntity> parameters)
        {
            if (target == null)
                throw new ArgumentNullException("target");

            if (this.m_type == null)
            {
                return target.GetType();
            }

            if (!this.m_type.IsInstanceOfType(target))
                return null; // doesn't apply

            if (this.m_property == null)
            {
                return target; // for general case, if no attribute specified, then return object itself
            }

            object value = null;

            if (this.m_property.PropertyType.IsGenericType &&
                typeof(System.Collections.IList).IsAssignableFrom(this.m_property.PropertyType))// &&
               // (typeof(SEntity).IsAssignableFrom(this.m_property.PropertyType.GetGenericArguments()[0]) || this.m_property.PropertyType.GetGenericArguments()[0].IsInterface))
            {
                System.Collections.IList list = (System.Collections.IList)this.m_property.GetValue(target, null);

                // if expecting array, then return it.
                if (this.m_vector || (this.m_identifier == null && this.m_inner == null))
                {
                    return list;
                }
                else if (this.m_identifier != null && this.m_identifier.StartsWith("@") && parameters == null)
                {
                    // return filtered list based on expected type -- may be none if no compatible types -- e.g. COBie properties only return IfcPropertyEnumeratedValue
                    if (this.InnerPath != null && this.InnerPath.Type != null)
                    {
                        List<SEntity> listFilter = null;
                        foreach (SEntity ent in list)
                        {
                            if (this.InnerPath.Type.IsInstanceOfType(ent))
                            {
                                if (listFilter == null)
                                {
                                    listFilter = new List<SEntity>();
                                }
                                listFilter.Add(ent);
                            }
                        }

                        return listFilter;
                    }
                    else
                    {
                        return list;
                    }
                }

                if (list != null)
                {
                    int listindex = 0; // identify by 1-based numeric index within list
                    if(!String.IsNullOrEmpty(this.m_identifier) && Int32.TryParse(this.m_identifier, out listindex) && listindex > 0 && listindex <= list.Count)
                    {
                        object eachelem = list[listindex - 1];

                        if (this.m_inner != null && eachelem is SEntity)
                        {
                            object eachvalue = this.m_inner.GetValue((SEntity)eachelem, parameters);
                            if (eachvalue != null)
                            {
                                return eachvalue;
                            }
                        }
                        else
                        {
                            return eachelem;
                        }                        
                    }

                    foreach (object eachelem in list)
                    {
                        // derived class may have its own specific property (e.g. IfcSIUnit, IfcConversionBasedUnit)
                        if (!String.IsNullOrEmpty(this.m_identifier))
                        {
                            Type eachtype = eachelem.GetType();

                            // special cases for properties and quantities
                            if (eachtype.Name.Equals("IfcRelDefinesByProperties"))
                            {
                                FieldInfo fieldRelatingPropertyDefinition = eachtype.GetField("RelatingPropertyDefinition");
                                object ifcPropertySet = fieldRelatingPropertyDefinition.GetValue(eachelem);
                                if (ifcPropertySet != null)
                                {
                                    Type typePropertySet = ifcPropertySet.GetType();
                                    FieldInfo fieldName = typePropertySet.GetField("Name");
                                    object ifcLabel = fieldName.GetValue(ifcPropertySet);
                                    if (ifcLabel != null)
                                    {
                                        FieldInfo fieldValue = ifcLabel.GetType().GetField("Value");
                                        if (fieldValue != null)
                                        {
                                            string sval = fieldValue.GetValue(ifcLabel) as string;
                                            if (this.m_identifier.Equals(sval))
                                            {
                                                // matches!
                                                if (this.m_inner != null)
                                                {
                                                    object eachvalue = this.m_inner.GetValue((SEntity)eachelem, parameters);
                                                    if (eachvalue != null)
                                                    {
                                                        return eachvalue;
                                                    }
                                                }
                                                else
                                                {
                                                    return eachelem;
                                                }

                                            }
                                        }
                                    }
                                }
                            }
                            else
                            {
                                // fall back on Name field for properties or quantities
                                FieldInfo fieldName = eachtype.GetField("Name");
                                if (fieldName != null)
                                {
                                    object ifcLabel = fieldName.GetValue(eachelem);
                                    if (ifcLabel != null)
                                    {
                                        FieldInfo fieldValue = ifcLabel.GetType().GetField("Value");
                                        if (fieldValue != null)
                                        {
                                            string sval = fieldValue.GetValue(ifcLabel) as string;
                                            if (this.m_identifier.Equals(sval))
                                            {
                                                // matches!
                                                if (this.m_inner != null)
                                                {
                                                    object eachvalue = this.m_inner.GetValue((SEntity)eachelem, parameters);
                                                    if (eachvalue != null)
                                                    {
                                                        return eachvalue;
                                                    }
                                                }
                                                else
                                                {
                                                    return eachelem;
                                                }

                                            }
                                        }
                                    }
                                }
                            }
                        }
                        else
                        {
                            // use first non-null item within inner reference
                            if (this.m_inner != null && eachelem is SEntity)
                            {
                                object eachvalue = this.m_inner.GetValue((SEntity)eachelem, parameters);
                                if (eachvalue != null)
                                {
                                    return eachvalue;
                                }
                            }
                            else
                            {
                                return eachelem;
                            }
                        }
                    }

                    return null; // not found
                }



            }
            else if (this.m_inner != null)
            {
                value = this.m_property.GetValue(target, null);
                if (value is SEntity)
                {
                    value = this.m_inner.GetValue((SEntity)value, parameters);

                    if (this.m_identifier != null && value != null)
                    {
                        // qualify the value
                        Type eachtype = value.GetType();
                        DefaultMemberAttribute[] attrs = (DefaultMemberAttribute[])eachtype.GetCustomAttributes(typeof(DefaultMemberAttribute), true);
                        PropertyInfo propElem = null;
                        if (attrs.Length > 0)
                        {
                            propElem = eachtype.GetProperty(attrs[0].MemberName);
                        }
                        else
                        {
                            propElem = eachtype.GetProperty("Name");
                        }

                        if (propElem != null)
                        {
                            object name = propElem.GetValue(value, null);
                            if (name == null || !this.m_identifier.Equals(name.ToString()))
                            {
                                return null;
                            }
                        }
                    }
                }
            }
            else
            {
                value = this.m_property.GetValue(target, null);
            }

            return value;
        }
Beispiel #14
0
        private SEntity Pick(Point pt, out int iAttr, out DocAttribute docAttribute, out Rectangle rc)
        {
            docAttribute = null;
            iAttr        = -1;
            rc           = new Rectangle();

            foreach (Rectangle rect in this.m_hitmap.Keys)
            {
                if (rect.Contains(pt))
                {
                    rc    = rect;
                    iAttr = (pt.Y - rc.Top) / FormatPNG.CY - 1;

                    SEntity sel = this.m_hitmap[rc];

                    if (sel is DocTemplateDefinition)
                    {
                        return(sel);
                    }
                    else
                    {
                        DocModelRuleEntity ruleEntity = sel as DocModelRuleEntity;

                        DocEntity docEntity = null;
                        if (ruleEntity != null)
                        {
                            DocObject docObjRef = null;

                            if (this.m_template != null && !String.IsNullOrEmpty(this.m_template.Code))
                            {
                                foreach (DocSection docSection in this.m_project.Sections)
                                {
                                    foreach (DocSchema docSchema in docSection.Schemas)
                                    {
                                        if (docSchema.Name.Equals(this.m_template.Code, StringComparison.OrdinalIgnoreCase))
                                        {
                                            docObjRef = docSchema.GetDefinition(ruleEntity.Name);
                                            break;
                                        }
                                    }
                                }
                            }

                            if (docObjRef == null)
                            {
                                docObjRef = this.m_project.GetDefinition(ruleEntity.Name);
                            }

                            if (docObjRef is DocEntity)
                            {
                                docEntity = (DocEntity)docObjRef;
                                List <DocAttribute> listAttr = new List <DocAttribute>();
                                FormatPNG.BuildAttributeList(docEntity, listAttr, this.m_project);

                                if (iAttr >= 0 && iAttr < listAttr.Count)
                                {
                                    docAttribute = listAttr[iAttr];
                                    foreach (DocModelRule ruleAttr in ruleEntity.Rules)
                                    {
                                        if (ruleAttr is DocModelRuleAttribute && ruleAttr.Name.Equals(docAttribute.Name))
                                        {
                                            return(ruleAttr);
                                        }
                                    }
                                }
                            }
                        }
                        else if (this.m_template != null)
                        {
                            docEntity = this.m_project.GetDefinition(this.m_template.Type) as DocEntity;
                            List <DocAttribute> listAttr = new List <DocAttribute>();
                            FormatPNG.BuildAttributeList(docEntity, listAttr, this.m_project);

                            if (iAttr >= 0 && iAttr < listAttr.Count)
                            {
                                docAttribute = listAttr[iAttr];
                                if (this.m_template.Rules != null)
                                {
                                    foreach (DocModelRule ruleAttr in this.m_template.Rules)
                                    {
                                        if (ruleAttr is DocModelRuleAttribute && ruleAttr.Name.Equals(docAttribute.Name))
                                        {
                                            return(ruleAttr);
                                        }
                                    }
                                }
                            }
                        }
                    }

                    return(sel);
                }
            }

            return(null);
        }
Beispiel #15
0
        private void ProcessAttribute(
            SEntity oneEntity,
            string AttributeName)
        {
            SAttribute satt = new SAttribute(AttributeName);
            SToken oneToken = SLexer.Tokenizer(_dataStream);
            if (oneToken.TokenType != STokenType.COLON)
            { throw new Exception("Error in attribute : " + SLexer.CurrentRow + " : " + SLexer.CurrentColumn); }

            satt.Type = ProcessParameter();
            oneEntity.ParameterList.Add(satt);
        }
Beispiel #16
0
        private void ProcessInverse(SEntity sEntity, SToken sToken)
        {
            SAttributeInverse sAttributeInverse = new SAttributeInverse(sToken.StringValue);
            SToken oneToken = SLexer.Tokenizer(_dataStream);
            if (oneToken.TokenType != STokenType.COLON)
            { throw new Exception("Error in inverse attribute : " + SLexer.CurrentRow + " : " + SLexer.CurrentColumn); }

            sAttributeInverse.Type = ProcessInverseParameter();
            oneToken = SLexer.Tokenizer(_dataStream);
            // referencing entity's attribute name
            oneToken = SLexer.Tokenizer(_dataStream);
            sAttributeInverse.InversingAttributeName = oneToken.StringValue;
            sEntity.InverseList.Add(sAttributeInverse);
            // semi colon
            oneToken = SLexer.Tokenizer(_dataStream);
        }
Beispiel #17
0
        private SToken ProcessSuperSub(SToken oneToken, SEntity aEntity)
        {
            if (oneToken.TokenType == STokenType.ABSTRACT)
            {
                aEntity.IsAbstract = true;
                //get new token for next step
                oneToken = SLexer.Tokenizer(_dataStream);
            }

            if (oneToken.TokenType == STokenType.SUPERTYPE)
            {   // remove OF token after supertype token
                oneToken = SLexer.Tokenizer(_dataStream);
                ProcessSupertypeOf(aEntity);
                //get new token for next step
                oneToken = SLexer.Tokenizer(_dataStream);
            }

            if (oneToken.TokenType == STokenType.SUBTYPE)
            {   // remove of token after supertype token
                oneToken = SLexer.Tokenizer(_dataStream);
                ProcessSubtypeOf(aEntity);
                //get new token for next step
                oneToken = SLexer.Tokenizer(_dataStream);
            }

            return SLexer.Tokenizer(_dataStream);
        }
Beispiel #18
0
        private void WriteAttribute(SEntity o, FieldInfo f, DocXsdFormat format)
        {
            object v = f.GetValue(o);

            if (v == null)
            {
                return;
            }

            this.WriteStartElementAttribute(f.Name, null);

            Type ft = f.FieldType;

            if (format == null || format.XsdFormat != DocXsdFormatEnum.Attribute || f.Name.Equals("InnerCoordIndices")) //hackhack -- need to resolve...
            {
                this.WriteOpenElement();
            }

            if (typeof(System.Collections.ICollection).IsAssignableFrom(ft))
            {
                System.Collections.IList list = (System.Collections.IList)v;

                // for nested lists, flatten; e.g. IfcBSplineSurfaceWithKnots.ControlPointList
                if (typeof(System.Collections.ICollection).IsAssignableFrom(ft.GetGenericArguments()[0]))
                {
                    // special case
                    if (f.Name.Equals("InnerCoordIndices")) //hack
                    {
                        foreach (System.Collections.ICollection innerlist in list)
                        {
                            string entname = "Seq-IfcPositiveInteger-wrapper"; // hack
                            this.WriteStartElementEntity(entname, null);
                            this.WriteOpenElement();
                            foreach (object e in innerlist)
                            {
                                object ev = e.GetType().GetField("Value").GetValue(e);

                                this.m_writer.Write(ev.ToString());
                                this.m_writer.Write(" ");
                            }
                            this.m_writer.WriteLine();
                            this.WriteEndElementEntity(entname);
                        }
                        WriteEndElementAttribute(f.Name);
                        return;
                    }

                    System.Collections.ArrayList flatlist = new System.Collections.ArrayList();
                    foreach (System.Collections.ICollection innerlist in list)
                    {
                        foreach (object e in innerlist)
                        {
                            flatlist.Add(e);
                        }
                    }

                    list = flatlist;
                }

                if (list.Count > 0 && list[0] is SEntity)
                {
                    this.WriteCollectionStart();
                }

                for (int i = 0; i < list.Count; i++)
                {
                    object e = list[i];
                    if (e is SEntity)
                    {
                        if (format != null && format.XsdFormat == DocXsdFormatEnum.Attribute)
                        {
                            // only one item, e.g. StyledByItem\IfcStyledItem
                            this.WriteEntityStart();
                            bool closeelem = this.WriteEntityAttributes((SEntity)e);
                            if (!closeelem)
                            {
                                this.WriteCloseElementAttribute();
                                return;
                            }
                            this.WriteEntityEnd();
                        }
                        else
                        {
                            this.WriteEntity((SEntity)e);
                        }

                        if (i < list.Count - 1)
                        {
                            this.WriteCollectionDelimiter();
                        }
                    }
                    else if (e is System.Collections.IList)
                    {
                        System.Collections.IList listInner = (System.Collections.IList)e;
                        for (int j = 0; j < listInner.Count; j++)
                        {
                            object oi = listInner[j];

                            Type et = oi.GetType();
                            while (et.IsValueType && !et.IsPrimitive)
                            {
                                FieldInfo fieldValue = et.GetField("Value");
                                if (fieldValue != null)
                                {
                                    oi = fieldValue.GetValue(oi);
                                    et = fieldValue.FieldType;
                                }
                                else
                                {
                                    break;
                                }
                            }

                            // write each value in sequence with spaces delimiting
                            string sval = oi.ToString();
                            this.m_writer.Write(sval);
                            this.m_writer.Write(" ");
                        }
                    }
                    else
                    {
                        // if flat-list (e.g. structural load Locations) or list of strings (e.g. IfcPostalAddress.AddressLines), must wrap
                        this.WriteValueWrapper(e);
                    }
                }

                if (list.Count > 0 && list[0] is SEntity)
                {
                    this.WriteCollectionEnd();
                }
            }
            else if (v is SEntity)
            {
                if (format != null && format.XsdFormat == DocXsdFormatEnum.Attribute)
                {
                    this.WriteEntityStart();

                    Type vt = v.GetType();
                    if (ft != vt)
                    {
                        string hyperlink = "../../schema/" + vt.Namespace.ToLower() + "/lexical/" + vt.Name.ToLower() + ".htm";
                        this.WriteType(vt.Name, hyperlink);
                    }

                    bool closeelem = this.WriteEntityAttributes((SEntity)v);

                    if (!closeelem)
                    {
                        this.WriteCloseElementEntity();
                        return;
                    }

                    this.WriteEntityEnd();
                }
                else
                {
                    // if rooted, then check if we need to use reference; otherwise embed
                    this.WriteEntity((SEntity)v);
                }
            }
            else if (f.FieldType.IsInterface && v is ValueType)
            {
                this.WriteValueWrapper(v);
            }
            else if (f.FieldType.IsValueType) // must be IfcBinary
            {
                FieldInfo fieldValue = f.FieldType.GetField("Value");
                if (fieldValue != null)
                {
                    v = fieldValue.GetValue(v);
                    if (v is byte[])
                    {
                        this.WriteOpenElement();

                        // binary data type - we don't support anything other than 8-bit aligned, though IFC doesn't either so no point in supporting extraBits
                        byte[] bytes = (byte[])v;

                        char[]        s_hexchar = new char[] { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' };
                        StringBuilder sb        = new StringBuilder(bytes.Length * 2);
                        for (int i = 0; i < bytes.Length; i++)
                        {
                            byte b = bytes[i];
                            sb.Append(s_hexchar[b / 0x10]);
                            sb.Append(s_hexchar[b % 0x10]);
                        }
                        v = sb.ToString();
                        this.m_writer.WriteLine(v);
                    }
                }
            }
            else
            {
                //???
                this.ToString();
            }

            WriteEndElementAttribute(f.Name);
        }
Beispiel #19
0
        private void WriteEntity(SEntity o)
        {
            // sanity check
            if (this.m_indent > 100)
            {
                return;
            }

            Type t = o.GetType();

            string hyperlink = "../../schema/" + t.Namespace.ToLower() + "/lexical/" + t.Name.ToLower() + ".htm";

            this.WriteStartElement(t.Name, hyperlink);

#if false
            // id
            if (gen != null)
            {
                bool firstTime;
                long id = gen.GetId(o, out firstTime);
                writer.WriteAttributeString("id", "i" + id.ToString());
            }
#endif

            /*
             * writer.WriteStartAttribute("id");
             * writer.WriteValue("i" + id.ToString());
             * writer.WriteEndAttribute();*/

            // write fields as attributes
            bool haselements         = false;
            IList <FieldInfo> fields = SEntity.GetFieldsOrdered(t);
            foreach (FieldInfo f in fields)
            {
                object v = f.GetValue(o);
                if (v != null)
                {
                    if (f.FieldType.IsValueType)
                    {
                        Type ft = f.FieldType;
                        if (ft.IsGenericType && ft.GetGenericTypeDefinition() == typeof(Nullable <>))
                        {
                            // special case for Nullable types
                            ft = ft.GetGenericArguments()[0];
                        }

                        Type typewrap = null;
                        while (ft.IsValueType && !ft.IsPrimitive)
                        {
                            FieldInfo fieldValue = ft.GetField("Value");
                            if (fieldValue != null)
                            {
                                v = fieldValue.GetValue(v);
                                if (typewrap == null)
                                {
                                    typewrap = ft;
                                }
                                ft = fieldValue.FieldType;
                            }
                            else
                            {
                                break;
                            }
                        }

                        if (v != null)
                        {
                            string encodedvalue = System.Security.SecurityElement.Escape(v.ToString());

                            m_writer.Write(" ");
                            m_writer.Write(f.Name);
                            m_writer.Write("=\"");
                            m_writer.Write(encodedvalue); //... escape it
                            m_writer.Write("\"");
                        }
                    }
                    else
                    {
                        haselements = true;
                    }
                }
            }

            IList <FieldInfo> inverses = SEntity.GetFieldsInverse(t);

            if (haselements || inverses.Count > 0)
            {
                WriteOpenElement();

                // write direct object references and lists
                foreach (FieldInfo f in fields)
                {
                    DocXsdFormat format = GetXsdFormat(f);

                    // hide fields where inverse attribute used instead
                    if (!f.FieldType.IsValueType &&
                        (format == null || (format.XsdFormat != DocXsdFormatEnum.Hidden)))
                    {
                        WriteAttribute(o, f);
                    }
                }

                // write inverse object references and lists
                foreach (FieldInfo f in inverses)
                {
                    DocXsdFormat format = GetXsdFormat(f);
                    if (format != null && format.XsdFormat == DocXsdFormatEnum.Element) //... check this
                    {
                        WriteAttribute(o, f);                                           //... careful - don't write back-references...
                    }
                }

                WriteEndElement(t.Name);
            }
            else
            {
                // close opening tag
                if (this.m_markup)
                {
                    this.m_writer.WriteLine("/&gt;<br/>");
                }
                else
                {
                    this.m_writer.WriteLine("/>");
                }

                this.m_indent--;
            }
        }
Beispiel #20
0
        /// <summary>
        /// Returns true if any elements written (requiring closing tag); or false if not
        /// </summary>
        /// <param name="o"></param>
        /// <returns></returns>
        private bool WriteEntityAttributes(SEntity o)
        {
            Type t = o.GetType();

            long oid = 0;

            if (this.m_saved.Contains(o))
            {
                // give it an ID if needed (first pass)
                if (!this.m_idmap.TryGetValue(o, out oid))
                {
                    this.m_nextID++;
                    this.m_idmap[o] = this.m_nextID;
                }

                // reference existing; return
                this.WriteReference(oid);
                return(false);
            }

            // mark as saved
            this.m_saved.Add(o);

            if (this.m_idmap.TryGetValue(o, out oid))
            {
                this.WriteIdentifier(oid);
            }

            bool previousattribute = false;

            // write fields as attributes
            bool haselements         = false;
            IList <FieldInfo> fields = SEntity.GetFieldsAll(t);

            foreach (FieldInfo f in fields)
            {
                DocXsdFormat xsdformat = this.GetXsdFormat(f);

                if (f.IsDefined(typeof(DataMemberAttribute)) && (xsdformat == null || (xsdformat.XsdFormat != DocXsdFormatEnum.Element && xsdformat.XsdFormat != DocXsdFormatEnum.Attribute)))
                {
                    // direct field

                    Type ft = f.FieldType;

                    bool isvaluelist     = (ft.IsGenericType && ft.GetGenericTypeDefinition() == typeof(List <>) && ft.GetGenericArguments()[0].IsValueType);
                    bool isvaluelistlist = (ft.IsGenericType && // e.g. IfcTriangulatedFaceSet.Normals
                                            ft.GetGenericTypeDefinition() == typeof(List <>) &&
                                            ft.GetGenericArguments()[0].IsGenericType &&
                                            ft.GetGenericArguments()[0].GetGenericTypeDefinition() == typeof(List <>) &&
                                            ft.GetGenericArguments()[0].GetGenericArguments()[0].IsValueType);

                    if (isvaluelistlist || isvaluelist || ft.IsValueType)
                    {
                        object v = f.GetValue(o);
                        if (v != null)
                        {
                            if (previousattribute)
                            {
                                this.WriteAttributeDelimiter();
                            }

                            previousattribute = true;
                            this.WriteStartAttribute(f.Name);

                            if (isvaluelistlist)
                            {
                                ft = ft.GetGenericArguments()[0].GetGenericArguments()[0];
                                FieldInfo fieldValue = ft.GetField("Value");

                                System.Collections.IList list = (System.Collections.IList)v;
                                for (int i = 0; i < list.Count; i++)
                                {
                                    System.Collections.IList listInner = (System.Collections.IList)list[i];
                                    for (int j = 0; j < listInner.Count; j++)
                                    {
                                        if (i > 0 || j > 0)
                                        {
                                            this.m_writer.Write(" ");
                                        }

                                        object elem = listInner[j];
                                        if (elem != null) // should never be null, but be safe
                                        {
                                            elem = fieldValue.GetValue(elem);
                                            string encodedvalue = System.Security.SecurityElement.Escape(elem.ToString());
                                            this.m_writer.Write(encodedvalue);
                                        }
                                    }
                                }
                            }
                            else if (isvaluelist)
                            {
                                ft = ft.GetGenericArguments()[0];
                                FieldInfo fieldValue = ft.GetField("Value");

                                System.Collections.IList list = (System.Collections.IList)v;
                                for (int i = 0; i < list.Count; i++)
                                {
                                    if (i > 0)
                                    {
                                        this.m_writer.Write(" ");
                                    }

                                    object elem = list[i];
                                    if (elem != null) // should never be null, but be safe
                                    {
                                        elem = fieldValue.GetValue(elem);
                                        if (elem is byte[])
                                        {
                                            // IfcPixelTexture.Pixels
                                            byte[] bytes = (byte[])elem;

                                            char[]        s_hexchar = new char[] { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' };
                                            StringBuilder sb        = new StringBuilder(bytes.Length * 2);
                                            for (int z = 0; z < bytes.Length; z++)
                                            {
                                                byte b = bytes[z];
                                                sb.Append(s_hexchar[b / 0x10]);
                                                sb.Append(s_hexchar[b % 0x10]);
                                            }
                                            v = sb.ToString();
                                            this.m_writer.Write(v);
                                        }
                                        else
                                        {
                                            string encodedvalue = System.Security.SecurityElement.Escape(elem.ToString());
                                            this.m_writer.Write(encodedvalue);
                                        }
                                    }
                                }
                            }
                            else
                            {
                                if (ft.IsGenericType && ft.GetGenericTypeDefinition() == typeof(Nullable <>))
                                {
                                    // special case for Nullable types
                                    ft = ft.GetGenericArguments()[0];
                                }

                                Type typewrap = null;
                                while (ft.IsValueType && !ft.IsPrimitive)
                                {
                                    FieldInfo fieldValue = ft.GetField("Value");
                                    if (fieldValue != null)
                                    {
                                        v = fieldValue.GetValue(v);
                                        if (typewrap == null)
                                        {
                                            typewrap = ft;
                                        }
                                        ft = fieldValue.FieldType;
                                    }
                                    else
                                    {
                                        break;
                                    }
                                }

                                if (ft.IsEnum || ft == typeof(bool))
                                {
                                    v = v.ToString().ToLowerInvariant();
                                }

                                if (v is System.Collections.IList)
                                {
                                    // IfcCompoundPlaneAngleMeasure
                                    System.Collections.IList list = (System.Collections.IList)v;
                                    for (int i = 0; i < list.Count; i++)
                                    {
                                        if (i > 0)
                                        {
                                            this.m_writer.Write(" ");
                                        }

                                        object elem = list[i];
                                        if (elem != null) // should never be null, but be safe
                                        {
                                            string encodedvalue = System.Security.SecurityElement.Escape(elem.ToString());
                                            this.m_writer.Write(encodedvalue);
                                        }
                                    }
                                }
                                else if (v != null)
                                {
                                    string encodedvalue = System.Security.SecurityElement.Escape(v.ToString());
                                    m_writer.Write(encodedvalue); //... escape it
                                }
                            }

                            this.WriteEndAttribute();
                        }
                    }
                    else
                    {
                        haselements = true;
                    }
                }
                else
                {
                    // inverse
                    haselements = true;
                }
            }

            if (haselements)
            {
                bool open = false;

                // write direct object references and lists
                foreach (FieldInfo f in fields)
                {
                    DocXsdFormat format = GetXsdFormat(f);
                    if (f.IsDefined(typeof(DataMemberAttribute)) && (format == null || (format.XsdFormat != DocXsdFormatEnum.Element && format.XsdFormat != DocXsdFormatEnum.Attribute)))
                    {
                        Type ft              = f.FieldType;
                        bool isvaluelist     = (ft.IsGenericType && ft.GetGenericTypeDefinition() == typeof(List <>) && ft.GetGenericArguments()[0].IsValueType);
                        bool isvaluelistlist = (ft.IsGenericType && // e.g. IfcTriangulatedFaceSet.Normals
                                                ft.GetGenericTypeDefinition() == typeof(List <>) &&
                                                ft.GetGenericArguments()[0].IsGenericType &&
                                                ft.GetGenericArguments()[0].GetGenericTypeDefinition() == typeof(List <>) &&
                                                ft.GetGenericArguments()[0].GetGenericArguments()[0].IsValueType);

                        // hide fields where inverse attribute used instead
                        if (!f.FieldType.IsValueType && !isvaluelist && !isvaluelistlist &&
                            (format == null || (format.XsdFormat != DocXsdFormatEnum.Hidden)))
                        {
                            object value = f.GetValue(o);
                            if (value != null)
                            {
                                if (!open)
                                {
                                    WriteOpenElement();
                                    open = true;
                                }

                                if (previousattribute)
                                {
                                    this.WriteAttributeDelimiter();
                                }
                                previousattribute = true;

                                WriteAttribute(o, f, format);
                            }
                        }
                    }
                    else if (format != null && (format.XsdFormat == DocXsdFormatEnum.Element || format.XsdFormat == DocXsdFormatEnum.Attribute))
                    {
                        object value = f.GetValue(o);
                        if (value != null)
                        {
                            if (!open)
                            {
                                WriteOpenElement();
                                open = true;
                            }

                            if (previousattribute)
                            {
                                this.WriteAttributeDelimiter();
                            }
                            previousattribute = true;

                            WriteAttribute(o, f, format);
                        }
                    }
                    else
                    {
                        object value = f.GetValue(o);

                        // inverse
                        // record it for downstream serialization
                        if (value is System.Collections.IList)
                        {
                            System.Collections.IList invlist = (System.Collections.IList)value;
                            foreach (SEntity invobj in invlist)
                            {
                                if (!this.m_saved.Contains(invobj))
                                {
                                    this.m_queue.Enqueue(invobj);
                                }
                            }
                        }
                    }
                }

                this.WriteAttributeTerminator();

                return(open);
            }
            else
            {
                this.WriteAttributeTerminator();
                return(false);
            }
        }
Beispiel #21
0
        private void WriteAttribute(SEntity o, FieldInfo f)
        {
            object v = f.GetValue(o);

            if (v == null)
            {
                return;
            }

            this.WriteStartElement(f.Name, null);
            this.WriteOpenElement();

            Type ft = f.FieldType;

            if (typeof(System.Collections.ICollection).IsAssignableFrom(ft))
            {
                System.Collections.IList list = (System.Collections.IList)v;
                for (int i = 0; i < list.Count; i++)
                {
                    object e = list[i];
                    if (e is SEntity)
                    {
                        this.WriteEntity((SEntity)e);

                        //...WriteReference(writer, (SEntity)e);
                    }
                    else if (e is System.Collections.IList)
                    {
                        System.Collections.IList listInner = (System.Collections.IList)e;
                        for (int j = 0; j < listInner.Count; j++)
                        {
                            object oi = listInner[j];

                            Type et = oi.GetType();
                            while (et.IsValueType && !et.IsPrimitive)
                            {
                                FieldInfo fieldValue = et.GetField("Value");
                                if (fieldValue != null)
                                {
                                    oi = fieldValue.GetValue(oi);
                                    et = fieldValue.FieldType;
                                }
                                else
                                {
                                    break;
                                }
                            }

                            // write each value in sequence with spaces delimiting
                            string sval = oi.ToString();
                            this.m_writer.Write(sval);
                            this.m_writer.Write(" ");
                        }
                    }
                    else
                    {
                        Type et = e.GetType();
                        while (et.IsValueType && !et.IsPrimitive)
                        {
                            FieldInfo fieldValue = et.GetField("Value");
                            if (fieldValue != null)
                            {
                                e  = fieldValue.GetValue(e);
                                et = fieldValue.FieldType;
                            }
                            else
                            {
                                break;
                            }
                        }

                        // write each value in sequence with spaces delimiting
                        string sval = e.ToString();
                        this.m_writer.Write(sval);
                        this.m_writer.Write(" ");
                    }
                }
            }
            else if (v is SEntity)
            {
                // if rooted, then check if we need to use reference; otherwise embed
                this.WriteEntity((SEntity)v);
                //this.WriteReference(writer, (SEntity)v);
            }
            else
            {
                // qualified value type
                this.WriteValue(v);
            }

            WriteEndElement(f.Name);
        }
Beispiel #22
0
 public void FormatData(Stream stream, DocProject docProject, DocPublication docPublication, DocExchangeDefinition docExchange, Dictionary <string, DocObject> map, Dictionary <string, Type> typemap, Dictionary <long, SEntity> instances, SEntity root, bool markup)
 {
     this.m_stream = stream;
     this.Instance = root;
     this.Markup   = markup;
     this.Save();
 }
Beispiel #23
0
        /// <summary>
        /// Saves all instances to the database
        /// </summary>
        public void Save()
        {
            foreach (SEntity entity in this.Instances.Values)
            {
                Type t = entity.GetType();
                IList <FieldInfo> fields = SEntity.GetFieldsOrdered(t);

                if (entity.Existing)
                {
                    //...update attributes...
                }
                else
                {
                    // create new
                    StringBuilder sb = new StringBuilder();
                    sb.Append("INSERT INTO ");
                    sb.Append(t.Name);
                    sb.Append("(oid");
                    foreach (FieldInfo f in fields)
                    {
                        if (!f.FieldType.IsGenericType)                         // don't deal with lists
                        {
                            sb.Append(", ");
                            sb.Append(f.Name);
                        }
                    }
                    sb.Append(") VALUES (");
                    sb.Append(entity.OID.ToString());
                    foreach (FieldInfo f in fields)
                    {
                        if (!f.FieldType.IsGenericType)                         // don't deal with lists
                        {
                            sb.Append(", ");
                            object val = f.GetValue(entity);
                            if (val is SEntity)
                            {
                                SEntity entref = (SEntity)val;
                                sb.Append(entref.OID);
                            }
                            else if (val is byte[])
                            {
                                byte[] bval = (byte[])val;
                                sb.Append("'");
                                sb.Append(BitConverter.ToString(bval));
                                sb.Append("'");
                            }
                            else if (val != null)
                            {
                                string encoded = val.ToString();
                                if (encoded != null)
                                {
                                    if (val is string || val is Enum)
                                    {
                                        sb.Append("'");
                                    }
                                    sb.Append(encoded.Replace("'", "''"));                                     // escape single quotes - note: does not handle other unicode quotes
                                    if (val is string || val is Enum)
                                    {
                                        sb.Append("'");
                                    }
                                }
                                else
                                {
                                    sb.Append("NULL");
                                }
                            }
                            else
                            {
                                sb.Append("NULL");
                            }
                        }
                    }
                    sb.Append(");");

                    Execute(sb.ToString());
                    entity.Existing = true;
                }

                // lists
                foreach (FieldInfo f in fields)
                {
                    if (f.FieldType.IsGenericType)
                    {
                        string tablename = t.Name + "_" + f.Name;

                        // clear existing
                        Execute("DELETE FROM " + tablename + " WHERE source=" + entity.OID.ToString() + ";");

                        System.Collections.IList list = (System.Collections.IList)f.GetValue(entity);
                        if (list != null)
                        {
                            for (int i = 0; i < list.Count; i++)
                            {
                                SEntity target = (SEntity)list[i];

                                Execute("INSERT INTO " + tablename +
                                        " (source, sequence, target) VALUES (" +
                                        entity.OID.ToString() + ", " +
                                        i.ToString() + ", " +
                                        target.OID.ToString() + ");");
                            }
                        }
                    }
                }
            }
        }
Beispiel #24
0
        public void FormatData(Stream stream, DocProject docProject, DocPublication docPublication, DocExchangeDefinition docExchange, Dictionary <string, DocObject> map, Dictionary <string, Type> typemap, Dictionary <long, SEntity> instances, SEntity root, bool markup)
        {
            StringBuilder sb = new StringBuilder();

            foreach (DocModelView docView in docPublication.Views)
            {
                foreach (DocConceptRoot docRoot in docView.ConceptRoots)
                {
                    // look for specific concept root dealing with mappings
                    foreach (DocTemplateUsage docConcept in docRoot.Concepts)
                    {
                        if (docConcept.Definition != null && docConcept.Definition.Uuid.Equals(DocTemplateDefinition.guidTemplateMapping) && docConcept.Items.Count > 0)                        //...
                        {
                            bool included = true;

                            if (docExchange != null)
                            {
                                included = false;
                                // if exhcnage specified, check for inclusion
                                foreach (DocExchangeItem docExchangeItem in docConcept.Exchanges)
                                {
                                    if (docExchangeItem.Exchange == docExchange && docExchangeItem.Requirement == DocExchangeRequirementEnum.Mandatory)
                                    {
                                        included = true;
                                        break;
                                    }
                                }
                            }

                            // check if there are any instances to populate table
                            if (included)
                            {
                                included = false;
                                foreach (SEntity e in instances.Values)
                                {
                                    string eachname = e.GetType().Name;
                                    if (docRoot.ApplicableEntity.IsInstanceOfType(e))
                                    {
                                        included = true;
                                        break;
                                    }
                                }
                            }

                            if (included)
                            {
                                string dataconcept = FormatDataConcept(docProject, docPublication, docExchange, map, typemap, instances, root, markup, docView, docRoot, docConcept);
                                sb.Append(dataconcept);
                            }
                        }
                    }
                }
            }
        }
Beispiel #25
0
        public string FormatData(DocProject docProject, DocPublication docPublication, DocExchangeDefinition docExchange, Dictionary <string, DocObject> map, Dictionary <long, SEntity> instances, SEntity root, bool markup)
        {
            //Guid guidMapping = Guid.Parse("");//...

            StringBuilder sb = new StringBuilder();

            foreach (DocModelView docView in docPublication.Views)
            {
                foreach (DocConceptRoot docRoot in docView.ConceptRoots)
                {
                    // look for specific concept root dealing with mappings
                    foreach (DocTemplateUsage docConcept in docRoot.Concepts)
                    {
                        if (docConcept.Definition != null && docConcept.Definition.Name.Equals("External Data Constraints") && docConcept.Items.Count > 0)//...
                        {
                            bool included = true;

                            if (docExchange != null)
                            {
                                included = false;
                                // if exhcnage specified, check for inclusion
                                foreach (DocExchangeItem docExchangeItem in docConcept.Exchanges)
                                {
                                    if (docExchangeItem.Exchange == docExchange && docExchangeItem.Requirement == DocExchangeRequirementEnum.Mandatory)
                                    {
                                        included = true;
                                        break;
                                    }
                                }
                            }

                            // check if there are any instances to populate table
                            if (included)
                            {
                                included = false;
                                foreach (SEntity e in instances.Values)
                                {
                                    string eachname = e.GetType().Name;
                                    if (docRoot.ApplicableEntity.IsInstanceOfType(e))
                                    {
                                        included = true;
                                        break;
                                    }
                                }
                            }

                            if (included)
                            {
                                string table = docConcept.Items[0].GetParameterValue("Table");
                                string query = docConcept.Items[0].GetParameterValue("Reference");

                                sb.AppendLine("<h4>" + docConcept.Name + "</h4>");
                                sb.AppendLine("<table class=\"gridtable\">");

                                List <string>       colstyles = new List <string>();
                                List <string>       colformat = new List <string>();
                                List <CvtValuePath> colmaps   = new List <CvtValuePath>();

                                // generate header row
                                sb.AppendLine("<tr>");
                                foreach (DocTemplateItem docItem in docConcept.Items)
                                {
                                    string name = docItem.GetParameterValue("Name");
                                    string disp = "#" + docItem.GetColor().ToArgb().ToString("X8"); //docItem.GetParameterValue("Color");docItem.GetParameterValue("Color");
                                    string expr = docItem.GetParameterValue("Reference");
                                    string form = docItem.GetParameterValue("Format");

                                    string style = "";
                                    if (!String.IsNullOrEmpty(disp))
                                    {
                                        style = " style=\"background-color:" + disp + ";\"";
                                    }
                                    colstyles.Add(style);

                                    string format = "";
                                    if (!String.IsNullOrEmpty(form))
                                    {
                                        format = form;
                                    }
                                    colformat.Add(format);

                                    string       desc    = "";
                                    CvtValuePath valpath = CvtValuePath.Parse(expr, map); //todo: move out of loop
                                    colmaps.Add(valpath);
                                    if (valpath != null)
                                    {
                                        desc = /*valpath.GetDescription(map) + "&#10;&#10;" + */ valpath.ToString().Replace("\\", "&#10;");
                                    }

                                    sb.Append("<th><a href=\"../../schema/views/" + DocumentationISO.MakeLinkName(docView) + "/" + DocumentationISO.MakeLinkName(docExchange) + ".htm#" + DocumentationISO.MakeLinkName(docConcept) + "\" title=\"" + desc + "\">");
                                    sb.Append(name);
                                    sb.Append("</a></th>");
                                }
                                ;
                                sb.AppendLine("</tr>");

                                // generate data rows
                                foreach (SEntity e in instances.Values)
                                {
                                    string eachname = e.GetType().Name;
                                    if (docRoot.ApplicableEntity.IsInstanceOfType(e))
                                    {
                                        bool          includerow = true;
                                        StringBuilder sbRow      = new StringBuilder();

                                        sbRow.Append("<tr>");
                                        int iCol = 0;
                                        foreach (DocTemplateItem docItem in docConcept.Items)
                                        {
                                            sbRow.Append("<td" + colstyles[iCol]);
                                            CvtValuePath valpath = colmaps[iCol];
                                            string       format  = colformat[iCol];

                                            iCol++;

                                            if (valpath != null)
                                            {
                                                string nn = docItem.GetParameterValue("Name");

                                                object value = valpath.GetValue(e, null);

                                                if (value == e)
                                                {
                                                    value = e.GetType().Name;
                                                }
                                                else if (value is SEntity)
                                                {
                                                    // use name
                                                    FieldInfo fieldValue = value.GetType().GetField("Name");
                                                    if (fieldValue != null)
                                                    {
                                                        value = fieldValue.GetValue(value);
                                                    }
                                                }
                                                else if (value is System.Collections.IList)
                                                {
                                                    System.Collections.IList list   = (System.Collections.IList)value;
                                                    StringBuilder            sbList = new StringBuilder();
                                                    foreach (object elem in list)
                                                    {
                                                        FieldInfo fieldName = elem.GetType().GetField("Name");
                                                        if (fieldName != null)
                                                        {
                                                            object elemname = fieldName.GetValue(elem);
                                                            if (elemname != null)
                                                            {
                                                                FieldInfo fieldValue = elemname.GetType().GetField("Value");
                                                                if (fieldValue != null)
                                                                {
                                                                    object elemval = fieldValue.GetValue(elemname);
                                                                    sbList.Append(elemval.ToString());
                                                                }
                                                            }
                                                        }
                                                        sbList.Append("; <br/>");
                                                    }
                                                    value = sbList.ToString();
                                                }
                                                else if (value is Type)
                                                {
                                                    value = ((Type)value).Name;
                                                }

                                                if (!String.IsNullOrEmpty(format))
                                                {
                                                    if (format.Equals("Required") && value == null)
                                                    {
                                                        includerow = false;
                                                    }
                                                }

                                                if (value != null)
                                                {
                                                    FieldInfo fieldValue = value.GetType().GetField("Value");
                                                    if (fieldValue != null)
                                                    {
                                                        value = fieldValue.GetValue(value);
                                                    }

                                                    if (format != null && format.Equals("True") && (value == null || !value.ToString().Equals("True")))
                                                    {
                                                        includerow = false;
                                                    }

                                                    if (value is Double)
                                                    {
                                                        sbRow.Append(" align=\"right\">");

                                                        sbRow.Append(((Double)value).ToString("N3"));
                                                    }
                                                    else if (value is List <Int64> )
                                                    {
                                                        sbRow.Append(">");

                                                        // latitude or longitude
                                                        List <Int64> intlist = (List <Int64>)value;
                                                        if (intlist.Count >= 3)
                                                        {
                                                            sbRow.Append(intlist[0] + "° " + intlist[1] + "' " + intlist[2] + "\"");
                                                        }
                                                    }
                                                    else if (value != null)
                                                    {
                                                        sbRow.Append(">");
                                                        sbRow.Append(value.ToString()); // todo: html-encode
                                                    }
                                                }
                                                else
                                                {
                                                    sbRow.Append(">");
                                                    sbRow.Append("&nbsp;");
                                                }
                                            }
                                            else
                                            {
                                                sbRow.Append(">");
                                            }

                                            sbRow.Append("</td>");
                                        }
                                        sbRow.AppendLine("</tr>");

                                        if (includerow)
                                        {
                                            sb.Append(sbRow.ToString());
                                        }
                                    }
                                }

                                sb.AppendLine("</table>");
                                sb.AppendLine("<br/>");
                            }
                        }
                    }
                }
            }

            return(sb.ToString());
        }
Beispiel #26
0
        public string FormatData(DocProject docProject, DocPublication docPublication, DocExchangeDefinition docExchange, Dictionary <string, DocObject> map, Dictionary <long, SEntity> instances, SEntity root, bool markup)
        {
            this.m_stream = new System.IO.MemoryStream();
            this.Instance = root;
            this.Markup   = markup;
            this.Save();

            this.m_stream.Position = 0;
            StreamReader reader  = new StreamReader(this.m_stream);
            string       content = reader.ReadToEnd();

            return(content);
        }
Beispiel #27
0
        private SEntity getEntity(string SimpleID)
        {
            SEntity aEntity;

            if (SchemaSet.EntityList.ContainsKey(SimpleID))
            {
                aEntity = SchemaSet.EntityList[SimpleID];
            }
            else
            {
                aEntity = new SEntity(SimpleID);
                SchemaSet.EntityList.Add(SimpleID, aEntity);
            }
            return aEntity;
        }
Beispiel #28
0
        [DataMember(Order = 3)] private string _Description;   // IfcText? : simplify

        public IfcRoot()
        {
            this._GlobalId     = SGuid.New().ToString();
            this._OwnerHistory = null;
        }
Beispiel #29
0
        /// <summary>
        /// not a complete derive implementation
        /// intended to identify omitted value in instance population
        /// </summary>
        /// <param name="oneEntity"></param>
        /// <param name="AttributeName"></param>
        private void ProcessDerivedAttribute(
            SEntity oneEntity,
            SToken mToken)
        {
            SAttributeDerived drvAtt;
            //SParam sParam;

            if (mToken.TokenType == STokenType.SELF)
            {
                //drvAtt = new SAttributeDerived(AttribType.DERIVED);
                // defines self drived attribute

                // reverse_solidus
                mToken = SLexer.Tokenizer(_dataStream);

                // super entity
                mToken = SLexer.Tokenizer(_dataStream);
                if (mToken.TokenType != STokenType.SIMPLEID)
                    throw new InvalidDataException(string.Format(
                        "schema is not in syntax at {0} : {1}",
                        oneEntity.Name, mToken.TokenType.ToString()));

                string orgSuperTypeName = mToken.StringValue;

                // period
                mToken = SLexer.Tokenizer(_dataStream);
                // attribute name
                mToken = SLexer.Tokenizer(_dataStream);

                string sAttName = mToken.StringValue;

                drvAtt = new SAttributeDerived(sAttName);
                drvAtt.OriginatingSuperType = orgSuperTypeName;
                drvAtt.Name = sAttName;
                drvAtt.isInherited = true;

                // colon
                mToken = SLexer.Tokenizer(_dataStream);
                drvAtt.Type = ProcessParameter();
                oneEntity.DerivedList.Add(drvAtt);
            }
            else //if (mToken.TokenType == SchemaTokenType.SIMPLEID)
            {
                string sAttName = mToken.StringValue;

                drvAtt = new SAttributeDerived(sAttName);
                drvAtt.Name = sAttName;
                drvAtt.isInherited = false;

                mToken = SLexer.Tokenizer(_dataStream);

                drvAtt.Type = ProcessParameter();
                oneEntity.DerivedList.Add(drvAtt);
            }

            //mToken = SLexer.Tokenizer(DataStream);
            //oneEntity.AttributeList.Add(oneAttribute);
            while (mToken.TokenType != STokenType.SEMICOLON)
            {
                mToken = SLexer.Tokenizer(_dataStream);
            }
        }
 private void AddSimpleDef(InstanceSimple instanceSimple, SEntity sEntity)
 {
     var j = 0;
     foreach (var t in sEntity.FlatList)
     {
         if (t is SAttributeInverse) continue;
         var parameter = instanceSimple.AttributeList[j];
         var sAttribute = t;
         AddAttributeDef(parameter, sAttribute);
         j++;
     }
 }
Beispiel #31
0
 private void ProcessSubtypeOf(SEntity aEntity)
 {
     SToken oneToken = SLexer.Tokenizer(_dataStream);
     if (oneToken.TokenType != STokenType.LEFTPARENTHESIS)
         throw new Exception("Syntax Error : Supertype Definition (");
     oneToken = SLexer.Tokenizer(_dataStream);
     if (oneToken.TokenType != STokenType.SIMPLEID)
         throw new Exception("Syntax Error : Supertype Definition simpleId");
     aEntity.SubTypesOf.Add(getEntity(oneToken.StringValue));
     oneToken = SLexer.Tokenizer(_dataStream);
     while (oneToken.TokenType != STokenType.RIGHTPARENTHESIS)
     {
         if (oneToken.TokenType != STokenType.COMMA)
             throw new Exception("Syntax Error : Supertype Definition ,");
         oneToken = SLexer.Tokenizer(_dataStream);
         if (oneToken.TokenType != STokenType.SIMPLEID)
             throw new Exception("Syntax Error : Supertype Definition simpleid2");
         aEntity.SuperTypesOf.Add(getEntity(oneToken.StringValue));
         oneToken = SLexer.Tokenizer(_dataStream);
     }
     //
     //oneToken = SchemaLexer.Tokenizer(DataStream);
 }
Beispiel #32
0
        public void DoInsert()
        {
            if (this.m_template == null)
            {
                return;
            }

            if (this.treeViewTemplate.Nodes.Count == 0)
            {
                DocEntity docEntityBase = null;
                if (this.m_parent is DocTemplateDefinition)
                {
                    string classname = ((DocTemplateDefinition)this.m_parent).Type;
                    docEntityBase = this.m_project.GetDefinition(classname) as DocEntity;
                }

                // get selected entity
                DocEntity docEntityThis = this.m_project.GetDefinition(this.m_template.Type) as DocEntity;

                using (FormSelectEntity form = new FormSelectEntity(docEntityBase, docEntityThis, this.m_project, SelectDefinitionOptions.Entity))
                {
                    DialogResult res = form.ShowDialog(this);
                    if (res == DialogResult.OK && form.SelectedEntity != null)
                    {
                        this.m_template.Type = form.SelectedEntity.Name;
                        this.LoadTemplateGraph();
                        this.ContentChanged(this, EventArgs.Empty);
                    }
                }

                return;
            }

            if (this.m_attribute != null && !String.IsNullOrEmpty(this.m_attribute.DefinedType))
            {
                DocTemplateDefinition docTemplate  = this.m_template;
                DocAttribute          docAttribute = this.m_attribute;

                string entityname = null;
                switch (this.m_attribute.DefinedType)
                {
                case "BOOLEAN":
                case "LOGICAL":
                case "BINARY":
                case "STRING":
                case "REAL":
                case "INTEGER":
                case "NUMBER":
                    entityname = this.m_attribute.DefinedType;
                    break;

                default:
                {
                    // qualify schema
                    DocObject docobj = null;

                    if (!String.IsNullOrEmpty(this.m_template.Code))
                    {
                        foreach (DocSection docSection in this.m_project.Sections)
                        {
                            foreach (DocSchema docSchema in docSection.Schemas)
                            {
                                if (docSchema.Name.Equals(this.m_template.Code, StringComparison.OrdinalIgnoreCase))
                                {
                                    docobj = docSchema.GetDefinition(docAttribute.DefinedType);
                                    break;
                                }
                            }
                        }
                    }

                    if (docobj == null)
                    {
                        docobj = this.m_project.GetDefinition(docAttribute.DefinedType);
                    }

                    using (FormSelectEntity form = new FormSelectEntity((DocDefinition)docobj, null, this.m_project, SelectDefinitionOptions.Entity | SelectDefinitionOptions.Type))
                    {
                        DialogResult res = form.ShowDialog(this);
                        if (res == DialogResult.OK && form.SelectedEntity != null)
                        {
                            entityname = form.SelectedEntity.Name;
                        }
                    }
                    break;
                }
                }

                if (entityname != null)
                {
                    // get or add attribute rule
                    TreeNode tn = this.treeViewTemplate.SelectedNode;
                    DocModelRuleAttribute docRuleAtt = null;
                    if (this.treeViewTemplate.SelectedNode.Tag is DocModelRuleAttribute)
                    {
                        docRuleAtt = (DocModelRuleAttribute)this.treeViewTemplate.SelectedNode.Tag;
                    }
                    else
                    {
                        docRuleAtt      = new DocModelRuleAttribute();
                        docRuleAtt.Name = docAttribute.Name;

                        if (this.treeViewTemplate.SelectedNode.Tag is DocModelRuleEntity)
                        {
                            DocModelRuleEntity docRuleEnt = (DocModelRuleEntity)this.treeViewTemplate.SelectedNode.Tag;
                            docRuleEnt.Rules.Add(docRuleAtt);
                        }
                        else if (this.treeViewTemplate.SelectedNode.Tag is DocTemplateDefinition)
                        {
                            docTemplate.Rules.Add(docRuleAtt);
                        }

                        tn = this.LoadTemplateGraph(tn, docRuleAtt);
                    }

                    // get and add entity rule
                    DocModelRuleEntity docRuleEntity = new DocModelRuleEntity();
                    docRuleEntity.Name = entityname;
                    docRuleAtt.Rules.Add(docRuleEntity);
                    this.treeViewTemplate.SelectedNode = this.LoadTemplateGraph(tn, docRuleEntity);

                    // copy to child templates
                    docTemplate.PropagateRule(this.treeViewTemplate.SelectedNode.FullPath);

                    this.m_selection = docRuleEntity;
                    this.ContentChanged(this, EventArgs.Empty);
                    this.SelectionChanged(this, EventArgs.Empty);
                }
            }
            else
            {
                // pick attribute, including attribute that may be on subtype
                DocModelRule rule = null;
                if (this.treeViewTemplate.SelectedNode != null)
                {
                    rule = this.treeViewTemplate.SelectedNode.Tag as DocModelRule;
                }

                //if (rule == null)
                //   return;

                DocTemplateDefinition docTemplate = (DocTemplateDefinition)this.m_template;

                string typename = null;
                if (rule is DocModelRuleEntity)
                {
                    DocModelRuleEntity docRuleEntity = (DocModelRuleEntity)rule;
                    typename = docRuleEntity.Name;
                }
                else
                {
                    // get applicable entity of target (or parent entity rule)
                    typename = docTemplate.Type;
                }

                DocEntity docEntity = this.m_project.GetDefinition(typename) as DocEntity;
                if (docEntity == null)
                {
#if false // constraints now edited at operations
                    // launch dialog for constraint
                    using (FormConstraint form = new FormConstraint())
                    {
                        DialogResult res = form.ShowDialog(this);
                        if (res == DialogResult.OK)
                        {
                            DocModelRuleConstraint docRuleConstraint = new DocModelRuleConstraint();
                            rule.Rules.Add(docRuleConstraint);
                            docRuleConstraint.Description = form.Expression;
                            docRuleConstraint.Name        = form.Expression; // for viewing

                            this.treeViewTemplate.SelectedNode = this.LoadTemplateGraph(this.treeViewTemplate.SelectedNode, docRuleConstraint);

                            // copy to child templates
                            docTemplate.PropagateRule(this.treeViewTemplate.SelectedNode.FullPath);
                        }
                    }
#endif
                }
                else
                {
                    // launch dialog to pick attribute of entity
                    using (FormSelectAttribute form = new FormSelectAttribute(docEntity, this.m_project, null, true))
                    {
                        DialogResult res = form.ShowDialog(this);
                        if (res == DialogResult.OK && form.Selection != null)
                        {
                            // then add and update tree
                            DocModelRuleAttribute docRuleAttr = new DocModelRuleAttribute();
                            docRuleAttr.Name = form.Selection;
                            if (rule != null)
                            {
                                rule.Rules.Add(docRuleAttr);
                            }
                            else
                            {
                                docTemplate.Rules.Add(docRuleAttr);
                            }
                            this.treeViewTemplate.SelectedNode = this.LoadTemplateGraph(this.treeViewTemplate.SelectedNode, docRuleAttr);

                            // copy to child templates
                            docTemplate.PropagateRule(this.treeViewTemplate.SelectedNode.FullPath);
                        }
                    }
                }
            }
        }
Beispiel #33
0
        private void ProcessSupertypeOf(SEntity aEntity)
        {
            //319 supertype_constraint = abstract_entity_declaration |
            //    abstract_supertype_declaration | supertype_rule .
            //164 abstract_entity_declaration = ABSTRACT .
            //166 abstract_supertype_declaration = ABSTRACT SUPERTYPE [ subtype_constraint ] .
            //313 subtype_constraint = OF ’(’ supertype_expression ’)’ .
            //320 supertype_expression = supertype_factor { ANDOR supertype_factor } .
            //321 supertype_factor = supertype_term { AND supertype_term } .
            //323 supertype_term = entity_ref | one_of | ’(’ supertype_expression ’)’ .
            //263 one_of = ONEOF ’(’ supertype_expression { ’,’ supertype_expression } ’)’ .
            //322 supertype_rule = SUPERTYPE subtype_constraint .

            int parenthesisCounter = 0;

            SToken oneToken = SLexer.Tokenizer(_dataStream);
            if (oneToken.TokenType != STokenType.LEFTPARENTHESIS)
            { throw new Exception("Syntax Error : Supertype Definition ("); }
            else { parenthesisCounter += 1; }

            while (parenthesisCounter != 0)
            {
                oneToken = SLexer.Tokenizer(_dataStream);

                switch (oneToken.TokenType)
                {
                    case STokenType.LEFTPARENTHESIS:
                        parenthesisCounter += 1;
                        break;
                    case STokenType.RIGHTPARENTHESIS:
                        parenthesisCounter -= 1;
                        break;
                    case STokenType.ONEOF:
                    case STokenType.COMMA:
                        break;
                    case STokenType.SIMPLEID:
                        aEntity.SuperTypesOf.Add(getEntity(oneToken.StringValue));
                        break;
                    default:
                        string logout = String.Format("Undefined supertype definition at row : {0}, column : {1}",
                            SLexer.CurrentRow,
                            SLexer.CurrentColumn);
                        if (_logFile != null)
                            _logFile.WriteLine(logout);
                        break;
                }

            }

            //if (oneToken.TokenType != SchemaTokenType.ONEOF)
            //    throw new Exception("Syntax Error : Supertype Definition oneof");

            //oneToken = SchemaLexer.Tokenizer(DataStream);

            //if (oneToken.TokenType != SchemaTokenType.LEFTPARENTHESIS)
            //    throw new Exception("Syntax Error : Supertype Definition (2");

            //oneToken = SchemaLexer.Tokenizer(DataStream);

            //if (oneToken.TokenType != SchemaTokenType.SIMPLEID)
            //    throw new Exception("Syntax Error : Supertype Definition simpleId");

            //aEntity.SuperTypesOf.Add(getEntity(oneToken.StringValue));

            //oneToken = SchemaLexer.Tokenizer(DataStream);

            //while (oneToken.TokenType != SchemaTokenType.RIGHTPARENTHESIS)
            //{
            //    if (oneToken.TokenType != SchemaTokenType.COMMA)
            //        throw new Exception("Syntax Error : Supertype Definition ,");
            //    oneToken = SchemaLexer.Tokenizer(DataStream);
            //    if (oneToken.TokenType != SchemaTokenType.SIMPLEID)
            //        throw new Exception("Syntax Error : Supertype Definition simpleid2");
            //    aEntity.SuperTypesOf.Add(getEntity(oneToken.StringValue));
            //    oneToken = SchemaLexer.Tokenizer(DataStream);
            //}
            //// for second parenthesis
            //oneToken = SchemaLexer.Tokenizer(DataStream);
        }
Beispiel #34
0
        public string FormatDataConcept(DocProject docProject, DocPublication docPublication, DocExchangeDefinition docExchange, Dictionary <string, DocObject> map, Dictionary <string, Type> typemap, Dictionary <long, SEntity> instances, SEntity root, bool markup, DocModelView docView, DocConceptRoot docRoot, DocTemplateUsage docConcept)
        {
            StringBuilder sb = new StringBuilder();

            string table = docConcept.Items[0].GetParameterValue("Table");
            string query = docConcept.Items[0].GetParameterValue("Reference");

            sb.AppendLine("<h4>" + docConcept.Name + "</h4>");
            sb.AppendLine("<table class=\"gridtable\">");

            List <string>       colstyles = new List <string>();
            List <string>       colformat = new List <string>();
            List <CvtValuePath> colmaps   = new List <CvtValuePath>();

            // generate header row
            sb.AppendLine("<tr>");
            foreach (DocTemplateItem docItem in docConcept.Items)
            {
                string name = docItem.GetParameterValue("Name");
                string disp = "#" + docItem.GetColor().ToArgb().ToString("X8");                 //docItem.GetParameterValue("Color");docItem.GetParameterValue("Color");
                string expr = docItem.GetParameterValue("Reference");
                string form = docItem.GetParameterValue("Format");

                string style = "";
                if (!String.IsNullOrEmpty(disp))
                {
                    style = " style=\"background-color:" + disp + ";\"";
                }
                colstyles.Add(style);

                string format = "";
                if (!String.IsNullOrEmpty(form))
                {
                    format = form;
                }
                colformat.Add(format);

                string       desc    = "";
                CvtValuePath valpath = CvtValuePath.Parse(expr, map);
                colmaps.Add(valpath);
                if (valpath != null)
                {
                    desc = /*valpath.GetDescription(map) + "&#10;&#10;" + */ valpath.ToString().Replace("\\", "&#10;");
                }

                sb.Append("<th><a href=\"../../schema/views/" + DocumentationISO.MakeLinkName(docView) + "/" + DocumentationISO.MakeLinkName(docExchange) + ".htm#" + DocumentationISO.MakeLinkName(docConcept) + "\" title=\"" + desc + "\">");
                sb.Append(name);
                sb.Append("</a></th>");
            }
            ;
            sb.AppendLine("</tr>");

            // generate data rows
            List <DocModelRule> trace = new List <DocModelRule>();

            foreach (SEntity e in instances.Values)
            {
                string eachname = e.GetType().Name;
                if (docRoot.ApplicableEntity.IsInstanceOfType(e))
                {
                    bool includerow = true;

                    // if root has more complex rules, check them
                    if (docRoot.ApplicableTemplate != null && docRoot.ApplicableItems.Count > 0)
                    {
                        includerow = false;

                        // must check1
                        foreach (DocTemplateItem docItem in docRoot.ApplicableItems)
                        {
                            foreach (DocModelRule rule in docRoot.ApplicableTemplate.Rules)
                            {
                                try
                                {
                                    trace.Clear();
                                    bool?result = rule.Validate(e, docItem, typemap, trace, e, null, null);
                                    if (result == true && docRoot.ApplicableOperator == DocTemplateOperator.Or)
                                    {
                                        includerow = true;
                                        break;
                                    }
                                }
                                catch
                                {
                                    docRoot.ToString();
                                }
                            }

                            // don't yet support AND or other operators

                            if (includerow)
                            {
                                break;
                            }
                        }
                    }


                    if (includerow)
                    {
                        StringBuilder sbRow = new StringBuilder();

                        sbRow.Append("<tr>");
                        int iCol = 0;
                        foreach (DocTemplateItem docItem in docConcept.Items)
                        {
                            sbRow.Append("<td" + colstyles[iCol]);
                            CvtValuePath valpath = colmaps[iCol];
                            string       format  = colformat[iCol];

                            iCol++;

                            if (valpath != null)
                            {
                                string nn = docItem.GetParameterValue("Name");

                                object value = valpath.GetValue(e, null);

                                if (value == e)
                                {
                                    value = e.GetType().Name;
                                }
                                else if (value is SEntity)
                                {
                                    // use name
                                    FieldInfo fieldValue = value.GetType().GetField("Name");
                                    if (fieldValue != null)
                                    {
                                        value = fieldValue.GetValue(value);
                                    }
                                }
                                else if (value is System.Collections.IList)
                                {
                                    System.Collections.IList list   = (System.Collections.IList)value;
                                    StringBuilder            sbList = new StringBuilder();
                                    foreach (object elem in list)
                                    {
                                        FieldInfo fieldName = elem.GetType().GetField("Name");
                                        if (fieldName != null)
                                        {
                                            object elemname = fieldName.GetValue(elem);
                                            if (elemname != null)
                                            {
                                                FieldInfo fieldValue = elemname.GetType().GetField("Value");
                                                if (fieldValue != null)
                                                {
                                                    object elemval = fieldValue.GetValue(elemname);
                                                    sbList.Append(elemval.ToString());
                                                }
                                            }
                                        }
                                        sbList.Append("; <br/>");
                                    }
                                    value = sbList.ToString();
                                }
                                else if (value is Type)
                                {
                                    value = ((Type)value).Name;
                                }

                                if (!String.IsNullOrEmpty(format))
                                {
                                    if (format.Equals("Required") && value == null)
                                    {
                                        includerow = false;
                                    }
                                }

                                if (value != null)
                                {
                                    FieldInfo fieldValue = value.GetType().GetField("Value");
                                    if (fieldValue != null)
                                    {
                                        value = fieldValue.GetValue(value);
                                    }

                                    if (format != null && format.Equals("True") && (value == null || !value.ToString().Equals("True")))
                                    {
                                        includerow = false;
                                    }

                                    if (value is Double)
                                    {
                                        sbRow.Append(" align=\"right\">");

                                        sbRow.Append(((Double)value).ToString("N3"));
                                    }
                                    else if (value is List <Int64> )
                                    {
                                        sbRow.Append(">");

                                        // latitude or longitude
                                        List <Int64> intlist = (List <Int64>)value;
                                        if (intlist.Count >= 3)
                                        {
                                            sbRow.Append(intlist[0] + "° " + intlist[1] + "' " + intlist[2] + "\"");
                                        }
                                    }
                                    else if (value != null)
                                    {
                                        sbRow.Append(">");
                                        sbRow.Append(value.ToString());                                         // todo: html-encode
                                    }
                                }
                                else
                                {
                                    sbRow.Append(">");
                                    sbRow.Append("&nbsp;");
                                }
                            }
                            else
                            {
                                sbRow.Append(">");
                            }

                            sbRow.Append("</td>");
                        }
                        sbRow.AppendLine("</tr>");

                        if (includerow)
                        {
                            sb.Append(sbRow.ToString());
                        }
                    }
                }
            }

            sb.AppendLine("</table>");
            sb.AppendLine("<br/>");

            return(sb.ToString());
        }