master new

using System;

using System.Collections.Generic;

using System.Linq;

using System.Web;

using System.Web.UI;

using System.Web.UI.WebControls;

using System.IO;

using System.Net;

using System.Text.RegularExpressions;

namespace FusionChartTest
{

    public partial class SiteMaster : System.Web.UI.MasterPage
    {

        protected void Page_Load(object sender, EventArgs e)
        {

            string current_file = Path.GetFileName(Request.Path); ///Path.GetFileName(Request.Path);




            if (current_file == "default.aspx" || current_file == "Default.aspx")
            {
                //string inputString;

                string[] lines1 = System.IO.File.ReadAllLines(Server.MapPath("~") + @"\sitemap.ini").Where(s => s.Trim() != string.Empty).ToArray();

                foreach (string linetext in lines1)
                {

                    string[] Content = linetext.Split('|');
                    string tag = Content[0].Substring(0, 2);



                    //index will get increase if the first position will not start with the - sign
                    if (Content[0].IndexOf('-') == -1)
                    {

                        string str = " ";
                        Label99.Text += str + "";
                    }

                }

            }

            // at first time load only the main menu item(parent)




            else
            {



                string parent = "";
                string child = "";
                string temp_parent = "";
                string temp_child = "";

                System.Diagnostics.Debug.WriteLine("filename: " + current_file);

                string[] filename_ini = this.show_parent_nodes("sitemap.ini", current_file);
                System.Diagnostics.Debug.WriteLine("filename_ini.Length : " + filename_ini);
                foreach (string name in filename_ini)
                {


                    if (name != null)
                    {
                        string[] datas = name.Split('|');
                        if (datas[0].Substring(0, 1) != "-")
                        {
                            parent = datas[1].Trim();
                        }
                        if (datas[0].Substring(0, 1) == "-")
                        {
                            child = datas[1].Trim();
                        }
                    }
                    //System.Diagnostics.Debug.WriteLine("got name: " + name);
                    System.Diagnostics.Debug.WriteLine("MAin parent: " + parent);
                    System.Diagnostics.Debug.WriteLine("mAin child: " + child);
                }

                //string[] lines = System.IO.File.ReadAllLines(Server.MapPath("~") + @"\sitemap.ini").Where(s => s.Trim() != string.Empty).ToArray();
                string[] lines = System.IO.File.ReadAllLines(@Server.MapPath("~") + @"\sitemap.ini");
                // int window_blank = 0;

                string nav_subject = "";

                string nav_link = "";

                string submenu_link = "";

                string menu_link = "";

                string div = "";


                foreach (string linetext in lines)
                {

                    //Kommentare und Leerzeilen auslassen

                    //string line = linetext.Substring(0,-1);
                    string line = linetext;

                    if (line.Length > 2)
                    {

                        //echo $line."";

                        string line_cleaned = Regex.Replace(line, "^-|^--|^---", "");
                        line_cleaned = Regex.Replace(line_cleaned, "^-|^--|^---", "");


                        //Seitentitel/Title

                        if (line.IndexOf('|') != 0)
                        {
                            string[] Content = line_cleaned.Split('|');
                            nav_subject = Content[0];
                        }
                        else
                        {
                            nav_subject = line_cleaned;
                        }
                        //System.Diagnostics.Debug.WriteLine("nav_subject: " + nav_subject);

                        //Link auslesen/llink
                        if (line.IndexOf('|') != 0)
                        {
                            string[] Content = line_cleaned.Split('|');
                            nav_link = Content[1];
                        }
                        else
                        {
                            nav_link = "#";
                        }
   

                        //Link für Submenü zusammenbauen
                        if (nav_link == "#")
                            submenu_link = "
";
                        else
                        {
                            if (line.Substring(0, 3) == "---")
                            {
                                submenu_link = "
" + div + "" + "\n";
                            }
                            else
                            {
                                submenu_link = "
" + "\n";
                            }
                        }

                        //System.Diagnostics.Debug.WriteLine("parent: " +parent);
                        //System.Diagnostics.Debug.WriteLine("nav_link: " + nav_link.Trim());

                        //1. Ebene
                        if (line.Substring(0, 1) != "-")
                        {

                            if (current_file == nav_link.Trim() || parent.Equals(nav_link.Trim()))
                            {
                                menu_link += "
";
                            }
                            else
                            {
                                menu_link += " ";
                            }

                        }


                        //2. Ebene
                        if (line.Substring(0, 1) == "-" && linetext.Substring(1, 1) != "-")
                        {
                            temp_parent = this.parent(nav_link);
                            /*
                            string datas = this.child(nav_link);
                            string[] Content = datas.Split('@');
                            temp_parent = Content[0];
                            temp_child = temp_parent = Content[1];
                           
                            System.Diagnostics.Debug.WriteLine("temp_parent^^^^^^^^^^^^^^> " + temp_parent);
                            System.Diagnostics.Debug.WriteLine("parent^^^^^^^^^^^^^^> " + parent);
                            System.Diagnostics.Debug.WriteLine("child^^^^^^^^^^^^^^> " + child);
                            System.Diagnostics.Debug.WriteLine("current file^^^^^^^^^^^^^^> " + current_file);
                            System.Diagnostics.Debug.WriteLine("nav link^^^^^^^^^^^^^^> " + nav_link);
                            */


                            if (parent == "")
                            {

                                if (parent == temp_parent || temp_parent == current_file)
                                {
                                    menu_link += " ";
                                }
                            }
                            else{
                               
                                //menu_link = "";

                                if (parent == temp_parent && current_file == nav_link)
                                {
                                    menu_link += " ";
                                }
                                else if (parent == temp_parent)
                                {
                                    menu_link += " ";
                                }
                            }

                        }

                        //3. Ebene

                        if (line.Substring(0, 2) == "--")
                        {


                            string datas = this.child(nav_link);
                            string[] Content = datas.Split('@');
                            temp_parent = Content[0];
                            temp_child = temp_parent = Content[1];
                           
                            string temp_parent1 = this.parent(nav_link);
                           
                            /*
                            System.Diagnostics.Debug.WriteLine("parent^^^^^^^^^^^^^^> " + parent+"\n");
                            System.Diagnostics.Debug.WriteLine("temp_parent^^^^^^^^^^^^^^> " + temp_parent + "\n");
                            System.Diagnostics.Debug.WriteLine("again temp_parent1^^^^^^^^^^^^^^> " + temp_parent1 + "\n");

                            System.Diagnostics.Debug.WriteLine("child^^^^^^^^^^^^^^> " + child + "\n");
                            System.Diagnostics.Debug.WriteLine("temp_child^^^^^^^^^^^^^^> " + temp_child + "\n");

                            System.Diagnostics.Debug.WriteLine("current file^^^^^^^^^^^^^^> " + current_file + "\n");
                            System.Diagnostics.Debug.WriteLine("nav link^^^^^^^^^^^^^^> " + nav_link + "\n");
                            */

                            if (child == "")
                            {

                                if (parent.Trim().Equals(temp_parent1.Trim()) && current_file.Trim().Equals(temp_child.Trim()) && current_file.Trim().Equals((nav_link.Trim())))
                                {
                                    menu_link += " ";
                                }
                                else if (parent.Trim().Equals(temp_parent1.Trim()) && current_file.Trim().Equals(temp_child.Trim()))
                                {
                                    menu_link += " ";
                                }
                            }
                            else {
                                if (child.Equals(temp_child) && parent.Equals(temp_parent1) && current_file.Equals(nav_link))
                                {
                                   menu_link += " ";
                                }
                                else if (child.Equals(temp_child) && parent.Equals(temp_parent1))
                                {
                                    menu_link += " ";
                                }
                            }

                        }




                    }

                }

                //navi +=  node_active?submenu:"";
                Label99.Text = menu_link;
                System.Diagnostics.Debug.WriteLine("Menu: " + menu_link);
                /*

                string[] filename_ini = this.show_parent_nodes("sitemap.ini", "d_cert.aspx");

                foreach (string name in filename_ini)
                {
                    System.Diagnostics.Debug.WriteLine("name :" + name);
                }
                  */
                //int level = this.show_level("--default");
                //System.Diagnostics.Debug.WriteLine("the filenameLast: " + filenameLast);

            }
        }


        public int show_level(string file)
        {

            int ebene = 0;

            //for the first lavel
            if (file.Substring(0, 1) != "-") ebene = 1;

            //for the 2nd lavel
            else if (file.Substring(0, 1) == "-" && file.Substring(1, 1) != "-") ebene = 2;

            //for the 3rd lavel
            else if (file.Substring(0, 2) == "--") ebene = 3;

            else if (file.Substring(0, 3) == "---") ebene = 4;

            return ebene;

        }



        //predecessor of the active node output (over: navigation array with level as index)

        public string[] show_parent_nodes(string sitemapFile, string current_file)
        {

            //intialize

            string sitemap = sitemapFile;

            int level = 0;

            int counter = 0;

            int current_level = 0;

            //string[] filename_ini;

            //string file_name_last = "";

            int i = 0;
            int haltpos = 0;


            //string[] file = System.IO.File.ReadAllLines(Server.MapPath("~") + @sitemapFile).Where(s => s.Trim() != string.Empty).ToArray();
            string[] file = System.IO.File.ReadAllLines(@Server.MapPath("~") + @sitemapFile);
            //string file = file(sitemap);

            current_file = current_file.Replace("/", "/");

            current_file = current_file.Replace("?", "?");





            foreach (string row in file)
            {

                if (row.Length > 2)
                {

                    if (Regex.IsMatch("|" + current_file.Trim() + "$/", row.Trim()))
                    {

                        //$treffer = $row;

                        break;

                    }

                } i++;

            }

            haltpos = i;
            //System.Diagnostics.Debug.WriteLine("halting pos :" + i);

            string[] filename_ini;
            filename_ini = new string[10];
            //string[] filename_ini;
            //filename_ini = new string[10];
            level = this.show_level(file[i]);
            counter = level;
            //System.Diagnostics.Debug.WriteLine("the counter :" + counter);
            //$filename_ini[$level] = trim($file[$i]);
           
            for(int d=1;d                for(int k =i;k>0;k--){
                   
                    if(file[k].Substring(0,1) != "#" && file[k].Length > 2){
                        current_level = show_level(file[k]);
                        if(current_level                            filename_ini[current_level] = file[k].Trim();
                            level = current_level;
                            break;
                        }
                    }
                }
            }

            return filename_ini.ToArray();

        }


        public string parent(string data) {
       
            string parentName = "";
           // int i = 0;
            string[] lines = System.IO.File.ReadAllLines(Server.MapPath("~") + @"sitemap.ini").Where(s => s.Trim() != string.Empty).ToArray();
            foreach(string line in lines){

                    string[] content = line.Split('|');
                    if (content[0].Substring(0,1) !="-") {
                        parentName = content[1];
                    }
                    if (data == content[1])
                    {
                       // parentName = content[1];
                        return parentName;
                    }
               
            }

            return parentName;
        }


        public string child(string data)
        {

            string parentName = "";
            string child = "";
            // int i = 0;
            string[] lines = System.IO.File.ReadAllLines(Server.MapPath("~") + @"sitemap.ini").Where(s => s.Trim() != string.Empty).ToArray();
            foreach (string line in lines)
            {

                string[] content = line.Split('|');
                if (content[0].Substring(0, 1) != "-")
                {
                    parentName = content[1];
                }
                if (content[0].Substring(0, 1) == "-" && content[0].Substring(1, 1) != "-")
                {
                    child = content[1];
                }
                if (data == content[1])
                {
                    // parentName = content[1];
                    return parentName +"@"+child;
                }

            }

            return parentName;
        }


    }

}

Comments

Popular posts from this blog

like php