/// <summary>
		/// Creates an <see cref="ICommand"/> according to the specified <see cref="CommandName"/>.
		/// </summary>
		/// <param name="commandName">One of the values of <see cref="CommandName"/>.</param>
		/// <param name="communicationProxy">The communication proxy as an instance of <see cref="IDokuWikiProvider"/>.</param>
		/// <param name="wikiClient">The "local" wiki client which has access to the persited data.</param>
		/// <returns>
		/// The created instance to the given named command.
		/// </returns>
		/// <exception cref="ArgumentNullException">Is thrown when <paramref name="communicationProxy"/> is a <see langword="null"/> reference.</exception>
		/// <exception cref="ArgumentNullException"> Is thrown when
		///		<para><paramref name="communicationProxy"/> is a <see langword="null"/> reference</para>
		///		<para>- or -</para>
		///		<para><paramref name="wikiClient"/> is a <see langword="null"/> reference.</para>
		/// </exception>
		/// <exception cref="ArgumentException">Is thrown when <paramref name="commandName"/> is not defined in <see cref="CommandName"/>.</exception>
		public static ICommand CreateCommand(CommandName commandName, IDokuWikiProvider communicationProxy, IDokuWikiClient wikiClient)
		{
			if (communicationProxy == null)
			{
				throw new ArgumentNullException("communicationProxy");
			}

			if (wikiClient == null)
			{
				throw new ArgumentNullException("wikiClient");
			}

			if (!Enum.IsDefined(typeof(CommandName), commandName))
			{
				throw new ArgumentException("Unkown command name", "commandName");
			}

			switch (commandName)
			{
				case CommandName.GetWikiPage:
					return new GetWikiPageCommand(communicationProxy);
				case CommandName.GetAllPages:
					return new GetAllPageItemsCommand(communicationProxy);
				case CommandName.GetWikiPageAsHtml:
					return new GetWikiPageAsHtmlCommand(communicationProxy);
				case CommandName.LoadMethodHelp:
					return new LoadMethodHelpCommand(communicationProxy);
				case CommandName.LoadMethodSignatures:
					return new LoadMethodSignaturesCommand(communicationProxy);
				case CommandName.ListStoredWikiAccounts:
					return new ListStoredWikiAccountsCommand(wikiClient, communicationProxy);
				case CommandName.ListServerMethods:
					return new ListServerMethodsCommand(communicationProxy);
				case CommandName.ExitApplication:
				default:
					throw new NotImplementedException("No command available for this command name.");
			}
		}
Пример #2
0
        /// <summary>
        /// Creates an <see cref="ICommand"/> according to the specified <see cref="CommandName"/>.
        /// </summary>
        /// <param name="commandName">One of the values of <see cref="CommandName"/>.</param>
        /// <param name="communicationProxy">The communication proxy as an instance of <see cref="IDokuWikiProvider"/>.</param>
        /// <param name="wikiClient">The "local" wiki client which has access to the persited data.</param>
        /// <returns>
        /// The created instance to the given named command.
        /// </returns>
        /// <exception cref="ArgumentNullException">Is thrown when <paramref name="communicationProxy"/> is a <see langword="null"/> reference.</exception>
        /// <exception cref="ArgumentNullException"> Is thrown when
        ///		<para><paramref name="communicationProxy"/> is a <see langword="null"/> reference</para>
        ///		<para>- or -</para>
        ///		<para><paramref name="wikiClient"/> is a <see langword="null"/> reference.</para>
        /// </exception>
        /// <exception cref="ArgumentException">Is thrown when <paramref name="commandName"/> is not defined in <see cref="CommandName"/>.</exception>
        public static ICommand CreateCommand(CommandName commandName, IDokuWikiProvider communicationProxy, IDokuWikiClient wikiClient)
        {
            if (communicationProxy == null)
            {
                throw new ArgumentNullException("communicationProxy");
            }

            if (wikiClient == null)
            {
                throw new ArgumentNullException("wikiClient");
            }

            if (!Enum.IsDefined(typeof(CommandName), commandName))
            {
                throw new ArgumentException("Unkown command name", "commandName");
            }

            switch (commandName)
            {
            case CommandName.GetWikiPage:
                return(new GetWikiPageCommand(communicationProxy));

            case CommandName.GetAllPages:
                return(new GetAllPageItemsCommand(communicationProxy));

            case CommandName.GetWikiPageAsHtml:
                return(new GetWikiPageAsHtmlCommand(communicationProxy));

            case CommandName.LoadMethodHelp:
                return(new LoadMethodHelpCommand(communicationProxy));

            case CommandName.LoadMethodSignatures:
                return(new LoadMethodSignaturesCommand(communicationProxy));

            case CommandName.ListStoredWikiAccounts:
                return(new ListStoredWikiAccountsCommand(wikiClient, communicationProxy));

            case CommandName.ListServerMethods:
                return(new ListServerMethodsCommand(communicationProxy));

            case CommandName.ExitApplication:
            default:
                throw new NotImplementedException("No command available for this command name.");
            }
        }
		/// <summary>
		/// Initializes a new instance of the <see cref="ListStoredWikiAccountsCommand"/> class.
		/// </summary>
		/// <param name="wikiProvider">The wiki provider which gives us access to the remote host.</param>
		public ListStoredWikiAccountsCommand(IDokuWikiClient wikiClient, IDokuWikiProvider wikiProvider)
			: base(wikiProvider)
		{
			this.Name = CommandName.ListStoredWikiAccounts;
			this.wikiClient = wikiClient;
		}
Пример #4
0
        /// <summary>
        /// Mains the specified args.
        /// </summary>
        /// <param name="args">The args.</param>
        public static void Main(string[] args)
        {
            AppDomain.CurrentDomain.UnhandledException += DokuWikiClientConsoleApplication.OnUnhandledException;
            XmlConfigurator.Configure();
            IDokuWikiProvider communicationClient;
            IDokuWikiClient   dokuWikiClient = DokuWikiClientFactory.CreateDokuWikiClient();

            Uri    uriToWiki;
            string password = string.Empty;
            string username = string.Empty;

            Console.WriteLine("Connecting to wiki.");
            if (args.Length > 0 && !String.IsNullOrEmpty(args[0]))
            {
                UriBuilder uriConstructor = new UriBuilder(args[0]);

                if (!uriConstructor.Uri.IsWellFormedOriginalString())
                {
                    if (uriConstructor.Scheme != "http" || uriConstructor.Scheme != "https")
                    {
                        uriConstructor.Scheme = "http";
                    }
                    uriConstructor.Host = args[0];
                }

                if (uriConstructor.Path == "/")
                {
                    uriConstructor.Path = "/lib/exe/xmlrpc.php";
                }

                uriToWiki = uriConstructor.Uri;

                if (args.Length == 3 && !String.IsNullOrEmpty(args[1]) && !String.IsNullOrEmpty(args[2]))
                {
                    password            = args[2];
                    username            = args[1];
                    communicationClient = XmlRpcProxyFactory.CreateSecureCommunicationProxy(uriToWiki, username, password);
                }
                else
                {
                    communicationClient = XmlRpcProxyFactory.CreateCommunicationProxy(uriToWiki);
                }
            }
            else
            {
                Console.WriteLine("Usage: DokuWikiClientConsoleApplication <URI of wiki> [username] [password]");
                Console.ReadLine();
                return;
            }

            try
            {
                Console.WriteLine("----------------------------------------------------");
                Console.WriteLine("Listing server capabilites.");

                Capability serverCapability = communicationClient.LoadServerCapabilites();
                if (serverCapability.XmlRpcSpecification != null)
                {
                    Console.WriteLine("Xml-Rpc Version: {0}", serverCapability.XmlRpcSpecification.SpecificationVersion);
                }
                if (serverCapability.IntrospectionSpecification != null)
                {
                    Console.WriteLine("Introspection Version: {0}", serverCapability.IntrospectionSpecification.SpecificationVersion);
                }
                if (serverCapability.MultiCallSpecification != null)
                {
                    Console.WriteLine("Multicall Version: {0}", serverCapability.MultiCallSpecification.SpecificationVersion);
                }
                if (serverCapability.FaultCodesSpecification != null)
                {
                    Console.WriteLine("Fault codes Version: {0}", serverCapability.FaultCodesSpecification.SpecificationVersion);
                }

                Console.WriteLine("----------------------------------------------------");

                Console.WriteLine("Listing server methods.");
                foreach (String serverMethodName in communicationClient.ListServerMethods())
                {
                    Console.WriteLine("Method name: {0}", serverMethodName);
                }
            }
            catch (ArgumentException ae)
            {
                Console.WriteLine(ae.Message);
                Console.WriteLine("Proceeding ....");
            }
            catch (CommunicationException ce)
            {
                Console.WriteLine("Communication error. Cause: {0}", ce.Message);
            }

            Console.WriteLine("----------------------------------------------------");

            StringBuilder menuString = new StringBuilder();

            menuString.AppendLine("Menu: ");

            foreach (CommandName enumValue in Enum.GetValues(typeof(CommandName)))
            {
                menuString.AppendLine(((int)enumValue) + " := " + enumValue.DescriptionOf());
            }
            menuString.AppendLine();

            do
            {
                Console.Write(menuString.ToString());
                string      input        = Console.ReadLine();
                CommandName commandValue = (CommandName)Enum.Parse(typeof(CommandName), input);

                if (commandValue == CommandName.ExitApplication)
                {
                    exitLoop = true;
                }
                else
                {
                    try
                    {
                        CommandFactory.CreateCommand(commandValue, communicationClient, dokuWikiClient).Execute();
                    }
                    catch (NotImplementedException nie)
                    {
                        Console.WriteLine(nie.Message);
                    }
                }

                Console.WriteLine("----------------------------------------------------");
            }while (!exitLoop);
        }
Пример #5
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ListStoredWikiAccountsCommand"/> class.
 /// </summary>
 /// <param name="wikiProvider">The wiki provider which gives us access to the remote host.</param>
 public ListStoredWikiAccountsCommand(IDokuWikiClient wikiClient, IDokuWikiProvider wikiProvider)
     : base(wikiProvider)
 {
     this.Name       = CommandName.ListStoredWikiAccounts;
     this.wikiClient = wikiClient;
 }