Ejemplo n.º 1
0
        internal void updateVariables()
        {
            try
            {
                string          xmlname       = beamproperties.xmfile;
                string          projectFolder = new DirectoryInfo(Environment.CurrentDirectory).Parent.Parent.FullName;
                string          xmlfile       = System.IO.Path.Combine(projectFolder, "DB") + "\\" + xmlname + "-PROFILES.xml";
                XmlDataDocument xmldoc        = new XmlDataDocument();
                XmlNodeList     xmlnode;
                int             i = 0;
                //FileStream fs = new FileStream(xmlfile, FileMode.Open, FileAccess.Read);

                //string str = null;
                using (FileStream fs = new FileStream(xmlfile, FileMode.Open, FileAccess.Read))
                {
                    xmldoc.Load(fs);
                    xmlnode = xmldoc.GetElementsByTagName("ProfileNames");
                    dict    = new Dictionary <string, List <ProfileNames> >();
                    for (i = 0; i <= xmlnode.Count - 1; i++)
                    {
                        xmlnode[i].ChildNodes.Item(0).InnerText.Trim();
                        //str = xmlnode[i].ChildNodes.Item(0).InnerText.Trim() + "  " + xmlnode[i].ChildNodes.Item(1).InnerText.Trim() + "  " + xmlnode[i].ChildNodes.Item(2).InnerText.Trim();
                        //MessageBox.Show(str);
                        ProfileName = xmlnode[i].ChildNodes.Item(0).InnerText.Trim();
                        Ht          = xmlnode[i].ChildNodes.Item(1).InnerText.Trim();
                        Wd          = xmlnode[i].ChildNodes.Item(2).InnerText.Trim();
                        webthk      = xmlnode[i].ChildNodes.Item(3).InnerText.Trim();
                        flangethk   = xmlnode[i].ChildNodes.Item(4).InnerText.Trim();
                        wt          = xmlnode[i].ChildNodes.Item(5).InnerText.Trim();

                        var ProfileNames = new ProfileNames {
                            ProfileName = ProfileName, Height = Ht, Width = Wd, Flange_thickness = flangethk, weight_per_unit_length = wt, Web_thickness = webthk
                        };
                        pflist = new List <ProfileNames>();
                        pflist.Add(ProfileNames);

                        dict.Add(ProfileName, pflist);
                    }
                }
            }
            catch (Teigha.Runtime.Exception ex)
            {
                IntelliCAD.ApplicationServices.Application.ShowAlertDialog(ex.ToString());
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// reads the xml file and appends the profileNames list
        /// </summary>
        /// <param name="xmlfile"></param>

        public void ReadXmlProfiles(string xmlfile)
        {
            try
            {
                bool wbool = false;

                pflist = new List <ProfileNames>();
                using (XmlReader reader = XmlReader.Create(@xmlfile))
                {
                    while (reader.Read())
                    {
                        if (reader.IsStartElement())
                        {
                            switch (reader.Name.ToString())
                            {
                            case "ProfileName":
                                ProfileName = reader.ReadString();
                                break;

                            case "Height":
                                Ht = reader.ReadString();
                                break;

                            case "Width":
                                Wd = reader.ReadString();
                                break;

                            case "Web_thickness":
                                webthk = reader.ReadString();
                                break;

                            case "Flange_thickness":
                                flangethk = reader.ReadString();
                                break;

                            case "weight_per_unit_length":
                                wt    = reader.ReadString();
                                wbool = true;
                                break;
                            }
                        }
                        if (wbool == true)
                        {
                            wbool = false;
                            var ProfileNames = new ProfileNames {
                                ProfileName = ProfileName, Height = Ht, Width = Wd, Flange_thickness = flangethk, weight_per_unit_length = wt, Web_thickness = webthk
                            };
                            pflist.Add(ProfileNames);
                            ProfileName = "";
                            Ht          = "";
                            Wd          = "";
                            flangethk   = "";
                            webthk      = "";
                        }
                    }
                }
            }
            catch (Teigha.Runtime.Exception ex)
            {
                IntelliCAD.ApplicationServices.Application.ShowAlertDialog(ex.ToString());
            }
            catch (System.Exception e)
            {
                Console.WriteLine("{0} Exception caught.", e);
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// This command is used to write xml files
        /// </summary>

        private void readProfile(string textFile)
        {
            try
            {
                string[] lines = File.ReadAllLines(textFile);

                string pfname = "";
                string ht     = "";
                string wd     = "";
                string fthk   = "";
                string wt     = "";
                string webthk = "";
                bool   wbool  = false;
                pflist = new List <ProfileNames>();
                foreach (string line in lines)
                {
                    if (line.StartsWith("PROFILE_NAME") == true)
                    {
                        string[] contents = line.Split(new char[] { '"' });
                        pfname = contents[1];
                    }
                    if (line.Contains("\"HEIGHT\"") == true)
                    {
                        string[] contents = line.Split(new char[] { ' ' });
                        ht = contents[contents.Length - 1];
                    }
                    if (line.Contains("\"WIDTH\"") == true)
                    {
                        string[] contents = line.Split(new char[] { ' ' });
                        wd = contents[contents.Length - 1];
                    }
                    if (line.Contains("\"WEB_THICKNESS\"") == true)
                    {
                        string[] contents = line.Split(new char[] { ' ' });
                        webthk = contents[contents.Length - 1];
                    }
                    if (line.Contains("\"FLANGE_THICKNESS\"") == true)
                    {
                        string[] contents = line.Split(new char[] { ' ' });
                        fthk = contents[contents.Length - 1];
                    }
                    if (line.Contains("\"WEIGHT_PER_UNIT_LENGTH\"") == true)
                    {
                        string[] contents = line.Split(new char[] { ' ' });
                        wt    = contents[contents.Length - 1];
                        wbool = true;
                    }
                    if (wbool == true)
                    {
                        wbool = false;
                        var ProfileNames = new ProfileNames {
                            ProfileName = pfname, Height = ht, Width = wd, Flange_thickness = fthk, weight_per_unit_length = wt, Web_thickness = webthk
                        };
                        pflist.Add(ProfileNames);
                    }
                }

                char[] charsToTrim = { '.', 'l', 'i', 's' };
                string xmlFile     = Path.Combine(textFile.TrimEnd(charsToTrim)) + ".xml";
                using (FileStream fs = new FileStream(xmlFile, FileMode.Create))
                {
                    new XmlSerializer(typeof(List <ProfileNames>)).Serialize(fs, pflist);
                }
            }
            catch (Teigha.Runtime.Exception ex)
            {
                IntelliCAD.ApplicationServices.Application.ShowAlertDialog(ex.ToString());
            }
            catch (System.Exception e)
            {
                Console.WriteLine("{0} Exception caught.", e);
            }
        }