Exemplo n.º 1
0
        public void createJSTreeModel(XElement xelementItem, JsTreeModel jstreeItemchild)
        {
            XElement XFolderItem = xelementItem.Element("folder");
            string   ItemName    = string.Empty;

            jstreeItemchild.children = new List <JsTreeModel>();
            if (XFolderItem != null)
            {
                ItemName = XFolderItem.Attribute("name").Value;
                JsTreeModel JsTreeFolder = new JsTreeModel();
                JsTreeFolder.attr = new JsTreeAttribute {
                    name = ItemName
                };
                jstreeItemchild.children.Add(JsTreeFolder);
                createJSTreeModel(XFolderItem, jstreeItemchild);
            }
            else
            {
                XElement XFilItem = xelementItem.Element("file");
                if (XFilItem != null)
                {
                    ItemName = XFilItem.Attribute("name").Value;
                    JsTreeModel JsTreeFolder = new JsTreeModel();
                    JsTreeFolder.attr = new JsTreeAttribute {
                        name = ItemName
                    };
                    jstreeItemchild.children.Add(JsTreeFolder);
                }
            }
        }
        public void CreateList(DirectoryInfo DirInfo, JsTreeModel jsmaintree)
        {
            jsmaintree.children = new List <JsTreeModel>();
            System.IO.FileInfo[]      fileInfo = DirInfo.GetFiles();
            System.IO.DirectoryInfo[] dirInfo  = DirInfo.GetDirectories();
            if (fileInfo.Length > 0)
            {
                foreach (System.IO.FileInfo file in fileInfo)
                {
                    JsTreeModel jsChildItem = new JsTreeModel();
                    jsChildItem.attr = new JsTreeAttribute()
                    {
                        title = file.Name
                    };

                    //jsChildItem.title = file.Name;
                    jsmaintree.children.Add(jsChildItem);
                }
            }
            if (dirInfo.Length > 0)
            {
                foreach (System.IO.DirectoryInfo dir in dirInfo)
                {
                    JsTreeModel jsChildItem = new JsTreeModel();
                    jsChildItem.attr = new JsTreeAttribute()
                    {
                        title = dir.Name
                    };
                    //jsChildItem.title = dir.Name;
                    jsmaintree.children.Add(jsChildItem);
                    CreateList(dir, jsChildItem);
                }
            }
        }
        public string HelloWorld(string id)
        {
            var tree = new JsTreeModel[]
            {
                new JsTreeModel
                {
                    text = "Confirm Application",
                    attr = new JsTreeAttribute {
                        id = "10", selected = true
                    }
                }
            };

            return(new JavaScriptSerializer().Serialize(tree));
        }
Exemplo n.º 4
0
        void Process(XElement element, int depth, JsTreeModel jstree)
        {
            // For simplicity, argument validation not performed
            jstree.children = new List <JsTreeModel>();
            if (!element.HasElements)
            {
                // element is child with no descendants
                JsTreeModel jsTreeFileItem = new JsTreeModel();
                jsTreeFileItem.attr = new JsTreeAttribute {
                    type = "File", name = element.Attribute("name").Value
                };
                jstree.children.Add(jsTreeFileItem);
            }
            else
            {
                // element is parent with children
                depth++;
                JsTreeModel jsTreeFolderItem = new JsTreeModel();
                if (element.Attribute("name") != null)
                {
                    jsTreeFolderItem.attr = new JsTreeAttribute {
                        type = "folder", name = element.Attribute("name").Value
                    }
                }
                ;
                else
                {
                    jsTreeFolderItem.attr = new JsTreeAttribute {
                        type = "folder", name = "root"
                    }
                };

                foreach (var child in element.Elements())
                {
                    Process(child, depth, jsTreeFolderItem);
                }
                parentjstree.children.Add(jsTreeFolderItem);
                jstree.children.Add(jsTreeFolderItem);
                depth--;
            }
        }
Exemplo n.º 5
0
        private void GetResourceList(JsTreeModel jsMaintree)
        {
            XDocument       xdoc          = XDocument.Load(@"D:\Workarea\SB-709\ResourceList_new.xml");
            XElement        newDoc        = new XElement("root");
            List <XElement> existingNodes = xdoc.Element("resources").Elements("resource").ToList <XElement>();              //ToList<XElement>();

            existingNodes = existingNodes.OrderByDescending(e => (int)e.Attribute("path").Value.Split('/').Length).ToList(); //ordered in descending order of no of subfolders in the path

            XElement    currentNode      = null;
            bool        init             = false;
            JsTreeModel jsMainFolderItem = new JsTreeModel();
            JsTreeModel jsFolderItem     = null;
            JsTreeModel jsSubFolderItem  = null;

            foreach (XElement node in existingNodes)
            {
                int    len            = node.Attribute("path").Value.LastIndexOf("/");
                string foldername     = node.Attribute("path").Value.Substring(0, len);
                string lastFolderName = foldername.Split('/').Last();

                if (foldername.Split('/').Count() > 1 && init == false)
                {
                    jsMainFolderItem.children = new List <JsTreeModel>();
                    jsFolderItem = new JsTreeModel();
                    init         = true;
                    foreach (string fold in foldername.Split('/'))
                    {
                        jsSubFolderItem = new JsTreeModel();
                        XElement xfolder = new XElement("folder", new XAttribute("name", fold));
                        if (currentNode == null)
                        {
                            newDoc.Add(xfolder);
                        }
                        else
                        {
                            currentNode.Add(xfolder);
                        }

                        jsSubFolderItem.attr = new JsTreeAttribute {
                            name = fold, type = "folder",
                        };
                        jsFolderItem.children = new List <JsTreeModel>();
                        jsFolderItem.children.Add(jsSubFolderItem);
                        jsFolderItem = jsSubFolderItem;
                        currentNode  = xfolder;
                        //jsMainFolderItem.children.Add(jsFolderItem);
                    }
                }
                string   filename = node.Attribute("path").Value.Substring(len + 1);
                XElement folder   = GetParentFolder(foldername.Split('/'), newDoc);
                if (folder == null)
                {
                    folder = new XElement("folder", new XAttribute("name", foldername));
                    //jsFolderItem.attr = new JsTreeAttribute { name = foldername, type = "folder", };
                    currentNode.Add(folder);
                }
                JsTreeModel jsFileItem = new JsTreeModel();
                jsFolderItem.children = new List <JsTreeModel>();
                jsFileItem.attr       = new JsTreeAttribute {
                    name = filename, type = "file"
                };
                jsFolderItem.children.Add(jsFileItem);

                XElement file = new XElement("file", new XAttribute("name", filename));
                file.Add(new XAttribute("path", node.Attribute("path").Value));
                folder.Add(file);
                currentNode = folder;

                /*if (jsFolderItem.children.Count > 0)
                 * {
                 *  jsMaintree = jsFolderItem;
                 *  parentjstree.children.Add(jsFolderItem);
                 * }*/
            }
            newDoc.Save(@"D:\Workarea\SB-709\new_resourseList1.xml");
            XmlDocument doc = new XmlDocument();

            doc.Load(@"D:\Workarea\SB-709\new_resourseList1.xml");
        }
        public void listHTTPDirectory(string url, JsTreeModel jsmaintree)
        {
            jsmaintree.children = new List <JsTreeModel>();
            counter             = 0;
            string         strURL  = url;
            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);

            request.Credentials = new NetworkCredential("root/pxmigration", "Px-Migration-123");
            HttpWebResponse response       = (HttpWebResponse)request.GetResponse();
            Stream          responseStream = response.GetResponseStream();
            StreamReader    reader         = new StreamReader(responseStream);
            string          html           = reader.ReadToEnd();
            Regex           regex          = new Regex(GetDirectoryListingRegexForUrl(url));
            MatchCollection matches        = regex.Matches(html);

            if (matches.Count > 0)
            {
                foreach (Match match in matches)
                {
                    if (match.Success)
                    {
                        //if ((!match.ToString().Contains("Content")) && (!match.ToString().Contains("text/html")) &&  (!match.ToString().Contains("PX_Registry_Filestore_TEST")))
                        if (counter > 2)
                        {
                            string dirName = match.ToString();
                            //dirName=dirName.Remove(0,2);
                            string finalString = string.Empty;
                            //lstbox.Items.Add(dirName);
                            if (!match.ToString().Contains('.'))
                            {
                                //finalString=dirName.Remove(dirName.Length - 2, 2);
                                finalString = replaceFolderString(dirName);
                                strURL      = "http://192.168.78.89/" + finalString;
                                JsTreeModel jsChildItem = new JsTreeModel();
                                jsChildItem.attr = new JsTreeAttribute()
                                {
                                    title = finalString.Replace("PX_Registry_Filestore_TEST//QTI", ""), id = 1
                                };
                                //jsChildItem.title = dir.Name;
                                jsmaintree.children.Add(jsChildItem);
                                listHTTPDirectory(strURL, jsChildItem);
                            }
                            else
                            {
                                finalString = replaceFileString(dirName);
                                //finalString = finalString.Replace("PX_Registry_Filestore_TEST/QTI/", "");
                                JsTreeModel jsChildItem = new JsTreeModel();
                                jsChildItem.attr = new JsTreeAttribute()
                                {
                                    title = finalString, id = 0
                                };

                                //jsChildItem.title = file.Name;

                                jsmaintree.children.Add(jsChildItem);
                            }
                        }
                        counter++;
                    }
                }
            }

            reader.Close();
            response.Close();
        }
Exemplo n.º 7
0
        public void ReadXMLtoCreateXML()
        {
            //FileInfo fileinfo = new FileInfo(@"C:\QTI\resourses.xml");
            TextReader      tr        = new StreamReader(@"C:\QTI\resourses_new.xml");
            List <XElement> itemList  = new List <XElement>();
            string          importXml = tr.ReadToEnd();

            tr.Close();
            tr = null;
            string strXML = importXml.Replace("xmlns", "abc");
            // Get all items (questions)
            XDocument xDoc = XDocument.Parse(strXML);

            itemList = new List <XElement>(xDoc.Element("response").Elements("resources").Elements("resource"));
            XmlDocument xmlNewDoc     = new XmlDocument();
            string      folderPath    = string.Empty;
            string      filePath      = string.Empty;
            XmlElement  xmlItemFolder = null;
            XmlElement  xmlItemFile   = null;
            XmlElement  xmlItemRoot   = xmlNewDoc.CreateElement("root");

            for (int i = 0; i < itemList.Count; i++)
            {
                XElement xmlItem = itemList[i];
                if (xmlItem.Attribute("size").Value == "0")
                {
                    XmlElement xmlItemFolderNew = xmlNewDoc.CreateElement("folder");

                    if (folderPath != xmlItem.Attribute("path").Value)
                    {
                        if (xmlItemFolder != null)
                        {
                            xmlItemRoot.AppendChild(xmlItemFolder);
                        }
                        xmlItemFolder = xmlItemFolderNew;
                    }
                    else
                    {
                        xmlItemFolder = xmlNewDoc.CreateElement("folder");
                    }

                    JsTreeModel jsChildFolderItem = new JsTreeModel();
                    jsChildFolderItem.attr = new JsTreeAttribute()
                    {
                        title = folderPath
                    };

                    xmlItemFolder.SetAttribute("name", "folder");
                    folderPath = xmlItem.Attribute("path").Value;
                    xmlItemFolder.SetAttribute("path", folderPath);
                }
                else if (xmlItem.Attribute("size").Value != "0")
                {
                    xmlItemFile = xmlNewDoc.CreateElement("file");
                    filePath    = xmlItem.Attribute("path").Value;
                    xmlItemFile.SetAttribute("path", filePath);
                }
                if (filePath.Contains(folderPath) && filePath != "")
                {
                    xmlItemFolder.AppendChild(xmlItemFile);
                }
                if (i == itemList.Count - 1)
                {
                    xmlItemRoot.AppendChild(xmlItemFolder);
                }
            }
            xmlNewDoc.AppendChild(xmlItemRoot);
            xmlNewDoc.Save(@"d:\test.xml");
        }
Exemplo n.º 8
0
        public string CreateXMLJason()
        {
            parentjstree.attr = new JsTreeAttribute()
            {
                title = "ROOT", name = "Root", type = "folder"
            };
            //CreateXML(parentjstree);

            //FileInfo fileinfo = new FileInfo(@"C:\QTI\resourses.xml");
            TextReader      tr       = new StreamReader(@"C:\QTI\resourses.xml");
            List <XElement> itemList = new List <XElement>();

            parentjstree.children = new List <JsTreeModel>();
            string importXml = tr.ReadToEnd();

            tr.Close();
            tr = null;
            string strXML = importXml.Replace("xmlns", "abc");
            // Get all items (questions)
            XDocument xDoc = XDocument.Parse(strXML);

            itemList = new List <XElement>(xDoc.Element("response").Elements("resources").Elements("resource"));
            XmlDocument xmlNewDoc     = new XmlDocument();
            string      folderPath    = string.Empty;
            string      filePath      = string.Empty;
            XmlElement  xmlItemFolder = null;
            XmlElement  xmlItemFile   = null;
            XmlElement  xmlItemRoot   = xmlNewDoc.CreateElement("root");

            for (int i = 0; i < itemList.Count; i++)
            {
                XElement xmlItem = itemList[i];
                if (xmlItem.Attribute("size").Value == "0")
                {
                    JsTreeModel jsFolderItem = new JsTreeModel();
                    folderPath    = xmlItem.Attribute("path").Value;
                    xmlItemFolder = xmlNewDoc.CreateElement("folder");
                    xmlItemFolder.SetAttribute("path", folderPath);
                    jsFolderItem.attr = new JsTreeAttribute {
                        title = folderPath, name = folderPath, type = "folder"
                    };
                    jsFolderItem.children = new List <JsTreeModel>();
                    for (int j = 0; j < itemList.Count; j++)
                    {
                        XElement xmlItemNew = itemList[j];
                        if (xmlItemNew.Attribute("size").Value != "0")
                        {
                            filePath = xmlItemNew.Attribute("path").Value;
                            string filePathtoMatch = filePath.Substring(0, filePath.LastIndexOf('/'));
                            string filename        = filePath.Substring(filePath.LastIndexOf('/') + 1, filePath.Length - filePath.LastIndexOf('/') - 1);
                            xmlItemFile = xmlNewDoc.CreateElement("file");
                            filePath    = xmlItemNew.Attribute("path").Value;
                            xmlItemFile.SetAttribute("path", filePath);
                            xmlItemFile.SetAttribute("name", filename);

                            //JsTreeModel jsFileItem = new JsTreeModel();

                            if (filePathtoMatch == folderPath)
                            {
                                xmlItemFolder.AppendChild(xmlItemFile);
                                //jsFolderItem.children = new List<JsTreeModel>();
                                JsTreeModel jsFileItem = new JsTreeModel();
                                jsFileItem.attr = new JsTreeAttribute {
                                    title = filePath, name = filename, type = "file"
                                };
                                jsFolderItem.children.Add(jsFileItem);
                            }
                        }
                    }
                    xmlItemRoot.AppendChild(xmlItemFolder);
                    if (jsFolderItem.children.Count > 0)
                    {
                        //jsMaintree = jsFolderItem;

                        parentjstree.children.Add(jsFolderItem);
                    }
                }
            }
            mainTreelist.Add(parentjstree);
            JavaScriptSerializer serializer = new JavaScriptSerializer();

            return(serializer.Serialize(mainTreelist));

            /*xmlNewDoc.AppendChild(xmlItemRoot);
             * xmlNewDoc.Save(@"d:\test.xml");*/
        }