コード例 #1
0
        public ActionResult UserGuide(string id, string page)
        {
            ViewBag.Posts = NetpingHelpers.Helpers.GetTopPosts();
            ViewBag.Devices = NetpingHelpers.Helpers.GetNewDevices();

            string file_name = HttpContext.Server.MapPath("~/Content/Data/UserGuides/" + id.Replace(".", "%2E").Replace("!2F", "%2F") + "_" + CultureInfo.CurrentCulture.IetfLanguageTag + ".dat");

            var sections = NavigationProvider.GetAllSections();
            var devices = _repository.Devices.Where(d => !d.Name.IsGroup());

            UserManualViewModel model = null;
            if (System.IO.File.Exists(file_name))
            {
                try
                {
                    var stream = System.IO.File.OpenRead(file_name);
                    BinaryFormatter binaryWrite = new BinaryFormatter();
                    var guide = binaryWrite.Deserialize(stream) as UserManualModel;

                    model = new UserManualViewModel
                    {
                        Id = guide.Id,
                        Title = guide.Title.Replace("%2E", "."),
                        Name = guide.Name,
                        Pages = guide.Pages.OrderBy(p => p.Title, new NaturalComparer(CultureInfo.CurrentCulture)),
                        ItemId = guide.ItemId
                    };

                    Device device = null;
                    if(model.ItemId > 0)
                        device = devices.FirstOrDefault(d => d.SFiles.Any(sf => sf.Id == model.ItemId));
                    else
                        device = devices.FirstOrDefault(d => d.SFiles.Any(f => id.Contains(f.Title)));
                    var group = _repository.Devices.FirstOrDefault(d => d.Name.IsGroup() && d.Name.IsIncludeOther(device.Name) && !string.IsNullOrEmpty(d.Url));
                    var section = sections.FirstOrDefault(s => s.Url == group.Url);

                    model.Device = device;
                    model.Section = section ?? new SectionModel
                        {
                            Title = "Other",
                            Url = "/"
                        };

                    if (string.IsNullOrEmpty(page))
                        return View("~/Views/Products/UserGuide.cshtml", model);
                    else
                    {
                        var m = guide.Pages.SingleOrDefault(p => p.Title.Contains(page.Replace(".", "%2E")));
                        Session["page"] = m;
                        return View("~/Views/Products/UserGuidePage.cshtml", m);
                    }
                }
                catch(Exception ex)
                {
                    throw;
                }
            }

            return View("~/Views/Products/UserGuide.cshtml", model);
        }
コード例 #2
0
        public ActionResult UserGuide(string id, string page)
        {
            ViewBag.Posts = NetpingHelpers.Helpers.GetTopPosts();
            ViewBag.Devices = NetpingHelpers.Helpers.GetNewDevices();

            var sections = NavigationProvider.GetAllSections();
            var devices = _repository.Devices.Where(d => !d.Name.IsGroup());

            UserManualViewModel model = null;

            try
            {
                var guide =
                    _repository.GetUserManual(id.Replace(".", "%2E").Replace("!2F", "%2F") );
                if (guide != null)
                {
                    model = new UserManualViewModel
                    {
                        Id = guide.Id,
                        Title = guide.Title.Replace("%2E", "."),
                        Name = guide.Name,
                        Pages = guide.Pages.OrderBy(p => p.Title, new NaturalComparer(CultureInfo.CurrentCulture)),
                        ItemId = guide.ItemId
                    };

                    Device device = null;
                    if (model.ItemId > 0)
                        device = devices.FirstOrDefault(d => d.SFiles.Any(sf => sf.Id == model.ItemId));
                    else
                        device = devices.FirstOrDefault(d => d.SFiles.Any(f => id.Contains(f.Title)));
                    var group =
                        _repository.Devices.FirstOrDefault(
                            d =>
                                d.Name.IsGroup() && d.Name.IsIncludeOther(device.Name) &&
                                !string.IsNullOrEmpty(d.Url));
                    var section = sections.FirstOrDefault(s => s.Url == group.Url);

                    model.Device = device;
                    model.Section = section ?? new SectionModel
                    {
                        Title = "Other",
                        Url = "/"
                    };

                    if (string.IsNullOrEmpty(page))
                        return View("~/Views/Products/UserGuide.cshtml", model);
                    else
                    {
                        var m = guide.Pages.SingleOrDefault(p => p.Title.Contains(page.Replace(".", "%2E")));
                        Session["page"] = m;
                        return View("~/Views/Products/UserGuidePage.cshtml", m);
                    }
                }
            }
            catch (Exception ex)
            {
                throw;
            }

            return View("~/Views/Products/UserGuide.cshtml", model);
        }