Exemplo n.º 1
0
        public List <BlogTypes> GetAllTypes()
        {
            List <BlogTypes> list = null;

            _data.ExecuteCmd(
                "dbo.BlogTypes_SelectAll",
                inputParamMapper : delegate(SqlParameterCollection parameterCollection)
            {
            },
                singleRecordMapper : delegate(IDataReader reader, short set)
            {
                BlogTypes aBlogType = MapBlogTypes(reader, out int startingIndex);
                if (list == null)
                {
                    list = new List <BlogTypes>();
                }
                list.Add(aBlogType);
            }
                );
            if (list != null)
            {
                list = new List <BlogTypes>(list);
            }
            return(list);
        }
Exemplo n.º 2
0
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            BlogTypes type = (BlogTypes)value;

            switch (type)
            {
            case BlogTypes.tumblr:
                return(string.Format(CultureInfo.CurrentCulture, Resources.BlogtypeTumblr));

            case BlogTypes.tmblrpriv:
                return(string.Format(CultureInfo.CurrentCulture, Resources.BlogtypeTumblrPrivate));

            case BlogTypes.tumblrsearch:
                return(string.Format(CultureInfo.CurrentCulture, Resources.BlogtypeTumblrSearch));

            case BlogTypes.tumblrtagsearch:
                return(string.Format(CultureInfo.CurrentCulture, Resources.BlogtypeTumblrTagSearch));

            case BlogTypes.tlb:
                return(string.Format(CultureInfo.CurrentCulture, Resources.BlogtypeTumblrLikedBy));

            case BlogTypes.instagram:
                return(string.Format(CultureInfo.CurrentCulture, Resources.BlogtypeInstagram));

            case BlogTypes.twitter:
                return(string.Format(CultureInfo.CurrentCulture, Resources.BlogtypeTwitter));

            case BlogTypes.all:
                return("");

            default:
                return("");
            }
        }
Exemplo n.º 3
0
        public ICrawler GetCrawler(BlogTypes blogtype, CancellationToken ct, PauseToken pt, IProgress <DownloadProgress> progress, IShellService shellService, ICrawlerService crawlerService, IBlog blog)
        {
            BlockingCollection <TumblrPost> producerConsumerCollection = GetProducerConsumerCollection();
            IFiles files = LoadFiles(blog);

            switch (blogtype)
            {
            case BlogTypes.tumblr:
                return(new TumblrBlogCrawler(shellService, ct, pt, progress, crawlerService, cookieService, GetTumblrDownloader(ct, pt, progress, shellService, crawlerService, blog, files, producerConsumerCollection), producerConsumerCollection, blog));

            case BlogTypes.tmblrpriv:
                return(new TumblrPrivateCrawler(shellService, ct, pt, progress, crawlerService, cookieService, GetTumblrDownloader(ct, pt, progress, shellService, crawlerService, blog, files, producerConsumerCollection), producerConsumerCollection, blog));

            case BlogTypes.tlb:
                return(new TumblrLikedByCrawler(shellService, ct, pt, progress, crawlerService, cookieService, GetTumblrDownloader(ct, pt, progress, shellService, crawlerService, blog, files, producerConsumerCollection), producerConsumerCollection, blog));

            case BlogTypes.tumblrsearch:
                return(new TumblrSearchCrawler(shellService, ct, pt, progress, crawlerService, cookieService, GetTumblrDownloader(ct, pt, progress, shellService, crawlerService, blog, files, producerConsumerCollection), producerConsumerCollection, blog));

            case BlogTypes.tumblrtagsearch:
                return(new TumblrTagSearchCrawler(shellService, ct, pt, progress, crawlerService, cookieService, GetTumblrDownloader(ct, pt, progress, shellService, crawlerService, blog, files, producerConsumerCollection), producerConsumerCollection, blog));

            default:
                throw new ArgumentException("Website is not supported!", "blogType");
            }
        }
Exemplo n.º 4
0
 protected Files(string name, string location, BlogTypes blogType)
 {
     Name       = name;
     Location   = location;
     BlogType   = blogType;
     this.links = new List <string>();
 }
Exemplo n.º 5
0
        public static Blog Create(string url, string location, BlogTypes blogType)
        {
            var blog = new Blog()
            {
                Url       = ExtractUrl(url),
                Name      = ExtractName(url),
                BlogType  = blogType,
                Location  = location,
                Version   = "3",
                DateAdded = DateTime.Now,
                links     = new List <string>()
            };

            Directory.CreateDirectory(location);
            Directory.CreateDirectory(Path.Combine(Directory.GetParent(location).FullName, blog.Name));

            blog.ChildId = Path.Combine(location, blog.Name + "_files." + blogType);
            if (!File.Exists(blog.ChildId))
            {
                IFiles files = new Files(blog.Name, blog.Location, blog.BlogType);
                files.Save();
                files = null;
            }
            return(blog);
        }
Exemplo n.º 6
0
 public Files(string name, string location, BlogTypes blogType) : this()
 {
     Name     = name;
     Location = location;
     BlogType = blogType;
     Version  = "1";
     links    = new List <string>();
 }
Exemplo n.º 7
0
        private static BlogTypes MapBlogTypes(IDataReader reader, out int startingIndex)
        {
            BlogTypes aBlogType = new BlogTypes();

            startingIndex  = 0;
            aBlogType.Id   = reader.GetSafeInt32(startingIndex++);
            aBlogType.Name = reader.GetSafeString(startingIndex++);

            return(aBlogType);
        }
Exemplo n.º 8
0
        public IDownloader GetDownloader(BlogTypes blogtype)
        {
            Lazy <IDownloader, IBlogTypeMetaData> downloaderInstance =
                DownloaderFactoryLazy.FirstOrDefault(list => list.Metadata.BlogType == blogtype);

            if (downloaderInstance != null)
            {
                return(downloaderInstance.Value);
            }
            throw new ArgumentException("Website is not supported!", "blogType");
        }
Exemplo n.º 9
0
        public Lazy <IDetailsViewModel> GetViewModel(BlogTypes blogtype)
        {
            Lazy <IDetailsViewModel, ICrawlerData> viewModel =
                ViewModelFactoryLazy.FirstOrDefault(list => list.Metadata.BlogType == blogtype);

            if (viewModel != null)
            {
                return(viewModel);
            }
            throw new ArgumentException("Website is not supported!", "blogType");
        }
Exemplo n.º 10
0
        public IDownloader GetDownloader(BlogTypes blogtype, IShellService shellService, ICrawlerService crawlerService, IBlog blog)
        {
            switch (blogtype)
            {
            case BlogTypes.tumblr:
                return(new TumblrDownloader(shellService, crawlerService, blog));

            default:
                throw new ArgumentException("Website is not supported!", "blogType");
            }
        }
Exemplo n.º 11
0
        protected Blog(string url, string location, BlogTypes blogType)
        {
            Url      = url;
            Url      = ExtractUrl();
            Name     = ExtractSubDomain();
            BlogType = blogType;
            ChildId  = Path.Combine(location, Name + "_files." + blogType);
            Location = location;

            DateAdded         = DateTime.Now;
            LastCompleteCrawl = new DateTime(0L, DateTimeKind.Utc);
        }
Exemplo n.º 12
0
        public TumblrBlog(string url, string location, BlogTypes type) : base(url, location, type)
        {
            Version = "3";

            Directory.CreateDirectory(Location);
            Directory.CreateDirectory(Path.Combine(Directory.GetParent(Location).FullName, Name));

            if (!File.Exists(ChildId))
            {
                Files files = new TumblrFiles(Name, Location, BlogType);

                files.Save();
                files = null;
            }
        }
Exemplo n.º 13
0
        public JsonBackResult AddArticleContent(string htmltext, string title, string typeid, string summary, string checkbox1)
        {
            var         id      = Convert.ToInt32(typeid);
            BlogTypes   type    = this._blogTypeWebService.GetList(s => s.Id == id && s.State == 1).ToList().FirstOrDefault();
            BlogArticle article = new BlogArticle();

            article.Content    = htmltext;
            article.CreateTime = DateTime.Now;
            article.State      = 1;
            article.Summary    = summary;
            article.Title      = title;
            article.Type       = type;
            article.UpdateTime = DateTime.Now;
            article.WatchCount = 0;
            article.ZanCount   = 0;
            article.Address    = " ";
            this._blogArticleWebService.Add(article);

            return(JsonBackResult(ResultStatus.Success));
        }
Exemplo n.º 14
0
        /// <summary>
        /// 编辑文章类型
        /// </summary>
        /// <param name="typename"></param>
        /// <param name="typeid"></param>
        /// <returns></returns>
        public ActionResult EditType(string typename, int typeid)
        {
            JSData jsdata = new JSData();

            #region 数据验证
            if (null == BLLSession.UserInfoSessioin)
            {
                jsdata.Message = "您还未登录~";
            }
            else if (string.IsNullOrEmpty(typename))
            {
                jsdata.Message = "类型不能为空~";
            }
            if (!string.IsNullOrEmpty(jsdata.Message))
            {
                jsdata.State = EnumState.失败;
                return(Json(jsdata));
            }
            #endregion

            BLL.BlogTypesBLL bll = new BlogTypesBLL();
            var blogtype         = new BlogTypes()
            {
                BlogTypeId = typeid,
                TypeName   = typename
            };


            if (bll.Mod(blogtype, "TypeName"))  //保存
            {
                BLL.DataCache.GetAllType(true); //更新缓存
                jsdata.State = EnumState.成功;
                // jsdata.Messg = "修改成功~";
            }
            else
            {
                jsdata.State   = EnumState.失败;
                jsdata.Message = "操作失败~";
            }
            return(Json(jsdata));
        }
Exemplo n.º 15
0
        public Blog(string url, string location, BlogTypes blogType)
        {
            Url       = url;
            Url       = ExtractUrl();
            Name      = ExtractName();
            BlogType  = blogType;
            ChildId   = Path.Combine(location, Name + "_files." + blogType);
            Location  = location;
            Version   = "3";
            DateAdded = DateTime.Now;

            Directory.CreateDirectory(Location);
            Directory.CreateDirectory(Path.Combine(Directory.GetParent(Location).FullName, Name));

            if (!File.Exists(ChildId))
            {
                IFiles files = new Files(Name, Location, BlogType);

                files.Save();
                files = null;
            }
        }
Exemplo n.º 16
0
        public List <BlogTypes> GetBlogTypes()
        {
            List <BlogTypes> list = null;

            string procName = "[dbo].[BlogTypes_SelectAll]";

            _data.ExecuteCmd(procName, inputParamMapper : null, singleRecordMapper : delegate(IDataReader reader, short set)
            {
                BlogTypes aType   = new BlogTypes();
                int startingIndex = 0;

                aType.BlogTypeId = reader.GetSafeInt32(startingIndex++);
                aType.Name       = reader.GetSafeString(startingIndex++);

                if (list == null)
                {
                    list = new List <BlogTypes>();
                }
                list.Add(aType);
            });
            return(list);
        }
Exemplo n.º 17
0
 public TumblrFiles(string name, string location, BlogTypes blogType) : base(name, location, blogType)
 {
     Version = "1";
 }
Exemplo n.º 18
0
 public TumblrSearchBlog(string url, string location, BlogTypes blogType) : base(url, location, blogType)
 {
 }
Exemplo n.º 19
0
 public InstagramFiles(string name, string location, BlogTypes blogType) : base(name, location, blogType)
 {
     version = "1";
 }
Exemplo n.º 20
0
 public InstagramBlog(string url, string location, BlogTypes type) : base(url, location, type)
 {
 }
Exemplo n.º 21
0
        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();
            WebApiConfig.Register(GlobalConfiguration.Configuration);
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            BundleConfig.RegisterBundles(BundleTable.Bundles);

            #region Autofac在MVC中注册
            ContainerBuilder builder = new ContainerBuilder();
            var        service       = Assembly.Load("IService");
            var        service1      = Assembly.Load("Service");
            var        service2      = Assembly.Load("Model");
            Assembly[] assemblyArr   = new Assembly[] { service, service1, service2 };
            builder.RegisterControllers(Assembly.GetExecutingAssembly());
            builder.RegisterAssemblyTypes(assemblyArr).AsImplementedInterfaces();
            var container = builder.Build();
            DependencyResolver.SetResolver(new AutofacDependencyResolver(container));
            #endregion

            #region 添加初始数据
            DbContext db = new MyContext();
            if (db.Database.CreateIfNotExists())
            {
                //前台权限
                IAuthorityWebService  authorityService = new AuthorityWebService();
                List <AuthorityModel> authorityList    = new List <AuthorityModel>()
                {
                    new AuthorityModel()
                    {
                        BuildTime = DateTime.Now, Description = "读博客的权限", Name = "读权限", State = 1, Type = 1, UpdateTime = DateTime.Now, RoleModels = new List <RoleModel>()
                    },
                    new AuthorityModel()
                    {
                        BuildTime = DateTime.Now, Description = "写博客的权限", Name = "写权限", State = 1, Type = 1, UpdateTime = DateTime.Now, RoleModels = new List <RoleModel>()
                    }
                };
                authorityService.AddRange(authorityList);
                AuthorityModel authority1 = new AuthorityModel();
                authority1 = authorityService.GetList(s => s.Name == "读权限" && s.State == 1).ToList().FirstOrDefault();


                //前台角色
                IRoleWebService  roleService = new RoleWebService();
                List <RoleModel> roleList    = new List <RoleModel>()
                {
                    new RoleModel()
                    {
                        BuildTime = DateTime.Now, Description = "一般用户", RoleName = "普通用户", State = 1, UpdateTime = DateTime.Now, AuthorityModels = new List <AuthorityModel>(), UserModels = new List <UserModel>()
                    },
                    new RoleModel()
                    {
                        BuildTime = DateTime.Now, Description = "充值的用户拥有更多权限", RoleName = "VIP用户", State = 1, UpdateTime = DateTime.Now, AuthorityModels = new List <AuthorityModel>(), UserModels = new List <UserModel>()
                    }
                };
                roleService.AddRange(roleList);

                var role1 = roleService.GetList(s => s.RoleName == "普通用户" && s.State == 1).ToList().FirstOrDefault();
                var role2 = roleService.GetList(s => s.RoleName == "VIP用户" && s.State == 1).ToList().FirstOrDefault();
                role1.AuthorityModels.Add(authority1);
                role2.AuthorityModels.Add(authority1);
                roleService.Update(role1);
                roleService.Update(role2);

                //用户数据
                IUserWebService  userService = new UserWebService();
                List <UserModel> userList    = new List <UserModel>()
                {
                    new UserModel()
                    {
                        BuildTime = DateTime.Now, Count = 0, EMail = "*****@*****.**", HeadPicUrl = "~/Imgs/HeadPic/headpic-1.jpg", LoginTime = DateTime.Now, Type = 1, Pwd = Common.EncryptionHelper.GetMd5Str("112233"), State = 1, TelNumber = "155555555", Name = "MrChen", UpdateTime = DateTime.Now, Role = role1
                    },
                    new UserModel()
                    {
                        BuildTime = DateTime.Now, Count = 0, EMail = "*****@*****.**", HeadPicUrl = "~/Imgs/HeadPic/headpic-2.jpg", LoginTime = DateTime.Now, Type = 2, Pwd = Common.EncryptionHelper.GetMd5Str("112233"), State = 1, TelNumber = "155555555", Name = "MrSong", UpdateTime = DateTime.Now, Role = role2
                    }
                };
                userService.AddRange(userList);

                UserModel user11 = new UserModel();
                user11 = userService.GetList(s => s.Id == 1).ToList().FirstOrDefault();

                //博客类型
                IBlogTypeWebService blogTypeService = new BlogTypeWebService();
                List <BlogTypes>    typeList        = new List <BlogTypes>()
                {
                    new BlogTypes()
                    {
                        CreateTime = DateTime.Now, State = 1, TypeName = "类型1", UpdateTmie = DateTime.Now, BlogArticles = new List <BlogArticle>()
                    },
                    new BlogTypes()
                    {
                        CreateTime = DateTime.Now, State = 1, TypeName = "类型2", UpdateTmie = DateTime.Now, BlogArticles = new List <BlogArticle>()
                    },
                };
                blogTypeService.AddRange(typeList);

                var       type1  = blogTypeService.GetList(s => s.Id == 1).ToList().FirstOrDefault();
                var       type2  = blogTypeService.GetList(s => s.Id == 2).ToList().FirstOrDefault();
                BlogTypes type11 = new BlogTypes();
                type11 = type1;
                BlogTypes type22 = new BlogTypes();
                type22 = type2;

                //博客文章
                IBlogArticleWebService blogArticleService = new BlogArticleWebService();
                List <BlogArticle>     articleList        = new List <BlogArticle>()
                {
                    new BlogArticle()
                    {
                        Address = "1313", Content = "1211122212", CreateTime = DateTime.Now, State = 1, Title = "测试1", UpdateTime = DateTime.Now, WatchCount = 1, ZanCount = 0, BlogComments = new List <BlogComment>(), Type = type11, Summary = "aaa"
                    },
                    new BlogArticle()
                    {
                        Address = "1312", Content = "1211122212", CreateTime = DateTime.Now, State = 1, Title = "测试2", UpdateTime = DateTime.Now, WatchCount = 1, ZanCount = 0, BlogComments = new List <BlogComment>(), Type = type22, Summary = "bbb"
                    }
                };
                blogArticleService.AddRange(articleList);

                BlogArticle article1 = new BlogArticle();
                article1 = blogArticleService.GetList(s => s.Id == 1).ToList().FirstOrDefault();

                //博客评论
                IBlogCommentWebService blogCommentService = new BlogCommentWebService();
                List <BlogComment>     commentList        = new List <BlogComment>()
                {
                    new BlogComment()
                    {
                        Content = "你好啊", UpdateTime = DateTime.Now, State = 1, CommentId = 0, BlogArticle = article1, User = user11, CreateTime = DateTime.Now
                    },
                    new BlogComment()
                    {
                        Content = "你好啊", UpdateTime = DateTime.Now, State = 1, CommentId = 1, BlogArticle = article1, User = user11, CreateTime = DateTime.Now
                    },
                };
                blogCommentService.AddRange(commentList);



                //管理员数据
                IAdminUserService adminUserService = new AdminUserService();
                List <AdminUser>  adminUserList    = new List <AdminUser>()
                {
                    new AdminUser()
                    {
                        BuildTime = DateTime.Now, Name = "sbk", LoginTime = DateTime.Now, Password = Common.EncryptionHelper.GetMd5Str("abc112233"), State = 1, TelNumber = "18251935175", Type = 1
                    },
                    new AdminUser()
                    {
                        BuildTime = DateTime.Now, Name = "admin", LoginTime = DateTime.Now, Password = Common.EncryptionHelper.GetMd5Str("abc112233"), State = 1, TelNumber = "18251935175", Type = 1
                    }
                };
                adminUserService.AddRange(adminUserList);

                //后台权限数据
                IAdminAuthorityService adminAuthorityService = new AdminAuthorityService();
                List <AdminAuthority>  adminAuthorityList    = new List <AdminAuthority>()
                {
                    new AdminAuthority()
                    {
                        BuildTime = DateTime.Now, Description = "用于读取基本信息的权限", Name = "读权限", State = 1, Type = 1
                    },
                    new AdminAuthority()
                    {
                        BuildTime = DateTime.Now, Description = "用于写入基本信息的权限", Name = "写权限", State = 1, Type = 1
                    }
                };
                adminAuthorityService.AddRange(adminAuthorityList);

                //后台角色数据
                IAdminRoleService adminRoleService = new AdminRoleService();
                List <AdminRole>  adminRoleList    = new List <AdminRole>()
                {
                    new AdminRole()
                    {
                        BuildTime = DateTime.Now, Description = "管理单个项目", RoleName = "S级管理员", State = 1
                    },
                    new AdminRole()
                    {
                        BuildTime = DateTime.Now, Description = "管理单个项目", RoleName = "SS级管理员", State = 1
                    }
                };
                adminRoleService.AddRange(adminRoleList);
            }
            #endregion
            //log4net.Config.XmlConfigurator.Configure();//读取Log4Net配置信息

            //MiniProfilerEF6.Initialize();//注册MiniProfiler,网页性能插件

            log4net.Config.XmlConfigurator.Configure();

            //WaitCallback
            ThreadPool.QueueUserWorkItem((a) =>
            {
                while (true)
                {
                    if (MyExceptionAttribute.ExceptionQueue.Count > 0)
                    {
                        Exception ex = MyExceptionAttribute.ExceptionQueue.Dequeue();//出队
                        //string fileName = DateTime.Now.ToString("yyyy-MM-dd")+".txt";
                        //File.AppendAllText(fileLogPath + fileName, ex.ToString(), System.Text.Encoding.Default);
                        //ILog logger = LogManager.GetLogger("errorMsg");
                        ILog logger = log4net.LogManager.GetLogger("logger");
                        logger.Error(ex.ToString());

                        #region 发送邮件
                        //MailHelper mail = new MailHelper();
                        //mail.MailServer = "smtp.qq.com";
                        //mail.MailboxName = "*****@*****.**";
                        //mail.MailboxPassword = "******";//开启QQ邮箱POP3/SMTP服务时给的授权码
                        ////操作打开QQ邮箱->在账号下方点击"设置"->账户->POP3/IMAP/SMTP/Exchange/CardDAV/CalDAV服务
                        ////obxxsfowztbideee为2872845261@qq的授权码
                        //mail.MailName = "Error";
                        //try
                        //{
                        //    mail.Send("*****@*****.**", "Error", ex.ToString());
                        //}
                        //catch
                        //{ }
                        #endregion
                    }
                    else
                    {
                        Thread.Sleep(3000);//如果队列中没有数据,则休息为了避免占用CPU的资源.
                    }
                }
            });
        }
Exemplo n.º 22
0
 public TumblrLikeByBlog(string url, string location, BlogTypes blogType) : base(url, location, blogType)
 {
 }