Example #1
0
        public override bool Resource(NetContext context, String path)
        {
            var paths = new List <string>(path.Split(new char[] { '/' }, StringSplitOptions.RemoveEmptyEntries));

            if (paths.Count == 0)
            {
                paths.Add("index.html");
            }

            var last = paths[paths.Count - 1];

            switch (last)
            {
            case "Sub.js":
            {
                using (System.IO.Stream stream = typeof(Initializer).Assembly
                                                 .GetManifestResourceStream("UMC.Subs.Resources.sub.js"))
                {
                    UMC.Data.Utility.Copy(stream, context.OutputStream);
                }
            }
                return(true);

            case "sub.html":
            case "index.html":
                context.ContentType = "text/html";

                using (System.IO.Stream stream = typeof(Initializer).Assembly
                                                 .GetManifestResourceStream("UMC.Subs.Resources.sub.html"))
                {
                    UMC.Data.Utility.Copy(stream, context.OutputStream);
                }
                return(true);

            default:
                if (last.IndexOf('.') > -1)
                {
                    context.Redirect(WebResource.Instance().WebDomain());
                    return(true);
                }
                break;
            }
            switch (paths[0].ToLower())
            {
            case "download":
            case "dashboard":
            case "explore":
                break;

            default:
                if (paths.Count > 3)
                {
                    context.Redirect(WebResource.Instance().WebDomain());
                    return(true);
                }

                var project = Utility.CMS.ObjectEntity <UMC.Data.Entities.Project>()
                              .Where.And().Equal(new Project {
                    Code = paths[0]
                }).Entities.Single();
                if (project == null)
                {
                    if (paths.Count > 1)
                    {
                        context.Redirect(WebResource.Instance().WebDomain());
                        return(true);
                    }
                    return(false);
                }
                if (paths.Count > 1)
                {
                    if (paths.Count == 2 && paths[1] == "follow")
                    {
                    }
                    else
                    {
                        var projectItem = Utility.CMS.ObjectEntity <UMC.Data.Entities.ProjectItem>()
                                          .Where.And().Equal(new ProjectItem {
                            Code = paths[1], project_id = project.Id
                        }).Entities.Single();
                        if (projectItem == null)
                        {
                            context.Redirect(WebResource.Instance().WebDomain() + project.Code);
                            //context.StatusCode = 404;
                            return(true);
                        }

                        if (paths.Count > 2)
                        {
                            var memberCount = Utility.CMS.ObjectEntity <UMC.Data.Entities.Subject>()
                                              .Where.And().Equal(new Subject
                            {
                                Code            = paths[2],
                                project_id      = project.Id,
                                project_item_id = projectItem.Id
                            }).Entities.Count();
                            if (memberCount == 0)
                            {
                                context.Redirect(String.Format("{2}{0}/{1}", project.Code, projectItem.Code, WebResource.Instance().WebDomain()));

                                return(true);
                            }
                        }
                    }
                }
                break;
            }
            context.ContentType = "text/html";

            using (System.IO.Stream stream = typeof(Initializer).Assembly
                                             .GetManifestResourceStream("UMC.Subs.Resources.sub.html"))
            {
                UMC.Data.Utility.Copy(stream, context.OutputStream);
            }
            return(true);
        }