public void Receive (IMessagePart message) { Trace.WriteLine ("ERROR"); List<IOVector> vecs = new List<IOVector> (); int length = 0; //vecs.Append (message); foreach (IOVector v in message) { vecs.Add (v); length += v.Length; } IOVector[] iovec = vecs.ToArray (); Trace.WriteLine ("Vectors: " + iovec.Length + " Length: " + length); if (length % 4 != 0) Trace.WriteLine ("Error: % 4"); ushort nBlocks = (ushort)(length / 4); Trace.WriteLine ("nBlocks: " + nBlocks); /* unsafe { Request* rq = (Request*)iovec[0].Start; rq->Length = nBlocks; } */ Trace.WriteLine ("ReadPoll: " + sock.Poll (-1, SelectMode.SelectRead)); VectorIO.Read (fd, iovec); }
public void Send (IMessagePart message, bool correctLength) { List<IOVector> vecs = new List<IOVector> (); int length = 0; //vecs.AddRange (message); foreach (IOVector v in message) { vecs.Add (v); length += v.Length; } IOVector[] iovec = vecs.ToArray (); Trace.WriteLine ("Vectors: " + iovec.Length + " Length: " + length); if (length % 4 != 0) Trace.WriteLine ("Error: % 4"); ushort nBlocks = (ushort)(length / 4); Trace.WriteLine ("nBlocks: " + nBlocks); if (correctLength) { unsafe { Request* rq = (Request*)iovec[0].Base; rq->Length = nBlocks; } } Trace.WriteLine ("WritePoll: " + sock.Poll (-1, SelectMode.SelectWrite)); VectorIO.Write (fd, iovec); //FallbackWrite (iovec); //queue.Enqueue (message); }
/// <summary> /// Заполнить адреса в сообщении /// </summary> /// <param name="message"></param> /// <param name="emailMessage"></param> /// <returns></returns> private async Task FillAddresses(MimeMessage message, IMessagePart emailMessage) { if (message.From?.Mailboxes != null) { foreach (var mailbox in message.From.Mailboxes) { emailMessage.From.Add(await _contactService.CreateContactSummaryAsync(mailbox)); } } if (message.To?.Mailboxes != null) { foreach (var mailbox in message.To.Mailboxes) { emailMessage.To.Add(await _contactService.CreateContactSummaryAsync(mailbox)); } } if (message.Cc?.Mailboxes != null) { foreach (var mailbox in message.Cc.Mailboxes) { emailMessage.To.Add(await _contactService.CreateContactSummaryAsync(mailbox)); } } if (message.Bcc?.Mailboxes != null) { foreach (var mailbox in message.Bcc.Mailboxes) { emailMessage.To.Add(await _contactService.CreateContactSummaryAsync(mailbox)); } } }
public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { var collection = new ObservableCollection <Inline>(); var items = value as IEnumerable <IMessagePart>; if (items == null) { return(collection); } IMessagePart before = null; foreach (IMessagePart item in items) { if (item is IMessageText text) { collection.Add(new Run(text.Text)); } else if (item is IMessageLink link) { collection.Add(new Hyperlink(new Run(link.Text)) { NavigateUri = new Uri(link.Url) }); } else if (item is IMessageImage remoteImage) { var uiContainer = ConverterTools.RemoteImage2UiContainer(remoteImage); if (uiContainer != null) { collection.Add(uiContainer); } } else if (item is IMessageImagePortion ico) { if (before is IMessageText) { collection.Add(new Run(" ")); } var uiContainer = ConverterTools.ImagePortion2UiContainer(ico); if (uiContainer != null) { collection.Add(uiContainer); } } before = item; } return(collection); }
/// <summary> /// заполнить направление /// </summary> /// <param name="emailMessage"></param> private void FillDirection(IMessagePart emailMessage) { //если в поле от есть наш пользователь значит письмо исходящее if (HasInMailBox(emailMessage.From)) { emailMessage.Direction = Direction.Outcoming; } else { emailMessage.Direction = HasInMailBox(emailMessage.To) //если в поле кому есть наша почта значит входящее во всех остальных случаях оно входящее ? Direction.Incoming : Direction.Outcoming; } }
private static void FillParticipants(IUserMailbox userMailbox, IMessagePart emailMessage, IEmailMessage message) { var participants = EmailMessageParticipants(userMailbox, emailMessage, message); var toParticipants = participants .Where(c => emailMessage.To.Any(e => e.Email == c.EmailString)).ToList(); message.To.AddAll(toParticipants); var fromParticipants = participants .Where(c => emailMessage.From.Any(e => e.Email == c.EmailString)).ToList(); message.From.AddAll(fromParticipants); }
public void Send(IMessagePart message, bool correctLength) { List <IOVector> vecs = new List <IOVector> (); int length = 0; //vecs.AddRange (message); foreach (IOVector v in message) { vecs.Add(v); length += v.Length; } IOVector[] iovec = vecs.ToArray(); Trace.WriteLine("Vectors: " + iovec.Length + " Length: " + length); if (length % 4 != 0) { Trace.WriteLine("Error: % 4"); } ushort nBlocks = (ushort)(length / 4); Trace.WriteLine("nBlocks: " + nBlocks); if (correctLength) { unsafe { Request *rq = (Request *)iovec[0].Base; rq->Length = nBlocks; } } Trace.WriteLine("WritePoll: " + sock.Poll(-1, SelectMode.SelectWrite)); VectorIO.Write(fd, iovec); //FallbackWrite (iovec); //queue.Enqueue (message); }
void ChopTrimPart(IMessagePart part) { var bytes0 = Guid.NewGuid().ToByteArray(); var int0 = (uint)Util.rng.Next(1000, 1000000); var int1 = (uint)Util.rng.Next(1000, 1000000); part.Append(bytes0); part.Insert(int0); part.Insert(int0); part.Trim((UIntPtr)4); part.Trim(out var trim); Assert.Equal(int0, trim); Assert.True(Util.BytesEqual(bytes0, part.Raw)); part.Append(int1); part.Append(int1); part.Chop((UIntPtr)4); part.Chop(out var chop); Assert.Equal(int1, chop); Assert.True(Util.BytesEqual(bytes0, part.Raw)); }
public void Receive(IMessagePart message) { Trace.WriteLine("ERROR"); List <IOVector> vecs = new List <IOVector> (); int length = 0; //vecs.Append (message); foreach (IOVector v in message) { vecs.Add(v); length += v.Length; } IOVector[] iovec = vecs.ToArray(); Trace.WriteLine("Vectors: " + iovec.Length + " Length: " + length); if (length % 4 != 0) { Trace.WriteLine("Error: % 4"); } ushort nBlocks = (ushort)(length / 4); Trace.WriteLine("nBlocks: " + nBlocks); /* * unsafe { * Request* rq = (Request*)iovec[0].Start; * rq->Length = nBlocks; * } */ Trace.WriteLine("ReadPoll: " + sock.Poll(-1, SelectMode.SelectRead)); VectorIO.Read(fd, iovec); }
public byte[] Serialize(IMessagePart messagePart) { messagePart.ThrowIfNull("messagePart"); var serializer = new CompactSerializer(); var messageColor = messagePart as MessageColor; var messageLineBreak = messagePart as MessageLineBreak; var messageQuestion = messagePart as MessageQuestion; var messageText = messagePart as MessageText; if (messageColor != null) { serializer[0] = Encoding.UTF8.GetBytes("Color"); serializer[1] = MessageColorSerializer.Instance.Serialize(messageColor); } else if (messageLineBreak != null) { serializer[0] = Encoding.UTF8.GetBytes("LineBreak"); serializer[1] = MessageLineBreakSerializer.Instance.Serialize(messageLineBreak); } else if (messageQuestion != null) { serializer[0] = Encoding.UTF8.GetBytes("Question"); serializer[1] = MessageQuestionSerializer.Instance.Serialize(messageQuestion); } else if (messageText != null) { serializer[0] = Encoding.UTF8.GetBytes("Text"); serializer[1] = MessageTextSerializer.Instance.Serialize(messageText); } else { throw new ArgumentException(String.Format("Unknown message part type '{0}'.", messagePart.GetType().Name)); } return serializer.Serialize(); }
internal NngMessageStream(IMessagePart part) { this.part = part; }
public void Send (IMessagePart message) { Send (message, true); }
public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { var collection = new ObservableCollection <Inline>(); var items = value as IEnumerable <IMessagePart>; if (items == null) { return(collection); } IMessagePart before = null; foreach (IMessagePart item in items) { if (item is IMessageText text) { collection.Add(new Run(text.Text)); } else if (item is IMessageImage remoteImage) { var uiContainer = ConverterTools.RemoteImage2UiContainer(remoteImage); if (uiContainer != null) { collection.Add(uiContainer); } } else if (item is IMessageImagePortion ico) { if (before is IMessageText) { collection.Add(new Run(" ")); } var uiContainer = ConverterTools.ImagePortion2UiContainer(ico); if (uiContainer != null) { collection.Add(uiContainer); } } else if (item is IMessageSvg svg) { var box = new SharpVectors.Converters.SvgViewbox(); box.SvgSource = svg.Data; //box.SvgSource = @"<svg viewBox=""0 0 16 16"" preserveAspectRatio=""xMidYMid meet"" focusable=""false"" class=""style-scope yt-icon"" style=""pointer-events: none; display: block; width: 100%; height: 100%;"" xmlns=""http://www.w3.org/2000/svg"" version=""1.1""><g class=""style-scope yt-icon""><path d=""M9.64589146,7.05569719 C9.83346524,6.562372 9.93617022,6.02722257 9.93617022,5.46808511 C9.93617022,3.00042984 7.93574038,1 5.46808511,1 C4.90894765,1 4.37379823,1.10270499 3.88047304,1.29027875 L6.95744681,4.36725249 L4.36725255,6.95744681 L1.29027875,3.88047305 C1.10270498,4.37379824 1,4.90894766 1,5.46808511 C1,7.93574038 3.00042984,9.93617022 5.46808511,9.93617022 C6.02722256,9.93617022 6.56237198,9.83346524 7.05569716,9.64589147 L12.4098057,15 L15,12.4098057 L9.64589146,7.05569719 Z"" class=""style-scope yt-icon""></path></g></svg>"; if (svg.Height.HasValue) { box.Height = svg.Height.Value; } if (svg.Width.HasValue) { box.Width = svg.Width.Value; } var inline = new InlineUIContainer(box); collection.Add(inline); } else { } before = item; } return(collection); }
public void Send(IMessagePart message) { Send(message, true); }
private static List <IEmailMessageParticipant> EmailMessageParticipants(IUserMailbox userMailbox, IMessagePart emailMessage, IEmailMessage message) { var contactSummaries = emailMessage.From.ToList(); contactSummaries.AddRange(emailMessage.To); var emailList = contactSummaries.Select(c => c.Email).ToList(); var emailMessageParticipantManager = EmailMessageParticipantManager.Instance; var participants = emailMessageParticipantManager.GetParticipants(emailList).ToList(); var notExistingParticipants = contactSummaries .Where(c => participants.All(e => e.EmailString != c.Email)).ToList(); if (notExistingParticipants.Any()) { var securityService = Locator.GetServiceNotNull <ISecurityService>(); securityService.RunByUser(userMailbox.Owner, () => { var newParticipants = emailMessageParticipantManager.CreateParticipants(notExistingParticipants); participants.AddRange(newParticipants); }); } var existContactParticipants = participants .Where(c => c.TypeUid == InterfaceActivator.UID <IEmailMessageParticipantContact>()) .Select(c => c.CastAsRealType() is IEmailMessageParticipantContact participantContact ? participantContact : null) .Where(c => c != null).ToList(); var contacts = existContactParticipants.Select(c => c.Contact) .Where(c => c != null).ToList(); var contractors = contacts.Select(c => c.Contractor) .Where(c => c != null).ToList(); message.Contacts.AddAll(contacts); message.Contractors.AddAll(contractors); return(participants); }
public IMessageBuilder WithPart(IMessagePart request) { Parts.Add(request); return(this); }
public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { var collection = new ObservableCollection <Inline>(); var items = value as IEnumerable <IMessagePart>; if (items == null) { return(collection); } IMessagePart before = null; foreach (IMessagePart item in items) { if (item is IMessageText text) { collection.Add(new Run(text.Text)); } else if (item is IMessageLink link) { collection.Add(new Hyperlink(new Run(link.Text)) { NavigateUri = new Uri(link.Url) }); } else if (item is IMessageImage remoteImage) { var uiContainer = ConverterTools.RemoteImage2UiContainer(remoteImage); if (uiContainer != null) { collection.Add(uiContainer); } } else if (item is IMessageImagePortion ico) { if (before is IMessageText) { collection.Add(new Run(" ")); } var uiContainer = ConverterTools.ImagePortion2UiContainer(ico); if (uiContainer != null) { collection.Add(uiContainer); } } else if (item is IMessageRemoteSvg remoteSvg) { try { var box = new SharpVectors.Converters.SvgViewbox(); box.BeginInit(); box.Source = new Uri(remoteSvg.Url); box.EndInit(); if (remoteSvg.Width.HasValue) { box.Width = remoteSvg.Width.Value; } if (remoteSvg.Height.HasValue) { box.Height = remoteSvg.Height.Value; } var inline = new InlineUIContainer(box); collection.Add(inline); } catch (Exception ex) { Debug.WriteLine(ex.Message); } } else { } before = item; } return(collection); }
// https://github.com/openaps/openomni/wiki/Command-1D-Status-response public StatusResponse(IEnumerable <IMessagePart> parts) { base.Parts = parts; IMessagePart part = null; foreach (var p in parts) { if (part != null) { throw new ParserException("Status response contains more than one part!"); } part = p; } if (part.Content.Length != 9) { throw new ParserException("Status response has invalid length"); } var b0 = part.Content[0]; // b0 => bits abcdeeee // 4 - bit abcd nibble is a bit mask for active insulin delivery // a 8: Extended bolus active, exclusive of 4 bit // b 4: Immediate bolus active, exclusive of 8 bit // c 2: Temp basal active, exclusive of 1 bit // d 1: Basal active, exclusive of 2 bit // 4 - bit eeee nibble is the Pod Progress State value(0 thru to F) var extendedBolusActive = (b0 & 0x80) > 0; var immediateBolusActive = (b0 & 0x40) > 0; var tempBasalActive = (b0 & 0x20) > 0; var basalActive = (b0 & 0x10) > 0; if (extendedBolusActive && immediateBolusActive) { throw new ParserException("Status response reports inconsistent state: Both extended and immediate bolus active"); } if (tempBasalActive && basalActive) { throw new ParserException("Status response reports inconsistent state: Both temporary and scheduled basal active"); } if (extendedBolusActive) { this.BolusState = BolusState.ExtendedBolus; } else if (immediateBolusActive) { this.BolusState = BolusState.Running; } else { this.BolusState = BolusState.Inactive; } if (tempBasalActive) { this.BasalState = BasalState.Temporary; } else if (basalActive) { this.BasalState = BasalState.Scheduled; } else { this.BasalState = BasalState.Suspended; } this.Progress = (PodProgress)(b0 & 0x0F); var i1 = part.Content.GetUInt32BigEndian(1); //i1 > 0PPPSNNN dword = 0000 pppp pppp pppp psss snnn nnnn nnnn //0000 4 zero bits //ppppppppppppp 13 bits, Total 0.05U insulin pulses //ssss 4 bits, message sequence number(saved B9 >> 2) //nnn nnnn nnnn 11 bits, 0.05U Insulin pulses not delivered if cancelled by user uint maskDelivered = 0b00001111111111111000000000000000; uint maskSequence = 0b10000000000000000111100000000000; uint maskCancelled = 0b10000000000000000000011111111111; this.DeliveredPulses = (int)((i1 & maskDelivered) >> 15); this.MessageSequence = (int)((i1 & maskSequence) >> 11); this.NotDeliveredPulses = (int)(i1 & maskCancelled); var i5 = part.Content.GetUInt32BigEndian(5); //i5 > dword = faaa aaaa attt tttt tttt ttrr rrrr rrrr //f 1 bit, 0 or 1 if the Pod has encountered fault event $14 //aaaaaaaa 8 bits, bit mask of the active, unacknowledged alerts (1 << alert #) from the Command 19 Configure Alerts; this bit mask is the same as the TT byte in the 02 Error Response Type 2 //ttttttttttttt 13 bits, Pod active time in minutes //rrrrrrrrrr 10 bits, Reservoir 0.05U pulses remaining(if <= 50U) or $3ff(if > 50U left) uint maskFaultEvent = 0b10000000000000000000000000000000; uint maskAlarms = 0b01111111100000000000000000000000; uint maskMinutes = 0b00000000011111111111110000000000; uint maskReservoir = 0b10000000000000000000001111111111; this.FaultEvent = (i5 & maskFaultEvent) != 0; this.Alarms = (Alarm)((i5 & maskAlarms) >> 23); this.ActiveMinutes = (int)((i5 & maskMinutes) >> 10); this.Reservoir = (int)(i5 & maskReservoir); }