/// <summary>
		/// Initializes a new instance of the <see cref="DokuWikiClient"/> class.
		/// </summary>
		/// <param name="account">The account to use for the communication etc.</param>
		/// <exception cref="ArgumentNullException"> Is thrown when
		///		<para><paramref name="account"/> is a <see langword="null"/> reference</para>
		///		<para>- or -</para>
		///		<para><see cref="WikiAccount.WikiUrlRaw"/> is a <see langword="null"/> reference.</para>
		/// </exception>
		internal void InitializeDokuWikiClient(WikiAccount account)
		{
			if (account == null || account.WikiUrlRaw == null)
			{
				throw new ArgumentNullException("account");
			}

			client = new XmlRpcClient(account.WikiUrl);
			this.ConnectToWiki();
		}
		public void Constructor_CreationWithValidInput_CreationIsDoneWithoutErrors()
		{
			WikiAccount account = new WikiAccount();
			account.AccountName = "Test Account";
			Wikipage pageToTest = new Wikipage(account);

			Assert.IsNotNull(pageToTest);
			Assert.IsTrue(pageToTest.IsAssociatedWithAnAccount());
			Assert.AreEqual(pageToTest.GetAssociatedAccountName(), account.AccountName);
		}
Example #3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Wikipage"/> class.
        /// </summary>
        /// <param name="account">The account this page is associated with.</param>
        /// <exception cref="ArgumentNullException">Is thrown when <paramref name="account"/> is a <see langword="null"/> reference.</exception>
        public Wikipage(WikiAccount account)
            : base()
        {
            if (account == null)
            {
                throw new ArgumentNullException("account");
            }

            this.accountName = account.AccountName;
        }
		/// <summary>
		/// Initializes a new instance of the <see cref="Wikipage"/> class.
		/// </summary>
		/// <param name="account">The account this page is associated with.</param>
		/// <exception cref="ArgumentNullException">Is thrown when <paramref name="account"/> is a <see langword="null"/> reference.</exception>
		public Wikipage(WikiAccount account)
			: base()
		{
			if (account == null)
			{
				throw new ArgumentNullException("account");
			}

			this.accountName = account.AccountName;
		}
		/// <summary>
		/// Creates the doku wiki client.
		/// </summary>
		/// <param name="account">The account to use for communication.</param>
		/// <returns>An initialized instance of <see cref="IDokuWikiClient"/> associated with the given <see cref="WikiAccount"/>.</returns>
		/// <exception cref="ArgumentNullException">Is thrown when <paramref name="account"/> is a <see langword="null"/> reference.</exception>
		public static IDokuWikiClient CreateDokuWikiClient(WikiAccount account)
		{
			if (account == null)
			{
				throw new ArgumentNullException("account");
			}

			DokuWikiClient client = new DokuWikiClient();
			client.InitializeDokuWikiClient(account);
			return client;
		}
		public void Store_StoreAWikiPage_BusinessObjectShouldBeStoredWithoutErrors()
		{
			WikiAccount account = new WikiAccount();
			Wikipage page = new Wikipage(account);
			page.WikiPageContent = "ölkjölkfsajdölkjafsd";
			page.WikiPageName = "start.php";

			IWikiRepository repository = WikiRepositoryFactory.CreateRepository(WikiRepositoryType.FileRepository);
			string identifier = repository.Store<Wikipage>(page);
			Assert.IsFalse(String.IsNullOrEmpty(identifier));
			Assert.AreEqual(identifier, page.ObjectIdentifier);
		}
		/// <summary>
		/// Initializes a new instance of the <see cref="MainWindow"/> class.
		/// </summary>
		public MainWindow()
		{
			InitializeComponent();
			this.statusProgress.Visibility = Visibility.Hidden;
			this.InitializeBackgroundWorker();
			this.knownWikiAccounts = this.dokuWikiClient.LoadWikiAccounts();
			this.updateActiveAccountsList();
			if (this.activeAccountSelector.SelectedItem != null)
			{
				string selectedAccountName = this.activeAccountSelector.SelectedItem as string;
				this.activeAccount = this.knownWikiAccounts.Find(accountList => accountList.AccountName.Equals(selectedAccountName));
				this.connectToWikiButton_Click(this, new RoutedEventArgs());
			}
			this.activeAccountSelector.SelectionChanged += activeAccountSelector_SelectionChanged;
		}
		public void Store_StoreAWikiObjectUsingItsOwnIdenitfier_ShouldBeDoneWithoutErrors()
		{
			WikiAccount myOwnAccount = new WikiAccount();
			myOwnAccount.LoginName = "jfdsah";
			myOwnAccount.Password = "******";
			myOwnAccount.WikiUrl = new Uri("ftp://ftp.google.com/");

			IWikiRepository repository = WikiRepositoryFactory.CreateRepository(WikiRepositoryType.FileRepository);
			string accountId = "MyOwnAccount";
			repository.Store<WikiAccount>(myOwnAccount, accountId);

			WikiAccount reloadedAccount = repository.Load<WikiAccount>(accountId);
			Assert.IsNotNull(reloadedAccount);
			Assert.AreEqual(myOwnAccount, reloadedAccount);
		}
		public void Store_StoreAModifiedWikiAccount_IdentifierShouldStayTheSame()
		{
			WikiAccount account = new WikiAccount();
			Wikipage pageToStore = new Wikipage(account);
			pageToStore.WikiPageName = "first.php";
			pageToStore.WikiPageContent = "Lorem ipsum dolor sit amet";

			IWikiRepository repository = WikiRepositoryFactory.CreateRepository(WikiRepositoryType.FileRepository);
			string firstIdentifier = repository.Store<Wikipage>(pageToStore);

			pageToStore.WikiPageContent = "Lorem ipsum dolor sit amet, consetetur sadipscing elitr," +
				" sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua.";
			string secondIdentifier = repository.Store<Wikipage>(pageToStore);

			Assert.AreEqual(firstIdentifier, secondIdentifier);
		}
		private void managementMenuNew_Click(object sender, RoutedEventArgs e)
		{
			WikiAccount newAccount = new WikiAccount();
			newAccount.AccountName = "My dokuwiki account somewhere.";
			newAccount.LoginName = "*****@*****.**";
			newAccount.Password = "******";
			newAccount.WikiUrlRaw = "http://www.mywiki.url/lib/exe/xmlrpc.php";

			WikiAccountDataDialog dataInputDialog = new WikiAccountDataDialog(newAccount);
			dataInputDialog.ShowDialog();
			if (String.IsNullOrEmpty(newAccount.Password))
			{
				MessageBox.Show("Account not saved.");
			}
			else
			{
				clientToUse.SaveWikiAccount(newAccount);
				this.wikiAccounts = this.clientToUse.LoadWikiAccounts();
				this.showWikiAccounts();
			}
		}
		/// <summary>
		/// Loads the wiki pages associated with a certain account.
		/// </summary>
		/// <param name="account">The <see cref="WikiAccount"/> the pages are associated with.</param>
		/// <returns>
		/// A List of all found <see cref="Wikipage"/>s in the store.
		/// </returns>
		/// <exception cref="ArgumentNullException">Is thrown when <paramref name="account"/> is a <see langword="null"/> reference.</exception>
		public List<Wikipage> LoadWikiPages(WikiAccount account)
		{
			if (account == null)
			{
				throw new ArgumentNullException("account", "The account cannot be null.");
			}

			List<Wikipage> loadedPages = new List<Wikipage>();

			List<string> identifiers;
			try
			{
				identifiers = (List<string>)repository.GetIdentifiers();
			}
			catch (WikiRepositoryException)
			{
				identifiers = new List<string>();
			}

			foreach (string identifier in identifiers)
			{
				Wikipage loadedPage = repository.Load<Wikipage>(identifier);
				if (loadedPage != null)
				{
					loadedPages.Add(loadedPage);
				}
			}

			return loadedPages;
		}
		public void Load_LoadAWikiAccount_IsLoadedWithoutErrors()
		{
			WikiAccount expectedAccount = new WikiAccount();
			expectedAccount.AccountName = "doodle";
			expectedAccount.LoginName = "Dödel";
			expectedAccount.Password = "******";
			expectedAccount.WikiUrl = new Uri("http://www.doodle.ch/tinyurl/349");

			IWikiRepository repository = WikiRepositoryFactory.CreateRepository(WikiRepositoryType.FileRepository);
			string targetIdenitfier = repository.Store<WikiAccount>(expectedAccount);

			WikiAccount targetAccount = repository.Load<WikiAccount>(targetIdenitfier);
			Assert.AreEqual(targetAccount, expectedAccount);
			Assert.IsTrue(targetAccount.Equals(expectedAccount));
		}
		private void activeAccountSelector_SelectionChanged(object sender, SelectionChangedEventArgs e)
		{
			string selectedAccountName = this.activeAccountSelector.SelectedItem as string;
			this.activeAccount = this.knownWikiAccounts.Find(accountList => accountList.AccountName.Equals(selectedAccountName));
			this.activeAccount.IsActive = true;
			this.dokuWikiClient.SaveWikiAccount(this.activeAccount);
			this.connectToWikiButton_Click(this, new RoutedEventArgs());
		}
		public void GetIdentifiers_StandardProcedure_AListOfStringsIsReturned()
		{
			bool found = false;

			WikiAccount account = new WikiAccount();
			account.AccountName = "foobar";
			account.LoginName = "barfoo";
			account.Password = "******";
			account.WikiUrl = new Uri("http://some.where.over/the/Rainbow");

			IWikiRepository repository = WikiRepositoryFactory.CreateRepository(WikiRepositoryType.FileRepository);
			string targetIdentifier = repository.Store<WikiAccount>(account);

			foreach (string identifier in repository.GetIdentifiers())
			{
				Assert.IsFalse(String.IsNullOrEmpty(identifier));
				if (targetIdentifier == identifier)
				{
					found = true;
					break;
				}
			}

			Assert.IsTrue(found);
		}
		/// <summary>
		/// Saves the wiki account.
		/// </summary>
		/// <param name="accountToSave">The account to save.</param>
		public void SaveWikiAccount(WikiAccount accountToSave)
		{
			repository.Store<WikiAccount>(accountToSave);
		}
		public void Delete_SaveAndThenDeleteAWikiPage_ShouldBeDoneWithoutErrors()
		{
			WikiAccount account = new WikiAccount();
			Wikipage pageToStore = new Wikipage(account);
			pageToStore.WikiPageName = "delete.php";
			pageToStore.WikiPageContent = "Lorem ipsum dolor sit amet, consetetur sadipscing elitr sed diam nonumy eirmod tempor invidunt ut labore et dolore ...";

			IWikiRepository repository = WikiRepositoryFactory.CreateRepository(WikiRepositoryType.FileRepository);
			string pageIdentifier = repository.Store<Wikipage>(pageToStore);
			repository.Delete(pageIdentifier);
		}
		public void Load_LoadAPersistedWikiPage_ShouldBeLoadedWithoutErrors()
		{
			WikiAccount account = new WikiAccount();
			Wikipage pageToStore = new Wikipage(account);
			pageToStore.WikiPageName = "first.php";
			pageToStore.WikiPageContent = "Lorem ipsum dolor sit amet, consetetur sadipscing elitr ...";

			IWikiRepository repository = WikiRepositoryFactory.CreateRepository(WikiRepositoryType.FileRepository);
			string pageIdentifier = repository.Store<Wikipage>(pageToStore);
			repository = null;
			repository = WikiRepositoryFactory.CreateRepository(WikiRepositoryType.FileRepository);

			Wikipage loadedPage = repository.Load<Wikipage>(pageIdentifier);
			Assert.AreEqual(pageToStore, loadedPage);
		}
		public void Load_LoadAManualPersistedWikiObject_IsLoadedAndAddedInRepository()
		{
			WikiAccount manualStoredAccount = new WikiAccount();
			manualStoredAccount.AccountName = "doodleidu";
			manualStoredAccount.LoginName = "Dödeldidu";
			manualStoredAccount.Password = "******";
			manualStoredAccount.WikiUrl = new Uri("http://www.doodle.ch/tinyurl/987436219874");

			IWikiRepository repository = WikiRepositoryFactory.CreateRepository(WikiRepositoryType.FileRepository);
			string targetIdenitfier = manualStoredAccount.Serialize(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + "//DokuWikiStore//", ".wiki");

			WikiAccount loadedAccount = repository.Load<WikiAccount>(targetIdenitfier);
			Assert.IsNotNull(loadedAccount);
			Assert.AreEqual(manualStoredAccount, loadedAccount);

			string addedIdentifier = repository.GetIdentifiers().First(x => x.Equals(targetIdenitfier));
			Assert.AreEqual(addedIdentifier, targetIdenitfier);
		}
		public WikiAccountDataDialog(WikiAccount account)
		{
			this.accountToEdit = account;
			this.DataContext = account;
			InitializeComponent();
		}