Ejemplo n.º 1
0
        public static TreeNodeCollection BuildFirstLevel()
        {
            string path = HttpContext.Current.Server.MapPath("~/Examples/");
            DirectoryInfo root = new DirectoryInfo(path);
            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;
                AsyncTreeNode node = new AsyncTreeNode();

                node.Text = MarkNew(folder.FullName, folder.Name.Replace("_", " "));
                node.IconCls = iconCls;
                string url = PhysicalToVirtual(folder.FullName + "/");
                node.NodeID = "e" + Math.Abs(url.ToLower().GetHashCode());

                nodes.Add(node);
            }

            return nodes;
        }
Ejemplo n.º 2
0
        public static TreeNodeCollection BuildFirstLevel()
        {
            string        path = HttpContext.Current.Server.MapPath("~/Examples/");
            DirectoryInfo root = new DirectoryInfo(path);

            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;
                AsyncTreeNode node    = new AsyncTreeNode();

                node.Text    = MarkNew(folder.FullName, folder.Name.Replace("_", " "));
                node.IconCls = iconCls;
                string url = PhysicalToVirtual(folder.FullName + "/");
                node.NodeID = "e" + Math.Abs(url.ToLower().GetHashCode());

                nodes.Add(node);
            }

            return(nodes);
        }
        private void AddComment(HttpContext context, ExampleConfig config)
        {
            lock (lockObj)
            {
                try
                {
                    string title = context.Request["CommentName"];
                    title = this.Shrink(title.IsEmpty() ? "[no title]" : title, 128);
                    string name = context.Request["UserName"];
                    name = this.Shrink(name.IsEmpty() ? "[anonymous]" : name, 128);
                    string message = this.Shrink(context.Request["CommentMessage"], 1024);

                    config.AddComment(new ExampleComment {
                        Name = name, Title = title, Message = message
                    });
                    context.Response.Write(JSON.Serialize(new { success = true }));
                }
                catch (Exception e)
                {
                    context.Response.Write(JSON.Serialize(new { success = false, msg = e.Message }));
                }

                context.Response.End();
            }
        }
Ejemplo n.º 4
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
                        });
                    }

                    UIHelpers.FindExamples(folder, level + 1, maxLevel, examples);
                }
                else
                {
                    string imgUrl = UIHelpers.ApplicationRoot + "/resources/images/noimage.gif";
                    string descr  = "No description";
                    string name   = folder.Name.Replace("_", " ");

                    if (IsNew(folder.FullName) || IsUpdated(folder.FullName))
                    {
                        name += "<span>&nbsp;</span>";
                    }

                    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" + Math.Abs(url.ToLower().GetHashCode()), name, url, imgUrl, descr, sub = folder.Parent.Name.Replace("_", " ") });
                }
            }
        }
 private void AddTag(HttpContext context, ExampleConfig config)
 {
     lock (lockObj)
     {
         try
         {
             config.AddTag(this.Shrink(context.Request["tag"], 128));
             new DirectResponse().Return();
         }
         catch (Exception e)
         {
             new DirectResponse {
                 Success = false, ErrorMessage = e.Message
             }.Return();
         }
     }
 }
Ejemplo n.º 6
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);
        }
Ejemplo n.º 7
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);
        }
Ejemplo n.º 8
0
        private static bool IsUpdated(string folder)
        {
            if (rootCfg == null)
            {
                rootCfg = new ExampleConfig(new DirectoryInfo(HttpContext.Current.Server.MapPath("~/Examples/")) + "\\config.xml", false);
            }

            foreach (string updFolder in rootCfg.UpdFolders)
            {
                string updPath = string.Concat(HttpContext.Current.Server.MapPath("~/Examples/"), updFolder);

                if (updPath.StartsWith(folder, StringComparison.CurrentCultureIgnoreCase))
                {
                    string end = updPath.Substring(folder.Length);

                    if ((end.StartsWith("\\") || end.Equals("")))
                    {
                        return(true);
                    }
                }
            }

            return(false);
        }
Ejemplo n.º 9
0
        private static NodeCollection BuildTreeLevel(DirectoryInfo root, int level, int maxLevel, XmlElement siteMap)
        {
            DirectoryInfo[] folders = root.GetDirectories();

            folders = SortFolders(root, folders);

            NodeCollection nodes = new NodeCollection(false);

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

#if !PREEXTENSIONS
                if (level == 1 && (folder.Name == "Gantt" || folder.Name == "Scheduler"))
                {
                    continue;
                }
#endif

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

                string     iconCls  = string.IsNullOrEmpty(cfg.IconCls) ? "" : cfg.IconCls;
                Node       node     = new Node();
                XmlElement siteNode = null;

                string folderName = folder.Name.Replace("_", " ");

                if (level < maxLevel)
                {
                    node.Text = folderName;

                    flagNode(ref node, folder.FullName);

                    node.IconCls = iconCls;
                    node.NodeID  = BaseControl.GenerateID();
                    //node.SingleClickExpand = true;

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

                    node.Children.AddRange(UIHelpers.BuildTreeLevel(folder, level + 1, maxLevel, siteNode));
                }
                else
                {
                    node.Text = folderName;

                    flagNode(ref node, folder.FullName);

                    node.IconCls = iconCls;
                    string url = PhysicalToVirtual(folder.FullName + "/");
                    node.NodeID = "e" + Math.Abs(url.ToLower().GetHashCode());
                    //node.Href = Regex.Replace(url, "^/Examples","");
                    node.CustomAttributes.Add(new ConfigItem("url", Regex.Replace(url, "^/Examples", "")));

                    node.Leaf = true;

                    if (siteMap != null)
                    {
                        siteNode = siteMap.OwnerDocument.CreateElement("siteMapNode");
                        siteNode.SetAttribute("title", folderName);
                        siteNode.SetAttribute("description", string.IsNullOrEmpty(cfg.Description) ? "No description" : cfg.Description);
                        siteNode.SetAttribute("url", "~" + UIHelpers.PhysicalToVirtual(folder.FullName + "/"));
                        siteMap.AppendChild(siteNode);
                    }
                }

                node.CustomAttributes.Add(new { tags = cfg.Tags.Select(item => item.ToLower()) });

                nodes.Add(node);
            }

            return(nodes);
        }
Ejemplo n.º 10
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;

                string folderName = folder.Name.Replace("_", " ");
                if (level < maxLevel)
                {
                    node.Text    = MarkNew(folder.FullName, folderName);
                    node.IconCls = iconCls;
                    //node.NodeID = "e" + Math.Abs(url.ToLower().GetHashCode());
                    //node.SingleClickExpand = true;

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

                    node.Nodes.AddRange(BuildTreeLevel(folder, level + 1, maxLevel, siteNode));
                }
                else
                {
                    node.Text    = MarkNew(folder.FullName, folderName);
                    node.IconCls = iconCls;
                    string url = PhysicalToVirtual(folder.FullName + "/");
                    node.NodeID = "e" + Math.Abs(url.ToLower().GetHashCode());
                    node.Href   = Regex.Replace(url, "^/Examples", "");

                    node.Leaf = true;

                    if (siteMap != null)
                    {
                        siteNode = siteMap.OwnerDocument.CreateElement("siteMapNode");
                        siteNode.SetAttribute("title", folderName);
                        siteNode.SetAttribute("description", string.IsNullOrEmpty(cfg.Description) ? "No description" : cfg.Description);
                        siteNode.SetAttribute("url", "~" + PhysicalToVirtual(folder.FullName + "/"));
                        siteMap.AppendChild(siteNode);
                    }
                }

                nodes.Add(node);
            }

            return(nodes);
        }
Ejemplo n.º 11
0
        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            string id = context.Request["id"];
            string url = context.Request["url"];
            string action = context.Request["action"];

            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;
            }

            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);
            }

            if (action.IsNotEmpty() && false)
            {
                switch (action)
                {
                    case "comments.count" :
                        int count = 0;

                        if (cfg != null)
                        {
                            count = cfg.Comments.Count;
                        }

                        context.Response.Write(count);
                        context.Response.End();
                        return;
                    case "comments.build" :
                        if (cfg != null)
                        {
                            context.Response.Write(JSON.Serialize(cfg.Comments));
                        }
                        
                        context.Response.End();
                        return;
                    case "comments.add" :
                        if (cfg != null)
                        {
                            this.AddComment(context, cfg);
                        }
                        return;
                    case "tags.add":
                        if (cfg != null)
                        {
                            this.AddTag(context, cfg);
                        }
                        return;
                    case "tags.read":
                        if (cfg != null)
                        {
                            context.Response.Write(JSON.Serialize(cfg.Tags.ConvertAll(input => new { Tag = input })));
                        }
                        context.Response.End();
                        return;
                }
            }

            if (id.StartsWith("extnet"))
            {
                id = "e" + Math.Abs(url.ToLower().GetHashCode());
            }

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

            //string script = string.Format("var w = Ext.getCmp({0});w.add({1});w.doLayout();", JSON.Serialize(wId), tabs);
            Ext.Net.Utilities.CompressionUtils.GZipAndSend(tabs);
            //context.Response.Write(tabs);
        }
Ejemplo n.º 12
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" + Math.Abs(url.ToLower().GetHashCode()), name, url, imgUrl, descr, sub = folder.Parent.Name.Replace("_", " ") });
                }
            }
        }
Ejemplo n.º 13
0
        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";

            string id     = context.Request["id"];
            string url    = context.Request["url"];
            string action = context.Request["action"];

            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;
            }

            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);
            }

            if (action.IsNotEmpty() && false)
            {
                switch (action)
                {
                case "comments.count":
                    int count = 0;

                    if (cfg != null)
                    {
                        count = cfg.Comments.Count;
                    }

                    context.Response.Write(count);
                    context.Response.End();
                    return;

                case "comments.build":
                    if (cfg != null)
                    {
                        context.Response.Write(JSON.Serialize(cfg.Comments));
                    }

                    context.Response.End();
                    return;

                case "comments.add":
                    if (cfg != null)
                    {
                        this.AddComment(context, cfg);
                    }
                    return;

                case "tags.add":
                    if (cfg != null)
                    {
                        this.AddTag(context, cfg);
                    }
                    return;

                case "tags.read":
                    if (cfg != null)
                    {
                        context.Response.Write(JSON.Serialize(cfg.Tags.ConvertAll(input => new { Tag = input })));
                    }
                    context.Response.End();
                    return;
                }
            }

            if (id.StartsWith("extnet"))
            {
                id = "e" + Math.Abs(url.ToLower().GetHashCode());
            }

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

            //string script = string.Format("var w = Ext.getCmp({0});w.add({1});w.updateLayout();", JSON.Serialize(wId), tabs);
            Ext.Net.Utilities.CompressionUtils.GZipAndSend(tabs);
            //context.Response.Write(tabs);
        }
Ejemplo n.º 14
0
        private string BuildSourceTabs(string id, string wId, 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]);
            }

            TabPanel tabs = new TabPanel
            {
                ID             = "tpw" + id,
                Border         = false,
                ActiveTabIndex = 0
            };

            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.Loader      = new ComponentLoader();
                panel.Loader.Url  = UIHelpers.ApplicationRoot + "/GenerateSource.ashx";
                panel.Loader.Mode = LoadMode.Frame;
                panel.Loader.Params.Add(new Parameter("f", UIHelpers.PhysicalToVirtual(fileInfo.FullName), ParameterMode.Value));
                panel.Loader.LoadMask.ShowMask = true;

                tabs.Items.Add(panel);
            }

            return(tabs.ToScript(RenderMode.AddTo, wId));
        }
        public void ZipFiles(string inputFolderPath)
        {
            ArrayList ar = GenerateFileList(inputFolderPath);
            int trimLength = (Directory.GetParent(inputFolderPath)).ToString().Length;
            trimLength += 1;
            FileStream ostream;
            byte[] obuffer;

            ZipOutputStream 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"))
            {
                ExampleConfig 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();
        }
Ejemplo n.º 16
0
        private static NodeCollection BuildTreeLevel(DirectoryInfo root, int level, int maxLevel, XmlElement siteMap)
        {
            DirectoryInfo[] folders = root.GetDirectories();

            folders = SortFolders(root, folders);

            NodeCollection nodes = new NodeCollection(false);

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

#if !PREEXTENSIONS
                if (level == 1 && (folder.Name == "Gantt" || folder.Name == "Scheduler"))
                {
                    continue;
                }
#endif

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

                string iconCls = string.IsNullOrEmpty(cfg.IconCls) ? "" : cfg.IconCls;
                Node node = new Node();
                XmlElement siteNode = null;

                string folderName = folder.Name.Replace("_", " ");

                if (level < maxLevel)
                {
                    node.Text = folderName;

                    if (UIHelpers.IsNew(folder.FullName))
                    {
                        node.CustomAttributes.Add(new ConfigItem("isNew", "true", ParameterMode.Raw));
                    }

                    node.IconCls = iconCls;
                    node.NodeID = BaseControl.GenerateID();
                    //node.SingleClickExpand = true;

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

                    node.Children.AddRange(UIHelpers.BuildTreeLevel(folder, level + 1, maxLevel, siteNode));
                }
                else
                {
                    node.Text = folderName;

                    if (UIHelpers.IsNew(folder.FullName))
                    {
                        node.CustomAttributes.Add(new ConfigItem("isNew", "true", ParameterMode.Raw));
                    }

                    node.IconCls = iconCls;
                    string url = PhysicalToVirtual(folder.FullName + "/");
                    node.NodeID = "e" + Math.Abs(url.ToLower().GetHashCode());
                    //node.Href = Regex.Replace(url, "^/Examples","");
                    node.CustomAttributes.Add(new ConfigItem("url", Regex.Replace(url, "^/Examples", "")));

                    node.Leaf = true;

                    if (siteMap != null)
                    {
                        siteNode = siteMap.OwnerDocument.CreateElement("siteMapNode");
                        siteNode.SetAttribute("title", folderName);
                        siteNode.SetAttribute("description", string.IsNullOrEmpty(cfg.Description) ? "No description" : cfg.Description);
                        siteNode.SetAttribute("url", "~" + UIHelpers.PhysicalToVirtual(folder.FullName + "/"));
                        siteMap.AppendChild(siteNode);
                    }
                }

                node.CustomAttributes.Add(new { tags = cfg.Tags.Select( item => item.ToLower()) });

                nodes.Add(node);
            }

            return nodes;
        }
Ejemplo n.º 17
0
        private static bool IsNew(string folder)
        {
            if (rootCfg == null)
            {
                rootCfg = new ExampleConfig(new DirectoryInfo(HttpContext.Current.Server.MapPath("~/Examples/")) + "\\config.xml", false);
            }

            foreach (string newFolder in rootCfg.NewFolders)
            {
                string newPath = string.Concat(HttpContext.Current.Server.MapPath("~/Examples/"), newFolder);

                if (newPath.StartsWith(folder, StringComparison.CurrentCultureIgnoreCase))
                {
                    string end = newPath.Substring(folder.Length);

                    if ((end.StartsWith("\\") || end.Equals("")))
                    {
                        return true;
                    }
                }
            }

            return false;
        }
Ejemplo n.º 18
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;
        }
Ejemplo n.º 19
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;
        }
Ejemplo n.º 20
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;

                string folderName = folder.Name.Replace("_", " ");
                if (level < maxLevel)
                {
                    node.Text = MarkNew(folder.FullName, folderName);
                    node.IconCls = iconCls;
                    //node.NodeID = "e" + Math.Abs(url.ToLower().GetHashCode());
                    //node.SingleClickExpand = true;

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

                    node.Nodes.AddRange(BuildTreeLevel(folder, level + 1, maxLevel, siteNode));
                }
                else
                {
                    node.Text = MarkNew(folder.FullName, folderName);
                    node.IconCls = iconCls;
                    string url = PhysicalToVirtual(folder.FullName + "/");
                    node.NodeID = "e" + Math.Abs(url.ToLower().GetHashCode());
                    node.Href = Regex.Replace(url, "^/Examples","");

                    node.Leaf = true;

                    if (siteMap != null)
                    {
                        siteNode = siteMap.OwnerDocument.CreateElement("siteMapNode");
                        siteNode.SetAttribute("title", folderName);
                        siteNode.SetAttribute("description", string.IsNullOrEmpty(cfg.Description) ? "No description" : cfg.Description);
                        siteNode.SetAttribute("url", "~" + PhysicalToVirtual(folder.FullName + "/"));
                        siteMap.AppendChild(siteNode);
                    }
                }

                nodes.Add(node);
            }

            return nodes;
        }
Ejemplo n.º 21
0
        private void AddComment(HttpContext context, ExampleConfig config)
        {
            lock (lockObj)
            {
                try
                {
                    string title = context.Request["CommentName"];
                    title = this.Shrink(title.IsEmpty() ? "[no title]" : title, 128);
                    string name = context.Request["UserName"];
                    name = this.Shrink( name.IsEmpty() ? "[anonymous]" : name, 128);
                    string message = this.Shrink(context.Request["CommentMessage"], 1024);

                    config.AddComment(new ExampleComment{Name = name, Title = title, Message = message});
                    context.Response.Write(JSON.Serialize(new {success = true}));
                }
                catch (Exception e)
                {
                    context.Response.Write(JSON.Serialize(new { success = false, msg = e.Message }));
                }

                context.Response.End();
            }
        }
Ejemplo n.º 22
0
        private string BuildSourceTabs(string id, string wId, 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]); 
            }

            TabPanel tabs = new TabPanel
                                {
                                    ID = "tpw"+id,
                                    EnableTabScroll = true,
                                    Border = false,
                                    ActiveTabIndex = 0
                                };

            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;

                tabs.Items.Add(panel);
            }

            return tabs.ToScript(RenderMode.AddTo, wId);
        }
Ejemplo n.º 23
0
        public void ZipFiles(string inputFolderPath)
        {
            ArrayList ar         = GenerateFileList(inputFolderPath);
            int       trimLength = (Directory.GetParent(inputFolderPath)).ToString().Length;

            trimLength += 1;
            FileStream ostream;

            byte[] obuffer;

            ZipOutputStream 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"))
            {
                ExampleConfig 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();
        }
Ejemplo n.º 24
0
 private void AddTag(HttpContext context, ExampleConfig config)
 {
     lock (lockObj)
     {
         try
         {
             config.AddTag(this.Shrink(context.Request["tag"], 128));
             new DirectResponse().Return();
         }
         catch (Exception e)
         {
             new DirectResponse{Success = false, ErrorMessage = e.Message}.Return();
         }
     }
 }