/// <summary>
        ///     Executes command 'path' appropriate to data stored in commandInfo
        /// </summary>
        /// <param name="commandInfo"></param>
        /// <returns></returns>
        public override bool Execute(CommandInfo commandInfo)
        {
            bool userExists =
                commandInfo.Email != null;

            if (!userExists)
            {
                IoService.Out.WriteLine(Resources.ErrorUnknownUserEmail);

                return false;
            }

            Response<List<UserModel>> response = shortestUserPathService.GetShortestPath(Session.LoggedUser.Id, commandInfo.Email);
            if (response.IsSuccessful)
            {
                foreach (var user in response.ResultTask.Result)
                {
                    IoService.Out.WriteLine(user.ToString());
                }
            }
            else
            {
                IoService.Out.WriteLine(Resources.ErrorWhileDataTransfering);
            }

            return true;
        }
        /// <summary>
        ///     Executes 'export' command. Writes appropriate data to file specified in commandInfo
        /// </summary>
        /// <param name="commandInfo"></param>
        /// <returns></returns>
        public override bool Execute(CommandInfo commandInfo)
        {
            bool appendWrite = commandInfo.User
                               && commandInfo.Message;
            if (commandInfo.User)
            {
                ExportUsers(commandInfo.FileName, appendWrite);
            }

            if (commandInfo.Message)
            {
                ExportMessages(commandInfo.FileName, appendWrite);
            }

            IoService.Out.WriteLine(
                Resources.InfoDataExportedToCVS,
                commandInfo.FileName,
                AppDomain.CurrentDomain.BaseDirectory);
            Logger.Info(
                string.Format(
                    Resources.InfoDataExportedToCVS,
                    commandInfo.FileName,
                    AppDomain.CurrentDomain.BaseDirectory));

            return true;
        }
        /// <summary>
        ///     Executes 'find' command appropriate to data stored in commandInfo
        /// </summary>
        /// <param name="commandInfo"></param>
        /// <returns></returns>
        public override bool Execute(CommandInfo commandInfo)
        {
            if (commandInfo.User && commandInfo.Email != null)
            {
                Response<UserModel> response = userSearchService.GetByEmail(commandInfo.Email);

                UserModel user = null;
                if (response.IsSuccessful)
                {
                    user = response.ResultTask.Result;
                }

                IoService.Out.WriteLine(
                    user?.ToString()
                    ?? Resources.ErrorUnknownUserEmail);
            }

            if (!commandInfo.Message)
            {
                return true;
            }

            // TODO Searching of messages
            return true;
        }
        /// <summary>
        ///     Executes command 'send' appropriately to data stored in commandInfo
        /// </summary>
        /// <param name="commandInfo"></param>
        /// <returns></returns>
        public override bool Execute(CommandInfo commandInfo)
        {
            // TODO validation: Does user with this email exists?
            SendMessage(commandInfo.Email);

            return true;
        }
        /// <summary>
        ///     Prints all mutual friends between logged in user and user specified by email,
        ///     if commandInfo containes option mutual = true and email is valid.
        ///     Elsewhere it prints all friends of current user
        /// </summary>
        /// <param name="commandInfo"></param>
        /// <returns></returns>
        public override bool Execute(CommandInfo commandInfo)
        {
            Response<List<UserModel>> response = null;

            bool isEmail = !string.IsNullOrEmpty(commandInfo.Email);
            if (commandInfo.Mutual && isEmail)
            {
                response = friendsService.GetMutualFriends(
                    Session.LoggedUser.Id,
                    commandInfo.Email);
                if (response.IsSuccessful)
                {
                    PrintFriends(response.ResultTask.Result);
                }

                return true;
            }

            if (!(commandInfo.Mutual ^ !isEmail))
            {
                IoService.Out.WriteLine(Resources.ErrorWrongParams);

                return false;
            }

            response = friendsService.GetFriends(Session.LoggedUser.Id);
            if (response.IsSuccessful)
            {
                PrintFriends(response.ResultTask.Result);
            }

            return true;
        }
        /// <summary>
        ///     Parses recieved command line and returns appropriately filled CommandInfo object
        /// </summary>
        /// <param name="commandLine"></param>
        /// <returns></returns>
        public CommandInfo GetCommandInfo(string commandLine)
        {
            var tokens = commandLine.Split(
                new[] { ' ' },
                StringSplitOptions.RemoveEmptyEntries);

            commandInfo = new CommandInfo { CommandName = string.Empty };
            helpIndicator = false;
            try
            {
                OptionSet.Parse(tokens);
            }
            catch (OptionException e)
            {
                printer.Out.WriteLine(e.Message);
                printer.Out.WriteLine(Resources.ParserHelpOffer);

                return null;
            }

            if (!helpIndicator)
            {
                return commandInfo;
            }

            ShowHelp(OptionSet);

            return null;
        }
        /// <summary>
        ///     Executes 'exit' command
        /// </summary>
        /// <param name="commandInfo"></param>
        /// <returns></returns>
        public override bool Execute(CommandInfo commandInfo)
        {
            Logger.Info($"User {Session.LoggedUser.Email} exited");

            var authenService = NinjectKernel.Get<AuthenticationService>();
            authenService.LogOut(SessionKey);

            Exited?.Invoke(this, new EventArgs());

            return true;
        }
        /// <summary>
        ///     Printes all commands that are available for user
        /// </summary>
        /// <param name="commandInfo"></param>
        /// <returns></returns>
        public override bool Execute(CommandInfo commandInfo)
        {
            if (Session.IsLogged)
            {
                PrintLoggedInCommands();
            }
            else
            {
                PrintNotLoggedCommands();
            }

            return true;
        }
        /// <summary>
        ///     Requests data about user and registers it into socialnetwork
        /// </summary>
        /// <param name="commandInfo"></param>
        /// <returns></returns>
        public override bool Execute(CommandInfo commandInfo)
        {
            SignUp();

            return true;
        }
 private void InitializeOptionSet()
 {
     commandInfo = new CommandInfo { CommandName = string.Empty };
     OptionSet = new OptionSet
     {
         {
             "<>|c", Resources.ParserOptionCommandInfo,
             AppendToCommandName
         },
         {
             "u|user", Resources.ParserOptionUser,
             v =>
             {
                 if (v != null)
                 {
                     commandInfo.User = true;
                 }
             }
         },
         {
             "m|message", Resources.ParserOptionMessage,
             v =>
             {
                 if (v != null)
                 {
                     commandInfo.Message = true;
                 }
             }
         },
         {
             "e|email:", Resources.ParserOptionEmail,
             v =>
             {
                 if (v != null)
                 {
                      ValidateEmail(v);
                 }
             }
         },
         {
             "f|file=", Resources.ParserOptionFileName,
             v =>
             {
                 if (v != null)
                 {
                     commandInfo.FileName = v;
                 }
             }
         },
         {
             "r|received", Resources.ParserOptionRecieved,
             v =>
             {
                 if (v != null)
                 {
                     commandInfo.Received = true;
                 }
             }
         },
         {
             "s|sended", Resources.ParserOptionSended,
             v =>
             {
                 if (v != null)
                 {
                     commandInfo.Sended = true;
                 }
             }
         },
         {
             "mutual", Resources.ParserOptionMutual,
             v =>
             {
                 if (v != null)
                 {
                     commandInfo.Mutual = true;
                 }
             }
         },
         {
             "?|h|help", Resources.ParserOptionHelp,
             v => helpIndicator = v != null
         }
     };
 }