Esempio n. 1
0
        public BlogServer(BlogServerOptions options)
        {
            if (options == null)
            {
                throw new System.ArgumentNullException("options");
            }
            this.Options = options;

            CreateFolderSafe(this.Options.OutputFolder);

            // Initialize the log
            string logfilename = GetLogFilename();
            Console.WriteLine("Log at: {0}", logfilename);
            if (this.Options.OverwriteLog)
            {
                LogStream = System.IO.File.CreateText(logfilename);                
            }
            else
            {
                LogStream = System.IO.File.AppendText(logfilename);                
            }
            LogStream.AutoFlush = true;

            this.WriteLog("----------------------------------------");
            this.WriteLog("Start New Server Session ");
            this.WriteLog("----------------------------------------");

            this.HostName = Environment.MachineName.ToLower();
            // The Primary url is what will normally be used
            // However the server supports using localhost as well
            this.ServerUrlPrimary = string.Format("http://{0}:{1}/", HostName, this.Options.Port);
            this.ServerUrlSecondary = string.Format("http://{0}:{1}/", "localhost", this.Options.Port);

            this.WriteLog("Primary Url: {0}", this.ServerUrlPrimary);
            this.WriteLog("Secondary Url: {0}", this.ServerUrlSecondary);
            // The title of the blog will be based on the class name
            this.BlogTitle = "Untitled Blog";

            // This server will contain a single user

            var adminuser = new BlogUser
            {
                Name = "admin",
                Password = "******"
            };

            // Setup Collections
            this.BlogList = new List<UserBlogInfo>();
            this.BlogUsers = new List<BlogUser>();
            this.PostList = new PostList();
            this.MediaObjectList = new MediaObjectList();
            this.CategoryList = new CategoryList();

            this.BlogUsers.Add(adminuser);
            
            // This server will contain a single blog
            this.BlogList.Add(new UserBlogInfo(adminuser.Name, this.ServerUrlPrimary, this.BlogTitle));

            // Add Placeholder Content
            if (this.Options.CreateSampleContent && this.PostList.Count < 1)
            {

                if (this.CategoryList.Count < 1)
                {
                    this.CategoryList.Add("0", "sports");
                    this.CategoryList.Add("0", "biology");
                    this.CategoryList.Add("0", "office supplies");
                    this.CategoryList.Add("0", "food");
                    this.CategoryList.Add("0", "tech");                    
                }

                var cats1 = new[] {"sports","biology", "office supplies"};
                var cats2 = new[] {"food"};
                var cats3 = new[] {"food" };
                var cats4 = new[] {"biology"};

                string lipsum =
                    "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.";

                this.PostList.Add(new System.DateTime(2012, 12, 2), "1000 Amazing Uses for Staples", lipsum, cats1, true);
                this.PostList.Add(new System.DateTime(2012, 1, 15), "Why Pizza is Great", lipsum, cats2, true);
                this.PostList.Add(new System.DateTime(2013, 4, 10), "Sandwiches I have loved", lipsum, cats3, true);
                this.PostList.Add(new System.DateTime(2013, 3, 31), "Useful Things You Can Do With a Giraffe", lipsum, cats4, true);
            }

            this.HttpListener = new System.Net.HttpListener();


        }
Esempio n. 2
0
        public BlogServer(BlogServerOptions options)
        {
            if (options == null)
            {
                throw new System.ArgumentNullException("options");
            }
            this.Options = options;

            CreateFolderSafe(this.Options.OutputFolder);

            // Initialize the log
            string logfilename = GetLogFilename();

            Console.WriteLine("Log at: {0}", logfilename);
            if (this.Options.OverwriteLog)
            {
                LogStream = System.IO.File.CreateText(logfilename);
            }
            else
            {
                LogStream = System.IO.File.AppendText(logfilename);
            }
            LogStream.AutoFlush = true;

            this.WriteLog("----------------------------------------");
            this.WriteLog("Start New Server Session ");
            this.WriteLog("----------------------------------------");

            this.HostName = Environment.MachineName.ToLower();
            // The Primary url is what will normally be used
            // However the server supports using localhost as well
            this.ServerUrlPrimary   = string.Format("http://{0}:{1}/", HostName, this.Options.Port);
            this.ServerUrlSecondary = string.Format("http://{0}:{1}/", "localhost", this.Options.Port);

            this.WriteLog("Primary Url: {0}", this.ServerUrlPrimary);
            this.WriteLog("Secondary Url: {0}", this.ServerUrlSecondary);
            // The title of the blog will be based on the class name
            this.BlogTitle = "Untitled Blog";

            // This server will contain a single user

            var adminuser = new BlogUser
            {
                Name     = "admin",
                Password = "******"
            };

            // Setup Collections
            this.BlogList        = new List <UserBlogInfo>();
            this.BlogUsers       = new List <BlogUser>();
            this.PostList        = new PostList();
            this.MediaObjectList = new MediaObjectList();
            this.CategoryList    = new CategoryList();

            this.BlogUsers.Add(adminuser);

            // This server will contain a single blog
            this.BlogList.Add(new UserBlogInfo(adminuser.Name, this.ServerUrlPrimary, this.BlogTitle));

            // Add Placeholder Content
            if (this.Options.CreateSampleContent && this.PostList.Count < 1)
            {
                if (this.CategoryList.Count < 1)
                {
                    this.CategoryList.Add("0", "sports");
                    this.CategoryList.Add("0", "biology");
                    this.CategoryList.Add("0", "office supplies");
                    this.CategoryList.Add("0", "food");
                    this.CategoryList.Add("0", "tech");
                }

                var cats1 = new[] { "sports", "biology", "office supplies" };
                var cats2 = new[] { "food" };
                var cats3 = new[] { "food" };
                var cats4 = new[] { "biology" };

                string lipsum =
                    "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.";

                this.PostList.Add(new System.DateTime(2012, 12, 2), "1000 Amazing Uses for Staples", lipsum, cats1, true);
                this.PostList.Add(new System.DateTime(2012, 1, 15), "Why Pizza is Great", lipsum, cats2, true);
                this.PostList.Add(new System.DateTime(2013, 4, 10), "Sandwiches I have loved", lipsum, cats3, true);
                this.PostList.Add(new System.DateTime(2013, 3, 31), "Useful Things You Can Do With a Giraffe", lipsum, cats4, true);
            }

            this.HttpListener = new System.Net.HttpListener();
        }