Esempio n. 1
0
        public IBlog GetBlog(string blogUrl, string path, string filenameTemplate)
        {
            blogUrl = _urlValidator.AddHttpsProtocol(blogUrl);

            if (_urlValidator.IsValidTumblrLikesUrl(blogUrl))
            {
                return(TumblrLikedByBlog.Create(blogUrl, path, filenameTemplate));
            }

            if (_urlValidator.IsValidTumblrUrl(blogUrl))
            {
                return(TumblrBlog.Create(blogUrl, path, filenameTemplate));
            }

            if (_urlValidator.IsTumbexUrl(blogUrl))
            {
                return(TumblrBlog.Create(CreateTumblrUrlFromTumbex(blogUrl), path, filenameTemplate));
            }

            if (_urlValidator.IsValidTumblrHiddenUrl(blogUrl))
            {
                return(TumblrHiddenBlog.Create(blogUrl, path, filenameTemplate));
            }

            if (_urlValidator.IsValidTumblrLikedByUrl(blogUrl))
            {
                return(TumblrLikedByBlog.Create(blogUrl, path, filenameTemplate));
            }

            if (_urlValidator.IsValidTumblrSearchUrl(blogUrl))
            {
                return(TumblrSearchBlog.Create(blogUrl, path, filenameTemplate));
            }

            if (_urlValidator.IsValidTumblrTagSearchUrl(blogUrl))
            {
                return(TumblrTagSearchBlog.Create(blogUrl, path, filenameTemplate));
            }

            if (_urlValidator.IsValidTwitterUrl(blogUrl))
            {
                return(TwitterBlog.Create(blogUrl, path, filenameTemplate));
            }

            throw new ArgumentException("Website is not supported!", nameof(blogUrl));
        }
Esempio n. 2
0
        private IReadOnlyList <IBlog> GetIBlogsCore(string directory)
        {
            Logger.Verbose("ManagerController:GetIBlogsCore Start");

            var blogs             = new List <IBlog>();
            var failedToLoadBlogs = new List <string>();

            string[] supportedFileTypes = Enum.GetNames(typeof(BlogTypes)).ToArray();

            int[] validCollectionIds = _shellService.Settings.Collections.Select(s => s.Id).ToArray();

            foreach (string filename in Directory.GetFiles(directory, "*").Where(
                         fileName => supportedFileTypes.Any(fileName.Contains) &&
                         !fileName.Contains("_files")))
            {
                //TODO: Refactor
                try
                {
                    IBlog blog = null;

                    if (filename.EndsWith(BlogTypes.tumblr.ToString()))
                    {
                        blog = new TumblrBlog().Load(filename);
                    }

                    if (filename.EndsWith(BlogTypes.tmblrpriv.ToString()))
                    {
                        blog = new TumblrHiddenBlog().Load(filename);
                    }

                    if (filename.EndsWith(BlogTypes.tlb.ToString()))
                    {
                        blog = new TumblrLikedByBlog().Load(filename);
                    }

                    if (filename.EndsWith(BlogTypes.tumblrsearch.ToString()))
                    {
                        blog = new TumblrSearchBlog().Load(filename);
                    }

                    if (filename.EndsWith(BlogTypes.tumblrtagsearch.ToString()))
                    {
                        blog = new TumblrTagSearchBlog().Load(filename);
                    }

                    if (filename.EndsWith(BlogTypes.twitter.ToString()))
                    {
                        blog = new TwitterBlog().Load(filename);
                    }

                    if (blog != null)
                    {
                        if (!validCollectionIds.Contains(blog.CollectionId))
                        {
                            blog.CollectionId = 0;
                        }

                        blogs.Add(blog);
                    }
                }
                catch (SerializationException ex)
                {
                    failedToLoadBlogs.Add(ex.Data["Filename"].ToString());
                }
            }

            if (failedToLoadBlogs.Any())
            {
                string failedBlogNames = failedToLoadBlogs.Aggregate((a, b) => a + ", " + b);
                Logger.Verbose("ManagerController:GetIBlogsCore: {0}", failedBlogNames);
                _shellService.ShowError(new SerializationException(), Resources.CouldNotLoadLibrary, failedBlogNames);
            }

            Logger.Verbose("ManagerController.GetIBlogsCore End");

            return(blogs);
        }