Exemple #1
0
        public override ActionResult Index()
        {
            //标签
            List <TreeSelectModel> tagItemsList = _itemsDetailRepository.GetCombobox("Tag");

            tagItemsList.RemoveAt(0);
            ViewData["Tag"] = tagItemsList;

            //最新文章
            List <ArtDetailDto> latestArticles = _articleRepository.GetRecentArticle(5);

            ViewData["LatestArticles"] = latestArticles;

            //最热文章
            List <Article> hotArticles = _articleRepository.GetHotArticle(8);

            ViewData["HotArticles"] = hotArticles;

            //吐槽
            List <ReplyDto> spitslotList = _reviewRepository.GetRecentReview(8);

            ViewData["SpitslotList"] = spitslotList;

            //统计
            SiteStatistics site = _articleRepository.GetSiteData();

            ViewData["Site"] = site;

            //轻松时刻 | 缓存
            ViewData["JustFun"] = _iredisHelper.UnitOfWork(string.Format(ConstHelper.App, "JustFun"), () =>
            {
                List <ArtDetailDto> justFunList = _articleRepository.GetArticleList(_articleRepository.Queryable(u => u.DeleteMark == false && u.ItemsDetail.ItemCode == CategoryCode.Justfun.ToString())).OrderByDescending(u => u.Id).Take(5).ToList();
                if (justFunList.Count > 0)
                {
                    justFunList[0].Content = Server.UrlDecode(justFunList[0].Content);
                }
                return(justFunList);
            });

            //人生感悟 | 缓存
            ViewData["FellLife"] = _iredisHelper.UnitOfWork(string.Format(ConstHelper.App, "FellLife"), () =>
            {
                List <ArtDetailDto> feLifeList = _articleRepository.GetArticleList(_articleRepository.Queryable(u => u.DeleteMark == false && u.ItemsDetail.ItemCode == CategoryCode.Feelinglife.ToString())).OrderByDescending(u => u.Id).Take(5).ToList();
                if (feLifeList.Count > 0)
                {
                    feLifeList[0].Content = Server.UrlDecode(feLifeList[0].Content);
                }
                return(feLifeList);
            });

            return(base.Index());
        }
Exemple #2
0
        public SiteObject(ILoggerFactory loggerFactory = null)
        {
            var sharedFolder = Path.Combine(Path.GetDirectoryName(typeof(SiteObject).GetTypeInfo().Assembly.Location), SharedFolderName);

            _contentFileSystems = new List <IFileSystem>();
            var sharedPhysicalFileSystem = new PhysicalFileSystem();

            // Make sure that SharedFileSystem is a read-only filesystem
            SharedFileSystem     = new ReadOnlyFileSystem(new SubFileSystem(sharedPhysicalFileSystem, sharedPhysicalFileSystem.ConvertPathFromInternal(sharedFolder)));
            SharedMetaFileSystem = SharedFileSystem.GetOrCreateSubFileSystem(LunetFolder);

            _fileSystem = new AggregateFileSystem(SharedFileSystem);

            MetaFileSystem = new SubFileSystem(_fileSystem, LunetFolder);

            ConfigFile = new FileEntry(_fileSystem, UPath.Root / DefaultConfigFileName);

            StaticFiles  = new PageCollection();
            Pages        = new PageCollection();
            DynamicPages = new PageCollection();

            // Create the logger
            LoggerFactory = loggerFactory ?? Microsoft.Extensions.Logging.LoggerFactory.Create(builder =>
            {
                builder.AddProvider(new LoggerProviderIntercept(this))
                .AddFilter(LogFilter)
                .AddConsole();
            });

            Log          = LoggerFactory.CreateLogger("lunet");
            ContentTypes = new ContentTypeManager();

            DefaultPageExtension = DefaultPageExtensionValue;

            Html = new HtmlObject(this);
            SetValue(SiteVariables.Html, Html, true);

            CommandLine = new LunetCommandLine(this);

            Statistics = new SiteStatistics();

            Scripts = new ScriptingPlugin(this);

            Content = new ContentPlugin(this);

            Plugins = new OrderedList <ISitePlugin>();

            _pluginBuilders = new ContainerBuilder();
            _pluginBuilders.RegisterInstance(LoggerFactory).As <ILoggerFactory>();
            _pluginBuilders.RegisterInstance(this);
        }
        public override void Apply(T ruleContext)
        {
            FinishTestRuleContext finishTestRuleContext = ruleContext as FinishTestRuleContext;

            if (finishTestRuleContext != null)
            {
                ITestConfiguration           configuration      = finishTestRuleContext.Configuration;
                IEnumerable <TestExperience> testExperience     = configuration.Experiences;
                IContentTestPerformance      performanceForTest = finishTestRuleContext.ContentTestPerformanceFactory.GetPerformanceForTest(configuration);

                StopTestArgs stopTestArgs = new StopTestArgs();
                stopTestArgs.Configuration = finishTestRuleContext.Configuration;

                List <float>          list = new List <float>();
                List <TestExperience> listTestExperience = new List <TestExperience>();

                foreach (var experience in testExperience)
                {
                    SiteStatistics siteStatistics = performanceForTest.GetExperienceSiteStatistics(experience.Combination);
                    list.Add(siteStatistics.BounceRate);
                    listTestExperience.Add(experience);
                }

                if (list.Count != 0)
                {
                    int indexOfMinBounceRate = GetIndexOfLowestBounceRate(list);

                    if (indexOfMinBounceRate != 0)
                    {
                        TestCombination testCombination = new TestCombination(listTestExperience[indexOfMinBounceRate].Combination, configuration.TestSet);

                        if (testCombination == null)
                        {
                            return;
                        }
                        using (new Sitecore.Data.Items.EditContext(configuration.TestDefinitionItem))
                        {
                            configuration.TestDefinitionItem.WinnerCombination = testCombination.Combination.MultiplexToString("-");
                        }
                        Sitecore.Data.Items.Item item    = configuration.TestDefinitionItem;
                        Sitecore.Data.Database[] targets = PublishingHelper.GetTargets(item).ToArray <Sitecore.Data.Database>();
                        Sitecore.Publishing.PublishManager.PublishItem(item, targets, item.Languages, true, true);
                        stopTestArgs.Combination = testCombination;
                        SettingsDependantPipeline <StopTestPipeline, StopTestArgs> .Instance.Run(stopTestArgs);
                    }
                }
            }
        }
Exemple #4
0
        /// <summary>
        /// Starts the importation process
        /// </summary>
        /// <returns>bool - sucess/fail</returns>
        public bool Import()
        {
            _status.Status    = "Loading configuration...";
            _status.Channels  = 0;
            _status.Programs  = 0;
            _status.StartTime = DateTime.Now;
            _status.EndTime   = new DateTime(1971, 11, 6);
            if (ShowProgress != null)
            {
                ShowProgress(_status);
            }

            if (!LoadConfig())
            {
                return(false);
            }

            _epgDataSink.Open();

            // Collect HttpStatistic
            IHttpStatistics httpStats;

            if (GlobalServiceProvider.Instance.IsRegistered <IHttpStatistics>())
            {
                httpStats = GlobalServiceProvider.Instance.Get <IHttpStatistics>();
            }
            else
            {
                httpStats = new HttpStatistics();
                GlobalServiceProvider.Instance.Add <IHttpStatistics>(httpStats);
            }

            Log.Info("WebEPG: Loading Channel Config");
            _grabList = new Dictionary <string, List <grabInfo> >();
            // for each channel write info xmltv file.
            List <ChannelMap> allChannels = new List <ChannelMap>(_config.Channels);

            allChannels.AddRange(_config.RadioChannels);
            foreach (ChannelMap channel in allChannels)
            {
                if (channel.id == null && channel.merged == null)
                {
                    Log.Info(" Ignoring Channel Name: {0} - No Channel id", channel.displayName);
                    continue;
                }

                if (channel.merged == null || channel.merged.Count == 0)
                {
                    if (channel.grabber != null)
                    {
                        Log.Debug(" Loading Channel {0} ID: {1}", channel.displayName, channel.id);
                        //xmltv.WriteChannel(channel.id, channel.displayName);
                        _epgDataSink.WriteChannel(channel.id, channel.displayName);

                        grabInfo grab = new grabInfo();
                        grab.name     = channel.displayName;
                        grab.id       = channel.id;
                        grab.grabber  = channel.grabber;
                        grab.merged   = false;
                        grab.linked   = true;
                        grab.linkTime = new TimeRange("00:00", "23:00");

                        if (!_grabList.ContainsKey(channel.id))
                        {
                            List <grabInfo> grabs = new List <grabInfo>();
                            grabs.Add(grab);
                            _grabList.Add(channel.id, grabs);
                        }
                        else
                        {
                            _grabList[channel.id].Add(grab);
                        }
                    }
                    else
                    {
                        Log.Info(" Ignoring Channel Name: {0} - No Grabber id", channel.displayName);
                    }
                }
                else
                {
                    Log.Debug(" Loading Merged Channel {0}", channel.displayName);
                    //xmltv.WriteChannel("[Merged]", channel.displayName);
                    _epgDataSink.WriteChannel("[Merged]", channel.displayName);

                    foreach (MergedChannel merged in channel.merged)
                    {
                        if (merged.grabber != null)
                        {
                            grabInfo grab = new grabInfo();
                            grab.name     = channel.displayName;
                            grab.id       = merged.id;
                            grab.grabber  = merged.grabber;
                            grab.merged   = true;
                            grab.linked   = true;
                            grab.linkTime = new TimeRange(merged.start, merged.end);
                            Log.Debug("  Loading Merged Sub-channel: {0} Time range: {1}", merged.id,
                                      grab.linkTime.ToString());

                            if (!_grabList.ContainsKey(merged.id))
                            {
                                List <grabInfo> grabs = new List <grabInfo>();
                                grabs.Add(grab);
                                _grabList.Add(merged.id, grabs);
                            }
                            else
                            {
                                _grabList[merged.id].Add(grab);
                            }
                        }
                        else
                        {
                            Log.Info("  Ignoring Merged Sub-channel: {0}/{1} - No Grabber id", channel.displayName,
                                     merged.id);
                        }
                    }
                }
            }

            string             grabberLast = "";
            List <ProgramData> programs    = null;
            bool initResult = false;

            _epgGrabber = new WebListingGrabber(_baseDirectory + "\\WebEPG\\grabbers\\");

            // For each channel get listing
            int i = 1;

            foreach (string channelid in _grabList.Keys)
            {
                _status.Status = string.Format("Getting Channel ID: {0} [{1} of {2}]", channelid, i, _grabList.Count);
                if (ShowProgress != null)
                {
                    ShowProgress(_status);
                }

                Log.Info("WebEPG: Getting Channel ID: {0}", channelid);
                Log.Info("        [{0} of {1}]", i++, _grabList.Count);

                if (_grabList[channelid].Count > 0)
                {
                    if (_grabList[channelid][0].grabber != grabberLast)
                    {
                        initResult = _epgGrabber.Initalise(_grabList[channelid][0].grabber, _config.Info.GrabDays);
                    }

                    grabberLast = _grabList[channelid][0].grabber;


                    // Get channel listing
                    if (initResult)
                    {
                        programs = _epgGrabber.GetGuide(channelid, _grabList[channelid][0].name, _grabList[channelid][0].linked,
                                                        _grabList[channelid][0].linkTime);
                    }

                    if (programs != null)
                    {
                        // write programs
                        foreach (grabInfo grab in _grabList[channelid])
                        {
                            _status.Status = string.Format("Writing channel {0}", grab.name);
                            if (ShowProgress != null)
                            {
                                ShowProgress(_status);
                            }

                            if (grab.merged)
                            {
                                Log.Info("WebEPG: Writing Merged Channel Part: {0}", grab.name);
                                Log.Info("        [{0}]", grab.linkTime);
                                if (_epgDataSink.StartChannelPrograms("[Merged]", grab.name))
                                {
                                    _epgDataSink.SetTimeWindow(grab.linkTime);
                                    for (int p = 0; p < programs.Count; p++)
                                    {
                                        if (grab.linkTime.IsInRange(programs[p].StartTime.ToLocalTime()))
                                        {
                                            //xmltv.WriteProgram(programs[p], grab.name, true);
                                            _epgDataSink.WriteProgram(programs[p], true);
                                            _status.Programs++;
                                        }
                                    }
                                    _epgDataSink.EndChannelPrograms("[Merged]", grab.name);
                                }
                            }
                            else
                            {
                                Log.Info("WebEPG: Writing Channel: {0}", grab.name);
                                if (_epgDataSink.StartChannelPrograms(channelid, grab.name))
                                {
                                    for (int p = 0; p < programs.Count; p++)
                                    {
                                        //xmltv.WriteProgram(programs[p], grab.name, false);
                                        _epgDataSink.WriteProgram(programs[p], false);
                                        _status.Programs++;
                                    }
                                    _epgDataSink.EndChannelPrograms(channelid, grab.name);
                                }
                            }

                            _status.Channels++;
                            if (ShowProgress != null)
                            {
                                ShowProgress(_status);
                            }
                        }
                    }
                    else
                    {
                        foreach (grabInfo grab in _grabList[channelid])
                        {
                            Log.Info("WebEPG: Grabber failed for: {0}", grab.name);
                        }
                    }
                }
            }

            _status.Status = "Finishing...";
            if (ShowProgress != null)
            {
                ShowProgress(_status);
            }
            //xmltv.Close();
            _epgDataSink.Close();

            // log Http statistics
            for (int h = 0; h < httpStats.Count; h++)
            {
                SiteStatistics site = httpStats.GetbyIndex(h);
                Log.Info("HTTP Statistics: {0}", site.ToString());
                httpStats.Clear(site.Site);
            }

            _status.EndTime = DateTime.Now;
            _status.Status  = "Finished grabbing.";
            if (ShowProgress != null)
            {
                ShowProgress(_status);
            }

            return(true);
        }
Exemple #5
0
        public SiteObject(ILoggerFactory loggerFactory = null)
        {
            ReadmeAsIndex = true;
            ErrorRedirect = "/404.html";
            var sharedFolder = Path.Combine(AppContext.BaseDirectory, SharedFolderName);

            _contentFileSystems = new List <IFileSystem>();
            var sharedPhysicalFileSystem = new PhysicalFileSystem();

            // Make sure that SharedFileSystem is a read-only filesystem
            SharedFileSystem     = new ReadOnlyFileSystem(new SubFileSystem(sharedPhysicalFileSystem, sharedPhysicalFileSystem.ConvertPathFromInternal(sharedFolder)));
            SharedMetaFileSystem = SharedFileSystem.GetOrCreateSubFileSystem(LunetFolder);

            _fileSystem = new AggregateFileSystem(SharedFileSystem);

            // MetaFileSystem provides an aggregate view of the shared meta file system + the user meta file system
            _metaFileSystem = new AggregateFileSystem(SharedMetaFileSystem);
            MetaFileSystem  = _metaFileSystem;

            ConfigFile = new FileEntry(_fileSystem, UPath.Root / DefaultConfigFileName);

            StaticFiles  = new PageCollection();
            Pages        = new PageCollection();
            DynamicPages = new PageCollection();

            // Create the logger
            LoggerFactory = loggerFactory ?? Microsoft.Extensions.Logging.LoggerFactory.Create(builder =>
            {
                // Similar to builder.AddSimpleConsole
                // But we are using our own console that stays on the same line if the message doesn't have new lines
                builder.AddConfiguration();
                builder.AddProvider(new LoggerProviderIntercept(this))
                .AddFilter(LogFilter)
                .AddConsoleFormatter <SimpleConsoleFormatter, SimpleConsoleFormatterOptions>(configure =>
                {
                    configure.SingleLine = true;
                });
                builder.Services.TryAddEnumerable(ServiceDescriptor.Singleton <ILoggerProvider, ConsoleLoggerProvider>());
                LoggerProviderOptions.RegisterProviderOptions <ConsoleLoggerOptions, ConsoleLoggerProvider>(builder.Services);
            });

            Log          = LoggerFactory.CreateLogger("lunet");
            ContentTypes = new ContentTypeManager();

            DefaultPageExtension = DefaultPageExtensionValue;

            Html = new HtmlPage(this);

            CommandLine = new LunetCommandLine(this);

            Statistics = new SiteStatistics();

            Scripts = new ScriptingPlugin(this);

            Content = new ContentPlugin(this);

            Plugins = new OrderedList <ISitePlugin>();

            Builtins      = new BuiltinsObject(this);
            ForceExcludes = new GlobCollection()
            {
                $"**/{LunetFolderName}/{BuildFolderName}/**",
                $"/{DefaultConfigFileName}",
            };
            Excludes = new GlobCollection()
            {
                "**/~*/**",
                "**/.*/**",
                "**/_*/**",
            };
            Includes = new GlobCollection()
            {
                $"**/{LunetFolderName}/**",
            };
            SetValue(SiteVariables.ForceExcludes, ForceExcludes, true);
            SetValue(SiteVariables.Excludes, Excludes, true);
            SetValue(SiteVariables.Includes, Includes, true);

            SetValue(SiteVariables.Pages, Pages, true);

            _pluginBuilders = new ContainerBuilder();
            _pluginBuilders.RegisterInstance(LoggerFactory).As <ILoggerFactory>();
            _pluginBuilders.RegisterInstance(this);
        }
    /// <summary>
    /// Adds to the statistics for a specified site.
    /// </summary>
    /// <param name="site">The site.</param>
    /// <param name="pages">The pages.</param>
    /// <param name="bytes">The bytes.</param>
    public void Add(string site, int pages, int bytes, TimeSpan time)
    {
      SiteStatistics stats;

      if (_siteList == null)
      {
        _siteList = new Dictionary<string, SiteStatistics>();
      }

      if (_siteList.ContainsKey(site))
      {
        stats = _siteList[site];
        stats.Add(pages, bytes, time);
      }
      else
      {
        stats = new SiteStatistics(site);
        stats.Add(pages, bytes, time);
        _siteList.Add(site, stats);
      }
    }