示例#1
0
        public void AddWebsite(WebsiteType type, WebsiteService service, string address, string url)
        {
            if (_websites == null)
            {
                _websites = new List <Website>(1);
            }

            _websites.Add(Website.Create(type, service, address, url));
        }
示例#2
0
        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="websiteType">网站类型</param>
        /// <param name="tag">搜索标签</param>
        public PictureItems(WebsiteType websiteType, string tag = "")
        {
            noMorePicture = false;
            DB            = new DataBase(GlobalConfig.DataBaseName);
            website       = new Services.WebsiteHelper(websiteType, tag);
            loadAll       = ServiceLocator.Current.GetInstance <UserConfigVM>().Config.Rating == RatingType.All;

            // initial load some
            if (!Busy)
            {
                LoadMoreItemsAsync(100);
            }
        }
        public static string ToFriendlyString(this WebsiteType me)
        {
            switch (me)
            {
            case WebsiteType.Home:
                return("home");

            case WebsiteType.Work:
                return("work");

            default:
                return("");
            }
        }
示例#4
0
        public static Website GetWebsite(WebsiteType type)
        {
            switch (type)
            {
            case WebsiteType.BLOG:
                return(new Blog());

            case WebsiteType.SHOP:
                return(new Shop());

            default:
                return(null);
            }
        }
示例#5
0
        public static Website Create(WebsiteType type, WebsiteService service, string address, string url)
        {
            if (string.IsNullOrEmpty(address))
            {
                throw new ArgumentException("Address must be populated");
            }

            return(new Website()
            {
                Service = service.ToFriendlyString(),
                Type = type.ToFriendlyString(),
                Address = address,
                Url = url
            });
        }
        public static Website GetWebsite(WebsiteType siteType)
        {
            switch (siteType)
            {
            case CreationalDesignPatterns.Entities.FactoryMethod.WebSite.WebsiteType.BLOG:
            {
                return(new Blog());
            }

            case CreationalDesignPatterns.Entities.FactoryMethod.WebSite.WebsiteType.SHOP:
            {
                return(new Shop());
            }

            default:
            {
                return(null);
            }
            }
        }
示例#7
0
        public static Website createWebsite(WebsiteType type)
        {
            switch (type)
            {
            case WebsiteType.aLotOfText:
                return(new ALotOfText());

            case WebsiteType.contacts:
                return(new Contacts());

            case WebsiteType.news:
                return(new News());

            case WebsiteType.photoGallery:
                return(new Gallery());

            default:
                break;
            }
            return(null);
        }
示例#8
0
文件: Program.cs 项目: Casiell/NJPO
        private static void GenerateRandomPage()
        {
            Console.WriteLine("Press any key to generate random html website");
            Console.ReadKey();
            Array       values = Enum.GetValues(typeof(WebsiteType));
            Random      random = new Random();
            Website     website;
            WebsiteType type = (WebsiteType)values.GetValue(random.Next(values.Length));

            website = WebsiteFactory.createWebsite(type);
            string code = pageStart(type) + website.pageCode() + pageEnd();

            Console.WriteLine(code);
            string mydocpath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);

            //string mydocpath = Environment.CurrentDirectory;
            File.WriteAllText(@"D:\Szkoła\NJPO" + type.ToString() + ".html", code);
            Console.WriteLine(@"D:\Szkoła\NJPO\" + type.ToString() + ".html");
            Console.ReadKey();
            Console.Clear();
            GenerateRandomPage();
        }
示例#9
0
        public async void DisplayBulkHeadLines(WebsiteType type, int headlines)
        {
            int            countSites = 0;
            List <Website> allSites   = TheInternet.ReadFile(type);
            int            totalSites = (allSites.Count() == 0) ? 1:allSites.Count();

            if (this.listView.Items.Count > 0)
            {
                this.listView.Items.Clear();
            }
            if (this.sitelistBox.Items.Count > 0)
            {
                this.sitelistBox.Items.Clear();
            }

            PopulateSiteListbox();



            foreach (var site in allSites)
            {
                Tools.DebugTrace("siteloop", Thread.CurrentThread.ManagedThreadId);

                countSites++;
                var data = await Task.Run(() => Downloader.DownloadHtml(site));

                var listView = data.ToObservable()
                               .ObserveOn(Dispatcher)
                               .Where(x => x.Length > 5)
                               .Select(x => x.Trim())
                               .Take(headlines)
                               .Subscribe(x => PopulateView(site, x));

                statusLabel = data.ToObservable()
                              .ObserveOn(Dispatcher)
                              .Subscribe(x => PopulateLabel($"From {site.SiteName}  |  Feteched {countSites} of {totalSites}"));
            }
            statusLabel.Dispose();
        }
示例#10
0
 public static List <Website> ReadFile(WebsiteType type)
 {
     return((type == 0) ? ReadFile() :  ReadFile()
            .Where(s => s.Category == type)
            .ToList());
 }
示例#11
0
文件: Program.cs 项目: Casiell/NJPO
 private static string pageStart(WebsiteType webType)
 {
     return("<html>\n<head>\n<title>" + webType.ToString() + "</title>\n</head>\n<body>\n");
 }