public void CanHandleFlags() { var paramses = new HandlerParams(null, new Update { Message = new Message { Text = "Blah" } }, null, "testbot"); var updateAttr = new UpdateAttribute { UpdateFlags = UpdateFlag.Message | UpdateFlag.Poll }; Assert.True(updateAttr.CanHandleInternal(paramses)); paramses = new HandlerParams(null, new Update { InlineQuery = new InlineQuery() }, null, "test"); Assert.False(updateAttr.CanHandleInternal(paramses)); paramses = new HandlerParams(null, new Update { ChosenInlineResult = new ChosenInlineResult() }, null, "test"); Assert.False(updateAttr.CanHandleInternal(paramses)); paramses = new HandlerParams(null, new Update { Poll = new Poll() }, null, "test"); Assert.True(updateAttr.CanHandleInternal(paramses)); updateAttr = new UpdateAttribute { UpdateFlags = UpdateFlag.All }; paramses = new HandlerParams(null, new Update(), null, "test"); Assert.True(updateAttr.CanHandleInternal(paramses)); }
private void BtnUpdateAttribute_Click(object sender, EventArgs e) { UpdateAttribute updateAttribute = new UpdateAttribute(); this.Hide(); updateAttribute.Show(); }
public void CanHandleInChannel() { var updateAttr = new UpdateAttribute { InChat = Setup.InChat.Channel }; var chat = new Chat { Type = ChatType.Channel }; var update = new Update { Message = new Message { Text = "Blah", Chat = chat } }; var paramses = new HandlerParams(null, update, null, "testbot"); Assert.True(updateAttr.CanHandleInternal(paramses)); chat = new Chat { Type = ChatType.Group }; update = new Update { Message = new Message { Text = "Blah", Chat = chat } }; paramses = new HandlerParams(null, update, null, "testbot"); Assert.False(updateAttr.CanHandleInternal(paramses)); chat = new Chat { Type = ChatType.Private }; update = new Update { Message = new Message { Text = "Blah", Chat = chat } }; paramses = new HandlerParams(null, update, null, "testbot"); Assert.False(updateAttr.CanHandleInternal(paramses)); chat = new Chat { Type = ChatType.Supergroup }; update = new Update { Message = new Message { Text = "Blah", Chat = chat } }; paramses = new HandlerParams(null, update, null, "testbot"); Assert.False(updateAttr.CanHandleInternal(paramses)); }
private void AutoRegisterUpdateObj() { var types = Assembly.GetAssembly(typeof(Game)).GetTypes(); foreach (Type type in types) { object[] attrs = type.GetCustomAttributes(typeof(UpdateAttribute), false); foreach (object attr in attrs) { UpdateAttribute mdAttr = attr as UpdateAttribute; if (mdAttr.autoRegister) { RegisterUpdateObj(mdAttr.name); } } } }
public Contracts.Attribute.Attribute Update(UpdateAttribute update) { using (var db = new RAAPEntities(GetConnectionString())) { var item = db.Attributes.FirstOrDefault(a => a.AttributeId == update.AttributeId); if (item == null) { throw new RAAPNotFoundException("Item not found."); } item.ApplyUpdate(update); RemoveChildAttributes(db, item, update.ChildAttributes.ToArray()); AddNewChildAttributes(db, item, update.ChildAttributes.ToArray()); db.SaveChanges(); return(new Attribute()); } }
public IApiResult Update(UpdateAttribute operation) { var result = operation.ExecuteAsync().Result; if (result is ValidationsOutput) { return(new ApiResult <List <ValidationItem> >() { Data = ((ValidationsOutput)result).Errors }); } else { return(new ApiResult <object>() { Status = ApiResult <object> .ApiStatus.Success }); } }
void UseUpdateAttribute() { // this class has methods // that need updating. HasUpdates needsUpdates = new HasUpdates(); // now we know what method has the attribute // in the class type var updateMethods = from m in needsUpdates.GetType().GetMethods() where m.GetCustomAttribute <UpdateAttribute>() is UpdateAttribute select m; /* hold onto the coroutines incase * we want to kill them later. */ List <IEnumerator> routineList = new List <IEnumerator>(); // has methods with update attribute foreach (var method in updateMethods) { /* inner function for each * method with custom attribute * inner function can pretty much * appear anywhere. */ IEnumerator updater() { while (true) { UpdateAttribute upa = method.GetCustomAttribute <UpdateAttribute>() as UpdateAttribute; method.Invoke(needsUpdates, new object[] { }); yield return(new WaitForSeconds(upa.Delay)); } } routineList.Add(updater()); } foreach (IEnumerator e in routineList) { StartCoroutine(e); } }
public async Task <bool> SetWebhook(string url, string certificate = null, int maxConnections = 40, List <UpdateType> allowedUpdates = null) { url.NullInspect(nameof(url)); if (maxConnections < 1 || maxConnections > 100) { throw new ArgumentOutOfRangeException(nameof(maxConnections), "Must be in range of 1 to 100"); } if (certificate != null) { if (!new FileInfo(certificate).Exists) { throw new ArgumentException("The file does not exists", certificate); } } using (var form = new MultipartFormDataContent()) { form.Add(new StringContent(url, Encoding.UTF8), "url"); form.Add(new StringContent(maxConnections.ToString(), Encoding.UTF8), "max_connections"); if (allowedUpdates != null) { var allowedUpdatesString = string.Join(",", allowedUpdates.Select(i => $"\"{UpdateAttribute.GetUpdateType(i)}\"")); form.Add(new StringContent($"[{allowedUpdatesString}]", Encoding.UTF8), "allowed_updates"); } if (certificate != null) { AddFileDataContent(form, certificate); } return(await UploadFormData <bool>(form).ConfigureAwait(false)); } }
public async Task <List <Update> > GetUpdates(long?offset = null, int?limit = null, int?timeout = null, List <UpdateType> allowedUpdates = null) { var content = new Content(); if (offset != null) { content.Add("offset", offset.ToString()); } if (limit != null) { content.Add("limit", limit.ToString()); } if (timeout != null) { content.Add("timeout", timeout.ToString()); } if (allowedUpdates != null) { var allowedUpdatesString = string.Join(",", allowedUpdates.Select(i => $"\"{UpdateAttribute.GetUpdateType(i)}\"")); content.Add("allowed_updates", $"[{allowedUpdatesString}]"); } using (var form = new FormUrlEncodedContent(content.Data)) { return(await UploadFormData <List <Update> >(form).ConfigureAwait(false)); } }
public StateContoller(object _obj) { m_curState = ANY_STATE; m_transitions = new List <TransPair>(); m_updates = new Dictionary <short, BasicFnct>(); MethodInfo[] mthds = _obj.GetType().GetMethods(BindingFlags.Instance | BindingFlags.NonPublic); // search all fields and find the attribute [TransitionAttribute] for (int i = 0; i < mthds.Length; i++) { TransitionAttribute attribute = Attribute.GetCustomAttribute(mthds[i], typeof(TransitionAttribute)) as TransitionAttribute; TransitionOverrideAttribute ovrride = Attribute.GetCustomAttribute(mthds[i], typeof(TransitionOverrideAttribute)) as TransitionOverrideAttribute; UpdateAttribute updateAttribute = Attribute.GetCustomAttribute(mthds[i], typeof(UpdateAttribute)) as UpdateAttribute; // if we detect a RememberMe attribute, generate field for dynamic class if (attribute != null) { TransPair p; p.m_key = getKey(attribute.m_from, attribute.m_to); //IF it already exists do not overrwrite! derrived fncts are handled first! @@actually should add some priority system bc the methodinfo can be any order int index; if (tryGetValue(p.m_key, out p.m_fnct, out index)) { //Debug.Log("Trying to define " + mthds[i].Name + " as a transition function."); //Debug.Log("transition already defined from: " + attribute.m_from + " to " + attribute.m_to + " on " + _obj); //Debug.Log("Ignore this if you've overriden a transition function with TransitionOverrideAttribute"); } else { //else add it p.m_fnct = Delegate.CreateDelegate(typeof(BasicFnct), _obj, mthds[i]) as BasicFnct; m_transitions.Add(p); } } // if we detect a RememberMe attribute, generate field for dynamic class else if (ovrride != null) { TransPair p; p.m_key = getKey(ovrride.m_from, ovrride.m_to); //IF it already exists DO overrwrite! int index; if (tryGetValue(p.m_key, out p.m_fnct, out index)) { m_transitions[index] = p; } else { p.m_fnct = Delegate.CreateDelegate(typeof(BasicFnct), _obj, mthds[i]) as BasicFnct; m_transitions.Add(p); } } else if (updateAttribute != null) //otherwise check for state update fnct { if (updateAttribute != null) { //seems like derrived class gets looked at first so we want first thing to not get overwritten... BasicFnct fnc = null; if (!m_updates.TryGetValue(updateAttribute.m_state, out fnc)) { m_updates[updateAttribute.m_state] = Delegate.CreateDelegate(typeof(BasicFnct), _obj, mthds[i]) as BasicFnct; } } } } }