public void CanHandleInChannel() { var command = new ParametrizedCommand(InChat.Channel, "test"); var paramses = new HandlerParams(null, new Update { Message = new Message { Text = "/test@testbot", Chat = new Chat { Type = ChatType.Channel } } }, null, "testbot"); Assert.True(command.CanHandleInternal(paramses)); paramses = new HandlerParams(null, new Update { Message = new Message { Text = "/test@testbot", Chat = new Chat { Type = ChatType.Group } } }, null, "testbot"); Assert.False(command.CanHandleInternal(paramses)); paramses = new HandlerParams(null, new Update { Message = new Message { Text = "/test@testbot", Chat = new Chat { Type = ChatType.Supergroup } } }, null, "testbot"); Assert.False(command.CanHandleInternal(paramses)); paramses = new HandlerParams(null, new Update { Message = new Message { Text = "/test@testbot", Chat = new Chat { Type = ChatType.Private } } }, null, "testbot"); Assert.False(command.CanHandleInternal(paramses)); }
public LoadSaveDataDialog() { InitializeComponent(); DataContext = this; CancelCommand = new Command(() => { MainWindow.Instance.Paths.Children.Remove(this); SelectedData = new SavedData() { Name = null }; evnt.Set(); }); LoadCommand = new ParametrizedCommand((o) => { SavedData d = (SavedData)o; SelectedData = d; MainWindow.Instance.Paths.Children.Remove(this); evnt.Set(); }); ItemList.Loaded += ItemList_Loaded; }
public void CanHandleByTextWithUsername() { var command = new ParametrizedCommand("test"); var paramses = new HandlerParams(null, new Update { Message = new Message { Text = "/test@testbot" } }, null, "testbot"); Assert.True(command.CanHandleInternal(paramses)); }
public void CanFilterUserName() { var commandInChat = new ParametrizedCommand(InChat.All, "test", CommandParseMode.Both); var command = new ParametrizedCommand("test", CommandParseMode.Both); var paramses = new HandlerParams(null, new Update { Message = new Message { Text = "/test@testbot" } }, null, "testbot"); Assert.True(commandInChat.CanHandleInternal(paramses)); Assert.True(command.CanHandleInternal(paramses)); commandInChat = new ParametrizedCommand(InChat.All, "test", CommandParseMode.WithUsername); command = new ParametrizedCommand("test", CommandParseMode.WithUsername); Assert.True(commandInChat.CanHandleInternal(paramses)); Assert.True(command.CanHandleInternal(paramses)); commandInChat = new ParametrizedCommand(InChat.All, "test", CommandParseMode.WithoutUsername); command = new ParametrizedCommand("test", CommandParseMode.WithoutUsername); Assert.False(commandInChat.CanHandleInternal(paramses)); Assert.False(command.CanHandleInternal(paramses)); paramses = new HandlerParams(null, new Update { Message = new Message { Text = "/test" } }, null, "testbot"); Assert.True(commandInChat.CanHandleInternal(paramses)); Assert.True(command.CanHandleInternal(paramses)); }
public MainWindowViewModel() { Services.Instance.AddMainWindowModel(this); Services.Instance.AddManualUserInput(ManualResolveViewModel); ImgProcessing = new ImageProcessor(SelectedShopRuleset); Services.Instance.ServerHandler.StartServer(); Services.Instance.ServerHandler.OnImageReceived += (s, e) => { ImageSource = e; }; ImgProcessing.OnImageParsed += OnImageParsed; Finalize = new ParametrizedCommand((obj) => { Purchase purchase = new Purchase(SelectedShopRuleset.Shop, ImgProcessing.CurrentParsingResult.Meta.PurchasedAt, _matchedItems.Select(s => s.ItemPurchase).ToArray()); purchase.FinalizePurchase(); ClearButtonVisible = true; FinalizeButtonVisible = false; }); Clear = new ParametrizedCommand((obj) => { ImageSource = ResourceNames.TRANSPARENT_IMAGE; FinalizeButtonVisible = false; SendToMTDBButtonVisible = false; ClearButtonVisible = false; ManualPurchaseButtonVisible = true; AnalyzeButtonVisible = true; UnknownItems.Clear(); MatchedItems.Clear(); }); Analyze = new ParametrizedCommand((obj) => { if (string.IsNullOrEmpty(ImageSource) || ImageSource == ResourceNames.TRANSPARENT_IMAGE) { //TODO return; } _ = ImgProcessing.Analyze(ImageSource); }); SendToMTDB = new ParametrizedCommand(async(obj) => { using (CPCServer server = new CrossProcessCommunication().StartServer(5689)) { server.StartListening(); await server.ListenForClient(); server.SendString(SenderHelper.GetString(ImgProcessing.CurrentParsingResult)); server.StopListening(); } }); OnMouseRightClickImage += (s, e) => { if (string.IsNullOrEmpty(ImageSource) || ImageSource == ResourceNames.TRANSPARENT_IMAGE) { //TODO return; } new Process { StartInfo = new ProcessStartInfo(ImageSource) }.Start(); }; Instance = this; }