Beispiel #1
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();
            }
        }
Beispiel #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
                        });
                    }

                    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("_", " ") });
                }
            }
        }
Beispiel #3
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();
         }
     }
 }
Beispiel #4
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);
        }
Beispiel #5
0
        public static NodeCollection BuildFirstLevel()
        {
            string        path = HttpContext.Current.Server.MapPath("~/Moduls/");
            DirectoryInfo root = new DirectoryInfo(path);

            DirectoryInfo[] folders = root.GetDirectories();
            folders = UIHelpers.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;
                }

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

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

                node.Text = folder.Name.Replace("_", " ");

                flagNode(ref node, folder.FullName);

                node.IconCls = iconCls;

                string url = UIHelpers.PhysicalToVirtual(folder.FullName + "/");
                node.NodeID = "e" + Math.Abs(url.ToLower().GetHashCode());

                nodes.Add(node);
            }

            return(nodes);
        }
Beispiel #6
0
        private static bool IsUpdated(string folder)
        {
            if (rootCfg == null)
            {
                rootCfg = new ExampleConfig(new DirectoryInfo(HttpContext.Current.Server.MapPath("~/Moduls/")) + "\\config.xml", false);
            }

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

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

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

            return(false);
        }
        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();
        }
Beispiel #8
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, "^/Moduls", "")));

                    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);
        }
Beispiel #9
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, "Moduls/").AbsolutePath.ToLower();

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

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

            Uri uri = new Uri(url, UriKind.Relative);

            string        path = AppDomain.CurrentDomain.BaseDirectory + url;
            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);
        }
Beispiel #10
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));
        }