Esempio n. 1
0
        private static void ParseStepFile(string fileInput, ref int countSuccess)
        {
            string fileName = string.Empty;

            try
            {
                string fullPath = Path.GetFullPath(fileInput);
                string onlyPath = Directory.GetParent(fullPath).FullName;
                fileName = Path.GetFileNameWithoutExtension(fileInput);
                Console.WriteLine("\nLoading STP file... " + fileName);
                LogWriter.Instance.ParsingFileName = fileInput;
                LogWriter.Instance.WriteInfoLog("Loading STP file... " + fileName);
                StepFile stepFile;
                using (FileStream fs = new FileStream(fullPath, FileMode.Open, FileAccess.Read))
                {
                    stepFile = StepFile.Load(fs);
                }

                XmlDocument doc     = new XmlDocument();
                XmlNode     docNode = doc.CreateXmlDeclaration("1.0", "UTF-8", null);

                Console.WriteLine("Writing XML file...");
                XmlWriterSettings settings = new XmlWriterSettings
                {
                    ConformanceLevel   = ConformanceLevel.Auto,
                    Indent             = true,
                    IndentChars        = "    ",
                    OmitXmlDeclaration = false,
                    CloseOutput        = false,
                    Encoding           = Encoding.UTF8
                };
                XmlWriter  xmlWriter  = XmlWriter.Create(onlyPath + "/" + fileName + ".xml", settings);
                StepWriter stepWriter = new StepWriter(stepFile, false, xmlWriter);

                xmlWriter.WriteStartDocument(true);
                xmlWriter.WriteStartElement("STP");
                stepWriter.Save();
                xmlWriter.WriteEndElement();
                xmlWriter.WriteEndDocument();

                xmlWriter.Flush();
                xmlWriter.Close();

                Console.WriteLine("Success!");
                LogWriter.Instance.WriteInfoLog("Success!");
                countSuccess++;
            }
            catch (Exception ex)
            {
                _failedFiles.Add(fileName);
                LogWriter.Instance.WriteErrorLog(ex);
                Console.WriteLine("Failed to parse file " + fileName + " " + ex.Message);
            }
        }
Esempio n. 2
0
        public StepReader(Stream stream)
        {
            _file = new StepFile();
            var tokenizer = new StepTokenizer(stream);

            _lexer = new StepLexer(tokenizer.GetTokens());
            if (tokenizer.IsFailed)
            {
                throw new Exception($"Unexpected parse character");
            }
        }
Esempio n. 3
0
        static void Main(string[] args)
        {
            if (args.Length > 0)
            {
                if (File.Exists(args[0]))
                {
                    string fullPath = Path.GetFullPath(args[0]);
                    string onlyPath = Directory.GetParent(fullPath).FullName;
                    string fileName = Path.GetFileNameWithoutExtension(args[0]);
                    Console.WriteLine("Loading STP file...");
                    StepFile stepFile;
                    using (FileStream fs = new FileStream(fullPath, FileMode.Open))
                    {
                        stepFile = StepFile.Load(fs);
                    }

                    XmlDocument doc     = new XmlDocument();
                    XmlNode     docNode = doc.CreateXmlDeclaration("1.0", "UTF-8", null);

                    Console.WriteLine("Writing XML file...");
                    XmlWriterSettings settings = new XmlWriterSettings
                    {
                        ConformanceLevel   = ConformanceLevel.Fragment,
                        Indent             = true,
                        IndentChars        = "    ",
                        OmitXmlDeclaration = false,
                        CloseOutput        = false,
                        Encoding           = Encoding.Unicode
                    };
                    XmlWriter  xmlWriter  = XmlWriter.Create(onlyPath + "/" + fileName + ".xml", settings);
                    StepWriter stepWriter = new StepWriter(stepFile, false, xmlWriter);
                    stepWriter.Save();

                    xmlWriter.Flush();
                    xmlWriter.Close();

                    Console.WriteLine("Success!");
                }
                else
                {
                    Console.WriteLine("File Not Exists");
                }
            }
            else
            {
                Console.WriteLine("No STP File found");
            }
        }
Esempio n. 4
0
        public StepWriter(StepFile stepFile, bool inlineReferences, XmlWriter xmlWriter)
        {
            try
            {
                _file             = stepFile;
                _itemMap          = new Dictionary <StepRepresentationItem, int>();
                _inlineReferences = inlineReferences;
                _xmlWriter        = xmlWriter;

                SetRelationShip();
            }
            catch (Exception ex)
            {
                LogWriter.Instance.WriteErrorLog(ex);
            }
        }