public PropertyChangeWatcher AddWatcher(IList <string> propertyNames, Action handler) { Contract.Requires(handler != null); Contract.Requires(propertyNames != null); Contract.Requires(propertyNames.Count > 0); Contract.Requires(propertyNames.AllUnique()); BotUtil.ThrowUnless(propertyNames.All(name => OwnerType.HasPublicInstanceProperty(name)), "The target object does not contain one or more of the properties provided"); lock (_handlers) { foreach (var key in propertyNames) { BotUtil.ThrowUnless <ArgumentException>(!IsWatching(key), "Must not already be watching property '{0}'".StringFormat(key)); } if (_handlers.Count == 0) { _owner.PropertyChanged += _owner_PropertyChanged; } foreach (var propertyName in propertyNames) { _handlers[propertyName] = handler; } return(this); } }
public void SetSetting(string[] path, string value) { if (path[0].Equals("enabled", StringComparison.CurrentCultureIgnoreCase)) { if (BotUtil.Bool(value)) { this.Enable(); } } }
private void updateMenuItems() { //antidle bool enabled = BotUtil.Bool(bot.GetSetting("/antidle/enabled")); antiidleToolStripMenuItem.Checked = enabled; //eat food enabled = BotUtil.Bool(bot.GetSetting("/eatfood/enabled")); eatFoodToolStripMenuItem.Checked = enabled; }
/// <summary> /// Ran by the thread to perform the request. /// </summary> public void Run() { if (this.param.Count > 0) { BotUtil.POSTPage(new Uri(this.url), this.param); } else { BotUtil.LoadPage(new Uri(url)); } }
public void StopWatching(string property) { lock (_handlers) { BotUtil.ThrowUnless(IsWatching(property)); _handlers.Remove(property); if (_handlers.Count == 0) { _owner.PropertyChanged -= _owner_PropertyChanged; } } }
/// <summary> /// Perform a post. /// </summary> /// <param name="service">The URL to post to.</param> /// <param name="stream">The stream to post.</param> public void PerformURLPOST(string service, Stream stream) { try { String contents = BotUtil.POSTPage(new Uri(service), stream); HandleResponse(contents); } catch (IOException e) { throw new EncogCloudError(e); } }
public string DownloadData(string[] args) { if (args.Length != 0) { _tempPath = args[0]; } else { _tempPath = Path.GetTempPath(); } string irisFile = Path.Combine(_tempPath, "auto-mpg.csv"); BotUtil.DownloadPage(new Uri(DataUrl), irisFile); Console.WriteLine(@"Downloading dataset to: " + irisFile); return(irisFile); }
private List <Item> findItemsOnContainer(int itemId, string location) { List <Item> items = new List <Item>(); Container c = this.GetContainer(BotUtil.Number(location)); if (c == null) { return(items); } foreach (Item item in c.Items) { if (item.Id == itemId) { items.Add(item); } } return(items); }
/// <summary> /// Perform a GET request. /// </summary> /// <param name="async">True if this request should be asynchronous.</param> /// <param name="url">The URL.</param> public void PerformURLGET(bool async, String url) { try { if (async) { AsynchronousCloudRequest request = new AsynchronousCloudRequest(url); Thread t = new Thread(new ThreadStart(request.Run)); t.Start(); } else { String contents = BotUtil.LoadPage(new Uri(url)); HandleResponse(contents); } } catch (IOException e) { throw new EncogCloudError(e); } }
/// <summary> /// Perform a POST to the cloud. /// </summary> /// <param name="async">True if this request should be asynchronous.</param> /// <param name="service">The service.</param> /// <param name="args">The POST arguments.</param> public void PerformURLPOST(bool async, String service, IDictionary <String, String> args) { try { if (async) { AsynchronousCloudRequest request = new AsynchronousCloudRequest( service, args); Thread t = new Thread(new ThreadStart(request.Run)); t.Start(); } else { String contents = BotUtil.POSTPage(new Uri(service), args); HandleResponse(contents); } } catch (IOException e) { throw new EncogCloudError(e); } }
/// <summary> /// Get a published text file. /// </summary> /// <param name="publishedPath">The path.</param> /// <returns>The file.</returns> public String GetPublishedTextFile(String publishedPath) { String uri = this.server + "published" + publishedPath; return(BotUtil.LoadPage(new Uri(uri))); }
private void button1_Click(object sender, EventArgs e) { //get the key if (String.IsNullOrEmpty(textBox1.Text)) { return; } KeyConverter k = new KeyConverter(); Key key = (Key)k.ConvertFromString(textBox1.Text); //hotkey type string sType = comboBox1.SelectedItem.ToString(); int count = bot.GetHotkeys().Count; string hotkeyID = Convert.ToString(count + 1); Hotkey hotkey; string slot; switch (sType) { case "Use item on yourself": hotkey = new Hotkey(hotkeyID, textBox1.Text, HotkeyType.UseOnYourself); hotkey.ItemId = BotUtil.Number(textBox2.Text); if (hotkey.ItemId < 0) { return; } //add from grid this.dataGridView1.Rows.Add(hotkeyID, textBox1.Text, "Use item on yourself", textBox2.Text, ""); bot.AddHotkey(hotkey); break; case "Use item on target": hotkey = new Hotkey(hotkeyID, textBox1.Text, HotkeyType.UseOnTarget); hotkey.ItemId = BotUtil.Number(textBox2.Text); if (hotkey.ItemId < 0) { return; } //add from grid this.dataGridView1.Rows.Add(hotkeyID, textBox1.Text, "Use item on target", textBox2.Text, ""); bot.AddHotkey(hotkey); break; case "Use with crosshairs": hotkey = new Hotkey(hotkeyID, textBox1.Text, HotkeyType.UseWithCrosshairs); hotkey.ItemId = BotUtil.Number(textBox2.Text); if (hotkey.ItemId < 0) { return; } //add from grid this.dataGridView1.Rows.Add(hotkeyID, textBox1.Text, "Use with crosshairs", textBox2.Text, ""); bot.AddHotkey(hotkey); break; case "Use item": hotkey = new Hotkey(hotkeyID, textBox1.Text, HotkeyType.UseItem); hotkey.ItemId = BotUtil.Number(textBox2.Text); if (hotkey.ItemId < 0) { return; } //add from grid this.dataGridView1.Rows.Add(hotkeyID, textBox1.Text, "Use item", textBox2.Text, ""); bot.AddHotkey(hotkey); break; case "Equip item": hotkey = new Hotkey(hotkeyID, textBox1.Text, HotkeyType.EquipItem); hotkey.ItemId = BotUtil.Number(textBox2.Text); if (hotkey.ItemId < 0) { return; } //add from grid slot = comboBox2.SelectedItem.ToString(); this.dataGridView1.Rows.Add(hotkeyID, textBox1.Text, "Equip item", textBox2.Text, slot); hotkey.InventoryLocation = getInventoryLocationByString(slot); bot.AddHotkey(hotkey); break; case "Unequip item": hotkey = new Hotkey(hotkeyID, textBox1.Text, HotkeyType.UnequipItem); //add from grid slot = comboBox2.SelectedItem.ToString(); this.dataGridView1.Rows.Add(hotkeyID, textBox1.Text, "Unequip item", "", slot); hotkey.InventoryLocation = getInventoryLocationByString(slot); bot.AddHotkey(hotkey); break; } textBox1.Clear(); }
public static void Requires(bool truth, string message = null) { BotUtil.ThrowUnless(truth, message); }
public static void Requires <TException>(bool truth, string message) where TException : Exception { BotUtil.ThrowUnless <TException>(truth, message); }
public static void Requires <TException>(bool truth) where TException : Exception, new() { BotUtil.ThrowUnless <TException>(truth); }
/// <summary> /// POST: api/Messages /// Receive a message from a user and reply to it /// </summary> public async Task <HttpResponseMessage> Post([FromBody] Activity activity) { try { if (activity.Type == ActivityTypes.Message) { string result = string.Empty; ConnectorClient connector = new ConnectorClient(new Uri(activity.ServiceUrl)); Activity replyMessage = activity.CreateReply("Expensify is typing..."); replyMessage.Type = ActivityTypes.Typing; await this.SendTypingResponse(connector, replyMessage); try { var handler = new BotCommandHandler(); var utilities = new BotUtil(activity, handler); if (utilities.State > 2) { result = await handler.GetReply(activity, utilities.UserName, utilities.ClientState, utilities.State); } if (string.IsNullOrEmpty(result)) { result = await utilities.GetReply(this.DatabaseFactory); } } catch (SerializationException ex) { this.TrackTelemetry(ex); if (ex.InnerException != null) { result = $"{ex.GetType().Name} : {ex.Message}"; } } catch (Exception ex) { this.TrackTelemetry(ex); if (ex.InnerException != null) { result = $"{ex.GetType().Name} : {ex.Message}"; } //result = "Thanks. :)"; //result = "Sorry, we have faced an issue. Can you please reframe the sentence and ask me again."; } if (!string.IsNullOrEmpty(result)) { replyMessage.Type = ActivityTypes.Message; replyMessage.Text = result; await connector.Conversations.ReplyToActivityAsync(replyMessage); } } else { await this.HandleSystemMessage(activity); } } catch { } var response = Request.CreateResponse(HttpStatusCode.OK); return(response); }
public void SetSetting(string[] path, string value) { if (path[0].Equals("enabled", StringComparison.CurrentCultureIgnoreCase)) { // Console.WriteLine("|Runemaker module: Enable: " + value); settings.Enabled = BotUtil.Bool(value); if (settings.Enabled) { this.Enable(); } else { this.Disable(); } } else if (path[0].Equals("hand", StringComparison.CurrentCultureIgnoreCase)) { if (!ItemLocation.IsInventory(value)) { return; } Console.WriteLine("seeting inventory location: " + value); settings.InventoryLocation = value; } else if (path[0].Equals("spell", StringComparison.CurrentCultureIgnoreCase)) { Spell spell = game.GetSpell(value); if (spell == null) { return; } settings.Spell = spell; } else if (path[0].Equals("value", StringComparison.CurrentCultureIgnoreCase)) { int val = BotUtil.Number(value); if (val < 0) { return; } settings.Value = val; } else if (path[0].Equals("condition", StringComparison.CurrentCultureIgnoreCase)) { value = value.ToLower(); switch (value) { case "mana percent above": settings.Condition = PlayerConditions.ManaPercentAbove; break; case "mana above": settings.Condition = PlayerConditions.ManaAbove; break; } } else if (path[0].Equals("logout", StringComparison.CurrentCultureIgnoreCase)) { settings.LogoutBlankRunes = BotUtil.Bool(value); } }