public bool Execute() { Uri uri = _uriString.ToUri("The from URI was invalid"); IInboundTransport fromTransport = Program.Transports.GetInboundTransport(uri); var text = new TextBlock() .BeginBlock("Peek URI: " + uri, ""); int peekCount = 0; fromTransport.Receive(receiveContext => { if (peekCount >= _count) { return(null); } var body = Encoding.UTF8.GetString(receiveContext.BodyStream.ReadToEnd()); text.BeginBlock("MessageId: " + receiveContext.MessageId ?? "", peekCount) .Body(body) .EndBlock(); peekCount++; return(null); }, 5.Seconds()); _log.Info(text.ToString()); return(true); }
public bool Execute() { Uri uri = _uriString.ToUri("The from URI was invalid"); IInboundTransport fromTransport = Program.Transports.GetTransport(uri); var text = new TextBlock() .BeginBlock("Peek URI: " + uri, ""); int peekCount = 0; fromTransport.Receive(receiveContext => { if (peekCount >= _count) return null; var body = Encoding.UTF8.GetString(receiveContext.BodyStream.ReadToEnd()); text.BeginBlock("MessageId: " + receiveContext.MessageId ?? "", peekCount) .Body(body) .EndBlock(); peekCount++; return null; }, TimeSpan.Zero); _log.Info(text.ToString()); return true; }
public void Consume(IConsumeContext <BusStatus> context) { if (!_requestId.Equals(context.RequestId)) { return; } if (_unsubscribe != null) { _unsubscribe(); } _unsubscribe = null; ITextBlock text = new TextBlock() .BeginBlock("Status URI:", _uriString) .EndBlock(); foreach (BusStatusEntry entry in context.Message.Entries) { text.BodyFormat("{0}:{1}", entry.Key, entry.Value); } text.EndBlock(); _log.Info(text.ToString()); _complete.Set(); }
public bool Execute() { Uri uri = _uriString.ToUri("The from URI was invalid"); AbsolutePathName fullPath = PathName.GetAbsolutePathName(_name, Environment.CurrentDirectory); _log.DebugFormat("Using output path name: {0}", fullPath); string directoryName = Path.GetDirectoryName(fullPath.GetPath()); if (!System.IO.Directory.Exists(directoryName)) { System.IO.Directory.CreateDirectory(directoryName); } IInboundTransport fromTransport = Program.Transports.GetInboundTransport(uri); ITextBlock text = new TextBlock() .BeginBlock("Save messages from URI: " + uri, ""); int lastCount; int saveCount = 0; do { lastCount = saveCount; fromTransport.Receive(receiveContext => { if (saveCount >= _count) { return(null); } string body = Encoding.UTF8.GetString(receiveContext.BodyStream.ReadToEnd()); text.BodyFormat("Message-Id: {0}", receiveContext.MessageId ?? ""); WriteMessageToFile(fullPath.ToString(), receiveContext, body); saveCount++; if (_remove) { return context => { } } ; return(null); }, 5.Seconds()); } while (_remove && saveCount < _count && saveCount != lastCount); _log.Info(text.ToString()); return(true); }
public bool Execute() { Uri uri = _uriString.ToUri("The from URI was invalid"); AbsolutePathName fullPath = PathName.GetAbsolutePathName(_name, Environment.CurrentDirectory); _log.DebugFormat("Using output path name: {0}", fullPath); string directoryName = Path.GetDirectoryName(fullPath.GetPath()); if (!System.IO.Directory.Exists(directoryName)) { System.IO.Directory.CreateDirectory(directoryName); } IOutboundTransport toTransport = Program.Transports.GetOutboundTransport(uri); ITextBlock text = new TextBlock() .BeginBlock("Load messages to URI: " + uri, ""); string[] files = System.IO.Directory.GetFiles(directoryName, fullPath.GetName() + "*.msg", SearchOption.TopDirectoryOnly) .OrderBy(x => x).ToArray(); int loadCount = 0; for (int i = 0; i < files.Length && loadCount < _count; i++) { string file = files[i]; string fileName = Path.Combine(directoryName, file); text.BodyFormat("Message File: {0}", file); ISendContext context = LoadMessageFromFile(fileName); toTransport.Send(context); if (_remove) { System.IO.File.Delete(fileName); } loadCount++; } _log.Info(text.ToString()); return(true); }
public void Consume(IReceivedMessageTraceList list) { if (_unsubscribe != null) { _unsubscribe(); } _unsubscribe = null; ITextBlock text = new TextBlock() .BeginBlock("Trace URI: " + _uriString, string.Format("{0} message{1}", list.Messages.Count, list.Messages.Count == 1 ? "" : "s")) .Break(); foreach (IReceivedMessageTraceDetail message in list.Messages) { text.BeginBlock("Received: " + message.Id, Format(message.StartTime)); text.Table(GetMessageHeaderDictionary(message), "Duration (ms)", ((int)message.Duration.TotalMilliseconds).ToString("N0")); text.Break(); if (message.Receivers != null) { foreach (IReceiverTraceDetail receiver in message.Receivers) { text.BeginBlock(receiver.ReceiverType, Format(receiver.StartTime)); text.Table(GetReceiverDictionary(receiver)); text.EndBlock(); } } if (message.SentMessages != null) { foreach (ISentMessageTraceDetail sent in message.SentMessages) { text.BeginBlock("Sent: " + sent.Id, Format(sent.StartTime)); text.Table(GetMessageHeaderDictionary(sent), "Endpoint Address", sent.Address.ToString()); text.EndBlock(); } } text.EndBlock(); } _log.Info(text.ToString()); _complete.Set(); }
public bool Execute() { Uri uri = _uriString.ToUri("The from URI was invalid"); AbsolutePathName fullPath = PathName.GetAbsolutePathName(_name, Environment.CurrentDirectory); _log.DebugFormat("Using output path name: {0}", fullPath); string directoryName = Path.GetDirectoryName(fullPath.GetPath()); if (!System.IO.Directory.Exists(directoryName)) System.IO.Directory.CreateDirectory(directoryName); IInboundTransport fromTransport = Program.Transports.GetTransport(uri); ITextBlock text = new TextBlock() .BeginBlock("Save messages from URI: " + uri, ""); int lastCount; int saveCount = 0; do { lastCount = saveCount; fromTransport.Receive(receiveContext => { if (saveCount >= _count) return null; string body = Encoding.UTF8.GetString(receiveContext.BodyStream.ReadToEnd()); text.BodyFormat("Message-Id: {0}", receiveContext.MessageId ?? ""); WriteMessageToFile(fullPath.ToString(), receiveContext, body); saveCount++; if (_remove) return context => { }; return null; }, TimeSpan.Zero); } while (_remove && saveCount < _count && saveCount != lastCount); _log.Info(text.ToString()); return true; }
private async Task UpdateTileAsync() { // create UI var grid = new Grid { VerticalAlignment = Windows.UI.Xaml.VerticalAlignment.Stretch, HorizontalAlignment = Windows.UI.Xaml.HorizontalAlignment.Stretch, }; var star = new FontIcon { Glyph = "", FontSize = 50 }; grid.Children.Add(star); var number = new TextBlock { Text = 12.ToString(), FontSize = 25, Foreground = new SolidColorBrush(Colors.White) }; grid.Children.Add(number); // create bitmap var bitmap = new RenderTargetBitmap(); await bitmap.RenderAsync(grid, 150, 150); // create destination file var folder = ApplicationData.Current.LocalFolder; var file = await folder.CreateFileAsync("tile.png", CreationCollisionOption.ReplaceExisting); // write bitmap to file using (var stream = await file.OpenAsync(FileAccessMode.ReadWrite)) { var pixels = await bitmap.GetPixelsAsync(); // using System.Runtime.InteropServices.WindowsRuntime; var bytes = pixels.ToArray(); var encoder = await BitmapEncoder .CreateAsync(BitmapEncoder.PngEncoderId, stream); var format = BitmapPixelFormat.Bgra8; var alpha = BitmapAlphaMode.Ignore; var width = (uint)bitmap.PixelWidth; var height = (uint)bitmap.PixelHeight; var dpi = DisplayInformation.GetForCurrentView().LogicalDpi; encoder.SetPixelData(format, alpha, width, height, dpi, dpi, bytes); await encoder.FlushAsync(); stream.Seek(0); } await FileIO.WriteBytesAsync(file, null); // replace existing tile var type = TileTemplateType.TileSquare150x150Image; var xml = TileUpdateManager.GetTemplateContent(type); // no text on tile var elements = xml.GetElementsByTagName("binding"); (elements[0] as XmlElement).SetAttribute("branding", "none"); // image on tile elements = xml.GetElementsByTagName("image"); (elements[0] as XmlElement).SetAttribute("src", file.Path); // update tile var notification = new TileNotification(xml); var updater = TileUpdateManager.CreateTileUpdaterForApplication(); updater.Clear(); updater.Update(notification); // prepare notification toast var toastTemplate = ToastTemplateType.ToastText01; xml = ToastNotificationManager.GetTemplateContent(toastTemplate); var text = xml.CreateTextNode(string.Format("Tile image updated to {0}", number)); elements = xml.GetElementsByTagName("text"); elements[0].AppendChild(text); // send toast var toast = new ToastNotification(xml); var notifier = ToastNotificationManager.CreateToastNotifier(); notifier.Show(toast); Debug.WriteLine("Background task toast shown: " + number.ToString()); }
public IEntity CreateEntity(TextBlock word) { return(CreateEntity(word.ToString(), word.TextBlockType)); }
public override string ToString() => $"Text {_source?.ToString() ?? _block?.ToString()}";