public IEnumerable <LastMessage> GetMessages(int id) { List <LastMessage> lastChatMessages = new List <LastMessage>(); IEnumerable <Contact> contacten = (from c in ctx.Contacts where c.OwnerAccount == id && c.ContactAccount != null select c).ToList(); Account myAcc = (from a in ctx.Accounts where a.Id == id select a).SingleOrDefault(); foreach (Contact c in contacten) //Loop alle contacten van de gebruiker langs die een account hebben { //account = het account van de contact Account account = (from a in ctx.Accounts where a.Id == c.ContactAccount select a).SingleOrDefault(); // Haal alle laatste berrichten van de chats ChatMessage lastchatMessage = (from ch in ctx.ChatMessages where ch.RecieverAccountID == account.Id && ch.SenderAccountId == myAcc.Id || ch.RecieverAccountID == myAcc.Id && ch.SenderAccountId == account.Id select ch).ToList().LastOrDefault(); if (lastchatMessage != null) //Er is ooit een berricht verstuurd { LastMessage lcm = new LastMessage(account, lastchatMessage.Message, lastchatMessage.Datetime); lastChatMessages.Add(lcm); } else // Er is nog nooit een berricht verstuud { LastMessage lcm = new LastMessage(account, "", default(DateTime)); lastChatMessages.Add(lcm); } } // Lijst met( welk account in de chat zit(ex. jezlef), de teskt van het berricht, datm en tijd van ontvangen IEnumerable <LastMessage> lm = lastChatMessages; return(lm); }
public FriendExtendedInfo GetFriendExtendedInfo(string uid) { var friendInfo = new FriendExtendedInfo(); LastMessage lm = ExecuteFQL <LastMessage>("SELECT status_id, uid, message, time FROM status WHERE uid = " + uid + " ORDER BY time DESC LIMIT 1").FirstOrDefault(); dynamic lc = ExecuteFQL("SELECT birthday, current_location from user where uid = " + uid); if (lm != null) { friendInfo.message = lm.message; friendInfo.message_datetime = UnixTimeStampToDateTime(lm.time); friendInfo.message_id = lm.status_id; } if (lc != null && lc.data != null) { friendInfo.birthday = lc.data[0].birthday; if (lc.data[0].current_location != null) { friendInfo.location = new Location(); friendInfo.location.city = lc.data[0].current_location.city == null ? null : lc.data[0].current_location.city.Value; friendInfo.location.country = lc.data[0].current_location.country == null ? null : lc.data[0].current_location.country.Value; friendInfo.location.latitude = lc.data[0].current_location.latitude == null ? 0 : (decimal)(lc.data[0].current_location.latitude.Value); friendInfo.location.longitude = lc.data[0].current_location.longitude == null ? 0 : (decimal)(lc.data[0].current_location.longitude.Value); friendInfo.location.state = lc.data[0].current_location.state == null ? null : lc.data[0].current_location.state.Value; friendInfo.location.street = lc.data[0].current_location.street == null ? null : lc.data[0].current_location.street.Value; friendInfo.location.zip = lc.data[0].current_location.zip == null ? null : lc.data[0].current_location.zip.Value; } } return(friendInfo); }
public void AddReaction(string emojiName) { string qualName = emojiName.StartsWith(":") == false || emojiName.EndsWith(":") == false ? $":{emojiName.Replace(":", "")}:" : emojiName; LastMessage.CreateReactionAsync(DiscordEmoji.FromName(CmdContext.Client, qualName)) .GetAwaiter() .GetResult(); }
public async Task WriteAsync(TProtocol oprot, CancellationToken cancellationToken) { oprot.IncrementRecursionDepth(); try { var struc = new TStruct("SquareChatStatus"); await oprot.WriteStructBeginAsync(struc, cancellationToken); var field = new TField(); if (LastMessage != null && __isset.lastMessage) { field.Name = "lastMessage"; field.Type = TType.Struct; field.ID = 3; await oprot.WriteFieldBeginAsync(field, cancellationToken); await LastMessage.WriteAsync(oprot, cancellationToken); await oprot.WriteFieldEndAsync(cancellationToken); } if (SenderDisplayName != null && __isset.senderDisplayName) { field.Name = "senderDisplayName"; field.Type = TType.String; field.ID = 4; await oprot.WriteFieldBeginAsync(field, cancellationToken); await oprot.WriteStringAsync(SenderDisplayName, cancellationToken); await oprot.WriteFieldEndAsync(cancellationToken); } if (OtherStatus != null && __isset.otherStatus) { field.Name = "otherStatus"; field.Type = TType.Struct; field.ID = 5; await oprot.WriteFieldBeginAsync(field, cancellationToken); await OtherStatus.WriteAsync(oprot, cancellationToken); await oprot.WriteFieldEndAsync(cancellationToken); } await oprot.WriteFieldStopAsync(cancellationToken); await oprot.WriteStructEndAsync(cancellationToken); } finally { oprot.DecrementRecursionDepth(); } }
public void Write(TProtocol oprot) { oprot.IncrementRecursionDepth(); try { TStruct struc = new TStruct("SquareChatStatus"); oprot.WriteStructBegin(struc); TField field = new TField(); if (LastMessage != null && __isset.lastMessage) { field.Name = "lastMessage"; field.Type = TType.Struct; field.ID = 3; oprot.WriteFieldBegin(field); LastMessage.Write(oprot); oprot.WriteFieldEnd(); } if (SenderDisplayName != null && __isset.senderDisplayName) { field.Name = "senderDisplayName"; field.Type = TType.String; field.ID = 4; oprot.WriteFieldBegin(field); oprot.WriteString(SenderDisplayName); oprot.WriteFieldEnd(); } if (OtherStatus != null && __isset.otherStatus) { field.Name = "otherStatus"; field.Type = TType.Struct; field.ID = 5; oprot.WriteFieldBegin(field); OtherStatus.Write(oprot); oprot.WriteFieldEnd(); } oprot.WriteFieldStop(); oprot.WriteStructEnd(); } finally { oprot.DecrementRecursionDepth(); } }
public override int GetHashCode() { int hashcode = 157; unchecked { if (__isset.lastMessage) { hashcode = (hashcode * 397) + LastMessage.GetHashCode(); } if (__isset.senderDisplayName) { hashcode = (hashcode * 397) + SenderDisplayName.GetHashCode(); } if (__isset.otherStatus) { hashcode = (hashcode * 397) + OtherStatus.GetHashCode(); } } return(hashcode); }
static void Main(string[] args) { var builder = new ConfigurationBuilder() .SetBasePath(Directory.GetCurrentDirectory()) .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true); IConfigurationRoot configuration = builder.Build(); var bot = new TelegramBotClient(configuration.GetSection("AccessToken").Value); var me = bot.GetMeAsync().Result; Console.WriteLine( $"I am user {me.Id} and my name is {me.FirstName}." ); var lastMessage = new LastMessage(bot); var itsTimeTo = new ItsTimeTo(bot); bot.OnMessage += lastMessage.OnMessage; bot.OnMessage += itsTimeTo.OnMessage; bot.StartReceiving(); Thread.Sleep(int.MaxValue); }
public override string ToString() { var sb = new StringBuilder("SquareChatStatus("); bool __first = true; if (LastMessage != null && __isset.lastMessage) { if (!__first) { sb.Append(", "); } __first = false; sb.Append("LastMessage: "); LastMessage.ToString(sb); } if (SenderDisplayName != null && __isset.senderDisplayName) { if (!__first) { sb.Append(", "); } __first = false; sb.Append("SenderDisplayName: "); SenderDisplayName.ToString(sb); } if (OtherStatus != null && __isset.otherStatus) { if (!__first) { sb.Append(", "); } __first = false; sb.Append("OtherStatus: "); OtherStatus.ToString(sb); } sb.Append(")"); return(sb.ToString()); }
public override string ToString() { StringBuilder __sb = new StringBuilder("SquareChatStatus("); bool __first = true; if (LastMessage != null && __isset.lastMessage) { if (!__first) { __sb.Append(", "); } __first = false; __sb.Append("LastMessage: "); __sb.Append(LastMessage == null ? "<null>" : LastMessage.ToString()); } if (SenderDisplayName != null && __isset.senderDisplayName) { if (!__first) { __sb.Append(", "); } __first = false; __sb.Append("SenderDisplayName: "); __sb.Append(SenderDisplayName); } if (OtherStatus != null && __isset.otherStatus) { if (!__first) { __sb.Append(", "); } __first = false; __sb.Append("OtherStatus: "); __sb.Append(OtherStatus == null ? "<null>" : OtherStatus.ToString()); } __sb.Append(")"); return(__sb.ToString()); }
public ITestAction AssertLastMessageContains(string message) { Assert.IsTrue(LastMessage.Contains(message), "Last message expected to contain: '" + message + "' actual: '" + LastMessage + "'"); return this; }
public IConversationBuilder SetLastMessage(LastMessage lastMessage) { this.conversation.LastMessage = lastMessage; return(this); }
public bool EqualsLastPacket(string Packet) { return(LastMessage.Equals(Packet)); }
private Message ReceiveMessageInternal(int timeout) { _logger.Trace("start, timeout: " + timeout); if (State != MasterDeviceState.Idle) { _logger.Debug("Master device is busy"); throw new Exception("Master device is busy"); } var buffer = new List <byte>(); var replyBit = false; Message result; // 2 reasons for break cycle // 1) end of message // 2) time is out try { State = MasterDeviceState.Receiving; lock (_syncRoot4SerialPortActions) { if (Port == null || !Port.IsOpen) { _logger.Debug("Master device is not available"); throw new Exception("Master device is not available"); } Port.ReadTimeout = timeout; } while (true) { //if (TraceThreadBlocking) // Debug.WriteLine("{1} thread {0} try to read byte", Task.CurrentId, DateTime.Now); byte b; lock (_syncRoot4SerialPortActions) { if (Port == null || !Port.IsOpen) { _logger.Debug("Master device is not available"); throw new Exception("Master device is not available"); } b = (byte)Port.ReadByte(); } replyBit = true; buffer.Add(b); // chech if message complete if (buffer.Count < CctalkMessage.MinMessageLength || buffer.Count != CctalkMessage.MinMessageLength + buffer[CctalkMessage.PosDataLen]) { continue; } _logger.Trace("end message"); // check if echo if (!LastMessage.ToBytes().SequenceEqual(buffer)) { if (buffer.Sum(x => x) % 256 != 0) { _logger.Debug("Invalid checksum"); throw new Exception("Invalid checksum"); } break; } buffer.Clear(); } _logger.Trace("-------- RX: " + string.Join(" ", buffer.Select(x => x.ToString("X2")))); result = new Message(buffer[CctalkMessage.PosDestAddr], buffer[CctalkMessage.PosSourceAddr], buffer[CctalkMessage.PosHeader]) { Data = buffer.Skip(4).Take(buffer[CctalkMessage.PosDataLen]).ToArray() }; } catch (TimeoutException ex) { if (!replyBit) { throw new TimeoutException("Slave device does not respond", ex); } result = GetDefaultMessage(buffer); } catch (Exception ex) { _logger.Debug(ex); result = GetDefaultMessage(buffer); } finally { State = MasterDeviceState.Idle; } LastMessage = result; return(result); }