public MainWindow()
        {
            InitializeComponent();

            appModel = new AppModel();
            appModel.Entities = new List<Entity>();
            appModel.Navigation = new List<WireGenerator.Model.MenuItem>();

            List<string> schemaNames = new List<string>();
            schemaNames.Add("New Configuration...");

            string assemblyPath = System.Reflection.Assembly.GetAssembly(typeof(MainWindow)).Location;
            string assemblyFolderPath = System.IO.Path.GetDirectoryName(assemblyPath);
            foreach (string file in Directory.GetFiles(assemblyFolderPath))
            {
                string fileName = System.IO.Path.GetFileName(file);
                if (file.Contains("_appconfig.xml"))
                    schemaNames.Add(fileName.Substring(0, fileName.Length - 14));
            }

            cmbSchemaNames.ItemsSource = schemaNames;
            cmbSchemaNames.SelectedIndex = 0;
        }
        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        private StringBuilder ConstructPageNavigation()
        {
            xAppModal = new AppModel();
            xAppModal.Name = appConfig.Element("Name").Value;
            xAppModal.LoginUser = appConfig.Element("LoginUser").Value;

            //load the navigation
            IEnumerable<XElement> navMenuItems = from el in appConfig.Elements("Navigation").Elements("MenuItem") select el;
            WireGenerator.Model.MenuItem menuItem;
            xAppModal.Navigation = new List<WireGenerator.Model.MenuItem>();

            foreach (XElement el in navMenuItems.ToList())
            {
                menuItem = new WireGenerator.Model.MenuItem();
                menuItem.Name = el.Attribute("name").Value;
                menuItem.LinkToUrl = (el.Attribute("linkTo") != null) ? el.Attribute("linkTo").Value : string.Empty;
                menuItem.MenuSubItems = new List<MenuSubItem>();
                IEnumerable<XElement> menuSubItems = el.Descendants();
                foreach (XElement subel in menuSubItems)
                {
                    menuSubItem = new MenuSubItem();
                    menuSubItem.SubItem = subel.Value;
                    if (subel.HasAttributes)
                        menuSubItem.LinkToURL = subel.Attribute("linkTo").Value + "_list.html";
                    menuItem.MenuSubItems.Add(menuSubItem);
                }
                xAppModal.Navigation.Add(menuItem);
            }

            #region top nav menu
            content = content.Append("<nav id=\"NavBar\" class=\"navbar navbar-default navbar-fixed-top\" role=\"navigation\">");
            content = content.Append("<div class=\"container-fluid\">");
            content = content.Append("<div class=\"wmnavbar\">");
            content = content.Append("<div class=\"navbar-header\">");
            content = content.Append("<span type=\"button\" class=\"navbar-toggle\" data-toggle=\"collapse\" data-target=\"#bs-example-navbar-collapse-1\">");
            content = content.Append("<i class=\"fa fa-bars fa-lg\"></i>");
            content = content.Append("</span>");
            content = content.Append("<span id=\"appname\" class=\"navbar-brand brandfont\">" + xAppModal.Name + "</span>");
            content = content.Append("</div>");

            content = content.Append("<div class=\"collapse navbar-collapse\" id=\"bs-example-navbar-collapse-1\">");
            content = content.Append("<ul id=\"Ul2\" class=\"nav navbar-nav\">");
            counter = 1;
            foreach (var nav in xAppModal.Navigation)
            {
                if (!string.IsNullOrEmpty(nav.LinkToUrl))
                {
                    content = content.Append("<li id=\"home\"><a href=\"" + nav.LinkToUrl + "\">" + nav.Name + " </a>");
                }
                else
                {
                    content = content.Append("<li id=\"li" + counter + "\" class=\"dropdown\"><a class=\"dropdown-toggle\" data-hover=\"dropdown\" data-toggle=\"dropdown\" href=\"#\">" + nav.Name + " <b class=\"caret\"></b></a>");
                    content = content.Append("<ul class=\"dropdown-menu\">");
                    foreach (var submenu in nav.MenuSubItems)
                        content = content.Append("<li><a href=\"" + submenu.LinkToURL + "\"><i class=\"fa fa-list-alt fa-fw\"></i>&nbsp;" + submenu.SubItem + "</a></li>");
                    content = content.Append("</ul>");
                    content = content.Append("</li>");
                    counter++;
                }
            }
            content = content.Append("</ul>");
            #endregion

            #region user quick links
            content = content.Append("<ul class=\"nav navbar-nav navbar-right\">");
            content = content.Append("<li class=\"dropdown\">");
            content = content.Append("<a href=\"#\" class=\"dropdown-toggle\" data-hover=\"dropdown\" data-toggle=\"dropdown\">" + xAppModal.LoginUser + " <b class=\"caret\"></b></a>");
            content = content.Append("<ul class=\"dropdown-menu\">");
            content = content.Append("<li><a href=\"javascript:ShowBookmarks();\"><i class=\"fa fa-thumb-tack fa-fw\"></i>&nbsp;My Bookmarks</a></li>");
            content = content.Append("<li><a href=\"javascript:ShowChangeMyPassword();\"><i class=\"fa fa-key fa-fw\"></i>&nbsp;Change My Password</a></li>");
            content = content.Append("<li class=\"divider\"></li>");
            content = content.Append("<li><a href=\"javascript:LogOff();\"><i class=\"fa fa-sign-out fa-fw\"></i>&nbsp;Logout</a></li>");
            content = content.Append("</ul>");
            content = content.Append("</li>");
            content = content.Append("</ul>");
            content = content.Append("</div>");
            content = content.Append("</div>");
            content = content.Append("</div>");
            content = content.Append("</nav>");
            #endregion

            return content;
        }
        private void cmbSchemaNames_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (cmbSchemaNames.SelectedIndex == 0)
            {
                txtSchemaName.Text = "Enter Configuration Name";
                txtSchemaName.Visibility = System.Windows.Visibility.Visible;
                txtAppName.Clear();
                txtAppUserName.Clear();
            }
            else
                txtSchemaName.Visibility = System.Windows.Visibility.Hidden;

            if (cmbSchemaNames.SelectedIndex > 0)
            {
                string executableLocation = System.IO.Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
                appModel = new AppModel();
                appModel.Navigation = new List<WireGenerator.Model.MenuItem>();
                schemaName = cmbSchemaNames.SelectedItem.ToString();
                schemaAbsoluteFileName = System.IO.Path.Combine(executableLocation, cmbSchemaNames.SelectedItem.ToString() + "_appConfig.xml");
                if (File.Exists(schemaAbsoluteFileName))
                {
                    appConfig = XElement.Load(schemaAbsoluteFileName);
                    #region load appModel from xml configuration
                    if (!appConfig.IsEmpty)
                    {
                        txtAppName.Text = appConfig.Element("Name").Value;
                        txtAppUserName.Text = appConfig.Element("LoginUser").Value;

                        //navigation
                        var navigation = new XElement("Navigation");
                        TreeViewItem node, subnode;
                        WireGenerator.Model.MenuItem menuItem;
                        IEnumerable<XElement> navMenuItems = from el in appConfig.Elements("Navigation").Elements("MenuItem") select el;
                        if (navMenuItems.ToList().Count > 0)
                        {
                            foreach (XElement el in navMenuItems.ToList())
                            {
                                menuItem = new WireGenerator.Model.MenuItem();
                                menuItem.Name = el.Attribute("name").Value;
                                menuItem.LinkToUrl = (el.Attribute("linkTo") != null) ? el.Attribute("linkTo").Value : string.Empty;

                                node = new TreeViewItem();
                                if (string.IsNullOrEmpty(menuItem.LinkToUrl))
                                    node.Header = el.Attribute("name").Value;
                                else
                                    node.Header = el.Attribute("name").Value + "(" + menuItem.LinkToUrl + ")";
                                IEnumerable<XElement> menuSubItems = el.Descendants();
                                menuItem.MenuSubItems = new List<MenuSubItem>();
                                foreach (XElement subel in menuSubItems)
                                {
                                    menuSubItem = new MenuSubItem();
                                    menuSubItem.SubItem = subel.Value;
                                    menuSubItem.LinkToURL = (subel.Attribute("linkTo") != null) ? subel.Attribute("linkTo").Value : string.Empty;
                                    menuItem.MenuSubItems.Add(menuSubItem);

                                    subnode = new TreeViewItem();
                                    if (string.IsNullOrEmpty(menuSubItem.LinkToURL))
                                        subnode.Header = subel.Value;
                                    else
                                        if (menuSubItem.LinkToURL.Contains("_"))
                                            subnode.Header = subel.Value + " (" + (menuSubItem.LinkToURL).Substring(0, menuSubItem.LinkToURL.IndexOf("_")) + ")";
                                        else
                                            subnode.Header = subel.Value + " (" + (menuSubItem.LinkToURL) + ")";

                                    node.Items.Add(subnode);
                                }
                                NavigationTreeView.Items.Add(node);
                                appModel.Navigation.Add(menuItem);
                            }
                        }

                        //entities
                        IEnumerable<XElement> xEntities = from el in appConfig.Elements("Entities").Elements("Entity") select el;
                        appModel.Entities = new List<Entity>();
                        if (xEntities.ToList().Count > 0)
                        {
                            Entity entity;
                            Field field;
                            WorkflowPhase phase;
                            WireGenerator.Model.Action action;
                            WireGenerator.Model.Section section;
                            XElement xElement;
                            XAttribute xListFieldsHasSelector;
                            IEnumerable<XElement> xElements, xFields;
                            IEnumerable<XElement> xListFields;

                            foreach (XElement xEntity in xEntities.ToList())
                            {
                                entity = new Entity();
                                entity.Name = xEntity.Attribute("name").Value;
                                entity.Title = xEntity.Attribute("title").Value;
                                entity.HasSearch = (xEntity.Attribute("hasSearch").Value == "true") ? true : false;

                                //load list screen fields
                                xListFieldsHasSelector = (from a in xEntity.Elements("ListFields").Attributes("WithSelector") select a).FirstOrDefault();
                                if (xListFieldsHasSelector != null)
                                    entity.IsListScreenWithSelector = Convert.ToBoolean(xListFieldsHasSelector.Value);

                                entity.ListScreenFields = new List<Field>();
                                if (xEntity.Elements("ListFields").Count() > 0)
                                {
                                    xListFields = from a in xEntity.Elements("ListFields").Descendants() select a;
                                    foreach (XElement xListField in xListFields.ToList())
                                    {
                                        field = new Field();
                                        field.FieldName = xListField.Value;
                                        field.Index = Convert.ToInt32(xListField.Attribute("index").Value);
                                        field.DataType = Convert.ToInt32(xListField.Attribute("datatype").Value);
                                        entity.ListScreenFields.Add(field);
                                    }
                                }

                                //load list screen actions
                                entity.ListScreenActions = new List<WireGenerator.Model.Action>();
                                if (xEntity.Elements("ListActions").Count() > 0)
                                {
                                    xElements = from a in xEntity.Elements("ListActions").Descendants() select a;
                                    foreach (XElement xListAction in xElements)
                                    {
                                        action = new WireGenerator.Model.Action();
                                        action.ActionName = xListAction.Value;
                                        action.LinkTo = xListAction.Attribute("linkTo").Value;
                                        entity.ListScreenActions.Add(action);
                                    }
                                }

                                //load add screen sections and fields
                                if (xEntity.Elements("AddFields").Count() > 0)
                                {
                                    xElements = from a in xEntity.Elements("AddFields").Elements("Section") select a;
                                    entity.AddScreenSections = new List<WireGenerator.Model.Section>();
                                    foreach (XElement xSection in xElements)
                                    {
                                        section = new Model.Section();
                                        section.SectionId = Convert.ToInt32(xSection.Attribute("id").Value);
                                        section.SectionName = xSection.Attribute("name").Value;
                                        section.Zone = xSection.Attribute("zone").Value;

                                        xFields = from a in xSection.Descendants() select a;
                                        section.Fields = new List<Field>();
                                        foreach (XElement xfield in xFields)
                                        {
                                            field = new Model.Field();
                                            field.FieldName = xfield.Attribute("label").Value;
                                            field.Index = Convert.ToInt32(xfield.Attribute("index").Value);
                                            field.Type = Convert.ToInt32(xfield.Attribute("type").Value);
                                            section.Fields.Add(field);
                                        }
                                        entity.AddScreenSections.Add(section);
                                    }
                                }

                                //load workflow
                                entity.Workflow = new List<WorkflowPhase>();
                                if (xEntity.Elements("Workflow").Count() > 0)
                                {
                                    xElement = (from a in xEntity.Elements("Workflow") select a).FirstOrDefault();
                                    if (xElement != null)
                                    {
                                        entity.WorkflowAliasName = xElement.Attribute("name").Value;
                                        xElements = from a in xEntity.Elements("Workflow").Descendants() select a;
                                        foreach (XElement xPhase in xElements)
                                        {
                                            phase = new WorkflowPhase();
                                            phase.PhaseName = xPhase.Value;
                                            entity.Workflow.Add(phase);
                                        }
                                    }
                                }
                                appModel.Entities.Add(entity);
                                lstEntities.Items.Add(entity.Name);
                            }
                        }
                    }
                    #endregion
                }
            }
        }