示例#1
0
        /// <summary>
        ///     Factory method that creates and returns the <see cref="LeanKitIntegration" /> implementation using the
        ///     LeanKitClient created with the default <see cref="IRestCommandProcessor" />.
        /// </summary>
        /// <remarks>
        ///     The default implementation of the <see cref="IRestCommandProcessor" /> uses RestSharp.
        /// </remarks>
        /// <param name="boardId">The Identity of the Board that will be watched and modified.</param>
        /// <param name="accountAuth">The account authentication information used to connect to the LeanKit API.</param>
        /// <returns>The <see cref="ILeanKitIntegration" /> used to monitor and modify the specified board. </returns>
        public ILeanKitIntegration Create(long boardId, LeanKitAccountAuth accountAuth)
        {
            var clientFactory = new LeanKitClientFactory();
            var apiClient     = clientFactory.Create(accountAuth);

            return(new LeanKitIntegration(boardId, apiClient));
        }
		public bool Initialize(string accountName, string emailAddress, string password)
		{
			try
			{
				var lkFactory = new LeanKitClientFactory();
				var lkAuth = new LeanKitBasicAuth
				{
					Hostname = accountName,
					Username = emailAddress,
					Password = password
				};
				_api = lkFactory.Create(lkAuth);
				// Test authentication
				var boards = _api.GetBoards();
				if (boards == null) return false;
				_cache.Set("boards", boards.ToArray(), DateTimeOffset.Now.AddMinutes(5));
				return true;
			}
			catch (Exception)
			{
				_api = null;
				return false;
			}
		}
		public void RunQuery()
		{
			ValidateQuery();

			var leanKitAuth = new LeanKitBasicAuth
			{
				Hostname = _args.Host,
				Username = _args.User,
				Password = _args.Password
			};

			// For internal development testing
			if (_args.Host.Equals("kanban-cibuild", StringComparison.InvariantCultureIgnoreCase)) 
				leanKitAuth.UrlTemplateOverride = "http://{0}.localkanban.com";

			WriteInfo("Connecting to LeanKit account...");
			var api = new LeanKitClientFactory().Create(leanKitAuth);

			if (_args.Boards)
			{
				WriteInfo("Getting all boards...");
				var boards = api.GetBoards();
				var boardList = boards.Select(Mapper.Map<BoardLiteView>);
				var output = _args.Csv ? boardList.ToCsv() : _args.Json ? boardList.ToJson() : boardList.Dump();
				Console.WriteLine(output);
			}
			else if (_args.Board > 0)
			{
				WriteInfo(string.Format("Getting board [{0}]...", _args.Board));
				var board = api.GetBoard(_args.Board);
				if (_args.Lanes || _args.Lane > 0 || _args.Cards)
				{
					// Get lanes
					var boardLanes = new List<Lane>();
					if (_args.Lane > 0)
					{
						WriteInfo(string.Format("Getting lane [{0}]...", _args.Lane));
						boardLanes.AddRange(board.AllLanes().Where(lane => lane.Id == _args.Lane));
					}
					else
					{
						if (_args.IncludeBacklog) boardLanes.AddRange(board.Backlog);
						boardLanes.AddRange(board.Lanes);
						if (_args.IncludeArchive) boardLanes.AddRange(board.Archive);
					}

					if (_args.Cards)
					{
						WriteInfo("Getting cards...");
						var cards = new List<MappedCardView>();
						foreach (var lane in boardLanes)
						{
							cards.AddRange(lane.Cards.Select(Mapper.Map<MappedCardView>));
						}
						// Archived cards is a separate API call
						if (_args.IncludeArchive)
						{
							var archivedCards = api.GetArchiveCards(_args.Board);
							cards.AddRange(archivedCards.Select(Mapper.Map<MappedCardView>));
						}
						var output = _args.Csv ? cards.ToCsv() : _args.Json ? cards.ToJson() : cards.Dump();
						Console.WriteLine(output);
					}
					else
					{
						var lanes = boardLanes.Select(Mapper.Map<LaneView>);
						var output = _args.Csv ? lanes.ToCsv() : _args.Json ? lanes.ToJson() : lanes.Dump();
						Console.WriteLine(output);
					}
				}
				else
				{
					var boardView = Mapper.Map<BoardView>(board);
					var output = _args.Csv ? boardView.ToCsv() : _args.Json ? boardView.ToJson() : boardView.Dump();
					Console.WriteLine(output);
				}
			}
		}
		/// <summary>
		///     Factory method that creates and returns the <see cref="LeanKitIntegration" /> implementation using the
		///     LeanKitClient created with the default <see cref="IRestCommandProcessor" />.
		/// </summary>
		/// <remarks>
		///     The default implementation of the <see cref="IRestCommandProcessor" /> uses RestSharp.
		/// </remarks>
		/// <param name="boardId">The Identity of the Board that will be watched and modified.</param>
		/// <param name="accountAuth">The account authentication information used to connect to the LeanKit API.</param>
		/// <returns>The <see cref="ILeanKitIntegration" /> used to monitor and modify the specified board. </returns>
		public ILeanKitIntegration Create(long boardId, LeanKitAccountAuth accountAuth)
		{
			var clientFactory = new LeanKitClientFactory();
			var apiClient = clientFactory.Create(accountAuth);
			return new LeanKitIntegration(boardId, apiClient);
		}