Пример #1
0
        private void ExecuteLoggedIn(Action <ConfluenceSoapServiceService, string> code)
        {
            ConfluenceSoapServiceService confluence = null;
            var token = string.Empty;

            try
            {
                confluence = new ConfluenceSoapServiceService
                {
                    Url = this.Url
                };
                token = confluence.login(this.UserName, this.Password);

                code(confluence, token);
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }
            finally
            {
                if (confluence != null)
                {
                    confluence.logout(token);
                }
            }
        }
Пример #2
0
 /// <summary>
 /// Internal login which catches the exceptions
 /// </summary>
 /// <returns>true if login was done sucessfully</returns>
 private bool doLogin(string user, string password)
 {
     try {
         this.credentials  = confluence.login(user, password);
         this.loggedInTime = DateTime.Now;
         this.loggedIn     = true;
     } catch (Exception e) {
         // Check if confluence-v2 caused an error, use v1 instead
         if (e.Message.Contains(V2_FAILED) && url.Contains("v2"))
         {
             init(url.Replace("v2", "v1"));
             return(doLogin(user, password));
         }
         // check if auth failed
         if (e.Message.Contains(AUTH_FAILED_EXCEPTION_NAME))
         {
             return(false);
         }
         // Not an authentication issue
         this.loggedIn    = false;
         this.credentials = null;
         e.Data.Add("user", user);
         e.Data.Add("url", url);
         throw;
     }
     return(true);
 }
Пример #3
0
        /// <summary>
        /// Actual code performed when action is executed in Do
        /// </summary>
        /// <param name="items">
        /// Items. ITextItem <see cref="IItem"/>
        /// </param>
        /// <param name="modItems">
        /// Modifier Items. None <see cref="IItem"/>
        /// </param>
        /// <returns>
        /// Array of Bookmark Items. URLs to search results <see cref="IItem"/>
        /// </returns>
        public override IEnumerable <Item> Perform(IEnumerable <Item> items, IEnumerable <Item> modItems)
        {
            try
            {
                ConfluenceSoapServiceService soapService = new ConfluenceSoapServiceService(_config.BaseUrl);

                // Only login if username AND password were provided in the config.
                // Otherwise, use anonymous access with a null token.
                String token = null;
                if (_config.Username != null && _config.Username.Trim().Length != 0 &&
                    _config.Password != null && _config.Password.Trim().Length != 0)
                {
                    token = soapService.login(_config.Username, _config.Password);
                }

                string query = (items.First() as ITextItem).Text;
                RemoteSearchResult[] results = soapService.search(token, query, _config.MaxSearchResults);

                List <Item> retItems = new List <Item> ();
                foreach (RemoteSearchResult result in results)
                {
                    retItems.Add(new BookmarkItem(result.title, result.url));
                }

                return(retItems.ToArray());
            }
            catch (Exception e)
            {
                Log("Unable to search Confluence: {0}", e);
                return(null);
            }
        }
Пример #4
0
        public string RunCommand()
        {
            IBitlyService bitlyService = new BitlyService("vhytyk", "R_5d31d4dc7a364cf6af291c7533655e55");

            string result = null;

            if (!string.IsNullOrEmpty(_searchPhrase))
            {
                var wikiService = new ConfluenceSoapServiceService();
                if (null == wikiToken)
                {
                    wikiToken = wikiService.login("vhytyk", "");
                }

                var resultList = new List <string>();
                var searchList = wikiService.search(wikiToken, _searchPhrase, 20)
                                 .Where(r => r.type == "page")
                                 .Take(3)
                                 .ToList();

                searchList.ForEach(s =>
                {
                    resultList.Add(string.Format("{1} ({0})",
                                                 bitlyService.Shorten(s.url.Replace("wiki/", "wiki.justanswer.local/")), s.title));
                });



                result = string.Join("\r", resultList);
            }

            return(result);
        }
Пример #5
0
 /// <summary>
 /// Internal login which catches the exceptions
 /// </summary>
 /// <returns>true if login was done sucessfully</returns>
 private bool DoLogin(string user, string password)
 {
     try {
         _credentials  = _confluence.login(user, password);
         _loggedInTime = DateTime.Now;
         _loggedIn     = true;
     } catch (Exception e) {
         // Check if confluence-v2 caused an error, use v1 instead
         if (e.Message.Contains(V2Failed) && _url.Contains("v2"))
         {
             Init(_url.Replace("v2", "v1"));
             return(DoLogin(user, password));
         }
         // check if auth failed
         if (e.Message.Contains(AuthFailedExceptionName))
         {
             return(false);
         }
         // Not an authentication issue
         _loggedIn    = false;
         _credentials = null;
         e.Data.Add("user", user);
         e.Data.Add("url", _url);
         throw;
     }
     return(true);
 }
 public string Reconnect()
 {
     _confluenceService     = new ConfluenceSoapServiceService();
     _confluenceService.Url = _confluenceApiUrl;
     _token = _confluenceService.login(_userName, _password);
     return(_token);
 }
Пример #7
0
 public bool Login(string username, string password)
 {
     try
     {
         m_soapAuthToken = m_soapService.login(username, password);
         m_username      = username;
         return(true);
     }
     catch (Exception)
     {
         return(false);
     }
 }
Пример #8
0
        /// <summary>
        /// Smiður sem tekur við Wiki-notandanafni og -lykilorði til þess að auðkenna notanda gagnvart RB Wiki.
        /// </summary>
        /// <param name="user">Wiki-notendanafn. Sé gildi þessa viðfangs null eða tómi strengurinn er Wiki-notendanafn úr stillingaskrá (App.config) notað.</param>
        /// <param name="password">Wiki-lykilorð. Sé gildi þessa viðfangs null eða tómi strengurinn er Wiki-lykilorð úr stillingaskrá (App.config) notað.</param>
        public ConfluenceProxy(string user, string password)
        {
            space = String.IsNullOrWhiteSpace(ConfigurationManager.AppSettings["confluence.space"])?
                    DEFAULT_SPACE:
                    ConfigurationManager.AppSettings["confluence.space"];
            grandparent_page_id = String.IsNullOrWhiteSpace(ConfigurationManager.AppSettings["confluence.grandparentpage"]) ?
                                  DEFAULT_GRANDPARENT_PAGE_ID :
                                  Convert.ToInt64(ConfigurationManager.AppSettings["confluence.grandparentpage"]);

            user     = string.IsNullOrWhiteSpace(user) ? ConfigurationManager.AppSettings["confluence.user"] : user;
            password = string.IsNullOrWhiteSpace(password) ? ConfigurationManager.AppSettings["confluence.password"] : password;

            wiki_access_token = confluence.login(user, password);
        }
        public ConfluenceClient(string user, string password)
        {
            if (String.IsNullOrEmpty(user))
            {
                throw new ArgumentNullException("user");
            }

            if (String.IsNullOrEmpty(password))
            {
                throw new ArgumentNullException("password");
            }

            m_client = new ConfluenceSoapServiceService();
            m_token  = m_client.login(user, password);
        }
Пример #10
0
 public string Login(string username, string password)
 {
     return(_service.login(username, password));
 }
Пример #11
0
        /// <summary>
        /// Actual code performed when action is executed in Do
        /// </summary>
        /// <param name="items">
        /// Items. ITextItem <see cref="IItem"/>
        /// </param>
        /// <param name="modItems">
        /// Modifier Items. None <see cref="IItem"/>
        /// </param>
        /// <returns>
        /// Array of Bookmark Items. URLs to search results <see cref="IItem"/>
        /// </returns>
        public override IEnumerable<Item> Perform(IEnumerable<Item> items, IEnumerable<Item> modItems)
        {
            try
            {
                ConfluenceSoapServiceService soapService = new ConfluenceSoapServiceService(_config.BaseUrl);

                // Only login if username AND password were provided in the config.
                // Otherwise, use anonymous access with a null token.
                String token = null;
                if (_config.Username != null && _config.Username.Trim().Length != 0 &&
                      _config.Password != null && _config.Password.Trim().Length != 0)
                {
                    token = soapService.login(_config.Username, _config.Password);
                }

                string query = (items.First () as ITextItem).Text;
                RemoteSearchResult[] results = soapService.search(token, query, _config.MaxSearchResults);

                List<Item> retItems = new List<Item> ();
                foreach (RemoteSearchResult result in results)
                {
                    retItems.Add(new BookmarkItem(result.title, result.url));
                }

                return retItems.ToArray();
            }
            catch( Exception e )
            {
                Log( "Unable to search Confluence: {0}", e );
                return null;
            }
        }