コード例 #1
0
        private static DirectoryInfo[] SortFolders(DirectoryInfo root, DirectoryInfo[] folders)
        {
            string cfgPath = root.FullName + "\\config.xml";

            if (File.Exists(root.FullName + "\\config.xml"))
            {
                ExampleConfig rootCfg = new ExampleConfig(cfgPath, false);
                if (rootCfg.OrderFolders.Count > 0)
                {
                    List <DirectoryInfo> list = new List <DirectoryInfo>(folders);
                    int pasteIndex            = 0;
                    foreach (string orderFolder in rootCfg.OrderFolders)
                    {
                        int dIndex = 0;
                        for (int ind = 0; ind < list.Count; ind++)
                        {
                            if (list[ind].Name.ToLower() == orderFolder)
                            {
                                dIndex = ind;
                            }
                        }

                        if (dIndex > 0)
                        {
                            DirectoryInfo di = list[dIndex];
                            list.RemoveAt(dIndex);
                            list.Insert(pasteIndex++, di);
                        }
                    }

                    folders = list.ToArray();
                }
            }
            return(folders);
        }
コード例 #2
0
        public static void FindExamples(DirectoryInfo root, int level, int maxLevel, List <ExampleGroup> examples)
        {
            DirectoryInfo[] folders = root.GetDirectories();
            folders = SortFolders(root, folders);

            foreach (DirectoryInfo folder in folders)
            {
                if ((folder.Attributes & FileAttributes.Hidden) == FileAttributes.Hidden ||
                    excludeList.Contains(folder.Name) || folder.Name.StartsWith("_"))
                {
                    continue;
                }

                if (level < maxLevel)
                {
                    if (level == 1)
                    {
                        examples.Add(new ExampleGroup {
                            id = folder.Name, title = folder.Name
                        });
                    }
                    FindExamples(folder, level + 1, maxLevel, examples);
                }
                else
                {
                    string imgUrl = UIHelpers.ApplicationRoot + "/resources/images/noimage.gif";
                    string descr  = "No description";
                    string name   = MarkNew(folder.FullName, folder.Name.Replace("_", " "));

                    if (File.Exists(folder.FullName + "\\config.xml"))
                    {
                        ExampleConfig cfg = new ExampleConfig(folder.FullName + "\\config.xml", false);
                        descr = cfg.Description;
                    }

                    if (File.Exists(folder.FullName + "\\thumbnail.png"))
                    {
                        imgUrl = PhysicalToVirtual(folder.FullName + "\\thumbnail.png");
                    }
                    else if (File.Exists(folder.FullName + "\\thumbnail.gif"))
                    {
                        imgUrl = PhysicalToVirtual(folder.FullName + "\\thumbnail.gif");
                    }

                    string url = PhysicalToVirtual(folder.FullName + "/");

                    ExampleGroup group = examples[examples.Count - 1];
                    group.samples.Add(new { id = "e" + url.ToLower().GetHashCode(), name, url, imgUrl, descr, sub = folder.Parent.Name.Replace("_", " ") });
                }
            }
        }
コード例 #3
0
        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            string id  = context.Request["id"];
            string url = context.Request["url"];

            if (string.IsNullOrEmpty(url))
            {
                return;
            }

            //url = url.ToLower();

            if (!url.EndsWith("/"))
            {
                url = url + "/";
            }

            string examplesFolder = new Uri(HttpContext.Current.Request.Url, "Examples/").AbsolutePath.ToLower();

            if (!url.StartsWith(examplesFolder, true, CultureInfo.InvariantCulture))
            {
                url = examplesFolder.TrimEnd(new [] { '/' }) + url;

                id = "e" + url.ToLower().GetHashCode().ToString();
            }

            string wId = context.Request["wId"];

            HttpRequest r   = HttpContext.Current.Request;
            Uri         uri = new Uri(r.Url.Scheme + "://" + r.Url.Authority + url, UriKind.Absolute);

            string        path = context.Server.MapPath(uri.AbsolutePath);
            DirectoryInfo dir  = new DirectoryInfo(path);

            ExampleConfig cfg = null;

            if (File.Exists(dir.FullName + "config.xml"))
            {
                cfg = new ExampleConfig(dir.FullName + "config.xml", false);
            }

            string tabs = BuildSourceTabs(id, cfg, dir);

            string script = string.Format("var w = Ext.getCmp({0});w.add({1});w.doLayout();", JSON.Serialize(wId), tabs);

            context.Response.Write(script);
        }
コード例 #4
0
        private static string MarkNew(string folder, string name)
        {
            if (rootCfg == null)
            {
                rootCfg = new ExampleConfig(new DirectoryInfo(HttpContext.Current.Server.MapPath("~/Examples/")) + "\\config.xml", false);
            }

            foreach (string newFolder in rootCfg.NewFolders)
            {
                if (string.Concat(HttpContext.Current.Server.MapPath("~/Examples/"), newFolder).StartsWith(folder, StringComparison.CurrentCultureIgnoreCase))
                {
                    return(name + NEW_MARKER);
                }
            }

            return(name);
        }
コード例 #5
0
        public void ZipFiles(string inputFolderPath)
        {
            ArrayList ar         = GenerateFileList(inputFolderPath);
            int       trimLength = (Directory.GetParent(inputFolderPath)).ToString().Length;

            trimLength += 1;
            FileStream ostream;

            byte[] obuffer;

            var oZipStream = new ZipOutputStream(HttpContext.Current.Response.OutputStream);

            oZipStream.SetLevel(6);
            ZipEntry oZipEntry;

            foreach (string file in ar)
            {
                oZipEntry = new ZipEntry(file.Remove(0, trimLength));
                oZipStream.PutNextEntry(oZipEntry);

                if (!file.EndsWith(@"/")) // if a file ends with '/' its a directory
                {
                    ostream = File.OpenRead(file);
                    obuffer = new byte[ostream.Length];
                    ostream.Read(obuffer, 0, obuffer.Length);
                    oZipStream.Write(obuffer, 0, obuffer.Length);
                }
            }

            if (File.Exists(inputFolderPath + "config.xml"))
            {
                var cfg = new ExampleConfig(inputFolderPath + "config.xml", true);
                foreach (string file in cfg.OuterFiles)
                {
                    oZipEntry = new ZipEntry(new FileInfo(file).Name);
                    oZipStream.PutNextEntry(oZipEntry);
                    ostream = File.OpenRead(file);
                    obuffer = new byte[ostream.Length];
                    ostream.Read(obuffer, 0, obuffer.Length);
                    oZipStream.Write(obuffer, 0, obuffer.Length);
                }

                foreach (string folder in cfg.ZipFolders)
                {
                    ar = GenerateFileList(folder);
                    DirectoryInfo dir = new DirectoryInfo(folder);
                    trimLength  = dir.Parent.FullName.Length;
                    trimLength += 1;

                    //oZipEntry = new ZipEntry(dir.Name);
                    //oZipStream.PutNextEntry(oZipEntry);

                    foreach (string file in ar)
                    {
                        oZipEntry = new ZipEntry(file.Remove(0, trimLength));
                        oZipStream.PutNextEntry(oZipEntry);

                        if (!file.EndsWith(@"/")) // if a file ends with '/' its a directory
                        {
                            ostream = File.OpenRead(file);
                            obuffer = new byte[ostream.Length];
                            ostream.Read(obuffer, 0, obuffer.Length);
                            oZipStream.Write(obuffer, 0, obuffer.Length);
                        }
                    }
                }
            }

            oZipStream.Finish();
            oZipStream.Close();
        }
コード例 #6
0
        private string BuildSourceTabs(string id, ExampleConfig cfg, DirectoryInfo dir)
        {
            List <string> files = cfg != null ? cfg.OuterFiles : new List <string>();

            FileInfo[]      filesInfo = dir.GetFiles();
            List <FileInfo> fileList  = new List <FileInfo>(filesInfo);

            int dIndex = 0;

            for (int ind = 0; ind < fileList.Count; ind++)
            {
                if (fileList[ind].Name.ToLower() == "default.aspx")
                {
                    dIndex = ind;
                }
            }

            if (dIndex > 0)
            {
                FileInfo fi = fileList[dIndex];
                fileList.RemoveAt(dIndex);
                fileList.Insert(0, fi);
            }

            foreach (string file in files)
            {
                fileList.Add(new FileInfo(file));
            }

            DirectoryInfo[] resources = dir.GetDirectories("resources", SearchOption.TopDirectoryOnly);

            if (resources.Length > 0)
            {
                GetSubFiles(fileList, resources[0]);
            }


            StringBuilder sb = new StringBuilder();

            sb.Append("{");
            sb.Append(string.Concat("id: \"tpw", id, "\","));
            sb.Append("xtype: \"tabpanel\",");
            sb.Append("border: false,");
            sb.Append("activeTab: 0,");
            sb.Append("items:[");

            int i = 0;

            foreach (FileInfo fileInfo in fileList)
            {
                if (excludeList.Contains(fileInfo.Name) || excludeExtensions.Contains(fileInfo.Extension.ToLower()))
                {
                    continue;
                }

                Panel panel = new Panel();
                panel.ID    = "tptw" + id + i++;
                panel.Title = fileInfo.Name;
                panel.CustomConfig.Add(new ConfigItem("url", UIHelpers.PhysicalToVirtual(fileInfo.FullName), ParameterMode.Value));
                switch (fileInfo.Extension)
                {
                case ".aspx":
                case ".ascx":
                    panel.Icon = Icon.PageWhiteCode;
                    break;

                case ".cs":
                    panel.Icon = Icon.PageWhiteCsharp;
                    break;

                case ".xml":
                case ".xsl":
                    panel.Icon = Icon.ScriptCodeRed;
                    break;

                case ".js":
                    panel.Icon = Icon.Script;
                    break;

                case ".css":
                    panel.Icon = Icon.Css;
                    break;
                }
                panel.AutoLoad.Url  = UIHelpers.ApplicationRoot + "/GenerateSource.ashx";
                panel.AutoLoad.Mode = LoadMode.IFrame;
                panel.AutoLoad.Params.Add(new Parameter("f", UIHelpers.PhysicalToVirtual(fileInfo.FullName), ParameterMode.Value));
                panel.AutoLoad.ShowMask = true;

                sb.Append(new ClientConfig(true).Serialize(panel));
                sb.Append(",");
            }

            if (sb[sb.Length - 1] == ',')
            {
                sb.Remove(sb.Length - 1, 1);
            }

            sb.Append("]");

            sb.Append("}");

            return(sb.ToString());
        }
コード例 #7
0
        private static TreeNodeCollection BuildTreeLevel(DirectoryInfo root, int level, int maxLevel, XmlElement siteMap)
        {
            DirectoryInfo[] folders = root.GetDirectories();

            folders = SortFolders(root, folders);

            TreeNodeCollection nodes = new TreeNodeCollection(false);

            foreach (DirectoryInfo folder in folders)
            {
                if ((folder.Attributes & FileAttributes.Hidden) == FileAttributes.Hidden ||
                    excludeList.Contains(folder.Name) || folder.Name.StartsWith("_"))
                {
                    continue;
                }

                ExampleConfig cfg = new ExampleConfig(folder.FullName + "\\config.xml", false);

                string     iconCls  = string.IsNullOrEmpty(cfg.IconCls) ? "" : cfg.IconCls;
                TreeNode   node     = new TreeNode();
                XmlElement siteNode = null;
                if (level < maxLevel)
                {
                    node.Text              = MarkNew(folder.FullName, folder.Name.Replace("_", " "));
                    node.IconCls           = iconCls;
                    node.SingleClickExpand = true;

                    if (siteMap != null)
                    {
                        siteNode = siteMap.OwnerDocument.CreateElement("siteMapNode");
                        siteNode.SetAttribute("title", node.Text);
                        siteMap.AppendChild(siteNode);
                    }

                    node.Nodes.AddRange(BuildTreeLevel(folder, level + 1, maxLevel, siteNode));
                }
                else
                {
                    string img   = UIHelpers.ApplicationRoot + "/resources/images/noimage.gif";
                    string title = folder.Name.Replace("_", " ");
                    string desc  = string.IsNullOrEmpty(cfg.Description) ? "No description" : cfg.Description;

                    if (File.Exists(folder.FullName + "\\thumbnail.png"))
                    {
                        img = PhysicalToVirtual(folder.FullName + "\\thumbnail.png");
                    }
                    else if (File.Exists(folder.FullName + "\\thumbnail.gif"))
                    {
                        img = PhysicalToVirtual(folder.FullName + "\\thumbnail.gif");
                    }

                    node.Text              = MarkNew(folder.FullName, folder.Name.Replace("_", " "));
                    node.IconCls           = iconCls;
                    node.SingleClickExpand = true;
                    string qtip = string.Format("<div class='thumb-wrap' style='margin:0px;float:none;'><img src='{0}' title='{1}'/><div><h4>{1}</h4><p>{2}</p></div></div>",
                                                img, title, desc);
                    node.Qtip = qtip;
                    string url = PhysicalToVirtual(folder.FullName + "/");
                    node.NodeID = "e" + url.ToLower().GetHashCode();
                    node.Href   = url;
                    node.Leaf   = true;

                    if (siteMap != null)
                    {
                        siteNode = siteMap.OwnerDocument.CreateElement("siteMapNode");
                        siteNode.SetAttribute("title", node.Text);
                        siteNode.SetAttribute("description", desc);
                        siteNode.SetAttribute("url", "~" + PhysicalToVirtual(folder.FullName + "/"));
                        siteMap.AppendChild(siteNode);
                    }
                }

                nodes.Add(node);
            }

            return(nodes);
        }