private static void Main() { var commandsClient = new CommandsClient(); var ctx = new Context(GetContextDirectory()); Listener(ctx, commandsClient); }
public NetworkCommandArgs(string CommandName, NetworkAccount senderAccount, CommandsClient sender, List <string> args) { this.CommandString = CommandName; this.senderAccount = senderAccount; this.sender = sender; this.Parameters = args; }
private void CommandsConnectionAccepter() { while (true) { try { Socket client = commandslistener.Accept(); CommandsClient newClient = new CommandsClient(client); } catch {} } }
/// <summary> /// Create new instance of DiskHttpApi. Keep one instance for all requests. /// </summary> /// <param name="baseUrl">Base url to Yandex Disk API.</param> /// <param name="oauthKey"> /// OAuth Key for authorization on API /// <see href="https://tech.yandex.ru/disk/api/concepts/quickstart-docpage/"/> /// </param> /// <param name="logSaver">Instance of custom logger.</param> /// <param name="httpClient"></param> public DiskHttpApi([NotNull] string baseUrl, [NotNull] string oauthKey, [CanBeNull] ILogSaver logSaver, [NotNull] IHttpClient httpClient) { BaseUrl = baseUrl; _httpClient = httpClient; var apiContext = new ApiContext { HttpClient = httpClient, BaseUrl = new Uri(baseUrl), LogSaver = logSaver }; Files = new FilesClient(apiContext); MetaInfo = new MetaInfoClient(apiContext); Commands = new CommandsClient(apiContext); }
public DiskHttpApi([NotNull] string oauthKey, [CanBeNull] ILogSaver logSaver = null) { var clientHandler = new HttpClientHandler(); var httpClient = new HttpClient(clientHandler, disposeHandler: true); httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("OAuth", oauthKey); httpClient.DefaultRequestHeaders.UserAgent.Add(new ProductInfoHeaderValue(AboutInfo.Client.ProductTitle, AboutInfo.Client.Version)); httpClient.Timeout = TimeSpan.FromHours(24); //For support large file uploading and downloading _httpClient = new RealHttpClientWrapper(httpClient); var apiContext = new ApiContext { HttpClient = _httpClient, BaseUrl = new Uri(BaseUrl), LogSaver = logSaver }; Files = new FilesClient(apiContext); MetaInfo = new MetaInfoClient(apiContext); Commands = new CommandsClient(apiContext); }
private static void Listener(Context ctx, CommandsClient commandsClient) { ICommand command; do { try { Console.Write(PROMPT_SIGN); var commandLine = new CommandLine(Console.ReadLine()); command = commandsClient.GetCommand(commandLine.Name); command.Run(ctx, commandLine.GetArgs()); } catch (CommandLineException ex) { Console.WriteLine(ex.Message); command = null; } Console.WriteLine(); }while (!commandsClient.IsExitCommand(command)); }
public static bool ExecuteCommand(string alias, NetworkAccount senderAccount, CommandsClient sender, List <string> parms) { foreach (NetworkCommand command in NetworkCommandsList.commands) { if (command.Names.Contains(alias)) { try { if (senderAccount.PermissionLvl < command.permission) { sender.SendMessage($"You are not allowed to use that command. For command \'{command.Names[0]}\' you need lvl {command.permission}"); return(false); } command.CommandDelegate(new NetworkCommandArgs(alias, senderAccount, sender, parms)); } catch (Exception ex) { sender.SendMessage($"Something went wrong while executing your command. Error: {ex.Message}"); return(false); } return(true); } } return(false); }