示例#1
0
 public void ParseGroupCode(DXFDocument doc, int groupcode, string value)
 {
     if (tablehandlers.Count == 0)
     {
         foreach (PropertyInfo info in doc.Tables.GetType().GetProperties(BindingFlags.Public | BindingFlags.Instance))
         {
             object[] attrs = info.GetCustomAttributes(true);
             foreach (object attr in attrs)
             {
                 TableAttribute casted = attr as TableAttribute;
                 if (casted != null)
                 {
                     tablehandlers[casted.TableName] = (ISectionParser)Activator.CreateInstance(casted.TableParser);
                 }
             }
         }
     }
     if (currentParser == null)
     {
         if (groupcode == 0 && value.Trim() == "TABLE")
         {
             waitingtableheader = true;
         }
         else if (waitingtableheader && groupcode == 2 && !ignoretable)
         {
             if (tablehandlers.ContainsKey(value.Trim()))
             {
                 currentParser      = tablehandlers[value.Trim()];
                 waitingtableheader = false;
                 ignoretable        = false;
                 firstrecordfound   = false;
             }
             else
             {
                 //TODO: generate warning
                 ignoretable = true;
             }
         }
         else if (waitingtableheader && groupcode == 0 && value.Trim() == "ENDTAB")
         {
             waitingtableheader = false;
             ignoretable        = false;
         }
     }
     else
     {
         if (groupcode == 0 && value.Trim() == "ENDTAB")
         {
             currentParser = null;
         }
         else
         {
             if (groupcode == 0)
             {
                 firstrecordfound = true;
             }
             if (firstrecordfound)
             {
                 currentParser.ParseGroupCode(doc, groupcode, value);
             }
         }
     }
 }
示例#2
0
        public void Load(Stream file)
        {
            CultureInfo currentCulture = Thread.CurrentThread.CurrentCulture;

            Thread.CurrentThread.CurrentCulture = CultureInfo.GetCultureInfo("en-US");
            bool versionwarningsent = false;

            Dictionary <string, ISectionParser> sectionparsers = new Dictionary <string, ISectionParser>();

            sectionparsers["HEADER"]   = new HeaderParser();
            sectionparsers["CLASSES"]  = new ClassParser();
            sectionparsers["TABLES"]   = new TableParser();
            sectionparsers["ENTITIES"] = new EntityParser();
            sectionparsers["BLOCKS"]   = new BlockParser();
            ISectionParser currentParser = null;

            TextReader reader = new StreamReader(file);
            LoadState  state  = LoadState.OutsideSection;
            int?       groupcode;
            string     value;

            reader.ReadDXFEntry(out groupcode, out value);
            while (groupcode != null)
            {
                switch (state)
                {
                case LoadState.OutsideSection:
                    if (groupcode == 0 && value.Trim() == "SECTION")
                    {
                        state = LoadState.InSection;
                        reader.ReadDXFEntry(out groupcode, out value);
                        if (groupcode != 2)
                        {
                            throw new Exception("Sektion gefunden aber keinen Namen zur Sektion");
                        }
                        value = value.Trim();
                        if (sectionparsers.ContainsKey(value))
                        {
                            currentParser = sectionparsers[value];
                        }
                    }
                    break;

                case LoadState.InSection:
                    if (groupcode == 0 && value.Trim() == "ENDSEC")
                    {
                        state = LoadState.OutsideSection;
                        //after each section check wether the File Version is set
                        if (Header.AutoCADVersion != null &&
                            Header.AutoCADVersion != "AC1014")
                        {
                            if (!versionwarningsent)
                            {
                                try
                                {
                                    if (OnFileVersionIncompatible != null)
                                    {
                                        OnFileVersionIncompatible(this, EventArgs.Empty);
                                    }
                                }
                                catch (Exception)
                                {
                                }
                                versionwarningsent = true;
                            }
                        }
                    }
                    else
                    {
                        if (currentParser != null)
                        {
                            currentParser.ParseGroupCode(this, (int)groupcode, value);
                        }
                    }
                    break;

                default:
                    break;
                }
                reader.ReadDXFEntry(out groupcode, out value);
            }
            if (state == LoadState.InSection)
            {
                throw new Exception("Dateiende erreicht aber immer noch offene Sektion vorhanden");
            }
            Thread.CurrentThread.CurrentCulture = currentCulture;
        }