Manages configuration UI and settings for templates that contain setup scripts
		public void GetAllData_LocalOnly_ReturnLocal()
		{
			var c = new Configurator(_libraryFolder.Path, new NavigationIsolator());
			dynamic j = new DynamicJson();
			j.one = 1;
			c.CollectJsonData(j.ToString());
			Assert.AreEqual(j, DynamicJson.Parse(c.GetAllData()));
		}
Example #2
0
        public BookServer(Book.Factory bookFactory, BookStorage.Factory storageFactory,
						  BookStarter.Factory bookStarterFactory, Configurator.Factory configuratorFactory)
        {
            _bookFactory = bookFactory;
            _storageFactory = storageFactory;
            _bookStarterFactory = bookStarterFactory;
            _configuratorFactory = configuratorFactory;
        }
		public void ShowConfigureDialog()
		{
			var c = new Configurator(_libraryFolder.Path, new NavigationIsolator());

			var stringRep = DynamicJson.Serialize(new
			{
				library = new { calendar = new { year = "2088" } }
			});
			c.CollectJsonData(stringRep);

			c.ShowConfigurationDialog(Get_NotYetConfigured_CalendardBookStorage().FolderPath);
			Assert.IsTrue(c.GetLibraryData().Contains("year"));
		}
        public void CollectJsonData_HasArrayValue_DataMerged()
        {
            var firstData = "{\"library\":{\"days\":[\"1\",\"2\"]}}";
            var secondData = "{\"library\":{\"days\":[\"one\",\"two\"]}}";

            var first = new Configurator(_libraryFolder.Path);
            first.CollectJsonData(firstData.ToString());
            first.CollectJsonData(secondData.ToString());

            var second = new Configurator(_libraryFolder.Path);
            dynamic j = (DynamicJson)DynamicJson.Parse(second.GetLibraryData());
            Assert.AreEqual("one", j.library.days[0]);
            Assert.AreEqual("two", j.library.days[1]);
        }
Example #5
0
        public Book CreateFromSourceBook(Book sourceBook, string containingDestinationFolder)
        {
            string pathToFolderOfNewBook = null;

            Logger.WriteMinorEvent("Starting CreateFromSourceBook({0})", sourceBook.FolderPath);
            try
            {
                var starter = _bookStarterFactory();
                pathToFolderOfNewBook = starter.CreateBookOnDiskFromTemplate(sourceBook.FolderPath, containingDestinationFolder);
                if (Configurator.IsConfigurable(pathToFolderOfNewBook))
                {
                    var c = new Configurator(containingDestinationFolder);
                    if (DialogResult.Cancel == c.ShowConfigurationDialog(pathToFolderOfNewBook))
                    {
                        return null; // the template had a configuration page and they clicked "cancel"
                    }
                    c.ConfigureBook(BookStorage.FindBookHtmlInFolder(pathToFolderOfNewBook));
                }

                var newBookInfo = new BookInfo(pathToFolderOfNewBook,true); // _bookInfos.Find(b => b.FolderPath == pathToFolderOfNewBook);
                if (newBookInfo is ErrorBookInfo)
                {
                    throw ((ErrorBookInfo)newBookInfo).Exception;
                }

                Book newBook = GetBookFromBookInfo(newBookInfo);

                //Hack: this is a bit of a hack, to handle problems where we make the book with the suggested initial name, but the title is still something else
                var name = Path.GetFileName(newBookInfo.FolderPath); // this way, we get "my book 1", "my book 2", etc.
                newBook.SetTitle(name);

                Logger.WriteMinorEvent("Finished CreateFromnewBook({0})", newBook.FolderPath);
                Logger.WriteEvent("CreateFromSourceBook({0})", newBook.FolderPath);
                return newBook;
            }
            catch (Exception)
            {
                Logger.WriteEvent("Cleaning up after error CreateFromSourceBook({0})", pathToFolderOfNewBook);
                //clean up this ill-fated book folder up
                if (!string.IsNullOrEmpty(pathToFolderOfNewBook) && Directory.Exists(pathToFolderOfNewBook))
                    Directory.Delete(pathToFolderOfNewBook, true);
                throw;
            }
        }
        public void CollectJsonData_NewTopLevelData_DataMerged()
        {
            var firstData = DynamicJson.Serialize(new
            {
                library = new { one = "1", color="red" }
            });
            var secondData = DynamicJson.Serialize(new
            {
                library = new { two = "2", color = "blue" }
            });

            var first = new Configurator(_libraryFolder.Path);
            first.CollectJsonData(firstData.ToString());
            first.CollectJsonData(secondData.ToString());

            var second = new Configurator(_libraryFolder.Path);
            dynamic j= (DynamicJson) DynamicJson.Parse(second.GetLibraryData());
            Assert.AreEqual("2", j.library.two);
            Assert.AreEqual("1", j.library.one);
            Assert.AreEqual("blue", j.library.color);
        }
        public void CollectJsonData_NewArrayItems_DataMerged()
        {
            var firstData = DynamicJson.Serialize(new
                                                    {
                                                        library = new {food = new {veg="v", fruit = "f"}}
                                                    });
            var secondData = DynamicJson.Serialize(new
            {
                library = new { food = new { bread = "b", fruit = "f" } }
            });

            var first = new Configurator(_libraryFolder.Path);
            first.CollectJsonData(firstData.ToString());
            first.CollectJsonData(secondData.ToString());

            var second = new Configurator(_libraryFolder.Path);
            dynamic j = (DynamicJson)DynamicJson.Parse(second.GetLibraryData());
            Assert.AreEqual("v", j.library.food.veg);
            Assert.AreEqual("f", j.library.food.fruit);
            Assert.AreEqual("b", j.library.food.bread);
        }
 public void WhenCollectedNoLocalDataThenLocalDataIsEmpty()
 {
     var first = new Configurator(_libraryFolder.Path);
     dynamic j = new DynamicJson();
     j.library = new DynamicJson();
     j.library.librarystuff = "foo";
     first.CollectJsonData(j.ToString());
     AssertEmpty(first.LocalData);
 }
 public void WhenCollectedNoGlobalDataThenGlobalDataIsEmpty()
 {
     var first = new Configurator(_libraryFolder.Path);
     dynamic j = new DynamicJson();
     j.one = 1;
     first.CollectJsonData(j.ToString());
     Assert.AreEqual(j, DynamicJson.Parse(first.LocalData));
 }
Example #10
0
 public void LocalData_NothingCollected_Empty()
 {
     var first = new Configurator(_libraryFolder.Path);
     Assert.AreEqual("", first.LocalData);
 }
Example #11
0
        public void LibrarySettingsAreRoundTriped()
        {
            var first = new Configurator(_libraryFolder.Path);
            var stringRep = DynamicJson.Serialize(new
                        {
                            library = new {stuff = "foo"}
                        });

            first.CollectJsonData(stringRep.ToString());

            var second = new Configurator(_libraryFolder.Path);
            dynamic j = (DynamicJson)DynamicJson.Parse(second.GetLibraryData());
            Assert.AreEqual("foo", j.library.stuff);
        }
Example #12
0
 public void GetLibraryData_NothingCollected_Empty()
 {
     var first = new Configurator(_libraryFolder.Path);
     Assert.AreEqual("{}", first.GetLibraryData());
 }
Example #13
0
 public void GetLibraryData_NoGlobalData_Empty()
 {
     var first = new Configurator(_libraryFolder.Path);
     dynamic j = new DynamicJson();
     j.one = 1;
     first.CollectJsonData(j.ToString());
     Assert.AreEqual("{}", first.GetLibraryData());
 }
		public void WhenCollectedNoLocalDataThenLocalDataIsEmpty()
		{
			var first = new Configurator(_libraryFolder.Path, new NavigationIsolator());
			var stringRep = DynamicJson.Serialize(new
				{
					library = new {librarystuff = "foo"}
				});

			first.CollectJsonData(stringRep.ToString());
			AssertEmpty(first.LocalData);
		}